aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorszarnekow2009-03-05 13:49:47 (EST)
committersefftinge2009-03-05 13:49:47 (EST)
commitbbf2554d485a5172c3866f6e8183286d404ff910 (patch)
treed16737918769c6d855b0633e712682b18c726af4
parent6686f44aa671906f3354705f150a9dc0405a93b1 (diff)
downloadorg.eclipse.xtext-bbf2554d485a5172c3866f6e8183286d404ff910.zip
org.eclipse.xtext-bbf2554d485a5172c3866f6e8183286d404ff910.tar.gz
org.eclipse.xtext-bbf2554d485a5172c3866f6e8183286d404ff910.tar.bz2
Fix: ErrorMarker for importUris, that cannot be resolved (see https://bugs.eclipse.org/bugs/show_bug.cgi?id=266879)
Feature: Allow declarative composition of validators (see ImportUriValidator and its usages)
-rw-r--r--examples/org.eclipse.xtext.example.domainmodel/src/org/eclipse/xtext/example/DomainModelValidator.java29
-rw-r--r--examples/org.eclipse.xtext.example.domainmodel/src/org/eclipse/xtext/example/DomainmodelRuntimeModule.java3
-rw-r--r--tests/org.eclipse.xtext.generator.tests/src/org/eclipse/xtext/crossrefs/DefaultScopeProviderTest.java76
-rw-r--r--tests/org.eclipse.xtext.generator.tests/src/org/eclipse/xtext/validator/AbstractDeclarativeValidatorTest.java19
4 files changed, 80 insertions, 47 deletions
diff --git a/examples/org.eclipse.xtext.example.domainmodel/src/org/eclipse/xtext/example/DomainModelValidator.java b/examples/org.eclipse.xtext.example.domainmodel/src/org/eclipse/xtext/example/DomainModelValidator.java
new file mode 100644
index 0000000..7f0c49e
--- /dev/null
+++ b/examples/org.eclipse.xtext.example.domainmodel/src/org/eclipse/xtext/example/DomainModelValidator.java
@@ -0,0 +1,29 @@
+/*******************************************************************************
+ * Copyright (c) 2009 itemis AG (http://www.itemis.eu) and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *******************************************************************************/
+package org.eclipse.xtext.example;
+
+import org.eclipse.emf.ecore.EValidator;
+import org.eclipse.xtext.crossref.impl.ImportUriValidator;
+import org.eclipse.xtext.example.domainmodel.DomainmodelPackage;
+import org.eclipse.xtext.validator.AbstractDeclarativeValidator;
+import org.eclipse.xtext.validator.ComposedChecks;
+
+import com.google.inject.Inject;
+
+/**
+ * @author Sebastian Zarnekow - Initial contribution and API
+ */
+@ComposedChecks(validators= {ImportUriValidator.class})
+public class DomainModelValidator extends AbstractDeclarativeValidator {
+
+ @Inject
+ public DomainModelValidator(EValidator.Registry registry) {
+ registry.put(DomainmodelPackage.eINSTANCE, this);
+ }
+
+}
diff --git a/examples/org.eclipse.xtext.example.domainmodel/src/org/eclipse/xtext/example/DomainmodelRuntimeModule.java b/examples/org.eclipse.xtext.example.domainmodel/src/org/eclipse/xtext/example/DomainmodelRuntimeModule.java
index dd32ccb..9542031 100644
--- a/examples/org.eclipse.xtext.example.domainmodel/src/org/eclipse/xtext/example/DomainmodelRuntimeModule.java
+++ b/examples/org.eclipse.xtext.example.domainmodel/src/org/eclipse/xtext/example/DomainmodelRuntimeModule.java
@@ -13,6 +13,7 @@ public class DomainmodelRuntimeModule extends AbstractDomainmodelRuntimeModule {
@Override
public void configure(Binder binder) {
super.configure(binder);
+ binder.bind(DomainModelValidator.class).asEagerSingleton();
}
-
+
}
diff --git a/tests/org.eclipse.xtext.generator.tests/src/org/eclipse/xtext/crossrefs/DefaultScopeProviderTest.java b/tests/org.eclipse.xtext.generator.tests/src/org/eclipse/xtext/crossrefs/DefaultScopeProviderTest.java
index bcc35ba..be7a9d7 100644
--- a/tests/org.eclipse.xtext.generator.tests/src/org/eclipse/xtext/crossrefs/DefaultScopeProviderTest.java
+++ b/tests/org.eclipse.xtext.generator.tests/src/org/eclipse/xtext/crossrefs/DefaultScopeProviderTest.java
@@ -29,99 +29,99 @@ public class DefaultScopeProviderTest extends AbstractGeneratorTest {
super.setUp();
with(ImportUriTestLanguageStandaloneSetup.class);
}
-
+
public void testSimple() throws Exception {
TestURIConverter models = new TestURIConverter();
ResourceSetImpl rs = new ResourceSetImpl();
rs.setURIConverter(models);
-
+
models.addModel("foo.importuritestlanguage", "import 'bar.importuritestlanguage' type foo extends bar");
models.addModel("bar.importuritestlanguage", "type bar");
-
+
Resource resource = rs.getResource(URI.createURI("foo.importuritestlanguage"), true);
-
+
assertWithXtend("'bar'", "types.first().extends.name", resource.getContents().get(0));
}
-
+
// see https://bugs.eclipse.org/bugs/show_bug.cgi?id=266879
public void testRelativeScope() throws Exception {
TestURIConverter models = new TestURIConverter();
ResourceSetImpl rs = new ResourceSetImpl();
rs.setURIConverter(models);
-
+
models.addModel("testfile://my/folder/foo.importuritestlanguage", "import 'bar.importuritestlanguage' type foo extends bar type bar extends bar2");
models.addModel("testfile://my/folder/bar.importuritestlanguage", "type bar type bar2 extends bar");
-
+
Resource resource = rs.getResource(URI.createURI("testfile://my/folder/foo.importuritestlanguage"), true);
-
+
assertWithXtend("'bar'", "types.first().extends.name", resource.getContents().get(0));
assertWithXtend("'bar2'", "types.first().extends.extends.name", resource.getContents().get(0));
assertWithXtend("'bar'", "types.first().extends.extends.extends.name", resource.getContents().get(0));
assertWithXtend("null", "types.first().extends.extends.extends.extends", resource.getContents().get(0));
}
-
+
// see https://bugs.eclipse.org/bugs/show_bug.cgi?id=266879
public void testRelativeScopeWithPath() throws Exception {
TestURIConverter models = new TestURIConverter();
ResourceSetImpl rs = new ResourceSetImpl();
rs.setURIConverter(models);
models.addModel("testfile://my/folder/foo.importuritestlanguage", "import './../folder/bar.importuritestlanguage' type foo extends bar type bar extends bar2");
-
+
models.addModel("testfile://my/folder/bar.importuritestlanguage", "type bar type bar2 extends bar");
-
+
Resource resource = rs.getResource(URI.createURI("testfile://my/folder/foo.importuritestlanguage"), true);
-
+
assertWithXtend("'bar'", "types.first().extends.name", resource.getContents().get(0));
assertWithXtend("'bar2'", "types.first().extends.extends.name", resource.getContents().get(0));
assertWithXtend("'bar'", "types.first().extends.extends.extends.name", resource.getContents().get(0));
assertWithXtend("null", "types.first().extends.extends.extends.extends", resource.getContents().get(0));
}
-
+
public void testScopeFileName() throws Exception {
TestURIConverter models = new TestURIConverter();
ResourceSetImpl rs = new ResourceSetImpl();
rs.setURIConverter(models);
-
+
models.addModel("foo.importuritestlanguage", "import 'bar.importuritestlanguage' type foo extends bar type bar extends bar2");
models.addModel("bar.importuritestlanguage", "type bar type bar2 extends bar");
-
+
Resource resource = rs.getResource(URI.createURI("foo.importuritestlanguage"), true);
-
+
assertWithXtend("'bar'", "types.first().extends.name", resource.getContents().get(0));
assertWithXtend("'bar2'", "types.first().extends.extends.name", resource.getContents().get(0));
assertWithXtend("'bar'", "types.first().extends.extends.extends.name", resource.getContents().get(0));
assertWithXtend("null", "types.first().extends.extends.extends.extends", resource.getContents().get(0));
}
-
+
// TODO: report a meaningful error to the user when resolving of an import fails
-
- /*
+
public void testUnresolvableImport() throws Exception {
TestURIConverter models = new TestURIConverter();
ResourceSetImpl rs = new ResourceSetImpl();
rs.setURIConverter(models);
-
- models.addModel("testfile://my/folder/foo.importuritestlanguage", "import <unknownfile.importuritestlanguage> type foo extends bar type bar extends bar2");
-
+
+ models.addModel("testfile://my/folder/foo.importuritestlanguage",
+ "import 'unknownfile.importuritestlanguage' type foo extends bar type bar extends bar2");
+
Resource resource = rs.getResource(URI.createURI("testfile://my/folder/foo.importuritestlanguage"), true);
+ assertNotNull(resource);
}
- */
-
+
public void testCircularImport() throws Exception {
TestURIConverter models = new TestURIConverter();
ResourceSetImpl rs = new ResourceSetImpl();
rs.setURIConverter(models);
-
+
models.addModel("foo.importuritestlanguage", "import 'bar.importuritestlanguage' type foo extends bar");
models.addModel("bar.importuritestlanguage", "import 'foo.importuritestlanguage' type bar extends foo");
-
+
Resource resource = rs.getResource(URI.createURI("foo.importuritestlanguage"), true);
-
+
assertWithXtend("'bar'", "types.first().extends.name", resource.getContents().get(0));
assertWithXtend("'foo'", "types.first().extends.extends.name", resource.getContents().get(0));
assertWithXtend("true", "types.first().extends.extends == types.first()", resource.getContents().get(0));
}
-
+
/**
* https://bugs.eclipse.org/bugs/show_bug.cgi?id=261630
*/
@@ -129,35 +129,35 @@ public class DefaultScopeProviderTest extends AbstractGeneratorTest {
TestURIConverter models = new TestURIConverter();
ResourceSetImpl rs = new ResourceSetImpl();
rs.setURIConverter(models);
-
+
models.addModel("foo.importuritestlanguage", "import 'bar.importuritestlanguage' import 'bar.importuritestlanguage' import 'bar.importuritestlanguage' type foo extends bar type bar extends bar2");
models.addModel("bar.importuritestlanguage", "type bar type bar2 extends bar");
-
+
Resource resource = rs.getResource(URI.createURI("foo.importuritestlanguage"), true);
-
+
assertWithXtend("'bar'", "types.first().extends.name", resource.getContents().get(0));
assertWithXtend("'bar2'", "types.first().extends.extends.name", resource.getContents().get(0));
assertWithXtend("'bar'", "types.first().extends.extends.extends.name", resource.getContents().get(0));
assertWithXtend("null", "types.first().extends.extends.extends.extends", resource.getContents().get(0));
}
-
-
+
+
class TestURIConverter extends ExtensibleURIConverterImpl {
- private Map<URI, InputStream> models = new HashMap<URI, InputStream>();
-
+ private final Map<URI, InputStream> models = new HashMap<URI, InputStream>();
+
public void addModel(String uri, String content) {
models.put(URI.createURI(uri), new StringInputStream(content));
}
-
+
@Override
public boolean exists(URI uri, Map<?, ?> options) {
return models.containsKey(uri);
}
-
+
@Override
public InputStream createInputStream(URI uri, Map<?, ?> options) throws IOException {
return models.get(uri);
}
}
-
+
}
diff --git a/tests/org.eclipse.xtext.generator.tests/src/org/eclipse/xtext/validator/AbstractDeclarativeValidatorTest.java b/tests/org.eclipse.xtext.generator.tests/src/org/eclipse/xtext/validator/AbstractDeclarativeValidatorTest.java
index 6e828cb..893f493 100644
--- a/tests/org.eclipse.xtext.generator.tests/src/org/eclipse/xtext/validator/AbstractDeclarativeValidatorTest.java
+++ b/tests/org.eclipse.xtext.generator.tests/src/org/eclipse/xtext/validator/AbstractDeclarativeValidatorTest.java
@@ -27,7 +27,6 @@ import org.eclipse.emf.ecore.EcorePackage;
public class AbstractDeclarativeValidatorTest extends TestCase {
public void testSimpleDispatch() throws Exception {
-
AbstractDeclarativeValidator test = new TestValidator();
TestChain chain = chain();
test.validate(EcorePackage.eINSTANCE.getEClass(), chain, null);
@@ -99,13 +98,8 @@ public class AbstractDeclarativeValidatorTest extends TestCase {
assertEquals(0,diagnostics.integers.size());
}
- @SuppressWarnings("unused")
- private class TestValidator extends AbstractDeclarativeValidator {
- @Check
- private void foo(EClass x) {
- error("fooString",1);
- }
-
+ @ComposedChecks(validators= {ExternalValidator.class})
+ private static class TestValidator extends AbstractDeclarativeValidator {
@Check
protected void foo(EStructuralFeature x) {
error("fooInteger",2);
@@ -117,6 +111,15 @@ public class AbstractDeclarativeValidatorTest extends TestCase {
}
}
+ @ComposedChecks(validators= {TestValidator.class})
+ private static class ExternalValidator extends AbstractDeclarativeValidator {
+ @SuppressWarnings("unused")
+ @Check
+ private void foo(EClass x) {
+ error("fooString",1);
+ }
+ }
+
private final class TestChain implements DiagnosticChain {
public List<Integer> integers = new ArrayList<Integer>();