public static AnnotationDeclaration mergeType(AnnotationDeclaration one, AnnotationDeclaration two) { if (isAllNull(one, two)) return null; AnnotationDeclaration annotationDeclaration = null; if (isAllNotNull(one, two)) { annotationDeclaration = new AnnotationDeclaration(); annotationDeclaration.setModifiers( mergeModifiers(one.getModifiers(), two.getModifiers())); annotationDeclaration.setJavaDoc( (JavadocComment) mergeSelective(one.getJavaDoc(), two.getJavaDoc())); annotationDeclaration.setComment(mergeSelective(one.getComment(), two.getComment())); annotationDeclaration.setAnnotations( mergeListNoDuplicate(one.getAnnotations(), two.getAnnotations())); // merge content body annotationDeclaration.setMembers(mergeBodies(one.getMembers(), two.getMembers())); LOG.info("merge AnnotationDeclaration --> {}", annotationDeclaration.getName()); } else { annotationDeclaration = findFirstNotNull(one, two); LOG.info("add AnnotationDeclaration --> {}", annotationDeclaration.getName()); } return annotationDeclaration; }
@Override public AnnotationDeclaration doMerge(AnnotationDeclaration first, AnnotationDeclaration second) { AnnotationDeclaration ad = new AnnotationDeclaration(); ad.setJavaDoc(mergeSingle(first.getJavaDoc(), second.getJavaDoc())); ad.setMembers(mergeCollections(first.getMembers(), second.getMembers())); ad.setAnnotations(mergeCollections(first.getAnnotations(), second.getAnnotations())); ad.setModifiers(mergeModifiers(first.getModifiers(), second.getModifiers())); return ad; }
@Override public String getQualifiedName() { String containerName = AstResolutionUtils.containerName(wrappedNode.getParentNode().orElse(null)); if (containerName.isEmpty()) { return wrappedNode.getName().getId(); } else { return containerName + "." + wrappedNode.getName(); } }
@Override public List<ResolvedAnnotationMemberDeclaration> getAnnotationMembers() { return wrappedNode.getMembers().stream() .filter(m -> m instanceof AnnotationMemberDeclaration) .map(m -> new JavaParserAnnotationMemberDeclaration((AnnotationMemberDeclaration)m, typeSolver)) .collect(Collectors.toList()); }
ResolvedAnnotationDeclaration annotationDeclaration = Navigator.findAncestor(node, AnnotationDeclaration.class).get().resolve(); ResolvedAnnotationMemberDeclaration resolved = annotationDeclaration.getAnnotationMembers().stream().filter(c -> ((JavaParserAnnotationMemberDeclaration)c).getWrappedNode() == node).findFirst().get(); if (resultClass.isInstance(resolved)) {
@Test public void annotationDeclarationResolve() throws IOException { File f = adaptPath(new File("src/test/resources/Annotations.java.txt")); CompilationUnit cu = parseWithSymbolResolution(f); AnnotationDeclaration declaration = (AnnotationDeclaration)cu.getType(0); assertEquals("MyAnnotation", declaration.getNameAsString()); ResolvedAnnotationDeclaration resolvedDeclaration = declaration.resolve(); }
@Override public String getName() { return wrappedNode.getName().getId(); }
@Override public List<ResolvedAnnotationMemberDeclaration> getAnnotationMembers() { return wrappedNode.getMembers().stream() .filter(m -> m instanceof AnnotationMemberDeclaration) .map(m -> new JavaParserAnnotationMemberDeclaration((AnnotationMemberDeclaration)m, typeSolver)) .collect(Collectors.toList()); } }
ResolvedAnnotationDeclaration annotationDeclaration = Navigator.findAncestor(node, AnnotationDeclaration.class).get().resolve(); ResolvedAnnotationMemberDeclaration resolved = annotationDeclaration.getAnnotationMembers().stream().filter(c -> ((JavaParserAnnotationMemberDeclaration)c).getWrappedNode() == node).findFirst().get(); if (resultClass.isInstance(resolved)) {
@Override public String getName() { return wrappedNode.getName().getId(); }
@Override public List<ResolvedAnnotationMemberDeclaration> getAnnotationMembers() { return wrappedNode.getMembers().stream() .filter(m -> m instanceof AnnotationMemberDeclaration) .map(m -> new JavaParserAnnotationMemberDeclaration((AnnotationMemberDeclaration)m, typeSolver)) .collect(Collectors.toList()); } }
ResolvedAnnotationDeclaration annotationDeclaration = node.findAncestor(AnnotationDeclaration.class).get().resolve(); ResolvedAnnotationMemberDeclaration resolved = annotationDeclaration.getAnnotationMembers().stream().filter(c -> ((JavaParserAnnotationMemberDeclaration) c).getWrappedNode() == node).findFirst().get(); if (resultClass.isInstance(resolved)) {
@Override public String getName() { return wrappedNode.getName().getId(); }
return NameRole.REFERENCE; if (whenParentIs(AnnotationDeclaration.class, name, (p, c) -> p.getName() == c)) { return NameRole.DECLARATION;