@NonNullByDefault
public interface ITypeComputationState
Modifier and Type | Method and Description |
---|---|
void |
acceptActualType(LightweightTypeReference type)
Annotates the currently considered expression(s) with the given type.
|
void |
acceptActualType(LightweightTypeReference type,
ConformanceHint... hints)
Annotates the currently considered expression(s) with the given type.
|
void |
addDiagnostic(AbstractDiagnostic diagnostic) |
void |
addExtensionsToCurrentScope(java.util.List<? extends JvmIdentifiableElement> extensionProviders)
Adds the given elements as extension providers to the current scope.
|
void |
addExtensionToCurrentScope(JvmIdentifiableElement extensionProvider)
Adds the given element as an extension provider to the current scope.
|
void |
addLocalToCurrentScope(JvmIdentifiableElement element)
Adds the given element as a local variable.
|
ITypeComputationState |
assignType(JvmIdentifiableElement element,
LightweightTypeReference type)
Assigns the type to the given element and makes the element available in the scope.
|
ITypeComputationState |
assignType(JvmIdentifiableElement element,
LightweightTypeReference type,
boolean addToChildScope)
Assigns the given type to the given element and optionally adds the element to the scope.
|
void |
assignType(QualifiedName name,
JvmType rawType,
LightweightTypeReference actualType)
Assigns the given actual type to the raw type which shall be reachable with the given name.
|
ITypeAssigner |
assignTypes()
Obtain a new
ITypeAssigner that allows to add a bulk of elements to this computation state. |
ITypeComputationResult |
computeTypes(XExpression expression)
Triggers type computation for a child expression of the currently considered expression.
|
UnboundTypeReference |
createUnboundTypeReference(XExpression expression,
JvmTypeParameter typeParameter)
Create a new, managed
UnboundTypeReference for the given type parameter which was
first encountered for the given expression. |
void |
discardReassignedTypes(JvmIdentifiableElement refinable)
A reassigned type may become obsolete due to assignments.
|
OwnedConverter |
getConverter()
Provides access to a configured
converter . |
java.util.List<? extends ITypeExpectation> |
getExpectations()
The result is never empty.
|
java.util.List<LightweightTypeReference> |
getExpectedExceptions() |
java.util.List<? extends IFeatureLinkingCandidate> |
getLinkingCandidates(XAbstractFeatureCall featureCall)
The result is never empty.
|
java.util.List<? extends IConstructorLinkingCandidate> |
getLinkingCandidates(XConstructorCall constructorCall)
The result is never empty.
|
ITypeReferenceOwner |
getReferenceOwner()
The current type reference owner for newly converted type references.
|
Severity |
getSeverity(java.lang.String issueCode) |
boolean |
isIgnored(java.lang.String issueCode) |
void |
reassignType(JvmIdentifiableElement refinable,
LightweightTypeReference type)
Allows to specialize the known type of an identifiable, that was already annotated
with a type.
|
void |
refineExpectedType(XExpression expression,
LightweightTypeReference expectation)
After the fact refinement of the expected type.
|
ITypeComputationState |
withExpectation(LightweightTypeReference expectation)
The given expectation will be resolved if it contains unresolved type
arguments, e.g. an operation that declares two parameters of the very
same type argument will yield a more detailed expectation if possible.
|
ITypeComputationState |
withExpectedExceptions(java.util.List<LightweightTypeReference> declaredExceptionTypes) |
ITypeComputationState |
withNonVoidExpectation()
Keep the current return expectation and assume an actual expectation that is not void.
|
ITypeComputationState |
withoutExpectation()
Keeps the return type expectation.
|
ITypeComputationState |
withoutRootExpectation()
The outer context is ignored for child expressions and the newly produced context
does not impose any restrictions on the expectation.
|
ITypeComputationState |
withReturnExpectation()
Transfers the available return type expectation to the actual expectation of this
computation step.
|
ITypeComputationState |
withRootExpectation(LightweightTypeReference expectation)
The given expectation becomes the expected return type and the expected type for
the current context.
|
ITypeComputationState |
withTypeCheckpoint(org.eclipse.emf.ecore.EObject context)
A type checkpoint allows to re-specify the type of an identifiable that was already
type-computed.
|
ITypeComputationState withExpectation(LightweightTypeReference expectation)
<T> T foo(T, T)
with
foo<String>(null, 'string')
will allow to pass the unresolved T
as expectation
where clients would be invoked with the better candidate 'string'.void refineExpectedType(XExpression expression, LightweightTypeReference expectation)
for(double d: produceIntArray) { }Expressions are resolved in the context of an expected type, which may or may not exist (e.g. it may be
null
).
The expectation for the call to produceIntArray
is double[]
.
However, the method returns an array of int. The tricky part is, that an int[]
is not assignable to a double[]
which would lead to incompatible types. Nevertheless,
the expression is valid, since the component type is relevant for the compatibility
in the context of a for-loop. Therefore, the expectation is refined after the fact to
int[]
because the conformance could be validated.ITypeComputationState withRootExpectation(LightweightTypeReference expectation)
ITypeComputationState withoutRootExpectation()
ITypeComputationState withNonVoidExpectation()
val x = someExpressionThe expectation for the call to
someExpression
is anything but void
.ITypeComputationState withReturnExpectation()
op someMethod: String { return someExpression }The actual expectation of the child
someExpression
is the return expectation
in that context, e.g. java.lang.String
in the given example.ITypeComputationState withoutExpectation()
{ someExpression subsequent }The expectation for the call to
someExpression
does not have any actual expectations.ITypeComputationState withTypeCheckpoint(@Nullable org.eclipse.emf.ecore.EObject context)
context
- an indicator that describes the context of this type checkpoint, e.g. an XCasePart
.ITypeComputationState withExpectedExceptions(java.util.List<LightweightTypeReference> declaredExceptionTypes)
java.util.List<LightweightTypeReference> getExpectedExceptions()
ITypeComputationResult computeTypes(@Nullable XExpression expression)
java.lang.IllegalArgumentException
- if the given expression is the currently computed expression.ITypeComputationState assignType(JvmIdentifiableElement element, @Nullable LightweightTypeReference type)
assignType(element, type, true)
.
Each element may only be typed once.element
- the identifiable that will be annotated with the given type.type
- the type of the element. null
or other invalid types will be treated as error types.assignType(JvmIdentifiableElement, LightweightTypeReference, boolean)
,
addLocalToCurrentScope(JvmIdentifiableElement)
,
assignTypes()
,
ITypeAssigner
ITypeComputationState assignType(JvmIdentifiableElement element, @Nullable LightweightTypeReference type, boolean addToChildScope)
element
- the identifiable that will be annotated with the given type.type
- the type of the element. null
or other invalid types will be treated as error types.addToChildScope
- true
if the element should be added to the child scope, false
if only the type
information should be recorded.ITypeAssigner
,
assignTypes()
,
addLocalToCurrentScope(JvmIdentifiableElement)
ITypeAssigner assignTypes()
ITypeAssigner
that allows to add a bulk of elements
to this computation state.void addLocalToCurrentScope(JvmIdentifiableElement element)
element
- the newly added element (e.g. a variable
or parameter
.FeatureNameValidator
void addExtensionToCurrentScope(JvmIdentifiableElement extensionProvider)
extensionProvider
- the identifiable that points to the extension providervoid addExtensionsToCurrentScope(java.util.List<? extends JvmIdentifiableElement> extensionProviders)
extensionProviders
- the identifiables that contribute to the extension scopevoid assignType(QualifiedName name, JvmType rawType, LightweightTypeReference actualType)
assignType(IFeatureNames.SELF, 'java.util.Comparator', 'java.util.Comparator<String>');
name
- the name of the feature that should point to the given type, e.g. IFeatureNames.THIS
rawType
- the type that declares the context of the expression.actualType
- the context type with bound type arguments (possibly unresolved).void addDiagnostic(AbstractDiagnostic diagnostic)
java.util.List<? extends ITypeExpectation> getExpectations()
java.util.List<? extends IConstructorLinkingCandidate> getLinkingCandidates(XConstructorCall constructorCall)
java.util.List<? extends IFeatureLinkingCandidate> getLinkingCandidates(XAbstractFeatureCall featureCall)
void acceptActualType(LightweightTypeReference type)
void acceptActualType(LightweightTypeReference type, ConformanceHint... hints)
void reassignType(JvmIdentifiableElement refinable, LightweightTypeReference type)
local variables
.
It's the clients responsibility to decide about that.
Example:
val Object x = obtainInstance if (x instanceof String && x.length > 0) { x.substring(1) }The instanceof expression may refine the type for subsequent expressions, e.g. in boolean conditions or blocks.
void discardReassignedTypes(JvmIdentifiableElement refinable)
var node = someNode; while(node instanceof ContainerNode) { node = node.container node.container // type error }After the assignment in the while loop, the node is no longer considered to be a ContainerNode.
ITypeReferenceOwner getReferenceOwner()
OwnedConverter getConverter()
converter
.UnboundTypeReference createUnboundTypeReference(XExpression expression, JvmTypeParameter typeParameter)
UnboundTypeReference
for the given type parameter which was
first encountered for the given expression.expression
- the expression that used / referenced the type parametertypeParameter
- the type parameterSeverity getSeverity(java.lang.String issueCode)
boolean isIgnored(java.lang.String issueCode)