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


Java TreeUtil类代码示例

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


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

示例1: suggestKeywords

import com.intellij.psi.impl.source.tree.TreeUtil; //导入依赖的package包/类
private static Collection<String> suggestKeywords(PsiElement position) {
    TextRange posRange = position.getTextRange();
    CupFile posFile = (CupFile) position.getContainingFile();
    TextRange range = new TextRange(0, posRange.getStartOffset());
    String text = range.isEmpty() ? CompletionInitializationContext.DUMMY_IDENTIFIER : range.substring(posFile.getText());
    int completionOffset = posRange.getStartOffset() - range.getStartOffset(); // = posRange.getStartOffset() ...

    PsiFile file = PsiFileFactory.getInstance(posFile.getProject()).createFileFromText("a.cup", CupLanguage.INSTANCE, text, true, false);
    GeneratedParserUtilBase.CompletionState state = new GeneratedParserUtilBase.CompletionState(completionOffset) {
        @Nullable
        @Override
        public String convertItem(Object o) {
            if (o == CupTypes.IDENTIFIER) {
                return null;
            }
            return o.toString();
        }
    };
    file.putUserData(GeneratedParserUtilBase.COMPLETION_STATE_KEY, state);
    TreeUtil.ensureParsed(file.getNode());

    return state.items;
}
 
开发者ID:Tirke,项目名称:cup-plugin,代码行数:24,代码来源:CupCompletionContributor.java

示例2: findChildByRole

