use of org.checkerframework.javacutil.BugInCF in project checker-framework by typetools.
the class TypeVarUseApplier method getParameterAnnos.
/**
* Currently, the metadata for storing annotations (i.e. the Attribute.TypeCompounds) is null for
* binary-only parameters and type parameters. However, it is present on the method. So in order
* to ensure that we correctly retrieve the annotations we need to index from the method and
* retrieve the annotations from its metadata.
*
* @return a list of annotations that were found on METHOD_FORMAL_PARAMETERS that match the
* parameter index of the input element in the parent methods formal parameter list
*/
private static List<Attribute.TypeCompound> getParameterAnnos(final Element paramElem) {
final Element enclosingElement = paramElem.getEnclosingElement();
if (!(enclosingElement instanceof ExecutableElement)) {
throw new BugInCF("Bad element passed to TypeFromElement.getTypeParameterAnnotationAttributes: " + "element: " + paramElem + " not found in enclosing executable: " + enclosingElement);
}
final MethodSymbol enclosingMethod = (MethodSymbol) enclosingElement;
if (enclosingMethod.getKind() != ElementKind.CONSTRUCTOR && enclosingMethod.getKind() != ElementKind.METHOD) {
// Initializer blocks don't have parameters, so there is nothing to do.
return Collections.emptyList();
}
// TODO: for the parameter in a lambda expression, the enclosingMethod isn't
// the lambda expression. Does this read the correct annotations?
final int paramIndex = enclosingMethod.getParameters().indexOf(paramElem);
final List<Attribute.TypeCompound> annotations = enclosingMethod.getRawTypeAttributes();
final List<Attribute.TypeCompound> result = new ArrayList<>();
for (final Attribute.TypeCompound typeAnno : annotations) {
if (typeAnno.position.type == TargetType.METHOD_FORMAL_PARAMETER) {
if (typeAnno.position.parameter_index == paramIndex) {
result.add(typeAnno);
}
}
}
return result;
}
use of org.checkerframework.javacutil.BugInCF in project checker-framework by typetools.
the class TypeVarUseApplier method getReturnAnnos.
/**
* Returns the annotations on the return type of the input ExecutableElement.
*
* @param methodElem the method whose return type annotations to return
* @return the annotations on the return type of the input ExecutableElement
*/
private static List<Attribute.TypeCompound> getReturnAnnos(final Element methodElem) {
if (!(methodElem instanceof ExecutableElement)) {
throw new BugInCF("Bad element passed to TypeVarUseApplier.getReturnAnnos:" + methodElem);
}
final MethodSymbol enclosingMethod = (MethodSymbol) methodElem;
final List<Attribute.TypeCompound> annotations = enclosingMethod.getRawTypeAttributes();
final List<Attribute.TypeCompound> result = new ArrayList<>();
for (final Attribute.TypeCompound typeAnno : annotations) {
if (typeAnno.position.type == TargetType.METHOD_RETURN) {
result.add(typeAnno);
}
}
return result;
}
use of org.checkerframework.javacutil.BugInCF in project checker-framework by typetools.
the class SceneToStubWriter method printClassDefinitions.
/**
* Print the hierarchy of outer classes up to and including the given class, and return the number
* of curly braces to close with. The classes are printed with appropriate opening curly braces,
* in standard Java style.
*
* <p>In an AScene, an inner class name is a binary name like "Outer$Inner". In a stub file, inner
* classes must be nested, as in Java source code.
*
* @param basename the binary name of the class without the package part
* @param aClass the AClass for {@code basename}
* @param printWriter the writer where the class definition should be printed
* @param checker the type-checker whose annotations are being written
* @return the number of outer classes within which this class is nested
*/
private static int printClassDefinitions(String basename, AClass aClass, PrintWriter printWriter, BaseTypeChecker checker) {
String[] classNames = basename.split("\\$");
TypeElement innermostTypeElt = aClass.getTypeElement();
if (innermostTypeElt == null) {
throw new BugInCF("typeElement was unexpectedly null in this aClass: " + aClass);
}
TypeElement[] typeElements = getTypeElementsForClasses(innermostTypeElt, classNames);
for (int i = 0; i < classNames.length; i++) {
String nameToPrint = classNames[i];
if (i == classNames.length - 1) {
printWriter.print(indents(i));
printWriter.println("@AnnotatedFor(\"" + checker.getClass().getCanonicalName() + "\")");
}
printWriter.print(indents(i));
if (aClass.isEnum(nameToPrint)) {
printWriter.print("enum ");
} else {
printWriter.print("class ");
}
if (i == classNames.length - 1) {
// Only print class annotations on the innermost class, which corresponds to aClass.
// If there should be class annotations on another class, it will have its own stub
// file, which will eventually be merged with this one.
printWriter.print(formatAnnotations(aClass.getAnnotations()));
}
printWriter.print(nameToPrint);
printTypeParameters(typeElements[i], printWriter);
printWriter.println(" {");
if (aClass.isEnum(nameToPrint) && i != classNames.length - 1) {
// Print a blank set of enum constants if this is an outer enum.
printWriter.println(indents(i + 1) + "/* omitted enum constants */ ;");
}
printWriter.println();
}
return classNames.length;
}
use of org.checkerframework.javacutil.BugInCF in project checker-framework by typetools.
the class WholeProgramInferenceImplementation method updateFromFieldAssignment.
@Override
public void updateFromFieldAssignment(Node lhs, Node rhs) {
Element element;
String fieldName;
if (lhs instanceof FieldAccessNode) {
element = ((FieldAccessNode) lhs).getElement();
fieldName = ((FieldAccessNode) lhs).getFieldName();
} else if (lhs instanceof LocalVariableNode) {
element = ((LocalVariableNode) lhs).getElement();
fieldName = ((LocalVariableNode) lhs).getName();
} else {
throw new BugInCF("updateFromFieldAssignment received an unexpected node type: " + lhs.getClass());
}
// TODO: For a primitive such as long, this is yielding just @GuardedBy rather than
// @GuardedBy({}).
AnnotatedTypeMirror rhsATM = atypeFactory.getAnnotatedType(rhs.getTree());
atypeFactory.wpiAdjustForUpdateField(lhs.getTree(), element, fieldName, rhsATM);
updateFieldFromType(lhs.getTree(), element, fieldName, rhsATM);
}
use of org.checkerframework.javacutil.BugInCF in project checker-framework by typetools.
the class WholeProgramInferenceScenesStorage method writeResultsToFile.
@Override
public void writeResultsToFile(WholeProgramInference.OutputFormat outputFormat, BaseTypeChecker checker) {
if (outputFormat == OutputFormat.AJAVA) {
throw new BugInCF("WholeProgramInferenceScenes used with format " + outputFormat);
}
for (String file : modifiedScenes) {
ASceneWrapper scene = scenes.get(file);
prepareSceneForWriting(scene.getAScene());
}
writeScenes(outputFormat, checker);
}
Aggregations