本文整理汇总了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();
}
示例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;
}
示例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;
}
示例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");
}
示例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");
}
示例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;
}
示例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);
}
}
示例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;
}
示例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);
}
}
示例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();
}
示例11: nextLeaf
import com.intellij.psi.impl.source.tree.TreeUtil; //导入方法依赖的package包/类
@Nullable
@Override
public ASTNode nextLeaf(@NotNull ASTNode current) {
return TreeUtil.nextLeaf(current);
}
示例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);
}