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 AnnotationClassLoader method getURLFromClasspaths.
/**
* Scans all classpaths and returns the resource URL to the jar which contains the checker's
* qual package, or the qual package directory if it exists, or null if no jar or directory
* contains the package
*
* @return a URL to the jar that contains the qual package, or to the qual package's directory,
* or null if no jar or directory contains the qual package
*/
@Nullable
private final URL getURLFromClasspaths() {
// Debug use, uncomment if needed to see all of the classpaths (boot
// classpath, extension classpath, and classpath)
// printPaths();
URL url = null;
// obtain all classpaths
Set<String> paths = getClasspaths();
// or environment variables will decide which one gets examined first
for (String path : paths) {
// see if the current classpath segment is a jar or a directory
if (path.endsWith(JAR_SUFFIX)) {
// current classpath segment is a jar
url = getJarURL(path);
// see if the jar contains the package
if (url != null && containsPackage(url)) {
return url;
}
} else {
// current classpath segment is a directory
url = getDirectoryURL(path);
// see if the directory contains the package
if (url != null && containsPackage(url)) {
// append a slash if necessary
if (!path.endsWith(Character.toString(SLASH))) {
path += SLASH;
}
// update URL to the qual directory
url = getDirectoryURL(path + packageNameWithSlashes);
return url;
}
}
}
// if no jar or directory contains the qual package, then return null
return null;
}
use of org.checkerframework.checker.nullness.qual.Nullable in project checker-framework by typetools.
the class UnitsRelationsTools method getPrefix.
/**
* Retrieves the SI Prefix of an Annotation
*
* @param unitsAnnotation an AnnotationMirror representing a Units Annotation
* @return a Prefix value (including Prefix.one), or null if it has none
*/
@Nullable
public static Prefix getPrefix(@Nullable final AnnotationMirror unitsAnnotation) {
AnnotationValue annotationValue = getAnnotationMirrorPrefix(unitsAnnotation);
// if this Annotation has no prefix, return null
if (hasNoPrefix(annotationValue)) {
return null;
}
// if the Annotation has a value, then detect and match the string name of the prefix, and
// return the matching Prefix
String prefixString = annotationValue.getValue().toString();
for (Prefix prefix : Prefix.values()) {
if (prefixString.equals(prefix.toString())) {
return prefix;
}
}
// if none of the strings match, then return null
return null;
}
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