Skip to content

Method: handle(GenInterfaceClass)

1: package de.fhdw.wtf.generator.transformer.transformers.classTransformer;
2:
3: import java.util.Collection;
4: import java.util.Iterator;
5: import java.util.List;
6: import java.util.Vector;
7:
8: import de.fhdw.wtf.common.ast.Attribute;
9: import de.fhdw.wtf.common.ast.ConstructorOrOperation;
10: import de.fhdw.wtf.common.ast.Group;
11: import de.fhdw.wtf.common.ast.Model;
12: import de.fhdw.wtf.common.ast.type.ClassType;
13: import de.fhdw.wtf.common.exception.walker.TaskException;
14: import de.fhdw.wtf.common.task.TaskExecutor;
15: import de.fhdw.wtf.generator.java.generatorModel.GenClass;
16: import de.fhdw.wtf.generator.java.generatorModel.GenClassClass;
17: import de.fhdw.wtf.generator.java.generatorModel.GenComment;
18: import de.fhdw.wtf.generator.java.generatorModel.GenException;
19: import de.fhdw.wtf.generator.java.generatorModel.GenExternalInterfaceClass;
20: import de.fhdw.wtf.generator.java.generatorModel.GenFullParsedOperationState;
21: import de.fhdw.wtf.generator.java.generatorModel.GenInterfaceClass;
22: import de.fhdw.wtf.generator.java.generatorModel.GenInterfaceWithClassImplClass;
23: import de.fhdw.wtf.generator.java.generatorModel.GenJavaOperation;
24: import de.fhdw.wtf.generator.java.generatorModel.GenOperationModifier;
25: import de.fhdw.wtf.generator.java.generatorModel.GenParameter;
26: import de.fhdw.wtf.generator.java.generatorModel.GenPrimitiveClass;
27: import de.fhdw.wtf.generator.java.generatorModel.GenSimpleInterfaceClass;
28: import de.fhdw.wtf.generator.java.generatorModel.GenSimpleOperationState;
29: import de.fhdw.wtf.generator.java.generatorModel.GenTypeReference;
30: import de.fhdw.wtf.generator.java.generatorModel.GenUserClass;
31: import de.fhdw.wtf.generator.java.generatorModel.GenVisibility;
32: import de.fhdw.wtf.generator.java.generatorModel.GeneratorModel;
33: import de.fhdw.wtf.generator.java.generatorModel.Generic;
34: import de.fhdw.wtf.generator.java.visitor.GenClassVisitorException;
35: import de.fhdw.wtf.generator.java.visitor.GenClassVisitorReturn;
36: import de.fhdw.wtf.generator.java.visitor.GenInterfaceClassVisitorException;
37: import de.fhdw.wtf.generator.java.visitor.GenInterfaceClassVisitorReturn;
38: import de.fhdw.wtf.generator.java.visitor.GenOperationStateVisitorReturnException;
39: import de.fhdw.wtf.generator.transformer.exception.GenTypeNotReferencedException;
40: import de.fhdw.wtf.walker.walker.SimpleWalkerTask;
41:
42: /**
43: * Transformer who realizes the delegation pattern for the generated model.
44: *
45: * @author hfw413sc
46: *
47: */
48: public class DelegationTransformer extends SimpleWalkerTask {
49:         
50:         /**
51:          * The referenced generator model.
52:          */
53:         private final GeneratorModel generatorModel;
54:         
55:         /**
56:          * Creates a DelegationTransformer.
57:          *
58:          * @param m
59:          * the model
60:          * @param taskmanager
61:          * the taskmanager
62:          * @param generatorModel
63:          * the generator model
64:          */
65:         public DelegationTransformer(final Model m, final TaskExecutor taskmanager, final GeneratorModel generatorModel) {
66:                 super(m, taskmanager);
67:                 this.generatorModel = generatorModel;
68:         }
69:         
70:         @Override
71:         public void handleClass(final ClassType c) throws TaskException {
72:                 final GenClass clazz = this.generatorModel.getJavaClassForWTFClass(c);
73:                 clazz.accept(new GenClassVisitorException<TaskException>() {
74:                         
75:                         @Override
76:                         public void handle(final GenClassClass classClass) throws GenTypeNotReferencedException {
77:                                 // nothing to do
78:                                 
79:                         }
80:                         
81:                         @Override
82:                         public void handle(final GenInterfaceClass interfaceClass) throws TaskException {
83:                                 interfaceClass.accept(new GenInterfaceClassVisitorException<TaskException>() {
84:                                         
85:                                         @Override
86:                                         public void handle(final GenSimpleInterfaceClass simpleInterface)
87:                                                         throws GenTypeNotReferencedException {
88:                                                 // nothing to do
89:                                         }
90:                                         
91:                                         @Override
92:                                         public void handle(final GenInterfaceWithClassImplClass interfaceWithImplClass)
93:                                                         throws TaskException {
94:                                                 if (DelegationTransformer.this.isInterfaceInheritanceRoot(interfaceWithImplClass)) {
95:                                                         DelegationTransformer.this.handleInheritanceRoot(interfaceWithImplClass
96:                                                                         .getClassRepresentation());
97:                                                 }
98:                                                 DelegationTransformer.this.makeDelegations(c, interfaceWithImplClass.getClassRepresentation());
99:                                                 
100:                                         }
101:                                         
102:                                         @Override
103:                                         public void handle(final GenExternalInterfaceClass iface) throws GenTypeNotReferencedException {
104:                                                 // nothing to do
105:                                         }
106:                                 });
107:                                 
108:                         }
109:                         
110:                         @Override
111:                         public void handle(final GenPrimitiveClass primitiveClass) throws GenTypeNotReferencedException {
112:                                 // nothing to do
113:                         }
114:                 });
115:         }
116:         
117:         /**
118:          * Adds delegation code to an inheritance root.
119:          *
120:          * @param classRepresentation
121:          * the root.
122:          * @throws TaskException
123:          * if an operation has the wrong state.
124:          */
125:         private void handleInheritanceRoot(final GenUserClass classRepresentation) throws TaskException {
126:                 final Iterator<GenJavaOperation> operations = classRepresentation.getOperations().iterator();
127:                 while (operations.hasNext()) {
128:                         final GenJavaOperation genJavaOperation = operations.next();
129:                         final String name = genJavaOperation.getName();
130:                         final List<GenParameter> parameters = genJavaOperation.getParameters();
131:                         final GenComment comment = this.getComment(genJavaOperation);
132:                         final Collection<GenException> exceptions = this.getExceptions(genJavaOperation);
133:                         final GenTypeReference returntyp = this.getReturnType(genJavaOperation);
134:                         final Collection<GenOperationModifier> modifiers = this.getModifiers(genJavaOperation);
135:                         final GenVisibility visibility = this.getVisibility(genJavaOperation);
136:                         if (!name.contains("$") && !name.equals("accept")) {
137:                                 final boolean isAbstract = modifiers.contains(GenOperationModifier.ABSTRACT);
138:                                 if (isAbstract) {
139:                                         final GenJavaOperation operation =
140:                                                         this.makeAbstractOperation(
141:                                                                         name,
142:                                                                         parameters,
143:                                                                         comment,
144:                                                                         exceptions,
145:                                                                         returntyp,
146:                                                                         modifiers,
147:                                                                         visibility,
148:                                                                         genJavaOperation.getGenerics());
149:                                         operation.getGenerics().addAll(genJavaOperation.getGenerics());
150:                                         classRepresentation.overrideExistingOperation(operation);
151:                                 } else {
152:                                         final GenJavaOperation operation =
153:                                                         this.makeConcreteOperationEmpty(
154:                                                                         name,
155:                                                                         parameters,
156:                                                                         comment,
157:                                                                         exceptions,
158:                                                                         returntyp,
159:                                                                         modifiers,
160:                                                                         visibility,
161:                                                                         genJavaOperation.getGenerics());
162:                                         operation.getGenerics().addAll(genJavaOperation.getGenerics());
163:                                         classRepresentation.overrideExistingOperation(operation);
164:                                 }
165:                         }
166:                 }
167:         }
168:         
169:         /**
170:          * Adds delegation to sub classes.
171:          *
172:          * @param c
173:          * the root as classType.
174:          * @param classRepresentation
175:          * the root.
176:          * @throws TaskException
177:          * if an operation has the wrong state.
178:          */
179:         private void makeDelegations(final ClassType c, final GenUserClass classRepresentation) throws TaskException {
180:                 final Iterator<GenJavaOperation> operations = classRepresentation.getOperations().iterator();
181:                 while (operations.hasNext()) {
182:                         final GenJavaOperation genJavaOperation = operations.next();
183:                         final String name = genJavaOperation.getName();
184:                         final Collection<GenOperationModifier> modifiers = this.getModifiers(genJavaOperation);
185:                         if (!name.contains("$")) {
186:                                 final boolean isAbstract = modifiers.contains(GenOperationModifier.ABSTRACT);
187:                                 final Iterator<ClassType> subTypes = c.getSubTypes().iterator();
188:                                 while (subTypes.hasNext()) {
189:                                         final ClassType subType = subTypes.next();
190:                                         final GenClassClass genSubClass =
191:                                                         this.getRepresentingClass(this.generatorModel.getJavaClassForWTFClass(subType));
192:                                         
193:                                         boolean sameNameFound = false;
194:                                         final Iterator<GenJavaOperation> i2 = genSubClass.getOperations().iterator();
195:                                         while (!sameNameFound && i2.hasNext()) {
196:                                                 final GenJavaOperation genJavaOperation2 = i2.next();
197:                                                 if (genJavaOperation.getName().equals("accept")) {
198:                                                         sameNameFound = genJavaOperation2.toString().equals(genJavaOperation.toString());
199:                                                 } else {
200:                                                         sameNameFound = genJavaOperation2.getName().equals(genJavaOperation.getName());
201:                                                 }
202:                                         }
203:                                         this.addDelegationsInSubClass(
204:                                                         subType,
205:                                                         genSubClass,
206:                                                         classRepresentation,
207:                                                         genJavaOperation,
208:                                                         isAbstract,
209:                                                         sameNameFound);
210:                                 }
211:                         }
212:                 }
213:         }
214:         
215:         /**
216:          * Adds delegations to a subclass.
217:          *
218:          * @param subType
219:          * the class type of sub.
220:          * @param sub
221:          * the representation.
222:          * @param superType
223:          * the super type to delegate to.
224:          * @param genJavaOperation
225:          * the operation.
226:          * @param isAbstract
227:          * true if genJavaOperation is abstract.
228:          * @param same
229:          * true if sub already has an operation equal to genJavaOperation.
230:          * @throws TaskException
231:          * if an operation is in a wrong state.
232:          */
233:         private void addDelegationsInSubClass(final ClassType subType,
234:                         final GenClassClass sub,
235:                         final GenUserClass superType,
236:                         final GenJavaOperation genJavaOperation,
237:                         final boolean isAbstract,
238:                         final boolean same) throws TaskException {
239:                 GenJavaOperation operation = null;
240:                 if (subType.isAbstract()) {
241:                         if (isAbstract) {
242:                                 operation = DelegationTransformer.this.makeAbstractOperation(genJavaOperation);
243:                         } else {
244:                                 operation = DelegationTransformer.this.makeOperationWithDelegationToSuper(superType, genJavaOperation);
245:                                 this.getModifiers(operation).remove(GenOperationModifier.ABSTRACT);
246:                         }
247:                 } else {
248:                         if (isAbstract) {
249:                                 operation = DelegationTransformer.this.makeConcreteOperationEmpty(genJavaOperation);
250:                                 this.getModifiers(operation).remove(GenOperationModifier.ABSTRACT);
251:                         } else {
252:                                 operation = DelegationTransformer.this.makeOperationWithDelegationToSuper(superType, genJavaOperation);
253:                                 this.getModifiers(operation).remove(GenOperationModifier.ABSTRACT);
254:                         }
255:                         
256:                 }
257:                 if (same) {
258:                         sub.overrideExistingOperation(operation);
259:                 } else {
260:                         sub.addOperation(operation);
261:                 }
262:         }
263:         
264:         /**
265:          * @param javaClass
266:          * the class to get the representing class from.
267:          * @return the Representing Class of javaClass.
268:          * @throws TaskException
269:          * if javaClass is not a not a GenInterfaceWithGenClass!
270:          */
271:         private GenClassClass getRepresentingClass(final GenClass javaClass) throws TaskException {
272:                 final GenClassClass classClass = javaClass.accept(new GenClassVisitorReturn<GenClassClass>() {
273:                         
274:                         @Override
275:                         public GenClassClass handle(final GenClassClass genClassClass) {
276:                                 return null;
277:                         }
278:                         
279:                         @Override
280:                         public GenClassClass handle(final GenInterfaceClass interfaceClass) {
281:                                 return interfaceClass.accept(new GenInterfaceClassVisitorReturn<GenClassClass>() {
282:                                         
283:                                         @Override
284:                                         public GenClassClass handle(final GenSimpleInterfaceClass simpleInterface) {
285:                                                 return null;
286:                                         }
287:                                         
288:                                         @Override
289:                                         public GenClassClass handle(final GenInterfaceWithClassImplClass interfaceWithImplClass) {
290:                                                 return interfaceWithImplClass.getClassRepresentation();
291:                                         }
292:                                         
293:                                         @Override
294:                                         public GenClassClass handle(final GenExternalInterfaceClass iface) {
295:                                                 return null;
296:                                         }
297:                                 });
298:                         }
299:                         
300:                         @Override
301:                         public GenClassClass handle(final GenPrimitiveClass primitiveClass) {
302:                                 return null;
303:                         }
304:                         
305:                 });
306:                 if (classClass == null) {
307:                         throw new TaskException("Subclass is not a GenInterfaceWithGenClass!");
308:                 }
309:                 return classClass;
310:         }
311:         
312:         /**
313:          * Creates an operation that delegates to superType.
314:          *
315:          * @param superType
316:          * @param genJavaOperation
317:          * the operation.
318:          * @return the new operation.
319:          * @throws TaskException
320:          * if operation is in an invalid state.
321:          */
322:         private GenJavaOperation makeOperationWithDelegationToSuper(final GenUserClass superType,
323:                         final GenJavaOperation genJavaOperation) throws TaskException {
324:                 final String name = genJavaOperation.getName();
325:                 final List<GenParameter> parameters = genJavaOperation.getParameters();
326:                 final GenComment comment = this.getComment(genJavaOperation);
327:                 final Collection<GenException> exceptions = this.getExceptions(genJavaOperation);
328:                 final GenTypeReference returntyp = this.getReturnType(genJavaOperation);
329:                 final Collection<GenOperationModifier> modifiers = new Vector<>();
330:                 modifiers.addAll(this.getModifiers(genJavaOperation));
331:                 final GenVisibility visibility = this.getVisibility(genJavaOperation);
332:                 return this.makeOperationWithDelegationToSuper(
333:                                 superType,
334:                                 name,
335:                                 parameters,
336:                                 comment,
337:                                 exceptions,
338:                                 returntyp,
339:                                 modifiers,
340:                                 visibility,
341:                                 genJavaOperation.getGenerics());
342:         }
343:         
344:         /**
345:          *
346:          * @param superType
347:          * superType.
348:          * @param name
349:          * name.
350:          * @param parameters
351:          * parameters.
352:          * @param comment
353:          * comment.
354:          * @param exceptions
355:          * exceptions.
356:          * @param returntyp
357:          * returntyp.
358:          * @param modifiers
359:          * modifiers.
360:          * @param visibility
361:          * visibility.
362:          * @param generics
363:          * generics.
364:          * @return the new operation.
365:          */
366:         private GenJavaOperation makeOperationWithDelegationToSuper(final GenUserClass superType,
367:                         final String name,
368:                         final List<GenParameter> parameters,
369:                         final GenComment comment,
370:                         final Collection<GenException> exceptions,
371:                         final GenTypeReference returntyp,
372:                         final Collection<GenOperationModifier> modifiers,
373:                         final GenVisibility visibility,
374:                         final List<Generic> generics) {
375:                 final String superTypeName = superType.getFullyQualifiedTypeName();
376:                 final boolean isVoid = returntyp.getFullyQualifiedName().equals("void");
377:                 final String returnString = isVoid ? "" : "return ";
378:                 final String methodBody =
379:                                 returnString + "((" + superTypeName
380:                                                 + ")this.$generatedObjects.get(new de.fhdw.wtf.context.model.Str(\"" + superTypeName + "\")))."
381:                                                 + name + "(" + this.generateParameterNamesList(parameters) + ");";
382:                 final GenFullParsedOperationState state =
383:                                 GenFullParsedOperationState.create(comment, exceptions, returntyp, modifiers, visibility, methodBody);
384:                 final GenJavaOperation operation = GenJavaOperation.create(name, parameters, state);
385:                 operation.getGenerics().addAll(generics);
386:                 return operation;
387:         }
388:         
389:         /**
390:          * @param parameters
391:          * parameters of an operation.
392:          * @return a string with the comma separated parameters.
393:          */
394:         private String generateParameterNamesList(final List<GenParameter> parameters) {
395:                 final StringBuilder parameterStringBuilder = new StringBuilder();
396:                 for (final GenParameter p : parameters) {
397:                         parameterStringBuilder.append(", ");
398:                         parameterStringBuilder.append(p.getName());
399:                 }
400:                 String parameterNamesList = parameterStringBuilder.toString();
401:                 if (parameterNamesList.length() > 0) {
402:                         parameterNamesList = parameterNamesList.replaceFirst("," + " ", "");
403:                 }
404:                 return parameterNamesList;
405:         }
406:         
407:         /**
408:          * Creates an operation with todo.
409:          *
410:          * @param genJavaOperation
411:          * the operation.
412:          * @return the new operation.
413:          * @throws TaskException
414:          * if operation is in an invalid state.
415:          */
416:         private GenJavaOperation makeConcreteOperationEmpty(final GenJavaOperation genJavaOperation) throws TaskException {
417:                 final String name = genJavaOperation.getName();
418:                 final List<GenParameter> parameters = genJavaOperation.getParameters();
419:                 final GenComment comment = this.getComment(genJavaOperation);
420:                 final Collection<GenException> exceptions = this.getExceptions(genJavaOperation);
421:                 final GenTypeReference returntyp = this.getReturnType(genJavaOperation);
422:                 final Collection<GenOperationModifier> modifiers = new Vector<>();
423:                 modifiers.addAll(this.getModifiers(genJavaOperation));
424:                 final GenVisibility visibility = this.getVisibility(genJavaOperation);
425:                 return this.makeConcreteOperationEmpty(
426:                                 name,
427:                                 parameters,
428:                                 comment,
429:                                 exceptions,
430:                                 returntyp,
431:                                 modifiers,
432:                                 visibility,
433:                                 genJavaOperation.getGenerics());
434:         }
435:         
436:         /**
437:          *
438:          * @param name
439:          * name.
440:          * @param parameters
441:          * parameters.
442:          * @param comment
443:          * comment.
444:          * @param exceptions
445:          * exceptions.
446:          * @param returntyp
447:          * returntyp.
448:          * @param modifiers
449:          * modifiers.
450:          * @param visibility
451:          * visibility.
452:          * @param generics
453:          * generics.
454:          * @return the new operation.
455:          */
456:         private GenJavaOperation makeConcreteOperationEmpty(final String name,
457:                         final List<GenParameter> parameters,
458:                         final GenComment comment,
459:                         final Collection<GenException> exceptions,
460:                         final GenTypeReference returntyp,
461:                         final Collection<GenOperationModifier> modifiers,
462:                         final GenVisibility visibility,
463:                         final List<Generic> generics) {
464:                 String methodBody = "";
465:                 if (name.equals("accept")) {
466:                         methodBody = "visitor.handle(this);";
467:                 } else {
468:                         methodBody =
469:                                         "//TODO implement operation " + name
470:                                                         + (returntyp.getFullyQualifiedName().equals("void") ? "" : "\n\t\treturn null;");
471:                 }
472:                 final GenFullParsedOperationState state =
473:                                 GenFullParsedOperationState.create(comment, exceptions, returntyp, modifiers, visibility, methodBody);
474:                 final GenJavaOperation operation = GenJavaOperation.create(name, parameters, state);
475:                 operation.getGenerics().addAll(generics);
476:                 return operation;
477:         }
478:         
479:         /**
480:          * Creates an operation with check for this.
481:          *
482:          * @param genJavaOperation
483:          * the operation.
484:          * @return the new operation.
485:          * @throws TaskException
486:          * if operation is in an invalid state.
487:          */
488:         private GenJavaOperation makeAbstractOperation(final GenJavaOperation genJavaOperation) throws TaskException {
489:                 final String name = genJavaOperation.getName();
490:                 final List<GenParameter> parameters = genJavaOperation.getParameters();
491:                 final GenComment comment = this.getComment(genJavaOperation);
492:                 final Collection<GenException> exceptions = this.getExceptions(genJavaOperation);
493:                 final GenTypeReference returntyp = this.getReturnType(genJavaOperation);
494:                 final Collection<GenOperationModifier> modifiers = new Vector<>();
495:                 modifiers.addAll(this.getModifiers(genJavaOperation));
496:                 final GenVisibility visibility = this.getVisibility(genJavaOperation);
497:                 return this.makeAbstractOperation(
498:                                 name,
499:                                 parameters,
500:                                 comment,
501:                                 exceptions,
502:                                 returntyp,
503:                                 modifiers,
504:                                 visibility,
505:                                 genJavaOperation.getGenerics());
506:         }
507:         
508:         /**
509:          *
510:          * @param name
511:          * name.
512:          * @param parameters
513:          * parameters.
514:          * @param comment
515:          * comment.
516:          * @param exceptions
517:          * exceptions.
518:          * @param returntyp
519:          * returntyp.
520:          * @param modifiers
521:          * modifiers.
522:          * @param visibility
523:          * visibility.
524:          * @param generics
525:          * generics.
526:          * @return the new operation.
527:          */
528:         private GenJavaOperation makeAbstractOperation(final String name,
529:                         final List<GenParameter> parameters,
530:                         final GenComment comment,
531:                         final Collection<GenException> exceptions,
532:                         final GenTypeReference returntyp,
533:                         final Collection<GenOperationModifier> modifiers,
534:                         final GenVisibility visibility,
535:                         final List<Generic> generics) {
536:                 final String methodBody =
537:                                 "if(this.$getThis()==this)throw new Error();" + "\n\t\t"
538:                                                 + (returntyp.getFullyQualifiedName().equals("void") ? "" : "return ") + "this.$getThis()."
539:                                                 + name + "();";
540:                 final GenFullParsedOperationState state =
541:                                 GenFullParsedOperationState.create(comment, exceptions, returntyp, modifiers, visibility, methodBody);
542:                 final GenJavaOperation operation = GenJavaOperation.create(name, parameters, state);
543:                 operation.getGenerics().addAll(generics);
544:                 return operation;
545:         }
546:         
547:         /**
548:          * Returns true if checkInterface is directly extending Anything.
549:          *
550:          * @param checkInterface
551:          * Interface to be checked
552:          * @return true if checkInterface is a root of the inheritance
553:          * @throws GenTypeNotReferencedException
554:          * possible exception
555:          */
556:         private boolean isInterfaceInheritanceRoot(final GenInterfaceWithClassImplClass checkInterface)
557:                         throws GenTypeNotReferencedException {
558:                 return checkInterface.getImplement().contains(
559:                                 this.generatorModel.getGenTypeForType(this.getModel().getAnything()));
560:         }
561:         
562:         @Override
563:         public void handleGroup(final Group g) throws TaskException {
564:                 // nothing to do
565:                 
566:         }
567:         
568:         @Override
569:         public void handleAttribute(final Attribute a, final ClassType owner) throws TaskException {
570:                 // nothing to do
571:                 
572:         }
573:         
574:         @Override
575:         public void handleConstructorOrOperation(final ConstructorOrOperation coo, final ClassType owner)
576:                         throws TaskException {
577:                 // nothing to do
578:                 
579:         }
580:         
581:         @Override
582:         public void finalizeTask() throws TaskException {
583:                 // Nothing to do.
584:         }
585:         
586:         /**
587:          *
588:          * @param genJavaOperation
589:          * an operation.
590:          * @return the desired field value.
591:          * @throws TaskException
592:          * if operation in wrong state.
593:          */
594:         private GenVisibility getVisibility(final GenJavaOperation genJavaOperation) throws TaskException {
595:                 return genJavaOperation.getState().accept(
596:                                 new GenOperationStateVisitorReturnException<GenVisibility, TaskException>() {
597:                                         
598:                                         @Override
599:                                         public GenVisibility handle(final GenSimpleOperationState s) throws TaskException {
600:                                                 throw new TaskException("Wrong state for operation");
601:                                         }
602:                                         
603:                                         @Override
604:                                         public GenVisibility handle(final GenFullParsedOperationState s) {
605:                                                 return s.getVisibility();
606:                                         }
607:                                 });
608:         }
609:         
610:         /**
611:          *
612:          * @param genJavaOperation
613:          * an operation.
614:          * @return the desired field value.
615:          * @throws TaskException
616:          * if operation in wrong state.
617:          */
618:         private Collection<GenOperationModifier> getModifiers(final GenJavaOperation genJavaOperation) throws TaskException {
619:                 return genJavaOperation.getState().accept(
620:                                 new GenOperationStateVisitorReturnException<Collection<GenOperationModifier>, TaskException>() {
621:                                         
622:                                         @Override
623:                                         public Collection<GenOperationModifier> handle(final GenSimpleOperationState s)
624:                                                         throws TaskException {
625:                                                 throw new TaskException("Wrong state for operation");
626:                                         }
627:                                         
628:                                         @Override
629:                                         public Collection<GenOperationModifier> handle(final GenFullParsedOperationState s) {
630:                                                 return s.getModifiers();
631:                                         }
632:                                 });
633:         }
634:         
635:         /**
636:          *
637:          * @param genJavaOperation
638:          * an operation.
639:          * @return the desired field value.
640:          * @throws TaskException
641:          * if operation in wrong state.
642:          */
643:         private GenTypeReference getReturnType(final GenJavaOperation genJavaOperation) throws TaskException {
644:                 return genJavaOperation.getState().accept(
645:                                 new GenOperationStateVisitorReturnException<GenTypeReference, TaskException>() {
646:                                         
647:                                         @Override
648:                                         public GenTypeReference handle(final GenSimpleOperationState s) throws TaskException {
649:                                                 throw new TaskException("Wrong state for operation");
650:                                         }
651:                                         
652:                                         @Override
653:                                         public GenTypeReference handle(final GenFullParsedOperationState s) {
654:                                                 return s.getReturntyp();
655:                                         }
656:                                 });
657:         }
658:         
659:         /**
660:          *
661:          * @param genJavaOperation
662:          * an operation.
663:          * @return the desired field value.
664:          * @throws TaskException
665:          * if operation in wrong state.
666:          */
667:         private GenComment getComment(final GenJavaOperation genJavaOperation) throws TaskException {
668:                 return genJavaOperation.getState().accept(
669:                                 new GenOperationStateVisitorReturnException<GenComment, TaskException>() {
670:                                         
671:                                         @Override
672:                                         public GenComment handle(final GenSimpleOperationState s) throws TaskException {
673:                                                 throw new TaskException("Wrong state for operation");
674:                                         }
675:                                         
676:                                         @Override
677:                                         public GenComment handle(final GenFullParsedOperationState s) {
678:                                                 return s.getComment();
679:                                         }
680:                                 });
681:         }
682:         
683:         /**
684:          *
685:          * @param genJavaOperation
686:          * an operation.
687:          * @return the desired field value.
688:          * @throws TaskException
689:          * if operation in wrong state.
690:          */
691:         private Collection<GenException> getExceptions(final GenJavaOperation genJavaOperation) throws TaskException {
692:                 return genJavaOperation.getState().accept(
693:                                 new GenOperationStateVisitorReturnException<Collection<GenException>, TaskException>() {
694:                                         
695:                                         @Override
696:                                         public Collection<GenException> handle(final GenSimpleOperationState s) throws TaskException {
697:                                                 throw new TaskException("Wrong state for operation");
698:                                         }
699:                                         
700:                                         @Override
701:                                         public Collection<GenException> handle(final GenFullParsedOperationState s) {
702:                                                 return s.getExceptions();
703:                                         }
704:                                 });
705:         }
706:         
707:         @Override
708:         public void beginTask() throws TaskException {
709:                 // nothing to do
710:                 
711:         }
712:         
713: }