Search in sources :

Example 1 with FormatConfiguration

use of com.avaloq.tools.ddk.xtext.format.format.FormatConfiguration in project dsl-devkit by dsldevkit.

the class FormatConfigurationImpl method setExtendedFormatConfiguration.

/**
 * <!-- begin-user-doc -->
 * <!-- end-user-doc -->
 * @generated
 */
public void setExtendedFormatConfiguration(FormatConfiguration newExtendedFormatConfiguration) {
    FormatConfiguration oldExtendedFormatConfiguration = extendedFormatConfiguration;
    extendedFormatConfiguration = newExtendedFormatConfiguration;
    if (eNotificationRequired())
        eNotify(new ENotificationImpl(this, Notification.SET, FormatPackage.FORMAT_CONFIGURATION__EXTENDED_FORMAT_CONFIGURATION, oldExtendedFormatConfiguration, extendedFormatConfiguration));
}
Also used : FormatConfiguration(com.avaloq.tools.ddk.xtext.format.format.FormatConfiguration) ENotificationImpl(org.eclipse.emf.ecore.impl.ENotificationImpl)

Example 2 with FormatConfiguration

use of com.avaloq.tools.ddk.xtext.format.format.FormatConfiguration in project dsl-devkit by dsldevkit.

the class FormatValidationTest method extendedGrammarCompatible.

/**
 * Verify that ExtendedGrammarCompatible validation issues error when grammars of the Format models are incompatible.
 */
@Test
public void extendedGrammarCompatible() {
    try {
        getXtextTestUtil().getModel("MyDsl.xtext", "grammar com.avaloq.tools.ddk.xtext.format.validation.MyDsl\nimport \"http://www.eclipse.org/emf/2002/Ecore\" as ecore\nRule: 'rule';");
    } catch (IOException e) {
        fail("Could not create MyDsl model: " + e.getMessage());
    }
    FormatConfiguration myDslModel = createModel("MyDsl", PARENT_MODEL_NAME, new String[] {});
    assertDiagnostic(myDslModel, FormatJavaValidator.EXTENDED_GRAMMAR_INCOMPATIBLE_CODE);
}
Also used : FormatConfiguration(com.avaloq.tools.ddk.xtext.format.format.FormatConfiguration) IOException(java.io.IOException) AbstractValidationTest(com.avaloq.tools.ddk.xtext.test.validation.AbstractValidationTest) Test(org.junit.Test)

Example 3 with FormatConfiguration

use of com.avaloq.tools.ddk.xtext.format.format.FormatConfiguration in project dsl-devkit by dsldevkit.

the class FormatValidationTest method extendedGrammarCompatibleOK.

/**
 * Verify that ExtendedGrammarCompatible validation issues no error.
 */
@Test
public void extendedGrammarCompatibleOK() {
    createModel(PARENT_MODEL_NAME, null, new String[] {});
    FormatConfiguration extendModel = createModel(EXTENDING_MODEL_NAME, PARENT_MODEL_NAME, new String[] {});
    assertNoDiagnostic(extendModel, FormatJavaValidator.EXTENDED_GRAMMAR_INCOMPATIBLE_CODE);
}
Also used : FormatConfiguration(com.avaloq.tools.ddk.xtext.format.format.FormatConfiguration) AbstractValidationTest(com.avaloq.tools.ddk.xtext.test.validation.AbstractValidationTest) Test(org.junit.Test)

Example 4 with FormatConfiguration

use of com.avaloq.tools.ddk.xtext.format.format.FormatConfiguration in project dsl-devkit by dsldevkit.

the class FormatJavaValidator method checkOverrideMissing.

/**
 * Checks that rules declare overrides when there is a corresponding inherited rule.
 *
 * @param model
 *          the model
 */
