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);
}
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;
}
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;
}
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;
}
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;
}
Aggregations