/** * Checks if the provided annotation type is likely to be the intended type for the given * annotation node. * * <p>This is a guess, but a decent one. */ public static boolean annotationTypeMatches( Class<? extends java.lang.annotation.Annotation> type, Node node) { if (node.getKind() != Kind.ANNOTATION) return false; TypeReference typeRef = ((Annotation) node.get()).type; if (typeRef == null || typeRef.getTypeName() == null) return false; String typeName = toQualifiedName(typeRef.getTypeName()); TypeLibrary library = new TypeLibrary(); library.addType(type.getName()); TypeResolver resolver = new TypeResolver(library, node.getPackageDeclaration(), node.getImportStatements()); Collection<String> typeMatches = resolver.findTypeMatches(node, typeName); for (String match : typeMatches) { if (match.equals(type.getName())) return true; } return false; }