org.stjs.generator.javac
Class ElementUtils

java.lang.Object
  extended by org.stjs.generator.javac.ElementUtils

public final class ElementUtils
extends Object

A Utility class for analyzing Elements.


Method Summary
static TypeElement enclosingClass(Element elem)
          Returns the innermost type element enclosing the given element
static PackageElement enclosingPackage(Element elem)
          Returns the innermost package element enclosing the given element.
static VariableElement findFieldInType(TypeElement type, String name)
          Returns the field of the class
static Set<VariableElement> findFieldsInType(TypeElement type, Collection<String> names)
           
static List<VariableElement> getAllFieldsIn(TypeElement type)
          Return all fields declared in the given type or any superclass/interface.
static List<ExecutableElement> getAllMethodsIn(TypeElement type)
          Return all methods declared in the given type or any superclass/interface.
static List<ExecutableElement> getAllMethodsIn(TypeElement type, boolean addInterfaces)
           
static Name getQualifiedClassName(Element element)
          Returns the qualified name of the inner most class enclosing the provided Element
static List<ExecutableElement> getSameMethodFromParents(ExecutableElement model)
           
static List<TypeElement> getSuperTypes(TypeElement type)
          Determine all type elements for the classes and interfaces referenced in the extends/implements clauses of the given type element.
static List<TypeElement> getSuperTypes(TypeElement type, boolean addInterfaces)
           
static TypeMirror getType(Element element)
          Returns the TypeMirror for usage of Element as a value.
static String getVerboseName(Element elt)
          Returns a verbose name that identifies the element.
static boolean hasReceiver(Element element)
          Does the given element need a receiver for accesses?
static boolean isCompileTimeConstant(Element elt)
          Returns true if the element is a constant time reference
static boolean isElementFromByteCode(Element elt)
          Returns true if the element is declared in ByteCode.
static boolean isError(Element element)
           
static boolean isFinal(Element element)
          Returns true if the element is a final element: a final field, final method, or final class
static boolean isObject(TypeElement element)
          Check if the element is an element for 'java.lang.Object'
static boolean isStatic(Element element)
          Returns true if the element is a static element: whether it is a static field, static method, or static class
static boolean isTypeKind(Element elem)
           
static PackageElement parentPackage(Elements e, PackageElement elem)
          Returns the "parent" package element for the given package element.
static boolean sameSignature(ExecutableElement m1, ExecutableElement m2)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

enclosingClass

public static TypeElement enclosingClass(Element elem)
Returns the innermost type element enclosing the given element

Parameters:
elem - the enclosed element of a class
Returns:
the innermost type element

enclosingPackage

public static PackageElement enclosingPackage(Element elem)
Returns the innermost package element enclosing the given element. The same effect as Elements.getPackageOf(Element). Returns the element itself if it is a package.

Parameters:
elem - the enclosed element of a package
Returns:
the innermost package element

parentPackage

public static PackageElement parentPackage(Elements e,
                                           PackageElement elem)
Returns the "parent" package element for the given package element. For package "A.B" it gives "A". For package "A" it gives the default package. For the default package it returns null; Note that packages are not enclosed within each other, we have to manually climb the namespaces. Calling "enclosingPackage" on a package element returns the package element itself again.

Parameters:
elem - the package to start from
Returns:
the parent package element

isStatic

public static boolean isStatic(Element element)
Returns true if the element is a static element: whether it is a static field, static method, or static class

Parameters:
element -
Returns:
true if element is static

isFinal

public static boolean isFinal(Element element)
Returns true if the element is a final element: a final field, final method, or final class

Parameters:
element -
Returns:
true if the element is final

getType

public static TypeMirror getType(Element element)
Returns the TypeMirror for usage of Element as a value. It returns the return type of a method element, the class type of a constructor, or simply the type mirror of the element itself.

Parameters:
element -
Returns:
the type for the element used as a value

getQualifiedClassName

public static Name getQualifiedClassName(Element element)
Returns the qualified name of the inner most class enclosing the provided Element

Parameters:
element - an element enclosed by a class, or a TypeElement
Returns:
The qualified Name of the innermost class enclosing the element

getVerboseName

public static String getVerboseName(Element elt)
Returns a verbose name that identifies the element.


isObject

public static boolean isObject(TypeElement element)
Check if the element is an element for 'java.lang.Object'

Parameters:
element - the type element
Returns:
true iff the element is java.lang.Object element

isCompileTimeConstant

public static boolean isCompileTimeConstant(Element elt)
Returns true if the element is a constant time reference


isElementFromByteCode

public static boolean isElementFromByteCode(Element elt)
Returns true if the element is declared in ByteCode. Always return false if elt is a package.


findFieldInType

public static VariableElement findFieldInType(TypeElement type,
                                              String name)
Returns the field of the class


findFieldsInType

public static Set<VariableElement> findFieldsInType(TypeElement type,
                                                    Collection<String> names)

isError

public static boolean isError(Element element)

hasReceiver

public static boolean hasReceiver(Element element)
Does the given element need a receiver for accesses? For example, an access to a local variable does not require a receiver.

Parameters:
element - The element to test.
Returns:
whether the element requires a receiver for accesses.

getSuperTypes

public static List<TypeElement> getSuperTypes(TypeElement type)
Determine all type elements for the classes and interfaces referenced in the extends/implements clauses of the given type element. TODO: can we learn from the implementation of com.sun.tools.javac.model.JavacElements.getAllMembers(TypeElement)?


getSuperTypes

public static List<TypeElement> getSuperTypes(TypeElement type,
                                              boolean addInterfaces)

getAllFieldsIn

public static List<VariableElement> getAllFieldsIn(TypeElement type)
Return all fields declared in the given type or any superclass/interface. TODO: should this use javax.lang.model.util.Elements.getAllMembers(TypeElement) instead of our own getSuperTypes?


getAllMethodsIn

public static List<ExecutableElement> getAllMethodsIn(TypeElement type)
Return all methods declared in the given type or any superclass/interface. Note that no constructors will be returned. TODO: should this use javax.lang.model.util.Elements.getAllMembers(TypeElement) instead of our own getSuperTypes?


getAllMethodsIn

public static List<ExecutableElement> getAllMethodsIn(TypeElement type,
                                                      boolean addInterfaces)

sameSignature

public static boolean sameSignature(ExecutableElement m1,
                                    ExecutableElement m2)

getSameMethodFromParents

public static List<ExecutableElement> getSameMethodFromParents(ExecutableElement model)
Parameters:
model -
Returns:
the methods from the parent classes having the same signature as the given method. it's useful when llong for annotations.

isTypeKind

public static boolean isTypeKind(Element elem)


Copyright © 2014. All Rights Reserved.