当前位置: 首页>>代码示例>>Java>>正文


Java ElementManipulators类代码示例

本文整理汇总了Java中com.intellij.psi.ElementManipulators的典型用法代码示例。如果您正苦于以下问题:Java ElementManipulators类的具体用法?Java ElementManipulators怎么用?Java ElementManipulators使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


ElementManipulators类属于com.intellij.psi包,在下文中一共展示了ElementManipulators类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: getRangePair

import com.intellij.psi.ElementManipulators; //导入依赖的package包/类
@Nullable
protected Pair<PsiElement, TextRange> getRangePair(final PsiFile file, final Editor editor) {
  final int offset = editor.getCaretModel().getOffset();
  final PsiLanguageInjectionHost host =
    PsiTreeUtil.getParentOfType(file.findElementAt(offset), PsiLanguageInjectionHost.class, false);
  if (host == null || ElementManipulators.getManipulator(host) == null) return null;
  final List<Pair<PsiElement, TextRange>> injections = InjectedLanguageManager.getInstance(host.getProject()).getInjectedPsiFiles(host);
  if (injections == null || injections.isEmpty()) return null;
  final int offsetInElement = offset - host.getTextRange().getStartOffset();
  final Pair<PsiElement, TextRange> rangePair = ContainerUtil.find(injections, new Condition<Pair<PsiElement, TextRange>>() {
    @Override
    public boolean value(final Pair<PsiElement, TextRange> pair) {
      return pair.second.containsRange(offsetInElement, offsetInElement);
    }
  });
  if (rangePair != null) {
    final Language language = rangePair.first.getContainingFile().getLanguage();
    final Object action = language.getUserData(EDIT_ACTION_AVAILABLE);
    if (action != null && action.equals(false)) return null;

    myLastLanguageName = language.getDisplayName();
  }
  return rangePair;
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:25,代码来源:QuickEditAction.java

示例2: getInjectedArea

import com.intellij.psi.ElementManipulators; //导入依赖的package包/类
@NotNull
public List<TextRange> getInjectedArea(final PsiElement element) {
  final TextRange textRange = ElementManipulators.getValueTextRange(element);
  if (myCompiledValuePattern == null) {
    return Collections.singletonList(textRange);
  }
  else {
    final LiteralTextEscaper<? extends PsiLanguageInjectionHost> textEscaper =
            ((PsiLanguageInjectionHost)element).createLiteralTextEscaper();
    final StringBuilder sb = new StringBuilder();
    textEscaper.decode(textRange, sb);
    final List<TextRange> ranges = getMatchingRanges(myCompiledValuePattern.matcher(StringPattern.newBombedCharSequence(sb)), sb.length());
    return !ranges.isEmpty() ? ContainerUtil.map(ranges, new Function<TextRange, TextRange>() {
      public TextRange fun(TextRange s) {
        return new TextRange(textEscaper.getOffsetInHost(s.getStartOffset(), textRange), textEscaper.getOffsetInHost(s.getEndOffset(), textRange));
      }
    }) : Collections.<TextRange>emptyList();
  }
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:20,代码来源:BaseInjection.java

示例3: checkValue

import com.intellij.psi.ElementManipulators; //导入依赖的package包/类
protected void checkValue( XmlAttributeValue value, XmlFile file, XmlRefCountHolder refHolder,
    XmlTag tag, ProblemsHolder holder )
{
    if( refHolder.isValidatable( tag.getParent() )
        && ((XmlAttribute)(value).getParent()).getName().equals( "xmi:id" ) )
    {

        int matches =
            StringUtils.countMatches( file.getText(), ((XmlAttribute)(value).getParent()).getText() );

        if( matches > 1 )
        {
            holder.registerProblem( value, "XMI Duplicate id", ProblemHighlightType.GENERIC_ERROR,
                ElementManipulators.getValueTextRange( value ), new DuplicateIdQuickFix() );
        }
    }
}
 
开发者ID:mcmil,项目名称:wuff-intellij-plugin,代码行数:18,代码来源:XmiDuplicatedIdInspection.java

示例4: createReferences

import com.intellij.psi.ElementManipulators; //导入依赖的package包/类
@NotNull
@Override
public PsiReference[] createReferences(GenericDomValue value, final PsiElement element, final ConvertContext context) {
  String text = value.getStringValue();
  TextRange range = ElementManipulators.getValueTextRange(element);
  return new PsiReference[]{new MavenUrlPsiReference(element, text, range) {

    @NotNull
    @Override
    public Object[] getVariants() {
      Module module = context.getModule();

      if (module != null) {
        String name = MavenRepositoriesProvider.getInstance().getRepositoryUrl(getRepositoryId(context));
        if (!StringUtil.isEmptyOrSpaces(name)) return new Object[]{name};
      }
      return super.getVariants();
    }
  }};
}
 
开发者ID:lshain-android-source,项目名称:tools-idea,代码行数:21,代码来源:MavenRepositoryConverter.java

示例5: getRangePair

import com.intellij.psi.ElementManipulators; //导入依赖的package包/类
@Nullable
protected Pair<PsiElement, TextRange> getRangePair(final PsiFile file, final Editor editor) {
  final int offset = editor.getCaretModel().getOffset();
  final PsiLanguageInjectionHost host =
          PsiTreeUtil.getParentOfType(file.findElementAt(offset), PsiLanguageInjectionHost.class, false);
  if (host == null || ElementManipulators.getManipulator(host) == null) return null;
  final List<Pair<PsiElement, TextRange>> injections = InjectedLanguageManager.getInstance(host.getProject()).getInjectedPsiFiles(host);
  if (injections == null || injections.isEmpty()) return null;
  final int offsetInElement = offset - host.getTextRange().getStartOffset();
  final Pair<PsiElement, TextRange> rangePair = ContainerUtil.find(injections, new Condition<Pair<PsiElement, TextRange>>() {
    @Override
    public boolean value(final Pair<PsiElement, TextRange> pair) {
      return pair.second.containsRange(offsetInElement, offsetInElement);
    }
  });
  if (rangePair != null) {
    final Language language = rangePair.first.getContainingFile().getLanguage();
    final Object action = language.getUserData(EDIT_ACTION_AVAILABLE);
    if (action != null && action.equals(false)) return null;

    myLastLanguageName = language.getDisplayName();
  }
  return rangePair;
}
 
开发者ID:consulo,项目名称:consulo,代码行数:25,代码来源:QuickEditAction.java

示例6: createReferences

import com.intellij.psi.ElementManipulators; //导入依赖的package包/类
@NotNull
public PsiReference[] createReferences(final GenericDomValue genericDomValue, final PsiElement element, final ConvertContext context) {
  final String s = genericDomValue.getStringValue();
  if (s != null) {
    final int offset = ElementManipulators.getOffsetInElement(element);
    final ArrayList<PsiReference> list = new ArrayList<PsiReference>();
    int pos = -1;
    while (true) {
      while (pos + 1 < s.length()) {
        if (!Character.isWhitespace(s.charAt(pos + 1))) {
          break;
        }
        pos++;
      }
      int nextPos = s.indexOf(',', pos + 1);
      if (nextPos == -1) {
        createReference(element, s.substring(pos + 1), pos + 1 + offset, list);
        break;
      }
      else {
        createReference(element, s.substring(pos + 1, nextPos), pos + 1 + offset, list);
        pos = nextPos;
      }
    }
    return list.toArray(new PsiReference[list.size()]);
  }
  return PsiReference.EMPTY_ARRAY;
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:29,代码来源:ClassArrayConverterImpl.java

示例7: testManipulatorRegistered

import com.intellij.psi.ElementManipulators; //导入依赖的package包/类
public void testManipulatorRegistered() {
  LanguageExtensionPoint[] extensions =
    Extensions.getExtensions(new ExtensionPointName<LanguageExtensionPoint>("com.intellij.lang.parserDefinition"));
  Set<String> classes = new HashSet<String>();
  List<String> failures = new ArrayList<String>();
  int total = 0;
  for (LanguageExtensionPoint e : extensions) {
    ParserDefinition definition = (ParserDefinition)e.getInstance();

    for (IElementType type : IElementType.enumerate(IElementType.TRUE)) {
      if (type instanceof ILeafElementType) continue;
      try {
        CompositeElement treeElement = ASTFactory.composite(type);
        total++;
        PsiElement element = treeElement instanceof PsiElement? (PsiElement)treeElement : definition.createElement(treeElement);
        if (element instanceof PsiLanguageInjectionHost && classes.add(element.getClass().getName())) {
          boolean ok = ElementManipulators.getManipulator(element) != null;
          System.out.println((ok ? "OK  " : "FAIL") + " " + element.getClass().getSimpleName() + " [" + definition.getClass().getSimpleName() + "]");
          if (!ok) failures.add(element.getClass().getName());
        }
      }
      catch (Throwable ignored) {
      }
    }
  }
  System.out.println("count: " + classes.size() + ", total: " + total);
  assertEmpty("PsiLanguageInjectionHost requires " + ElementManipulators.EP_NAME, failures);
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:29,代码来源:IElementTypeTest.java

示例8: getManipulator

import com.intellij.psi.ElementManipulators; //导入依赖的package包/类
@NotNull
public static <T extends PsiElement> ElementManipulator<T> getManipulator(T currentElement){
  ElementManipulator<T> manipulator = ElementManipulators.getManipulator(currentElement);
  if (manipulator == null) {
    throw new IncorrectOperationException("Manipulator for this element is not defined: " + currentElement + "; " + currentElement.getClass());
  }
  return manipulator;
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:9,代码来源:CachingReference.java

示例9: createReferences

import com.intellij.psi.ElementManipulators; //导入依赖的package包/类
@Override
public boolean createReferences(@NotNull final PsiElement psiElement, final @NotNull List<PsiReference> references, final boolean soft) {

  final TextRange range = ElementManipulators.getValueTextRange(psiElement);
  int offset = range.getStartOffset();
  int endOffset = range.getEndOffset();
  final String elementText = psiElement.getText();
  for (DynamicContextProvider provider: Extensions.getExtensions(DynamicContextProvider.EP_NAME)) {
    final int dynamicOffset = provider.getOffset(psiElement, offset, elementText);
    if (dynamicOffset == -1) {
      return false;
    } else if (dynamicOffset != offset) {
      offset = dynamicOffset;
    }
  }

  final int pos = getLastPosOfURL(offset, elementText);
  if (pos != -1 && pos < endOffset) {
    endOffset = pos;
  }
  try {
    final String text = elementText.substring(offset, endOffset);
    return createReferences(psiElement, offset, text, references, soft);
  } catch (StringIndexOutOfBoundsException e) {
    LOG.error("Cannot process string: '" + psiElement.getParent().getParent().getText() + "'", e);
    return false;
  }
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:29,代码来源:PathReferenceProviderBase.java

示例10: select

import com.intellij.psi.ElementManipulators; //导入依赖的package包/类
@Override
public List<TextRange> select(PsiElement e, CharSequence editorText, int cursorOffset, Editor editor) {
  final IElementType type = e.getNode().getElementType();
  final StringLiteralLexer lexer = new StringLiteralLexer(type == SINGLE_QUOTED_STRING ? '\'' : '"', type, false, "/", false, false);
  final List<TextRange> result = new ArrayList<TextRange>();
  SelectWordUtil.addWordHonoringEscapeSequences(editorText, e.getTextRange(), cursorOffset, lexer, result);

  final PsiElement parent = e.getParent();
  result.add(ElementManipulators.getValueTextRange(parent).shiftRight(parent.getTextOffset()));
  return result;
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:12,代码来源:JsonStringLiteralSelectionHandler.java

示例11: handleElementRename

import com.intellij.psi.ElementManipulators; //导入依赖的package包/类
@Override
public PsiElement handleElementRename(String newElementName) throws IncorrectOperationException {
  final String canonicalText = getCanonicalText();

  final PsiElement element = ElementManipulators.getManipulator(myElement)
    .handleContentChange(myElement, getRangeInElement(), newElementName);
  myRange = new TextRange(myRange.getStartOffset(),myRange.getEndOffset() - (canonicalText.length() - newElementName.length()));
  return element;
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:10,代码来源:TypeOrElementOrAttributeReference.java

示例12: handleElementRename

import com.intellij.psi.ElementManipulators; //导入依赖的package包/类
public PsiElement handleElementRename(String newElementName) throws IncorrectOperationException {
  return ElementManipulators.getManipulator(myElement).handleContentChange(
    myElement,
    getRangeInElement(),
    newElementName
  );
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:8,代码来源:BasicAttributeValueReference.java

示例13: createJspPrefix

import com.intellij.psi.ElementManipulators; //导入依赖的package包/类
public static SchemaPrefix createJspPrefix(XmlAttributeValue element, String prefix) {
  TextRange range = ElementManipulators.getValueTextRange(element).shiftRight(element.getStartOffsetInParent());
  return new SchemaPrefix((XmlAttribute)element.getParent(), range, prefix) {
    @Override
    protected String getNamespace() {
      return ((XmlAttribute)getParent()).getParent().getAttributeValue("uri");
    }
  };
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:10,代码来源:SchemaPrefix.java

示例14: setName

import com.intellij.psi.ElementManipulators; //导入依赖的package包/类
@Override
public PsiElement setName(@NotNull String name) throws IncorrectOperationException {
  final PsiElement nameElement = getNameElement();

  if (nameElement != null) {
    return ElementManipulators.getManipulator(nameElement).handleContentChange(
      nameElement,
      new TextRange(0,nameElement.getTextLength()),
      name
    );
  }
  return null;
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:14,代码来源:XmlEntityDeclImpl.java

示例15: createReferences

import com.intellij.psi.ElementManipulators; //导入依赖的package包/类
@Override
public boolean createReferences(@NotNull final PsiElement psiElement, @NotNull final List<PsiReference> references, final boolean soft) {

  final TextRange range = ElementManipulators.getValueTextRange(psiElement);
  final String elementText = psiElement.getText();
  final int anchorOffset = elementText.indexOf('#');
  if (anchorOffset == -1) {
    return false;
  }
  final boolean dynamic = isDynamic(psiElement, anchorOffset + 1, elementText);
  if (dynamic) {
    return false;
  }

  FileReference fileReference = null;
  if (range.getStartOffset() != anchorOffset) {
    fileReference = findFileReference(references);
    if (fileReference == null || fileReference.resolve() == null) {
      return false;
    }
  }
  final int pos = elementText.indexOf('?', anchorOffset);
  final String anchor;
  try {
    int endIndex = pos != -1 ? pos : range.getEndOffset();
    if (endIndex <= anchorOffset) {
      endIndex = anchorOffset + 1;
    }
    anchor = elementText.substring(anchorOffset + 1, endIndex);
  }
  catch (StringIndexOutOfBoundsException e) {      
    throw new RuntimeException(elementText, e);
  }
  final AnchorReferenceImpl anchorReference = new AnchorReferenceImpl(anchor, fileReference, psiElement, anchorOffset + 1, soft);
  references.add(anchorReference);
  return false;
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:38,代码来源:AnchorPathReferenceProvider.java


注:本文中的com.intellij.psi.ElementManipulators类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。