mirror of
https://github.com/sigmasternchen/xtext-core
synced 2025-03-16 00:38:56 +00:00
cross references first draft
This commit is contained in:
parent
3a424da17e
commit
0ecf2f16a3
6 changed files with 92 additions and 4 deletions
|
@ -12,6 +12,7 @@ import org.apache.log4j.Logger;
|
|||
import org.eclipse.emf.common.util.URI;
|
||||
import org.eclipse.emf.ecore.resource.Resource;
|
||||
import org.eclipse.emf.ecore.resource.impl.ResourceSetImpl;
|
||||
import org.eclipse.xtext.crossrefs.LangA;
|
||||
import org.eclipse.xtext.dummy.DummyLanguage;
|
||||
import org.eclipse.xtext.grammarinheritance.AbstractTestLanguage;
|
||||
import org.eclipse.xtext.grammarinheritance.ConcreteTestLanguage;
|
||||
|
@ -36,12 +37,11 @@ public class GenerateAllTestGrammars {
|
|||
|
||||
private static Logger log = Logger.getLogger(GenerateAllTestGrammars.class);
|
||||
|
||||
public final static Class<?>[] testclasses = new Class[] { AbstractTestLanguage.class,ConcreteTestLanguage.class,XtextGrammarTest.class, MetamodelRefTest.class,
|
||||
public final static Class<?>[] testclasses = new Class[] { LangA.class, AbstractTestLanguage.class,ConcreteTestLanguage.class,XtextGrammarTest.class, MetamodelRefTest.class,
|
||||
DummyLanguage.class, TestLanguage.class, SimpleReconstrTest.class, ComplexReconstrTest.class,
|
||||
LexerLanguage.class, SimpleExpressions.class, ActionTestLanguage.class, OptionalEmptyLanguage.class,
|
||||
ReferenceGrammar.class, LookaheadLanguage.class
|
||||
};// MultiGenMMTest.
|
||||
// class
|
||||
ReferenceGrammar.class, LookaheadLanguage.class
|
||||
};
|
||||
|
||||
public static void main(String[] args) throws Exception {
|
||||
XtextStandaloneSetup.doSetup();
|
||||
|
|
|
@ -0,0 +1,19 @@
|
|||
package org.eclipse.xtext.crossrefs;
|
||||
|
||||
import org.eclipse.emf.ecore.EObject;
|
||||
import org.eclipse.xtext.tests.AbstractGeneratorTest;
|
||||
|
||||
public class CrossRefTest extends AbstractGeneratorTest {
|
||||
@Override
|
||||
protected void setUp() throws Exception {
|
||||
super.setUp();
|
||||
with(LangAStandaloneSetup.class);
|
||||
}
|
||||
|
||||
public void testSimple() throws Exception {
|
||||
EObject model = getModel("type A extends B type B extends A");
|
||||
System.out.println(invokeWithXtend("types.collect(e|e.name+' '+e.extends.name).toString(',')", model));
|
||||
assertWithXtend("'B'", "types.first().extends.name", model);
|
||||
assertWithXtend("types.first()", "types.first().extends.extends", model);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,5 @@
|
|||
package org.eclipse.xtext.crossrefs;
|
||||
|
||||
public class LangA {
|
||||
|
||||
}
|
|
@ -0,0 +1,13 @@
|
|||
language org.eclipse.xtext.crossrefs.LangA
|
||||
|
||||
generate langA "http://eclipse.org/xtext/langA"
|
||||
|
||||
Main :
|
||||
imports+=Import*
|
||||
types+=Type*;
|
||||
|
||||
Import :
|
||||
'import' uri=STRING;
|
||||
|
||||
Type :
|
||||
'type' name=ID 'extends' ^extends=[Type];
|
|
@ -15,4 +15,9 @@ public class XtextParserTest extends AbstractGeneratorTest {
|
|||
Grammar model = (Grammar) getModel("language foo generate foo 'bar' as x Model returns x::Foo : 'holla' name=ID;");
|
||||
assertWithXtend("'x'", "metamodelDeclarations.first().alias", model);
|
||||
}
|
||||
|
||||
public void testParseCrossRef() throws Exception {
|
||||
Grammar model = (Grammar) getModel("language foo generate foo 'bar' Model : 'a' stuff+=Stuff*; Stuff : 'stuff' name=ID refersTo=[Stuff];");
|
||||
assertWithXtend("'Stuff'", "eAllContents.typeSelect(xtext::CrossReference).first().type.name", model);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,46 @@
|
|||
package org.eclipse.xtext.xtext2ecore;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.eclipse.xtext.Grammar;
|
||||
import org.eclipse.xtext.RuleCall;
|
||||
import org.eclipse.xtext.XtextStandaloneSetup;
|
||||
import org.eclipse.xtext.tests.AbstractGeneratorTest;
|
||||
import org.eclipse.xtext.xtextutil.MetaModel;
|
||||
import org.eclipse.xtext.xtextutil.XtextutilPackage;
|
||||
|
||||
public class XtextUtilTrafoTest extends AbstractGeneratorTest {
|
||||
@Override
|
||||
protected void setUp() throws Exception {
|
||||
super.setUp();
|
||||
XtextutilPackage.eINSTANCE.getAbstractType(); // initialze and register
|
||||
with(XtextStandaloneSetup.class);
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public void testCrossRefs() throws Exception {
|
||||
Grammar model = (Grammar) getModel("language foo generate foo 'bar' Model : stuff+=Stuff*; Stuff : 'stuff' name=ID refersTo=[Stuff];");
|
||||
List<MetaModel> metamodels = (List<MetaModel>) invokeWithXtend("getAllMetaModels(this)", model);
|
||||
assertEquals(2, metamodels.size());
|
||||
assertWithXtend("'Stuff'",
|
||||
"eAllContents.flatten().typeSelect(xtextutil::ComplexType).select(e|e.name=='Stuff')"
|
||||
+ ".first().features.selectFirst(e|e.name=='refersTo').type.name", metamodels);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String[] importedExtensions() {
|
||||
return new String[] { "org::eclipse::xtext::XtextUtil" };
|
||||
}
|
||||
|
||||
public void testCurrentType() throws Exception {
|
||||
Grammar model = (Grammar) getModel("language org.eclipse.xtext.crossrefs.LangA" +
|
||||
" generate langA 'http://eclipse.org/xtext/langA' "
|
||||
+ "Main : ^import+=Import* types+=Type*;"
|
||||
+ "Import : 'import' uri=STRING;"
|
||||
+ "Type : 'type' name=ID 'extends' ^extends=[Type];");
|
||||
RuleCall rc = (RuleCall) invokeWithXtend("parserRules.first().eAllContents.typeSelect(xtext::RuleCall).first()", model);
|
||||
assertNotNull(rc);
|
||||
assertWithXtend("'Main'", "testCurrentType().name", rc);
|
||||
assertWithXtend("false", "testCurrentType().abstract", rc);
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue