/** * Check if the list of annotation contains the annotation of given name. * * @param annos, the annotation list * @param annotationName, the annotation name * @return <code>true</code> if the annotation list contains the given annotation. */ private boolean containsAnnotation(List<AnnotationExpr> annos, String annotationName) { for (AnnotationExpr anno : annos) { if (anno.getName().getName().equals(annotationName)) { return true; } } return false; }
@Override public void visit(final MethodDeclaration m, final Context ctx) { if (!script) { boolean mvc = m.getAnnotations().stream() .map(it -> it.getName().getName()) .filter(Route.METHODS::contains) .findFirst() .isPresent(); if (mvc) { nodes.add(Maps.immutableEntry(m, m.getBody())); } } }
private MemberParameterTag createMemberParamTag(JavadocDescription javadocDescription, Stream<AnnotationExpr> annotationStream) { Map<String, String> annotations = annotationStream .filter(Expression::isSingleMemberAnnotationExpr) .collect(Collectors.toMap(a -> a.getName().getIdentifier(), this::createMemberParamValue)); return new MemberParameterTag(javadocDescription.toText(), annotations); }
private boolean isGenerated(BodyDeclaration<?> node) { for (AnnotationExpr annotation : node.getAnnotations()) { if (annotation.getName().toString().equals("Generated")) { return true; } } return false; }
private MemberParameterTag createMemberParamTag(JavadocDescription javadocDescription, Stream<AnnotationExpr> annotationStream) { Map<String, String> annotations = annotationStream .filter(Expression::isSingleMemberAnnotationExpr) .collect(Collectors.toMap(a -> a.getName().getIdentifier(), this::createMemberParamValue)); return new MemberParameterTag(javadocDescription.toText(), annotations); }
@Override public void visit(MethodDeclaration methodDeclaration, Object arg) { super.visit(methodDeclaration, arg); boolean isATestMethod = false; for(AnnotationExpr expr : methodDeclaration.getAnnotations()) { if (expr.getName().getName().equals(Test.class.getSimpleName()) || expr.getName().getName().equals(Test.class.getName())) { isATestMethod = true; break; } } if (!isATestMethod) { return; } methodAnnotationMap.put(methodDeclaration.getName(), MutablePair.of(methodDeclaration, new HashMap<String, AnnotationExpr>())); for(AnnotationExpr expr : methodDeclaration.getAnnotations()) { String[] split = expr.getName().getName().split("\\."); methodAnnotationMap.get(methodDeclaration.getName()).getRight().put(split[split.length - 1], expr); } }
@Override public void visit(MethodDeclaration methodDeclaration, Object arg) { super.visit(methodDeclaration, arg); boolean isATestMethod = false; for(AnnotationExpr expr : methodDeclaration.getAnnotations()) { if (expr.getName().getName().equals(Test.class.getSimpleName()) || expr.getName().getName().equals(Test.class.getName())) { isATestMethod = true; break; } } if (!isATestMethod) { return; } methodAnnotationMap.put(methodDeclaration.getName(), MutablePair.of(methodDeclaration, new HashMap<String, AnnotationExpr>())); for(AnnotationExpr expr : methodDeclaration.getAnnotations()) { String[] split = expr.getName().getName().split("\\."); methodAnnotationMap.get(methodDeclaration.getName()).getRight().put(split[split.length - 1], expr); } }
private static AnnotationInfo getAnnotationInfo(String packgeName, List<String> imports, AnnotationExpr ae) { AnnotationInfo annotation = new AnnotationInfo(); annotation.className = getClassName(packgeName, ae.getName().toString(), imports); return annotation; }
private static AnnotationInfo getAnnotationInfo(String packgeName, List<String> imports, AnnotationExpr ae) { AnnotationInfo annotation = new AnnotationInfo(); annotation.className = getClassName(packgeName, ae.getName().toString(), imports); return annotation; }
@Override public void visit(FieldDeclaration fd, List<EntityField> f) { if (fd.getAnnotations().stream().anyMatch(anno -> anno.getName().getName().equals("Column"))) { Class<?> type = null; switch (fd.getType().toString()) { case "String": type = String.class; break; case "Long": type = Long.class; break; case "Integer": type = Integer.class; break; case "boolean": type = boolean.class; break; } if (type == null) return; f.add(new EntityField( fd.getVariables().get(0).getId().getName(), type, fd.getAnnotations().stream().anyMatch(anno -> anno.getName().getName().equals("Id")))); } } }, entityFields);
@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())); } } } } } }
@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; }
static boolean hasDirectlyAnnotation(NodeWithAnnotations<?> nodeWithAnnotations, TypeSolver typeSolver, String canonicalName) { for (AnnotationExpr annotationExpr : nodeWithAnnotations.getAnnotations()) { SymbolReference<ResolvedTypeDeclaration> ref = JavaParserFactory.getContext(annotationExpr, typeSolver) .solveType(annotationExpr.getName().getId()); if (ref.isSolved()) { if (ref.getCorrespondingDeclaration().getQualifiedName().equals(canonicalName)) { return true; } } else { throw new UnsolvedSymbolException(annotationExpr.getName().getId()); } } return false; }
/** * Visit the Controller methods. * <p> * We visit each methods that are annotated with the Route annotations with the {@link RouteMethodSourceVisitor}. * The routes are add to the model indexed by their Path. The routes are ordered according to natural ordering * and their hierarchy. * </p> * * @param method {@inheritDoc} * @param controller The ControllerModel we are building. */ @Override public void visit(MethodDeclaration method, ControllerModel controller) { List<AnnotationExpr> annos = method.getAnnotations(); if(annos ==null || annos.isEmpty()){ return; } for(AnnotationExpr anno: annos){ if(anno.getName().getName().equals(ANNOTATION_ROUTE)){ ControllerRouteModel route = new ControllerRouteModel(); route.setMethodName(method.getName()); routeVisitor.visit(method, route); //controllerParsed the method, annotations and params LOGGER.info("[controller]The route method " + route.getMethodName() + " starting at line " + method.getBeginLine() + " has been properly visited."); //add the route to the controller controller.addRoute(route); } } }
if (null != annoList && !annoList.isEmpty()) { for (AnnotationExpr anno : annoList) { String annoName = anno.getName().getName(); if (actionAnnotations.contains(annoName)) { needJavadoc = true;
if (null != annoList && !annoList.isEmpty()) { for (AnnotationExpr anno : annoList) { String annoName = anno.getName().getName(); if (actionAnnotations.contains(annoName)) { needJavadoc = true;