import com.intellij.psi.impl.source.tree.TreeUtil; //导入依赖的package包/类
@Override
public ASTNode findChildByRole(int role) {
  LOG.assertTrue(ChildRole.isUnique(role));
  switch(role){
    default:
      return null;

    case ChildRole.BREAK_KEYWORD:
      return findChildByType(BREAK_KEYWORD);

    case ChildRole.LABEL:
      return findChildByType(IDENTIFIER);

    case ChildRole.CLOSING_SEMICOLON:
      return TreeUtil.findChildBackward(this, SEMICOLON);
  }
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:18,代码来源:PsiBreakStatementImpl.java

示例3: findChildByRole

import com.intellij.psi.impl.source.tree.TreeUtil; //导入依赖的package包/类
@Override
public ASTNode findChildByRole(int role) {
  LOG.assertTrue(ChildRole.isUnique(role));
  switch(role){
    default:
      return null;

    case ChildRole.RETURN_KEYWORD:
      return findChildByType(RETURN_KEYWORD);

    case ChildRole.RETURN_VALUE:
      return findChildByType(EXPRESSION_BIT_SET);

    case ChildRole.CLOSING_SEMICOLON:
      return TreeUtil.findChildBackward(this, SEMICOLON);
  }
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:18,代码来源:PsiReturnStatementImpl.java

示例4: findChildByRole

import com.intellij.psi.impl.source.tree.TreeUtil; //导入依赖的package包/类
@Override
public ASTNode findChildByRole(int role){
  LOG.assertTrue(ChildRole.isUnique(role));
  switch(role){
    default:
      return null;

    case ChildRole.IMPORT_KEYWORD:
      return getFirstChildNode();

    case ChildRole.IMPORT_ON_DEMAND_DOT:
      return findChildByType(JavaTokenType.DOT);

    case ChildRole.IMPORT_ON_DEMAND_ASTERISK:
      return findChildByType(JavaTokenType.ASTERISK);

    case ChildRole.CLOSING_SEMICOLON:
      return TreeUtil.findChildBackward(this, JavaTokenType.SEMICOLON);
  }
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:21,代码来源:ImportStatementBaseElement.java

示例5: findChildByRole

import com.intellij.psi.impl.source.tree.TreeUtil; //导入依赖的package包/类
@Override
public ASTNode findChildByRole(int role) {
  LOG.assertTrue(ChildRole.isUnique(role));
  switch(role){
    default:
      return null;

    case ChildRole.THROW_KEYWORD:
      return findChildByType(THROW_KEYWORD);

    case ChildRole.EXCEPTION:
      return findChildByType(EXPRESSION_BIT_SET);

    case ChildRole.CLOSING_SEMICOLON:
      return TreeUtil.findChildBackward(this, SEMICOLON);
  }
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:18,代码来源:PsiThrowStatementImpl.java

示例6: stripAnnotationsFromModifierList

import com.intellij.psi.impl.source.tree.TreeUtil; //导入依赖的package包/类
private static int stripAnnotationsFromModifierList(@NotNull PsiElement element) {
  TextRange textRange = element.getTextRange();
  if (textRange == null) return 0;
  PsiAnnotation lastAnnotation = null;
  for (PsiElement child : element.getChildren()) {
    if (child instanceof PsiAnnotation) lastAnnotation = (PsiAnnotation)child;
  }
  if (lastAnnotation == null) {
    return textRange.getStartOffset();
  }
  ASTNode node = lastAnnotation.getNode();
  if (node != null) {
    do {
      node = TreeUtil.nextLeaf(node);
    }
    while (node != null && ElementType.JAVA_COMMENT_OR_WHITESPACE_BIT_SET.contains(node.getElementType()));
  }
  if (node != null) return node.getTextRange().getStartOffset();
  return textRange.getStartOffset();
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:21,代码来源:HighlightNamesUtil.java

示例7: getContainingFileByTree

import com.intellij.psi.impl.source.tree.TreeUtil; //导入依赖的package包/类
@Nullable
private static PsiFile getContainingFileByTree(@NotNull final PsiElement changeScope) {
  // there could be pseudo physical trees (JSPX/JSP/etc.) which must not translate
  // any changes to document and not to fire any PSI events
  final PsiFile psiFile;
  final ASTNode node = changeScope.getNode();
  if (node == null) {
    psiFile = changeScope.getContainingFile();
  }
  else {
    final FileElement fileElement = TreeUtil.getFileElement((TreeElement)node);
    // assert fileElement != null : "Can't find file element for node: " + node;
    // Hack. the containing tree can be invalidated if updating supplementary trees like HTML in JSP.
    if (fileElement == null) return null;

    psiFile = (PsiFile)fileElement.getPsi();
  }
  return psiFile.getNode() != null ? psiFile : null;
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:20,代码来源:PomModelImpl.java

示例8: getMatchingLength

import com.intellij.psi.impl.source.tree.TreeUtil; //导入依赖的package包/类
private static int getMatchingLength(@NotNull FileElement treeElement, @NotNull CharSequence text, boolean fromStart) {
  int patternIndex = fromStart ? 0 : text.length() - 1;
  int finalPatternIndex = fromStart ? text.length() - 1 : 0;
  int direction = fromStart ? 1 : -1;
  ASTNode leaf = fromStart ? TreeUtil.findFirstLeaf(treeElement, false) : TreeUtil.findLastLeaf(treeElement, false);
  int result = 0;
  while (leaf != null && (fromStart ? patternIndex <= finalPatternIndex : patternIndex >= finalPatternIndex)) {
    if (!(leaf instanceof ForeignLeafPsiElement)) {
      CharSequence chars = leaf.getChars();
      if (chars.length() > 0) {
        int matchingLength = getLeafMatchingLength(chars, text, patternIndex, finalPatternIndex, direction);
        result += matchingLength;
        if (matchingLength != chars.length()) {
          break;
        }
        patternIndex += (fromStart ? matchingLength : -matchingLength);
      }
    }
    leaf = fromStart ? TreeUtil.nextLeaf(leaf, false) : TreeUtil.prevLeaf(leaf, false);
  }
  return result;
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:23,代码来源:DocumentCommitProcessor.java

示例9: markToReformatBeforeOrInsertWhitespace

import com.intellij.psi.impl.source.tree.TreeUtil; //导入依赖的package包/类
private static void markToReformatBeforeOrInsertWhitespace(final ASTNode left, @NotNull final ASTNode right) {
  final Language leftLang = left != null ? PsiUtilCore.getNotAnyLanguage(left) : null;
  final Language rightLang = PsiUtilCore.getNotAnyLanguage(right);

  ASTNode generatedWhitespace = null;
  if (leftLang != null && leftLang.isKindOf(rightLang)) {
    generatedWhitespace = LanguageTokenSeparatorGenerators.INSTANCE.forLanguage(leftLang).generateWhitespaceBetweenTokens(left, right);
  }
  else if (rightLang.isKindOf(leftLang)) {
    generatedWhitespace = LanguageTokenSeparatorGenerators.INSTANCE.forLanguage(rightLang).generateWhitespaceBetweenTokens(left, right);
  }

  if (generatedWhitespace != null) {
    final TreeUtil.CommonParentState parentState = new TreeUtil.CommonParentState();
    TreeUtil.prevLeaf((TreeElement)right, parentState);
    parentState.nextLeafBranchStart.getTreeParent().addChild(generatedWhitespace, parentState.nextLeafBranchStart);
  }
  else {
    markToReformatBefore(right, true);
  }
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:22,代码来源:CodeEditUtil.java

示例10: hasLineBreakAfterIgnoringComments

import com.intellij.psi.impl.source.tree.TreeUtil; //导入依赖的package包/类
private static boolean hasLineBreakAfterIgnoringComments(@NotNull ASTNode node) {
  for (ASTNode next = TreeUtil.nextLeaf(node); next != null; next = TreeUtil.nextLeaf(next)) {
    if (isWhitespace(next)) {
      if (next.textContains('\n')) {
        return true;
      }
    }
    else if (next.getElementType() == PyTokenTypes.END_OF_LINE_COMMENT) {
      return true;
    }
    else {
      break;
    }
  }
  return false;
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:17,代码来源:PyBlock.java

示例11: calcBaseIndent

import com.intellij.psi.impl.source.tree.TreeUtil; //导入依赖的package包/类
public static int calcBaseIndent(ASTNode chameleon) {
  final ASTNode prevLeaf = TreeUtil.prevLeaf(chameleon, true);
  if (prevLeaf == null) {
    return 0;
  }

  final CharSequence text = prevLeaf.getChars();
  int offset = text.length();

  int answer = 0;

  while (--offset > 0) {
    final char c = text.charAt(offset);
    if (c == '\n') {
      break;
    }
    if (c != ' ' && c != '\t') {
      answer = 0;
      break;
    }
    answer++;
  }
  return answer;
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:25,代码来源:EmbeddingUtil.java

示例12: _testPerformance1

import com.intellij.psi.impl.source.tree.TreeUtil; //导入依赖的package包/类
public void _testPerformance1() throws Exception {
  final String text = loadFile("pallada.xml");
  long time = System.currentTimeMillis();
  final PsiFile file = createFile("test.xml", text);
  transformAllChildren(file.getNode());
  System.out.println("Old parsing took " + (System.currentTimeMillis() - time) + "ms");
  int index = 0;
  while (index++ < 10) {
    newParsing(text);
  }
  LeafElement firstLeaf = TreeUtil.findFirstLeaf(file.getNode());
  index = 0;
  do {
    index++;
  }
  while ((firstLeaf = TreeUtil.nextLeaf(firstLeaf, null)) != null);
  System.out.println("For " + index + " lexems");
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:19,代码来源:XmlParsingTest.java

示例13: _testPerformance2

import com.intellij.psi.impl.source.tree.TreeUtil; //导入依赖的package包/类
public void _testPerformance2() throws Exception {
  final String text = loadFile("performance2.xml");
  long time = System.currentTimeMillis();
  final PsiFile file = createFile("test.xml", text);
  transformAllChildren(file.getNode());
  System.out.println("Old parsing took " + (System.currentTimeMillis() - time) + "ms");
  int index = 0;
  while (index++ < 10) {
    newParsing(text);
  }
  LeafElement firstLeaf = TreeUtil.findFirstLeaf(file.getNode());
  index = 0;
  do {
    index++;
  }
  while ((firstLeaf = TreeUtil.nextLeaf(firstLeaf, null)) != null);
  System.out.println("For " + index + " lexems");
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:19,代码来源:XmlParsingTest.java

示例14: deleteChildInternal

import com.intellij.psi.impl.source.tree.TreeUtil; //导入依赖的package包/类
@Override
public void deleteChildInternal(@NotNull ASTNode child) {
  PsiElement element = child.getPsi();
  if (element instanceof GrExpression || element instanceof GrNamedArgument) {
    ASTNode prev = TreeUtil.skipElementsBack(child.getTreePrev(), TokenSets.WHITE_SPACES_OR_COMMENTS);
    if (prev != null && prev.getElementType() == GroovyTokenTypes.mCOMMA) {
      final ASTNode pprev = prev.getTreePrev();
      if (pprev != null && PsiImplUtil.isWhiteSpaceOrNls(pprev)) {
        super.deleteChildInternal(pprev);
      }
      super.deleteChildInternal(prev);
    }
    else {
      ASTNode next = TreeUtil.skipElements(child.getTreeNext(), TokenSets.WHITE_SPACES_OR_COMMENTS);
      if (next != null && next.getElementType() == GroovyTokenTypes.mCOMMA) {
        final ASTNode nnext = next.getTreeNext();
        if (nnext != null && PsiImplUtil.isWhiteSpaceOrNls(nnext)) {
          super.deleteChildInternal(nnext);
        }
        super.deleteChildInternal(next);
      }
    }
  }
  super.deleteChildInternal(child);
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:26,代码来源:GrArgumentListImpl.java

示例15: deleteChildInternal

import com.intellij.psi.impl.source.tree.TreeUtil; //导入依赖的package包/类
public void deleteChildInternal(@NotNull ASTNode child) {
  PsiElement element = child.getPsi();
  if (element instanceof GrExpression || element instanceof GrNamedArgument) {
    ASTNode prev = TreeUtil.skipElementsBack(child.getTreePrev(), TokenSets.WHITE_SPACES_OR_COMMENTS);
    if (prev != null && prev.getElementType() == mCOMMA) {
      final ASTNode pprev = prev.getTreePrev();
      if (pprev != null && TokenSets.WHITE_SPACES_SET.contains(pprev.getElementType())) {
        super.deleteChildInternal(pprev);
      }
      super.deleteChildInternal(prev);
    }
    else {
      ASTNode next = TreeUtil.skipElements(child.getTreeNext(), TokenSets.WHITE_SPACES_OR_COMMENTS);
      if (next != null && next.getElementType() == mCOMMA) {
        final ASTNode nnext = next.getTreeNext();
        if (nnext != null && TokenSets.WHITE_SPACES_SET.contains(nnext.getElementType())) {
          super.deleteChildInternal(nnext);
        }
        super.deleteChildInternal(next);
      }
    }
  }
  super.deleteChildInternal(child);
}
 
开发者ID:lshain-android-source,项目名称:tools-idea,代码行数:25,代码来源:GrArgumentListImpl.java


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