edu.cmu.cs.crystal.annotations
Class AnnotationDatabase

java.lang.Object
  extended by edu.cmu.cs.crystal.annotations.AnnotationDatabase

public class AnnotationDatabase
extends Object

This class is a database for annotations. It can store annotations of methods we have analyzed or of ones we have not. Either way, it does not store any AST information, so it returns Crystal objects that represent an annotation. Those who want to use this database must register the type of annotations to scan for, @see{ICrystalAnnotation}. A ICrystalAnnotation provides all the information that one needs about the annotations. An AnnotationSummary is particularly useful for finding all information relating to the method, including parameters. And just in case you were wondering...we can not use regular reflection objects here (Class, Annotation, etc.) as the files we are analyzing aren't on the classpath of the system we are running. The annotation database currently allows clients to request annotations if they provide an ITypeBinding. However, this means that Crystal needs to have parsed and analyzed the code in question to get an ITypeBinding in the first place. Instead, we would like to retrieve annotations from unanalyzed code (for example, a library). This can currently be done with @link{#getAnnosForType(IType)}, and the plan is to eventually allow methods and fields based upon the Java Model instead of the Java ASTNodes.

Author:
ciera, Nels Beckman

Constructor Summary
AnnotationDatabase()
           
 
Method Summary
 void addAnnotationToField(ICrystalAnnotation anno, FieldDeclaration field)
           
 void addAnnotationToMethod(AnnotationSummary anno, MethodDeclaration method)
           
 void addAnnotationToType(ICrystalAnnotation anno, TypeDeclaration type)
           
 ICrystalAnnotation createCrystalAnnotation(IType typeOfAnnotation)
          See createCrystalAnnotation(ITypeBinding).
 ICrystalAnnotation createCrystalAnnotation(ITypeBinding typeBinding)
           
static
<A extends ICrystalAnnotation>
List<A>
filter(List<ICrystalAnnotation> list, Class<A> type)
           
 List<ICrystalAnnotation> getAnnosForType(IType type)
          This method will return the list of annotations associated with the given type.
 List<ICrystalAnnotation> getAnnosForType(ITypeBinding type)
          This method will return the list of annotations associated with the given type.
 List<ICrystalAnnotation> getAnnosForVariable(IVariableBinding binding)
          This method will return the list of annotations associated with the given variable.
 AnnotationSummary getSummaryForMethod(IMethodBinding binding)
          Given a method binding, returns a summary that represents annotation info for that method declaration.
 boolean isMulti(IAnnotationBinding annoBinding)
          Checks whether this annotation is marked as a multi annotation, as described by MultiAnnotation
 boolean isMulti(IAnnotation anno, IType relative_type)
          See isMulti(IAnnotationBinding).
 void register(String fullyQualifiedName, Class<? extends ICrystalAnnotation> crystalAnnotationClass, boolean isMeta)
           
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

AnnotationDatabase

public AnnotationDatabase()
Method Detail

register

public void register(String fullyQualifiedName,
                     Class<? extends ICrystalAnnotation> crystalAnnotationClass,
                     boolean isMeta)

getSummaryForMethod

public AnnotationSummary getSummaryForMethod(IMethodBinding binding)
Given a method binding, returns a summary that represents annotation info for that method declaration.


getAnnosForType

public List<ICrystalAnnotation> getAnnosForType(IType type)
                                         throws JavaModelException
This method will return the list of annotations associated with the given type. It's very similar in functionality to getAnnosForType(ITypeBinding) except that it works on the Java model element, so it does not require the type to have been parsed and analyzed by Crystal.

Throws:
JavaModelException

getAnnosForType

public List<ICrystalAnnotation> getAnnosForType(ITypeBinding type)
This method will return the list of annotations associated with the given type. To work, this binding had to be parsed by Crystal. If you do not have a type that was parsed by Crystal, use getAnnosForType(IType).


getAnnosForVariable

public List<ICrystalAnnotation> getAnnosForVariable(IVariableBinding binding)
This method will return the list of annotations associated with the given variable.


isMulti

public boolean isMulti(IAnnotationBinding annoBinding)
Checks whether this annotation is marked as a multi annotation, as described by MultiAnnotation

Parameters:
annoBinding -
Returns:
true id this is a multi annotation, and false if it is not.

isMulti

public boolean isMulti(IAnnotation anno,
                       IType relative_type)
                throws JavaModelException
See isMulti(IAnnotationBinding).

Throws:
JavaModelException

createCrystalAnnotation

public ICrystalAnnotation createCrystalAnnotation(IType typeOfAnnotation)
                                           throws JavaModelException
See createCrystalAnnotation(ITypeBinding).

Throws:
JavaModelException

createCrystalAnnotation

public ICrystalAnnotation createCrystalAnnotation(ITypeBinding typeBinding)

addAnnotationToField

public void addAnnotationToField(ICrystalAnnotation anno,
                                 FieldDeclaration field)

addAnnotationToMethod

public void addAnnotationToMethod(AnnotationSummary anno,
                                  MethodDeclaration method)

addAnnotationToType

public void addAnnotationToType(ICrystalAnnotation anno,
                                TypeDeclaration type)

filter

public static <A extends ICrystalAnnotation> List<A> filter(List<ICrystalAnnotation> list,
                                                            Class<A> type)