public class WholeProgramInferenceScenes extends Object implements WholeProgramInference
WholeProgramInference
that uses a storage
class (WholeProgramInferenceScenesStorage
) that
manipulates AScene
s 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.)
Constructor and Description |
---|
WholeProgramInferenceScenes(boolean ignoreNullAssignments)
Default constructor.
|
Modifier and Type | Method and Description |
---|---|
void |
saveResults()
Write all modified scenes into .jaif files.
|
void |
updateFromFieldAssignment(FieldAccessNode 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,
AnnotatedTypeFactory atf)
Updates the return type of the method
methodTree based on returnedExpression . |
public WholeProgramInferenceScenes(boolean ignoreNullAssignments)
ignoreNullAssignments
- indicates whether assignments where the rhs is null should be
ignoredpublic void updateFromObjectCreation(ObjectCreationNode objectCreationNode, ExecutableElement constructorElt, AnnotatedTypeFactory atf)
WholeProgramInference
constructorElt
based on the arguments
in objectCreationNode
.
For each parameter in constructorElt:
updateFromObjectCreation
in interface WholeProgramInference
objectCreationNode
- 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)
WholeProgramInference
methodElt
based on the arguments in the
method invocation methodInvNode
.
For each formal parameter in methodElt (including the receiver):
updateFromMethodInvocation
in interface WholeProgramInference
methodInvNode
- 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)
WholeProgramInference
methodTree
based
on the parameter types of the overridden method overriddenMethod
.
For each formal parameter in methodElt:
updateFromOverride
in interface WholeProgramInference
methodTree
- 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)
WholeProgramInference
lhs
based on an assignment of rhs
to lhs
.
updateFromLocalAssignment
in interface WholeProgramInference
lhs
- 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(FieldAccessNode lhs, Node rhs, ClassTree classTree, AnnotatedTypeFactory atf)
WholeProgramInference
field
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 WholeProgramInference
lhs
- the field whose type will be refinedrhs
- 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 updateFromReturn(ReturnNode retNode, com.sun.tools.javac.code.Symbol.ClassSymbol classSymbol, MethodTree methodTree, AnnotatedTypeFactory atf)
WholeProgramInference
methodTree
based on returnedExpression
.
If there is no stored annotated return type for the method methodTree, then the type of the return expression will be added to the return type of that method. If there is a stored annotated return type for the method methodTree, its new type will be the LUB between the previous type and the type of the return expression.
updateFromReturn
in interface WholeProgramInference
retNode
- 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 updatedatf
- the annotated type factory of a given type system, whose type hierarchy will be
used to update the method's return typepublic void saveResults()
saveResults
in interface WholeProgramInference