Search in sources :

Example 1 with ValidModel

use of com.avaloq.tools.ddk.xtext.valid.valid.ValidModel in project dsl-devkit by dsldevkit.

the class ValidScopingTest method testEStructuralFeatureScope.

/**
 * Tests that validations may be declared on existing EClass and EStructuralFeature instances.
 */
@Test
public void testEStructuralFeatureScope() throws IOException {
    final ValidModel validModel = (ValidModel) getTestSource().getModel();
    final NativeContext context = getXtextTestUtil().getFirstInstanceOf(validModel, NativeContext.class);
    // Check context feature reference
    IScope scope = scopeProvider.getScope(context, ValidPackage.Literals.CONTEXT__CONTEXT_FEATURE);
    IEObjectDescription name = scope.getSingleElement(QualifiedName.create("name"));
    assertNotNull("Found valid EStructuralFeature \"name\"", name);
    final EObject resolvedName = name.getEObjectOrProxy();
    assertNotNull("Valid EStructuralFeature \"name\" can be resolved", resolvedName);
    // Check context type reference
    scope = scopeProvider.getScope(context, ValidPackage.Literals.CONTEXT__CONTEXT_TYPE);
    assertEquals("Scope provider returns correct context type", context.getContextType(), scope.getSingleElement(QualifiedName.create("Model")).getEObjectOrProxy());
    assertEquals("Container of \"name\" reference instance is \"Model\" instance", resolvedName.eContainer(), scope.getSingleElement(QualifiedName.create("Model")).getEObjectOrProxy());
    // Check marker type reference
    scope = scopeProvider.getScope(context, ValidPackage.Literals.NATIVE_CONTEXT__MARKER_TYPE);
    assertEquals("Scope provider returns correct marker type", context.getMarkerType(), scope.getSingleElement(QualifiedName.create("Element")).getEObjectOrProxy());
    // Check marker feature reference
    scope = scopeProvider.getScope(context, ValidPackage.Literals.NATIVE_CONTEXT__MARKER_FEATURE);
    assertEquals("Scope provider returns correct marker feature", context.getMarkerFeature(), scope.getSingleElement(QualifiedName.create("name")).getEObjectOrProxy());
}
Also used : ValidModel(com.avaloq.tools.ddk.xtext.valid.valid.ValidModel) NativeContext(com.avaloq.tools.ddk.xtext.valid.valid.NativeContext) EObject(org.eclipse.emf.ecore.EObject) IScope(org.eclipse.xtext.scoping.IScope) IEObjectDescription(org.eclipse.xtext.resource.IEObjectDescription) AbstractScopingTest(com.avaloq.tools.ddk.xtext.test.scoping.AbstractScopingTest) Test(org.junit.Test)

Example 2 with ValidModel

use of com.avaloq.tools.ddk.xtext.valid.valid.ValidModel in project dsl-devkit by dsldevkit.

the class ValidScopingTest method testEPackageScope.

/**
 * Tests that EPackage instances can be imported by means of their NS URI. If an NS URI to a non-existing EPackage is provided,
 * the scope provider will return <code>null</code> for such an import, i.e. will not locate it.
 */
@Test
public void testEPackageScope() throws IOException {
    final ValidModel model = (ValidModel) getTestSource().getModel();
    IScope scope = scopeProvider.getScope(model, ValidPackage.Literals.IMPORT__PACKAGE);
    final EPackage validScopingTestPackage = model.getImports().get(0).getPackage();
    assertEquals("NS URI of first import is valid", ValidscopingtestPackage.eNS_URI, validScopingTestPackage.getNsURI());
    final EPackage nonExistingPackage = model.getImports().get(1).getPackage();
    assertNull("Non-existing EPackage has no NS URI", nonExistingPackage.getNsURI());
    assertNotNull("Import of existing EPackage is valid", scope.getSingleElement(QualifiedName.create(ValidscopingtestPackage.eNS_URI)));
    assertNull("Non-existing EPackage cannot be imported", scope.getSingleElement(QualifiedName.create("http://www.avaloq.com/tools/ddk/acf/nonexistingnsuri")));
}
Also used : ValidModel(com.avaloq.tools.ddk.xtext.valid.valid.ValidModel) IScope(org.eclipse.xtext.scoping.IScope) EPackage(org.eclipse.emf.ecore.EPackage) AbstractScopingTest(com.avaloq.tools.ddk.xtext.test.scoping.AbstractScopingTest) Test(org.junit.Test)

Example 3 with ValidModel

use of com.avaloq.tools.ddk.xtext.valid.valid.ValidModel in project dsl-devkit by dsldevkit.

the class ValidValidatorFragment method generate.

/**
 * {@inheritDoc}
 */
@Override
public void generate(final Grammar grammar, final XpandExecutionContext ctx) {
    if (LOGGER.isInfoEnabled()) {
        LOGGER.info(NLS.bind(Messages.EXECUTING_GENERATE, getClass().getName()));
    }
    ValidStandaloneSetup.doSetup();
    final ValidModel validModel = getValidModel(grammar);
    grammar.eResource().getResourceSet().getResources().add(validModel.eResource());
    grammar.eResource().getResourceSet().getResources().add(validModel.getImports().get(0).eResource());
    // profile for generator is:
    // <<DEFINE generate(List[String] packageQNames, List[String] composedChecks, ValidModel validModel) FOR Grammar>>
    // template //$NON-NLS-1$
    XpandFacade.create(ctx).evaluate(// template //$NON-NLS-1$
    getTemplate() + "::generate", // this (the grammar)
    grammar, // package Qualified Names (first parameter of the argument list is the 'list of
    getParameters(grammar).get(0), // composed checks
    this.composedChecks, // validModel
    validModel);
    if (generateTests) {
        // template //$NON-NLS-1$
        XpandFacade.create(ctx).evaluate(// template //$NON-NLS-1$
        "com::avaloq::tools::ddk::xtext::valid::generator::ValidatorTests::generate", // this (the grammar)
        grammar, // validModel
        validModel);
        // template //$NON-NLS-1$
        XpandFacade.create(ctx).evaluate(// template //$NON-NLS-1$
        "com::avaloq::tools::ddk::xtext::valid::generator::QuickfixTests::generate", // this (the grammar)
        grammar, // validModel
        validModel);
    }
}
Also used : ValidModel(com.avaloq.tools.ddk.xtext.valid.valid.ValidModel)

Aggregations

ValidModel (com.avaloq.tools.ddk.xtext.valid.valid.ValidModel)3 AbstractScopingTest (com.avaloq.tools.ddk.xtext.test.scoping.AbstractScopingTest)2 IScope (org.eclipse.xtext.scoping.IScope)2 Test (org.junit.Test)2 NativeContext (com.avaloq.tools.ddk.xtext.valid.valid.NativeContext)1 EObject (org.eclipse.emf.ecore.EObject)1 EPackage (org.eclipse.emf.ecore.EPackage)1 IEObjectDescription (org.eclipse.xtext.resource.IEObjectDescription)1