Skip to content

Method: handle(GenClass)

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