Java Code Examples for org.sonar.plugins.java.api.tree.ExpressionTree#is()
The following examples show how to use
org.sonar.plugins.java.api.tree.ExpressionTree#is() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: UnusedMethodParameterCheck.java From vjtools with Apache License 2.0 | 5 votes |
@Override public void visitMethodInvocation(MethodInvocationTree tree) { ExpressionTree methodSelect = tree.methodSelect(); if (!methodSelect.is(Tree.Kind.IDENTIFIER)) { // not interested in simple method invocations, we are targeting usage of method parameters scan(methodSelect); } scan(tree.typeArguments()); scan(tree.arguments()); }
Example 2
Source File: UnusedPrivateFieldCheck.java From vjtools with Apache License 2.0 | 5 votes |
private void addAssignment(ExpressionTree tree) { ExpressionTree variable = ExpressionUtils.skipParentheses(tree); if (variable.is(Tree.Kind.IDENTIFIER)) { addAssignment((IdentifierTree) variable); } else if (variable.is(Tree.Kind.MEMBER_SELECT)) { addAssignment(((MemberSelectExpressionTree) variable).identifier()); } }
Example 3
Source File: UnusedMethodParameterCheck.java From vjtools with Apache License 2.0 | 5 votes |
@Override public void visitMethodInvocation(MethodInvocationTree tree) { ExpressionTree methodSelect = tree.methodSelect(); if (!methodSelect.is(Tree.Kind.IDENTIFIER)) { // not interested in simple method invocations, we are targeting usage of method parameters scan(methodSelect); } scan(tree.typeArguments()); scan(tree.arguments()); }
Example 4
Source File: UnusedPrivateFieldCheck.java From vjtools with Apache License 2.0 | 5 votes |
private void addAssignment(ExpressionTree tree) { ExpressionTree variable = ExpressionUtils.skipParentheses(tree); if (variable.is(Tree.Kind.IDENTIFIER)) { addAssignment((IdentifierTree) variable); } else if (variable.is(Tree.Kind.MEMBER_SELECT)) { addAssignment(((MemberSelectExpressionTree) variable).identifier()); } }
Example 5
Source File: DefaultInjectionStrategyAnnotationCheck.java From AEM-Rules-for-SonarQube with Apache License 2.0 | 5 votes |
private boolean isOptionalDefaultValue(Arguments arguments) { boolean optionalIsDefaultValue = false; for (ExpressionTree argument : arguments) { if (argument.is(Tree.Kind.ASSIGNMENT)) { AssignmentExpressionTree assignment = (AssignmentExpressionTree) argument; if (isDefaultInjectionStrategyAssignment(assignment)) { optionalIsDefaultValue = isOptionalStrategyValue(assignment); } } } return optionalIsDefaultValue; }
Example 6
Source File: PreferSlingServletAnnotation.java From AEM-Rules-for-SonarQube with Apache License 2.0 | 5 votes |
private boolean isAssignmentToName(ExpressionTree expression) { boolean result = false; if (expression.is(Tree.Kind.ASSIGNMENT)) { AssignmentExpressionTree assignment = (AssignmentExpressionTree) expression; result = NAME.equals(((IdentifierTree) assignment.variable()).name()); } return result; }
Example 7
Source File: AbstractSmellCheck.java From qualinsight-plugins-sonarqube-smell with GNU Lesser General Public License v3.0 | 5 votes |
private void handleSmellAnnotation(final AnnotationTree annotationTree) { String message = ""; Integer minutes = 0; SmellType type = null; final Arguments arguments = annotationTree.arguments(); for (final ExpressionTree expressionTree : arguments) { if (expressionTree.is(Tree.Kind.ASSIGNMENT)) { final AssignmentExpressionTree aet = (AssignmentExpressionTree) expressionTree; final String variable = ((IdentifierTree) aet.variable()).name(); switch (variable) { case "minutes": minutes += Integer.valueOf(((LiteralTree) aet.expression()).value()); LOGGER.debug("{} = {}", variable, minutes); break; case "reason": message = extractMessage(aet.expression()); LOGGER.debug("{} = {}", variable, message); break; case "type": type = SmellType.valueOf(((MemberSelectExpressionTree) aet.expression()).identifier() .name()); break; default: break; } } } if (smellType().equals(type)) { final Matcher matcher = PATTERN.matcher(message); if (matcher.matches()) { message = matcher.group(1); } reportIssue(annotationTree, message, new ArrayList<JavaFileScannerContext.Location>(), minutes); } }
Example 8
Source File: UnusedPrivateFieldCheck.java From vjtools with Apache License 2.0 | 4 votes |
private void collectAssignment(ExpressionTree expressionTree) { if (expressionTree.is(ASSIGNMENT_KINDS)) { addAssignment(((AssignmentExpressionTree) expressionTree).variable()); } }
Example 9
Source File: UnusedPrivateFieldCheck.java From vjtools with Apache License 2.0 | 4 votes |
private void collectAssignment(ExpressionTree expressionTree) { if (expressionTree.is(ASSIGNMENT_KINDS)) { addAssignment(((AssignmentExpressionTree) expressionTree).variable()); } }