Skip to content

Package: ConstructorOrOperation$1$1

ConstructorOrOperation$1$1

nameinstructionbranchcomplexitylinemethod
handle(ListType)
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%
handle(MapType)
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%
handle(ProductType)
M: 19 C: 0
0%
M: 2 C: 0
0%
M: 2 C: 0
0%
M: 5 C: 0
0%
M: 1 C: 0
0%
handle(SumType)
M: 11 C: 0
0%
M: 2 C: 0
0%
M: 2 C: 0
0%
M: 4 C: 0
0%
M: 1 C: 0
0%
handle(ThrownType)
M: 6 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 2 C: 0
0%
M: 1 C: 0
0%
{...}
M: 9 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 2 C: 0
0%
M: 1 C: 0
0%

Coverage

1: package de.fhdw.wtf.common.ast;
2:
3: import java.util.HashSet;
4: import java.util.Iterator;
5:
6: import de.fhdw.wtf.common.ast.type.AtomicType;
7: import de.fhdw.wtf.common.ast.type.BaseType;
8: import de.fhdw.wtf.common.ast.type.ClassType;
9: import de.fhdw.wtf.common.ast.type.CompositeType;
10: import de.fhdw.wtf.common.ast.type.ListType;
11: import de.fhdw.wtf.common.ast.type.MapType;
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.AtomicTypeVisitor;
18: import de.fhdw.wtf.common.ast.visitor.CompositeTypeVisitor;
19: import de.fhdw.wtf.common.ast.visitor.ConstructorOrOperationExceptionVisitor;
20: import de.fhdw.wtf.common.ast.visitor.TypeVisitor;
21: import de.fhdw.wtf.common.exception.walker.TaskException;
22: import de.fhdw.wtf.common.token.Token;
23:
24: /**
25: * This abstract class represents constructors or operations of a class.
26: */
27: public abstract class ConstructorOrOperation extends SyntaxObject {
28:         
29:         /**
30:          * Represents {@link Type} which will be returned by this constructor or operation.
31:          */
32:         private final Type returnType;
33:         
34:         /**
35:          * @return Represents the type which includes the {@link ConstructorOrOperation}
36:          */
37:         public Type getReturnType() {
38:                 return this.returnType;
39:         }
40:         
41:         private final ConstructorOrOperationSignature signature;
42:         
43:         /**
44:          * Creates a new {@link ConstructorOrOperation}.
45:          *
46:          * @param parameters
47:          * The parameters of the constructor or operation.
48:          * @param containingType
49:          * containingType of the Constructor or Operation
50:          * @param returnType
51:          * @param firstToken
52:          * firstToken.
53:          * @param lastToken
54:          * lastToken.
55:          */
56:         protected ConstructorOrOperation(final String name,
57:                         final ProductType parameters,
58:                         final ClassType containingType,
59:                         final Type returnType,
60:                         final Token firstToken,
61:                         final Token lastToken) {
62:                 super(firstToken, lastToken);
63:                 this.signature = ConstructorOrOperationSignature.create(name, parameters, containingType);
64:                 this.returnType = returnType;
65:         }
66:         
67:         /**
68:          * @return Returns the signature of this {@link ConstructorOrOperation}
69:          */
70:         public ConstructorOrOperationSignature getSignature() {
71:                 return this.signature;
72:         }
73:         
74:         @Override
75:         public abstract boolean equals(final Object o);
76:         
77:         @Override
78:         public abstract int hashCode();
79:         
80:         @Override
81:         public abstract String toString();
82:         
83:         /**
84:          * Same as getSignature().getParameter()
85:          *
86:          * @return the parameter which is assigned to this {@link ConstructorOrOperation}
87:          */
88:         public ProductType getParameters() {
89:                 return this.signature.getParameters();
90:         }
91:         
92:         /**
93:          * Same as getSignature().getName()
94:          *
95:          * @return the name of this {@link ConstructorOrOperation}
96:          */
97:         public String getName() {
98:                 return this.signature.getName();
99:         }
100:         
101:         /**
102:          * Same as getSignature().getContainingType()
103:          *
104:          * @return the containingType which is assigned to this {@link ConstructorOrOperation}
105:          */
106:         public ClassType getContainingType() {
107:                 return this.signature.getContainingType();
108:         }
109:         
110:         public HashSet<Type> getThrownExceptions() {
111:                 final HashSet<Type> outputLst = new HashSet<Type>();
112:                 
113:                 this.getReturnType().accept(new TypeVisitor() {
114:                         
115:                         @Override
116:                         public void handle(final TypeProxy typeProxy) {
117:                                 // TODO Auto-generated method stub
118:                                 
119:                         }
120:                         
121:                         @Override
122:                         public void handle(final CompositeType compositeType) {
123:                                 compositeType.accept(new CompositeTypeVisitor() {
124:                                         
125:                                         @Override
126:                                         public void handle(final ThrownType thrownType) {
127:                                                 outputLst.add(thrownType);
128:                                                 
129:                                         }
130:                                         
131:                                         @Override
132:                                         public void handle(final SumType sum) {
133:                                                 
134:                                                 final Iterator<ThrownType> itera =
135:                                                                 ConstructorOrOperation.this.getThrownTypeHelperSum(sum).iterator();
136:•                                                while (itera.hasNext()) {
137:                                                 }
138:                                         }
139:                                         
140:                                         @Override
141:                                         public void handle(final ProductType product) {
142:                                                 final Iterator<ThrownType> itera =
143:                                                                 ConstructorOrOperation.this.getThrownTypeHelperPro(product).iterator();
144:•                                                while (itera.hasNext()) {
145:                                                         outputLst.add(itera.next());
146:                                                 }
147:                                         }
148:                                         
149:                                         @Override
150:                                         public void handle(final MapType map) {
151:                                                 // nothing to do here
152:                                                 
153:                                         }
154:                                         
155:                                         @Override
156:                                         public void handle(final ListType list) {
157:                                                 // nothing to do here;
158:                                                 
159:                                         }
160:                                 });
161:                                 
162:                         }
163:                         
164:                         @Override
165:                         public void handle(final AtomicType atomicType) {
166:                                 atomicType.accept(new AtomicTypeVisitor() {
167:                                         
168:                                         @Override
169:                                         public void handle(final ClassType clazz) {
170:                                                 if (clazz.isThrownType()) {
171:                                                         outputLst.add(clazz);
172:                                                 }
173:                                                 
174:                                         }
175:                                         
176:                                         @Override
177:                                         public void handle(final BaseType baseType) {
178:                                                 // nothing To Do Here!
179:                                                 
180:                                         }
181:                                 });
182:                                 
183:                         }
184:                 });
185:                 
186:                 return outputLst;
187:         }
188:         
189:         private HashSet<ThrownType> getThrownTypeHelperSum(final SumType input) {
190:                 final HashSet<ThrownType> output = new HashSet<ThrownType>();
191:                 return output;
192:         }
193:         
194:         private HashSet<ThrownType> getThrownTypeHelperPro(final ProductType input) {
195:                 final HashSet<ThrownType> output = new HashSet<ThrownType>();
196:                 return output;
197:         }
198:         
199:         /**
200:          * @param constructorAndOperationVisitor
201:          * @throws TaskException
202:          */
203:         public abstract void accept(final ConstructorOrOperationExceptionVisitor<TaskException> constructorAndOperationVisitor)
204:                         throws TaskException;
205: }