org.sonar.plugins.java.api.tree.MemberSelectExpressionTree Java Examples
The following examples show how to use
org.sonar.plugins.java.api.tree.MemberSelectExpressionTree.
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: ImplicitWaitCheck.java From sonar-webdriver-plugin with MIT License | 6 votes |
@Override public void visitMethodInvocation(MethodInvocationTree tree) { JavaFileScannerContext context = getContext(); if (!tree.methodSelect().is(Tree.Kind.IDENTIFIER)) { MemberSelectExpressionTree memberSelectExpressionTree = ((MemberSelectExpressionTree) tree.methodSelect()); String methodName = memberSelectExpressionTree.identifier().name(); String fullyQualifiedNameOfExpression = memberSelectExpressionTree.expression().symbolType() .fullyQualifiedName(); if (IMPLICITLY_WAIT_METHOD_NAME.equals(methodName) && isPartOfWebDriverPackage(fullyQualifiedNameOfExpression)) { context.reportIssue(this, tree, "Avoid using implicit wait, use explicit wait instead"); } } }
Example #2
Source File: HardCodedSleepCheck.java From sonar-webdriver-plugin with MIT License | 6 votes |
@Override public void visitMethodInvocation(MethodInvocationTree tree) { JavaFileScannerContext context = getContext(); if (!tree.methodSelect().is(Tree.Kind.IDENTIFIER)) { MemberSelectExpressionTree memberSelectExpressionTree = ((MemberSelectExpressionTree) tree.methodSelect()); String methodName = memberSelectExpressionTree.identifier().name(); String fullyQualifiedNameOfExpression = memberSelectExpressionTree.expression().symbolType() .fullyQualifiedName(); if (SLEEP_METHOD_NAME.equals(methodName) && fullyQualifiedNameOfExpression.equals(THREAD)) { context.reportIssue(this, tree, "Avoid using hard coded sleeps, use explicit wait instead"); } } }
Example #3
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 #4
Source File: MethodMatcher.java From AEM-Rules-for-SonarQube with Apache License 2.0 | 5 votes |
private static IdentifierTree getIdentifier(MethodInvocationTree methodInvocationTree) { // methodSelect can only be the Tree.Kind.IDENTIFIER or the Tree.Kind.MEMBER_SELECT if (methodInvocationTree.methodSelect().is(Tree.Kind.IDENTIFIER)) { return (IdentifierTree) methodInvocationTree.methodSelect(); } return ((MemberSelectExpressionTree) methodInvocationTree.methodSelect()).identifier(); }
Example #5
Source File: ContentResourceShouldBeNullCheckedCheck.java From AEM-Rules-for-SonarQube with Apache License 2.0 | 5 votes |
private void chainedMethodsNullCheck(MethodInvocationTree tree) { if (tree.methodSelect() instanceof MemberSelectExpressionTree) { MemberSelectExpressionTree method = (MemberSelectExpressionTree) tree.methodSelect(); if (method.expression() instanceof MethodInvocationTree) { MethodInvocationTree invocation = (MethodInvocationTree) method.expression(); if (!invocation.symbol().isUnknown() && isPage(invocation.symbol().owner().type().fullyQualifiedName()) && isGetContentResourceUsedOnPage(invocation) && !returnOccurredInsideEqualNullCheck) { context.reportIssue(this, tree, RULE_MESSAGE); } } } }
Example #6
Source File: ModifiableValueMapUsageCheck.java From AEM-Rules-for-SonarQube with Apache License 2.0 | 5 votes |
private void checkIfMapVariableIsModified(List<IdentifierTree> usagesOfMVM) { for (IdentifierTree modifiableValueMapUsageIdentifier : usagesOfMVM) { Tree usageOfMVM = modifiableValueMapUsageIdentifier.parent(); if (usageOfMVM != null) { if (usageOfMVM.is(Tree.Kind.ARGUMENTS)) { visitMethodWithMVM(modifiableValueMapUsageIdentifier, usageOfMVM); } else if (usageOfMVM.is(Tree.Kind.MEMBER_SELECT) && isSomeoneCallingMutableMethodsOnMap((MemberSelectExpressionTree) usageOfMVM)) { isModified = true; break; } } } }
Example #7
Source File: CheckClosedVisitor.java From AEM-Rules-for-SonarQube with Apache License 2.0 | 5 votes |
@Override public void visitMemberSelectExpression(MemberSelectExpressionTree tree) { if (usages.contains(tree.expression())) { closed |= tree.identifier().name().equals(CLOSE_METHOD_NAME); } super.visitMemberSelectExpression(tree); }
Example #8
Source File: CheckLoggedOutVisitor.java From AEM-Rules-for-SonarQube with Apache License 2.0 | 5 votes |
@Override public void visitMemberSelectExpression(MemberSelectExpressionTree tree) { if (usages.contains(tree.expression())) { loggedOut |= tree.identifier().name().equals(LOG_OUT_METHOD_NAME); } super.visitMemberSelectExpression(tree); }
Example #9
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 #10
Source File: UnusedPrivateFieldCheck.java From vjtools with Apache License 2.0 | 5 votes |
private static String fullQualifiedName(Tree tree) { if (tree.is(Tree.Kind.IDENTIFIER)) { return ((IdentifierTree) tree).name(); } else if (tree.is(Tree.Kind.MEMBER_SELECT)) { MemberSelectExpressionTree m = (MemberSelectExpressionTree) tree; return fullQualifiedName(m.expression()) + "." + m.identifier().name(); } throw new UnsupportedOperationException(String.format("Kind/Class '%s' not supported", tree.getClass())); }
Example #11
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 #12
Source File: UnusedPrivateFieldCheck.java From vjtools with Apache License 2.0 | 5 votes |
private static String fullQualifiedName(Tree tree) { if (tree.is(Tree.Kind.IDENTIFIER)) { return ((IdentifierTree) tree).name(); } else if (tree.is(Tree.Kind.MEMBER_SELECT)) { MemberSelectExpressionTree m = (MemberSelectExpressionTree) tree; return fullQualifiedName(m.expression()) + "." + m.identifier().name(); } throw new UnsupportedOperationException(String.format("Kind/Class '%s' not supported", tree.getClass())); }
Example #13
Source File: CommonUtil.java From sonar-webdriver-plugin with MIT License | 5 votes |
private static IdentifierTree getIdentifier(MethodInvocationTree methodInvocationTree) { // methodSelect can only be Tree.Kind.IDENTIFIER or Tree.Kind.MEMBER_SELECT if (methodInvocationTree.methodSelect().is(Tree.Kind.IDENTIFIER)) { return (IdentifierTree) methodInvocationTree.methodSelect(); } return ((MemberSelectExpressionTree) methodInvocationTree.methodSelect()).identifier(); }
Example #14
Source File: CommonUtil.java From sonar-webdriver-plugin with MIT License | 5 votes |
public static Map<String, String> getLocatorValueMapInAnnotationTree(AnnotationTree annotationTree) { Map<String, String> locatorMap = new HashMap<>(); String annotationType = annotationTree.annotationType().toString(); String fullyQualifiedName = annotationTree.annotationType().symbolType().fullyQualifiedName(); if (FIND_BY_ANNOTATION_NAME.equals(annotationType) && isPartOfWebDriverPackage(fullyQualifiedName)) { for (ExpressionTree expressionTree : annotationTree.arguments()) { AssignmentExpressionTree assignmentExpressionTree = (AssignmentExpressionTree) expressionTree; String property = assignmentExpressionTree.variable().toString(); String locator = HOW_PROPERTY.equals(property) ? ((MemberSelectExpressionTree) ((AssignmentExpressionTree) expressionTree) .expression()).identifier().name() : ((AssignmentExpressionTree) expressionTree).variable().toString(); String propertyValue = assignmentExpressionTree.expression().is(Kind.STRING_LITERAL) ? ((LiteralTree) assignmentExpressionTree.expression()).value().replace("\"", "") : null; ExpressionTree howExpressionTree = annotationTree.arguments() .stream() .filter(aet -> HOW_PROPERTY.equals(((AssignmentExpressionTree) aet).variable().toString())) // Only one "how" property allowed in annotation .findFirst() .orElse(null); if (howExpressionTree != null && USING_PROPERTY.equals(property)) { String howLocator = ((MemberSelectExpressionTree) ((AssignmentExpressionTree) howExpressionTree) .expression()).identifier().name(); locatorMap.put(howLocator, propertyValue); } else { locatorMap.put(locator, propertyValue); } } } return locatorMap; }
Example #15
Source File: UnusedMethodParameterCheck.java From vjtools with Apache License 2.0 | 4 votes |
@Override public void visitMemberSelectExpression(MemberSelectExpressionTree tree) { // skip annotations and identifier, a method parameter will only be used in expression side (before the dot) scan(tree.expression()); }
Example #16
Source File: AdministrativeAccessUsageCheck.java From AEM-Rules-for-SonarQube with Apache License 2.0 | 4 votes |
private void onMethodInvocationFound(MethodInvocationTree mit) { String method = ((MemberSelectExpressionTree) mit.methodSelect()).identifier().name(); context.reportIssue(this, mit, String.format("Method '%s' is deprecated. Use '%s' instead.", method, SUBSTITUTES.get(method))); }
Example #17
Source File: ModifiableValueMapUsageCheck.java From AEM-Rules-for-SonarQube with Apache License 2.0 | 4 votes |
private boolean isSomeoneCallingMutableMethodsOnMap(MemberSelectExpressionTree usageOfMVM) { return MUTABLE_METHODS.contains(usageOfMVM.identifier().name()); }
Example #18
Source File: DefaultInjectionStrategyAnnotationCheck.java From AEM-Rules-for-SonarQube with Apache License 2.0 | 4 votes |
private boolean isOptionalStrategyValue(AssignmentExpressionTree assignment) { return OPTIONAL.equals(((MemberSelectExpressionTree) assignment.expression()).identifier().name()); }
Example #19
Source File: UnusedMethodParameterCheck.java From vjtools with Apache License 2.0 | 4 votes |
@Override public void visitMemberSelectExpression(MemberSelectExpressionTree tree) { // skip annotations and identifier, a method parameter will only be used in expression side (before the dot) scan(tree.expression()); }