Class WholeProgramInferenceScenesStorage
- All Implemented Interfaces:
- WholeProgramInferenceStorage<org.checkerframework.afu.scenelib.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.
- 
Nested Class SummaryNested ClassesModifier and TypeClassDescriptionstatic classMaps theaTypeElementToString(org.checkerframework.afu.scenelib.el.ATypeElement)representation of an ATypeElement and its TypeUseLocation to a set of names of annotations.
- 
Field SummaryFieldsModifier and TypeFieldDescriptionprotected final AnnotatedTypeFactoryThe type factory associated with this WholeProgramInferenceScenesStorage.static final StringDirectory where .jaif files will be written to and read from.Scenes that were modified since the last time all Scenes were written into .jaif files.final Map<String,ASceneWrapper> Maps .jaif file paths (Strings) to Scenes.
- 
Constructor SummaryConstructorsConstructorDescriptionWholeProgramInferenceScenesStorage(AnnotatedTypeFactory atypeFactory) Default constructor.
- 
Method SummaryModifier and TypeMethodDescriptionbooleanaddClassDeclarationAnnotation(TypeElement classElt, AnnotationMirror anno) Adds an annotation to a class declaration.booleanaddDeclarationAnnotationToFormalParameter(ExecutableElement methodElt, int index, AnnotationMirror anno) Adds a declaration annotation to a formal parameter.booleanaddFieldDeclarationAnnotation(VariableElement field, AnnotationMirror anno) Updates a field to add a declaration annotation.booleanaddMethodDeclarationAnnotation(ExecutableElement methodElt, AnnotationMirror anno) Updates a method to add a declaration annotation.atmFromStorageLocation(TypeMirror typeMirror, org.checkerframework.afu.scenelib.el.ATypeElement storageLocation) Obtain the type from a storage location.static StringaTypeElementToString(org.checkerframework.afu.scenelib.el.ATypeElement aType) Returns a string representation of an ATypeElement, for use as part of a key inWholeProgramInferenceScenesStorage.AnnotationsInContexts.protected org.checkerframework.afu.scenelib.el.AClassgetAClass(@BinaryName String className, String jaifPath) Returns the scene-lib representation of the given className in the scene identified by the given jaifPath.protected org.checkerframework.afu.scenelib.el.AClassgetAClass(@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.org.checkerframework.afu.scenelib.el.ATypeElementgetFieldAnnotations(Element element, String fieldName, AnnotatedTypeMirror lhsATM, AnnotatedTypeFactory atypeFactory) Get the annotations for a field type.getFileForElement(Element elt) Returns the file corresponding to the given element.protected StringgetJaifPath(String className) Returns the String representing the .jaif path of a class given its name.org.checkerframework.afu.scenelib.el.ATypeElementgetParameterAnnotations(ExecutableElement methodElt, int i, AnnotatedTypeMirror paramATM, VariableElement ve, AnnotatedTypeFactory atypeFactory) Get the annotations for a formal parameter type.getPostconditionDeclaredType(org.checkerframework.afu.scenelib.el.AMethod m, String expression) Fetches the declared type of an expression for which a postcondition was inferred, for the given AMethod.getPreconditionDeclaredType(org.checkerframework.afu.scenelib.el.AMethod m, String expression) Fetches the declared type of an expression for which a precondition was inferred, for the given AMethod.org.checkerframework.afu.scenelib.el.ATypeElementgetPreOrPostconditions(Analysis.BeforeOrAfter preOrPost, ExecutableElement methodElement, String expression, AnnotatedTypeMirror declaredType, AnnotatedTypeFactory atypeFactory) Returns the pre- or postcondition annotations for an expression.org.checkerframework.afu.scenelib.el.ATypeElementgetReceiverAnnotations(ExecutableElement methodElt, AnnotatedTypeMirror paramATM, AnnotatedTypeFactory atypeFactory) Get the annotations for the receiver type.org.checkerframework.afu.scenelib.el.ATypeElementgetReturnAnnotations(ExecutableElement methodElt, AnnotatedTypeMirror atm, AnnotatedTypeFactory atypeFactory) Get the annotations for the return type.booleanhasStorageLocationForMethod(ExecutableElement methodElt) Given an ExecutableElement in a compilation unit that has already been read into storage, returns whether there exists a stored method matchingelt.voidprepareClassForWriting(org.checkerframework.afu.scenelib.el.AClass classAnnos) Side-effects the class annotations to make any desired changes before writing to a file.voidprepareMethodForWriting(org.checkerframework.afu.scenelib.el.AMethod methodAnnos) Side-effects the method or constructor annotations to make any desired changes before writing to a file.voidprepareSceneForWriting(org.checkerframework.afu.scenelib.el.AScene compilationUnitAnnos) Side-effects the compilation unit annotations to make any desired changes before writing to a file.voidpreprocessClassTree(ClassTree classTree) Performs any preparation required for inference on the elements of a class.voidsetFileModified(String path) Indicates that inferred annotations for the file atpathhave changed since last written.protected voidupdateAnnotationSetInScene(org.checkerframework.afu.scenelib.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.voidupdateStorageLocationFromAtm(AnnotatedTypeMirror newATM, AnnotatedTypeMirror curATM, org.checkerframework.afu.scenelib.el.ATypeElement typeToUpdate, TypeUseLocation defLoc, boolean ignoreIfAnnotated) Updates a storage location to have the annotations of the givenAnnotatedTypeMirror.voidwriteResultsToFile(WholeProgramInference.OutputFormat outputFormat, BaseTypeChecker checker) Writes the inferred results to a file.voidwriteScenes(WholeProgramInference.OutputFormat outputFormat, BaseTypeChecker checker) Write all modified scenes into files.
- 
Field Details- 
JAIF_FILES_PATHDirectory where .jaif files will be written to and read from. This directory is relative to where the CF's javac command is executed.
- 
atypeFactoryThe type factory associated with this WholeProgramInferenceScenesStorage.
- 
scenesMaps .jaif file paths (Strings) to Scenes. Relative to JAIF_FILES_PATH.
- 
modifiedScenesScenes that were modified since the last time all Scenes were written into .jaif files. Each String element of this set is a path (relative to JAIF_FILES_PATH) to the .jaif file of the corresponding Scene in the set. It is obtained by passing a class name as argument to thegetJaifPath(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(org.checkerframework.afu.scenelib.el.ATypeElement, org.checkerframework.framework.qual.TypeUseLocation, org.checkerframework.framework.type.AnnotatedTypeMirror, org.checkerframework.framework.type.AnnotatedTypeMirror, java.lang.String, boolean).)
 
- 
- 
Constructor Details- 
WholeProgramInferenceScenesStorageDefault constructor.- Parameters:
- atypeFactory- the type factory associated with this WholeProgramInferenceScenesStorage
 
 
- 
- 
Method Details- 
getFileForElementDescription copied from interface:WholeProgramInferenceStorageReturns the file corresponding to the given element. This may side-effect the storage to load the file if it hasn't been read yet.- Specified by:
- getFileForElementin interface- WholeProgramInferenceStorage<org.checkerframework.afu.scenelib.el.ATypeElement>
- Parameters:
- elt- an element
- Returns:
- the path to the file where inference results for the element will be written
 
- 
hasStorageLocationForMethodDescription copied from interface:WholeProgramInferenceStorageGiven an ExecutableElement in a compilation unit that has already been read into storage, returns whether there exists a stored method matchingelt.An implementation is permitted to return false if eltrepresents a method that was synthetically added by javac, such as zero-argument constructors or valueOf(String) methods for enum types.- Specified by:
- hasStorageLocationForMethodin interface- WholeProgramInferenceStorage<org.checkerframework.afu.scenelib.el.ATypeElement>
- Parameters:
- methodElt- a method or constructor Element
- Returns:
- true if the storage has a method corresponding to elt
 
- 
getParameterAnnotationspublic org.checkerframework.afu.scenelib.el.ATypeElement getParameterAnnotations(ExecutableElement methodElt, int i, AnnotatedTypeMirror paramATM, VariableElement ve, AnnotatedTypeFactory atypeFactory) Description copied from interface:WholeProgramInferenceStorageGet the annotations for a formal parameter type.- Specified by:
- getParameterAnnotationsin interface- WholeProgramInferenceStorage<org.checkerframework.afu.scenelib.el.ATypeElement>
- Parameters:
- methodElt- the method or constructor Element
- i- the parameter index (0-based)
- paramATM- the parameter type
- ve- the parameter variable
- atypeFactory- the type factory
- Returns:
- the annotations for a formal parameter type
 
- 
getReceiverAnnotationspublic org.checkerframework.afu.scenelib.el.ATypeElement getReceiverAnnotations(ExecutableElement methodElt, AnnotatedTypeMirror paramATM, AnnotatedTypeFactory atypeFactory) Description copied from interface:WholeProgramInferenceStorageGet the annotations for the receiver type.- Specified by:
- getReceiverAnnotationsin interface- WholeProgramInferenceStorage<org.checkerframework.afu.scenelib.el.ATypeElement>
- Parameters:
- methodElt- the method or constructor Element
- paramATM- the receiver type
- atypeFactory- the type factory
- Returns:
- the annotations for the receiver type
 
- 
getReturnAnnotationspublic org.checkerframework.afu.scenelib.el.ATypeElement getReturnAnnotations(ExecutableElement methodElt, AnnotatedTypeMirror atm, AnnotatedTypeFactory atypeFactory) Description copied from interface:WholeProgramInferenceStorageGet the annotations for the return type.- Specified by:
- getReturnAnnotationsin interface- WholeProgramInferenceStorage<org.checkerframework.afu.scenelib.el.ATypeElement>
- Parameters:
- methodElt- the method or constructor Element
- atm- the return type
- atypeFactory- the type factory
- Returns:
- the annotations for the return type
 
- 
getFieldAnnotationspublic org.checkerframework.afu.scenelib.el.ATypeElement getFieldAnnotations(Element element, String fieldName, AnnotatedTypeMirror lhsATM, AnnotatedTypeFactory atypeFactory) Description copied from interface:WholeProgramInferenceStorageGet the annotations for a field type.- Specified by:
- getFieldAnnotationsin interface- WholeProgramInferenceStorage<org.checkerframework.afu.scenelib.el.ATypeElement>
- Parameters:
- element- the element for the field
- fieldName- the simple field name
- lhsATM- the field type
- atypeFactory- the annotated type factory
- Returns:
- the annotations for a field type
 
- 
getPreOrPostconditionspublic org.checkerframework.afu.scenelib.el.ATypeElement getPreOrPostconditions(Analysis.BeforeOrAfter preOrPost, ExecutableElement methodElement, String expression, AnnotatedTypeMirror declaredType, AnnotatedTypeFactory atypeFactory) Description copied from interface:WholeProgramInferenceStorageReturns the pre- or postcondition annotations for an expression. The format of the expression is the same as a programmer would write in aRequiresQualifierorEnsuresQualifierannotation.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). - Specified by:
- getPreOrPostconditionsin interface- WholeProgramInferenceStorage<org.checkerframework.afu.scenelib.el.ATypeElement>
- Parameters:
- preOrPost- whether to get the precondition or postcondition
- methodElement- the method
- expression- the expression
- declaredType- the declared type of the expression
- atypeFactory- the type factory
- Returns:
- the pre- or postcondition annotations for an expression, or null if the given expression is not a supported expression type
 
- 
getPreconditionDeclaredTypepublic AnnotatedTypeMirror getPreconditionDeclaredType(org.checkerframework.afu.scenelib.el.AMethod m, String expression) Fetches the declared type of an expression for which a precondition was inferred, for the given AMethod.- Parameters:
- m- a method
- expression- the expression
- Returns:
- the declared type
 
- 
getPostconditionDeclaredTypepublic AnnotatedTypeMirror getPostconditionDeclaredType(org.checkerframework.afu.scenelib.el.AMethod m, String expression) Fetches the declared type of an expression for which a postcondition was inferred, for the given AMethod.- Parameters:
- m- a method
- expression- the expression
- Returns:
- the declared type
 
- 
addMethodDeclarationAnnotationDescription copied from interface:WholeProgramInferenceStorageUpdates a method to add a declaration annotation.- Specified by:
- addMethodDeclarationAnnotationin interface- WholeProgramInferenceStorage<org.checkerframework.afu.scenelib.el.ATypeElement>
- Parameters:
- methodElt- the method to annotate
- anno- the declaration annotation to add to the method
- Returns:
- true if annois a new declaration annotation formethodElt, false otherwise
 
- 
addFieldDeclarationAnnotationDescription copied from interface:WholeProgramInferenceStorageUpdates a field to add a declaration annotation.- Specified by:
- addFieldDeclarationAnnotationin interface- WholeProgramInferenceStorage<org.checkerframework.afu.scenelib.el.ATypeElement>
- Parameters:
- field- the field
- anno- the declaration annotation to add to the field
- Returns:
- true if annois a new declaration annotation forfieldElt, false otherwise
 
- 
addDeclarationAnnotationToFormalParameterpublic boolean addDeclarationAnnotationToFormalParameter(ExecutableElement methodElt, int index, AnnotationMirror anno) Description copied from interface:WholeProgramInferenceStorageAdds a declaration annotation to a formal parameter.- Specified by:
- addDeclarationAnnotationToFormalParameterin interface- WholeProgramInferenceStorage<org.checkerframework.afu.scenelib.el.ATypeElement>
- Parameters:
- methodElt- the method whose formal parameter will be annotated
- index- the index of the parameter (0-indexed)
- anno- the annotation to add
- Returns:
- true if annois a new declaration annotation formethodElt, false otherwise
 
- 
addClassDeclarationAnnotationDescription copied from interface:WholeProgramInferenceStorageAdds an annotation to a class declaration.- Specified by:
- addClassDeclarationAnnotationin interface- WholeProgramInferenceStorage<org.checkerframework.afu.scenelib.el.ATypeElement>
- Parameters:
- classElt- the class declaration to annotate
- anno- the annotation to add
- Returns:
- true if annois a new declaration annotation forclassElt, false otherwise
 
- 
writeScenesWrite all modified scenes into files. (Scenes are modified by the methodupdateAnnotationSetInScene(org.checkerframework.afu.scenelib.el.ATypeElement, org.checkerframework.framework.qual.TypeUseLocation, org.checkerframework.framework.type.AnnotatedTypeMirror, org.checkerframework.framework.type.AnnotatedTypeMirror, java.lang.String, boolean).)- Parameters:
- outputFormat- the output format to use when writing files
- checker- the checker from which this method is called, for naming stub files
 
- 
getJaifPathReturns the String representing the .jaif path of a class given its name.- Parameters:
- className- the simple name of a class
- Returns:
- the path to the .jaif file
 
- 
getAClassprotected org.checkerframework.afu.scenelib.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.- Parameters:
- className- the name of the class to get, in binary form
- jaifPath- 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.
- Returns:
- a version of the scene-lib representation of the class, augmented with symbol
     information if classSymbolwas non-null
 
- 
getAClassprotected org.checkerframework.afu.scenelib.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.- Parameters:
- className- the name of the class to get, in binary form
- jaifPath- the path to the jaif file that would represent that class (must end in ".jaif")
- Returns:
- the scene-lib representation of the class, possibly augmented with symbol information
     if getAClass(String, String, com.sun.tools.javac.code.Symbol.ClassSymbol)has already been called with a non-null third argument
 
- 
updateAnnotationSetInSceneprotected void updateAnnotationSetInScene(org.checkerframework.afu.scenelib.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.- If there was no previous annotation for that location, then the updated set will be the annotations in rhsATM.
- If there was a previous annotation, the updated set will be the LUB between the previous annotation and rhsATM.
 - Parameters:
- type- ATypeElement of the Scene which will be modified
- jaifPath- 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 code
- lhsATM- the LHS of the annotated type on the source code
- defLoc- the location where the annotation will be added
- ignoreIfAnnotated- if true, don't update any type that is explicitly annotated in the source code
 
- 
atmFromStorageLocationpublic AnnotatedTypeMirror atmFromStorageLocation(TypeMirror typeMirror, org.checkerframework.afu.scenelib.el.ATypeElement storageLocation) Description copied from interface:WholeProgramInferenceStorageObtain the type from a storage location.- Specified by:
- atmFromStorageLocationin interface- WholeProgramInferenceStorage<org.checkerframework.afu.scenelib.el.ATypeElement>
- Parameters:
- typeMirror- the underlying type for the result
- storageLocation- the storage location from which to obtain annotations
- Returns:
- an annotated type mirror with underlying type typeMirrorand annotations fromstorageLocation
 
- 
updateStorageLocationFromAtmpublic void updateStorageLocationFromAtm(AnnotatedTypeMirror newATM, AnnotatedTypeMirror curATM, org.checkerframework.afu.scenelib.el.ATypeElement typeToUpdate, TypeUseLocation defLoc, boolean ignoreIfAnnotated) Description copied from interface:WholeProgramInferenceStorageUpdates a storage location to have the annotations of the givenAnnotatedTypeMirror. Annotations in the original set that should be ignored are not added to the resulting set. IfignoreIfAnnotatedis 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 AnnotatedTypeMirrorhas 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 inWholeProgramInferenceperform LUB. This one just does replacement. (Thus, the naming may be a bit confusing.)- Specified by:
- updateStorageLocationFromAtmin interface- WholeProgramInferenceStorage<org.checkerframework.afu.scenelib.el.ATypeElement>
- Parameters:
- 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 code
- typeToUpdate- the storage location that will be updated
- defLoc- the location where the annotation will be added
- ignoreIfAnnotated- if true, don't update any type that is explicitly annotated in the source code
 
- 
prepareSceneForWritingpublic void prepareSceneForWriting(org.checkerframework.afu.scenelib.el.AScene compilationUnitAnnos) Side-effects the compilation unit annotations to make any desired changes before writing to a file.- Parameters:
- compilationUnitAnnos- the compilation unit annotations to modify
 
- 
prepareClassForWritingpublic void prepareClassForWriting(org.checkerframework.afu.scenelib.el.AClass classAnnos) Side-effects the class annotations to make any desired changes before writing to a file.- Parameters:
- classAnnos- the class annotations to modify
 
- 
prepareMethodForWritingpublic void prepareMethodForWriting(org.checkerframework.afu.scenelib.el.AMethod methodAnnos) Side-effects the method or constructor annotations to make any desired changes before writing to a file.- Parameters:
- methodAnnos- the method or constructor annotations to modify
 
- 
writeResultsToFilepublic void writeResultsToFile(WholeProgramInference.OutputFormat outputFormat, BaseTypeChecker checker) Description copied from interface:WholeProgramInferenceStorageWrites the inferred results to a file. Ideally, it should be called at the end of the type-checking process. In practice, it is called after each class, because we don't know which class will be the last one in the type-checking process.- Specified by:
- writeResultsToFilein interface- WholeProgramInferenceStorage<org.checkerframework.afu.scenelib.el.ATypeElement>
- Parameters:
- outputFormat- the file format in which to write the results
- checker- the checker from which this method is called, for naming annotation files
 
- 
setFileModifiedDescription copied from interface:WholeProgramInferenceStorageIndicates that inferred annotations for the file atpathhave changed since last written. This causes output files forpathto be written out next timeWholeProgramInferenceStorage.writeResultsToFile(org.checkerframework.common.wholeprograminference.WholeProgramInference.OutputFormat, org.checkerframework.common.basetype.BaseTypeChecker)is called.- Specified by:
- setFileModifiedin interface- WholeProgramInferenceStorage<org.checkerframework.afu.scenelib.el.ATypeElement>
- Parameters:
- path- path to the file with annotations that have been modified
 
- 
preprocessClassTreeDescription copied from interface:WholeProgramInferenceStoragePerforms any preparation required for inference on the elements of a class. Should be called on each top-level class declaration in a compilation unit before processing it.- Specified by:
- preprocessClassTreein interface- WholeProgramInferenceStorage<org.checkerframework.afu.scenelib.el.ATypeElement>
- Parameters:
- classTree- the class to preprocess
 
- 
aTypeElementToStringReturns a string representation of an ATypeElement, for use as part of a key inWholeProgramInferenceScenesStorage.AnnotationsInContexts.- Parameters:
- aType- an ATypeElement to convert to a string representation
- Returns:
- a string representation of the argument
 
 
-