public class WholeProgramInferenceScenes extends Object implements WholeProgramInference
WholeProgramInference
that uses a helper class
(WholeProgramInferenceScenesHelper
)
that manipulates .jaif files to perform whole-program inference.
Calling an update* method (updateInferredFieldType
, updateInferredMethodParameterTypes
, updateInferredParameterType
, or updateInferredMethodReturnType
) 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: an update* method ignores an explicitly annotated field, method return, or method parameter when passed as an argument.
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) |
Modifier and Type | Method and Description |
---|---|
void |
saveResults()
Write all modified scenes into .jaif files.
|
void |
updateInferredConstructorParameterTypes(ObjectCreationNode objectCreationNode,
ExecutableElement constructorElt,
AnnotatedTypeFactory atf)
Updates the parameter types of the constructor created by objectCreationNode based on
arguments to the constructor.
|
void |
updateInferredFieldType(FieldAccessNode lhs,
Node rhs,
ClassTree classTree,
AnnotatedTypeFactory atf)
Updates the type of the field lhs in the Scene of the class with tree classTree.
|
void |
updateInferredMethodParameterTypes(MethodInvocationNode methodInvNode,
Tree receiverTree,
ExecutableElement methodElt,
AnnotatedTypeFactory atf)
Updates the parameter types of the method methodElt in the Scene of the receiverTree's
enclosing class based on the arguments to the method.
|
void |
updateInferredMethodParameterTypes(MethodTree methodTree,
ExecutableElement methodElt,
AnnotatedTypeMirror.AnnotatedExecutableType overriddenMethod,
AnnotatedTypeFactory atf)
Updates the parameter types of the method
methodElt in the Scene of the method's
enclosing class based on the overridden method overriddenMethod parameter types. |
void |
updateInferredMethodReceiverType(MethodTree methodTree,
ExecutableElement methodElt,
AnnotatedTypeMirror.AnnotatedExecutableType overriddenMethod,
AnnotatedTypeFactory atf)
Updates the receiver type of the method
methodElt in the Scene of the method's
enclosing class based on the overridden method overriddenMethod receiver type. |
void |
updateInferredMethodReturnType(ReturnNode retNode,
com.sun.tools.javac.code.Symbol.ClassSymbol classSymbol,
MethodTree methodTree,
AnnotatedTypeFactory atf)
Updates the return type of the method methodTree in the Scene of the class with symbol
classSymbol.
|
void |
updateInferredParameterType(LocalVariableNode lhs,
Node rhs,
ClassTree classTree,
MethodTree methodTree,
AnnotatedTypeFactory atf)
Updates the parameter type represented by lhs of the method methodTree in the Scene of the
receiverTree's enclosing class based on assignments to the parameter inside the method body.
|
public WholeProgramInferenceScenes(boolean ignoreNullAssignments)
public void updateInferredConstructorParameterTypes(ObjectCreationNode objectCreationNode, ExecutableElement constructorElt, AnnotatedTypeFactory atf)
For each parameter in constructorElt:
updateInferredConstructorParameterTypes
in interface WholeProgramInference
objectCreationNode
- the new Object() nodeatf
- the annotated type factory of a given type system, whose type hierarchy will be
used to update the constructor's parameters' typesconstructorElt
- the Element of the constructorpublic void updateInferredMethodParameterTypes(MethodTree methodTree, ExecutableElement methodElt, AnnotatedTypeMirror.AnnotatedExecutableType overriddenMethod, AnnotatedTypeFactory atf)
methodElt
in the Scene of the method's
enclosing class based on the overridden method overriddenMethod
parameter types.
For each method parameter in methodElt:
updateInferredMethodParameterTypes
in interface WholeProgramInference
methodTree
- the tree of the method that contains the parametermethodElt
- 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 updateInferredMethodParameterTypes(MethodInvocationNode methodInvNode, Tree receiverTree, ExecutableElement methodElt, AnnotatedTypeFactory atf)
For each method parameter in methodElt:
updateInferredMethodParameterTypes
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 updateInferredParameterType(LocalVariableNode lhs, Node rhs, ClassTree classTree, MethodTree methodTree, AnnotatedTypeFactory atf)
updateInferredParameterType
in interface WholeProgramInference
lhs
- the node representing the parameterrhs
- the node being assigned to the parameterclassTree
- 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 updateInferredMethodReceiverType(MethodTree methodTree, ExecutableElement methodElt, AnnotatedTypeMirror.AnnotatedExecutableType overriddenMethod, AnnotatedTypeFactory atf)
methodElt
in the Scene of the method's
enclosing class based on the overridden method overriddenMethod
receiver type.
For the receiver in methodElt:
updateInferredMethodReceiverType
in interface WholeProgramInference
methodTree
- the tree of the method that contains the receivermethodElt
- the element of the methodoverriddenMethod
- the overridden methodatf
- the annotated type factory of a given type system, whose type hierarchy will be
used to update the receiver typepublic void updateInferredFieldType(FieldAccessNode lhs, Node rhs, ClassTree classTree, AnnotatedTypeFactory atf)
IgnoreInWholeProgramInference
meta-annotation,
no type annotation will be inferred for that field.
If the Scene contains no entry for the field lhs, the entry will be created and its type will be the type of rhs. If the Scene previously contained an entry/type for lhs, its new type will be the LUB between the previous type and the type of rhs.
updateInferredFieldType
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 updateInferredMethodReturnType(ReturnNode retNode, com.sun.tools.javac.code.Symbol.ClassSymbol classSymbol, MethodTree methodTree, 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.
updateInferredMethodReturnType
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