use of javax.lang.model.element.Name in project buck by facebook.
the class DescriptorAndSignatureFactoryTestBase method findErrors.
private void findErrors(TypeElement typeElement, Function<FieldNode, String> fieldNodeExpectedValueGetter, Function<MethodNode, String> methodNodeExpectedValueGetter, Function<ClassNode, String> classNodeExpectedValueGetter, Function<Element, String> elementActualValueGetter) throws IOException {
ClassNode typeNode = getClassNode(elements.getBinaryName(typeElement).toString());
for (Element enclosedElement : typeElement.getEnclosedElements()) {
Name elementName = enclosedElement.getSimpleName();
String actual = elementActualValueGetter.apply(enclosedElement);
switch(enclosedElement.getKind()) {
case FIELD:
checkValue("Field", elementName, fieldNodeExpectedValueGetter.apply(getFieldNode(typeNode, elementName)), actual);
break;
case CONSTRUCTOR:
case METHOD:
checkValue("Method", elementName, methodNodeExpectedValueGetter.apply(getMethodNode(typeNode, elementName)), actual);
break;
case ANNOTATION_TYPE:
case CLASS:
case ENUM:
case INTERFACE:
ClassNode innerTypeNode = getClassNode(elements.getBinaryName((TypeElement) enclosedElement).toString());
checkValue("Class", elementName, classNodeExpectedValueGetter.apply(innerTypeNode), actual);
findErrors((TypeElement) enclosedElement, fieldNodeExpectedValueGetter, methodNodeExpectedValueGetter, classNodeExpectedValueGetter, elementActualValueGetter);
break;
// $CASES-OMITTED$
default:
fail(String.format("Didn't implement testing for element kind %s", enclosedElement.getKind()));
continue;
}
}
}
use of javax.lang.model.element.Name in project lombok by rzwitserloot.
the class FindTypeVarScanner method visitTypeVariable.
@Override
public Void visitTypeVariable(TypeVariable t, Void p) {
Name name = null;
try {
name = ((Type) t).tsym.name;
} catch (NullPointerException e) {
}
if (name != null)
typeVariables.add(name.toString());
subVisit(t.getLowerBound());
subVisit(t.getUpperBound());
return null;
}
use of javax.lang.model.element.Name in project bazel by bazelbuild.
the class TreeUtils method isSelfAccess.
/**
* Returns true if the tree is a tree that 'looks like' either an access
* of a field or an invocation of a method that are owned by the same
* accessing instance.
*
* It would only return true if the access tree is of the form:
* <pre>
* field
* this.field
*
* method()
* this.method()
* </pre>
*
* It does not perform any semantical check to differentiate between
* fields and local variables; local methods or imported static methods.
*
* @param tree expression tree representing an access to object member
* @return {@code true} iff the member is a member of {@code this} instance
*/
public static boolean isSelfAccess(final ExpressionTree tree) {
ExpressionTree tr = TreeUtils.skipParens(tree);
// If method invocation check the method select
if (tr.getKind() == Tree.Kind.ARRAY_ACCESS)
return false;
if (tree.getKind() == Tree.Kind.METHOD_INVOCATION) {
tr = ((MethodInvocationTree) tree).getMethodSelect();
}
tr = TreeUtils.skipParens(tr);
if (tr.getKind() == Tree.Kind.TYPE_CAST)
tr = ((TypeCastTree) tr).getExpression();
tr = TreeUtils.skipParens(tr);
if (tr.getKind() == Tree.Kind.IDENTIFIER)
return true;
if (tr.getKind() == Tree.Kind.MEMBER_SELECT) {
tr = ((MemberSelectTree) tr).getExpression();
if (tr.getKind() == Tree.Kind.IDENTIFIER) {
Name ident = ((IdentifierTree) tr).getName();
return ident.contentEquals("this") || ident.contentEquals("super");
}
}
return false;
}
use of javax.lang.model.element.Name in project bazel by bazelbuild.
the class TreeUtils method isEnumSuper.
/**
* @param node the method invocation to check
* @return true if this is a super call to the {@link Enum} constructor
*/
public static boolean isEnumSuper(MethodInvocationTree node) {
ExecutableElement ex = TreeUtils.elementFromUse(node);
Name name = ElementUtils.getQualifiedClassName(ex);
boolean correctClass = "java.lang.Enum".contentEquals(name);
boolean correctMethod = "<init>".contentEquals(ex.getSimpleName());
return correctClass && correctMethod;
}
use of javax.lang.model.element.Name 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