Search in sources :

Example 1 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(RichStringForLoop object, ITypeComputationState state) {
    LightweightTypeReference charSequence = getRawTypeForName(CharSequence.class, state);
    ITypeComputationState eachState = state.withExpectation(charSequence);
    JvmFormalParameter parameter = object.getDeclaredParam();
    if (parameter != null) {
        LightweightTypeReference parameterType = computeForLoopParameterType(object, state);
        eachState = eachState.assignType(parameter, parameterType);
    }
    eachState.computeTypes(object.getEachExpression());
    state.withNonVoidExpectation().computeTypes(object.getBefore());
    state.withNonVoidExpectation().computeTypes(object.getSeparator());
    state.withNonVoidExpectation().computeTypes(object.getAfter());
    LightweightTypeReference primitiveVoid = getPrimitiveVoid(state);
    state.acceptActualType(primitiveVoid);
    state.acceptActualType(charSequence);
}
Also used : ITypeComputationState(org.eclipse.xtext.xbase.typesystem.computation.ITypeComputationState) LightweightTypeReference(org.eclipse.xtext.xbase.typesystem.references.LightweightTypeReference) JvmFormalParameter(org.eclipse.xtext.common.types.JvmFormalParameter)

Example 2 with ITypeComputationState

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

the class ExtensionAwareClosureTypeComputer method createUnknownClosureTypeHelper.

@Override
protected UnknownClosureTypeHelper createUnknownClosureTypeHelper() {
    return new UnknownClosureTypeHelper(getClosure(), getExpectation(), getState()) {

        @Override
        protected ITypeComputationState assignParameters(ITypeAssigner typeAssigner) {
            ITypeComputationState result = super.assignParameters(typeAssigner);
            addExtensions(result);
            return result;
        }
    };
}
Also used : ITypeAssigner(org.eclipse.xtext.xbase.typesystem.computation.ITypeAssigner) ITypeComputationState(org.eclipse.xtext.xbase.typesystem.computation.ITypeComputationState) UnknownClosureTypeHelper(org.eclipse.xtext.xbase.typesystem.computation.UnknownClosureTypeHelper)

Example 3 with ITypeComputationState

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

the class ExtensionAwareClosureTypeComputer method createClosureWithExpectationHelper.

@Override
protected ClosureWithExpectationHelper createClosureWithExpectationHelper(JvmOperation operation) {
    return new ClosureWithExpectationHelper(getClosure(), operation, getExpectation(), getState()) {

        @Override
        protected ITypeComputationState assignParameters(ITypeAssigner typeAssigner) {
            ITypeComputationState result = super.assignParameters(typeAssigner);
            addExtensions(result);
            return result;
        }
    };
}
Also used : ITypeAssigner(org.eclipse.xtext.xbase.typesystem.computation.ITypeAssigner) ITypeComputationState(org.eclipse.xtext.xbase.typesystem.computation.ITypeComputationState) ClosureWithExpectationHelper(org.eclipse.xtext.xbase.typesystem.computation.ClosureWithExpectationHelper)

Example 4 with ITypeComputationState

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

the class ExtensionAwareClosureTypeComputer method createClosureWithoutExpectationHelper.

@Override
protected ClosureWithoutExpectationHelper createClosureWithoutExpectationHelper() {
    return new ClosureWithoutExpectationHelper(getClosure(), getExpectation(), getState()) {

        @Override
        protected ITypeComputationState assignParameters(ITypeAssigner typeAssigner, FunctionTypeReference incompleteClosureType) {
            ITypeComputationState result = super.assignParameters(typeAssigner, incompleteClosureType);
            addExtensions(result);
            return result;
        }
    };
}
Also used : ITypeAssigner(org.eclipse.xtext.xbase.typesystem.computation.ITypeAssigner) ITypeComputationState(org.eclipse.xtext.xbase.typesystem.computation.ITypeComputationState) FunctionTypeReference(org.eclipse.xtext.xbase.typesystem.references.FunctionTypeReference) ClosureWithoutExpectationHelper(org.eclipse.xtext.xbase.typesystem.computation.ClosureWithoutExpectationHelper)

Example 5 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