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.)QualifierKey
won't be written into .jaif. (This will probably change once we support
type-checkers that use a CheckerAdapter.)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() node.atf
- the annotated type factory of a given type system, whose
type hierarchy will be used to update the constructor's parameters' types.constructorElt
- 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 parameter.methodElt
- the element of the method.overriddenMethod
- the AnnotatedExecutableType of the overridden
method.atf
- the annotated type factory of a given type system, whose
type hierarchy will be used to update the parameter type.public 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 invocation.receiverTree
- the Tree of the class that contains the method being
invoked.methodElt
- the element of the method being invoked.atf
- the annotated type factory of a given type system, whose
type hierarchy will be used to update the method parameters' types.public void updateInferredParameterType(LocalVariableNode lhs, Node rhs, ClassTree classTree, MethodTree methodTree, AnnotatedTypeFactory atf)
updateInferredParameterType
in interface WholeProgramInference
lhs
- the node representing the parameter.rhs
- the node being assigned to the parameter.classTree
- the tree of the class that contains the parameter.methodTree
- the tree of the method that contains the parameter.atf
- the annotated type factory of a given type system, whose
type hierarchy will be used to update the parameter type.public 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 receiver.methodElt
- the element of the method.overriddenMethod
- the overridden method.atf
- the annotated type factory of a given type system, whose
type hierarchy will be used to update the receiver type.public 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 refined.rhs
- the expression being assigned to the field.classTree
- the ClassTree for the enclosing class of the assignment.atf
- the annotated type factory of a given type system, whose
type hierarchy will be used to update the field's type.public 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 returned.classSymbol
- the symbol of the class that contains the method.methodTree
- the tree of the method whose return type
may be updated.atf
- the annotated type factory of a given type system, whose
type hierarchy will be used to update the method's return type.public void saveResults()
saveResults
in interface WholeProgramInference