use of org.checkerframework.checker.signature.qual.CanonicalNameOrEmpty in project checker-framework by typetools.
the class ReflectiveEvaluator method getMethodObject.
/**
* Method for reflectively obtaining a method object so it can (potentially) be statically
* executed by the checker for constant propagation.
*
* @param tree a method invocation tree
* @return the Method object corresponding to the method invocation tree
*/
private Method getMethodObject(MethodInvocationTree tree) {
final ExecutableElement ele = TreeUtils.elementFromUse(tree);
List<Class<?>> paramClasses = null;
try {
@CanonicalNameOrEmpty String className = TypesUtils.getQualifiedName((DeclaredType) ele.getEnclosingElement().asType());
paramClasses = getParameterClasses(ele);
// https://tinyurl.com/cfissue/658 for Class.toString
@SuppressWarnings("signature") Class<?> clazz = Class.forName(className.toString());
Method method = clazz.getMethod(ele.getSimpleName().toString(), paramClasses.toArray(new Class<?>[0]));
// TODO: find alternative
@SuppressWarnings("deprecation") boolean acc = method.isAccessible();
if (!acc) {
method.setAccessible(true);
}
return method;
} catch (ClassNotFoundException | UnsupportedClassVersionError | NoClassDefFoundError e) {
if (reportWarnings) {
checker.reportWarning(tree, "class.find.failed", ele.getEnclosingElement());
}
return null;
} catch (Throwable e) {
// The class we attempted to getMethod from inside the
// call to getMethodObject.
Element classElem = ele.getEnclosingElement();
if (classElem == null) {
if (reportWarnings) {
checker.reportWarning(tree, "method.find.failed", ele.getSimpleName(), paramClasses);
}
} else {
if (reportWarnings) {
checker.reportWarning(tree, "method.find.failed.in.class", ele.getSimpleName(), paramClasses, classElem);
}
}
return null;
}
}
use of org.checkerframework.checker.signature.qual.CanonicalNameOrEmpty in project checker-framework by typetools.
the class AnnotationFileElementTypes method getOutermostEnclosingClass.
/**
* Returns the fully qualified name of the outermost enclosing class of {@code e} or {@code null}
* if no such class exists for {@code e}.
*
* @param e an element whose outermost enclosing class to return
* @return the canonical name of the outermost enclosing class of {@code e} or {@code null} if no
* class encloses {@code e}
*/
@CanonicalNameOrEmpty
private String getOutermostEnclosingClass(Element e) {
TypeElement enclosingClass = ElementUtils.enclosingTypeElement(e);
if (enclosingClass == null) {
return null;
}
while (true) {
Element element = enclosingClass.getEnclosingElement();
if (element == null || element.getKind() == ElementKind.PACKAGE) {
break;
}
TypeElement t = ElementUtils.enclosingTypeElement(element);
if (t == null) {
break;
}
enclosingClass = t;
}
@// https://tinyurl.com/cfissue/658:
SuppressWarnings(// https://tinyurl.com/cfissue/658:
"signature:assignment") @CanonicalNameOrEmpty String result = enclosingClass.getQualifiedName().toString();
return result;
}
use of org.checkerframework.checker.signature.qual.CanonicalNameOrEmpty in project checker-framework by typetools.
the class TypesUtils method getQualifiedName.
// / Getters
/**
* Gets the fully qualified name for a provided type. It returns an empty name if type is an
* anonymous type.
*
* @param type the declared type
* @return the name corresponding to that type
*/
// todo: add fake override of Name.toString.
@SuppressWarnings("signature:return")
@CanonicalNameOrEmpty
public static String getQualifiedName(DeclaredType type) {
TypeElement element = (TypeElement) type.asElement();
@CanonicalNameOrEmpty Name name = element.getQualifiedName();
return name.toString();
}
Aggregations