Search in sources :

Example 1 with ScopeDefinition

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

the class ScopeJavaValidator method checkScopeDefinitionUniqueness.

/**
 * Checks that all scope definitions are unique. If not a warning is issued.
 *
 * @param context
 *          scoping section to check
 */
@Check
public void checkScopeDefinitionUniqueness(final ScopeModel context) {
    // NOPMD
    final Map<String, ScopeDefinition> profileMap = Maps.newHashMap();
    for (ScopeDefinition def : context.getScopes()) {
        String profile = null;
        if (isDefaultScope(def)) {
            profile = def.getTargetType() != null ? def.getTargetType().toString() : def.getReference().toString();
        } else {
            profile = def.getName();
        }
        final ScopeDefinition other = profileMap.get(profile);
        if (other != null) {
            EStructuralFeature feature = isDefaultScope(def) ? (def.getTargetType() != null ? ScopePackage.Literals.SCOPE_DEFINITION__TARGET_TYPE : ScopePackage.Literals.SCOPE_DEFINITION__REFERENCE) : ScopePackage.Literals.SCOPE_DEFINITION__NAME;
            errorOnDuplicate(def, other, Messages.duplicatedScopeDefinition, feature);
        } else {
            profileMap.put(profile, def);
        }
        if (!isDefaultScope(def)) {
            ScopeDefinition base = getOverriddenScope(context, def);
            if (base != null && (def.getTargetType() != base.getTargetType() || def.getReference() != base.getReference())) {
                errorOnDuplicate(def, base, Messages.wrongScopeDefinitionSignature, ScopePackage.Literals.SCOPE_DEFINITION__NAME);
            }
        }
    }
}
Also used : ScopeDefinition(com.avaloq.tools.ddk.xtext.scope.scope.ScopeDefinition) EStructuralFeature(org.eclipse.emf.ecore.EStructuralFeature) Check(org.eclipse.xtext.validation.Check)

Example 2 with ScopeDefinition

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

the class ScopeJavaValidator method getAllInheritedScopeDefinitions.

/**
 * Returns a set comprising all inherited scope definitions (excluding local scope definitions).
 *
 * @param context
 *          scope model to retrieve inherited scope definitions for
 * @return all inherited (recursively) scope definitions
 */
private Set<ScopeDefinition> getAllInheritedScopeDefinitions(final ScopeModel context) {
    final Set<ScopeDefinition> defs = Sets.newLinkedHashSet();
    for (ScopeModel include : context.getIncludedScopes()) {
        defs.addAll(include.getScopes());
        defs.addAll(getAllInheritedScopeDefinitions(include));
    }
    return defs;
}
Also used : ScopeDefinition(com.avaloq.tools.ddk.xtext.scope.scope.ScopeDefinition) ScopeModel(com.avaloq.tools.ddk.xtext.scope.scope.ScopeModel)

Example 3 with ScopeDefinition

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

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

the class ScopeUtil method getSignature.

/**
 * Computes a signature string representation which must be unique for the given rule.
 *
 * @param rule
 *          rule to calculate signature for
 * @return string signature
 */
public static String getSignature(final ScopeRule rule) {
    // NOPMD NPathComplexity
    StringBuffer result = new StringBuffer();
    final ScopeDefinition def = EObjectUtil.eContainer(rule, ScopeDefinition.class);
    result.append(def.getName()).append('_');
    final EClass type = def.getReference() != null ? def.getReference().getEReferenceType() : def.getTargetType();
    final EReference ref = def.getReference();
    if (ref != null) {
        result.append(ref.getEContainingClass().getEPackage().getName()).append('_').append(ref.getEContainingClass().getName()).append('_').append(ref.getName()).append("_EReference");
    } else {
        result.append(type.getEPackage().getName()).append('_').append(type.getName()).append("_EClass");
    }
    result.append('_');
    if (rule.getContext().isGlobal()) {
        result.append("org.eclipse.emf.ecore.resource.Resource");
    } else {
        result.append(rule.getContext().getContextType().getEPackage().getName()).append('_').append(rule.getContext().getContextType().getName());
    }
    return result.toString();
}
Also used : ScopeDefinition(com.avaloq.tools.ddk.xtext.scope.scope.ScopeDefinition) EClass(org.eclipse.emf.ecore.EClass) EReference(org.eclipse.emf.ecore.EReference)

Example 5 with ScopeDefinition

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

the class ScopeDelegationImpl method setScope.

/**
 * <!-- begin-user-doc -->
 * <!-- end-user-doc -->
 * @generated
 */
public void setScope(ScopeDefinition newScope) {
    ScopeDefinition oldScope = scope;
    scope = newScope;
    if (eNotificationRequired())
        eNotify(new ENotificationImpl(this, Notification.SET, ScopePackage.SCOPE_DELEGATION__SCOPE, oldScope, scope));
}
Also used : ScopeDefinition(com.avaloq.tools.ddk.xtext.scope.scope.ScopeDefinition) ENotificationImpl(org.eclipse.emf.ecore.impl.ENotificationImpl)

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