public static AnalyzerMessage.TextSpan textSpanFor(Tree syntaxNode) { SyntaxToken firstSyntaxToken = getNonEmptyTree(syntaxNode).firstToken(); SyntaxToken lastSyntaxToken = getNonEmptyTree(syntaxNode).lastToken(); return textSpanBetween(firstSyntaxToken, lastSyntaxToken); }
public static AnalyzerMessage.TextSpan textSpanBetween(Tree startTree, Tree endTree) { SyntaxToken firstSyntaxToken = getNonEmptyTree(startTree).firstToken(); SyntaxToken lastSyntaxToken = getNonEmptyTree(endTree).lastToken(); return textSpanBetween(firstSyntaxToken, lastSyntaxToken); }
public static AnalyzerMessage.TextSpan textSpanBetween(Tree startTree, Tree endTree) { SyntaxToken firstSyntaxToken = getNonEmptyTree(startTree).firstToken(); SyntaxToken lastSyntaxToken = getNonEmptyTree(endTree).lastToken(); return textSpanBetween(firstSyntaxToken, lastSyntaxToken); }
public static AnalyzerMessage.TextSpan textSpanFor(Tree syntaxNode) { SyntaxToken firstSyntaxToken = getNonEmptyTree(syntaxNode).firstToken(); SyntaxToken lastSyntaxToken = getNonEmptyTree(syntaxNode).lastToken(); return textSpanBetween(firstSyntaxToken, lastSyntaxToken); }
/** * It's possible that tree has no source code to match, thus no tokens. For example {@code InferedTypeTree}. * In this case we will report on a parent tree. * @return tree itself if it's not empty or its first non-empty ancestor */ private static Tree getNonEmptyTree(Tree tree) { if (tree.firstToken() != null) { return tree; } Tree parent = tree.parent(); if (parent != null) { return getNonEmptyTree(parent); } throw new IllegalStateException("Trying to report on an empty tree with no parent"); }
/** * It's possible that tree has no source code to match, thus no tokens. For example {@code InferedTypeTree}. * In this case we will report on a parent tree. * @return tree itself if it's not empty or its first non-empty ancestor */ private static Tree getNonEmptyTree(Tree tree) { if (tree.firstToken() != null) { return tree; } Tree parent = tree.parent(); if (parent != null) { return getNonEmptyTree(parent); } throw new IllegalStateException("Trying to report on an empty tree with no parent"); }