Search in sources :

Example 1 with NamingDefinition

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

NamingDefinition (com.avaloq.tools.ddk.xtext.scope.scope.NamingDefinition)1 NamingSection (com.avaloq.tools.ddk.xtext.scope.scope.NamingSection)1 ScopeDefinition (com.avaloq.tools.ddk.xtext.scope.scope.ScopeDefinition)1 ScopeModel (com.avaloq.tools.ddk.xtext.scope.scope.ScopeModel)1 EClass (org.eclipse.emf.ecore.EClass)1 Check (org.eclipse.xtext.validation.Check)1