use of org.checkerframework.checker.nullness.qual.Nullable in project checker-framework by typetools.
the class TreeUtils method enclosingTopLevelBlock.
@Nullable
public static BlockTree enclosingTopLevelBlock(TreePath path) {
TreePath parpath = path.getParentPath();
while (parpath != null && !classTreeKinds.contains(parpath.getLeaf().getKind())) {
path = parpath;
parpath = parpath.getParentPath();
}
if (path.getLeaf().getKind() == Tree.Kind.BLOCK) {
return (BlockTree) path.getLeaf();
}
return null;
}
use of org.checkerframework.checker.nullness.qual.Nullable in project checker-framework by typetools.
the class StubParser method findVariableElement.
@Nullable
private VariableElement findVariableElement(FieldAccessExpr faexpr) {
if (findVariableElementFieldCache.containsKey(faexpr)) {
return findVariableElementFieldCache.get(faexpr);
}
TypeElement rcvElt = elements.getTypeElement(faexpr.getScope().toString());
if (rcvElt == null) {
// Search importedConstants for full annotation name.
for (String imp : importedConstants) {
// TODO: should this use StubUtil.partitionQualifiedName?
String[] import_delimited = imp.split("\\.");
if (import_delimited[import_delimited.length - 1].equals(faexpr.getScope().toString())) {
StringBuilder full_annotation = new StringBuilder();
for (int i = 0; i < import_delimited.length - 1; i++) {
full_annotation.append(import_delimited[i]);
full_annotation.append('.');
}
full_annotation.append(faexpr.getScope().toString());
rcvElt = elements.getTypeElement(full_annotation);
break;
}
}
if (rcvElt == null) {
stubWarnNotFound("Type " + faexpr.getScope().toString() + " not found");
return null;
}
}
VariableElement res = findFieldElement(rcvElt, faexpr.getNameAsString());
findVariableElementFieldCache.put(faexpr, res);
return res;
}
use of org.checkerframework.checker.nullness.qual.Nullable in project checker-framework by typetools.
the class StubParser method findVariableElement.
@Nullable
private VariableElement findVariableElement(NameExpr nexpr) {
if (findVariableElementNameCache.containsKey(nexpr)) {
return findVariableElementNameCache.get(nexpr);
}
VariableElement res = null;
boolean importFound = false;
for (String imp : importedConstants) {
Pair<String, String> partitionedName = StubUtil.partitionQualifiedName(imp);
String typeName = partitionedName.first;
String fieldName = partitionedName.second;
if (fieldName.equals(nexpr.getNameAsString())) {
TypeElement enclType = getTypeElement(typeName, String.format("Enclosing type of static import %s not found", fieldName));
if (enclType == null) {
return null;
} else {
importFound = true;
res = findFieldElement(enclType, fieldName);
break;
}
}
}
// only warn on fields missing an import
if (res == null && !importFound) {
stubWarnNotFound("Static field " + nexpr.getName() + " is not imported");
}
findVariableElementNameCache.put(nexpr, res);
return res;
}
use of org.checkerframework.checker.nullness.qual.Nullable in project checker-framework by typetools.
the class AnnotatedTypeFactory method aliasedAnnotation.
/**
* Returns the canonical annotation for the passed annotation if it is an alias of a canonical
* one in the framework. If it is not an alias, the method returns null.
*
* <p>A canonical annotation is the internal annotation that will be used by the Checker
* Framework in the aliased annotation's place.
*
* @param a the qualifier to check for an alias
* @return the canonical annotation or null if none exists
*/
@Nullable
public AnnotationMirror aliasedAnnotation(AnnotationMirror a) {
TypeElement elem = (TypeElement) a.getAnnotationType().asElement();
String qualName = elem.getQualifiedName().toString();
AnnotationMirror canonicalAnno = aliases.get(qualName);
if (canonicalAnno != null && a.getElementValues().size() > 0) {
AnnotationBuilder builder = new AnnotationBuilder(processingEnv, canonicalAnno);
if (aliasesCopyElements.contains(qualName)) {
builder.copyElementValuesFromAnnotation(a, aliasesIgnorableElements.get(qualName));
}
return builder.build();
} else {
return canonicalAnno;
}
}
use of org.checkerframework.checker.nullness.qual.Nullable in project checker-framework by typetools.
the class DelayQueue method poll.
/**
* Retrieves and removes the head of this queue, or returns {@code null}
* if this queue has no elements with an expired delay.
*
* @return the head of this queue, or {@code null} if this
* queue has no elements with an expired delay
*/
@Nullable
public E poll() {
final ReentrantLock lock = this.lock;
lock.lock();
try {
E first = q.peek();
if (first == null || first.getDelay(NANOSECONDS) > 0)
return null;
else
return q.poll();
} finally {
lock.unlock();
}
}
Aggregations