Search in sources :

Example 6 with ScopeDefinition

use of com.avaloq.tools.ddk.xtext.scope.scope.ScopeDefinition in project dsl-devkit by dsldevkit.

the class ScopeJavaValidator method checkScopeRuleOverriding.

/**
 * Checks that the local scope rules do not override any inherited scope rules (not supported).
 *
 * @param context
 *          scoping section to check
 */
@Check
public void checkScopeRuleOverriding(final ScopeModel context) {
    final Set<ScopeDefinition> inheritedDefinitions = getAllInheritedScopeDefinitions(context);
    if (inheritedDefinitions.isEmpty()) {
        return;
    }
    final Map<String, ScopeRule> profileMap = Maps.newHashMap();
    for (ScopeDefinition def : inheritedDefinitions) {
        for (ScopeRule rule : def.getRules()) {
            final String profile = ScopeUtil.getSignature(rule);
            profileMap.put(profile, rule);
        }
    }
    for (ScopeDefinition def : context.getScopes()) {
        for (ScopeRule rule : def.getRules()) {
            final String profile = ScopeUtil.getSignature(rule);
            final ScopeRule other = profileMap.get(profile);
            if (other != null) {
                errorOnDuplicate(rule, other, Messages.overriddenInheritedScopeRule, ScopePackage.Literals.SCOPE_RULE__CONTEXT);
            }
        }
    }
}
Also used : ScopeDefinition(com.avaloq.tools.ddk.xtext.scope.scope.ScopeDefinition) ScopeRule(com.avaloq.tools.ddk.xtext.scope.scope.ScopeRule) Check(org.eclipse.xtext.validation.Check)

Example 7 with ScopeDefinition

use of com.avaloq.tools.ddk.xtext.scope.scope.ScopeDefinition in project dsl-devkit by dsldevkit.

the class ScopeJavaValidator method checkGuardDefaultExists.

/**
 * Checks that a guarded scope rule is matched by a unguarded default scope rule.
 *
 * @param context
 *          scope rule to check
 */
@Check
public void checkGuardDefaultExists(final ScopeRule context) {
    if (context.getContext() == null || context.getContext().getGuard() == null) {
        return;
    }
    ScopeDefinition def = EObjectUtil.eContainer(context, ScopeDefinition.class);
    ScopeContext ctx = context.getContext();
    boolean defaultFound = false;
    for (ScopeRule r : def.getRules()) {
        ScopeContext c = r.getContext();
        if (c != null && c.getGuard() == null && c.getContextType() == ctx.getContextType()) {
            defaultFound = true;
            break;
        }
    }
    if (!defaultFound) {
        warning("No matching default scope rule defined", ScopePackage.Literals.SCOPE_RULE__CONTEXT);
    }
}
Also used : ScopeDefinition(com.avaloq.tools.ddk.xtext.scope.scope.ScopeDefinition) ScopeContext(com.avaloq.tools.ddk.xtext.scope.scope.ScopeContext) ScopeRule(com.avaloq.tools.ddk.xtext.scope.scope.ScopeRule) Check(org.eclipse.xtext.validation.Check)

Example 8 with ScopeDefinition

use of com.avaloq.tools.ddk.xtext.scope.scope.ScopeDefinition in project dsl-devkit by dsldevkit.

the class ScopeJavaValidator method checkNameFunctionExists.

/**
 * Verifies that a matching default name function exists for scope expressions without explicit name functions.
 *
 * @param expr
 *          scope expression to check
 */
@Check
public void checkNameFunctionExists(final SimpleScopeExpression expr) {
    if (expr.getNaming() != null && !expr.getNaming().getNames().isEmpty()) {
        return;
    }
    ScopeDefinition def = EObjectUtil.eContainer(expr, ScopeDefinition.class);
    ScopeModel model = EObjectUtil.eContainer(expr, ScopeModel.class);
    if (def != null && model != null) {
        EClass scopeType = getType(def);
        NamingSection namingSection = model.getNaming();
        if (namingSection != null) {
            for (NamingDefinition naming : namingSection.getNamings()) {
                if (naming.getType() != null && isLeftMostSuperType(naming.getType(), scopeType)) {
                    return;
                }
            }
        }
        error(NLS.bind(Messages.missingNameFunction, scopeType.getName()), ScopePackage.Literals.SIMPLE_SCOPE_EXPRESSION__EXPR);
    }
}
Also used : ScopeDefinition(com.avaloq.tools.ddk.xtext.scope.scope.ScopeDefinition) EClass(org.eclipse.emf.ecore.EClass) ScopeModel(com.avaloq.tools.ddk.xtext.scope.scope.ScopeModel) NamingSection(com.avaloq.tools.ddk.xtext.scope.scope.NamingSection) NamingDefinition(com.avaloq.tools.ddk.xtext.scope.scope.NamingDefinition) Check(org.eclipse.xtext.validation.Check)

Aggregations

ScopeDefinition (com.avaloq.tools.ddk.xtext.scope.scope.ScopeDefinition)8 Check (org.eclipse.xtext.validation.Check)5 ScopeRule (com.avaloq.tools.ddk.xtext.scope.scope.ScopeRule)3 ScopeModel (com.avaloq.tools.ddk.xtext.scope.scope.ScopeModel)2 EClass (org.eclipse.emf.ecore.EClass)2 Expression (com.avaloq.tools.ddk.xtext.expression.expression.Expression)1 GlobalScopeExpression (com.avaloq.tools.ddk.xtext.scope.scope.GlobalScopeExpression)1 NamingDefinition (com.avaloq.tools.ddk.xtext.scope.scope.NamingDefinition)1 NamingSection (com.avaloq.tools.ddk.xtext.scope.scope.NamingSection)1 ScopeContext (com.avaloq.tools.ddk.xtext.scope.scope.ScopeContext)1 SimpleScopeExpression (com.avaloq.tools.ddk.xtext.scope.scope.SimpleScopeExpression)1 EReference (org.eclipse.emf.ecore.EReference)1 EStructuralFeature (org.eclipse.emf.ecore.EStructuralFeature)1 ENotificationImpl (org.eclipse.emf.ecore.impl.ENotificationImpl)1