Class WholeProgramInferenceJavaParserStorage
- All Implemented Interfaces:
WholeProgramInferenceStorage<AnnotatedTypeMirror>
WholeProgramInferenceStorage that stores annotations
directly with the JavaParser node corresponding to the annotation's location. It outputs ajava
files.-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionclassStores the JavaParser node for a method or constructor and the annotations that have been inferred about its parameters and return type. -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final FileDirectory where .ajava files will be written to and read from.protected final AnnotatedTypeFactoryThe type factory associated with this.protected final ElementsThe element utilities foratypeFactory. -
Constructor Summary
ConstructorsConstructorDescriptionWholeProgramInferenceJavaParserStorage(AnnotatedTypeFactory atypeFactory, boolean inferOutputOriginal) Constructs a newWholeProgramInferenceJavaParserthat has not yet inferred any annotations. -
Method Summary
Modifier and TypeMethodDescriptionbooleanaddClassDeclarationAnnotation(TypeElement classElt, AnnotationMirror anno) Adds an annotation to a class declaration.booleanaddDeclarationAnnotationToFormalParameter(ExecutableElement methodElt, @org.checkerframework.checker.index.qual.Positive int index_1based, 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, AnnotatedTypeMirror storageLocation) Obtain the type from a storage location.getFieldAnnotations(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.getInvisibleQualifierNames(AnnotatedTypeFactory atypeFactory) Returns the names of all qualifiers that are marked withInvisibleQualifier, and that are supported by the given type factory.getMethodDeclarationAnnotations(ExecutableElement methodElt) Return the list of declaration annotations inferred on the given method so far in this round of WPI.getParameterAnnotations(ExecutableElement methodElt, @org.checkerframework.checker.index.qual.Positive int index_1based, AnnotatedTypeMirror paramATM, VariableElement ve, AnnotatedTypeFactory atypeFactory) Get the annotations for a formal parameter type.getPreOrPostconditions(Analysis.BeforeOrAfter preOrPost, ExecutableElement methodElement, String expression, AnnotatedTypeMirror declaredType, AnnotatedTypeFactory atypeFactory) Returns the pre- or postcondition annotations for an expression.getReceiverAnnotations(ExecutableElement methodElt, AnnotatedTypeMirror paramATM, AnnotatedTypeFactory atypeFactory) Get the annotations for the receiver type.getReturnAnnotations(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.static booleanisInvisible(Class<? extends Annotation> qual) Is the definition of the given annotation class annotated withInvisibleQualifier?voidpreprocessClassTree(ClassTree classTree) Performs any preparation required for inference on the elements of a class.booleanRemoves the given annotation from the given method element's inferred declaration annotation.voidsetFileModified(String path) Indicates that inferred annotations for the file atpathhave changed since last written.voidFor every modified file, consider its subclasses and superclasses modified, too.voidupdateStorageLocationFromAtm(AnnotatedTypeMirror newATM, AnnotatedTypeMirror curATM, AnnotatedTypeMirror typeToUpdate, TypeUseLocation defLoc, boolean ignoreIfAnnotated) Updates a storage location to have the annotations of the givenAnnotatedTypeMirror.voidwpiPrepareClassForWriting(org.checkerframework.common.wholeprograminference.WholeProgramInferenceJavaParserStorage.ClassOrInterfaceAnnos classAnnos, Collection<@BinaryName String> supertypes, Collection<@BinaryName String> subtypes) Side-effects the class annotations to make any desired changes before writing to a file.voidwpiPrepareCompilationUnitForWriting(org.checkerframework.common.wholeprograminference.WholeProgramInferenceJavaParserStorage.CompilationUnitAnnos compilationUnitAnnos) Side-effects the compilation unit annotations to make any desired changes before writing to a file.voidwpiPrepareMethodForWriting(WholeProgramInferenceJavaParserStorage.CallableDeclarationAnnos methodAnnos, Collection<WholeProgramInferenceJavaParserStorage.CallableDeclarationAnnos> inSupertypes, Collection<WholeProgramInferenceJavaParserStorage.CallableDeclarationAnnos> inSubtypes) Side-effects the method or constructor annotations to make any desired changes before writing to a file.voidwriteResultsToFile(WholeProgramInference.OutputFormat outputFormat, BaseTypeChecker checker) Writes the inferred results to a file.
-
Field Details
-
AJAVA_FILES_PATH
Directory where .ajava files will be written to and read from. This directory is relative to where the javac command is executed. -
atypeFactory
The type factory associated with this. -
elements
The element utilities foratypeFactory.
-
-
Constructor Details
-
WholeProgramInferenceJavaParserStorage
public WholeProgramInferenceJavaParserStorage(AnnotatedTypeFactory atypeFactory, boolean inferOutputOriginal) Constructs a newWholeProgramInferenceJavaParserthat has not yet inferred any annotations.- Parameters:
atypeFactory- the associated type factoryinferOutputOriginal- whether the -AinferOutputOriginal option was supplied to the checker
-
-
Method Details
-
getInvisibleQualifierNames
Returns the names of all qualifiers that are marked withInvisibleQualifier, and that are supported by the given type factory.- Parameters:
atypeFactory- a type factory- Returns:
- the names of every invisible qualifier supported by
atypeFactory
-
isInvisible
Is the definition of the given annotation class annotated withInvisibleQualifier?- Parameters:
qual- an annotation class- Returns:
- true iff
qualis meta-annotated withInvisibleQualifier
-
getFileForElement
Description 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 interfaceWholeProgramInferenceStorage<AnnotatedTypeMirror>- Parameters:
elt- an element- Returns:
- the path to the file where inference results for the element will be written
-
setFileModified
Description 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 interfaceWholeProgramInferenceStorage<AnnotatedTypeMirror>- Parameters:
path- path to the file with annotations that have been modified
-
setSupertypesAndSubtypesModified
public void setSupertypesAndSubtypesModified()For every modified file, consider its subclasses and superclasses modified, too. The reason is that an annotation change in a class might require annotations in its superclasses and supclasses to be modified, in order to preserve behavioral subtyping. Setting it modified will cause it to be written out, and while writing out, the annotations will be made consistent across the class hierarchy bywpiPrepareCompilationUnitForWriting(org.checkerframework.common.wholeprograminference.WholeProgramInferenceJavaParserStorage.CompilationUnitAnnos). -
hasStorageLocationForMethod
Description 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 interfaceWholeProgramInferenceStorage<AnnotatedTypeMirror>- Parameters:
methodElt- a method or constructor Element- Returns:
- true if the storage has a method corresponding to
elt
-
getMethodDeclarationAnnotations
Description copied from interface:WholeProgramInferenceStorageReturn the list of declaration annotations inferred on the given method so far in this round of WPI.- Specified by:
getMethodDeclarationAnnotationsin interfaceWholeProgramInferenceStorage<AnnotatedTypeMirror>- Parameters:
methodElt- a method- Returns:
- the declaration annotations inferred on elt so far (may be empty)
-
getParameterAnnotations
public AnnotatedTypeMirror getParameterAnnotations(ExecutableElement methodElt, @org.checkerframework.checker.index.qual.Positive int index_1based, AnnotatedTypeMirror paramATM, VariableElement ve, AnnotatedTypeFactory atypeFactory) Description copied from interface:WholeProgramInferenceStorageGet the annotations for a formal parameter type.- Specified by:
getParameterAnnotationsin interfaceWholeProgramInferenceStorage<AnnotatedTypeMirror>- Parameters:
methodElt- the method or constructor Elementindex_1based- the parameter index (1-based)paramATM- the parameter typeve- the parameter variableatypeFactory- the type factory- Returns:
- the annotations for a formal parameter type
-
getReceiverAnnotations
public AnnotatedTypeMirror getReceiverAnnotations(ExecutableElement methodElt, AnnotatedTypeMirror paramATM, AnnotatedTypeFactory atypeFactory) Description copied from interface:WholeProgramInferenceStorageGet the annotations for the receiver type.- Specified by:
getReceiverAnnotationsin interfaceWholeProgramInferenceStorage<AnnotatedTypeMirror>- Parameters:
methodElt- the method or constructor ElementparamATM- the receiver typeatypeFactory- the type factory- Returns:
- the annotations for the receiver type
-
getReturnAnnotations
public AnnotatedTypeMirror getReturnAnnotations(ExecutableElement methodElt, AnnotatedTypeMirror atm, AnnotatedTypeFactory atypeFactory) Description copied from interface:WholeProgramInferenceStorageGet the annotations for the return type.- Specified by:
getReturnAnnotationsin interfaceWholeProgramInferenceStorage<AnnotatedTypeMirror>- Parameters:
methodElt- the method or constructor Elementatm- the return typeatypeFactory- the type factory- Returns:
- the annotations for the return type
-
getFieldAnnotations
public @Nullable AnnotatedTypeMirror getFieldAnnotations(Element element, String fieldName, AnnotatedTypeMirror lhsATM, AnnotatedTypeFactory atypeFactory) Description copied from interface:WholeProgramInferenceStorageGet the annotations for a field type.- Specified by:
getFieldAnnotationsin interfaceWholeProgramInferenceStorage<AnnotatedTypeMirror>- Parameters:
element- the element for the fieldfieldName- the simple field namelhsATM- the field typeatypeFactory- the annotated type factory- Returns:
- the annotations for a field type
-
getPreOrPostconditions
public AnnotatedTypeMirror 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 interfaceWholeProgramInferenceStorage<AnnotatedTypeMirror>- Parameters:
preOrPost- whether to get the precondition or postconditionmethodElement- the methodexpression- the expressiondeclaredType- the declared type of the expressionatypeFactory- the type factory- Returns:
- the pre- or postcondition annotations for an expression, or null if the given expression is not a supported expression type
-
addMethodDeclarationAnnotation
Description copied from interface:WholeProgramInferenceStorageUpdates a method to add a declaration annotation.- Specified by:
addMethodDeclarationAnnotationin interfaceWholeProgramInferenceStorage<AnnotatedTypeMirror>- Parameters:
methodElt- the method to annotateanno- the declaration annotation to add to the method- Returns:
- true if
annois a new declaration annotation formethodElt, false otherwise
-
removeMethodDeclarationAnnotation
Description copied from interface:WholeProgramInferenceStorageRemoves the given annotation from the given method element's inferred declaration annotation. If the given annotation was not in the list of inferred declaration annotations on the given method, calling this method is a no-op.- Specified by:
removeMethodDeclarationAnnotationin interfaceWholeProgramInferenceStorage<AnnotatedTypeMirror>- Parameters:
elt- a method elementanno- a declaration annotation to remove- Returns:
- true if the annotation was successfully removed, false if not (e.g., if it wasn't present)
-
addFieldDeclarationAnnotation
Description copied from interface:WholeProgramInferenceStorageUpdates a field to add a declaration annotation.- Specified by:
addFieldDeclarationAnnotationin interfaceWholeProgramInferenceStorage<AnnotatedTypeMirror>- Parameters:
field- the fieldanno- the declaration annotation to add to the field- Returns:
- true if
annois a new declaration annotation forfieldElt, false otherwise
-
addDeclarationAnnotationToFormalParameter
public boolean addDeclarationAnnotationToFormalParameter(ExecutableElement methodElt, @org.checkerframework.checker.index.qual.Positive int index_1based, AnnotationMirror anno) Description copied from interface:WholeProgramInferenceStorageAdds a declaration annotation to a formal parameter.- Specified by:
addDeclarationAnnotationToFormalParameterin interfaceWholeProgramInferenceStorage<AnnotatedTypeMirror>- Parameters:
methodElt- the method whose formal parameter will be annotatedindex_1based- the index of the parameter (1-indexed)anno- the annotation to add- Returns:
- true if
annois a new declaration annotation formethodElt, false otherwise
-
addClassDeclarationAnnotation
Description copied from interface:WholeProgramInferenceStorageAdds an annotation to a class declaration.- Specified by:
addClassDeclarationAnnotationin interfaceWholeProgramInferenceStorage<AnnotatedTypeMirror>- Parameters:
classElt- the class declaration to annotateanno- the annotation to add- Returns:
- true if
annois a new declaration annotation forclassElt, false otherwise
-
atmFromStorageLocation
public AnnotatedTypeMirror atmFromStorageLocation(TypeMirror typeMirror, AnnotatedTypeMirror storageLocation) Description copied from interface:WholeProgramInferenceStorageObtain the type from a storage location.- Specified by:
atmFromStorageLocationin interfaceWholeProgramInferenceStorage<AnnotatedTypeMirror>- Parameters:
typeMirror- the underlying type for the resultstorageLocation- the storage location from which to obtain annotations- Returns:
- an annotated type mirror with underlying type
typeMirrorand annotations fromstorageLocation
-
updateStorageLocationFromAtm
public void updateStorageLocationFromAtm(AnnotatedTypeMirror newATM, AnnotatedTypeMirror curATM, AnnotatedTypeMirror 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 interfaceWholeProgramInferenceStorage<AnnotatedTypeMirror>- Parameters:
newATM- the type whose annotations will be added to theAnnotatedTypeMirrorcurATM- 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 code
-
preprocessClassTree
Description 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 interfaceWholeProgramInferenceStorage<AnnotatedTypeMirror>- Parameters:
classTree- the class to preprocess
-
wpiPrepareCompilationUnitForWriting
public void wpiPrepareCompilationUnitForWriting(org.checkerframework.common.wholeprograminference.WholeProgramInferenceJavaParserStorage.CompilationUnitAnnos 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
-
wpiPrepareClassForWriting
public void wpiPrepareClassForWriting(org.checkerframework.common.wholeprograminference.WholeProgramInferenceJavaParserStorage.ClassOrInterfaceAnnos classAnnos, Collection<@BinaryName String> supertypes, Collection<@BinaryName String> subtypes) Side-effects the class annotations to make any desired changes before writing to a file.Because of the side effect, clients may want to pass a copy into this method.
- Parameters:
classAnnos- the class annotations to modifysupertypes- the binary names of all supertypes; not side-effectedsubtypes- the binary names of all subtypes; not side-effected
-
wpiPrepareMethodForWriting
public void wpiPrepareMethodForWriting(WholeProgramInferenceJavaParserStorage.CallableDeclarationAnnos methodAnnos, Collection<WholeProgramInferenceJavaParserStorage.CallableDeclarationAnnos> inSupertypes, Collection<WholeProgramInferenceJavaParserStorage.CallableDeclarationAnnos> inSubtypes) Side-effects the method or constructor annotations to make any desired changes before writing to a file. For example, this method may make inferred annotations consistent with one another between superclasses and subclasses.- Parameters:
methodAnnos- the method or constructor annotations to modifyinSupertypes- the method or constructor annotations for all overridden methods; not side-effectedinSubtypes- the method or constructor annotations for all overriding methods; not side-effected
-
writeResultsToFile
public 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 interfaceWholeProgramInferenceStorage<AnnotatedTypeMirror>- Parameters:
outputFormat- the file format in which to write the resultschecker- the checker from which this method is called, for naming annotation files
-