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


Java TreeUtil.nextLeaf方法代码示例

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


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

示例1: 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

示例2: 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

示例3: 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

示例4: _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

示例5: _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

示例6: getMatchingLength

import com.intellij.psi.impl.source.tree.TreeUtil; //导入方法依赖的package包/类
private static int getMatchingLength(@Nonnull FileElement treeElement, @Nonnull 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:consulo,项目名称:consulo,代码行数:23,代码来源:ChangedPsiRangeUtil.java

示例7: replaceChild

import com.intellij.psi.impl.source.tree.TreeUtil; //导入方法依赖的package包/类
public static void replaceChild(ASTNode parent, @NotNull ASTNode oldChild, @NotNull ASTNode newChild) {
  saveWhitespacesInfo(oldChild);
  saveWhitespacesInfo(newChild);
  checkForOuters(oldChild);
  checkForOuters(newChild);

  LeafElement oldFirst = TreeUtil.findFirstLeaf(oldChild);

  parent.replaceChild(oldChild, newChild);
  final LeafElement firstLeaf = TreeUtil.findFirstLeaf(newChild);
  final ASTNode prevToken = TreeUtil.prevLeaf(newChild);
  if (firstLeaf != null) {
    final ASTNode nextLeaf = TreeUtil.nextLeaf(newChild);
    makePlaceHolderBetweenTokens(prevToken, firstLeaf, isFormattingRequired(prevToken, newChild), false);
    if (nextLeaf != null && !CharArrayUtil.containLineBreaks(nextLeaf.getText())) {
      makePlaceHolderBetweenTokens(TreeUtil.prevLeaf(nextLeaf), nextLeaf, false, false);
    }
  }
  else {
    if (oldFirst != null && prevToken == null) {
      ASTNode whitespaceNode = newChild.getTreeNext();
      if (whitespaceNode != null && whitespaceNode.getElementType() == TokenType.WHITE_SPACE) {
        // Replacing non-empty prefix to empty shall remove whitespace
        parent.removeChild(whitespaceNode);
      }
    }

    makePlaceHolderBetweenTokens(prevToken, TreeUtil.nextLeaf(newChild), isFormattingRequired(prevToken, newChild), false);
  }
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:31,代码来源:CodeEditUtil.java

示例8: findAfterCaret

import com.intellij.psi.impl.source.tree.TreeUtil; //导入方法依赖的package包/类
private static PsiElement findAfterCaret(ASTNode atCaret, Class<? extends PsiElement>... classes) {
  while (atCaret != null) {
    if (atCaret.getElementType() != TokenType.WHITE_SPACE) {
      return getNonStrictParentOfType(atCaret.getPsi(), classes);
    }
    atCaret = TreeUtil.nextLeaf(atCaret);
  }
  return null;
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:10,代码来源:PythonEnterHandler.java

示例9: replaceChild

import com.intellij.psi.impl.source.tree.TreeUtil; //导入方法依赖的package包/类
public static void replaceChild(ASTNode parent, @Nonnull ASTNode oldChild, @Nonnull ASTNode newChild) {
  saveWhitespacesInfo(oldChild);
  saveWhitespacesInfo(newChild);
  checkForOuters(oldChild);
  checkForOuters(newChild);

  LeafElement oldFirst = TreeUtil.findFirstLeaf(oldChild);

  parent.replaceChild(oldChild, newChild);
  final LeafElement firstLeaf = TreeUtil.findFirstLeaf(newChild);
  final ASTNode prevToken = TreeUtil.prevLeaf(newChild);
  if (firstLeaf != null) {
    final ASTNode nextLeaf = TreeUtil.nextLeaf(newChild);
    makePlaceHolderBetweenTokens(prevToken, firstLeaf, isFormattingRequired(prevToken, newChild), false);
    if (nextLeaf != null && !CharArrayUtil.containLineBreaks(nextLeaf.getText())) {
      makePlaceHolderBetweenTokens(TreeUtil.prevLeaf(nextLeaf), nextLeaf, false, false);
    }
  }
  else {
    if (oldFirst != null && prevToken == null) {
      ASTNode whitespaceNode = newChild.getTreeNext();
      if (whitespaceNode != null && whitespaceNode.getElementType() == TokenType.WHITE_SPACE) {
        // Replacing non-empty prefix to empty shall remove whitespace
        parent.removeChild(whitespaceNode);
      }
    }

    makePlaceHolderBetweenTokens(prevToken, TreeUtil.nextLeaf(newChild), isFormattingRequired(prevToken, newChild), false);
  }
}
 
开发者ID:consulo,项目名称:consulo,代码行数:31,代码来源:CodeEditUtil.java

示例10: 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:consulo,项目名称:consulo-java,代码行数:35,代码来源:HighlightNamesUtil.java

示例11: nextLeaf

import com.intellij.psi.impl.source.tree.TreeUtil; //导入方法依赖的package包/类
@Nullable
@Override
public ASTNode nextLeaf(@NotNull ASTNode current) {
  return TreeUtil.nextLeaf(current);
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:6,代码来源:TabPostFormatProcessor.java

示例12: checkFile

import com.intellij.psi.impl.source.tree.TreeUtil; //导入方法依赖的package包/类
@Nullable
@Override
public ProblemDescriptor[] checkFile(@NotNull PsiFile file, @NotNull final InspectionManager manager, final boolean isOnTheFly) {

  final List<ProblemDescriptor> result = new ArrayList<ProblemDescriptor>();
  final ProblemReporter reporter = new ProblemReporter() {
    @Override
    public void reportProblem(ASTNode node, String message) {
      result.add( manager.createProblemDescriptor( node.getPsi(),
                                                   message,
                                                   (LocalQuickFix)null,
                                                   ProblemHighlightType.ERROR,
                                                   isOnTheFly));
    }
  };

  FileASTNode node1 = file.getNode();
  LeafElement firstLeaf = TreeUtil.findFirstLeaf(node1);

  Stack<List<ASTNode>> levels = new Stack<List<ASTNode>>();
  List<ASTNode> nodes = new ArrayList<ASTNode>();
  // Push the root node, just in case there is no #if to start it off.
  levels.push(nodes);

  ASTNode leaf = firstLeaf;
  while (leaf != null) {
    IElementType leafElementType = leaf.getElementType();

    if (leafElementType.equals(HaxeTokenTypes.PPIF)) {
      nodes = new ArrayList<ASTNode>();
      levels.push(nodes);
      nodes.add(leaf);
    }
    else if (leafElementType.equals(HaxeTokenTypes.PPEND)) {
      nodes.add(leaf);
      // Leave the base level in place, even if there are extra ends.
      if (levels.size() > 1) {
        validateLevel(nodes, reporter);
        levels.pop();
        nodes = levels.peek();
      }
    }
    else if (leafElementType.equals(HaxeTokenTypes.PPELSEIF)) {
      nodes.add(leaf);
    }
    else if (leafElementType.equals(HaxeTokenTypes.PPELSE)) {
      nodes.add(leaf);
    }
    leaf = TreeUtil.nextLeaf(leaf);
  }

  // Any levels that are still left need to be validated.
  for (List<ASTNode> level : levels) {
    validateLevel(level, reporter);
  }

  return ArrayUtil.toObjectArray(result, ProblemDescriptor.class);
}
 
开发者ID:HaxeFoundation,项目名称:intellij-haxe,代码行数:59,代码来源:HaxePreprocessorInspection.java


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