Search in sources :

Example 1 with ScopeRule

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

the class ScopeJavaValidator method checkScopeRuleUniqueness.

/**
 * Checks that the all local scope rules (i.e. excluding inherited rules) have a unique context (context type, reference,
 * guard).
 *
 * @param context
 *          scoping section to check
 */
@Check
public void checkScopeRuleUniqueness(final ScopeModel context) {
    final Map<String, ScopeRule> profileMap = Maps.newHashMap();
    for (ScopeDefinition def : context.getScopes()) {
        for (ScopeRule rule : def.getRules()) {
            final Expression guard = rule.getContext().getGuard();
            // $NON-NLS-1$ //$NON-NLS-2$
            final String profile = ScopeUtil.getSignature(rule) + ":" + (guard != null ? serializer.serialize(guard) : "");
            final ScopeRule other = profileMap.get(profile);
            if (other != null) {
                errorOnDuplicate(rule, other, Messages.duplicatedScopeRule, ScopePackage.Literals.SCOPE_RULE__CONTEXT);
            } else {
                profileMap.put(profile, rule);
            }
        }
    }
}
Also used : ScopeDefinition(com.avaloq.tools.ddk.xtext.scope.scope.ScopeDefinition) GlobalScopeExpression(com.avaloq.tools.ddk.xtext.scope.scope.GlobalScopeExpression) Expression(com.avaloq.tools.ddk.xtext.expression.expression.Expression) SimpleScopeExpression(com.avaloq.tools.ddk.xtext.scope.scope.SimpleScopeExpression) ScopeRule(com.avaloq.tools.ddk.xtext.scope.scope.ScopeRule) Check(org.eclipse.xtext.validation.Check)

Example 2 with ScopeRule

use of com.avaloq.tools.ddk.xtext.scope.scope.ScopeRule 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 3 with ScopeRule

use of com.avaloq.tools.ddk.xtext.scope.scope.ScopeRule 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)

Aggregations

ScopeDefinition (com.avaloq.tools.ddk.xtext.scope.scope.ScopeDefinition)3 ScopeRule (com.avaloq.tools.ddk.xtext.scope.scope.ScopeRule)3 Check (org.eclipse.xtext.validation.Check)3 Expression (com.avaloq.tools.ddk.xtext.expression.expression.Expression)1 GlobalScopeExpression (com.avaloq.tools.ddk.xtext.scope.scope.GlobalScopeExpression)1 ScopeContext (com.avaloq.tools.ddk.xtext.scope.scope.ScopeContext)1 SimpleScopeExpression (com.avaloq.tools.ddk.xtext.scope.scope.SimpleScopeExpression)1