public class WholeProgramInferenceScenesStorage extends Object implements WholeProgramInferenceStorage<scenelib.annotations.el.ATypeElement>
The set of annotations inferred for a certain class is stored in an AScene
, which writeScenes()
can write into a file. For example,
a class my.pakkage.MyClass
will have its members' inferred types stored in a Scene, and
later written into a file named my.pakkage.MyClass.jaif
if using WholeProgramInference.OutputFormat.JAIF
, or my.pakkage.MyClass.astub
if using WholeProgramInference.OutputFormat.STUB
.
This class populates the initial Scenes by reading existing .jaif files on the JAIF_FILES_PATH
directory (regardless of output format). Having more information in those
initial .jaif files means that the precision achieved by the whole-program inference analysis
will be better. writeScenes(org.checkerframework.common.wholeprograminference.WholeProgramInference.OutputFormat, org.checkerframework.common.basetype.BaseTypeChecker)
rewrites the initial .jaif files and may create new ones.
Modifier and Type | Class and Description |
---|---|
static class |
WholeProgramInferenceScenesStorage.AnnotationsInContexts
Maps the
aTypeElementToString(scenelib.annotations.el.ATypeElement) representation of an ATypeElement and its
TypeUseLocation to a set of names of annotations. |
Modifier and Type | Field and Description |
---|---|
protected AnnotatedTypeFactory |
atypeFactory
The type factory associated with this WholeProgramInferenceScenesStorage.
|
static String |
JAIF_FILES_PATH
Directory where .jaif files will be written to and read from.
|
Set<String> |
modifiedScenes
Scenes that were modified since the last time all Scenes were written into .jaif files.
|
Map<String,ASceneWrapper> |
scenes
Maps .jaif file paths (Strings) to Scenes.
|
Constructor and Description |
---|
WholeProgramInferenceScenesStorage(AnnotatedTypeFactory atypeFactory)
Default constructor.
|
Modifier and Type | Method and Description |
---|---|
boolean |
addMethodDeclarationAnnotation(ExecutableElement methodElt,
AnnotationMirror anno)
Updates a method to add a declaration annotation.
|
AnnotatedTypeMirror |
atmFromStorageLocation(TypeMirror typeMirror,
scenelib.annotations.el.ATypeElement storageLocation)
Obtain the type from a storage location.
|
static String |
aTypeElementToString(scenelib.annotations.el.ATypeElement aType)
Returns a string representation of an ATypeElement, for use as part of a key in
WholeProgramInferenceScenesStorage.AnnotationsInContexts . |
protected scenelib.annotations.el.AClass |
getAClass(@BinaryName String className,
String jaifPath)
Returns the scene-lib representation of the given className in the scene identified by the
given jaifPath.
|
protected scenelib.annotations.el.AClass |
getAClass(@BinaryName String className,
String jaifPath,
@Nullable com.sun.tools.javac.code.Symbol.ClassSymbol classSymbol)
Returns the scene-lib representation of the given className in the scene identified by the
given jaifPath.
|
scenelib.annotations.el.ATypeElement |
getFieldAnnotations(Element element,
String fieldName,
AnnotatedTypeMirror lhsATM,
AnnotatedTypeFactory atypeFactory)
Get the annotations for a field type.
|
String |
getFileForElement(Element elt)
Returns the file corresponding to the given element.
|
protected String |
getJaifPath(String className)
Returns the String representing the .jaif path of a class given its name.
|
scenelib.annotations.el.ATypeElement |
getParameterAnnotations(ExecutableElement methodElt,
int i,
AnnotatedTypeMirror paramATM,
VariableElement ve,
AnnotatedTypeFactory atypeFactory)
Get the annotations for a formal parameter type.
|
AnnotatedTypeMirror |
getPostconditionDeclaredType(scenelib.annotations.el.AMethod m,
String expression)
Fetches the declared type of an expression for which a postcondition was inferred, for the
given AMethod.
|
AnnotatedTypeMirror |
getPreconditionDeclaredType(scenelib.annotations.el.AMethod m,
String expression)
Fetches the declared type of an expression for which a precondition was inferred, for the given
AMethod.
|
scenelib.annotations.el.ATypeElement |
getPreOrPostconditions(Analysis.BeforeOrAfter preOrPost,
ExecutableElement methodElement,
String expression,
AnnotatedTypeMirror declaredType,
AnnotatedTypeFactory atypeFactory)
Returns the pre- or postcondition annotations for an expression.
|
scenelib.annotations.el.ATypeElement |
getReceiverAnnotations(ExecutableElement methodElt,
AnnotatedTypeMirror paramATM,
AnnotatedTypeFactory atypeFactory)
Get the annotations for the receiver type.
|
scenelib.annotations.el.ATypeElement |
getReturnAnnotations(ExecutableElement methodElt,
AnnotatedTypeMirror atm,
AnnotatedTypeFactory atypeFactory)
Get the annotations for the return type.
|
boolean |
hasStorageLocationForMethod(ExecutableElement methodElt)
Given an ExecutableElement in a compilation unit that has already been read into storage,
returns whether there exists a stored method matching
elt . |
void |
prepareClassForWriting(scenelib.annotations.el.AClass classAnnos)
Side-effects the class annotations to make any desired changes before writing to a file.
|
void |
prepareMethodForWriting(scenelib.annotations.el.AMethod methodAnnos)
Side-effects the method or constructor annotations to make any desired changes before writing
to a file.
|
void |
prepareSceneForWriting(scenelib.annotations.el.AScene compilationUnitAnnos)
Side-effects the compilation unit annotations to make any desired changes before writing to a
file.
|
void |
preprocessClassTree(ClassTree classTree)
Performs any preparation required for inference on the elements of a class.
|
void |
setFileModified(String path)
Indicates that inferred annotations for the file at
path have changed since last
written. |
protected void |
updateAnnotationSetInScene(scenelib.annotations.el.ATypeElement type,
TypeUseLocation defLoc,
AnnotatedTypeMirror rhsATM,
AnnotatedTypeMirror lhsATM,
String jaifPath,
boolean ignoreIfAnnotated)
Updates the set of annotations in a location of a Scene, as the result of a pseudo-assignment.
|
void |
updateStorageLocationFromAtm(AnnotatedTypeMirror newATM,
AnnotatedTypeMirror curATM,
scenelib.annotations.el.ATypeElement typeToUpdate,
TypeUseLocation defLoc,
boolean ignoreIfAnnotated)
Updates a storage location to have the annotations of the given
AnnotatedTypeMirror . |
void |
writeResultsToFile(WholeProgramInference.OutputFormat outputFormat,
BaseTypeChecker checker)
Writes the inferred results to a file.
|
void |
writeScenes(WholeProgramInference.OutputFormat outputFormat,
BaseTypeChecker checker)
Write all modified scenes into files.
|
public static final String JAIF_FILES_PATH
protected final AnnotatedTypeFactory atypeFactory
public final Map<String,ASceneWrapper> scenes
public final Set<String> modifiedScenes
getJaifPath(java.lang.String)
method.
Modifying a Scene means adding (or changing) a type annotation for a field, method return
type, or method parameter type in the Scene. (Scenes are modified by the method updateAnnotationSetInScene(scenelib.annotations.el.ATypeElement, org.checkerframework.framework.qual.TypeUseLocation, org.checkerframework.framework.type.AnnotatedTypeMirror, org.checkerframework.framework.type.AnnotatedTypeMirror, java.lang.String, boolean)
.)
public WholeProgramInferenceScenesStorage(AnnotatedTypeFactory atypeFactory)
atypeFactory
- the type factory associated with this WholeProgramInferenceScenesStoragepublic String getFileForElement(Element elt)
WholeProgramInferenceStorage
getFileForElement
in interface WholeProgramInferenceStorage<scenelib.annotations.el.ATypeElement>
elt
- an elementpublic boolean hasStorageLocationForMethod(ExecutableElement methodElt)
WholeProgramInferenceStorage
elt
.
An implementation is permitted to return false if elt
represents a method that was
synthetically added by javac, such as zero-argument constructors or valueOf(String) methods for
enum types.
hasStorageLocationForMethod
in interface WholeProgramInferenceStorage<scenelib.annotations.el.ATypeElement>
methodElt
- a method or constructor Elementelt
public scenelib.annotations.el.ATypeElement getParameterAnnotations(ExecutableElement methodElt, int i, AnnotatedTypeMirror paramATM, VariableElement ve, AnnotatedTypeFactory atypeFactory)
WholeProgramInferenceStorage
getParameterAnnotations
in interface WholeProgramInferenceStorage<scenelib.annotations.el.ATypeElement>
methodElt
- the method or constructor Elementi
- the parameter index (0-based)paramATM
- the parameter typeve
- the parameter variableatypeFactory
- the type factorypublic scenelib.annotations.el.ATypeElement getReceiverAnnotations(ExecutableElement methodElt, AnnotatedTypeMirror paramATM, AnnotatedTypeFactory atypeFactory)
WholeProgramInferenceStorage
getReceiverAnnotations
in interface WholeProgramInferenceStorage<scenelib.annotations.el.ATypeElement>
methodElt
- the method or constructor ElementparamATM
- the receiver typeatypeFactory
- the type factorypublic scenelib.annotations.el.ATypeElement getReturnAnnotations(ExecutableElement methodElt, AnnotatedTypeMirror atm, AnnotatedTypeFactory atypeFactory)
WholeProgramInferenceStorage
getReturnAnnotations
in interface WholeProgramInferenceStorage<scenelib.annotations.el.ATypeElement>
methodElt
- the method or constructor Elementatm
- the return typeatypeFactory
- the type factorypublic scenelib.annotations.el.ATypeElement getFieldAnnotations(Element element, String fieldName, AnnotatedTypeMirror lhsATM, AnnotatedTypeFactory atypeFactory)
WholeProgramInferenceStorage
getFieldAnnotations
in interface WholeProgramInferenceStorage<scenelib.annotations.el.ATypeElement>
element
- the element for the fieldfieldName
- the simple field namelhsATM
- the field typeatypeFactory
- the annotated type factorypublic scenelib.annotations.el.ATypeElement getPreOrPostconditions(Analysis.BeforeOrAfter preOrPost, ExecutableElement methodElement, String expression, AnnotatedTypeMirror declaredType, AnnotatedTypeFactory atypeFactory)
WholeProgramInferenceStorage
RequiresQualifier
or EnsuresQualifier
annotation.
This method may return null if the given expression is not a supported expression type. Currently, the supported expression types are: fields of "this" (e.g. "this.f", pre- and postconditions), "this" (postconditions only), and method parameters (e.g. "#1", "#2", postconditions only).
getPreOrPostconditions
in interface WholeProgramInferenceStorage<scenelib.annotations.el.ATypeElement>
preOrPost
- whether to get the precondition or postconditionmethodElement
- the methodexpression
- the expressiondeclaredType
- the declared type of the expressionatypeFactory
- the type factorypublic AnnotatedTypeMirror getPreconditionDeclaredType(scenelib.annotations.el.AMethod m, String expression)
m
- a methodexpression
- the expressionpublic AnnotatedTypeMirror getPostconditionDeclaredType(scenelib.annotations.el.AMethod m, String expression)
m
- a methodexpression
- the expressionpublic boolean addMethodDeclarationAnnotation(ExecutableElement methodElt, AnnotationMirror anno)
WholeProgramInferenceStorage
addMethodDeclarationAnnotation
in interface WholeProgramInferenceStorage<scenelib.annotations.el.ATypeElement>
methodElt
- the method to annotateanno
- the declaration annotation to add to the methodanno
is a new declaration annotation for methodElt
, false
otherwisepublic void writeScenes(WholeProgramInference.OutputFormat outputFormat, BaseTypeChecker checker)
updateAnnotationSetInScene(scenelib.annotations.el.ATypeElement, org.checkerframework.framework.qual.TypeUseLocation, org.checkerframework.framework.type.AnnotatedTypeMirror, org.checkerframework.framework.type.AnnotatedTypeMirror, java.lang.String, boolean)
.)outputFormat
- the output format to use when writing fileschecker
- the checker from which this method is called, for naming stub filesprotected String getJaifPath(String className)
className
- the simple name of a classprotected scenelib.annotations.el.AClass getAClass(@BinaryName String className, String jaifPath, @Nullable com.sun.tools.javac.code.Symbol.ClassSymbol classSymbol)
className
- the name of the class to get, in binary formjaifPath
- the path to the jaif file that would represent that class (must end in ".jaif")classSymbol
- optionally, the ClassSymbol representing the class. Used to set the symbol
information stored on an AClass.classSymbol
was non-nullprotected scenelib.annotations.el.AClass getAClass(@BinaryName String className, String jaifPath)
className
- the name of the class to get, in binary formjaifPath
- the path to the jaif file that would represent that class (must end in ".jaif")getAClass(String, String, com.sun.tools.javac.code.Symbol.ClassSymbol)
has
already been called with a non-null third argumentprotected void updateAnnotationSetInScene(scenelib.annotations.el.ATypeElement type, TypeUseLocation defLoc, AnnotatedTypeMirror rhsATM, AnnotatedTypeMirror lhsATM, String jaifPath, boolean ignoreIfAnnotated)
type
- ATypeElement of the Scene which will be modifiedjaifPath
- path to a .jaif file for a Scene; used for marking the scene as modified
(needing to be written to disk)rhsATM
- the RHS of the annotated type on the source codelhsATM
- the LHS of the annotated type on the source codedefLoc
- the location where the annotation will be addedignoreIfAnnotated
- if true, don't update any type that is explicitly annotated in the
source codepublic AnnotatedTypeMirror atmFromStorageLocation(TypeMirror typeMirror, scenelib.annotations.el.ATypeElement storageLocation)
WholeProgramInferenceStorage
atmFromStorageLocation
in interface WholeProgramInferenceStorage<scenelib.annotations.el.ATypeElement>
typeMirror
- the underlying type for the resultstorageLocation
- the storage location from which to obtain annotationstypeMirror
and annotations from
storageLocation
public void updateStorageLocationFromAtm(AnnotatedTypeMirror newATM, AnnotatedTypeMirror curATM, scenelib.annotations.el.ATypeElement typeToUpdate, TypeUseLocation defLoc, boolean ignoreIfAnnotated)
WholeProgramInferenceStorage
AnnotatedTypeMirror
.
Annotations in the original set that should be ignored are not added to the resulting set. If
ignoreIfAnnotated
is true, doesn't add annotations for locations with explicit
annotations in source code.
This method removes from the storage location all annotations supported by the
AnnotatedTypeFactory before inserting new ones. It is assumed that every time this method is
called, the new AnnotatedTypeMirror
has a better type estimate for the given location.
Therefore, it is not a problem to remove all annotations before inserting the new annotations.
The update*
methods in WholeProgramInference
perform LUB. This one just does
replacement. (Thus, the naming may be a bit confusing.)
updateStorageLocationFromAtm
in interface WholeProgramInferenceStorage<scenelib.annotations.el.ATypeElement>
newATM
- the type whose annotations will be added to the AnnotatedTypeMirror
curATM
- the annotations currently stored at the location, used to check if the element
that will be updated has explicit annotations in source codetypeToUpdate
- the storage location that will be updateddefLoc
- the location where the annotation will be addedignoreIfAnnotated
- if true, don't update any type that is explicitly annotated in the
source codepublic void prepareSceneForWriting(scenelib.annotations.el.AScene compilationUnitAnnos)
compilationUnitAnnos
- the compilation unit annotations to modifypublic void prepareClassForWriting(scenelib.annotations.el.AClass classAnnos)
classAnnos
- the class annotations to modifypublic void prepareMethodForWriting(scenelib.annotations.el.AMethod methodAnnos)
methodAnnos
- the method or constructor annotations to modifypublic void writeResultsToFile(WholeProgramInference.OutputFormat outputFormat, BaseTypeChecker checker)
WholeProgramInferenceStorage
writeResultsToFile
in interface WholeProgramInferenceStorage<scenelib.annotations.el.ATypeElement>
outputFormat
- the file format in which to write the resultschecker
- the checker from which this method is called, for naming annotation filespublic void setFileModified(String path)
WholeProgramInferenceStorage
path
have changed since last
written. This causes output files for path
to be written out next time WholeProgramInferenceStorage.writeResultsToFile(org.checkerframework.common.wholeprograminference.WholeProgramInference.OutputFormat, org.checkerframework.common.basetype.BaseTypeChecker)
is called.setFileModified
in interface WholeProgramInferenceStorage<scenelib.annotations.el.ATypeElement>
path
- path to the file with annotations that have been modifiedpublic void preprocessClassTree(ClassTree classTree)
WholeProgramInferenceStorage
preprocessClassTree
in interface WholeProgramInferenceStorage<scenelib.annotations.el.ATypeElement>
classTree
- the class to preprocesspublic static String aTypeElementToString(scenelib.annotations.el.ATypeElement aType)
WholeProgramInferenceScenesStorage.AnnotationsInContexts
.aType
- an ATypeElement to convert to a string representation