public abstract class AbstractTypeComputationState extends java.lang.Object implements ITypeComputationState
| Modifier and Type | Field and Description |
|---|---|
protected ResolvedTypes |
resolvedTypes |
| Modifier | Constructor and Description |
|---|---|
protected |
AbstractTypeComputationState(ResolvedTypes resolvedTypes,
IFeatureScopeSession featureScopeSession) |
| 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 |
acceptActualType(LightweightTypeReference type,
java.util.EnumSet<ConformanceHint> hints)
Annotates the currently considered expression(s) with the given type.
|
void |
acceptActualType(LightweightTypeReference type,
int flags)
Annotates the currently considered expression(s) with the given type.
|
void |
acceptCandidate(XExpression expression,
IApplicableCandidate candidate)
Allows to register a candidate that gets the chance to validate or change the state
of the AST in a subsequent processing step.
|
protected abstract LightweightTypeReference |
acceptType(ResolvedTypes types,
AbstractTypeExpectation expectation,
LightweightTypeReference type,
boolean returnType,
int flags) |
protected abstract LightweightTypeReference |
acceptType(XExpression alreadyHandled,
ResolvedTypes types,
AbstractTypeExpectation expectation,
LightweightTypeReference type,
boolean returnType,
int flags) |
void |
addDiagnostic(org.eclipse.xtext.diagnostics.AbstractDiagnostic diagnostic)
Adds the given diagnostic to the current state.
|
void |
addExtensionsToCurrentScope(java.util.List<? extends org.eclipse.xtext.common.types.JvmIdentifiableElement> extensionProviders)
Adds the given elements as extension providers to the current scope.
|
void |
addExtensionToCurrentScope(org.eclipse.xtext.common.types.JvmIdentifiableElement extensionProvider)
Adds the given element as an extension provider to the current scope.
|
void |
addImports(ITypeImporter.Client importer)
Allows to add several imports in a bulk operation on a fine grained basis,
e.g.
|
void |
addLocalToCurrentScope(org.eclipse.xtext.common.types.JvmIdentifiableElement element)
Adds the given element as a local variable.
|
protected void |
addLocalToCurrentScope(org.eclipse.xtext.naming.QualifiedName elementName,
org.eclipse.xtext.common.types.JvmIdentifiableElement element,
boolean raiseIssueIfShadowing) |
void |
addTypeToStaticExtensionImportScope(org.eclipse.xtext.common.types.JvmDeclaredType type)
Adds the given type to the static extension scope.
|
void |
addTypeToStaticImportScope(org.eclipse.xtext.common.types.JvmDeclaredType type)
Adds the given type to the static scope.
|
void |
afterScope(org.eclipse.emf.ecore.EObject context)
If the expression tree contains intermediate objects, e.g.
|
AbstractTypeComputationState |
assignType(org.eclipse.xtext.common.types.JvmIdentifiableElement element,
LightweightTypeReference type)
Assigns the type to the given element and makes the element available in the scope.
|
AbstractTypeComputationState |
assignType(org.eclipse.xtext.common.types.JvmIdentifiableElement element,
LightweightTypeReference type,
boolean addToChildScope)
Assigns the given type to the given element and optionally adds the element to the scope.
|
void |
assignType(org.eclipse.xtext.naming.QualifiedName name,
org.eclipse.xtext.common.types.JvmType rawType,
LightweightTypeReference actualType)
Assigns the given actual type to the raw type which shall be reachable with the given name.
|
TypeAssigner |
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.
|
protected IFeatureLinkingCandidate |
createCandidate(XAbstractFeatureCall featureCall,
StackedResolvedTypes demandComputedTypes,
IIdentifiableElementDescription description) |
protected IConstructorLinkingCandidate |
createCandidate(XConstructorCall constructorCall,
IIdentifiableElementDescription description) |
protected IFeatureLinkingCandidate |
createCandidateWithReceiverType(XAbstractFeatureCall featureCall,
StackedResolvedTypes demandComputedTypes,
IIdentifiableElementDescription description) |
protected ExpressionTypeComputationState |
createExpressionComputationState(XExpression expression,
StackedResolvedTypes typeResolution) |
protected IFeatureLinkingCandidate |
createResolvedLink(XAbstractFeatureCall featureCall,
org.eclipse.xtext.common.types.JvmIdentifiableElement resolvedTo) |
protected IConstructorLinkingCandidate |
createResolvedLink(XConstructorCall constructorCall,
org.eclipse.xtext.common.types.JvmConstructor resolvedTo) |
protected TypeAssigner |
createTypeAssigner(AbstractTypeComputationState state) |
UnboundTypeReference |
createUnboundTypeReference(XExpression expression,
org.eclipse.xtext.common.types.JvmTypeParameter typeParameter)
Create a new, managed
UnboundTypeReference for the given type parameter which was
first encountered for the given expression. |
void |
discardReassignedTypes(org.eclipse.xtext.common.types.JvmIdentifiableElement refinable)
A reassigned type may become obsolete due to assignments.
|
protected ExpressionAwareStackedResolvedTypes |
doComputeTypes(XExpression expression) |
java.util.List<? extends ITypeExpectation> |
getExpectations()
The result is never empty.
|
protected abstract java.util.List<AbstractTypeExpectation> |
getExpectations(AbstractTypeComputationState actualState) |
java.util.List<LightweightTypeReference> |
getExpectedExceptions() |
IFeatureScopeSession |
getFeatureScopeSession() |
java.util.List<IFeatureLinkingCandidate> |
getLinkingCandidates(XAbstractFeatureCall featureCall)
The result is never empty.
|
java.util.List<IConstructorLinkingCandidate> |
getLinkingCandidates(XConstructorCall constructorCall)
The result is never empty.
|
ITypeReferenceOwner |
getReferenceOwner()
The current type reference owner for newly converted type references.
|
ResolvedTypes |
getResolvedTypes() |
protected DefaultReentrantTypeResolver |
getResolver() |
protected java.util.List<? extends ITypeExpectation> |
getReturnExpectations() |
protected abstract java.util.List<AbstractTypeExpectation> |
getReturnExpectations(AbstractTypeComputationState actualState,
boolean asActualExpectation) |
protected org.eclipse.xtext.validation.IssueSeverities |
getSeverities() |
org.eclipse.xtext.diagnostics.Severity |
getSeverity(java.lang.String issueCode)
Returns the severity for the given
issueCode. |
protected ITypeExpectation |
getSingleExpectation(ITypeComputationState state) |
protected ITypeComputer |
getTypeComputer() |
protected org.eclipse.xtext.common.types.util.TypeReferences |
getTypeReferences() |
boolean |
isIgnored(java.lang.String issueCode)
Returns
false if no issues have to be produced for the given issueCode. |
protected ExpressionAwareStackedResolvedTypes |
pushTypes(XExpression expression) |
void |
reassignType(org.eclipse.xtext.common.types.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.
|
void |
rewriteScope(org.eclipse.emf.ecore.EObject context)
If the container of an expression decides to alter the scope after the
expression was typed, its AFTER scope may be rewritten.
|
protected IIdentifiableElementDescription |
toIdentifiableDescription(org.eclipse.xtext.resource.IEObjectDescription description) |
java.lang.String |
toString() |
TypeComputationStateWithExpectation |
withExpectation(LightweightTypeReference expectation)
The given expectation will be resolved if it contains unresolved type
arguments, e.g.
|
AbstractTypeComputationState |
withExpectedExceptions(java.util.List<LightweightTypeReference> declaredExceptionTypes) |
void |
withinScope(org.eclipse.emf.ecore.EObject context)
If the expression tree contains expressions that define a new scope, e.g.
|
AbstractTypeComputationState |
withNonVoidExpectation()
Keep the current return expectation and assume an actual expectation that is not void.
|
protected AbstractTypeComputationState |
withNonVoidExpectation(ResolvedTypes resolvedTypes) |
AbstractTypeComputationState |
withoutExpectation()
Keeps the return type expectation.
|
TypeComputationStateWithRootExpectation |
withoutRootExpectation()
The outer context is ignored for child expressions and the newly produced context
does not impose any restrictions on the expectation.
|
AbstractTypeComputationState |
withReturnExpectation()
Transfers the available return type expectation to the actual expectation of this
computation step.
|
TypeComputationStateWithRootExpectation |
withRootExpectation(LightweightTypeReference expectation)
The given expectation becomes the expected return type and the expected type for
the current context.
|
TypeCheckpointComputationState |
withTypeCheckpoint(org.eclipse.emf.ecore.EObject context)
A type checkpoint allows to re-specify the type of an identifiable that was already
type-computed.
|
protected final ResolvedTypes resolvedTypes
protected AbstractTypeComputationState(ResolvedTypes resolvedTypes, IFeatureScopeSession featureScopeSession)
public ResolvedTypes getResolvedTypes()
public IFeatureScopeSession getFeatureScopeSession()
protected org.eclipse.xtext.common.types.util.TypeReferences getTypeReferences()
protected ITypeComputer getTypeComputer()
protected DefaultReentrantTypeResolver getResolver()
protected abstract LightweightTypeReference acceptType(ResolvedTypes types, AbstractTypeExpectation expectation, LightweightTypeReference type, boolean returnType, int flags)
protected abstract LightweightTypeReference acceptType(XExpression alreadyHandled, ResolvedTypes types, AbstractTypeExpectation expectation, LightweightTypeReference type, boolean returnType, int flags)
public final ITypeComputationResult computeTypes(XExpression expression)
ITypeComputationStatecomputeTypes in interface ITypeComputationStateprotected ExpressionAwareStackedResolvedTypes doComputeTypes(XExpression expression)
protected ExpressionAwareStackedResolvedTypes pushTypes(XExpression expression)
protected ExpressionTypeComputationState createExpressionComputationState(XExpression expression, StackedResolvedTypes typeResolution)
public TypeComputationStateWithExpectation withExpectation(LightweightTypeReference expectation)
ITypeComputationState<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'.withExpectation in interface ITypeComputationStatepublic void refineExpectedType(XExpression expression, LightweightTypeReference expectation)
ITypeComputationState
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.refineExpectedType in interface ITypeComputationStatepublic TypeComputationStateWithRootExpectation withRootExpectation(LightweightTypeReference expectation)
ITypeComputationStatewithRootExpectation in interface ITypeComputationStatepublic TypeComputationStateWithRootExpectation withoutRootExpectation()
ITypeComputationStatewithoutRootExpectation in interface ITypeComputationStatepublic AbstractTypeComputationState withNonVoidExpectation()
ITypeComputationStateval x = someExpressionThe expectation for the call to
someExpression is anything but void.withNonVoidExpectation in interface ITypeComputationStateprotected AbstractTypeComputationState withNonVoidExpectation(ResolvedTypes resolvedTypes)
public AbstractTypeComputationState withReturnExpectation()
ITypeComputationState
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.withReturnExpectation in interface ITypeComputationStatepublic AbstractTypeComputationState withoutExpectation()
ITypeComputationState
{
someExpression
subsequent
}
The expectation for the call to someExpression does not have any actual expectations.withoutExpectation in interface ITypeComputationStatepublic TypeCheckpointComputationState withTypeCheckpoint(org.eclipse.emf.ecore.EObject context)
ITypeComputationStatewithTypeCheckpoint in interface ITypeComputationStatecontext - an indicator that describes the context of this type checkpoint, e.g. an XCasePart.public AbstractTypeComputationState withExpectedExceptions(java.util.List<LightweightTypeReference> declaredExceptionTypes)
withExpectedExceptions in interface ITypeComputationStatepublic AbstractTypeComputationState assignType(org.eclipse.xtext.common.types.JvmIdentifiableElement element, LightweightTypeReference type)
ITypeComputationStateassignType(element, type, true).
Each element may only be typed once.assignType in interface ITypeComputationStateelement - 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.ITypeComputationState.assignType(JvmIdentifiableElement, LightweightTypeReference, boolean),
ITypeComputationState.addLocalToCurrentScope(JvmIdentifiableElement),
ITypeComputationState.assignTypes(),
ITypeAssignerpublic AbstractTypeComputationState assignType(org.eclipse.xtext.common.types.JvmIdentifiableElement element, LightweightTypeReference type, boolean addToChildScope)
ITypeComputationStateassignType in interface ITypeComputationStateelement - 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,
ITypeComputationState.assignTypes(),
ITypeComputationState.addLocalToCurrentScope(JvmIdentifiableElement)public void addLocalToCurrentScope(org.eclipse.xtext.common.types.JvmIdentifiableElement element)
ITypeComputationStateaddLocalToCurrentScope in interface ITypeComputationStateelement - the newly added element (e.g. a variable or parameter.FeatureNameValidatorpublic void addExtensionToCurrentScope(org.eclipse.xtext.common.types.JvmIdentifiableElement extensionProvider)
ITypeComputationStateaddExtensionToCurrentScope in interface ITypeComputationStateextensionProvider - the identifiable that points to the extension providerpublic void addTypeToStaticImportScope(org.eclipse.xtext.common.types.JvmDeclaredType type)
ITypeComputationStateaddTypeToStaticImportScope in interface ITypeComputationStatetype - the type that is added to the static scope.public void addTypeToStaticExtensionImportScope(org.eclipse.xtext.common.types.JvmDeclaredType type)
ITypeComputationStateaddTypeToStaticExtensionImportScope in interface ITypeComputationStatetype - the type that is added to the static extension scope.public void addImports(ITypeImporter.Client importer)
ITypeComputationStateaddImports in interface ITypeComputationStatepublic void addExtensionsToCurrentScope(java.util.List<? extends org.eclipse.xtext.common.types.JvmIdentifiableElement> extensionProviders)
ITypeComputationStateaddExtensionsToCurrentScope in interface ITypeComputationStateextensionProviders - the identifiables that contribute to the extension scopeprotected void addLocalToCurrentScope(org.eclipse.xtext.naming.QualifiedName elementName,
org.eclipse.xtext.common.types.JvmIdentifiableElement element,
boolean raiseIssueIfShadowing)
public void assignType(org.eclipse.xtext.naming.QualifiedName name,
org.eclipse.xtext.common.types.JvmType rawType,
LightweightTypeReference actualType)
ITypeComputationState
assignType(IFeatureNames.SELF, 'java.util.Comparator', 'java.util.Comparator<String>');
assignType in interface ITypeComputationStatename - the name of the feature that should point to the given type, e.g. IFeatureNames.THISrawType - the type that declares the context of the expression.actualType - the context type with bound type arguments (possibly unresolved).public TypeAssigner assignTypes()
ITypeComputationStateITypeAssigner that allows to add a bulk of elements to this computation state.assignTypes in interface ITypeComputationStatepublic void addDiagnostic(org.eclipse.xtext.diagnostics.AbstractDiagnostic diagnostic)
ITypeComputationStateaddDiagnostic in interface ITypeComputationStateprotected TypeAssigner createTypeAssigner(AbstractTypeComputationState state)
public final java.util.List<? extends ITypeExpectation> getExpectations()
ITypeComputationStategetExpectations in interface ITypeComputationStateprotected final java.util.List<? extends ITypeExpectation> getReturnExpectations()
protected abstract java.util.List<AbstractTypeExpectation> getExpectations(AbstractTypeComputationState actualState)
protected abstract java.util.List<AbstractTypeExpectation> getReturnExpectations(AbstractTypeComputationState actualState, boolean asActualExpectation)
public void acceptCandidate(XExpression expression, IApplicableCandidate candidate)
ITypeComputationStateacceptCandidate in interface ITypeComputationStateexpression - the expression that the given candidate is associated with.candidate - the candidate to validate if it is still present at the root of the decision tree.IClosureCandidatepublic void acceptActualType(LightweightTypeReference type)
ITypeComputationStateacceptActualType in interface ITypeComputationStatepublic void acceptActualType(LightweightTypeReference type, ConformanceHint... hints)
ITypeComputationStateacceptActualType in interface ITypeComputationStatepublic void acceptActualType(LightweightTypeReference type, java.util.EnumSet<ConformanceHint> hints)
ITypeComputationStateacceptActualType in interface ITypeComputationStatepublic void acceptActualType(LightweightTypeReference type, int flags)
ITypeComputationStateacceptActualType in interface ITypeComputationStateConformanceFlagspublic void reassignType(org.eclipse.xtext.common.types.JvmIdentifiableElement refinable,
LightweightTypeReference type)
ITypeComputationStatelocal 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.reassignType in interface ITypeComputationStatepublic void discardReassignedTypes(org.eclipse.xtext.common.types.JvmIdentifiableElement refinable)
ITypeComputationState
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.discardReassignedTypes in interface ITypeComputationStatepublic java.util.List<IFeatureLinkingCandidate> getLinkingCandidates(XAbstractFeatureCall featureCall)
ITypeComputationStategetLinkingCandidates in interface ITypeComputationStateprotected IFeatureLinkingCandidate createResolvedLink(XAbstractFeatureCall featureCall, org.eclipse.xtext.common.types.JvmIdentifiableElement resolvedTo)
protected IFeatureLinkingCandidate createCandidate(XAbstractFeatureCall featureCall, StackedResolvedTypes demandComputedTypes, IIdentifiableElementDescription description)
protected ITypeExpectation getSingleExpectation(ITypeComputationState state)
protected IFeatureLinkingCandidate createCandidateWithReceiverType(XAbstractFeatureCall featureCall, StackedResolvedTypes demandComputedTypes, IIdentifiableElementDescription description)
public java.util.List<IConstructorLinkingCandidate> getLinkingCandidates(XConstructorCall constructorCall)
ITypeComputationStategetLinkingCandidates in interface ITypeComputationStateprotected IIdentifiableElementDescription toIdentifiableDescription(org.eclipse.xtext.resource.IEObjectDescription description)
protected IConstructorLinkingCandidate createResolvedLink(XConstructorCall constructorCall, org.eclipse.xtext.common.types.JvmConstructor resolvedTo)
protected IConstructorLinkingCandidate createCandidate(XConstructorCall constructorCall, IIdentifiableElementDescription description)
public java.lang.String toString()
toString in class java.lang.Objectpublic ITypeReferenceOwner getReferenceOwner()
ITypeComputationStategetReferenceOwner in interface ITypeComputationStatepublic UnboundTypeReference createUnboundTypeReference(XExpression expression, org.eclipse.xtext.common.types.JvmTypeParameter typeParameter)
ITypeComputationStateUnboundTypeReference for the given type parameter which was
first encountered for the given expression.createUnboundTypeReference in interface ITypeComputationStateexpression - the expression that used / referenced the type parametertypeParameter - the type parameterpublic java.util.List<LightweightTypeReference> getExpectedExceptions()
getExpectedExceptions in interface ITypeComputationStateprotected org.eclipse.xtext.validation.IssueSeverities getSeverities()
public org.eclipse.xtext.diagnostics.Severity getSeverity(java.lang.String issueCode)
ITypeComputationStateissueCode.getSeverity in interface ITypeComputationStatepublic boolean isIgnored(java.lang.String issueCode)
ITypeComputationStatefalse if no issues have to be produced for the given issueCode.isIgnored in interface ITypeComputationStatepublic void withinScope(org.eclipse.emf.ecore.EObject context)
ITypeComputationStateXForLoopExpression would do, the scope for contained expressions may
be explicitly recorded by announcing that the inference is now done within that newly created scope.withinScope in interface ITypeComputationStatepublic void afterScope(org.eclipse.emf.ecore.EObject context)
ITypeComputationStateXCasePart
or XCatchClause, one can explicitly record the scope of these
objects as these won't be processed by the inference infrastructure.afterScope in interface ITypeComputationStatepublic void rewriteScope(org.eclipse.emf.ecore.EObject context)
ITypeComputationStaterewriteScope in interface ITypeComputationState