Search in sources :

Example 81 with Nullable

use of org.checkerframework.checker.nullness.qual.Nullable in project checker-framework by typetools.

the class SystemUtil method getReleaseValue.

/**
 * Returns the release value passed to the compiler or null if release was not passed.
 *
 * @param env the ProcessingEnvironment
 * @return the release value or null if none was passed
 */
@Nullable
public static String getReleaseValue(ProcessingEnvironment env) {
    Context ctx = ((JavacProcessingEnvironment) env).getContext();
    Options options = Options.instance(ctx);
    return options.get(Option.RELEASE);
}
Also used : Context(com.sun.tools.javac.util.Context) Options(com.sun.tools.javac.util.Options) JavacProcessingEnvironment(com.sun.tools.javac.processing.JavacProcessingEnvironment) Nullable(org.checkerframework.checker.nullness.qual.Nullable)

Example 82 with Nullable

use of org.checkerframework.checker.nullness.qual.Nullable in project checker-framework by typetools.

the class ElementUtils method enclosingPackage.

/**
 * Returns the innermost package element enclosing the given element. The same effect as {@link
 * javax.lang.model.util.Elements#getPackageOf(Element)}. Returns the element itself if it is a
 * package.
 *
 * @param elem the enclosed element of a package
 * @return the innermost package element
 */
public static PackageElement enclosingPackage(final Element elem) {
    Element result = elem;
    while (result != null && result.getKind() != ElementKind.PACKAGE) {
        @Nullable Element encl = result.getEnclosingElement();
        result = encl;
    }
    return (PackageElement) result;
}
Also used : PackageElement(javax.lang.model.element.PackageElement) VariableElement(javax.lang.model.element.VariableElement) TypeElement(javax.lang.model.element.TypeElement) ExecutableElement(javax.lang.model.element.ExecutableElement) Element(javax.lang.model.element.Element) PackageElement(javax.lang.model.element.PackageElement) Nullable(org.checkerframework.checker.nullness.qual.Nullable)

Example 83 with Nullable

use of org.checkerframework.checker.nullness.qual.Nullable in project checker-framework by typetools.

the class RegexUtil method regexError.

/**
 * Returns null if the argument is a syntactically valid regular expression with at least the
 * given number of groups. Otherwise returns a string describing why the argument is not a regex.
 *
 * @param s string to check for being a regular expression
 * @param groups number of groups expected
 * @return null, or a string describing why the argument is not a regex
 */
// RegexUtil;
@SuppressWarnings({ "regex", "not.sef" })
@SideEffectFree
@Nullable
public static String regexError(String s, int groups) {
    try {
        Pattern p = Pattern.compile(s);
        int actualGroups = getGroupCount(p);
        if (actualGroups < groups) {
            return regexErrorMessage(s, groups, actualGroups);
        }
    } catch (PatternSyntaxException e) {
        return e.getMessage();
    }
    return null;
}
Also used : Pattern(java.util.regex.Pattern) PatternSyntaxException(java.util.regex.PatternSyntaxException) SideEffectFree(org.checkerframework.dataflow.qual.SideEffectFree) Nullable(org.checkerframework.checker.nullness.qual.Nullable)

Example 84 with Nullable

use of org.checkerframework.checker.nullness.qual.Nullable in project checker-framework by typetools.

the class AnnotationFileParser method findAnnotatedType.

/**
 * Return the annotated type corresponding to {@code type}, or null if none exists. More
 * specifically, returns the element of {@code types} whose name matches {@code type}.
 *
 * @param type the type to search for
 * @param types the list of AnnotatedDeclaredTypes to search in
 * @param astNode where to report errors
 * @return the annotated type in {@code types} corresponding to {@code type}, or null if none
 *     exists
 */
@Nullable
private AnnotatedDeclaredType findAnnotatedType(ClassOrInterfaceType type, List<AnnotatedDeclaredType> types, NodeWithRange<?> astNode) {
    String typeString = type.getNameAsString();
    for (AnnotatedDeclaredType supertype : types) {
        if (supertype.getUnderlyingType().asElement().getSimpleName().contentEquals(typeString)) {
            return supertype;
        }
    }
    stubWarnNotFound(astNode, "Supertype " + typeString + " not found");
    if (debugAnnotationFileParser) {
        stubDebug("Supertypes that were searched:");
        for (AnnotatedDeclaredType supertype : types) {
            stubDebug(String.format("  %s", supertype));
        }
    }
    return null;
}
Also used : AnnotatedDeclaredType(org.checkerframework.framework.type.AnnotatedTypeMirror.AnnotatedDeclaredType) Nullable(org.checkerframework.checker.nullness.qual.Nullable)

Example 85 with Nullable

use of org.checkerframework.checker.nullness.qual.Nullable in project checker-framework by typetools.

the class TypeAnnotationMover method getAnnotationDeclaration.

/**
 * Returns the TypeElement for an annotation, or null if it cannot be found.
 *
 * @param annotation a JavaParser annotation
 * @return the TypeElement for {@code annotation}, or null if it cannot be found
 */
@Nullable
private TypeElement getAnnotationDeclaration(AnnotationExpr annotation) {
    // https://tinyurl.com/cfissue/3094
    @SuppressWarnings("signature") @FullyQualifiedName String annoNameFq = annotation.getNameAsString();
    TypeElement annoTypeElt = allAnnotations.get(annoNameFq);
    if (annoTypeElt == null) {
        annoTypeElt = elements.getTypeElement(annoNameFq);
        if (annoTypeElt == null) {
            // Not a supported annotation.
            return null;
        }
        AnnotationFileParser.putAllNew(allAnnotations, AnnotationFileParser.createNameToAnnotationMap(Collections.singletonList(annoTypeElt)));
    }
    return annoTypeElt;
}
Also used : TypeElement(javax.lang.model.element.TypeElement) FullyQualifiedName(org.checkerframework.checker.signature.qual.FullyQualifiedName) 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