use of org.checkerframework.checker.nullness.qual.Nullable in project checker-framework by typetools.
the class StubParser method findTypeOfName.
/**
* Returns the TypeElement with the name {@code name}, if one exists. Otherwise, checks the
* class and package of {@code parseState} for a class named {@code name}.
*
* @param name classname (simple, or Outer.Inner, or fully-qualified)
* @return the TypeElement for {@code name}, or null if not found
*/
@Nullable
private TypeElement findTypeOfName(String name) {
String packageName = parseState.packageName;
String packagePrefix = (packageName == null) ? "" : packageName + ".";
// stubWarn("findTypeOfName(%s), parseState %s %s%n", name, packageName, enclosingClass);
// As soon as typeElement is set to a non-null value, it will be returned.
TypeElement typeElement = getTypeElementOrNull(name);
if (typeElement == null && packageName != null) {
typeElement = getTypeElementOrNull(packagePrefix + name);
}
String enclosingClass = parseState.className;
while (typeElement == null && enclosingClass != null) {
typeElement = getTypeElementOrNull(packagePrefix + enclosingClass + "." + name);
int lastDot = enclosingClass.lastIndexOf('.');
if (lastDot == -1) {
break;
} else {
enclosingClass = enclosingClass.substring(0, lastDot);
}
}
if (typeElement == null && !"java.lang".equals(packageName)) {
typeElement = getTypeElementOrNull("java.lang." + name);
}
return typeElement;
}
use of org.checkerframework.checker.nullness.qual.Nullable in project checker-framework by typetools.
the class AnnotatedTypeFactory method getCurrentMethodReceiver.
/**
* Returns the receiver type of the current method being visited, and returns null if the
* visited tree is not within a method or if that method has no receiver (e.g. a static method).
*
* <p>The method uses the parameter only if the most enclosing method cannot be found directly.
*
* @return receiver type of the most enclosing method being visited
*/
@Nullable
protected final AnnotatedDeclaredType getCurrentMethodReceiver(Tree tree) {
AnnotatedDeclaredType res = visitorState.getMethodReceiver();
if (res == null) {
TreePath path = getPath(tree);
if (path != null) {
MethodTree enclosingMethod = TreeUtils.enclosingMethod(path);
ClassTree enclosingClass = TreeUtils.enclosingClass(path);
boolean found = false;
for (Tree member : enclosingClass.getMembers()) {
if (member.getKind() == Tree.Kind.METHOD) {
if (member == enclosingMethod) {
found = true;
}
}
}
if (found && enclosingMethod != null) {
AnnotatedExecutableType method = getAnnotatedType(enclosingMethod);
res = method.getReceiverType();
// TODO: three tests fail if one adds the following, which would make
// sense, or not?
// visitorState.setMethodReceiver(res);
} else {
// We are within an anonymous class or field initializer
res = this.getAnnotatedType(enclosingClass);
}
}
}
return res;
}
use of org.checkerframework.checker.nullness.qual.Nullable in project checker-framework by typetools.
the class UnitsRelationsDefault method multiplication.
/**
* Provides rules for resolving the result Unit of the multiplication of checker-framework
* provided Units
*/
@Override
@Nullable
public AnnotationMirror multiplication(AnnotatedTypeMirror lht, AnnotatedTypeMirror rht) {
// checking SI units only
if (UnitsRelationsTools.hasSpecificUnitIgnoringPrefix(lht, m) && UnitsRelationsTools.hasSpecificUnitIgnoringPrefix(rht, m)) {
if (UnitsRelationsTools.hasNoPrefix(lht) && UnitsRelationsTools.hasNoPrefix(rht)) {
// m * m
return m2;
}
Prefix lhtPrefix = UnitsRelationsTools.getPrefix(lht);
Prefix rhtPrefix = UnitsRelationsTools.getPrefix(rht);
if (bothHaveSpecificPrefix(lhtPrefix, rhtPrefix, Prefix.kilo)) {
// km * km
return km2;
} else if (bothHaveSpecificPrefix(lhtPrefix, rhtPrefix, Prefix.one)) {
// m(Prefix.one) * m(Prefix.one)
return m2;
} else if (bothHaveSpecificPrefix(lhtPrefix, rhtPrefix, Prefix.milli)) {
// mm * mm
return mm2;
} else {
return null;
}
} else if (havePairOfUnitsIgnoringOrder(lht, s, rht, mPERs)) {
// s * mPERs or mPERs * s => m
return m;
} else if (havePairOfUnitsIgnoringOrder(lht, s, rht, mPERs2)) {
// s * mPERs2 or mPERs2 * s => mPERs
return mPERs;
} else if (havePairOfUnitsIgnoringOrder(lht, h, rht, kmPERh)) {
// h * kmPERh or kmPERh * h => km
return km;
} else {
return null;
}
}
use of org.checkerframework.checker.nullness.qual.Nullable in project checker-framework by typetools.
the class UnitsRelationsTools method buildAnnoMirrorWithSpecificPrefix.
/**
* Creates an AnnotationMirror representing a unit defined by annoClass, with the specific
* Prefix p
*
* @param env the Checker Processing Environment, provided as a parameter in init() of a
* UnitsRelations implementation
* @param annoClass the Class of an Annotation representing a Unit (eg m.class for meters)
* @param p a Prefix value
* @return an AnnotationMirror of the Unit with the Prefix p, or null if it cannot be
* constructed
*/
@Nullable
public static AnnotationMirror buildAnnoMirrorWithSpecificPrefix(final ProcessingEnvironment env, final Class<? extends Annotation> annoClass, final Prefix p) {
if (env == null || annoClass == null || p == null) {
return null;
}
AnnotationBuilder builder = new AnnotationBuilder(env, annoClass);
builder.setValue("value", p);
return builder.build();
}
use of org.checkerframework.checker.nullness.qual.Nullable in project checker-framework by typetools.
the class ElementUtils method enclosingClass.
/**
* Returns the innermost type element enclosing the given element
*
* @param elem the enclosed element of a class
* @return the innermost type element
*/
public static TypeElement enclosingClass(final Element elem) {
Element result = elem;
while (result != null && !result.getKind().isClass() && !result.getKind().isInterface()) {
@Nullable Element encl = result.getEnclosingElement();
result = encl;
}
return (TypeElement) result;
}
Aggregations