1 package de.fhdw.wtf.walker.tasks.test;
2
3 import static org.junit.Assert.assertEquals;
4
5 import java.util.ArrayList;
6 import java.util.Collection;
7 import java.util.Iterator;
8 import java.util.Vector;
9 import java.util.concurrent.ExecutionException;
10
11 import org.junit.Before;
12 import org.junit.Test;
13
14 import de.fhdw.wtf.common.ast.Attribute;
15 import de.fhdw.wtf.common.ast.AttributeModifier;
16 import de.fhdw.wtf.common.ast.Constructor;
17 import de.fhdw.wtf.common.ast.Group;
18 import de.fhdw.wtf.common.ast.GroupElement;
19 import de.fhdw.wtf.common.ast.Model;
20 import de.fhdw.wtf.common.ast.Name;
21 import de.fhdw.wtf.common.ast.Operation;
22 import de.fhdw.wtf.common.ast.QualifiedName;
23 import de.fhdw.wtf.common.ast.UnqualifiedName;
24 import de.fhdw.wtf.common.ast.type.BaseType;
25 import de.fhdw.wtf.common.ast.type.ByReferenceState;
26 import de.fhdw.wtf.common.ast.type.ClassModifier;
27 import de.fhdw.wtf.common.ast.type.ClassType;
28 import de.fhdw.wtf.common.ast.type.ProductElementType;
29 import de.fhdw.wtf.common.ast.type.ProductType;
30 import de.fhdw.wtf.common.ast.type.SumType;
31 import de.fhdw.wtf.common.ast.type.Type;
32 import de.fhdw.wtf.common.ast.type.TypeProxy;
33 import de.fhdw.wtf.common.stream.FilteredTokenStream;
34 import de.fhdw.wtf.common.stream.SimpleScannerInput;
35 import de.fhdw.wtf.common.stream.TokenStream;
36 import de.fhdw.wtf.common.task.TaskExecutor;
37 import de.fhdw.wtf.common.task.TaskExecutorFixed;
38 import de.fhdw.wtf.common.task.result.ExceptionalTaskResult;
39 import de.fhdw.wtf.common.task.result.OKTaskResult;
40 import de.fhdw.wtf.common.task.result.TaskResult;
41 import de.fhdw.wtf.common.task.result.visitor.TaskResultVisitor;
42 import de.fhdw.wtf.common.token.DummyToken;
43 import de.fhdw.wtf.common.token.IdentifierToken;
44 import de.fhdw.wtf.common.token.Position;
45 import de.fhdw.wtf.core.integration.testutil.AssertOperations;
46 import de.fhdw.wtf.dsl.scanner.common.Scanner;
47 import de.fhdw.wtf.dsl.scanner.modelScanner.ModelDslScanner;
48 import de.fhdw.wtf.parser.Parser;
49 import de.fhdw.wtf.walker.tasks.Referencer;
50
51
52
53
54
55 public class TestReferencer {
56
57
58
59
60 private AssertOperations assertOperations;
61
62
63
64
65 @Before
66 public void setUp() {
67 this.assertOperations = new AssertOperations();
68 }
69
70
71
72
73
74
75
76
77 @Test
78 public void simpleGroupWithClassAndOneAttribute() throws Exception {
79 final Scanner scanner = ModelDslScanner.create();
80 final SimpleScannerInput input = new SimpleScannerInput("Group1:group=[Class1:class={name:String prior;};];");
81 final TokenStream output = FilteredTokenStream.create();
82 scanner.scan(input, output);
83 final Parser parser = Parser.create(output);
84 final Model result = parser.parse();
85
86 final ReturnValue v = new ReturnValue(result);
87
88 assertEquals(1, v.getOkResult().size());
89 assertEquals(0, v.getFailResult().size());
90 this.assertOperations.assertAllReferencesByType(result);
91 }
92
93
94
95
96
97
98
99
100 @Test
101 public void simpleGroupInGroupAnd3ClassesWithDifferentAttributes() throws Exception {
102 final Scanner scanner = ModelDslScanner.create();
103 final SimpleScannerInput input =
104 new SimpleScannerInput("Group1:group=[Class1:class={name:String prior;};"
105 + "Class2:class={type:Class1*;name:String prior;alter:Integer prior;};"
106 + "Group2:group=[Class1:class= Class2 + {beschreibungen:String * prior;};];];");
107 final TokenStream output = FilteredTokenStream.create();
108 scanner.scan(input, output);
109 final Parser parser = Parser.create(output);
110 final Model result = parser.parse();
111
112 final ReturnValue v = new ReturnValue(result);
113
114 assertEquals(0, v.getFailResult().size());
115 assertEquals(1, v.getOkResult().size());
116 this.assertOperations.assertAllReferencesByType(result);
117 }
118
119
120
121
122
123
124
125
126
127 @Test
128 public void simple2GroupsAnd3ClassesWithDifferentAttributesAndAWrongQualification() throws Exception {
129 final Scanner scanner = ModelDslScanner.create();
130 final SimpleScannerInput input =
131 new SimpleScannerInput("Group1:group=[Class1:class={name:String prior;};"
132 + "Class2:class={type:Class1*;name:String prior;alter:Integer prior;};];"
133 + "Group2:group=[Class1:class= Class2 + {beschreibungen:String * prior;};];");
134 final TokenStream output = FilteredTokenStream.create();
135 scanner.scan(input, output);
136 final Parser parser = Parser.create(output);
137 final Model result = parser.parse();
138
139 final ReturnValue v = new ReturnValue(result);
140
141 assertEquals(1, v.getFailResult().size());
142 assertEquals(0, v.getOkResult().size());
143 }
144
145
146
147
148
149
150
151
152
153 @Test
154 public void simple2GroupsAnd3ClassesWithDifferentAttributesAnd2Supertypes() throws Exception {
155 final Scanner scanner = ModelDslScanner.create();
156 final SimpleScannerInput input =
157 new SimpleScannerInput("Group1:group=[Class1:class={name:String prior;};"
158 + "Class2:class={type:Class1*;name:String prior;alter:Integer prior;};"
159 + "Group2:group=[Class1:class= Class2 + Class2 + {beschreibungen:String * prior;};];];");
160 final TokenStream output = FilteredTokenStream.create();
161 scanner.scan(input, output);
162 final Parser parser = Parser.create(output);
163 final Model result = parser.parse();
164 final ReturnValue v = new ReturnValue(result);
165 assertEquals(0, v.getFailResult().size());
166 assertEquals(1, v.getOkResult().size());
167 this.assertOperations.assertAllReferencesByType(result);
168 }
169
170
171
172
173
174
175
176
177
178
179 @Test
180 public void test3GroupsAndManyClassesWithDifferentAttributes() throws Exception {
181 final Scanner scanner = ModelDslScanner.create();
182 final SimpleScannerInput input =
183 new SimpleScannerInput("Group1:group=[Class1:class={"
184 + "name:String prior;};Class2:class={type:Class1*;name:String prior;"
185 + "alter:Integer prior;}abstract;Group2:group=[Class1:class= Class2 + Class2 + {"
186 + "beschreibungen:String * prior;}; Class1:class = {name:String prior;};"
187 + "Group3:group=[Class1:class= Class1 + {alter:Integer;};];];];");
188 final TokenStream output = FilteredTokenStream.create();
189 scanner.scan(input, output);
190 final Parser parser = Parser.create(output);
191 final Model result = parser.parse();
192
193 final ReturnValue v = new ReturnValue(result);
194
195 assertEquals(0, v.getFailResult().size());
196 assertEquals(1, v.getOkResult().size());
197 this.assertOperations.assertAllReferencesByType(result);
198 }
199
200
201
202
203
204
205
206
207
208 @Test
209 public void testSupertypesWithDifferentGroups() throws Exception {
210 final Scanner scanner = ModelDslScanner.create();
211 final SimpleScannerInput input =
212 new SimpleScannerInput("Group1:group=[Group1:group=[Class1:class={"
213 + "};];Class1:class= Group1>Group1>Class1 + {};];Group2:group=["
214 + "Class2:class = Group1>Class1 + Group1>Group1>Class1 + {class1:Group1>Class1* prior;};];");
215 final TokenStream output = FilteredTokenStream.create();
216 scanner.scan(input, output);
217 final Parser parser = Parser.create(output);
218 final Model result = parser.parse();
219
220 final ReturnValue v = new ReturnValue(result);
221
222 assertEquals(1, v.getFailResult().size());
223
224
225 assertEquals(0, v.getOkResult().size());
226 }
227
228
229
230
231
232
233
234
235
236
237
238 @Test
239 public void test2GroupsInModelAndDifferentOtherGroupsCheckingRelativePath() throws Exception {
240 final Scanner scanner = ModelDslScanner.create();
241 final SimpleScannerInput input =
242 new SimpleScannerInput("Group1:group = [Group2:group = ["
243 + "Class1:class={};];];Group2:group= [Class1:class={};Group1:group=["
244 + "Class1:class= Group2>Class1 +{classa:Group1>Group2>Class1;};Group1:group=["
245 + "Class1:class = Group2>Group1>Class1 + {class21:Group2>Group1>Class1;};];];];");
246 final IdentifierToken group1IdentifierToken =
247 IdentifierToken.create("Group1", Position.create("", 0 + 1, 0 + 1, 0));
248 final Model model = Model.create(group1IdentifierToken, null);
249
250 final Name group1Name = UnqualifiedName.create(group1IdentifierToken);
251 final Collection<GroupElement> group1Elements = new Vector<>();
252 final Group group1 = Group.create(group1Name, group1Elements, group1IdentifierToken, null);
253 model.addGroup(group1);
254 final IdentifierToken group12IdentifierToken =
255 IdentifierToken.create("Group2", Position.create("", 0 + 1, 0 + 1, 0));
256 final Name group12Name = group1Name.addName(group12IdentifierToken);
257 final Collection<GroupElement> group12Elements = new Vector<>();
258 final Group group12 = Group.create(group12Name, group12Elements, group12IdentifierToken, null);
259 group1Elements.add(group12);
260 final IdentifierToken class121IdentifierToken =
261 IdentifierToken.create("Class1", Position.create("", 0 + 1, 0 + 1, 0));
262 final Name class121Name = group12Name.addName(class121IdentifierToken);
263 final Collection<ClassModifier> class121Modifiers = new Vector<>();
264 final Collection<Attribute> class121Attributes = new Vector<>();
265 final Collection<Type> class121SuperTypes = new Vector<>();
266 final Collection<Operation> class121Operations = new Vector<>();
267 final ClassType class121 =
268 ClassType.create(
269 class121Name,
270 class121Modifiers,
271 class121Attributes,
272 class121SuperTypes,
273 class121Operations,
274 new Vector<Constructor>(),
275 class121IdentifierToken,
276 false,
277 new Vector<ClassType>(),
278 null);
279 group12Elements.add(class121);
280 final IdentifierToken group2IdentifierToken =
281 IdentifierToken.create("Group2", Position.create("", 0 + 1, 0 + 1, 0));
282 final Name group2Name = UnqualifiedName.create(group2IdentifierToken);
283 final Collection<GroupElement> group2Elements = new Vector<>();
284 final Group group2 = Group.create(group2Name, group2Elements, group2IdentifierToken, null);
285 model.addGroup(group2);
286 final IdentifierToken class21IdentifierToken =
287 IdentifierToken.create("Class1", Position.create("", 0 + 1, 0 + 1, 0));
288 final Name class21Name = group2Name.addName(class21IdentifierToken);
289 final Collection<ClassModifier> class21Modifiers = new Vector<>();
290 final Collection<Attribute> class21Attributes = new Vector<>();
291 final Collection<Type> class21SuperTypes = new Vector<>();
292 final Collection<Operation> class21Operations = new Vector<>();
293 final ClassType class21 =
294 ClassType.create(
295 class21Name,
296 class21Modifiers,
297 class21Attributes,
298 class21SuperTypes,
299 class21Operations,
300 new Vector<Constructor>(),
301 class21IdentifierToken,
302 false,
303 new Vector<ClassType>(),
304 null);
305 group2Elements.add(class21);
306 final IdentifierToken group21IdentifierToken =
307 IdentifierToken.create("Group1", Position.create("", 0 + 1, 0 + 1, 0));
308 final Name group21Name = group2Name.addName(group21IdentifierToken);
309 final Collection<GroupElement> group21Elements = new Vector<>();
310 final Group group21 = Group.create(group21Name, group21Elements, group21IdentifierToken, null);
311 group2Elements.add(group21);
312 final IdentifierToken class211IdentifierToken =
313 IdentifierToken.create("Class1", Position.create("", 0 + 1, 0 + 1, 0));
314 final Name class211Name = group21Name.addName(class211IdentifierToken);
315 final Collection<ClassModifier> class211Modifiers = new Vector<>();
316 final Collection<Attribute> class211Attributes = new Vector<>();
317 final Collection<Type> class211SuperTypes = new Vector<>();
318 final Collection<Operation> class211Operations = new Vector<>();
319 final ClassType class211 =
320 ClassType.create(
321 class211Name,
322 class211Modifiers,
323 class211Attributes,
324 class211SuperTypes,
325 class211Operations,
326 new Vector<Constructor>(),
327 class211IdentifierToken,
328 false,
329 new Vector<ClassType>(),
330 null);
331 group21Elements.add(class211);
332 final ByReferenceState class211SuperTypeState = ByReferenceState.create(class21, class21.getTypeName());
333 final TypeProxy class211Supertype = TypeProxy.create(class211IdentifierToken, class211SuperTypeState, null);
334 class211SuperTypes.add(class211Supertype);
335 final ByReferenceState class211AttributeTypeReferenceState =
336 ByReferenceState.create(class121, class121.getTypeName());
337 final TypeProxy class211AttributeTypeReference =
338 TypeProxy.create(class121IdentifierToken, class211AttributeTypeReferenceState, null);
339
340 final IdentifierToken class211AttributeTypeIdentifier =
341 IdentifierToken.create("", Position.create("", 0 + 1, 0 + 1, 0));
342 final Attribute class211Attribute =
343 Attribute.create(
344 "classa",
345 class211AttributeTypeReference,
346 new Vector<AttributeModifier>(),
347 class211IdentifierToken,
348 null);
349 class211Attributes.add(class211Attribute);
350 final IdentifierToken group211IdentifierToken =
351 IdentifierToken.create("Group1", Position.create("", 0 + 1, 0 + 1, 0));
352 final Name group211Name = group21Name.addName(group211IdentifierToken);
353 final Collection<GroupElement> group211Elements = new Vector<>();
354 final Group group211 = Group.create(group211Name, group211Elements, group211IdentifierToken, null);
355 group21Elements.add(group211);
356 final IdentifierToken class2111IdentifierToken =
357 IdentifierToken.create("Class1", Position.create("", 0 + 1, 0 + 1, 0));
358 final Name class2111Name = group211Name.addName(class2111IdentifierToken);
359 final Collection<ClassModifier> class2111Modifiers = new Vector<>();
360 final Collection<Attribute> class2111Attributes = new Vector<>();
361 final Collection<Type> class2111SuperTypes = new Vector<>();
362 final Collection<Operation> class2111Operations = new Vector<>();
363 final ClassType class2111 =
364 ClassType.create(
365 class2111Name,
366 class2111Modifiers,
367 class2111Attributes,
368 class2111SuperTypes,
369 class2111Operations,
370 new Vector<Constructor>(),
371 class211IdentifierToken,
372 false,
373 new Vector<ClassType>(),
374 null);
375 group211Elements.add(class2111);
376 final ByReferenceState class2111SuperTypeState = ByReferenceState.create(class211, class211.getTypeName());
377 final TypeProxy class2111Supertype = TypeProxy.create(class2111IdentifierToken, class2111SuperTypeState, null);
378 class2111SuperTypes.add(class2111Supertype);
379 final ByReferenceState class2111AttributeTypeReferenceState =
380 ByReferenceState.create(class211, class211.getTypeName());
381 final TypeProxy class2111AttributeTypeReference =
382 TypeProxy.create(class211AttributeTypeIdentifier, class2111AttributeTypeReferenceState, null);
383 final Attribute class2111Attribute =
384 Attribute.create(
385 "class21",
386 class2111AttributeTypeReference,
387 new Vector<AttributeModifier>(),
388 class2111IdentifierToken,
389 null);
390 class2111Attributes.add(class2111Attribute);
391
392 final TokenStream output = FilteredTokenStream.create();
393 scanner.scan(input, output);
394 final Parser parser = Parser.create(output);
395
396 final Model result = parser.parse();
397 final ReturnValue v = new ReturnValue(result);
398
399 assertEquals(1, v.getFailResult().size());
400 assertEquals(1, v.getReferencer().getExceptions().size());
401 assertEquals(0, v.getOkResult().size());
402 }
403
404
405
406
407
408
409
410
411
412
413 @Test
414 public void test2GroupsWithClassesRelativePath() throws Exception {
415 final Scanner scanner = ModelDslScanner.create();
416 final SimpleScannerInput input =
417 new SimpleScannerInput("Group1:group = [Group2:group = ["
418 + "Class1:class={};];]; Group2:group= [Class1:class= Group1>Class1 + {};"
419 + "Group1:group=[Class1:class= {classa:Group1>Group2>Class1;};Group1:group=["
420 + "Class1:class = Group2>Group1>Class1 + {class21:Group2>Group1>Class1;};];];];");
421 final IdentifierToken group1IdentifierToken =
422 IdentifierToken.create("Group1", Position.create("", 0 + 1, 0 + 1, 0));
423 final Model model = Model.create(group1IdentifierToken, null);
424
425 final Name group1Name = UnqualifiedName.create(group1IdentifierToken);
426 final Collection<GroupElement> group1Elements = new Vector<>();
427 final Group group1 = Group.create(group1Name, group1Elements, group1IdentifierToken, null);
428 model.addGroup(group1);
429 final IdentifierToken group12IdentifierToken =
430 IdentifierToken.create("Group2", Position.create("", 0 + 1, 0 + 1, 0));
431 final Name group12Name = group1Name.addName(group12IdentifierToken);
432 final Collection<GroupElement> group12Elements = new Vector<>();
433 final Group group12 = Group.create(group12Name, group12Elements, group12IdentifierToken, null);
434 group1Elements.add(group12);
435 final IdentifierToken class121IdentifierToken =
436 IdentifierToken.create("Class1", Position.create("", 0 + 1, 0 + 1, 0));
437 final Name class121Name = group12Name.addName(class121IdentifierToken);
438 final Collection<ClassModifier> class121Modifiers = new Vector<>();
439 final Collection<Attribute> class121Attributes = new Vector<>();
440 final Collection<Type> class121SuperTypes = new Vector<>();
441 final Collection<Operation> class121Operations = new Vector<>();
442 final ClassType class121 =
443 ClassType.create(
444 class121Name,
445 class121Modifiers,
446 class121Attributes,
447 class121SuperTypes,
448 class121Operations,
449 new Vector<Constructor>(),
450 class121IdentifierToken,
451 false,
452 new Vector<ClassType>(),
453 null);
454 group12Elements.add(class121);
455 final IdentifierToken group2IdentifierToken =
456 IdentifierToken.create("Group2", Position.create("", 0 + 1, 0 + 1, 0));
457 final Name group2Name = UnqualifiedName.create(group2IdentifierToken);
458 final Collection<GroupElement> group2Elements = new Vector<>();
459 final Group group2 = Group.create(group2Name, group2Elements, group2IdentifierToken, null);
460 model.addGroup(group2);
461 final IdentifierToken class21IdentifierToken =
462 IdentifierToken.create("Class1", Position.create("", 0 + 1, 0 + 1, 0));
463 final Name class21Name = group2Name.addName(class21IdentifierToken);
464 final Collection<ClassModifier> class21Modifiers = new Vector<>();
465 final Collection<Attribute> class21Attributes = new Vector<>();
466 final Collection<Type> class21SuperTypes = new Vector<>();
467 final Collection<Operation> class21Operations = new Vector<>();
468 final ClassType class21 =
469 ClassType.create(
470 class21Name,
471 class21Modifiers,
472 class21Attributes,
473 class21SuperTypes,
474 class21Operations,
475 new Vector<Constructor>(),
476 class21IdentifierToken,
477 false,
478 new Vector<ClassType>(),
479 null);
480 group2Elements.add(class21);
481 final IdentifierToken group21IdentifierToken =
482 IdentifierToken.create("Group1", Position.create("", 0 + 1, 0 + 1, 0));
483 final Name group21Name = group2Name.addName(group21IdentifierToken);
484 final Collection<GroupElement> group21Elements = new Vector<>();
485 final Group group21 = Group.create(group21Name, group21Elements, group21IdentifierToken);
486 group2Elements.add(group21);
487 final IdentifierToken class211IdentifierToken =
488 IdentifierToken.create("Class1", Position.create("", 0 + 1, 0 + 1, 0));
489 final Name class211Name = group21Name.addName(class211IdentifierToken);
490 final Collection<ClassModifier> class211Modifiers = new Vector<>();
491 final Collection<Attribute> class211Attributes = new Vector<>();
492 final Collection<Type> class211SuperTypes = new Vector<>();
493 final Collection<Operation> class211Operations = new Vector<>();
494 final ClassType class211 =
495 ClassType.create(
496 class211Name,
497 class211Modifiers,
498 class211Attributes,
499 class211SuperTypes,
500 class211Operations,
501 new Vector<Constructor>(),
502 class211IdentifierToken,
503 false,
504 new Vector<ClassType>());
505 group21Elements.add(class211);
506 final ByReferenceState class21SuperTypeReferenceState =
507 ByReferenceState.create(class211, class211.getTypeName());
508 final TypeProxy class21SuperTypeReference =
509 TypeProxy.create(class211IdentifierToken, class21SuperTypeReferenceState);
510 class21SuperTypes.add(class21SuperTypeReference);
511 final ByReferenceState class211AttributeTypeReferenceState =
512 ByReferenceState.create(class121, class121.getTypeName());
513 final TypeProxy class211AttributeTypeReference =
514 TypeProxy.create(class121IdentifierToken, class211AttributeTypeReferenceState);
515 final IdentifierToken class211AttributeTypeIdentifier =
516 IdentifierToken.create("", Position.create("", 0 + 1, 0 + 1, 0));
517 final IdentifierToken class211AttributeIdentifier =
518 IdentifierToken.create("classa", Position.create("", 0 + 1, 0 + 1, 0));
519 final Attribute class211Attribute =
520 Attribute.create(
521 "classa",
522 class211AttributeTypeReference,
523 new Vector<AttributeModifier>(),
524 class211AttributeIdentifier);
525 class211Attributes.add(class211Attribute);
526 final IdentifierToken group211IdentifierToken =
527 IdentifierToken.create("Group1", Position.create("", 0 + 1, 0 + 1, 0));
528 final Name group211Name = group21Name.addName(group211IdentifierToken);
529 final Collection<GroupElement> group211Elements = new Vector<>();
530 final Group group211 = Group.create(group211Name, group211Elements, group211IdentifierToken);
531 group21Elements.add(group211);
532 final IdentifierToken class2111IdentifierToken =
533 IdentifierToken.create("Class1", Position.create("", 0 + 1, 0 + 1, 0));
534 final Name class2111Name = group211Name.addName(class2111IdentifierToken);
535 final Collection<ClassModifier> class2111Modifiers = new Vector<>();
536 final Collection<Attribute> class2111Attributes = new Vector<>();
537 final Collection<Type> class2111SuperTypes = new Vector<>();
538 final Collection<Operation> class2111Operations = new Vector<>();
539 final ClassType class2111 =
540 ClassType.create(
541 class2111Name,
542 class2111Modifiers,
543 class2111Attributes,
544 class2111SuperTypes,
545 class2111Operations,
546 new Vector<Constructor>(),
547 class2111IdentifierToken,
548 false,
549 new Vector<ClassType>());
550 group211Elements.add(class2111);
551 final ByReferenceState class2111SuperTypeState = ByReferenceState.create(class211, class211.getTypeName());
552 final TypeProxy class2111Supertype = TypeProxy.create(class2111IdentifierToken, class2111SuperTypeState);
553 class2111SuperTypes.add(class2111Supertype);
554 final ByReferenceState class2111AttributeTypeReferenceState =
555 ByReferenceState.create(class211, class211.getTypeName());
556 final TypeProxy class2111AttributeTypeReference =
557 TypeProxy.create(class211AttributeTypeIdentifier, class2111AttributeTypeReferenceState);
558 final IdentifierToken class2111AttributeIdentifier =
559 IdentifierToken.create("", Position.create("", 0 + 1, 0 + 1, 0));
560 final Attribute class2111Attribute =
561 Attribute.create(
562 "class21",
563 class2111AttributeTypeReference,
564 new Vector<AttributeModifier>(),
565 class2111AttributeIdentifier);
566 class2111Attributes.add(class2111Attribute);
567
568 final TokenStream output = FilteredTokenStream.create();
569 scanner.scan(input, output);
570 final Parser parser = Parser.create(output);
571 final Model result = parser.parse();
572
573 final ReturnValue v = new ReturnValue(result);
574
575 assertEquals(1, v.getFailResult().size());
576 assertEquals(1, v.getReferencer().getExceptions().size());
577 assertEquals(0, v.getOkResult().size());
578 }
579
580
581
582
583
584
585
586
587
588
589 @Test
590 public void test2GroupsWithClasseHierarchieZyklus() throws Exception {
591 final Scanner scanner = ModelDslScanner.create();
592 final SimpleScannerInput input =
593 new SimpleScannerInput("Group1:group = [Group2:group = ["
594 + "Class1:class={};];];Group2:group= [Class1:class= Group1>Class1 + {};"
595 + "Group1:group=[Class1:class= Group2>Class1 +{classa:Group1>Group2>Class1;};"
596 + "Group1:group=[Class1:class = Group2>Group1>Class1 + {class21:Group2>Group1>Class1;};];];];");
597 final IdentifierToken group1IdentifierToken =
598 IdentifierToken.create("Group1", Position.create("", 0 + 1, 0 + 1, 0));
599 final Model model = Model.create(group1IdentifierToken);
600
601 final Name group1Name = UnqualifiedName.create(group1IdentifierToken);
602 final Collection<GroupElement> group1Elements = new Vector<>();
603 final Group group1 = Group.create(group1Name, group1Elements, group1IdentifierToken);
604 model.addGroup(group1);
605 final IdentifierToken group12IdentifierToken =
606 IdentifierToken.create("Group2", Position.create("", 0 + 1, 0 + 1, 0));
607 final Name group12Name = group1Name.addName(group12IdentifierToken);
608 final Collection<GroupElement> group12Elements = new Vector<>();
609 final Group group12 = Group.create(group12Name, group12Elements, group12IdentifierToken);
610 group1Elements.add(group12);
611 final IdentifierToken class121IdentifierToken =
612 IdentifierToken.create("Class1", Position.create("", 0 + 1, 0 + 1, 0));
613 final Name class121Name = group12Name.addName(class121IdentifierToken);
614 final Collection<ClassModifier> class121Modifiers = new Vector<>();
615 final Collection<Attribute> class121Attributes = new Vector<>();
616 final Collection<Type> class121SuperTypes = new Vector<>();
617 final Collection<Operation> class121Operations = new Vector<>();
618 final ClassType class121 =
619 ClassType.create(
620 class121Name,
621 class121Modifiers,
622 class121Attributes,
623 class121SuperTypes,
624 class121Operations,
625 new Vector<Constructor>(),
626 class121IdentifierToken,
627 false,
628 new Vector<ClassType>());
629 group12Elements.add(class121);
630 final IdentifierToken group2IdentifierToken =
631 IdentifierToken.create("Group2", Position.create("", 0 + 1, 0 + 1, 0));
632 final Name group2Name = UnqualifiedName.create(group2IdentifierToken);
633 final Collection<GroupElement> group2Elements = new Vector<>();
634 final Group group2 = Group.create(group2Name, group2Elements, group2IdentifierToken);
635 model.addGroup(group2);
636 final IdentifierToken class21IdentifierToken =
637 IdentifierToken.create("Class1", Position.create("", 0 + 1, 0 + 1, 0));
638 final Name class21Name = group2Name.addName(class21IdentifierToken);
639 final Collection<ClassModifier> class21Modifiers = new Vector<>();
640 final Collection<Attribute> class21Attributes = new Vector<>();
641 final Collection<Type> class21SuperTypes = new Vector<>();
642 final Collection<Operation> class21Operations = new Vector<>();
643 final ClassType class21 =
644 ClassType.create(
645 class21Name,
646 class21Modifiers,
647 class21Attributes,
648 class21SuperTypes,
649 class21Operations,
650 new Vector<Constructor>(),
651 class21IdentifierToken,
652 false,
653 new Vector<ClassType>());
654 group2Elements.add(class21);
655 final IdentifierToken group21IdentifierToken =
656 IdentifierToken.create("Group1", Position.create("", 0 + 1, 0 + 1, 0));
657 final Name group21Name = group2Name.addName(group21IdentifierToken);
658 final Collection<GroupElement> group21Elements = new Vector<>();
659 final Group group21 = Group.create(group21Name, group21Elements, group21IdentifierToken);
660 group2Elements.add(group21);
661 final IdentifierToken class211IdentifierToken =
662 IdentifierToken.create("Class1", Position.create("", 0 + 1, 0 + 1, 0));
663 final Name class211Name = group21Name.addName(class211IdentifierToken);
664 final Collection<ClassModifier> class211Modifiers = new Vector<>();
665 final Collection<Attribute> class211Attributes = new Vector<>();
666 final Collection<Type> class211SuperTypes = new Vector<>();
667 final Collection<Operation> class211Operations = new Vector<>();
668 final ClassType class211 =
669 ClassType.create(
670 class211Name,
671 class211Modifiers,
672 class211Attributes,
673 class211SuperTypes,
674 class211Operations,
675 new Vector<Constructor>(),
676 class211IdentifierToken,
677 false,
678 new Vector<ClassType>());
679 group21Elements.add(class211);
680 final ByReferenceState class21SuperTypeReferenceState =
681 ByReferenceState.create(class211, class211.getTypeName());
682 final TypeProxy class21SuperTypeReference =
683 TypeProxy.create(class211IdentifierToken, class21SuperTypeReferenceState);
684 class21SuperTypes.add(class21SuperTypeReference);
685 final ByReferenceState class211SuperTypeState = ByReferenceState.create(class21, class21.getTypeName());
686 final TypeProxy class211Supertype = TypeProxy.create(class21IdentifierToken, class211SuperTypeState);
687 class211SuperTypes.add(class211Supertype);
688 final ByReferenceState class211AttributeTypeReferenceState =
689 ByReferenceState.create(class121, class121.getTypeName());
690 final TypeProxy class211AttributeTypeReference =
691 TypeProxy.create(class121IdentifierToken, class211AttributeTypeReferenceState);
692 final IdentifierToken class211AttributeTypeIdentifier =
693 IdentifierToken.create("", Position.create("", 0 + 1, 0 + 1, 0));
694 final IdentifierToken class211AttributeIdentifier =
695 IdentifierToken.create("classa", Position.create("", 0 + 1, 0 + 1, 0));
696 final Attribute class211Attribute =
697 Attribute.create(
698 "classa",
699 class211AttributeTypeReference,
700 new Vector<AttributeModifier>(),
701 class211AttributeIdentifier);
702 class211Attributes.add(class211Attribute);
703 final IdentifierToken group211IdentifierToken =
704 IdentifierToken.create("Group1", Position.create("", 0 + 1, 0 + 1, 0));
705 final Name group211Name = group21Name.addName(group211IdentifierToken);
706 final Collection<GroupElement> group211Elements = new Vector<>();
707 final Group group211 = Group.create(group211Name, group211Elements, group211IdentifierToken);
708 group21Elements.add(group211);
709 final IdentifierToken class2111IdentifierToken =
710 IdentifierToken.create("Class1", Position.create("", 0 + 1, 0 + 1, 0));
711 final Name class2111Name = group211Name.addName(class2111IdentifierToken);
712 final Collection<ClassModifier> class2111Modifiers = new Vector<>();
713 final Collection<Attribute> class2111Attributes = new Vector<>();
714 final Collection<Type> class2111SuperTypes = new Vector<>();
715 final ClassType class2111 =
716 ClassType.create(
717 class2111Name,
718 class2111Modifiers,
719 class2111Attributes,
720 class2111SuperTypes,
721 class211Operations,
722 new Vector<Constructor>(),
723 class2111IdentifierToken,
724 false,
725 new Vector<ClassType>());
726 group211Elements.add(class2111);
727 final ByReferenceState class2111SuperTypeState = ByReferenceState.create(class211, class211.getTypeName());
728 final TypeProxy class2111Supertype = TypeProxy.create(class211IdentifierToken, class2111SuperTypeState);
729 class2111SuperTypes.add(class2111Supertype);
730 final ByReferenceState class2111AttributeTypeReferenceState =
731 ByReferenceState.create(class211, class211.getTypeName());
732 final TypeProxy class2111AttributeTypeReference =
733 TypeProxy.create(class211AttributeTypeIdentifier, class2111AttributeTypeReferenceState);
734 final IdentifierToken class2111AttributeIdentifier =
735 IdentifierToken.create("class21", Position.create("", 0 + 1, 0 + 1, 0));
736 final Attribute class2111Attribute =
737 Attribute.create(
738 "class21",
739 class2111AttributeTypeReference,
740 new Vector<AttributeModifier>(),
741 class2111AttributeIdentifier);
742 class2111Attributes.add(class2111Attribute);
743
744 final TokenStream output = FilteredTokenStream.create();
745 scanner.scan(input, output);
746 final Parser parser = Parser.create(output);
747
748 final Model result = parser.parse();
749 final ReturnValue v = new ReturnValue(result);
750 assertEquals(1, v.getFailResult().size());
751 assertEquals(1, v.getReferencer().getExceptions().size());
752 assertEquals(0, v.getOkResult().size());
753 }
754
755
756
757
758
759
760
761
762 @Test
763 public void testSimpleReferencingFullQualified() throws Exception {
764 final SimpleScannerInput input =
765 new SimpleScannerInput(
766 "group1 : group = [ class1 : class = {} abstract; class2 : class = group1>class1 + {};] ; ");
767 final TokenStream output = FilteredTokenStream.create();
768 final Scanner scanner = ModelDslScanner.create();
769 scanner.scan(input, output);
770 final Parser parser = Parser.create(output);
771 final Model model = parser.parse();
772
773 final ReturnValue v = new ReturnValue(model);
774
775 assertEquals(0, v.getFailResult().size());
776 assertEquals(1, v.getOkResult().size());
777 this.assertOperations.assertAllReferencesByType(model);
778 }
779
780
781
782
783
784
785
786
787 @Test
788 public void testSimpleReferencingUnqualified() throws Exception {
789 final SimpleScannerInput input =
790 new SimpleScannerInput(
791 "group1 : group = [ class1 : class = {} abstract; class2 : class = class1 + {};] ; ");
792 final TokenStream output = FilteredTokenStream.create();
793 final Scanner scanner = ModelDslScanner.create();
794 scanner.scan(input, output);
795 final Parser parser = Parser.create(output);
796 final Model model = parser.parse();
797
798 final ReturnValue v = new ReturnValue(model);
799
800 assertEquals(0, v.getFailResult().size());
801 assertEquals(1, v.getOkResult().size());
802 this.assertOperations.assertAllReferencesByType(model);
803 }
804
805
806
807
808
809
810
811
812 @Test
813 public void testSimpleReferencingBaseTypeAttribute() throws Exception {
814 final SimpleScannerInput input =
815 new SimpleScannerInput(
816 "group1 : group = [ class1 : class = {} abstract; class2 : class = {farbe : Integer;};] ; ");
817 final TokenStream output = FilteredTokenStream.create();
818 final Scanner scanner = ModelDslScanner.create();
819 scanner.scan(input, output);
820 final Parser parser = Parser.create(output);
821 final Model model = parser.parse();
822
823 final ReturnValue v = new ReturnValue(model);
824
825 assertEquals(0, v.getFailResult().size());
826 assertEquals(1, v.getOkResult().size());
827 this.assertOperations.assertAllReferencesByType(model);
828 }
829
830
831
832
833
834
835
836
837
838
839 @Test
840 public void testSameClassNameDifferentGroups() throws Exception {
841 final SimpleScannerInput input =
842 new SimpleScannerInput(
843 "group1:group=[class1:class={}abstract;group2:group=[class1:class={farben:String*;alter:Integer;};"
844 + "class2:class=class1+{x:class2;};class3:class=group1>class1+{};];];");
845 final TokenStream output = FilteredTokenStream.create();
846 final Scanner scanner = ModelDslScanner.create();
847 scanner.scan(input, output);
848 final Parser parser = Parser.create(output);
849 final Model model = parser.parse();
850
851 final ReturnValue v = new ReturnValue(model);
852
853 assertEquals(0, v.getFailResult().size());
854 assertEquals(1, v.getOkResult().size());
855 this.assertOperations.assertAllReferencesByType(model);
856 }
857
858
859
860
861
862
863
864
865 @Test
866 public void testNoClassException1() throws Exception {
867 final SimpleScannerInput input =
868 new SimpleScannerInput("group1:group=[class1:class={" + "attr1:Class2 prior;};];");
869 final TokenStream output = FilteredTokenStream.create();
870 final Scanner scanner = ModelDslScanner.create();
871 scanner.scan(input, output);
872 final Parser parser = Parser.create(output);
873 final Model model = parser.parse();
874 final ReturnValue v = new ReturnValue(model);
875
876 assertEquals(1, v.getFailResult().size());
877 assertEquals(0, v.getOkResult().size());
878 assertEquals(1, v.getReferencer().getExceptions().size());
879 }
880
881
882
883
884
885
886
887
888
889 @Test
890 public void testNoClassException2() throws Exception {
891 final SimpleScannerInput input =
892 new SimpleScannerInput("group1:group=[class1:class={" + "attr1:group2>Class2 prior;};"
893 + "class2:class={};];group2:group=[" + "class3:class={};];");
894 final TokenStream output = FilteredTokenStream.create();
895 final Scanner scanner = ModelDslScanner.create();
896 scanner.scan(input, output);
897 final Parser parser = Parser.create(output);
898 final Model model = parser.parse();
899
900 final ReturnValue v = new ReturnValue(model);
901
902 assertEquals(1, v.getFailResult().size());
903 assertEquals(0, v.getOkResult().size());
904 assertEquals(1, v.getReferencer().getExceptions().size());
905 }
906
907
908
909
910
911
912
913
914
915 @Test
916 public void testRelativeQualifiers() throws Exception {
917 final SimpleScannerInput input =
918 new SimpleScannerInput("group1:group=[class1:class={};"
919 + "group2:group=[class2:class={};group3:group=[class3:class={a:group2>class2;};];];];");
920 final TokenStream output = FilteredTokenStream.create();
921 final Scanner scanner = ModelDslScanner.create();
922 scanner.scan(input, output);
923 final Parser parser = Parser.create(output);
924 final Model model = parser.parse();
925
926 final ReturnValue v = new ReturnValue(model);
927
928 assertEquals(0, v.getFailResult().size());
929 assertEquals(1, v.getOkResult().size());
930 this.assertOperations.assertAllReferencesByType(model);
931 }
932
933
934
935
936
937
938
939
940 @Test
941 public void testClassAsAttribute() throws Exception {
942 final SimpleScannerInput input = new SimpleScannerInput("group1:group=[class1:class={a:class1;};];");
943 final TokenStream output = FilteredTokenStream.create();
944 final Scanner scanner = ModelDslScanner.create();
945 scanner.scan(input, output);
946 final Parser parser = Parser.create(output);
947 final Model model = parser.parse();
948
949 final ReturnValue v = new ReturnValue(model);
950
951 assertEquals(0, v.getFailResult().size());
952 assertEquals(1, v.getOkResult().size());
953 this.assertOperations.assertAllReferencesByType(model);
954 }
955
956
957
958
959
960
961
962
963 @Test
964 public void testUserString() throws Exception {
965 final SimpleScannerInput input =
966 new SimpleScannerInput("group1:group=[String:class={};" + "group2:group=[class1:class={a:String;};];];");
967 final TokenStream output = FilteredTokenStream.create();
968 final Scanner scanner = ModelDslScanner.create();
969 scanner.scan(input, output);
970 final Parser parser = Parser.create(output);
971 final Model model = parser.parse();
972 final ReturnValue v = new ReturnValue(model);
973
974 assertEquals(0, v.getFailResult().size());
975 assertEquals(1, v.getOkResult().size());
976 this.assertOperations.assertAllReferencesByType(model);
977 }
978
979
980
981
982
983
984
985
986 @Test
987 public void testFindNoClassBecauseLocal() throws Exception {
988 final SimpleScannerInput input =
989 new SimpleScannerInput("group1:group=[class1:class={};group1:group=["
990 + "class2:class=group1>class1+{};];];");
991 final TokenStream output = FilteredTokenStream.create();
992 final Scanner scanner = ModelDslScanner.create();
993 scanner.scan(input, output);
994 final Parser parser = Parser.create(output);
995 final Model model = parser.parse();
996
997 final ReturnValue v = new ReturnValue(model);
998
999 assertEquals(1, v.getFailResult().size());
1000 assertEquals(0, v.getOkResult().size());
1001
1002
1003 }
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014 @Test
1015 public void testDuplicateSumElimination() throws Exception {
1016 final SimpleScannerInput input =
1017 new SimpleScannerInput("outerGroup:group=[outerClass:class={"
1018 + "op:[[(sum:{String, Integer}) -> Integer]];};innerGroup:group=[innerClass:class={"
1019 + "duplicateSumOp:[[(sameSum:{Integer, String} ) -> Integer]];};];];");
1020 final TokenStream output = FilteredTokenStream.create();
1021 final Scanner scanner = ModelDslScanner.create();
1022 scanner.scan(input, output);
1023
1024
1025
1026
1027
1028
1029
1030 }
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041 @Test
1042 public void testDuplicateProductElimination() throws Exception {
1043 final SimpleScannerInput input =
1044 new SimpleScannerInput("outerGroup:group=[outerClass:class={"
1045 + "op:[[(param:Integer) -> (x:Integer, y:Integer)]];};innerGroup:group=["
1046 + "innerClass:class={duplicateSumOp:[[(param:Integer) -> (y:Integer, x:Integer)]];};];];");
1047 final TokenStream output = FilteredTokenStream.create();
1048 final Scanner scanner = ModelDslScanner.create();
1049 scanner.scan(input, output);
1050
1051
1052
1053
1054
1055
1056 }
1057
1058
1059
1060
1061
1062
1063
1064
1065 @Test
1066 public void testSimpleAnything1() throws Exception {
1067
1068 final IdentifierToken class1Identifier = IdentifierToken.create("class1", Position.create("", 1, 15, 14));
1069 final IdentifierToken group1Identifier = IdentifierToken.create("group1", Position.create("", 1, 15, 14));
1070
1071 final SimpleScannerInput input = new SimpleScannerInput("group1:group=[class1:class={attribute:Anything;};];");
1072
1073 final TokenStream output = FilteredTokenStream.create();
1074 final Scanner scanner = ModelDslScanner.create();
1075 scanner.scan(input, output);
1076 final Parser parser = Parser.create(output);
1077 final Model model = parser.parse();
1078 final ReturnValue v = new ReturnValue(model);
1079 assertEquals(1, v.getOkResult().size());
1080 assertEquals(0, v.getFailResult().size());
1081 this.assertOperations.assertAllReferencesByType(model);
1082
1083 final Vector<Attribute> attributes = new Vector<>();
1084
1085 final QualifiedName name =
1086 QualifiedName
1087 .create(UnqualifiedName.create(group1Identifier), UnqualifiedName.create(class1Identifier));
1088
1089 final ClassType clazz =
1090 ClassType.create(
1091 name,
1092 new Vector<ClassModifier>(),
1093 attributes,
1094 new Vector<Type>(),
1095 new Vector<Operation>(),
1096 new Vector<Constructor>(),
1097 DummyToken.getInstance(),
1098 false,
1099 new Vector<ClassType>());
1100 ByReferenceState classState = ByReferenceState.create(clazz, clazz.getTypeName());
1101 TypeProxy proxy = TypeProxy.create(class1Identifier, classState);
1102 final SumType sum = SumType.create(DummyToken.getInstance());
1103 sum.add(proxy);
1104
1105 final BaseType string = model.getString();
1106 classState = ByReferenceState.create(string, string.getTypeName());
1107 proxy = TypeProxy.create(DummyToken.getInstance(), classState);
1108 sum.add(proxy);
1109
1110 final BaseType integer = model.getInteger();
1111 classState = ByReferenceState.create(integer, integer.getTypeName());
1112 proxy = TypeProxy.create(DummyToken.getInstance(), classState);
1113 sum.add(proxy);
1114
1115 final Group g = model.getGroups().iterator().next();
1116 final ClassType c = (ClassType) g.getGroupElements().iterator().next();
1117 final Attribute a = c.getAttributes().iterator().next();
1118 final TypeProxy t = (TypeProxy) a.getAttrType();
1119 final ByReferenceState state = (ByReferenceState) t.getState();
1120
1121
1122
1123
1124 }
1125
1126
1127
1128
1129
1130
1131
1132
1133 @Test
1134 public void testSimpleAnything3() throws Exception {
1135
1136 final IdentifierToken class1Identifier = IdentifierToken.create("class1", Position.create("", 1, 15, 14));
1137 final IdentifierToken group1Identifier = IdentifierToken.create("group1", Position.create("", 1, 15, 14));
1138 final IdentifierToken anythingIdentifier = IdentifierToken.create("Anything", DummyToken.getDummyPosition());
1139 final IdentifierToken irgendwasIdentifier = IdentifierToken.create("irgendwas", DummyToken.getDummyPosition());
1140
1141 final SimpleScannerInput input =
1142 new SimpleScannerInput("group1:group=[" + "class1:class={attribute:(irgendwas:Anything);};];");
1143
1144 final TokenStream output = FilteredTokenStream.create();
1145 final Scanner scanner = ModelDslScanner.create();
1146 scanner.scan(input, output);
1147 final Parser parser = Parser.create(output);
1148 final Model model = parser.parse();
1149 final ReturnValue v = new ReturnValue(model);
1150 assertEquals(1, v.getOkResult().size());
1151 assertEquals(0, v.getFailResult().size());
1152 this.assertOperations.assertAllReferencesByType(model);
1153
1154 final Vector<Attribute> attributes = new Vector<>();
1155
1156 final QualifiedName name =
1157 QualifiedName
1158 .create(UnqualifiedName.create(group1Identifier), UnqualifiedName.create(class1Identifier));
1159
1160 final SumType sum = SumType.create(DummyToken.getInstance());
1161 final ByReferenceState sumState = ByReferenceState.create(sum, UnqualifiedName.create(anythingIdentifier));
1162 final TypeProxy sumProxy = TypeProxy.create(anythingIdentifier, sumState);
1163
1164 final ProductElementType element = ProductElementType.create("irgendwas", sumProxy, irgendwasIdentifier);
1165 final ProductType product = ProductType.create(DummyToken.getInstance());
1166 product.addElement(element);
1167
1168 sum.add(product);
1169
1170 final ClassType clazz =
1171 ClassType.create(
1172 name,
1173 new Vector<ClassModifier>(),
1174 attributes,
1175 new Vector<Type>(),
1176 new Vector<Operation>(),
1177 new Vector<Constructor>(),
1178 DummyToken.getInstance(),
1179 false,
1180 new Vector<ClassType>());
1181 ByReferenceState classState = ByReferenceState.create(clazz, clazz.getTypeName());
1182 TypeProxy proxy = TypeProxy.create(class1Identifier, classState);
1183
1184 sum.add(proxy);
1185
1186 final BaseType string = model.getString();
1187 classState = ByReferenceState.create(string, string.getTypeName());
1188 proxy = TypeProxy.create(DummyToken.getInstance(), classState);
1189 sum.add(proxy);
1190
1191 final BaseType integer = model.getInteger();
1192 classState = ByReferenceState.create(integer, integer.getTypeName());
1193 proxy = TypeProxy.create(DummyToken.getInstance(), classState);
1194 sum.add(proxy);
1195
1196 final Group g = model.getGroups().iterator().next();
1197 final ClassType c = (ClassType) g.getGroupElements().iterator().next();
1198 final Attribute a = c.getAttributes().iterator().next();
1199 final ProductType p = (ProductType) a.getAttrType();
1200 final TypeProxy s = (TypeProxy) p.getElements().get(0).getType();
1201 final ByReferenceState r = (ByReferenceState) s.getState();
1202
1203
1204
1205 }
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215 @Test
1216 public void testSimpleAnything2() throws Exception {
1217
1218 final IdentifierToken class1Identifier = IdentifierToken.create("class1", Position.createDummyPosition());
1219 final IdentifierToken class2Identifier = IdentifierToken.create("class2", Position.createDummyPosition());
1220 final IdentifierToken group1Identifier = IdentifierToken.create("group1", Position.createDummyPosition());
1221 final IdentifierToken anythingIdentifier = IdentifierToken.create("Anything", DummyToken.getDummyPosition());
1222
1223 final SimpleScannerInput input =
1224 new SimpleScannerInput("group1:group=["
1225 + "class1:class={operation:[[(param1:Anything) -> Anything]];};"
1226 + "class2:class={attribute:Anything;};];");
1227
1228 final TokenStream output = FilteredTokenStream.create();
1229 final Scanner scanner = ModelDslScanner.create();
1230 scanner.scan(input, output);
1231 final Parser parser = Parser.create(output);
1232 final Model model = parser.parse();
1233 final ReturnValue v = new ReturnValue(model);
1234 assertEquals(1, v.getOkResult().size());
1235 assertEquals(0, v.getFailResult().size());
1236 this.assertOperations.assertAllReferencesByType(model);
1237
1238 final Vector<Attribute> attributes = new Vector<>();
1239 final Vector<Operation> operations = new Vector<>();
1240
1241 final QualifiedName class1Name =
1242 QualifiedName
1243 .create(UnqualifiedName.create(group1Identifier), UnqualifiedName.create(class1Identifier));
1244 final QualifiedName class2Name =
1245 QualifiedName
1246 .create(UnqualifiedName.create(group1Identifier), UnqualifiedName.create(class2Identifier));
1247
1248 final ClassType clazz1 =
1249 ClassType.create(
1250 class1Name,
1251 new Vector<ClassModifier>(),
1252 new Vector<Attribute>(),
1253 new Vector<Type>(),
1254 operations,
1255 new Vector<Constructor>(),
1256 DummyToken.getInstance(),
1257 false,
1258 new Vector<ClassType>());
1259 final ByReferenceState class1State = ByReferenceState.create(clazz1, clazz1.getTypeName());
1260 final TypeProxy proxy1 = TypeProxy.create(class1Identifier, class1State);
1261
1262 final ClassType clazz2 =
1263 ClassType.create(
1264 class2Name,
1265 new Vector<ClassModifier>(),
1266 attributes,
1267 new Vector<Type>(),
1268 new Vector<Operation>(),
1269 new Vector<Constructor>(),
1270 DummyToken.getInstance(),
1271 false,
1272 new Vector<ClassType>());
1273 final ByReferenceState class2State = ByReferenceState.create(clazz2, clazz2.getTypeName());
1274 final TypeProxy proxy2 = TypeProxy.create(class1Identifier, class2State);
1275 final SumType sum = SumType.create(DummyToken.getInstance());
1276 final ByReferenceState stateSum = ByReferenceState.create(sum, UnqualifiedName.create(anythingIdentifier));
1277 final TypeProxy typeProxySum = TypeProxy.create(DummyToken.getInstance(), stateSum);
1278
1279 final ProductType product = ProductType.create(DummyToken.getInstance());
1280 final ProductElementType element = ProductElementType.create("param1", typeProxySum, DummyToken.getInstance());
1281 product.addElement(element);
1282
1283 sum.add(product);
1284
1285 sum.add(proxy1);
1286 sum.add(proxy2);
1287
1288 final BaseType string = model.getString();
1289 ByReferenceState classState = ByReferenceState.create(string, string.getTypeName());
1290 TypeProxy proxy = TypeProxy.create(DummyToken.getInstance(), classState);
1291 sum.add(proxy);
1292
1293 final BaseType integer = model.getInteger();
1294 classState = ByReferenceState.create(integer, integer.getTypeName());
1295 proxy = TypeProxy.create(DummyToken.getInstance(), classState);
1296 sum.add(proxy);
1297
1298 final Group g = model.getGroups().iterator().next();
1299 final Iterator<GroupElement> classIterator = g.getGroupElements().iterator();
1300 final ClassType c1 = (ClassType) classIterator.next();
1301 final ClassType c2 = (ClassType) classIterator.next();
1302 final Operation o = c1.getOperations().iterator().next();
1303
1304 final TypeProxy typeProxyParam = (TypeProxy) o.getParams().getElements().get(0).getType();
1305 final ByReferenceState stateParam = (ByReferenceState) typeProxyParam.getState();
1306
1307
1308
1309
1310 final TypeProxy typeProxyReturnValue = (TypeProxy) o.getReturnType();
1311 final ByReferenceState stateReturnValue = (ByReferenceState) typeProxyReturnValue.getState();
1312
1313
1314
1315
1316 final Attribute a = c2.getAttributes().iterator().next();
1317 final TypeProxy t = (TypeProxy) a.getAttrType();
1318 final ByReferenceState state = (ByReferenceState) t.getState();
1319
1320
1321
1322 }
1323 }
1324
1325
1326
1327
1328
1329 class ReturnValue {
1330
1331
1332
1333
1334 private final Collection<OKTaskResult> okResult;
1335
1336
1337
1338
1339 private final Collection<ExceptionalTaskResult> failResult;
1340
1341
1342
1343
1344 private final Referencer referencer;
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356 ReturnValue(final Model model) throws InterruptedException, ExecutionException {
1357
1358 final TaskExecutor taskManager = TaskExecutorFixed.create();
1359 this.referencer = Referencer.create(model, taskManager);
1360 taskManager.startAllKnownTasks();
1361 this.okResult = new ArrayList<>();
1362 this.failResult = new ArrayList<>();
1363 final Collection<TaskResult> results = taskManager.getResultsAndShutdown();
1364
1365 for (final TaskResult current : results) {
1366 current.accept(new TaskResultVisitor() {
1367
1368 @Override
1369 public void handleOkTaskResult(final OKTaskResult result) {
1370 ReturnValue.this.okResult.add(result);
1371 }
1372
1373 @Override
1374 public void handleExceptionalTaskResult(final ExceptionalTaskResult result) {
1375 ReturnValue.this.failResult.add(result);
1376 }
1377 });
1378 }
1379 }
1380
1381
1382
1383
1384
1385
1386 public Collection<OKTaskResult> getOkResult() {
1387 return this.okResult;
1388 }
1389
1390
1391
1392
1393
1394
1395 public Collection<ExceptionalTaskResult> getFailResult() {
1396 return this.failResult;
1397 }
1398
1399
1400
1401
1402
1403
1404 public Referencer getReferencer() {
1405 return this.referencer;
1406 }
1407 }