@Check
public void checkOverrideMissing(final FormatConfiguration model) {
    FormatConfiguration extendedModel = model.getExtendedFormatConfiguration();
    if (extendedModel == null || extendedModel.eIsProxy()) {
        return;
    }
    Iterable<Rule> nonOverrideRules = Iterables.filter(model.getRules(), Predicates.not(IS_OVERRIDE));
    Iterable<Rule> overriddenRules = collectRules(extendedModel);
    Map<AbstractRule, GrammarRule> localAbstractRuleMap = Maps.newHashMap();
    for (GrammarRule rule : Iterables.filter(nonOverrideRules, GrammarRule.class)) {
        localAbstractRuleMap.put(TARGET_RULE.apply(rule), rule);
    }
    // Check GrammarRules
    for (GrammarRule overriddenRule : Iterables.filter(overriddenRules, GrammarRule.class)) {
        if (localAbstractRuleMap.containsKey(TARGET_RULE.apply(overriddenRule))) {
            GrammarRule localRule = localAbstractRuleMap.get(TARGET_RULE.apply(overriddenRule));
            error(OVERRIDE_MISSING_MESSAGE, localRule, FormatPackage.Literals.GRAMMAR_RULE__TARGET_RULE, OVERRIDE_MISSING_CODE);
        }
    }
    // Check WildcardRule
    if (!Iterables.isEmpty(Iterables.filter(nonOverrideRules, WildcardRule.class)) && !Iterables.isEmpty(Iterables.filter(overriddenRules, WildcardRule.class))) {
        error(OVERRIDE_MISSING_MESSAGE, Iterables.filter(nonOverrideRules, WildcardRule.class).iterator().next(), null, OVERRIDE_MISSING_CODE);
    }
}
Also used : FormatConfiguration(com.avaloq.tools.ddk.xtext.format.format.FormatConfiguration) WildcardRule(com.avaloq.tools.ddk.xtext.format.format.WildcardRule) GrammarRule(com.avaloq.tools.ddk.xtext.format.format.GrammarRule) Rule(com.avaloq.tools.ddk.xtext.format.format.Rule) EnumRule(org.eclipse.xtext.EnumRule) WildcardRule(com.avaloq.tools.ddk.xtext.format.format.WildcardRule) GrammarRule(com.avaloq.tools.ddk.xtext.format.format.GrammarRule) TerminalRule(org.eclipse.xtext.TerminalRule) ParserRule(org.eclipse.xtext.ParserRule) AbstractRule(org.eclipse.xtext.AbstractRule) AbstractRule(org.eclipse.xtext.AbstractRule) Check(org.eclipse.xtext.validation.Check)

Example 5 with FormatConfiguration

use of com.avaloq.tools.ddk.xtext.format.format.FormatConfiguration in project dsl-devkit by dsldevkit.

the class FormatJavaValidator method collectRules.

/**
 * Collect all rules contained by the given model (including any of its extended configurations).
 *
 * @param model
 *          the model
 * @return all rules
 */
private Iterable<Rule> collectRules(final FormatConfiguration model) {
    Iterable<Rule> result = model.getRules();
    FormatConfiguration extendedModel = model.getExtendedFormatConfiguration();
    if (extendedModel != null && !extendedModel.eIsProxy()) {
        result = Iterables.concat(result, collectRules(extendedModel));
    }
    return result;
}
Also used : FormatConfiguration(com.avaloq.tools.ddk.xtext.format.format.FormatConfiguration) Rule(com.avaloq.tools.ddk.xtext.format.format.Rule) EnumRule(org.eclipse.xtext.EnumRule) WildcardRule(com.avaloq.tools.ddk.xtext.format.format.WildcardRule) GrammarRule(com.avaloq.tools.ddk.xtext.format.format.GrammarRule) TerminalRule(org.eclipse.xtext.TerminalRule) ParserRule(org.eclipse.xtext.ParserRule) AbstractRule(org.eclipse.xtext.AbstractRule)

Aggregations

FormatConfiguration (com.avaloq.tools.ddk.xtext.format.format.FormatConfiguration)11 GrammarRule (com.avaloq.tools.ddk.xtext.format.format.GrammarRule)5 Rule (com.avaloq.tools.ddk.xtext.format.format.Rule)4 WildcardRule (com.avaloq.tools.ddk.xtext.format.format.WildcardRule)4 AbstractRule (org.eclipse.xtext.AbstractRule)4 Check (org.eclipse.xtext.validation.Check)4 EnumRule (org.eclipse.xtext.EnumRule)3 ParserRule (org.eclipse.xtext.ParserRule)3 TerminalRule (org.eclipse.xtext.TerminalRule)3 AbstractValidationTest (com.avaloq.tools.ddk.xtext.test.validation.AbstractValidationTest)2 Test (org.junit.Test)2 Constant (com.avaloq.tools.ddk.xtext.format.format.Constant)1 Function (com.google.common.base.Function)1 IOException (java.io.IOException)1 EObject (org.eclipse.emf.ecore.EObject)1 ENotificationImpl (org.eclipse.emf.ecore.impl.ENotificationImpl)1 Grammar (org.eclipse.xtext.Grammar)1