Skip to content

Package: TypeExtensionWithCondition

TypeExtensionWithCondition

nameinstructionbranchcomplexitylinemethod
TypeExtensionWithCondition(NamedVariableType, TypeFileManager, RegEx, NamedVariableType, RegEx)
M: 0 C: 16
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 6
100%
M: 0 C: 1
100%
accept(TypeExtensionVisitor)
M: 4 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 2 C: 0
0%
M: 1 C: 0
0%
checkValidation()
M: 5 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 2 C: 0
0%
M: 1 C: 0
0%
convertExpression(String)
M: 8 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%
executeCheckValidation()
M: 20 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 5 C: 0
0%
M: 1 C: 0
0%
getConditionExpression()
M: 3 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%
getConditionIdentifier()
M: 3 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%
getExpression()
M: 3 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%
getExtensionIdentifier()
M: 3 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%
getMeldung()
M: 3 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%
getTypeFileManager()
M: 3 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%
setConditionExpression(RegEx)
M: 0 C: 4
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 2
100%
M: 0 C: 1
100%
setConditionIdentifier(NamedVariableType)
M: 4 C: 11
73%
M: 1 C: 1
50%
M: 1 C: 1
50%
M: 1 C: 4
80%
M: 0 C: 1
100%
setExpression(RegEx)
M: 0 C: 4
100%
M: 0 C: 0
100%
M: 0 C: 1
100%
M: 0 C: 2
100%
M: 0 C: 1
100%
setMeldung(String)
M: 4 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: /**
2: *
3: */
4: package model.type;
5:
6: import dk.brics.automaton.Automaton;
7: import dk.brics.automaton.RegExp;
8:
9: /**
10: * @author Hendrik
11: * @author of changes Erik, Jannik
12: *
13: */
14: public class TypeExtensionWithCondition extends TypeExtension {
15:
16:         /**
17:          * The variable is used in the Typextensioncondition.
18:          */
19:         private NamedVariableType conditionIdentifier;
20:         /**
21:          * The value of the variable. Default Value is "yes";
22:          */
23:         private RegEx conditionExpression;
24:
25:         /**
26:          * The reference to the typeFileManager to get the VariableAssigment.
27:          */
28:         private final TypeFileManager typeFileManager;
29:
30:         /**
31:          *
32:          * @param variableIdentifier
33:          * the used Variable in TypExtension.
34:          * @param typeFileManager
35:          * the reference to the typeFileManager.
36:          * @param expression
37:          * the reference to the expressoion.
38:          * @param conditionIdentifier
39:          * the reference to the conditionIdentifier.
40:          * @param condition
41:          * the reference to the condition.
42:          */
43:         public TypeExtensionWithCondition(final NamedVariableType variableIdentifier,
44:                         final TypeFileManager typeFileManager, final RegEx expression,
45:                         final NamedVariableType conditionIdentifier, final RegEx condition) {
46:                 super(variableIdentifier);
47:                 this.typeFileManager = typeFileManager;
48:                 this.setExpression(expression);
49:                 this.setConditionIdentifier(conditionIdentifier);
50:                 this.setConditionExpression(condition);
51:         }
52:
53:         /**
54:          * @return the regEx
55:          */
56:         @Override
57:         public RegEx getExpression() {
58:                 return super.getExpression();
59:         }
60:
61:         /**
62:          * @param expression
63:          * the regEx to set
64:          */
65:         @Override
66:         public void setExpression(final RegEx expression) {
67:                 super.setExpression(expression);
68:         }
69:
70:         /**
71:          * @return the meldung
72:          */
73:         @Override
74:         public String getMeldung() {
75:                 return super.getMeldung();
76:         }
77:
78:         /**
79:          * @param meldung
80:          * the meldung to set
81:          */
82:         @Override
83:         public void setMeldung(final String meldung) {
84:                 super.setMeldung(meldung);
85:         }
86:
87:         /**
88:          * @return the variableIdentifier
89:          */
90:         @Override
91:         public NamedVariableType getExtensionIdentifier() {
92:                 return super.getExtensionIdentifier();
93:         }
94:
95:         /**
96:          * @return the value
97:          */
98:         public RegEx getConditionExpression() {
99:                 return this.conditionExpression;
100:         }
101:
102:         /**
103:          * @param regEx
104:          * the value to set
105:          */
106:         public void setConditionExpression(final RegEx regEx) {
107:                 this.conditionExpression = regEx;
108:         }
109:
110:         /**
111:          * get the getConditionIdentifier.
112:          *
113:          * @return the getConditionIdentifier
114:          */
115:         public NamedVariableType getConditionIdentifier() {
116:                 return conditionIdentifier;
117:         }
118:
119:         /**
120:          * @param namedVariableType
121:          * the variable to set
122:          */
123:         public void setConditionIdentifier(final NamedVariableType namedVariableType) {
124:•                if (this.conditionIdentifier != null) {
125:                         this.conditionIdentifier.deleteInCondition(this);
126:                 }
127:                 this.conditionIdentifier = namedVariableType;
128:                 this.conditionIdentifier.addInCondition(this);
129:
130:         }
131:
132:         /**
133:          * get the TypeFileManager.
134:          *
135:          * @return the TypeFileManager
136:          */
137:         public TypeFileManager getTypeFileManager() {
138:                 return typeFileManager;
139:         }
140:
141:         @Override
142:         public void accept(final TypeExtensionVisitor vis)
143:                         throws TypeDoesNotExistException, TypeExceptions {
144:                 vis.visit(this);
145:         }
146:
147:         /**
148:          * Check if condition of TypeExentionVariable is fulfilled. Set the VariableConditionFlag to
149:          * true if condition is true, otherwise set it to false.
150:          *
151:          * @throws ReferenceIsUnresolvedException
152:          * the ReferenceIsUnresolvedException
153:          * @throws IllegalArgumentException
154:          * the IllegalArgumentException
155:          */
156:         public void checkValidation()
157:                         throws IllegalArgumentException, ReferenceIsUnresolvedException {
158:                 this.setVariableConditionFlag(executeCheckValidation());
159:         }
160:
161:         /**
162:          * Creates an automat to check the condition.
163:          *
164:          * @return the flag.
165:          * @throws ReferenceIsUnresolvedException
166:          * the ReferenceIsUnresolvedException
167:          * @throws IllegalArgumentException
168:          * the IllegalArgumentException
169:          */
170:         private boolean executeCheckValidation()
171:                         throws IllegalArgumentException, ReferenceIsUnresolvedException {
172:                 final RegExp completeRegEx =
173:                                 new RegExp(convertExpression(this.getConditionExpression().toStringResolved()));
174:                 final Automaton automatonRegEx = completeRegEx.toAutomaton();
175:                 return automatonRegEx
176:                                 .run(this.getTypeFileManager().getAssignmentValue(this.getConditionIdentifier()));
177:         }
178:
179:         /**
180:          * Convert expression, if whole expressions are evaluated, this method will be dropped.
181:          *
182:          * @param expression
183:          * expression to be converted
184:          *
185:          * @return the converted expression
186:          */
187:         String convertExpression(final String expression) {
188:                 return expression.replace("^", "").replace("$", "");
189:
190:         }
191: }