/** * 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; }
/** * Checks if the given TypeReference node is likely to be a reference to the provided class. * * @param type An actual type. This method checks if {@code typeNode} is likely to be a reference * to this type. * @param node A Lombok AST node. Any node in the appropriate compilation unit will do (used to * get access to import statements). * @param typeNode A type reference to check. */ public static boolean typeMatches(Class<?> type, JavacNode node, JCTree typeNode) { String typeName = typeNode.toString(); TypeResolver resolver = new TypeResolver(node.getImportList()); return resolver.typeMatches(node, type.getName(), typeName); }