use of org.sonar.plugins.java.api.tree.SyntaxToken in project sonar-java by SonarSource.
the class SyntaxHighlighterVisitor method highlight.
private void highlight(Tree from, Tree to, TypeOfText typeOfText) {
SyntaxToken firstToken = from.firstToken();
SyntaxToken lastToken = to.lastToken();
highlighting.highlight(firstToken.line(), firstToken.column(), lastToken.line(), lastToken.column() + lastToken.text().length(), typeOfText);
}
use of org.sonar.plugins.java.api.tree.SyntaxToken in project sonar-java by SonarSource.
the class TreeFactory method newModuleName.
public ModuleNameTree newModuleName(InternalSyntaxToken firstIdentifier, Optional<List<Tuple<InternalSyntaxToken, InternalSyntaxToken>>> rest) {
List<IdentifierTree> identifiers = new ArrayList<>();
List<SyntaxToken> separators = new ArrayList<>();
identifiers.add(new IdentifierTreeImpl(firstIdentifier));
if (rest.isPresent()) {
for (Tuple<InternalSyntaxToken, InternalSyntaxToken> modulePart : rest.get()) {
separators.add(modulePart.first());
identifiers.add(new IdentifierTreeImpl(modulePart.second()));
}
}
return new ModuleNameTreeImpl(Collections.unmodifiableList(identifiers), Collections.unmodifiableList(separators));
}
use of org.sonar.plugins.java.api.tree.SyntaxToken in project sonar-java by SonarSource.
the class SubscriptionVisitor method visit.
private void visit(Tree tree) {
boolean isSubscribed = isSubscribed(tree);
boolean shouldVisitSyntaxToken = (visitToken || visitTrivia) && tree.is(Tree.Kind.TOKEN);
if (shouldVisitSyntaxToken) {
SyntaxToken syntaxToken = (SyntaxToken) tree;
if (visitToken) {
visitToken(syntaxToken);
}
if (visitTrivia) {
for (SyntaxTrivia syntaxTrivia : syntaxToken.trivias()) {
visitTrivia(syntaxTrivia);
}
}
} else if (isSubscribed) {
visitNode(tree);
}
visitChildren(tree);
if (!shouldVisitSyntaxToken && isSubscribed) {
leaveNode(tree);
}
}
use of org.sonar.plugins.java.api.tree.SyntaxToken in project sonar-java by SonarSource.
the class AnyRuleIssueFilterTest method invalid_tree_does_not_exclude_lines.
@Test
public void invalid_tree_does_not_exclude_lines() {
// by default, any issue oin line 7 is accepted
assertThatIssueWillBeAccepted(7).isTrue();
Tree mockTree = mock(Tree.class);
// without first nor last token, line can not be excluded
filter.excludeLines(mockTree);
assertThatIssueWillBeAccepted(7).isTrue();
SyntaxToken mockFirstToken = mock(SyntaxToken.class);
when(mockFirstToken.line()).thenReturn(7);
when(mockTree.firstToken()).thenReturn(mockFirstToken);
// without last token, line can not be excluded
filter.excludeLines(mockTree);
assertThatIssueWillBeAccepted(7).isTrue();
SyntaxToken mockLastToken = mock(SyntaxToken.class);
when(mockLastToken.line()).thenReturn(7);
when(mockTree.lastToken()).thenReturn(mockLastToken);
// with first and last token, line 7 can be excluded
filter.excludeLines(mockTree);
assertThatIssueWillBeAccepted(7).isFalse();
}
use of org.sonar.plugins.java.api.tree.SyntaxToken in project sonar-java by SonarSource.
the class AnalyzerMessage method textSpanFor.
public static AnalyzerMessage.TextSpan textSpanFor(Tree syntaxNode) {
SyntaxToken firstSyntaxToken = syntaxNode.firstToken();
SyntaxToken lastSyntaxToken = syntaxNode.lastToken();
return textSpanBetween(firstSyntaxToken, lastSyntaxToken);
}
Aggregations