Search in sources :

Example 1 with ITypeExpectation

use of org.eclipse.xtext.xbase.typesystem.computation.ITypeExpectation 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

RichString (org.eclipse.xtend.core.xtend.RichString)1 StringConcatenation (org.eclipse.xtend2.lib.StringConcatenation)1 XCastedExpression (org.eclipse.xtext.xbase.XCastedExpression)1 XExpression (org.eclipse.xtext.xbase.XExpression)1 XVariableDeclaration (org.eclipse.xtext.xbase.XVariableDeclaration)1 ITypeComputationState (org.eclipse.xtext.xbase.typesystem.computation.ITypeComputationState)1 ITypeExpectation (org.eclipse.xtext.xbase.typesystem.computation.ITypeExpectation)1 LightweightTypeReference (org.eclipse.xtext.xbase.typesystem.references.LightweightTypeReference)1