Search in sources :

Example 1 with InferenceResult

use of org.yakindu.base.types.inferrer.ITypeSystemInferrer.InferenceResult in project statecharts by Yakindu.

the class SGenJavaValidator method checkParameterValueType.

@Check
public void checkParameterValueType(final FeatureParameterValue parameterValue) {
    if (parameterValue == null || parameterValue.getExpression() == null)
        return;
    InferenceResult valueResult = inferrer.infer(parameterValue.getExpression());
    ParameterTypes parameterType = parameterValue.getParameter().getParameterType();
    typeValidator.assertAssignable(InferenceResult.from(mapType(parameterType)), valueResult, null, this);
}
Also used : InferenceResult(org.yakindu.base.types.inferrer.ITypeSystemInferrer.InferenceResult) ParameterTypes(org.yakindu.sct.model.sgen.ParameterTypes) Check(org.eclipse.xtext.validation.Check)

Example 2 with InferenceResult

use of org.yakindu.base.types.inferrer.ITypeSystemInferrer.InferenceResult in project statecharts by Yakindu.

the class SGenJavaValidator method checkInitialValue.

@Check(CheckType.FAST)
public void checkInitialValue(PropertyDefinition property) {
    if (property.getType() == null || property.getType().eIsProxy())
        return;
    InferenceResult expressionResult = inferrer.infer(property.getInitialValue(), this);
    typeValidator.assertAssignable(InferenceResult.from(property.getType()), expressionResult, null, this);
}
Also used : InferenceResult(org.yakindu.base.types.inferrer.ITypeSystemInferrer.InferenceResult) Check(org.eclipse.xtext.validation.Check)

Example 3 with InferenceResult

use of org.yakindu.base.types.inferrer.ITypeSystemInferrer.InferenceResult in project statecharts by Yakindu.

the class STextScopeProvider method scope_FeatureCall_feature.

public IScope scope_FeatureCall_feature(final FeatureCall context, EReference reference) {
    Predicate<IEObjectDescription> predicate = calculateFilterPredicate(context, reference);
    Expression owner = context.getOwner();
    EObject element = null;
    if (owner instanceof ElementReferenceExpression) {
        element = ((ElementReferenceExpression) owner).getReference();
    } else if (owner instanceof FeatureCall) {
        element = ((FeatureCall) owner).getFeature();
    } else {
        return getDelegate().getScope(context, reference);
    }
    IScope scope = IScope.NULLSCOPE;
    InferenceResult result = typeInferrer.infer(owner);
    Type ownerType = result != null ? result.getType() : null;
    if (element instanceof Scope) {
        scope = Scopes.scopeFor(((Scope) element).getDeclarations());
        return new FilteringScope(scope, predicate);
    } else if (ownerType != null) {
        scope = Scopes.scopeFor(typeSystem.getPropertyExtensions(ownerType));
        scope = Scopes.scopeFor(typeSystem.getOperationExtensions(ownerType), scope);
    }
    if (ownerType instanceof ComplexType) {
        return addScopeForComplexType((ComplexType) ownerType, scope, predicate);
    }
    if (ownerType instanceof EnumerationType) {
        return addScopeForEnumType((EnumerationType) ownerType, scope, predicate);
    }
    return scope;
}
Also used : InferenceResult(org.yakindu.base.types.inferrer.ITypeSystemInferrer.InferenceResult) EnumerationType(org.yakindu.base.types.EnumerationType) IEObjectDescription(org.eclipse.xtext.resource.IEObjectDescription) ComplexType(org.yakindu.base.types.ComplexType) EnumerationType(org.yakindu.base.types.EnumerationType) Type(org.yakindu.base.types.Type) FilteringScope(org.eclipse.xtext.scoping.impl.FilteringScope) InterfaceScope(org.yakindu.sct.model.stext.stext.InterfaceScope) Scope(org.yakindu.sct.model.sgraph.Scope) IScope(org.eclipse.xtext.scoping.IScope) SimpleScope(org.eclipse.xtext.scoping.impl.SimpleScope) InternalScope(org.yakindu.sct.model.stext.stext.InternalScope) ImportScope(org.eclipse.xtext.scoping.impl.ImportScope) Expression(org.yakindu.base.expressions.expressions.Expression) ElementReferenceExpression(org.yakindu.base.expressions.expressions.ElementReferenceExpression) EObject(org.eclipse.emf.ecore.EObject) IScope(org.eclipse.xtext.scoping.IScope) ElementReferenceExpression(org.yakindu.base.expressions.expressions.ElementReferenceExpression) FeatureCall(org.yakindu.base.expressions.expressions.FeatureCall) ComplexType(org.yakindu.base.types.ComplexType) FilteringScope(org.eclipse.xtext.scoping.impl.FilteringScope)

