private static class ClassVisitor extends VoidVisitorAdapter { @Override public void visit(ClassOrInterfaceDeclaration n, Object arg) { for (AnnotationExpr ann: n.getAnnotations()) { System.out.println(ann.toString()); } } }
/** * Visit the Class declaration and return true if it corresponds to a wisdom controller. * * @param declaration The class declaration created by the JavaParser. * @param extra Extra out value argument, not used here. * @return <code>true</code> if the declaration correspond to a wisdom controller, <code>false</code> otherwise. */ public Boolean visit(ClassOrInterfaceDeclaration declaration, Object extra) { if (declaration.getAnnotations() != null && containsAnnotation(declaration.getAnnotations(), CONTROL_ANNO_NAME)) { return true; } //Get the list of extended and implemented class List<ClassOrInterfaceType> hierarchy = new ArrayList<>(); if (declaration.getExtends() != null) { hierarchy.addAll(declaration.getExtends()); } if (declaration.getImplements() != null) { hierarchy.addAll(declaration.getImplements()); } return containsClassName(hierarchy, CONTROL_CLASSNAMES); }
@Override public boolean hasDirectlyAnnotation(String canonicalName) { for (AnnotationExpr annotationExpr : wrappedNode.getAnnotations()) { if (solveType(annotationExpr.getName().getId(), typeSolver).getCorrespondingDeclaration().getQualifiedName().equals(canonicalName)) { return true; } } return false; }
@Override public boolean hasDirectlyAnnotation(String canonicalName) { for (AnnotationExpr annotationExpr : wrappedNode.getAnnotations()) { if (solveType(annotationExpr.getName().getId(), typeSolver).getCorrespondingDeclaration().getQualifiedName().equals(canonicalName)) { return true; } } return false; }
@Override public boolean hasDirectlyAnnotation(String canonicalName) { for (AnnotationExpr annotationExpr : wrappedNode.getAnnotations()) { if (solveType(annotationExpr.getName().getId(), typeSolver).getCorrespondingDeclaration().getQualifiedName().equals(canonicalName)) { return true; } } return false; }
@Override public boolean hasDirectlyAnnotation(String canonicalName) { for (AnnotationExpr annotationExpr : wrappedNode.getAnnotations()) { if (solveType(annotationExpr.getName().getId(), typeSolver).getCorrespondingDeclaration().getQualifiedName().equals(canonicalName)) { return true; } } return false; }
private void addPlanTargetsFromClassAnnotationFields() { for (AnnotationExpr annotationExpr : pair.getRight().getAnnotations()) { if (annotationExpr.getName().getName().equals(ContinuousIntegrationPlan.class.getName()) || annotationExpr.getName().getName().equals(ContinuousIntegrationPlan.class.getSimpleName())) { Map<String, MemberValuePair> classAnnotationFields = AgileTestingJavaParserTools.mapAnnotationFields(annotationExpr); if (classAnnotationFields.containsKey(AgileTestingAnnotationTools.CLASS_TARGETS)) { Expression expression = classAnnotationFields.get(AgileTestingAnnotationTools.CLASS_TARGETS).getValue(); if (expression instanceof FieldAccessExpr) { FieldAccessExpr fieldAccessExpr = (FieldAccessExpr) expression; classPlanTargets.add(IntegrationCategory.fromString(fieldAccessExpr.getField())); } else if (expression instanceof ArrayInitializerExpr) { ArrayInitializerExpr arrayInitializerExpr = (ArrayInitializerExpr) expression; for (Expression arrayField : arrayInitializerExpr.getValues()) { FieldAccessExpr arrayFieldAccessExpr = (FieldAccessExpr) arrayField; classPlanTargets.add(IntegrationCategory.fromString(arrayFieldAccessExpr.getField())); } } } } } }
public void calculate(ClassOrInterfaceDeclaration classOrInterfaceDeclaration, CompilationUnit compilationUnit) { List<AnnotationExpr> annotations = classOrInterfaceDeclaration.getAnnotations(); for (AnnotationExpr annotation : annotations) { String annotationName = annotation.getNameAsString(); String annotationPackageName = annotation .findCompilationUnit() .flatMap(CompilationUnit::getPackageDeclaration) .flatMap(pkg -> Optional.of(pkg.getNameAsString())).orElse("???"); if (typeDao.exist(annotationName, annotationPackageName)) { // JDK annotations are not indexed int annotationId = typeDao.getId(annotationName, annotationPackageName); int typeId = typeDao.getId(classOrInterfaceDeclaration.getNameAsString(), compilationUnit.getPackageDeclaration().get().getNameAsString()); annotatedWithDao.save(new AnnotatedWith(typeId, annotationId)); } } } }
for (AnnotationExpr annotationExpr : pair.getRight().getAnnotations())
n.setJavaDoc((JavadocComment) n.getJavaDoc().accept(this, arg)); List<AnnotationExpr> annotations = n.getAnnotations(); if (annotations != null) { for (int i = 0; i < annotations.size(); i++) {
@Override public ClassOrInterfaceDeclaration doMerge(ClassOrInterfaceDeclaration first, ClassOrInterfaceDeclaration second) { ClassOrInterfaceDeclaration declaration = new ClassOrInterfaceDeclaration(); declaration.setInterface(first.isInterface()); declaration.setName(first.getName()); declaration.setModifiers(mergeModifiers(first.getModifiers(), second.getModifiers())); declaration.setJavaDoc(mergeSingle(first.getJavaDoc(), second.getJavaDoc())); declaration.setTypeParameters(mergeCollections(first.getTypeParameters(), second.getTypeParameters())); declaration.setImplements(mergeCollections(first.getImplements(), second.getImplements())); declaration.setExtends(mergeCollections(first.getExtends(), second.getExtends())); declaration.setAnnotations(mergeCollections(first.getAnnotations(), second.getAnnotations())); declaration.setMembers(mergeCollections(first.getMembers(), second.getMembers())); return declaration; }
public static ClassOrInterfaceDeclaration mergeType(ClassOrInterfaceDeclaration one, ClassOrInterfaceDeclaration two) { if (isAllNull(one, two)) return null; ClassOrInterfaceDeclaration coid = null; if (isAllNotNull(one, two)) { coid = new ClassOrInterfaceDeclaration(); coid.setName(one.getName()); coid.setJavaDoc(mergeSelective(one.getJavaDoc(), two.getJavaDoc())); coid.setComment(mergeSelective(one.getComment(), two.getComment())); coid.setAnnotations(mergeListNoDuplicate(one.getAnnotations(), two.getAnnotations())); coid.setModifiers(mergeModifiers(one.getModifiers(), two.getModifiers())); coid.setExtends(mergeListNoDuplicate(one.getExtends(), two.getExtends())); coid.setImplements(mergeListNoDuplicate(one.getImplements(), two.getImplements())); coid.setTypeParameters(mergeSelective(one.getTypeParameters(), two.getTypeParameters())); coid.setInterface(one.isInterface()); coid.setMembers(mergeBodies(one.getMembers(), two.getMembers())); LOG.info("merge ClassOrInterfaceDeclaration --> {}", coid.getName()); } else { coid = findFirstNotNull(one, two); LOG.info("add ClassOrInterfaceDeclaration --> {}", coid.getName()); } return coid; }