public class WholeProgramInferenceScenes extends Object implements WholeProgramInference
WholeProgramInference that uses a storage
class (WholeProgramInferenceScenesStorage) that
manipulates AScenes to perform whole-program inference, and
writes them out to a .jaif file at the end.
Calling an update* method replaces the currently-stored type for an element in a AScene, if any, by the LUB of it and the update method's argument.
This class does not perform inference for an element if the element has explicit annotations: calling an update* method on an explicitly annotated field, method return, or method parameter has no effect.
In addition, whole program inference ignores inferred types in a few scenarios. When discovering a use, if:
null literal, except when doing inference for the
NullnessChecker. (The rationale for this is that null is a frequently-used default
value, and it would be undesirable to compute any inferred type if null were the
only value passed as an argument.)
WholeProgramInference.OutputFormat| Constructor and Description |
|---|
WholeProgramInferenceScenes(boolean ignoreNullAssignments)
Default constructor.
|
| Modifier and Type | Method and Description |
|---|---|
void |
addMethodDeclarationAnnotation(ExecutableElement methodElt,
AnnotationMirror anno)
Updates a method to add a declaration annotation.
|
void |
updateFieldFromType(Tree lhsTree,
Element element,
String fieldName,
AnnotatedTypeMirror rhsATM,
AnnotatedTypeFactory atf)
Updates the type of
field based on an assignment whose right-hand side has type
rhsATM. |
void |
updateFromFieldAssignment(Node lhs,
Node rhs,
ClassTree classTree,
AnnotatedTypeFactory atf)
Updates the type of
field based on an assignment of rhs to field. |
void |
updateFromLocalAssignment(LocalVariableNode lhs,
Node rhs,
ClassTree classTree,
MethodTree methodTree,
AnnotatedTypeFactory atf)
Updates the type of
lhs based on an assignment of rhs to lhs. |
void |
updateFromMethodInvocation(MethodInvocationNode methodInvNode,
Tree receiverTree,
ExecutableElement methodElt,
AnnotatedTypeFactory atf)
Updates the parameter types of the method
methodElt based on the arguments in the
method invocation methodInvNode. |
void |
updateFromObjectCreation(ObjectCreationNode objectCreationNode,
ExecutableElement constructorElt,
AnnotatedTypeFactory atf)
Updates the parameter types of the constructor
constructorElt based on the arguments
in objectCreationNode. |
void |
updateFromOverride(MethodTree methodTree,
ExecutableElement methodElt,
AnnotatedTypeMirror.AnnotatedExecutableType overriddenMethod,
AnnotatedTypeFactory atf)
Updates the parameter types (including the receiver) of the method
methodTree based
on the parameter types of the overridden method overriddenMethod. |
void |
updateFromReturn(ReturnNode retNode,
com.sun.tools.javac.code.Symbol.ClassSymbol classSymbol,
MethodTree methodTree,
Map<AnnotatedTypeMirror.AnnotatedDeclaredType,ExecutableElement> overriddenMethods,
AnnotatedTypeFactory atf)
Updates the return type of the method methodTree in the Scene of the class with symbol
classSymbol.
|
void |
writeResultsToFile(WholeProgramInference.OutputFormat outputFormat,
BaseTypeChecker checker)
Writes the inferred results to a file.
|
public WholeProgramInferenceScenes(boolean ignoreNullAssignments)
ignoreNullAssignments - indicates whether assignments where the rhs is null should be
ignoredpublic void updateFromObjectCreation(ObjectCreationNode objectCreationNode, ExecutableElement constructorElt, AnnotatedTypeFactory atf)
WholeProgramInferenceconstructorElt based on the arguments
in objectCreationNode.
For each parameter in constructorElt:
updateFromObjectCreation in interface WholeProgramInferenceobjectCreationNode - the Node that invokes the constructorconstructorElt - the Element of the constructoratf - the annotated type factory of a given type system, whose type hierarchy will be
used to update the constructor's parameters' typespublic void updateFromMethodInvocation(MethodInvocationNode methodInvNode, Tree receiverTree, ExecutableElement methodElt, AnnotatedTypeFactory atf)
WholeProgramInferencemethodElt based on the arguments in the
method invocation methodInvNode.
For each formal parameter in methodElt (including the receiver):
updateFromMethodInvocation in interface WholeProgramInferencemethodInvNode - the node representing a method invocationreceiverTree - the Tree of the class that contains the method being invokedmethodElt - the element of the method being invokedatf - the annotated type factory of a given type system, whose type hierarchy will be
used to update the method parameters' typespublic void updateFromOverride(MethodTree methodTree, ExecutableElement methodElt, AnnotatedTypeMirror.AnnotatedExecutableType overriddenMethod, AnnotatedTypeFactory atf)
WholeProgramInferencemethodTree based
on the parameter types of the overridden method overriddenMethod.
For each formal parameter in methodElt:
updateFromOverride in interface WholeProgramInferencemethodTree - the tree of the method that contains the parameter(s)methodElt - the element of the methodoverriddenMethod - the AnnotatedExecutableType of the overridden methodatf - the annotated type factory of a given type system, whose type hierarchy will be
used to update the parameter typepublic void updateFromLocalAssignment(LocalVariableNode lhs, Node rhs, ClassTree classTree, MethodTree methodTree, AnnotatedTypeFactory atf)
WholeProgramInferencelhs based on an assignment of rhs to lhs.
updateFromLocalAssignment in interface WholeProgramInferencelhs - the node representing the local variable, such as a formal parameterrhs - the node being assigned to the parameter in the method bodyclassTree - the tree of the class that contains the parametermethodTree - the tree of the method that contains the parameteratf - the annotated type factory of a given type system, whose type hierarchy will be
used to update the parameter typepublic void updateFromFieldAssignment(Node lhs, Node rhs, ClassTree classTree, AnnotatedTypeFactory atf)
WholeProgramInferencefield based on an assignment of rhs to field. If
the field has a declaration annotation with the IgnoreInWholeProgramInference
meta-annotation, no type annotation will be inferred for that field.
If there is no stored entry for the field lhs, the entry will be created and its type will be the type of rhs. If there is a stored entry/type for lhs, its new type will be the LUB between the previous type and the type of rhs.
updateFromFieldAssignment in interface WholeProgramInferencelhs - the field whose type will be refined. Must be either a FieldAccessNode or a
LocalVariableNode whose element kind is FIELD.rhs - the expression being assigned to the fieldclassTree - the ClassTree for the enclosing class of the assignmentatf - the annotated type factory of a given type system, whose type hierarchy will be
used to update the field's typepublic void updateFieldFromType(Tree lhsTree, Element element, String fieldName, AnnotatedTypeMirror rhsATM, AnnotatedTypeFactory atf)
field based on an assignment whose right-hand side has type
rhsATM. See more details at updateFromFieldAssignment(org.checkerframework.dataflow.cfg.node.Node, org.checkerframework.dataflow.cfg.node.Node, com.sun.source.tree.ClassTree, org.checkerframework.framework.type.AnnotatedTypeFactory).lhsTree - the tree for the field whose type will be refinedelement - the element for the field whose type will be refinedfieldName - the name of the field whose type will be refinedrhsATM - the type of the expression being assigned to the fieldatf - the annotated type factorypublic void updateFromReturn(ReturnNode retNode, com.sun.tools.javac.code.Symbol.ClassSymbol classSymbol, MethodTree methodTree, Map<AnnotatedTypeMirror.AnnotatedDeclaredType,ExecutableElement> overriddenMethods, AnnotatedTypeFactory atf)
If the Scene does not contain an annotated return type for the method methodTree, then the type of the value passed to the return expression will be added to the return type of that method in the Scene. If the Scene previously contained an annotated return type for the method methodTree, its new type will be the LUB between the previous type and the type of the value passed to the return expression.
updateFromReturn in interface WholeProgramInferenceretNode - the node that contains the expression returnedclassSymbol - the symbol of the class that contains the methodmethodTree - the tree of the method whose return type may be updatedoverriddenMethods - the methods that the given method return overrides, each indexed by
the annotated type of the class that defines itatf - the annotated type factory of a given type system, whose type hierarchy will be
used to update the method's return typepublic void addMethodDeclarationAnnotation(ExecutableElement methodElt, AnnotationMirror anno)
WholeProgramInferenceaddMethodDeclarationAnnotation in interface WholeProgramInferencemethodElt - the method to annotateanno - the declaration annotation to add to the methodpublic void writeResultsToFile(WholeProgramInference.OutputFormat outputFormat, BaseTypeChecker checker)
WholeProgramInferencewriteResultsToFile in interface WholeProgramInferenceoutputFormat - the file format in which to write the resultschecker - the checker from which this method is called, for naming stub files