Skip to content

Package: ProductCheck

ProductCheck

nameinstructionbranchcomplexitylinemethod
ProductCheck(Model, TaskExecutor)
M: 0 C: 5
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 2
100%
M: 0 C: 1
100%
beginTask()
M: 0 C: 1
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
create(Model, TaskExecutor)
M: 0 C: 6
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
finalizeTask()
M: 0 C: 1
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
M: 0 C: 1
100%
handleType(Type)
M: 0 C: 7
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 2
100%
M: 0 C: 1
100%

Coverage

1: package de.fhdw.wtf.walker.tasks;
2:
3: import java.util.HashSet;
4: import java.util.Set;
5:
6: import de.fhdw.wtf.common.ast.Model;
7: import de.fhdw.wtf.common.ast.type.AtomicType;
8: import de.fhdw.wtf.common.ast.type.CompositeType;
9: import de.fhdw.wtf.common.ast.type.ListType;
10: import de.fhdw.wtf.common.ast.type.MapType;
11: import de.fhdw.wtf.common.ast.type.ProductElementType;
12: import de.fhdw.wtf.common.ast.type.ProductType;
13: import de.fhdw.wtf.common.ast.type.SumType;
14: import de.fhdw.wtf.common.ast.type.ThrownType;
15: import de.fhdw.wtf.common.ast.type.Type;
16: import de.fhdw.wtf.common.ast.type.TypeProxy;
17: import de.fhdw.wtf.common.ast.visitor.CompositeTypeVisitorException;
18: import de.fhdw.wtf.common.ast.visitor.TypeVisitorException;
19: import de.fhdw.wtf.common.exception.walker.InvalidProductException;
20: import de.fhdw.wtf.common.exception.walker.TaskException;
21: import de.fhdw.wtf.common.task.TaskExecutor;
22: import de.fhdw.wtf.walker.walker.SimpleWalkerTaskForTypes;
23:
24: /**
25: * This Task check that the names of the productElements are pairwise distinct in every product!
26: */
27: public final class ProductCheck extends SimpleWalkerTaskForTypes {
28:         
29:         /**
30:          * Constructor of {@link ProductCheck}.
31:          *
32:          * @param m
33:          * model
34:          * @param taskmanager
35:          * taskmanager
36:          */
37:         private ProductCheck(final Model m, final TaskExecutor taskmanager) {
38:                 super(m, taskmanager);
39:         }
40:         
41:         /**
42:          * Creates a {@link ProductCheck}-Object.
43:          *
44:          * @param m
45:          * model
46:          * @param taskmanager
47:          * taskmanager
48:          * @return The {@link ProductCheck}-Object.
49:          */
50:         public static ProductCheck create(final Model m, final TaskExecutor taskmanager) {
51:                 return new ProductCheck(m, taskmanager);
52:         }
53:         
54:         @Override
55:         public void handleType(final Type type) throws TaskException {
56:                 type.accept(new TypeVisitorException<TaskException>() {
57:                         
58:                         @Override
59:                         public void handle(final AtomicType s) throws TaskException {
60:                                 // Nothing to do
61:                         }
62:                         
63:                         @Override
64:                         public void handle(final CompositeType c) throws TaskException {
65:                                 c.accept(new CompositeTypeVisitorException<TaskException>() {
66:                                         
67:                                         @Override
68:                                         public void handle(final MapType map) throws TaskException {
69:                                                 // Nothing to do
70:                                         }
71:                                         
72:                                         @Override
73:                                         public void handle(final ListType list) throws TaskException {
74:                                                 // Nothing to do
75:                                         }
76:                                         
77:                                         @Override
78:                                         public void handle(final ProductType product) throws TaskException {
79:                                                 final Set<String> set = new HashSet<>();
80:                                                 for (final ProductElementType element : product.getElements()) {
81:                                                         if (set.contains(element.getName())) {
82:                                                                 throw InvalidProductException.create(
83:                                                                                 element.getName(),
84:                                                                                 product.getFirstToken(),
85:                                                                                 product.getLastToken());
86:                                                         }
87:                                                         set.add(element.getName());
88:                                                 }
89:                                         }
90:                                         
91:                                         @Override
92:                                         public void handle(final SumType sum) throws TaskException {
93:                                                 // Nothing to do
94:                                         }
95:                                         
96:                                         @Override
97:                                         public void handle(final ThrownType thrownType) throws TaskException {
98:                                                 // Nothing to do
99:                                         }
100:                                 });
101:                         }
102:                         
103:                         @Override
104:                         public void handle(final TypeProxy s) throws TaskException {
105:                                 // Nothing to do
106:                         }
107:                 });
108:         }
109:         
110:         @Override
111:         public void finalizeTask() throws TaskException {
112:                 // Nothing to do here
113:         }
114:         
115:         @Override
116:         public void beginTask() throws TaskException {
117:                 // Nothing to do here
118:         }
119: }