public class WholeProgramInferenceJavaParserStorage extends Object implements WholeProgramInferenceStorage<AnnotatedTypeMirror>
WholeProgramInferenceStorage
that stores annotations
directly with the JavaParser node corresponding to the annotation's location. It outputs ajava
files.Modifier and Type | Class and Description |
---|---|
class |
WholeProgramInferenceJavaParserStorage.CallableDeclarationAnnos
Stores the JavaParser node for a method or constructor and the annotations that have been
inferred about its parameters and return type.
|
Modifier and Type | Field and Description |
---|---|
static String |
AJAVA_FILES_PATH
Directory where .ajava files will be written to and read from.
|
protected AnnotatedTypeFactory |
atypeFactory
The type factory associated with this.
|
Constructor and Description |
---|
WholeProgramInferenceJavaParserStorage(AnnotatedTypeFactory atypeFactory,
boolean inferOutputOriginal)
Constructs a new
WholeProgramInferenceJavaParser that has not yet inferred any
annotations. |
Modifier and Type | Method and Description |
---|---|
boolean |
addFieldDeclarationAnnotation(Element field,
AnnotationMirror anno)
Updates a field to add a declaration annotation.
|
boolean |
addMethodDeclarationAnnotation(ExecutableElement methodElt,
AnnotationMirror anno)
Updates a method to add a declaration annotation.
|
AnnotatedTypeMirror |
atmFromStorageLocation(TypeMirror typeMirror,
AnnotatedTypeMirror storageLocation)
Obtain the type from a storage location.
|
AnnotatedTypeMirror |
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.
|
AnnotatedTypeMirror |
getParameterAnnotations(ExecutableElement methodElt,
int i,
AnnotatedTypeMirror paramATM,
VariableElement ve,
AnnotatedTypeFactory atypeFactory)
Get the annotations for a formal parameter type.
|
AnnotatedTypeMirror |
getPreOrPostconditions(Analysis.BeforeOrAfter preOrPost,
ExecutableElement methodElement,
String expression,
AnnotatedTypeMirror declaredType,
AnnotatedTypeFactory atypeFactory)
Returns the pre- or postcondition annotations for an expression.
|
AnnotatedTypeMirror |
getReceiverAnnotations(ExecutableElement methodElt,
AnnotatedTypeMirror paramATM,
AnnotatedTypeFactory atypeFactory)
Get the annotations for the receiver type.
|
AnnotatedTypeMirror |
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(org.checkerframework.common.wholeprograminference.WholeProgramInferenceJavaParserStorage.ClassOrInterfaceAnnos classAnnos)
Side-effects the class annotations to make any desired changes before writing to a file.
|
void |
prepareCompilationUnitForWriting(org.checkerframework.common.wholeprograminference.WholeProgramInferenceJavaParserStorage.CompilationUnitAnnos compilationUnitAnnos)
Side-effects the compilation unit annotations to make any desired changes before writing to a
file.
|
void |
prepareMethodForWriting(WholeProgramInferenceJavaParserStorage.CallableDeclarationAnnos methodAnnos)
Side-effects the method or constructor 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. |
void |
updateStorageLocationFromAtm(AnnotatedTypeMirror newATM,
AnnotatedTypeMirror curATM,
AnnotatedTypeMirror 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.
|
public static final String AJAVA_FILES_PATH
protected final AnnotatedTypeFactory atypeFactory
public WholeProgramInferenceJavaParserStorage(AnnotatedTypeFactory atypeFactory, boolean inferOutputOriginal)
WholeProgramInferenceJavaParser
that has not yet inferred any
annotations.atypeFactory
- the associated type factoryinferOutputOriginal
- whether the -AinferOutputOriginal option was supplied to the checkerpublic String getFileForElement(Element elt)
WholeProgramInferenceStorage
getFileForElement
in interface WholeProgramInferenceStorage<AnnotatedTypeMirror>
elt
- an elementpublic 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<AnnotatedTypeMirror>
path
- path to the file with annotations that have been modifiedpublic 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<AnnotatedTypeMirror>
methodElt
- a method or constructor Elementelt
public AnnotatedTypeMirror getParameterAnnotations(ExecutableElement methodElt, int i, AnnotatedTypeMirror paramATM, VariableElement ve, AnnotatedTypeFactory atypeFactory)
WholeProgramInferenceStorage
getParameterAnnotations
in interface WholeProgramInferenceStorage<AnnotatedTypeMirror>
methodElt
- the method or constructor Elementi
- the parameter index (0-based)paramATM
- the parameter typeve
- the parameter variableatypeFactory
- the type factorypublic AnnotatedTypeMirror getReceiverAnnotations(ExecutableElement methodElt, AnnotatedTypeMirror paramATM, AnnotatedTypeFactory atypeFactory)
WholeProgramInferenceStorage
getReceiverAnnotations
in interface WholeProgramInferenceStorage<AnnotatedTypeMirror>
methodElt
- the method or constructor ElementparamATM
- the receiver typeatypeFactory
- the type factorypublic AnnotatedTypeMirror getReturnAnnotations(ExecutableElement methodElt, AnnotatedTypeMirror atm, AnnotatedTypeFactory atypeFactory)
WholeProgramInferenceStorage
getReturnAnnotations
in interface WholeProgramInferenceStorage<AnnotatedTypeMirror>
methodElt
- the method or constructor Elementatm
- the return typeatypeFactory
- the type factorypublic AnnotatedTypeMirror getFieldAnnotations(Element element, String fieldName, AnnotatedTypeMirror lhsATM, AnnotatedTypeFactory atypeFactory)
WholeProgramInferenceStorage
getFieldAnnotations
in interface WholeProgramInferenceStorage<AnnotatedTypeMirror>
element
- the element for the fieldfieldName
- the simple field namelhsATM
- the field typeatypeFactory
- the annotated type factorypublic AnnotatedTypeMirror 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<AnnotatedTypeMirror>
preOrPost
- whether to get the precondition or postconditionmethodElement
- the methodexpression
- the expressiondeclaredType
- the declared type of the expressionatypeFactory
- the type factorypublic boolean addMethodDeclarationAnnotation(ExecutableElement methodElt, AnnotationMirror anno)
WholeProgramInferenceStorage
addMethodDeclarationAnnotation
in interface WholeProgramInferenceStorage<AnnotatedTypeMirror>
methodElt
- the method to annotateanno
- the declaration annotation to add to the methodanno
is a new declaration annotation for methodElt
, false
otherwisepublic boolean addFieldDeclarationAnnotation(Element field, AnnotationMirror anno)
WholeProgramInferenceStorage
addFieldDeclarationAnnotation
in interface WholeProgramInferenceStorage<AnnotatedTypeMirror>
field
- the fieldanno
- the declaration annotation to add to the fieldanno
is a new declaration annotation for fieldElt
, false
otherwisepublic AnnotatedTypeMirror atmFromStorageLocation(TypeMirror typeMirror, AnnotatedTypeMirror storageLocation)
WholeProgramInferenceStorage
atmFromStorageLocation
in interface WholeProgramInferenceStorage<AnnotatedTypeMirror>
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, AnnotatedTypeMirror 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<AnnotatedTypeMirror>
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 preprocessClassTree(ClassTree classTree)
WholeProgramInferenceStorage
preprocessClassTree
in interface WholeProgramInferenceStorage<AnnotatedTypeMirror>
classTree
- the class to preprocesspublic void prepareCompilationUnitForWriting(org.checkerframework.common.wholeprograminference.WholeProgramInferenceJavaParserStorage.CompilationUnitAnnos compilationUnitAnnos)
compilationUnitAnnos
- the compilation unit annotations to modifypublic void prepareClassForWriting(org.checkerframework.common.wholeprograminference.WholeProgramInferenceJavaParserStorage.ClassOrInterfaceAnnos classAnnos)
classAnnos
- the class annotations to modifypublic void prepareMethodForWriting(WholeProgramInferenceJavaParserStorage.CallableDeclarationAnnos methodAnnos)
methodAnnos
- the method or constructor annotations to modifypublic void writeResultsToFile(WholeProgramInference.OutputFormat outputFormat, BaseTypeChecker checker)
WholeProgramInferenceStorage
writeResultsToFile
in interface WholeProgramInferenceStorage<AnnotatedTypeMirror>
outputFormat
- the file format in which to write the resultschecker
- the checker from which this method is called, for naming annotation files