Search in sources :

Example 1 with Nullable

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;
}
Also used : TreePath(com.sun.source.util.TreePath) BlockTree(com.sun.source.tree.BlockTree) Nullable(org.checkerframework.checker.nullness.qual.Nullable)

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

Example 3 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 4 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 5 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)285 ArrayList (java.util.ArrayList)27 TypeElement (javax.lang.model.element.TypeElement)23 IOException (java.io.IOException)21 Map (java.util.Map)21 ExecutableElement (javax.lang.model.element.ExecutableElement)19 ServerLevel (net.minecraft.server.level.ServerLevel)19 List (java.util.List)16 Instant (org.joda.time.Instant)16 VariableElement (javax.lang.model.element.VariableElement)15 HashMap (java.util.HashMap)14 Optional (java.util.Optional)14 Element (javax.lang.model.element.Element)13 TreePath (com.sun.source.util.TreePath)12 BlockPos (net.minecraft.core.BlockPos)12 Method (java.lang.reflect.Method)11 BlockEntity (net.minecraft.world.level.block.entity.BlockEntity)11 MonotonicNonNull (org.checkerframework.checker.nullness.qual.MonotonicNonNull)10 VariableTree (com.sun.source.tree.VariableTree)8 ClassTree (com.sun.source.tree.ClassTree)7