use of javax.lang.model.element.TypeElement in project bazel by bazelbuild.
the class ElementUtils method getAllMethodsIn.
/**
* 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?
*/
public static List<ExecutableElement> getAllMethodsIn(TypeElement type) {
List<ExecutableElement> meths = new ArrayList<ExecutableElement>();
meths.addAll(ElementFilter.methodsIn(type.getEnclosedElements()));
List<TypeElement> alltypes = getSuperTypes(type);
for (TypeElement atype : alltypes) {
meths.addAll(ElementFilter.methodsIn(atype.getEnclosedElements()));
}
return Collections.<ExecutableElement>unmodifiableList(meths);
}
use of javax.lang.model.element.TypeElement in project bazel by bazelbuild.
the class ElementUtils method enclosingClass.
/**
* Returns the innermost type element enclosing the given element
*
* @param elem the enclosed element of a class
* @return the innermost type element
*/
public static TypeElement enclosingClass(final Element elem) {
Element result = elem;
while (result != null && !result.getKind().isClass() && !result.getKind().isInterface()) {
/*@Nullable*/
Element encl = result.getEnclosingElement();
result = encl;
}
return (TypeElement) result;
}
use of javax.lang.model.element.TypeElement in project bazel by bazelbuild.
the class ElementUtils method getAllFieldsIn.
/**
* 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?
*/
public static List<VariableElement> getAllFieldsIn(TypeElement type) {
List<VariableElement> fields = new ArrayList<VariableElement>();
fields.addAll(ElementFilter.fieldsIn(type.getEnclosedElements()));
List<TypeElement> alltypes = getSuperTypes(type);
for (TypeElement atype : alltypes) {
fields.addAll(ElementFilter.fieldsIn(atype.getEnclosedElements()));
}
return Collections.<VariableElement>unmodifiableList(fields);
}
use of javax.lang.model.element.TypeElement in project bazel by bazelbuild.
the class AnnotationUtils method annotationName.
// **********************************************************************
// Helper methods to handle annotations. mainly workaround
// AnnotationMirror.equals undesired property
// (I think the undesired property is that it's reference equality.)
// **********************************************************************
/**
* @return the fully-qualified name of an annotation as a Name
*/
public static final /*@Interned*/
String annotationName(AnnotationMirror annotation) {
if (annotationMirrorNames.containsKey(annotation))
return annotationMirrorNames.get(annotation);
final DeclaredType annoType = annotation.getAnnotationType();
final TypeElement elm = (TypeElement) annoType.asElement();
/*@Interned*/
String name = elm.getQualifiedName().toString().intern();
annotationMirrorNames.put(annotation, name);
return name;
}
use of javax.lang.model.element.TypeElement in project bazel by bazelbuild.
the class TypesUtils method isThrowable.
/** @return type represents a Throwable type (e.g. Exception, Error) **/
public static boolean isThrowable(TypeMirror type) {
while (type != null && type.getKind() == TypeKind.DECLARED) {
DeclaredType dt = (DeclaredType) type;
TypeElement elem = (TypeElement) dt.asElement();
Name name = elem.getQualifiedName();
if ("java.lang.Throwable".contentEquals(name))
return true;
type = elem.getSuperclass();
}
return false;
}
Aggregations