Skip to content

Package: SpecializationGenerationTask

SpecializationGenerationTask

nameinstructionbranchcomplexitylinemethod
SpecializationGenerationTask(Model, TaskExecutor, InitialGenerator)
M: 8 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 3 C: 0
0%
M: 1 C: 0
0%
beginTask()
M: 1 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%
finalizeTask()
M: 12 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 5 C: 0
0%
M: 1 C: 0
0%
handleType(Type)
M: 37 C: 0
0%
M: 2 C: 0
0%
M: 2 C: 0
0%
M: 11 C: 0
0%
M: 1 C: 0
0%

Coverage

1: package de.fhdw.wtf.generator.database.tasks;
2:
3: import java.util.Iterator;
4:
5: import de.fhdw.wtf.common.ast.Model;
6: import de.fhdw.wtf.common.ast.type.Type;
7: import de.fhdw.wtf.common.exception.generation.NoTypeIdSetException;
8: import de.fhdw.wtf.common.exception.walker.TaskException;
9: import de.fhdw.wtf.common.task.TaskExecutor;
10: import de.fhdw.wtf.generator.database.generation.InitialGenerator;
11: import de.fhdw.wtf.persistence.exception.PersistenceException;
12: import de.fhdw.wtf.walker.walker.HelperUtils;
13: import de.fhdw.wtf.walker.walker.SimpleWalkerTaskForTypes;
14:
15: /**
16: * The {@link TypeGenerationService} puts all specializations of the Model (AST) into the database.
17: *
18: */
19: public class SpecializationGenerationTask extends SimpleWalkerTaskForTypes {
20:         
21:         /**
22:          * Creates a {@link SpecializationGenerationTask}.
23:          *
24:          * @param m
25:          * The associated model.
26:          * @param man
27:          * The task manager to use.
28:          * @param generator
29:          * The generator to use.
30:          */
31:         public SpecializationGenerationTask(final Model m, final TaskExecutor man, final InitialGenerator generator) {
32:                 super(m, man);
33:                 this.generator = generator;
34:         }
35:         
36:         /**
37:          * The generator to use.
38:          */
39:         private final InitialGenerator generator;
40:         
41:         @Override
42:         public void handleType(final Type c) throws TaskException {
43:                 final Iterator<Type> i = c.getSuperTypes().iterator();
44:•                while (i.hasNext()) {
45:                         final Type current = i.next();
46:                         Type superType;
47:                         try {
48:                                 superType = HelperUtils.getReferencedType(current);
49:                                 this.generator.createSpecialisation(superType.getTypeId().getId(), c.getTypeId().getId());
50:                                 this.generator.getClassFacade().finalizeSpecialization();
51:                         } catch (final PersistenceException | NoTypeIdSetException e) {
52:                                 throw new TaskException(e.getMessage());
53:                         }
54:                 }
55:         }
56:         
57:         @Override
58:         public void finalizeTask() throws TaskException {
59:                 try {
60:                         this.generator.getClassFacade().finalizeSpecialization();
61:                 } catch (final PersistenceException e) {
62:                         throw new TaskException(e);
63:                 }
64:         }
65:         
66:         @Override
67:         public void beginTask() throws TaskException {
68:                 // Nothing
69:         }
70: }