Search in sources :

Example 6 with ITypeComputationState

use of org.eclipse.xtext.xbase.typesystem.computation.ITypeComputationState in project xtext-xtend by eclipse.

the class XtendTypeComputer method _computeTypes.

protected void _computeTypes(RichString object, ITypeComputationState state) {
    List<XExpression> expressions = object.getExpressions();
    if (!expressions.isEmpty()) {
        for (XExpression expression : expressions) {
            ITypeComputationState expressionState = state.withoutExpectation();
            expressionState.computeTypes(expression);
            if (expression instanceof XVariableDeclaration) {
                addLocalToCurrentScope((XVariableDeclaration) expression, state);
            }
        }
    }
    for (ITypeExpectation expectation : state.getExpectations()) {
        LightweightTypeReference expectedType = expectation.getExpectedType();
        if (expectedType != null && expectedType.isType(StringConcatenation.class)) {
            expectation.acceptActualType(expectedType, ConformanceFlags.CHECKED_SUCCESS | ConformanceFlags.DEMAND_CONVERSION);
        } else if (expectedType != null && expectedType.isType(StringConcatenationClient.class)) {
            expectation.acceptActualType(expectedType, ConformanceFlags.CHECKED_SUCCESS | ConformanceFlags.DEMAND_CONVERSION);
        } else if (expectedType != null && expectedType.isType(String.class)) {
            expectation.acceptActualType(expectedType, ConformanceFlags.CHECKED_SUCCESS | ConformanceFlags.DEMAND_CONVERSION);
        // TODO this special treatment here should become obsolete as soon as the expectations are properly propagated
        } else if (!(object.eContainer() instanceof XCastedExpression) && object.eContainingFeature() != XbasePackage.Literals.XMEMBER_FEATURE_CALL__MEMBER_CALL_TARGET && (expectedType != null && !expectedType.isResolved() || expectedType == null && !expectation.isVoidTypeAllowed())) {
            LightweightTypeReference type = getRawTypeForName(String.class, state);
            expectation.acceptActualType(type, ConformanceFlags.UNCHECKED | ConformanceFlags.DEMAND_CONVERSION);
        } else {
            LightweightTypeReference type = getRawTypeForName(CharSequence.class, state);
            expectation.acceptActualType(type, ConformanceFlags.UNCHECKED);
        }
    }
}
Also used : ITypeComputationState(org.eclipse.xtext.xbase.typesystem.computation.ITypeComputationState) XVariableDeclaration(org.eclipse.xtext.xbase.XVariableDeclaration) XCastedExpression(org.eclipse.xtext.xbase.XCastedExpression) LightweightTypeReference(org.eclipse.xtext.xbase.typesystem.references.LightweightTypeReference) StringConcatenation(org.eclipse.xtend2.lib.StringConcatenation) XExpression(org.eclipse.xtext.xbase.XExpression) RichString(org.eclipse.xtend.core.xtend.RichString) ITypeExpectation(org.eclipse.xtext.xbase.typesystem.computation.ITypeExpectation)

Aggregations

ITypeComputationState (org.eclipse.xtext.xbase.typesystem.computation.ITypeComputationState)6 ITypeAssigner (org.eclipse.xtext.xbase.typesystem.computation.ITypeAssigner)3 LightweightTypeReference (org.eclipse.xtext.xbase.typesystem.references.LightweightTypeReference)3 XExpression (org.eclipse.xtext.xbase.XExpression)2 RichString (org.eclipse.xtend.core.xtend.RichString)1 RichStringElseIf (org.eclipse.xtend.core.xtend.RichStringElseIf)1 StringConcatenation (org.eclipse.xtend2.lib.StringConcatenation)1 JvmFormalParameter (org.eclipse.xtext.common.types.JvmFormalParameter)1 XCastedExpression (org.eclipse.xtext.xbase.XCastedExpression)1 XVariableDeclaration (org.eclipse.xtext.xbase.XVariableDeclaration)1 ClosureWithExpectationHelper (org.eclipse.xtext.xbase.typesystem.computation.ClosureWithExpectationHelper)1 ClosureWithoutExpectationHelper (org.eclipse.xtext.xbase.typesystem.computation.ClosureWithoutExpectationHelper)1 ITypeExpectation (org.eclipse.xtext.xbase.typesystem.computation.ITypeExpectation)1 UnknownClosureTypeHelper (org.eclipse.xtext.xbase.typesystem.computation.UnknownClosureTypeHelper)1 FunctionTypeReference (org.eclipse.xtext.xbase.typesystem.references.FunctionTypeReference)1