summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSven Efftinge2011-08-04 04:05:55 (EDT)
committer Ed Merks2011-08-04 04:05:55 (EDT)
commit03b63e3485f2874340ad6548e45bf992ab1e7a1e (patch)
tree7e3040d254023d477a3603559873828bba2e1c01
parenta6ff262e668c27388fca8812328f78acf5d526f8 (diff)
downloadorg.eclipse.emf-03b63e3485f2874340ad6548e45bf992ab1e7a1e.zip
org.eclipse.emf-03b63e3485f2874340ad6548e45bf992ab1e7a1e.tar.gz
org.eclipse.emf-03b63e3485f2874340ad6548e45bf992ab1e7a1e.tar.bz2
some more parsing tests
-rwxr-xr-xorg.eclipse.emf.ecore.xcore.tests/.project6
-rw-r--r--org.eclipse.emf.ecore.xcore.tests/META-INF/MANIFEST.MF3
-rw-r--r--org.eclipse.emf.ecore.xcore.tests/src/org/eclipse/emf/ecore/xcore/tests/ParserTest.java30
-rw-r--r--org.eclipse.emf.ecore.xcore.tests/src/org/eclipse/emf/ecore/xcore/tests/ParsingTest.xtend66
-rw-r--r--org.eclipse.emf.ecore.xcore.tests/xtend-gen/org/eclipse/emf/ecore/xcore/tests/ParsingTest.java115
-rw-r--r--org.eclipse.emf.ecore.xcore/src/org/eclipse/emf/ecore/xcore/XcoreExtensions.xtend20
-rw-r--r--org.eclipse.emf.ecore.xcore/xtend-gen/org/eclipse/emf/ecore/xcore/XcoreExtensions.java46
7 files changed, 255 insertions, 31 deletions
diff --git a/org.eclipse.emf.ecore.xcore.tests/.project b/org.eclipse.emf.ecore.xcore.tests/.project
index 51b603e..401d0f9 100755
--- a/org.eclipse.emf.ecore.xcore.tests/.project
+++ b/org.eclipse.emf.ecore.xcore.tests/.project
@@ -20,9 +20,15 @@
<arguments>
</arguments>
</buildCommand>
+ <buildCommand>
+ <name>org.eclipse.xtext.ui.shared.xtextBuilder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.pde.PluginNature</nature>
<nature>org.eclipse.jdt.core.javanature</nature>
+ <nature>org.eclipse.xtext.ui.shared.xtextNature</nature>
</natures>
</projectDescription>
diff --git a/org.eclipse.emf.ecore.xcore.tests/META-INF/MANIFEST.MF b/org.eclipse.emf.ecore.xcore.tests/META-INF/MANIFEST.MF
index 47d2342..f2fead2 100644
--- a/org.eclipse.emf.ecore.xcore.tests/META-INF/MANIFEST.MF
+++ b/org.eclipse.emf.ecore.xcore.tests/META-INF/MANIFEST.MF
@@ -12,5 +12,6 @@ Require-Bundle: org.eclipse.emf.ecore.xcore,
org.eclipse.xtext.junit4;bundle-version="2.0.0",
org.eclipse.emf.codegen.ecore;bundle-version="2.7.0",
org.eclipse.xtext.common.types;bundle-version="2.0.0",
- org.eclipse.xtext.xbase;bundle-version="2.0.0"
+ org.eclipse.xtext.xbase;bundle-version="2.0.0",
+ org.eclipse.xtext.xtend2.lib;bundle-version="2.0.1"
Import-Package: org.eclipse.xtext.junit
diff --git a/org.eclipse.emf.ecore.xcore.tests/src/org/eclipse/emf/ecore/xcore/tests/ParserTest.java b/org.eclipse.emf.ecore.xcore.tests/src/org/eclipse/emf/ecore/xcore/tests/ParserTest.java
deleted file mode 100644
index 629f9c1..0000000
--- a/org.eclipse.emf.ecore.xcore.tests/src/org/eclipse/emf/ecore/xcore/tests/ParserTest.java
+++ /dev/null
@@ -1,30 +0,0 @@
-package org.eclipse.emf.ecore.xcore.tests;
-
-import org.eclipse.emf.ecore.xcore.XPackage;
-import org.eclipse.emf.ecore.xcore.XcoreInjectorProvider;
-import org.eclipse.xtext.junit4.InjectWith;
-import org.eclipse.xtext.junit4.XtextRunner;
-import org.eclipse.xtext.junit4.util.ParseHelper;
-import org.junit.Test;
-import org.junit.runner.RunWith;
-
-import com.google.inject.Inject;
-
-import static org.junit.Assert.*;
-
-@RunWith(XtextRunner.class)
-@InjectWith(XcoreInjectorProvider.class)
-public class ParserTest
-{
-
- @Inject
- private ParseHelper<XPackage> parser;
-
- @Test
- public void parseSimpleFile() throws Exception
- {
- XPackage parse = parser.parse("package foo");
- assertEquals("foo", parse.getName());
- }
-
-}
diff --git a/org.eclipse.emf.ecore.xcore.tests/src/org/eclipse/emf/ecore/xcore/tests/ParsingTest.xtend b/org.eclipse.emf.ecore.xcore.tests/src/org/eclipse/emf/ecore/xcore/tests/ParsingTest.xtend
new file mode 100644
index 0000000..96c6e74
--- /dev/null
+++ b/org.eclipse.emf.ecore.xcore.tests/src/org/eclipse/emf/ecore/xcore/tests/ParsingTest.xtend
@@ -0,0 +1,66 @@
+package org.eclipse.emf.ecore.xcore.tests
+
+import org.junit.runner.RunWith
+import org.eclipse.xtext.junit4.InjectWith
+import com.google.inject.Inject
+import org.eclipse.xtext.junit4.util.ParseHelper
+import org.eclipse.emf.ecore.xcore.XPackage
+import org.junit.Test
+import static org.junit.Assert.*
+import org.eclipse.xtext.junit4.XtextRunner
+import org.eclipse.emf.ecore.xcore.XcoreInjectorProvider
+import org.eclipse.emf.ecore.xcore.XClass
+import org.eclipse.emf.ecore.xcore.XcoreExtensions
+
+@RunWith(typeof(XtextRunner))
+@InjectWith(typeof(XcoreInjectorProvider))
+class ParsingTest {
+
+ @Inject
+ ParseHelper<XPackage> parser
+
+ @Inject
+ extension XcoreExtensions exts
+
+
+ @Test
+ def void parseSimpleFile() {
+ val parse = parser.parse("package foo");
+ assertEquals("foo", parse.getName());
+ }
+
+ @Test
+ def void testSuperTypeLinking_1() {
+ val pack = parser.parse('''
+ package foo
+ class A {}
+ class B extends A {}
+ ''')
+ val clazz = pack.classifiers.get(1) as XClass
+ assertEquals("A", clazz.superTypes.head.genClass.name)
+ }
+
+ @Test
+ def void testSuperTypeLinking_2() {
+ val pack = parser.parse('''
+ package foo
+ class A {}
+ class B extends foo.A {}
+ ''')
+ val clazz = pack.classifiers.get(1) as XClass
+ assertEquals("A", clazz.superTypes.head.genClass.name)
+ }
+
+ @Test
+ def void testReferenceToAnnotation() {
+ val pack = parser.parse('''
+ package foo
+ annotation 'foo/bar' as foo
+ @foo(holla='bar')
+ class A {}
+ ''')
+ val clazz = pack.classifiers.get(0) as XClass
+ assertEquals(pack.annotationDirectives.head, clazz.annotations.head.source)
+ }
+
+} \ No newline at end of file
diff --git a/org.eclipse.emf.ecore.xcore.tests/xtend-gen/org/eclipse/emf/ecore/xcore/tests/ParsingTest.java b/org.eclipse.emf.ecore.xcore.tests/xtend-gen/org/eclipse/emf/ecore/xcore/tests/ParsingTest.java
new file mode 100644
index 0000000..f7cbcae
--- /dev/null
+++ b/org.eclipse.emf.ecore.xcore.tests/xtend-gen/org/eclipse/emf/ecore/xcore/tests/ParsingTest.java
@@ -0,0 +1,115 @@
+package org.eclipse.emf.ecore.xcore.tests;
+
+import com.google.inject.Inject;
+import org.eclipse.emf.codegen.ecore.genmodel.GenClass;
+import org.eclipse.emf.common.util.EList;
+import org.eclipse.emf.ecore.xcore.XAnnotation;
+import org.eclipse.emf.ecore.xcore.XAnnotationDirective;
+import org.eclipse.emf.ecore.xcore.XClass;
+import org.eclipse.emf.ecore.xcore.XClassifier;
+import org.eclipse.emf.ecore.xcore.XGenericType;
+import org.eclipse.emf.ecore.xcore.XPackage;
+import org.eclipse.emf.ecore.xcore.XcoreExtensions;
+import org.eclipse.emf.ecore.xcore.XcoreInjectorProvider;
+import org.eclipse.xtext.junit4.InjectWith;
+import org.eclipse.xtext.junit4.XtextRunner;
+import org.eclipse.xtext.junit4.util.ParseHelper;
+import org.eclipse.xtext.xbase.lib.IterableExtensions;
+import org.eclipse.xtext.xtend2.lib.StringConcatenation;
+import org.junit.Assert;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+
+@SuppressWarnings("all")
+@RunWith(XtextRunner.class)
+@InjectWith(XcoreInjectorProvider.class)
+public class ParsingTest {
+
+ @Inject
+ private ParseHelper<XPackage> parser;
+
+ @Inject
+ private XcoreExtensions exts;
+
+ @Test
+ public void parseSimpleFile() throws Exception {
+ {
+ XPackage _parse = this.parser.parse("package foo");
+ final XPackage parse = _parse;
+ String _name = parse.getName();
+ Assert.assertEquals("foo", _name);
+ }
+ }
+
+ @Test
+ public void testSuperTypeLinking_1() throws Exception {
+ {
+ StringConcatenation _builder = new StringConcatenation();
+ _builder.append("package foo ");
+ _builder.newLine();
+ _builder.append("class A {} ");
+ _builder.newLine();
+ _builder.append("class B extends A {}");
+ _builder.newLine();
+ XPackage _parse = this.parser.parse(_builder);
+ final XPackage pack = _parse;
+ EList<XClassifier> _classifiers = pack.getClassifiers();
+ XClassifier _get = _classifiers.get(1);
+ final XClass clazz = ((XClass) _get);
+ EList<XGenericType> _superTypes = clazz.getSuperTypes();
+ XGenericType _head = IterableExtensions.<XGenericType>head(_superTypes);
+ GenClass _genClass = this.exts.getGenClass(_head);
+ String _name = _genClass.getName();
+ Assert.assertEquals("A", _name);
+ }
+ }
+
+ @Test
+ public void testSuperTypeLinking_2() throws Exception {
+ {
+ StringConcatenation _builder = new StringConcatenation();
+ _builder.append("package foo ");
+ _builder.newLine();
+ _builder.append("class A {} ");
+ _builder.newLine();
+ _builder.append("class B extends foo.A {}");
+ _builder.newLine();
+ XPackage _parse = this.parser.parse(_builder);
+ final XPackage pack = _parse;
+ EList<XClassifier> _classifiers = pack.getClassifiers();
+ XClassifier _get = _classifiers.get(1);
+ final XClass clazz = ((XClass) _get);
+ EList<XGenericType> _superTypes = clazz.getSuperTypes();
+ XGenericType _head = IterableExtensions.<XGenericType>head(_superTypes);
+ GenClass _genClass = this.exts.getGenClass(_head);
+ String _name = _genClass.getName();
+ Assert.assertEquals("A", _name);
+ }
+ }
+
+ @Test
+ public void testReferenceToAnnotation() throws Exception {
+ {
+ StringConcatenation _builder = new StringConcatenation();
+ _builder.append("package foo ");
+ _builder.newLine();
+ _builder.append("annotation \'foo/bar\' as foo");
+ _builder.newLine();
+ _builder.append("@foo(holla=\'bar\')");
+ _builder.newLine();
+ _builder.append("class A {} ");
+ _builder.newLine();
+ XPackage _parse = this.parser.parse(_builder);
+ final XPackage pack = _parse;
+ EList<XClassifier> _classifiers = pack.getClassifiers();
+ XClassifier _get = _classifiers.get(0);
+ final XClass clazz = ((XClass) _get);
+ EList<XAnnotationDirective> _annotationDirectives = pack.getAnnotationDirectives();
+ XAnnotationDirective _head = IterableExtensions.<XAnnotationDirective>head(_annotationDirectives);
+ EList<XAnnotation> _annotations = clazz.getAnnotations();
+ XAnnotation _head_1 = IterableExtensions.<XAnnotation>head(_annotations);
+ XAnnotationDirective _source = _head_1.getSource();
+ Assert.assertEquals(_head, _source);
+ }
+ }
+} \ No newline at end of file
diff --git a/org.eclipse.emf.ecore.xcore/src/org/eclipse/emf/ecore/xcore/XcoreExtensions.xtend b/org.eclipse.emf.ecore.xcore/src/org/eclipse/emf/ecore/xcore/XcoreExtensions.xtend
new file mode 100644
index 0000000..f2dcc69
--- /dev/null
+++ b/org.eclipse.emf.ecore.xcore/src/org/eclipse/emf/ecore/xcore/XcoreExtensions.xtend
@@ -0,0 +1,20 @@
+package org.eclipse.emf.ecore.xcore
+
+import org.eclipse.emf.codegen.ecore.genmodel.GenClass
+import org.eclipse.emf.codegen.ecore.genmodel.GenTypeParameter
+
+class XcoreExtensions {
+ def getGenClass(XGenericType type) {
+ switch t : type.type {
+ GenClass : t
+ default : null
+ }
+ }
+
+ def getGenTypeParameter(XGenericType type) {
+ switch t : type.type {
+ GenTypeParameter : t
+ default : null
+ }
+ }
+} \ No newline at end of file
diff --git a/org.eclipse.emf.ecore.xcore/xtend-gen/org/eclipse/emf/ecore/xcore/XcoreExtensions.java b/org.eclipse.emf.ecore.xcore/xtend-gen/org/eclipse/emf/ecore/xcore/XcoreExtensions.java
new file mode 100644
index 0000000..560664b
--- /dev/null
+++ b/org.eclipse.emf.ecore.xcore/xtend-gen/org/eclipse/emf/ecore/xcore/XcoreExtensions.java
@@ -0,0 +1,46 @@
+package org.eclipse.emf.ecore.xcore;
+
+import org.eclipse.emf.codegen.ecore.genmodel.GenBase;
+import org.eclipse.emf.codegen.ecore.genmodel.GenClass;
+import org.eclipse.emf.codegen.ecore.genmodel.GenTypeParameter;
+import org.eclipse.emf.ecore.xcore.XGenericType;
+
+@SuppressWarnings("all")
+public class XcoreExtensions {
+
+ public GenClass getGenClass(final XGenericType type) {
+ GenClass _switchResult = null;
+ GenBase _type = type.getType();
+ final GenBase t = _type;
+ boolean matched = false;
+ if (!matched) {
+ if (t instanceof GenClass) {
+ final GenClass t_1 = (GenClass) t;
+ matched=true;
+ _switchResult = t_1;
+ }
+ }
+ if (!matched) {
+ _switchResult = null;
+ }
+ return _switchResult;
+ }
+
+ public GenTypeParameter getGenTypeParameter(final XGenericType type) {
+ GenTypeParameter _switchResult = null;
+ GenBase _type = type.getType();
+ final GenBase t = _type;
+ boolean matched = false;
+ if (!matched) {
+ if (t instanceof GenTypeParameter) {
+ final GenTypeParameter t_1 = (GenTypeParameter) t;
+ matched=true;
+ _switchResult = t_1;
+ }
+ }
+ if (!matched) {
+ _switchResult = null;
+ }
+ return _switchResult;
+ }
+} \ No newline at end of file