Lombok.ast - v0.2

lombok.ast.resolve
Class Resolver

java.lang.Object
  extended by lombok.ast.resolve.Resolver

public class Resolver
extends Object

Contains simplistic (guesstimations) resolution that doesn't require full resolution and symbol lookup but it isn't perfect.


Constructor Summary
Resolver()
           
 
Method Summary
 String getAnnotationClassAsString(Annotation annotation, String methodName)
          Use together with toAnnotationInstance(Class, Annotation).
 List<String> getAnnotationClassesAsStrings(Annotation annotation, String methodName)
          Use together with toAnnotationInstance(Class, Annotation).
<E extends Enum<E>>
E
resolveEnum(Class<E> enumClass, Node value)
          If value is an enum constant of type enumClass, then the enum value will be returned.
<A extends Annotation>
A
toAnnotationInstance(Class<A> type, Annotation node)
          Turns an annotation AST node into an actual instance of an annotation class provided you already know its type.
 boolean typesMatch(String wanted, TypeReference typeReference)
          Checks if the given typeReference could legally be referring to the listed fully qualified typeName.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Resolver

public Resolver()
Method Detail

resolveEnum

public <E extends Enum<E>> E resolveEnum(Class<E> enumClass,
                                         Node value)
If value is an enum constant of type enumClass, then the enum value will be returned. null will be returned if value is an actual null literal.

Throws:
ResolutionException - If value cannot be converted.

typesMatch

public boolean typesMatch(String wanted,
                          TypeReference typeReference)
Checks if the given typeReference could legally be referring to the listed fully qualified typeName. Will check import statements, and checks for any shadowing by types in this file with the same name.

WARNING: This method will return true if there's a star import of i.e. java.util.*, you ask if ArrayList could be referring to java.util.ArrayList, and there is another class in the same package also named ArrayList. The right answer is of course false, but without a classpath/sourcepath this cannot be determined. Therefore, this method is 99% but not 100% accurate. Also, god kills a puppy everytime you write a star import.

NB: Any type arguments (generics) on either the typeReference or wanted are stripped off before comparing the two.

NB: If you want array types, just put array brackets at the end of your wanted string, for example: "java.lang.String[]".

Parameters:
wanted - A fully qualified type name, such as java.lang.String.
typeReference - A type reference node.
Returns:
true if the typeReference is most likely a reference to wanted.

toAnnotationInstance

public <A extends Annotation> A toAnnotationInstance(Class<A> type,
                                                     Annotation node)
Turns an annotation AST node into an actual instance of an annotation class provided you already know its type. NB: non-literal compile-time constants cannot be converted, and you should avoid querying classes; instead call resolver.getAnnotationClassAsString(objectReturnedByThisMethod, "annotation method name").

See Also:
getAnnotationClassesAsStrings(java.lang.annotation.Annotation, String), getAnnotationClassAsString(java.lang.annotation.Annotation, String)

getAnnotationClassAsString

public String getAnnotationClassAsString(Annotation annotation,
                                         String methodName)
Use together with toAnnotationInstance(Class, Annotation).

See Also:
getAnnotationClassesAsStrings(java.lang.annotation.Annotation, String)

getAnnotationClassesAsStrings

public List<String> getAnnotationClassesAsStrings(Annotation annotation,
                                                  String methodName)
Use together with toAnnotationInstance(Class, Annotation).

See Also:
getAnnotationClassAsString(java.lang.annotation.Annotation, String)

Lombok.ast - v0.2

Copyright © 2010-2011 The Project Lombok Authors, licensed under the MIT licence.