use of lombok.core.TypeResolver in project lombok by rzwitserloot.
the class HandlerLibrary method handleAnnotation.
/**
* Handles the provided annotation node by first finding a qualifying instance of
* {@link JavacAnnotationHandler} and if one exists, calling it with a freshly cooked up
* instance of {@link lombok.core.AnnotationValues}.
*
* Note that depending on the printASTOnly flag, the {@link lombok.core.PrintAST} annotation
* will either be silently skipped, or everything that isn't {@code PrintAST} will be skipped.
*
* The HandlerLibrary will attempt to guess if the given annotation node represents a lombok annotation.
* For example, if {@code lombok.*} is in the import list, then this method will guess that
* {@code Getter} refers to {@code lombok.Getter}, presuming that {@link lombok.javac.handlers.HandleGetter}
* has been loaded.
*
* @param unit The Compilation Unit that contains the Annotation AST Node.
* @param node The Lombok AST Node representing the Annotation AST Node.
* @param annotation 'node.get()' - convenience parameter.
*/
public void handleAnnotation(JCCompilationUnit unit, JavacNode node, JCAnnotation annotation, long priority) {
TypeResolver resolver = new TypeResolver(node.getImportList());
String rawType = annotation.annotationType.toString();
String fqn = resolver.typeRefToFullyQualifiedName(node, typeLibrary, rawType);
if (fqn == null)
return;
AnnotationHandlerContainer<?> container = annotationHandlers.get(fqn);
if (container == null)
return;
try {
if (container.getPriority() == priority) {
if (checkAndSetHandled(annotation))
container.handle(node);
}
} catch (AnnotationValueDecodeFail fail) {
fail.owner.setError(fail.getMessage(), fail.idx);
} catch (Throwable t) {
String sourceName = "(unknown).java";
if (unit != null && unit.sourcefile != null)
sourceName = unit.sourcefile.getName();
javacError(String.format("Lombok annotation handler %s failed on " + sourceName, container.handler.getClass()), t);
}
}
use of lombok.core.TypeResolver in project lombok by rzwitserloot.
the class JavacHandlerUtil method typeMatches.
/**
* 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);
}
use of lombok.core.TypeResolver in project lombok by rzwitserloot.
the class HandlerLibrary method handleAnnotation.
/**
* Handles the provided annotation node by first finding a qualifying instance of
* {@link EclipseAnnotationHandler} and if one exists, calling it with a freshly cooked up
* instance of {@link AnnotationValues}.
*
* Note that depending on the printASTOnly flag, the {@link lombok.core.PrintAST} annotation
* will either be silently skipped, or everything that isn't {@code PrintAST} will be skipped.
*
* The HandlerLibrary will attempt to guess if the given annotation node represents a lombok annotation.
* For example, if {@code lombok.*} is in the import list, then this method will guess that
* {@code Getter} refers to {@code lombok.Getter}, presuming that {@link lombok.eclipse.handlers.HandleGetter}
* has been loaded.
*
* @param ast The Compilation Unit that contains the Annotation AST Node.
* @param annotationNode The Lombok AST Node representing the Annotation AST Node.
* @param annotation 'node.get()' - convenience parameter.
*/
public void handleAnnotation(CompilationUnitDeclaration ast, EclipseNode annotationNode, org.eclipse.jdt.internal.compiler.ast.Annotation annotation, long priority) {
TypeResolver resolver = new TypeResolver(annotationNode.getImportList());
TypeReference rawType = annotation.type;
if (rawType == null)
return;
String fqn = resolver.typeRefToFullyQualifiedName(annotationNode, typeLibrary, toQualifiedName(annotation.type.getTypeName()));
if (fqn == null)
return;
AnnotationHandlerContainer<?> container = annotationHandlers.get(fqn);
if (container == null)
return;
if (priority != container.getPriority())
return;
if (!annotationNode.isCompleteParse() && container.deferUntilPostDiet()) {
if (needsHandling(annotation))
container.preHandle(annotation, annotationNode);
return;
}
try {
if (checkAndSetHandled(annotation))
container.handle(annotation, annotationNode);
} catch (AnnotationValueDecodeFail fail) {
fail.owner.setError(fail.getMessage(), fail.idx);
} catch (Throwable t) {
error(ast, String.format("Lombok annotation handler %s failed", container.handler.getClass()), t);
}
}
use of lombok.core.TypeResolver in project lombok by rzwitserloot.
the class EclipseHandlerUtil method typeMatches.
/**
* 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 typeRef A type reference to check.
*/
public static boolean typeMatches(Class<?> type, EclipseNode node, TypeReference typeRef) {
if (typeRef == null || typeRef.getTypeName() == null || typeRef.getTypeName().length == 0)
return false;
String lastPartA = new String(typeRef.getTypeName()[typeRef.getTypeName().length - 1]);
String lastPartB = type.getSimpleName();
if (!lastPartA.equals(lastPartB))
return false;
String typeName = toQualifiedName(typeRef.getTypeName());
TypeResolver resolver = new TypeResolver(node.getImportList());
return resolver.typeMatches(node, type.getName(), typeName);
}
Aggregations