8
8
*******************************************************************************/
9
9
package org .eclipse .xtext .serializer ;
10
10
11
+ import java .util .Iterator ;
12
+ import java .util .List ;
13
+
14
+ import org .eclipse .emf .common .notify .Adapter ;
11
15
import org .eclipse .emf .common .util .URI ;
16
+ import org .eclipse .emf .ecore .EObject ;
17
+ import org .eclipse .emf .ecore .util .EcoreUtil ;
12
18
import org .eclipse .xtext .AbstractRule ;
13
19
import org .eclipse .xtext .Grammar ;
14
20
import org .eclipse .xtext .GrammarUtil ;
15
21
import org .eclipse .xtext .Group ;
16
- import org .eclipse .xtext .RuleCall ;
17
- import org .eclipse .xtext .TerminalRule ;
18
22
import org .eclipse .xtext .XtextStandaloneSetup ;
19
- import org .eclipse .xtext .common .services .TerminalsGrammarAccess ;
20
- import org .eclipse .xtext .grammarinheritance .services .BaseInheritanceTestLanguageGrammarAccess ;
21
- import org .eclipse .xtext .grammarinheritance .services .InheritanceTestLanguageGrammarAccess ;
23
+ import org .eclipse .xtext .nodemodel .ICompositeNode ;
22
24
import org .eclipse .xtext .resource .XtextResourceSet ;
23
- import org .eclipse .xtext .service .GrammarProvider ;
24
- import org .eclipse .xtext .services .XtextGrammarAccess ;
25
25
import org .eclipse .xtext .testing .serializer .SerializerTestHelper ;
26
26
import org .eclipse .xtext .tests .AbstractXtextTests ;
27
+ import org .eclipse .xtext .util .Pair ;
28
+ import org .eclipse .xtext .util .Tuples ;
27
29
import org .junit .Assert ;
28
30
import org .junit .Ignore ;
29
31
import org .junit .Test ;
30
32
33
+ import com .google .common .collect .Lists ;
31
34
import com .google .inject .Inject ;
32
- import com .google .inject .Provider ;
33
35
34
36
/**
35
37
* @author Moritz Eysholdt - Initial contribution and API
@@ -38,11 +40,6 @@ public class XtextSerializerTest extends AbstractXtextTests {
38
40
@ Inject
39
41
private SerializerTestHelper tester ;
40
42
41
- private Grammar load (URI uri ) {
42
- XtextResourceSet rs = new XtextResourceSet ();
43
- return (Grammar ) rs .getResource (uri , true ).getContents ().get (0 );
44
- }
45
-
46
43
@ Override
47
44
public void setUp () throws Exception {
48
45
super .setUp ();
@@ -58,48 +55,14 @@ public void testXtextXtextWithNM() throws Exception {
58
55
}
59
56
60
57
@ Test
61
- @ Ignore ("To be done" )
62
- public void testXtextXtextWithoutNM () throws Exception {
58
+ public void testGroup () {
63
59
Grammar grammar = load (URI .createURI ("classpath:/org/eclipse/xtext/Xtext.xtext" ));
64
- tester .assertSerializeWithoutNodeModel (grammar );
60
+ AbstractRule rule = GrammarUtil .findRuleForName (grammar , "org.eclipse.xtext.Xtext.Grammar" );
61
+ Group cGroup_2 = (Group ) rule .eContents ().get (1 ).eContents ().get (2 );
62
+ detachNodeModel (grammar );
63
+ String string = get (ISerializer .class ).serialize (cGroup_2 );
64
+ Assert .assertEquals ("(\" with\" usedGrammars+=[Grammar|GrammarID] (\" ,\" usedGrammars+=[Grammar|GrammarID])*)?" ,
65
+ string );
65
66
}
66
67
67
- @ Test
68
- public void testGroup () {
69
- XtextGrammarAccess grammarAccess = get (XtextGrammarAccess .class );
70
- String string = get (ISerializer .class ).serialize (grammarAccess .getGrammarAccess ().getGroup_2 ());
71
- Assert .assertEquals ("(\" with\" usedGrammars+=[Grammar|GrammarID] (\" ,\" usedGrammars+=[Grammar|GrammarID])*)?" , string );
72
- }
73
-
74
- @ Test
75
- public void testFQNInSuper_01 () {
76
- GrammarProvider grammarProvider = new GrammarProvider ("org.eclipse.xtext.grammarinheritance.InheritanceTestLanguage" , new Provider <XtextResourceSet >() {
77
- @ Override
78
- public XtextResourceSet get () {
79
- return XtextSerializerTest .this .get (XtextResourceSet .class );
80
- }
81
- });
82
- grammarProvider .setClassLoader (getClass ().getClassLoader ());
83
- TerminalsGrammarAccess gaTerminals = new TerminalsGrammarAccess (grammarProvider );
84
- BaseInheritanceTestLanguageGrammarAccess gaBaseInheritanceTestLanguage = new BaseInheritanceTestLanguageGrammarAccess (grammarProvider , gaTerminals );
85
- InheritanceTestLanguageGrammarAccess grammarAccess = new InheritanceTestLanguageGrammarAccess (grammarProvider , gaBaseInheritanceTestLanguage , gaTerminals );
86
- String string = get (ISerializer .class ).serialize (grammarAccess .getFQNRule ().getAlternatives ());
87
- Assert .assertEquals ("ID (\" .\" ID)*" , string );
88
- }
89
-
90
- @ Ignore ("Serialization does not have the correct context information" )
91
- @ Test
92
- public void testFQNInSuper_02 () {
93
- Grammar grammar = load (URI .createURI ("classpath:/org/eclipse/xtext/grammarinheritance/InheritanceTestLanguage.xtext" ));
94
- AbstractRule rule = GrammarUtil .findRuleForName (grammar , "FQN" );
95
- Assert .assertNotNull (rule );
96
- Group group = (Group ) rule .getAlternatives ();
97
- RuleCall ruleCall = (RuleCall ) group .getElements ().get (0 );
98
- TerminalRule id = (TerminalRule ) ruleCall .getRule ();
99
- Assert .assertSame (grammar , GrammarUtil .getGrammar (id ));
100
- String string = get (ISerializer .class ).serialize (rule .getAlternatives ());
101
- Assert .assertEquals ("ID (\" .\" ID)*" , string );
102
- // currently wrong result is
103
- Assert .assertEquals ("super::ID (\" .\" super::ID)*" , string );
104
- }
105
68
}
0 commit comments