Java Code Examples for org.sonar.plugins.java.api.tree.AnnotationTree#arguments()
The following examples show how to use
org.sonar.plugins.java.api.tree.AnnotationTree#arguments() .
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: 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 2
Source File: PreferSlingServletAnnotation.java From AEM-Rules-for-SonarQube with Apache License 2.0 | 5 votes |
@Override public void visitAnnotation(AnnotationTree annotationTree) { if (annotations.hasSlingServletAnnotation() && isPropertyAnnotation(annotationTree)) { for (ExpressionTree expression : annotationTree.arguments()) { if (isAssignmentToName(expression)) { checkIfPropertyInsteadSlingServletIsUsed(annotationTree, (AssignmentExpressionTree) expression); } } } super.visitAnnotation(annotationTree); }
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); } }