com.puppycrawl.tools.checkstyle.api
Class AnnotationUtility

java.lang.Object
  extended by com.puppycrawl.tools.checkstyle.api.AnnotationUtility

public final class AnnotationUtility
extends Object

Contains utility methods designed to work with annotations.

Author:
Travis Schneeberger

Method Summary
static DetailAST annotatingWhat(DetailAST aAST)
          Checks to see what the passed in AST (representing an annotation) is annotating.
static boolean containsAnnotation(DetailAST aAST)
          Checks to see if the AST is annotated with any annotation.
static boolean containsAnnotation(DetailAST aAST, String aAnnotation)
          Checks to see if the AST is annotated with the passed in annotation.
static DetailAST getAnnotation(DetailAST aAST, String aAnnotation)
          Checks to see if the AST is annotated with the passed in annotation and return the AST representing that annotation.
static DetailAST getAnnotationHolder(DetailAST aAST)
          Gets the AST that holds a series of annotations for the potentially annotated AST.
static boolean isAnnotatingType(DetailAST aAST, int aTokenType)
          Checks to see if the passed in AST (representing an annotation) is annotating the passed in type.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

containsAnnotation

public static boolean containsAnnotation(DetailAST aAST,
                                         String aAnnotation)
Checks to see if the AST is annotated with the passed in annotation.

This method will not look for imports or package statements to detect the passed in annotation.

To check if an AST contains a passed in annotation taking into account fully-qualified names (ex: java.lang.Override, Override) this method will need to be called twice. Once for each name given.

Parameters:
aAST - the current node
aAnnotation - the annotation name to check for
Returns:
true if contains the annotation
Throws:
NullPointerException - if the aAST or aAnnotation is null

containsAnnotation

public static boolean containsAnnotation(DetailAST aAST)
Checks to see if the AST is annotated with any annotation.

Parameters:
aAST - the current node
Returns:
true if contains an annotation
Throws:
NullPointerException - if the aAST is null

getAnnotationHolder

public static DetailAST getAnnotationHolder(DetailAST aAST)
Gets the AST that holds a series of annotations for the potentially annotated AST. Returns null the passed in AST is not have an Annotation Holder.

Parameters:
aAST - the current node
Returns:
the Annotation Holder
Throws:
NullPointerException - if the aAST is null

getAnnotation

public static DetailAST getAnnotation(DetailAST aAST,
                                      String aAnnotation)
Checks to see if the AST is annotated with the passed in annotation and return the AST representing that annotation.

This method will not look for imports or package statements to detect the passed in annotation.

To check if an AST contains a passed in annotation taking into account fully-qualified names (ex: java.lang.Override, Override) this method will need to be called twice. Once for each name given.

Parameters:
aAST - the current node
aAnnotation - the annotation name to check for
Returns:
the AST representing that annotation
Throws:
NullPointerException - if the aAST or aAnnotation is null

annotatingWhat

public static DetailAST annotatingWhat(DetailAST aAST)
Checks to see what the passed in AST (representing an annotation) is annotating.

Parameters:
aAST - the AST representing an annotation.
Returns:
the AST the annotation is annotating.
Throws:
NullPointerException - if the aAST is null
IllegalArgumentException - if the aAST is not an TokenTypes.ANNOTATION

isAnnotatingType

public static boolean isAnnotatingType(DetailAST aAST,
                                       int aTokenType)
Checks to see if the passed in AST (representing an annotation) is annotating the passed in type.

Parameters:
aAST - the AST representing an annotation
aTokenType - the passed in type
Returns:
true if the annotation is annotating a type equal to the passed in type
Throws:
NullPointerException - if the aAST is null
IllegalArgumentException - if the aAST is not an TokenTypes.ANNOTATION


Copyright © 2001-2011. All Rights Reserved.