Search in sources :

Example 6 with Nullable

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;
}
Also used : TypeElement(javax.lang.model.element.TypeElement) VariableElement(javax.lang.model.element.VariableElement) Nullable(org.checkerframework.checker.nullness.qual.Nullable)

Example 7 with Nullable

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;
    }
}
Also used : AnnotationMirror(javax.lang.model.element.AnnotationMirror) AnnotationBuilder(org.checkerframework.javacutil.AnnotationBuilder) TypeElement(javax.lang.model.element.TypeElement) Nullable(org.checkerframework.checker.nullness.qual.Nullable)

Example 8 with Nullable

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;
}
Also used : URL(java.net.URL) Nullable(org.checkerframework.checker.nullness.qual.Nullable)

Example 9 with Nullable

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;
}
Also used : AnnotationValue(javax.lang.model.element.AnnotationValue) Prefix(org.checkerframework.checker.units.qual.Prefix) Nullable(org.checkerframework.checker.nullness.qual.Nullable)

Example 10 with Nullable

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();
    }
}
Also used : ReentrantLock(java.util.concurrent.locks.ReentrantLock) Nullable(org.checkerframework.checker.nullness.qual.Nullable)

Aggregations

Nullable (org.checkerframework.checker.nullness.qual.Nullable)27 TypeElement (javax.lang.model.element.TypeElement)7 VariableElement (javax.lang.model.element.VariableElement)4 TreePath (com.sun.source.util.TreePath)3 Method (java.lang.reflect.Method)3 ReentrantLock (java.util.concurrent.locks.ReentrantLock)3 Element (javax.lang.model.element.Element)3 ClassTree (com.sun.source.tree.ClassTree)2 MethodTree (com.sun.source.tree.MethodTree)2 VariableTree (com.sun.source.tree.VariableTree)2 ExecutableElement (javax.lang.model.element.ExecutableElement)2 PackageElement (javax.lang.model.element.PackageElement)2 Prefix (org.checkerframework.checker.units.qual.Prefix)2 AssignmentNode (org.checkerframework.dataflow.cfg.node.AssignmentNode)2 Node (org.checkerframework.dataflow.cfg.node.Node)2 Pure (org.checkerframework.dataflow.qual.Pure)2 AnnotationBuilder (org.checkerframework.javacutil.AnnotationBuilder)2 AnnotationTree (com.sun.source.tree.AnnotationTree)1 AssignmentTree (com.sun.source.tree.AssignmentTree)1 BlockTree (com.sun.source.tree.BlockTree)1