Example 4 with InferenceResult

use of org.yakindu.base.types.inferrer.ITypeSystemInferrer.InferenceResult in project statecharts by Yakindu.

the class TypeValidator method assertTypeBindingsSame.

public void assertTypeBindingsSame(InferenceResult result1, InferenceResult result2, String msg, IValidationIssueAcceptor acceptor) {
    List<InferenceResult> bindings1 = result1.getBindings();
    List<InferenceResult> bindings2 = result2.getBindings();
    msg = msg != null ? msg : String.format(ASSERT_COMPATIBLE, result1, result2);
    if (bindings1.size() != bindings2.size()) {
        acceptor.accept(new ValidationIssue(Severity.ERROR, msg, NOT_COMPATIBLE_CODE));
        return;
    }
    for (int i = 0; i < bindings1.size(); i++) {
        assertSame(bindings1.get(i), bindings2.get(i), msg, acceptor);
    }
}
Also used : InferenceResult(org.yakindu.base.types.inferrer.ITypeSystemInferrer.InferenceResult) ValidationIssue(org.yakindu.base.types.validation.IValidationIssueAcceptor.ValidationIssue)

Example 5 with InferenceResult

use of org.yakindu.base.types.inferrer.ITypeSystemInferrer.InferenceResult in project statecharts by Yakindu.

the class TypeValidator method assertNotType.

public void assertNotType(InferenceResult currentResult, String msg, IValidationIssueAcceptor acceptor, InferenceResult... candidates) {
    if (currentResult == null)
        return;
    for (InferenceResult type : candidates) {
        if (registry.isSame(currentResult.getType(), type.getType())) {
            msg = msg != null ? msg : String.format(ASSERT_NOT_TYPE, currentResult);
            acceptor.accept(new ValidationIssue(Severity.ERROR, msg, NOT_TYPE_CODE));
        }
    }
}
Also used : InferenceResult(org.yakindu.base.types.inferrer.ITypeSystemInferrer.InferenceResult) ValidationIssue(org.yakindu.base.types.validation.IValidationIssueAcceptor.ValidationIssue)

Aggregations

InferenceResult (org.yakindu.base.types.inferrer.ITypeSystemInferrer.InferenceResult)5 Check (org.eclipse.xtext.validation.Check)2 ValidationIssue (org.yakindu.base.types.validation.IValidationIssueAcceptor.ValidationIssue)2 EObject (org.eclipse.emf.ecore.EObject)1 IEObjectDescription (org.eclipse.xtext.resource.IEObjectDescription)1 IScope (org.eclipse.xtext.scoping.IScope)1 FilteringScope (org.eclipse.xtext.scoping.impl.FilteringScope)1 ImportScope (org.eclipse.xtext.scoping.impl.ImportScope)1 SimpleScope (org.eclipse.xtext.scoping.impl.SimpleScope)1 ElementReferenceExpression (org.yakindu.base.expressions.expressions.ElementReferenceExpression)1 Expression (org.yakindu.base.expressions.expressions.Expression)1 FeatureCall (org.yakindu.base.expressions.expressions.FeatureCall)1 ComplexType (org.yakindu.base.types.ComplexType)1 EnumerationType (org.yakindu.base.types.EnumerationType)1 Type (org.yakindu.base.types.Type)1 ParameterTypes (org.yakindu.sct.model.sgen.ParameterTypes)1 Scope (org.yakindu.sct.model.sgraph.Scope)1 InterfaceScope (org.yakindu.sct.model.stext.stext.InterfaceScope)1 InternalScope (org.yakindu.sct.model.stext.stext.InternalScope)1