public class WholeProgramInferenceScenesStorage extends Object
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,
boolean ignoreNullAssignments)
Default constructor.
|
Modifier and Type | Method and Description |
---|---|
AnnotatedTypeMirror |
atmFromATypeElement(TypeMirror typeMirror,
scenelib.annotations.el.ATypeElement type)
Obtain the type from an ATypeElement (which is part of a Scene).
|
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.
|
protected String |
getJaifPath(String className)
Returns the String representing the .jaif path of a class given its name.
|
protected ASceneWrapper |
getScene(String jaifPath)
Reads a Scene from the given .jaif file, or returns an empty Scene if the file does not
exist.
|
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 |
writeScenes(WholeProgramInference.OutputFormat outputFormat,
BaseTypeChecker checker)
Write all modified scenes into files.
|
protected final AnnotatedTypeFactory atypeFactory
public static final String JAIF_FILES_PATH
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, boolean ignoreNullAssignments)
ignoreNullAssignments
- if true, assignments where the rhs is null are ignoredatypeFactory
- the type factory associated with this WholeProgramInferenceScenesStoragepublic 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 ASceneWrapper getScene(String jaifPath)
jaifPath
- the .jaif fileprotected 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 atmFromATypeElement(TypeMirror typeMirror, scenelib.annotations.el.ATypeElement type)
typeMirror
- the underlying type for the resulttype
- the ATypeElement from which to obtain annotationstypeMirror
and annotations from
type
public static String aTypeElementToString(scenelib.annotations.el.ATypeElement aType)
WholeProgramInferenceScenesStorage.AnnotationsInContexts
.aType
- an ATypeElement to convert to a string representation