use of org.sonar.plugins.java.api.tree.SyntaxToken in project sonar-java by SonarSource.
the class LambdaOptionalParenthesisCheck method visitNode.
@Override
public void visitNode(Tree tree) {
LambdaExpressionTree let = (LambdaExpressionTree) tree;
SyntaxToken openParenToken = let.openParenToken();
if (openParenToken != null && let.parameters().size() == 1) {
VariableTree param = let.parameters().get(0);
String identifier = param.simpleName().name();
if (param.type().is(Tree.Kind.INFERED_TYPE)) {
reportIssue(openParenToken, "Remove the parentheses around the \"" + identifier + "\" parameter" + context.getJavaVersion().java8CompatibilityMessage());
}
}
}
use of org.sonar.plugins.java.api.tree.SyntaxToken in project sonar-java by SonarSource.
the class MethodInvocationTreeImpl method firstToken.
@Override
public SyntaxToken firstToken() {
if (typeArguments() != null && methodSelect.is(Tree.Kind.MEMBER_SELECT)) {
ExpressionTree expression = ((MemberSelectExpressionTree) methodSelect).expression();
SyntaxToken firstToken = expression.firstToken();
if (firstToken != null) {
return firstToken;
}
}
return super.firstToken();
}
use of org.sonar.plugins.java.api.tree.SyntaxToken in project sonar-java by SonarSource.
the class TryStatementTreeImpl method filterVariableTreeResources.
private static ListTree filterVariableTreeResources(ResourceListTreeImpl resources) {
ImmutableList.Builder<Tree> filteredResources = ImmutableList.builder();
ImmutableList.Builder<SyntaxToken> filteredSeparators = ImmutableList.builder();
Iterator<SyntaxToken> separators = resources.separators().iterator();
for (Tree resource : resources) {
SyntaxToken separator = null;
if (separators.hasNext()) {
separator = separators.next();
}
if (resource.is(Kind.VARIABLE)) {
filteredResources.add(resource);
if (separator != null) {
filteredSeparators.add(separator);
}
}
}
return new ResourceListTreeImpl(filteredResources.build(), filteredSeparators.build());
}
use of org.sonar.plugins.java.api.tree.SyntaxToken in project sonar-java by SonarSource.
the class ReassignmentFinder method isBefore.
private static int isBefore(Tree t1, Tree t2) {
SyntaxToken firstTokenT1 = t1.firstToken();
SyntaxToken firstTokenT2 = t2.firstToken();
int line = Integer.compare(firstTokenT1.line(), firstTokenT2.line());
return line != 0 ? line : Integer.compare(firstTokenT1.column(), firstTokenT2.column());
}
use of org.sonar.plugins.java.api.tree.SyntaxToken in project sonar-java by SonarSource.
the class ReassignmentFinder method getClosestReassignmentOrDeclarationExpression.
@CheckForNull
public static ExpressionTree getClosestReassignmentOrDeclarationExpression(Tree startingPoint, Symbol referenceSymbol) {
Tree result = referenceSymbol.declaration();
List<IdentifierTree> usages = referenceSymbol.usages();
if (usages.size() != 1) {
List<AssignmentExpressionTree> reassignments = getReassignments(referenceSymbol.owner().declaration(), usages);
SyntaxToken startPointToken = startingPoint.firstToken();
Tree lastReassignment = getClosestReassignment(startPointToken, reassignments);
if (lastReassignment != null) {
result = lastReassignment;
}
}
ExpressionTree initializerOrExpression = getInitializerOrExpression(result);
if (initializerOrExpression == startingPoint) {
return getClosestReassignmentOrDeclarationExpression(result, referenceSymbol);
}
return initializerOrExpression;
}
Aggregations