use of org.checkerframework.javacutil.BugInCF in project checker-framework by typetools.
the class GenericAnnotatedTypeFactory method getAnnotatedTypeVarargsArray.
/**
* Returns the type of a varargs array of a method invocation or a constructor invocation. Returns
* null only if private field {@code useFlow} is false.
*
* @param tree a method invocation or a constructor invocation
* @return AnnotatedTypeMirror of varargs array for a method or constructor invocation {@code
* tree}; returns null if private field {@code useFlow} is false
*/
@Nullable
public AnnotatedTypeMirror getAnnotatedTypeVarargsArray(Tree tree) {
if (!useFlow) {
return null;
}
// Get the synthetic NewArray tree that dataflow creates as the last argument of a call to a
// vararg method. Do this by getting the MethodInvocationNode to which "tree" maps. The last
// argument node of the MethodInvocationNode stores the synthetic NewArray tree.
List<Node> args;
switch(tree.getKind()) {
case METHOD_INVOCATION:
args = getFirstNodeOfKindForTree(tree, MethodInvocationNode.class).getArguments();
break;
case NEW_CLASS:
args = getFirstNodeOfKindForTree(tree, ObjectCreationNode.class).getArguments();
break;
default:
throw new BugInCF("Unexpected kind of tree: " + tree);
}
assert !args.isEmpty() : "Arguments are empty";
Node varargsArray = args.get(args.size() - 1);
AnnotatedTypeMirror varargtype = getAnnotatedType(varargsArray.getTree());
return varargtype;
}
use of org.checkerframework.javacutil.BugInCF in project checker-framework by typetools.
the class GenericAnnotatedTypeFactory method getPostconditionAnnotations.
/**
* Return the postcondition annotations for the given AMethod. Does not modify the AMethod. This
* method must only be called when using WholeProgramInferenceScenes.
*
* @param m AFU representation of a method
* @param preconds the precondition annotations for the method; used to suppress redundant
* postconditions
* @return postcondition annotations for the method
*/
public List<AnnotationMirror> getPostconditionAnnotations(AMethod m, List<AnnotationMirror> preconds) {
List<AnnotationMirror> result = new ArrayList<>(m.getPostconditions().size());
for (Map.Entry<String, AField> entry : m.getPostconditions().entrySet()) {
WholeProgramInferenceImplementation<?> wholeProgramInference = (WholeProgramInferenceImplementation<?>) getWholeProgramInference();
WholeProgramInferenceScenesStorage storage = (WholeProgramInferenceScenesStorage) wholeProgramInference.getStorage();
TypeMirror typeMirror = entry.getValue().getTypeMirror();
if (typeMirror == null) {
throw new BugInCF("null TypeMirror in AField inferred by WPI postcondition inference. AField: " + entry.getValue().toString());
}
AnnotatedTypeMirror declaredType = storage.getPostconditionDeclaredType(m, entry.getKey());
AnnotatedTypeMirror inferredType = storage.atmFromStorageLocation(typeMirror, entry.getValue().type);
result.addAll(getPostconditionAnnotations(entry.getKey(), inferredType, declaredType, preconds));
}
Collections.sort(result, Ordering.usingToString());
return result;
}
use of org.checkerframework.javacutil.BugInCF in project checker-framework by typetools.
the class QualifierHierarchy method greatestLowerBounds.
/**
* Returns the greatest lower bound of the two sets of qualifiers. The result is the lub of the
* qualifier for the same hierarchy in each set.
*
* @param qualifiers1 set of qualifiers; exactly one per hierarchy
* @param qualifiers2 set of qualifiers; exactly one per hierarchy
* @return the greatest lower bound of the two sets of qualifiers
*/
default Set<? extends AnnotationMirror> greatestLowerBounds(Collection<? extends AnnotationMirror> qualifiers1, Collection<? extends AnnotationMirror> qualifiers2) {
assertSameSize(qualifiers1, qualifiers2);
if (qualifiers1.isEmpty()) {
throw new BugInCF("QualifierHierarchy.greatestLowerBounds: tried to determine GLB with empty sets");
}
Set<AnnotationMirror> result = AnnotationUtils.createAnnotationSet();
for (AnnotationMirror a1 : qualifiers1) {
for (AnnotationMirror a2 : qualifiers2) {
AnnotationMirror glb = greatestLowerBound(a1, a2);
if (glb != null) {
result.add(glb);
}
}
}
assertSameSize(qualifiers1, qualifiers2, result);
return result;
}
use of org.checkerframework.javacutil.BugInCF in project checker-framework by typetools.
the class AnnotationClassLoader method loadBundledAnnotationClasses.
/**
* Loads the set of annotation classes in the qual directory of a checker shipped with the Checker
* Framework.
*/
private void loadBundledAnnotationClasses() {
// retrieve the fully qualified class names of the annotations
Set<@BinaryName String> annotationNames;
// see whether the resource URL has a protocol of jar or file
if (resourceURL != null && resourceURL.getProtocol().contentEquals("jar")) {
// if the checker class file is contained within a jar, then the resource URL for the qual
// directory will have the protocol "jar". This means the whole checker is loaded as a jar
// file.
JarURLConnection connection;
// create a connection to the jar file
try {
connection = (JarURLConnection) resourceURL.openConnection();
// disable caching / connection sharing of the low level URLConnection to the Jar file
connection.setDefaultUseCaches(false);
connection.setUseCaches(false);
// connect to the Jar file
connection.connect();
} catch (IOException e) {
throw new BugInCF("AnnotationClassLoader: cannot open a connection to the Jar file " + resourceURL.getFile());
}
// open up that jar file and extract annotation class names
try (JarFile jarFile = connection.getJarFile()) {
// get class names inside the jar file within the particular package
annotationNames = getBundledAnnotationNamesFromJar(jarFile);
} catch (IOException e) {
throw new BugInCF("AnnotationClassLoader: cannot open the Jar file " + resourceURL.getFile());
}
} else if (resourceURL != null && resourceURL.getProtocol().contentEquals("file")) {
// If the checker class file is found within the file system itself within some directory
// (usually development build directories), then process the package as a file directory in
// the file system and load the annotations contained in the qual directory.
// open up the directory
File packageDir = new File(resourceURL.getFile());
annotationNames = getAnnotationNamesFromDirectory(packageName, packageDir, packageDir);
} else {
// We do not support a resource URL with any other protocols, so create an empty set.
annotationNames = Collections.emptySet();
}
if (annotationNames.isEmpty()) {
PackageElement pkgEle = checker.getElementUtils().getPackageElement(packageName);
if (pkgEle != null) {
for (Element e : pkgEle.getEnclosedElements()) {
if (e.getKind() == ElementKind.ANNOTATION_TYPE) {
// Elements needs to be annotated.
@SuppressWarnings("signature:assignment") @BinaryName String annoBinName = checker.getElementUtils().getBinaryName((TypeElement) e).toString();
annotationNames.add(annoBinName);
}
}
}
}
supportedBundledAnnotationClasses.addAll(loadAnnotationClasses(annotationNames));
}
use of org.checkerframework.javacutil.BugInCF in project checker-framework by typetools.
the class DefaultInferredTypesApplier method removePrimaryAnnotationTypeVar.
private void removePrimaryAnnotationTypeVar(AnnotatedTypeVariable annotatedTypeVariable, TypeMirror inferredTypeMirror, AnnotationMirror top, AnnotationMirror previousAnnotation) {
if (inferredTypeMirror.getKind() != TypeKind.TYPEVAR) {
throw new BugInCF("Missing annos");
}
TypeVariable typeVar = (TypeVariable) inferredTypeMirror;
AnnotatedTypeVariable typeVariableDecl = (AnnotatedTypeVariable) factory.getAnnotatedType(typeVar.asElement());
AnnotationMirror upperBound = typeVariableDecl.getEffectiveAnnotationInHierarchy(top);
if (omitSubtypingCheck || hierarchy.isSubtype(upperBound, previousAnnotation)) {
annotatedTypeVariable.removeAnnotationInHierarchy(top);
AnnotationMirror ub = typeVariableDecl.getUpperBound().getAnnotationInHierarchy(top);
apply(annotatedTypeVariable.getUpperBound(), ub, typeVar.getUpperBound(), top);
AnnotationMirror lb = typeVariableDecl.getLowerBound().getAnnotationInHierarchy(top);
apply(annotatedTypeVariable.getLowerBound(), lb, typeVar.getLowerBound(), top);
}
}
Aggregations