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)
Constructs a new
WholeProgramInferenceJavaParser that has not yet inferred any
annotations. |
| Modifier and Type | Method and Description |
|---|---|
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 |
getPreOrPostconditionsForField(Analysis.BeforeOrAfter preOrPost,
ExecutableElement methodElement,
VariableElement fieldElement,
AnnotatedTypeFactory atypeFactory)
Returns the pre- or postcondition annotations for a field.
|
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)
WholeProgramInferenceJavaParser that has not yet inferred any
annotations.atypeFactory - the associated type factorypublic String getFileForElement(Element elt)
WholeProgramInferenceStoragegetFileForElement in interface WholeProgramInferenceStorage<AnnotatedTypeMirror>elt - an elementpublic void setFileModified(String path)
WholeProgramInferenceStoragepath 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)
WholeProgramInferenceStorageelt.
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 Elementeltpublic AnnotatedTypeMirror getParameterAnnotations(ExecutableElement methodElt, int i, AnnotatedTypeMirror paramATM, VariableElement ve, AnnotatedTypeFactory atypeFactory)
WholeProgramInferenceStoragegetParameterAnnotations 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)
WholeProgramInferenceStoragegetReceiverAnnotations in interface WholeProgramInferenceStorage<AnnotatedTypeMirror>methodElt - the method or constructor ElementparamATM - the receiver typeatypeFactory - the type factorypublic AnnotatedTypeMirror getReturnAnnotations(ExecutableElement methodElt, AnnotatedTypeMirror atm, AnnotatedTypeFactory atypeFactory)
WholeProgramInferenceStoragegetReturnAnnotations 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)
WholeProgramInferenceStoragegetFieldAnnotations in interface WholeProgramInferenceStorage<AnnotatedTypeMirror>element - the element for the fieldfieldName - the simple field namelhsATM - the field typeatypeFactory - the annotated type factorypublic AnnotatedTypeMirror getPreOrPostconditionsForField(Analysis.BeforeOrAfter preOrPost, ExecutableElement methodElement, VariableElement fieldElement, AnnotatedTypeFactory atypeFactory)
WholeProgramInferenceStoragegetPreOrPostconditionsForField in interface WholeProgramInferenceStorage<AnnotatedTypeMirror>preOrPost - whether to get the precondition or postconditionmethodElement - the methodfieldElement - the fieldatypeFactory - the type factorypublic boolean addMethodDeclarationAnnotation(ExecutableElement methodElt, AnnotationMirror anno)
WholeProgramInferenceStorageaddMethodDeclarationAnnotation 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 AnnotatedTypeMirror atmFromStorageLocation(TypeMirror typeMirror, AnnotatedTypeMirror storageLocation)
WholeProgramInferenceStorageatmFromStorageLocation in interface WholeProgramInferenceStorage<AnnotatedTypeMirror>typeMirror - the underlying type for the resultstorageLocation - the storage location from which to obtain annotationstypeMirror and annotations from
storageLocationpublic void updateStorageLocationFromAtm(AnnotatedTypeMirror newATM, AnnotatedTypeMirror curATM, AnnotatedTypeMirror typeToUpdate, TypeUseLocation defLoc, boolean ignoreIfAnnotated)
WholeProgramInferenceStorageAnnotatedTypeMirror.
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 AnnotatedTypeMirrorcurATM - 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)
WholeProgramInferenceStoragepreprocessClassTree 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)
WholeProgramInferenceStoragewriteResultsToFile 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