use of org.checkerframework.framework.qual.DefaultQualifiers in project checker-framework by typetools.
the class QualifierDefaults method defaultsAt.
private DefaultSet defaultsAt(final Element elt) {
if (elt == null) {
return DefaultSet.EMPTY;
}
if (elementDefaults.containsKey(elt)) {
return elementDefaults.get(elt);
}
DefaultSet qualifiers = null;
{
DefaultQualifier d = elt.getAnnotation(DefaultQualifier.class);
if (d != null) {
qualifiers = new DefaultSet();
Set<Default> p = fromDefaultQualifier(d);
if (p != null) {
qualifiers.addAll(p);
}
}
}
{
DefaultQualifiers ds = elt.getAnnotation(DefaultQualifiers.class);
if (ds != null) {
if (qualifiers == null) {
qualifiers = new DefaultSet();
}
for (DefaultQualifier d : ds.value()) {
Set<Default> p = fromDefaultQualifier(d);
if (p != null) {
qualifiers.addAll(p);
}
}
}
}
Element parent;
if (elt.getKind() == ElementKind.PACKAGE) {
parent = ElementUtils.parentPackage((PackageElement) elt, elements);
} else {
parent = elt.getEnclosingElement();
}
DefaultSet parentDefaults = defaultsAt(parent);
if (qualifiers == null || qualifiers.isEmpty()) {
qualifiers = parentDefaults;
} else {
qualifiers.addAll(parentDefaults);
}
if (qualifiers != null && !qualifiers.isEmpty()) {
elementDefaults.put(elt, qualifiers);
return qualifiers;
} else {
return DefaultSet.EMPTY;
}
}
use of org.checkerframework.framework.qual.DefaultQualifiers in project checker-framework by typetools.
the class QualifierDefaults method nearestEnclosingExceptLocal.
/**
* Determines the nearest enclosing element for a tree by climbing the tree toward the root and
* obtaining the element for the first declaration (variable, method, or class) that encloses
* the tree. Initializers of local variables are handled in a special way: within an initializer
* we look for the DefaultQualifier(s) annotation and keep track of the previously visited tree.
* TODO: explain the behavior better.
*
* @param tree the tree
* @return the nearest enclosing element for a tree
*/
private Element nearestEnclosingExceptLocal(Tree tree) {
TreePath path = atypeFactory.getPath(tree);
if (path == null) {
Element method = atypeFactory.getEnclosingMethod(tree);
if (method != null) {
return method;
} else {
return TreeUtils.elementFromTree(tree);
}
}
Tree prev = null;
for (Tree t : path) {
switch(t.getKind()) {
case VARIABLE:
VariableTree vtree = (VariableTree) t;
ExpressionTree vtreeInit = vtree.getInitializer();
if (vtreeInit != null && prev == vtreeInit) {
Element elt = TreeUtils.elementFromDeclaration((VariableTree) t);
DefaultQualifier d = elt.getAnnotation(DefaultQualifier.class);
DefaultQualifiers ds = elt.getAnnotation(DefaultQualifiers.class);
if (d == null && ds == null) {
break;
}
}
if (prev != null && prev.getKind() == Tree.Kind.MODIFIERS) {
// type.
break;
}
return TreeUtils.elementFromDeclaration((VariableTree) t);
case METHOD:
return TreeUtils.elementFromDeclaration((MethodTree) t);
case CLASS:
case ENUM:
case INTERFACE:
case ANNOTATION_TYPE:
return TreeUtils.elementFromDeclaration((ClassTree) t);
// Do nothing.
default:
}
prev = t;
}
return null;
}
Aggregations