Skip to content

Method: handle(Generic)

1: package de.fhdw.wtf.generator.java.generatorModel;
2:
3: import java.util.ArrayList;
4: import java.util.Collection;
5: import java.util.HashMap;
6: import java.util.Iterator;
7: import java.util.Map;
8: import java.util.Vector;
9:
10: import de.fhdw.wtf.common.ast.type.BaseType;
11: import de.fhdw.wtf.common.ast.type.ClassType;
12: import de.fhdw.wtf.common.ast.type.ExceptionClassType;
13: import de.fhdw.wtf.common.ast.type.Type;
14: import de.fhdw.wtf.common.exception.walker.TaskException;
15: import de.fhdw.wtf.facade.PackageConstants;
16: import de.fhdw.wtf.generator.java.visitor.GenPrimitiveTypeVisitor;
17: import de.fhdw.wtf.generator.java.visitor.GenPrimitiveTypeVisitorReturn;
18: import de.fhdw.wtf.generator.java.visitor.GenTypeVisitor;
19: import de.fhdw.wtf.generator.java.visitor.GenTypeVisitorReturn;
20: import de.fhdw.wtf.generator.transformer.exception.GenTypeNotReferencedException;
21: import de.fhdw.wtf.generator.transformer.transformers.classTransformer.UtilTransformer;
22: import de.fhdw.wtf.generator.transformer.util.Tuple;
23:
24: /**
25: * A GeneratorModel is used to represent a given Model from Core as a Java-Model, that can be generated and that
26: * provides all features of WTF with the generated sources.
27: */
28: public class GeneratorModel {
29:         
30:         /**
31:          * A collection of all GenClasses that additionally to the AST-Model needs to be generated. Those "classes" are for
32:          * example the AppStarter, Visitors, Factories, the FinderAspect and additional classes to realize symmetric
33:          * relations.
34:          */
35:         private final Vector<GenClass> nonASTClasses;
36:         /**
37:          * TODO
38:          */
39:         private final Map<GenUserClass, Vector<ClassType>> symmetricManagers;
40:         /**
41:          * A mapping from AST-Types to GenPrimitiveClasses. GenPrimitiveClasses will not be generated as they already exist
42:          * in de.wtf.context.model.
43:          */
44:         private final Map<Type, GenPrimitiveClass> baseClassMapping;
45:         /**
46:          * A mapping from AST-Types to GenClasses. GenClasses can be Interfaces or Classes that will be generated.
47:          */
48:         private final Map<Type, GenClass> classMapping;
49:         /**
50:          * A mapping that contains all AST-Types to a Tuple of GenType and a collection of ExceptionClassType that are part
51:          * of the AST-model.
52:          */
53:         private final Map<Type, Tuple<GenType, Collection<ExceptionClassType>>> typeMapping;
54:         /**
55:          * A mapping from Gen-Types to GenAspects. GenAspects represent AspectJ-files that will be generated and shall
56:          * expand the GenClass provided as key. A GenClass represents an AST-Type.
57:          */
58:         private final Map<GenClass, GenAspect> aspectJMapping;
59:         
60:         /**
61:          * Suffix for aspect-name.
62:          */
63:         private static final String ASPECT_SUFFIX = "Aspect";
64:         /**
65:          * Suffix for aspect-name of an aspect for the expansion of an Ast-BaseType.
66:          */
67:         private static final String BASETYPE_EXPANSION_ASPECT_SUFFIX = "Expansion" + ASPECT_SUFFIX;
68:         /**
69:          * Standard comment for an aspect.
70:          */
71:         private static final String ASPECT_COMMENT = "This is an aspect.";
72:         
73:         /**
74:          * Adds a class to the classes that are not classes of the AST.
75:          *
76:          * @param c
77:          * The GenClass to add
78:          */
79:         public void addNonAstClass(final GenClass c) {
80:                 this.nonASTClasses.add(c);
81:         }
82:         
83:         /**
84:          * Adds a symmetric manager (and one of the corresponding classes) to the inner list.
85:          *
86:          * @param manager
87:          * The SymmetricRelationAccess-Manager.
88:          * @param userClass
89:          * The class.
90:          */
91:         public void addSymmetricManager(final GenUserClass manager, final ClassType userClass) {
92:                 if (!this.symmetricManagers.containsKey(manager)) {
93:                         this.symmetricManagers.put(manager, new Vector<ClassType>());
94:                 }
95:                 this.symmetricManagers.get(manager).add(userClass);
96:         }
97:         
98:         /**
99:          * Gets the SymmetricRelationManager that handles the symmetric relation between the two classes. It returns "null"
100:          * if the manager is not found.
101:          *
102:          * @param clss1
103:          * First Class.
104:          * @param clss2
105:          * Second Class.
106:          * @return The singleton manager.
107:          */
108:         public GenUserClass getSymmetricManager(final ClassType clss1, final ClassType clss2) {
109:                 final Iterator<GenUserClass> i = this.symmetricManagers.keySet().iterator();
110:                 while (i.hasNext()) {
111:                         final GenUserClass singleton = i.next();
112:                         if (!this.symmetricManagers.get(singleton).contains(clss1)) {
113:                                 continue;
114:                         }
115:                         if (!this.symmetricManagers.get(singleton).contains(clss2)) {
116:                                 continue;
117:                         }
118:                         return singleton;
119:                 }
120:                 return null;
121:         }
122:         
123:         /**
124:          * Set the aspect that shall be generated for <code>genClass</code>.
125:          *
126:          * @param genClass
127:          * The GenClass to set the aspect for
128:          * @param aspect
129:          * The aspect to set
130:          */
131:         public void addAspect(final GenClass genClass, final GenAspect aspect) {
132:                 this.getAspectJMapping().put(genClass, aspect);
133:         }
134:         
135:         /**
136:          * Returns all classes that will be generated. These classes can represent an AST-Type or can be classes like the
137:          * AppStarter, Visitors, Factories, the FinderAspect or additional classes to realize symmetric relations.
138:          *
139:          * @return Returns a collection of GenClass.
140:          */
141:         public Collection<GenClass> getClasses() {
142:                 final Vector<GenClass> res = new Vector<>();
143:                 res.addAll(this.classMapping.values());
144:                 res.addAll(this.nonASTClasses);
145:                 res.addAll(this.aspectJMapping.values());
146:                 return res;
147:         }
148:         
149:         /**
150:          * Instantiates a new GeneratorModel. A GeneratorModel is used to represent a given Model from Core as a Java-Model,
151:          * that can be generated and that provides all features of WTF with the generated sources.
152:          */
153:         public GeneratorModel() {
154:                 this.baseClassMapping = new HashMap<>();
155:                 this.classMapping = new HashMap<>();
156:                 this.typeMapping = new HashMap<>();
157:                 this.nonASTClasses = new Vector<>();
158:                 this.aspectJMapping = new HashMap<>();
159:                 this.symmetricManagers = new HashMap<>();
160:         }
161:         
162:         /**
163:          * Creates a new GeneratorModel. A GeneratorModel is used to represent a given Model from Core as a Java-Model, that
164:          * can be generated and that provides all features of WTF with the generated sources.
165:          *
166:          * @return Returns the created GeneratorModel
167:          */
168:         public static GeneratorModel create() {
169:                 return new GeneratorModel();
170:         }
171:         
172:         /**
173:          * Adds map-entries from the given AST-type to a given GenType. The GenType is added to the type-mapping in every
174:          * case. Additionally also a GenClass will be added to the class-mapping.
175:          *
176:          * @param type
177:          * The AST-Type to add a GenType- and if possible a GenClass-representation for.
178:          * @param genTypes
179:          * A Tuple with the GenType that represents the AST-type as GenType or even as GenClass and a list of
180:          * GenExceptions defined in the AST-type.
181:          */
182:         public void addToMapping(final Type type, final Tuple<GenType, Collection<ExceptionClassType>> genTypes) {
183:                 final Type typeProxyFreePrototype = UtilTransformer.getTypeProxyFreePrototype(type);
184:                 
185:                 // TODO mapped classes shall have an unique name
186:                 // if(this.getTypeMapping().containsKey(wtfType)){
187:                 // throw new TypeNameAlreadyTakenException(typeName);
188:                 // }
189:                 
190:                 this.typeMapping.put(typeProxyFreePrototype, genTypes);
191:                 
192:                 genTypes.getA().accept(new GenTypeVisitor() {
193:                         @Override
194:                         public void handle(final GenPrimitiveType primitiveType) {
195:                                 primitiveType.accept(new AddToMappingPrimitiveTypeVisitor(typeProxyFreePrototype));
196:                         }
197:                         
198:                         @Override
199:                         public void handle(final GenCollectionType collectionType) {
200:                                 // add to GeneratorModel.classMapping not possible
201:                         }
202:                         
203:                         @Override
204:                         public void handle(final GenClass cla) {
205:                                 GeneratorModel.this.getClassMapping().put(typeProxyFreePrototype, cla);
206:                         }
207:                         
208:                         @Override
209:                         public void handle(final GenMapType mapType) {
210:                                 // add to GeneratorModel.classMapping not possible
211:                         }
212:                         
213:                         @Override
214:                         public void handle(final Generic generic) {
215:                                 // add to GeneratorModel.classMapping not possible
216:                         }
217:                         
218:                         @Override
219:                         public void handle(final GenJavaUtilCollection javaUtilCollection) {
220:                                 // add to GeneratorModel.classMapping not possible
221:                         }
222:                         
223:                         @Override
224:                         public void handle(final GenImportType importType) {
225:                                 // add to GeneratorModel.classMapping not possible
226:                         }
227:                         
228:                         @Override
229:                         public void handle(final GenDummyType dummy) {
230:                                 // add to GeneratorModel.classMapping not possible
231:                         }
232:                 });
233:         }
234:         
235:         /**
236:          * The private class to handle primitive Types while adding them to the mapping.
237:          */
238:         private final class AddToMappingPrimitiveTypeVisitor implements GenPrimitiveTypeVisitor {
239:                 /**
240:                  * The AST-Type to add a GenType- and if possible a GenClass-representation for.
241:                  */
242:                 private final Type wtfType;
243:                 
244:                 /**
245:                  * Instantietes a new AddToMappingPrimitiveTypeVisitor.
246:                  *
247:                  * @param wtfType
248:                  * The AST-Type to add a GenType- and if possible a GenClass-representation for.
249:                  */
250:                 private AddToMappingPrimitiveTypeVisitor(final Type wtfType) {
251:                         this.wtfType = wtfType;
252:                 }
253:                 
254:                 @Override
255:                 public void handle(final GenVoidType voidType) {
256:                         // nothing to do
257:                 }
258:                 
259:                 @Override
260:                 public void handle(final GenStringType stringType) {
261:                         GeneratorModel.this.getBaseClassMapping().put(this.wtfType, GenStringType.getCorrespondingClass());
262:                 }
263:                 
264:                 @Override
265:                 public void handle(final GenIntegerType integerType) {
266:                         GeneratorModel.this.getBaseClassMapping().put(this.wtfType, GenIntegerType.getCorrespondingClass());
267:                 }
268:         }
269:         
270:         /**
271:          * Returns the GenType for a AST-Type.
272:          *
273:          * @param type
274:          * The type to get the GenType for.
275:          * @throws GenTypeNotReferencedException
276:          * if no GenType is set for the given type
277:          * @return GenType
278:          */
279:         public GenType getGenTypeForType(final Type type) throws GenTypeNotReferencedException {
280:                 final Type protoType = UtilTransformer.getTypeProxyFreePrototype(type);
281:                 final Tuple<GenType, Collection<ExceptionClassType>> result = this.typeMapping.get(protoType);
282:                 if (result == null || result.getA() == null) {
283:                         throw new GenTypeNotReferencedException();
284:                 }
285:                 return result.getA();
286:         }
287:         
288:         /**
289:          * Returns the collection of GenExceptions for a AST-Type.
290:          *
291:          * @param type
292:          * The type to get the collection of exceptions for.
293:          * @throws TaskException
294:          * GenExceptionsNotReferencedException -> if no list of GenExceptions is set for the given type.
295:          * TaskException -> if the underlying type of the thrownType is not a exceptionClassType.
296:          *
297:          * @return Collection<GenExceptions>
298:          */
299:         public Collection<GenException> getGenExceptionsForType(final Type type) throws TaskException {
300:                 final Type protoType = UtilTransformer.getTypeProxyFreePrototype(type);
301:                 final Collection<GenException> result = new ArrayList<>();
302:                 final Collection<ExceptionClassType> exceptions = this.typeMapping.get(protoType).getB();
303:                 final Iterator<ExceptionClassType> iterator = exceptions.iterator();
304:                 while (iterator.hasNext()) {
305:                         final ExceptionClassType current = iterator.next();
306:                         final Tuple<GenType, Collection<ExceptionClassType>> types = this.typeMapping.get(current.getPrototype());
307:                         if (types.getA() instanceof GenException) {
308:                                 result.add((GenException) types.getA());
309:                         }
310:                 }
311:                 return result;
312:         }
313:         
314:         /**
315:          * Returns the GenClass that represents the given Type if possible. May returns null.
316:          *
317:          * @param type
318:          * The AST-Type to return the GenClass for.
319:          * @return GenClass that represents Type.
320:          */
321:         public GenClass getJavaClassForWTFClass(final Type type) {
322:                 final Type prototype = UtilTransformer.getTypeProxyFreePrototype(type);
323:                 final GenClass result = this.classMapping.get(prototype);
324:                 if (result == null) {
325:                         System.out.println("Impl class not found");
326:                 }
327:                 return result;
328:         }
329:         
330:         /**
331:          * Creates a GenClassClass for a Type. Attributes, operations, constructors, implementations and extend will be
332:          * initialized in a standard way.
333:          *
334:          * @param name
335:          * Name of the class to create
336:          * @param modifiers
337:          * Modifiers for the class
338:          * @param type
339:          * The corresponding Ast-Type for the class
340:          * @param comment
341:          * The comment to describe the class
342:          * @param packag
343:          * The package of the class
344:          * @param nonGeneratedPart
345:          * The additional part to the part that will be generated
346:          * @return GenUserClass that represents a ClassType
347:          */
348:         public GenUserClass createClass(final String name,
349:                         final Collection<GenClassModifier> modifiers,
350:                         final Type type,
351:                         final GenComment comment,
352:                         final GenPackage packag,
353:                         final String nonGeneratedPart) {
354:                 final Collection<GenJavaAttribute> attributes = new Vector<>();
355:                 final Collection<GenJavaOperation> operations = new Vector<>();
356:                 final Collection<GenJavaOperation> constructors = new Vector<>();
357:                 final Collection<GenInterfaceClass> implement = new Vector<>();
358:                 final GenClassClass extend = GenAnyType.getInstance();
359:                 return this.createClassInternal(
360:                                 name,
361:                                 attributes,
362:                                 operations,
363:                                 modifiers,
364:                                 constructors,
365:                                 implement,
366:                                 extend,
367:                                 type,
368:                                 comment,
369:                                 packag,
370:                                 nonGeneratedPart);
371:         }
372:         
373:         /**
374:          * Creates a GenClassClass for a Type with the given parameters.
375:          *
376:          * @param name
377:          * The name of the class and the java-file to generate.
378:          * @param attributes
379:          * The attribute the class has.
380:          * @param operations
381:          * The operations the class has.
382:          * @param modifiers
383:          * The class-modifiers for this class. For example "public".
384:          * @param constructors
385:          * The constructor-operations for this class.
386:          * @param implement
387:          * The interfaces the class implements.
388:          * @param extend
389:          * The class the class extends.
390:          * @param type
391:          * The AST-Type the class represents.
392:          * @param comment
393:          * The comment that describes this class.
394:          * @param packag
395:          * The package the class will be generated in.
396:          * @param nonGeneratedPart
397:          * Additional lines of code.
398:          * @return Returns a new GenUserClass with the given parameters.
399:          */
400:         private GenUserClass createClassInternal(final String name,
401:                         final Collection<GenJavaAttribute> attributes,
402:                         final Collection<GenJavaOperation> operations,
403:                         final Collection<GenClassModifier> modifiers,
404:                         final Collection<GenJavaOperation> constructors,
405:                         final Collection<GenInterfaceClass> implement,
406:                         final GenClassClass extend,
407:                         final Type type,
408:                         final GenComment comment,
409:                         final GenPackage packag,
410:                         final String nonGeneratedPart) {
411:                 final GenUserClass c =
412:                                 GenUserClass.create(
413:                                                 name,
414:                                                 operations,
415:                                                 implement,
416:                                                 attributes,
417:                                                 modifiers,
418:                                                 constructors,
419:                                                 extend,
420:                                                 packag,
421:                                                 comment,
422:                                                 nonGeneratedPart);
423:                 return c;
424:         }
425:         
426:         /**
427:          * Creates a GenInterfaceClass for a ClassType. Operations and implementations will be initialized in a standard
428:          * way.
429:          *
430:          * @param name
431:          * Name of the interface to create
432:          * @param type
433:          * The corresponding AST-Type for the class
434:          * @param comment
435:          * The comment to describe the class
436:          * @param packag
437:          * The package of the class
438:          * @param nonGeneratedPart
439:          * The additional part to the part that will be generated
440:          * @return GenInterfaceClass that represents a ClassType
441:          */
442:         public GenInterfaceClass createInterface(final String name,
443:                         final Type type,
444:                         final GenComment comment,
445:                         final GenPackage packag,
446:                         final String nonGeneratedPart) {
447:                 final Vector<GenJavaOperation> operations = new Vector<>();
448:                 final Vector<GenInterfaceClass> implement = new Vector<>();
449:                 return this.createInterfaceInternal(name, operations, implement, type, comment, packag, nonGeneratedPart);
450:         }
451:         
452:         /**
453:          * Creates a GenInterfaceClass with for a Type with the given parameters.
454:          *
455:          * @param name
456:          * The name of the interface and the java-file to generate.
457:          * @param operations
458:          * The operations the interface has.
459:          * @param implement
460:          * The interfaces the interface implements.
461:          * @param type
462:          * The AST-Type the interface represents.
463:          * @param comment
464:          * The comment that describes this interface.
465:          * @param packag
466:          * The package the interface will be generated in.
467:          * @param nonGeneratedPart
468:          * Additional lines of code.
469:          * @return Returns a new GenInterfaceClass with the given parameters.
470:          */
471:         private GenInterfaceClass createInterfaceInternal(final String name,
472:                         final Vector<GenJavaOperation> operations,
473:                         final Vector<GenInterfaceClass> implement,
474:                         final Type type,
475:                         final GenComment comment,
476:                         final GenPackage packag,
477:                         final String nonGeneratedPart) {
478:                 final GenInterfaceClass c =
479:                                 GenSimpleInterfaceClass.create(name, operations, implement, packag, comment, nonGeneratedPart);
480:                 return c;
481:         }
482:         
483:         /**
484:          * Creates a GenInterfaceWithClassImplClass for a ClassType. Operations and implementations will be initialized in a
485:          * standard way. Also the contained "Impl"-class will be initialized in a standard way.
486:          *
487:          * @param name
488:          * Name of the class to create
489:          * @param type
490:          * The corresponding AST-Type for the class
491:          * @param classModifiers
492:          * The class-modifiers for the inner class. For example "public".
493:          * @param comment
494:          * The comment to describe the class
495:          * @param packag
496:          * The package of the class
497:          * @param nonGeneratedPart
498:          * The additional part to the part that will be generated
499:          * @return GenInterfaceClass that represents a ClassType
500:          */
501:         public GenInterfaceWithClassImplClass createInterfaceWithImplClass(final String name,
502:                         final ClassType type,
503:                         final Collection<GenClassModifier> classModifiers,
504:                         final GenComment comment,
505:                         final GenPackage packag,
506:                         final String nonGeneratedPart) {
507:                 final Vector<GenJavaOperation> operations = new Vector<>();
508:                 final Vector<GenInterfaceClass> implement = new Vector<>();
509:                 
510:                 final Collection<GenClassModifier> modifiers = new Vector<>();
511:                 final Iterator<GenClassModifier> i = classModifiers.iterator();
512:                 while (i.hasNext()) {
513:                         final GenClassModifier current = i.next();
514:                         if (current != GenClassModifier.ABSTRACT) {
515:                                 modifiers.add(current);
516:                         }
517:                         
518:                 }
519:                 final GenUserClass classRepresentation =
520:                                 this.createClass(name, modifiers, type, comment, packag, nonGeneratedPart);
521:                 return this.createInterfaceWithImplClassInternal(
522:                                 name,
523:                                 operations,
524:                                 implement,
525:                                 type,
526:                                 comment,
527:                                 packag,
528:                                 nonGeneratedPart,
529:                                 classRepresentation);
530:         }
531:         
532:         /**
533:          * Creates a GenInterfaceWithClassImplClass with for a Type with the given parameters.
534:          *
535:          * @param name
536:          * The name of the interface and the java-file to generate.
537:          * @param operations
538:          * The operations the interface has.
539:          * @param implement
540:          * The interfaces the interface implements.
541:          * @param type
542:          * The AST-Type the interface represents.
543:          * @param comment
544:          * The comment that describes this interface.
545:          * @param packag
546:          * The package the interface will be generated in.
547:          * @param nonGeneratedPart
548:          * Additional lines of code.
549:          * @param classRepresentation
550:          * The "Impl"-class inside the interface that represents the AST-type.
551:          * @return Returns a new GenInterfaceClass with the given parameters.
552:          */
553:         private GenInterfaceWithClassImplClass createInterfaceWithImplClassInternal(final String name,
554:                         final Vector<GenJavaOperation> operations,
555:                         final Vector<GenInterfaceClass> implement,
556:                         final Type type,
557:                         final GenComment comment,
558:                         final GenPackage packag,
559:                         final String nonGeneratedPart,
560:                         final GenUserClass classRepresentation) {
561:                 final GenInterfaceWithClassImplClass i =
562:                                 GenInterfaceWithClassImplClass.create(
563:                                                 name,
564:                                                 operations,
565:                                                 implement,
566:                                                 packag,
567:                                                 comment,
568:                                                 nonGeneratedPart,
569:                                                 classRepresentation);
570:                 return i;
571:         }
572:         
573:         /**
574:          * Creates a GenException for a ClassType that is an exception. Attributes, operations, modifiers, constructors,
575:          * implementations and extend will be initialized in a standard way.
576:          *
577:          * @param name
578:          * Name of the exception to create
579:          * @param type
580:          * The corresponding AST-Type for the exception
581:          * @param comment
582:          * The comment to describe the exception
583:          * @param packag
584:          * The package of the exception
585:          * @param nonGeneratedPart
586:          * The additional part to the part that will be generated
587:          * @return GenException that represents a ClassType
588:          */
589:         public GenException createException(final String name,
590:                         final ClassType type,
591:                         final GenComment comment,
592:                         final GenPackage packag,
593:                         final String nonGeneratedPart) {
594:                 final Collection<GenJavaAttribute> attributes = new Vector<>();
595:                 final Collection<GenJavaOperation> operations = new Vector<>();
596:                 final Collection<GenClassModifier> modifiers = new Vector<>();
597:                 final Collection<GenJavaOperation> constructors = new Vector<>();
598:                 final Collection<GenInterfaceClass> implement = new Vector<>();
599:                 return this.createExceptionInternal(
600:                                 name,
601:                                 attributes,
602:                                 operations,
603:                                 modifiers,
604:                                 constructors,
605:                                 implement,
606:                                 type,
607:                                 comment,
608:                                 packag,
609:                                 nonGeneratedPart);
610:         }
611:         
612:         /**
613:          * Creates a GenException for a ClassType with the given parameters.
614:          *
615:          * @param name
616:          * The name of the exception and the java-file to generate.
617:          * @param attributes
618:          * The attribute the exception has.
619:          * @param operations
620:          * The operations the exception has.
621:          * @param modifiers
622:          * The class-modifiers for this exception. For example "public".
623:          * @param constructors
624:          * The constructor-operations for this exception.
625:          * @param implement
626:          * The interfaces the exception implements.
627:          * @param type
628:          * The AST-ClassType the exception represents.
629:          * @param comment
630:          * The comment that describes this exception.
631:          * @param packag
632:          * The package the exception will be generated in.
633:          * @param nonGeneratedPart
634:          * Additional lines of code.
635:          * @return Returns a new GenException with the given parameters.
636:          */
637:         private GenException createExceptionInternal(final String name,
638:                         final Collection<GenJavaAttribute> attributes,
639:                         final Collection<GenJavaOperation> operations,
640:                         final Collection<GenClassModifier> modifiers,
641:                         final Collection<GenJavaOperation> constructors,
642:                         final Collection<GenInterfaceClass> implement,
643:                         final ClassType type,
644:                         final GenComment comment,
645:                         final GenPackage packag,
646:                         final String nonGeneratedPart) {
647:                 final GenException result =
648:                                 GenException.create(
649:                                                 name,
650:                                                 operations,
651:                                                 implement,
652:                                                 attributes,
653:                                                 modifiers,
654:                                                 constructors,
655:                                                 packag,
656:                                                 comment,
657:                                                 nonGeneratedPart);
658:                 return result;
659:         }
660:         
661:         /**
662:          * Returns the {@link GenAspect} for <code>baseType</code>. If no {@link GenAspect} for <code>baseType</code> was
663:          * found it will return a new created {@link GenAspect}. If no {@link GenPrimitiveClass} is mapped for
664:          * {@link BaseType} it will throw an exception.
665:          *
666:          * @param baseType
667:          * The {@link BaseType} to get or create an GenAspect for to expand the {@link GenPrimitiveClass} that
668:          * represents the baseType.
669:          * @return The GenAspect which shall contain additional declarations for the {@link GenPrimitiveClass} that is
670:          * represented by the baseType.
671:          * @throws GenTypeNotReferencedException
672:          * Thrown when no {@link GenClass} is mapped for baseType.
673:          */
674:         public GenAspect getAspectForBaseTypeExpansion(final BaseType baseType) throws GenTypeNotReferencedException {
675:                 final GenType genType = this.getGenTypeForType(baseType);
676:                 final GenClass genClass = genType.accept(new GenTypeVisitorReturn<GenClass>() {
677:                         
678:                         @Override
679:                         public GenClass handle(final GenClass cla) {
680:                                 return cla;
681:                         }
682:                         
683:                         @Override
684:                         public GenClass handle(final GenCollectionType collectionType) {
685:                                 return null;
686:                         }
687:                         
688:                         @Override
689:                         public GenClass handle(final GenPrimitiveType primitiveType) {
690:                                 return primitiveType.accept(new GenPrimitiveTypeVisitorReturn<GenClass>() {
691:                                         
692:                                         @Override
693:                                         public GenClass handle(final GenVoidType voidType) {
694:                                                 return null;
695:                                         }
696:                                         
697:                                         @Override
698:                                         public GenClass handle(final GenStringType stringType) {
699:                                                 return GenStringType.getCorrespondingClass();
700:                                         }
701:                                         
702:                                         @Override
703:                                         public GenClass handle(final GenIntegerType integerType) {
704:                                                 return GenIntegerType.getCorrespondingClass();
705:                                         }
706:                                 });
707:                         }
708:                         
709:                         @Override
710:                         public GenClass handle(final GenMapType mapType) {
711:                                 return null;
712:                         }
713:                         
714:                         @Override
715:                         public GenClass handle(final GenImportType importType) {
716:                                 return null;
717:                         }
718:                         
719:                         @Override
720:                         public GenClass handle(final GenDummyType dummyType) {
721:                                 return null;
722:                         }
723:                         
724:                         @Override
725:                         public GenClass handle(final Generic generic) {
726:                                 return null;
727:                         }
728:                         
729:                         @Override
730:                         public GenClass handle(final GenJavaUtilCollection javaUtilCollection) {
731:                                 return null;
732:                         }
733:                 });
734:                 return this.getAspectForType(genClass);
735:         }
736:         
737:         /**
738:          * Returns the {@link GenAspect} for <code>primitiveClass</code>. If no {@link GenAspect} for
739:          * <code>primitiveClass</code> was found it will return a new created {@link GenAspect}.
740:          *
741:          * @param clazz
742:          * The {@link GenPrimitiveClass} to get or create an GenAspect for to expand the primitiveClass.
743:          * @return The GenAspect which shall contain additional declarations for the primitiveClass.
744:          */
745:         public GenAspect getAspectForType(final GenClass clazz) {
746:                 if (this.getAspectJMapping().containsKey(clazz)) {
747:                         return this.getAspectJMapping().get(clazz);
748:                 } else {
749:                         final String name = clazz.getName() + GeneratorModel.BASETYPE_EXPANSION_ASPECT_SUFFIX;
750:                         final Vector<GenJavaOperation> operations = new Vector<>();
751:                         final Vector<GenAspectOperation> aspectOperations = new Vector<>();
752:                         final Vector<GenInterfaceClass> impl = new Vector<>();
753:                         final Vector<GenJavaAttribute> attributes = new Vector<>();
754:                         final Vector<GenAspectAttribute> aspectAttributes = new Vector<>();
755:                         final Vector<GenClassModifier> modifiers = new Vector<>();
756:                         final Vector<GenJavaOperation> constructors = new Vector<>();
757:                         final GenPackage packag = PackageConstants.ASPECT_PACKAGE;
758:                         final GenComment comment = GenComment.createFromPlainText(GeneratorModel.ASPECT_COMMENT, false);
759:                         
760:                         final GenAspect aspect =
761:                                         GenAspect.create(
762:                                                         name,
763:                                                         operations,
764:                                                         aspectOperations,
765:                                                         impl,
766:                                                         attributes,
767:                                                         aspectAttributes,
768:                                                         modifiers,
769:                                                         constructors,
770:                                                         null,
771:                                                         packag,
772:                                                         comment,
773:                                                         "");
774:                         this.addAspect(clazz, aspect);
775:                         return aspect;
776:                 }
777:         }
778:         
779:         /**
780:          * Returns a map from AST-Types to classes that represent a primitive type.
781:          *
782:          * @return Map<Type, GenPrimitiveClass>
783:          */
784:         public Map<Type, GenPrimitiveClass> getBaseClassMapping() {
785:                 return this.baseClassMapping;
786:         }
787:         
788:         /**
789:          * Returns a map of all AST-Types that can be generated as GenClasses.
790:          *
791:          * @return Map<Type, GenClass>
792:          */
793:         public Map<Type, GenClass> getClassMapping() {
794:                 return this.classMapping;
795:         }
796:         
797:         /**
798:          * Returns a map from AST-Types to a tuple of GenType that represents them and a collection of
799:          * {@link ExceptionClassType}s that represents the thrown exceptions in the AST-type.
800:          *
801:          * @return Map<Type, GenType>
802:          */
803:         public Map<Type, Tuple<GenType, Collection<ExceptionClassType>>> getTypeMapping() {
804:                 return this.typeMapping;
805:         }
806:         
807:         /**
808:          * Returns a map from {@link GenClass} to {@link GenAspect} that are created to help realizing the given AST-Model.
809:          *
810:          * @return Map<GenClass, GenAspect>
811:          */
812:         public Map<GenClass, GenAspect> getAspectJMapping() {
813:                 return this.aspectJMapping;
814:         }
815:         
816:         /**
817:          * Returns the collection of all GenClasses that additionally to the AST-Model needs to be generated. Those
818:          * "classes" are for example the AppStarter, Visitors, Factories, the FinderAspect and additional classes to realize
819:          * symmetric relations.
820:          *
821:          * @return Vector<GenClass>
822:          */
823:         public Vector<GenClass> getNonAstType() {
824:                 return this.nonASTClasses;
825:         }
826:         
827:         /**
828:          * Returns a Collection of all GenClasses that additionally to the AST-Model needs to be generated. All contained
829:          * {@link GenClass}es represent an abstract prototype of a {@link ProductType}.
830:          */
831:         // public Set<GenClass> getAbstractPrototypeProducts() {
832:         // return this.abstractPrototypeProducts;
833:         // }
834:         
835: }