if (jjtGetChild(0) instanceof ASTMarkerAnnotation) { return false; if (isSuppressWarnings()) { for (ASTLiteral element : findDescendantsOfType(ASTLiteral.class)) { if (element.hasImageEqualTo("\"PMD\"") || element.hasImageEqualTo("\"PMD." + rule.getName() + "\"")
@Override public ASTAnnotation getAnnotation(String annotQualifiedName) { List<ASTAnnotation> annotations = getDeclaredAnnotations(); for (ASTAnnotation annotation : annotations) { ASTName name = annotation.getFirstDescendantOfType(ASTName.class); if (name != null && TypeHelper.isA(name, annotQualifiedName)) { return annotation; } } return null; }
final public void Annotation() throws ParseException { ASTAnnotation jjtn000 = new ASTAnnotation(this, JJTANNOTATION); boolean jjtc000 = true; jjtree.openNodeScope(jjtn000); jjtn000.jjtSetFirstToken(getToken(1)); try { if (jj_2_81(2147483647)) { if (jjtc000) { jjtree.closeNodeScope(jjtn000, true); jjtn000.jjtSetLastToken(getToken(0));
@Override public Object visit(ASTAnnotation node, Object data) { ASTName name = node.getFirstDescendantOfType(ASTName.class); boolean noTransactional = name == null || !(TRANSACTIONAL_ANNOTATION_NAME.equals(name.getImage()) && !TRANSACTIONAL_FULL_NAME.equals(name.getImage())); return super.visit(node, data); List<ASTMemberValuePair> memberValuePairList = node.findDescendantsOfType(ASTMemberValuePair.class); if (shouldSkip(memberValuePairList)) { return super.visit(node, data);
@Override public Object visit(ASTAnnotation node, Object data) { final List<ASTMemberValuePair> annotationProperties = node.findDescendantsOfType(ASTMemberValuePair.class); // all that needs to be done is check to if there's a single property in the annotation and if if that property is value // then it's a violation and it should be resolved. if (annotationProperties.size() == 1 && "value".equals(annotationProperties.get(0).getImage())) { addViolation(data, node); } return data; } }
/** * Returns the name of the annotation as it is used, * eg {@code java.lang.Override} or {@code Override}. */ public String getAnnotationName() { return jjtGetChild(0).jjtGetChild(0).getImage(); }
private boolean isSuppressWarnings() { return "SuppressWarnings".equals(getAnnotationName()) || "java.lang.SuppressWarnings".equals(getAnnotationName()); }
@Override public Object visit(ASTMethodDeclaration node, Object data) { if (currentLookup.peek() == null) { return super.visit(node, data); } for (ASTAnnotation annot : node.getDeclaredAnnotations()) { if (Override.class.equals(annot.getType())) { // we assume the compiler has already checked it, so it's correct return super.visit(node, data); } } try { boolean overridden = currentLookup.peek().isOverridden(node.getName(), node.getFormalParameters()); if (overridden) { addViolation(data, node, new Object[]{node.getQualifiedName().getOperation()}); } } catch (NoSuchMethodException e) { // may happen in the body of an enum constant, // because the method lookup used is the one of // the parent class. LOG.warning("MissingOverride encountered unexpected method " + node.getMethodName()); // throw new RuntimeException(e); // uncomment when enum constants are handled by typeres } return super.visit(node, data); }
/** * annotation is sibling of classOrInterface declaration or method declaration * * @param node transactional annotation * @param clz classOrInterface declaration or method declaration * @param <T> generic * @return sibling node */ private <T> T getSiblingForType(ASTAnnotation node, Class<T> clz) { Node parent = node.jjtGetParent(); int num = parent.jjtGetNumChildren(); for (int i = 0; i < num; i++) { Node child = parent.jjtGetChild(i); if (clz.isAssignableFrom(child.getClass())) { return clz.cast(child); } if (!(child instanceof ASTAnnotation)) { return null; } } return null; } }
Token lastToken = (Token)annotation.jjtGetLastToken();
private boolean isOkUsingLombok(ASTClassOrInterfaceDeclaration parent) { // check if there's a lombok no arg private constructor, if so skip the rest of the rules ASTAnnotation annotation = parent.getAnnotation("lombok.NoArgsConstructor"); if (annotation != null) { List<ASTMemberValuePair> memberValuePairs = annotation.findDescendantsOfType(ASTMemberValuePair.class); for (ASTMemberValuePair memberValuePair : memberValuePairs) { // to set the access level of a constructor in lombok, you set the access property on the annotation if ("access".equals(memberValuePair.getImage())) { List<ASTName> names = memberValuePair.findDescendantsOfType(ASTName.class); for (ASTName name : names) { // check to see if the value of the member value pair ends PRIVATE. This is from the AccessLevel enum in Lombok if (name.getImage().endsWith("PRIVATE")) { // if the constructor is found and the accesslevel is private no need to check anything else return true; } } } } } return false; }
private boolean doesNodeContainJUnitAnnotation(Node node, String annotationTypeClassName) { List<ASTAnnotation> annotations = node.findDescendantsOfType(ASTAnnotation.class); for (ASTAnnotation annotation : annotations) { Node annotationTypeNode = annotation.jjtGetChild(0); TypeNode annotationType = (TypeNode) annotationTypeNode; if (annotationType.getType() == null) { ASTName name = annotationTypeNode.getFirstChildOfType(ASTName.class); if (name != null && (name.hasImageEqualTo("Test") || name.hasImageEqualTo(annotationTypeClassName))) { return true; } } else if (TypeHelper.isA(annotationType, annotationTypeClassName)) { return true; } } return false; }
private boolean isSuppressWarnings() { return "SuppressWarnings".equals(getAnnotationName()) || "java.lang.SuppressWarnings".equals(getAnnotationName()); }
@Override public Object visit(ASTMethodDeclaration node, Object data) { if (currentLookup.peek() == null) { return super.visit(node, data); } for (ASTAnnotation annot : node.getDeclaredAnnotations()) { if (Override.class.equals(annot.getType())) { // we assume the compiler has already checked it, so it's correct return super.visit(node, data); } } try { boolean overridden = currentLookup.peek().isOverridden(node.getName(), node.getFormalParameters()); if (overridden) { addViolation(data, node, new Object[]{node.getQualifiedName().getOperation()}); } } catch (NoSuchMethodException e) { // may happen in the body of an enum constant, // because the method lookup used is the one of // the parent class. LOG.warning("MissingOverride encountered unexpected method " + node.getMethodName()); // throw new RuntimeException(e); // uncomment when enum constants are handled by typeres } return super.visit(node, data); }
if (jjtGetChild(0) instanceof ASTMarkerAnnotation) { return false; if (isSuppressWarnings()) { for (ASTLiteral element : findDescendantsOfType(ASTLiteral.class)) { if (element.hasImageEqualTo("\"PMD\"") || element.hasImageEqualTo("\"PMD." + rule.getName() + "\"")
List<ASTAnnotation> annotations = parent.findChildrenOfType(ASTAnnotation.class); for (ASTAnnotation annotation : annotations) { ASTName name = annotation.getFirstDescendantOfType(ASTName.class); if (name != null) { String annotationName = name.getImage();
final public void Annotation() throws ParseException { ASTAnnotation jjtn000 = new ASTAnnotation(this, JJTANNOTATION); boolean jjtc000 = true; jjtree.openNodeScope(jjtn000); jjtn000.jjtSetFirstToken(getToken(1)); try { if (jj_2_81(2147483647)) { if (jjtc000) { jjtree.closeNodeScope(jjtn000, true); jjtn000.jjtSetLastToken(getToken(0));
@Override public Object visit(ASTAnnotation node, Object data) { final List<ASTMemberValuePair> annotationProperties = node.findDescendantsOfType(ASTMemberValuePair.class); // all that needs to be done is check to if there's a single property in the annotation and if if that property is value // then it's a violation and it should be resolved. if (annotationProperties.size() == 1 && "value".equals(annotationProperties.get(0).getImage())) { addViolation(data, node); } return data; } }
/** * Returns the name of the annotation as it is used, * eg {@code java.lang.Override} or {@code Override}. */ public String getAnnotationName() { return jjtGetChild(0).jjtGetChild(0).getImage(); }
@Override public Object visit(ASTMethodDeclaration methodDeclaration, Object o) { if (junitImported && isAllowedMethod(methodDeclaration)) { return super.visit(methodDeclaration, o); } if (methodDeclaration.getMethodName().startsWith("test")) { return super.visit(methodDeclaration, o); } // Ignore overridden methods, the issue should be marked on the method definition final List<ASTAnnotation> methodAnnotations = methodDeclaration.jjtGetParent().findChildrenOfType(ASTAnnotation.class); for (final ASTAnnotation annotation : methodAnnotations) { final ASTName annotationName = annotation.getFirstDescendantOfType(ASTName.class); if (annotationName.hasImageEqualTo("Override") || annotationName.hasImageEqualTo("java.lang.Override")) { return super.visit(methodDeclaration, o); } } checkExceptions(methodDeclaration, o); return super.visit(methodDeclaration, o); }