| 1 |
|
|
| 2 |
|
|
| 3 |
|
|
| 4 |
|
|
| 5 |
|
|
| 6 |
|
|
| 7 |
|
|
| 8 |
|
|
| 9 |
|
|
| 10 |
|
|
| 11 |
|
|
| 12 |
|
|
| 13 |
|
|
| 14 |
|
|
| 15 |
|
|
| 16 |
|
package org.qedeq.kernel.bo.logic; |
| 17 |
|
|
| 18 |
|
import org.qedeq.base.trace.Trace; |
| 19 |
|
import org.qedeq.kernel.base.list.Atom; |
| 20 |
|
import org.qedeq.kernel.base.list.Element; |
| 21 |
|
import org.qedeq.kernel.base.list.ElementList; |
| 22 |
|
import org.qedeq.kernel.bo.logic.wf.ElementCheckException; |
| 23 |
|
import org.qedeq.kernel.bo.logic.wf.EverythingExists; |
| 24 |
|
import org.qedeq.kernel.bo.logic.wf.ExistenceChecker; |
| 25 |
|
import org.qedeq.kernel.bo.logic.wf.FormulaBasicErrors; |
| 26 |
|
import org.qedeq.kernel.bo.logic.wf.FormulaCheckException; |
| 27 |
|
import org.qedeq.kernel.bo.logic.wf.LogicalCheckExceptionList; |
| 28 |
|
import org.qedeq.kernel.bo.logic.wf.Operators; |
| 29 |
|
import org.qedeq.kernel.bo.logic.wf.TermCheckException; |
| 30 |
|
import org.qedeq.kernel.common.ModuleContext; |
| 31 |
|
import org.qedeq.kernel.dto.list.ElementSet; |
| 32 |
|
|
| 33 |
|
|
| 34 |
|
|
| 35 |
|
@link |
| 36 |
|
|
| 37 |
|
|
| 38 |
|
|
| 39 |
|
@link |
| 40 |
|
|
| 41 |
|
|
| 42 |
|
@author |
| 43 |
|
|
|
|
|
| 94.4% |
Uncovered Elements: 24 (429) |
Complexity: 114 |
Complexity Density: 0.41 |
|
| 44 |
|
public final class FormulaChecker implements Operators, FormulaBasicErrors { |
| 45 |
|
|
| 46 |
|
|
| 47 |
|
|
| 48 |
|
|
| 49 |
|
|
| 50 |
|
|
| 51 |
|
|
| 52 |
|
|
| 53 |
|
|
| 54 |
|
|
| 55 |
|
|
| 56 |
|
|
| 57 |
|
|
| 58 |
|
private static final Class CLASS = FormulaChecker.class; |
| 59 |
|
|
| 60 |
|
|
| 61 |
|
private final ModuleContext currentContext; |
| 62 |
|
|
| 63 |
|
|
| 64 |
|
private final ExistenceChecker existenceChecker; |
| 65 |
|
|
| 66 |
|
|
| 67 |
|
private final LogicalCheckExceptionList exceptions; |
| 68 |
|
|
| 69 |
|
|
| 70 |
|
|
| 71 |
|
|
| 72 |
|
|
| 73 |
|
@param |
| 74 |
|
@param |
| 75 |
|
@throws |
| 76 |
|
|
| 77 |
|
|
| 78 |
|
|
|
|
|
| 71.4% |
Uncovered Elements: 2 (7) |
Complexity: 3 |
Complexity Density: 0.6 |
|
| 79 |
1107
|
private FormulaChecker(final ModuleContext context,... |
| 80 |
|
final ExistenceChecker existenceChecker) { |
| 81 |
1107
|
this.existenceChecker = existenceChecker; |
| 82 |
1107
|
if (existenceChecker.identityOperatorExists() |
| 83 |
|
&& !existenceChecker.predicateExists(existenceChecker.getIdentityOperator(), 2)) { |
| 84 |
0
|
throw new IllegalArgumentException("identy predicate should exist, but it doesn't"); |
| 85 |
|
} |
| 86 |
1107
|
currentContext = new ModuleContext(context); |
| 87 |
1107
|
exceptions = new LogicalCheckExceptionList(); |
| 88 |
|
} |
| 89 |
|
|
| 90 |
|
|
| 91 |
|
@link |
| 92 |
|
|
| 93 |
|
|
| 94 |
|
@param |
| 95 |
|
@param |
| 96 |
|
@param |
| 97 |
|
@return |
| 98 |
|
|
|
|
|
| 100% |
Uncovered Elements: 0 (3) |
Complexity: 1 |
Complexity Density: 0.33 |
|
| 99 |
943
|
public static final LogicalCheckExceptionList checkFormula(final Element element,... |
| 100 |
|
final ModuleContext context, final ExistenceChecker existenceChecker) { |
| 101 |
943
|
final FormulaChecker checker = new FormulaChecker(context, existenceChecker); |
| 102 |
943
|
checker.checkFormula(element); |
| 103 |
943
|
return checker.exceptions; |
| 104 |
|
} |
| 105 |
|
|
| 106 |
|
|
| 107 |
|
@link |
| 108 |
|
|
| 109 |
|
|
| 110 |
|
|
| 111 |
|
@link |
| 112 |
|
|
| 113 |
|
@param |
| 114 |
|
@param |
| 115 |
|
@return |
| 116 |
|
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 117 |
51
|
public static final LogicalCheckExceptionList checkFormula(final Element element,... |
| 118 |
|
final ModuleContext context) { |
| 119 |
51
|
return checkFormula(element, context, EverythingExists.getInstance()); |
| 120 |
|
} |
| 121 |
|
|
| 122 |
|
|
| 123 |
|
@link |
| 124 |
|
|
| 125 |
|
|
| 126 |
|
@param |
| 127 |
|
@param |
| 128 |
|
@param |
| 129 |
|
@return |
| 130 |
|
|
|
|
|
| 100% |
Uncovered Elements: 0 (3) |
Complexity: 1 |
Complexity Density: 0.33 |
|
| 131 |
164
|
public static final LogicalCheckExceptionList checkTerm(final Element element,... |
| 132 |
|
final ModuleContext context, final ExistenceChecker existenceChecker) { |
| 133 |
164
|
final FormulaChecker checker = new FormulaChecker(context, existenceChecker); |
| 134 |
164
|
checker.checkTerm(element); |
| 135 |
164
|
return checker.exceptions; |
| 136 |
|
} |
| 137 |
|
|
| 138 |
|
|
| 139 |
|
@link |
| 140 |
|
|
| 141 |
|
|
| 142 |
|
@link |
| 143 |
|
|
| 144 |
|
@param |
| 145 |
|
@param |
| 146 |
|
@return |
| 147 |
|
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 148 |
21
|
public static final LogicalCheckExceptionList checkTerm(final Element element,... |
| 149 |
|
final ModuleContext context) { |
| 150 |
21
|
return checkTerm(element, context, EverythingExists.getInstance()); |
| 151 |
|
} |
| 152 |
|
|
| 153 |
|
|
| 154 |
|
@link |
| 155 |
|
|
| 156 |
|
@param |
| 157 |
|
|
|
|
|
| 100% |
Uncovered Elements: 0 (82) |
Complexity: 22 |
Complexity Density: 0.39 |
|
| 158 |
9422
|
private final void checkFormula(final Element element) {... |
| 159 |
9422
|
final String method = "checkFormula"; |
| 160 |
9422
|
Trace.begin(CLASS, this, method); |
| 161 |
9422
|
Trace.param(CLASS, this, method, "element", element); |
| 162 |
9422
|
final String context = getCurrentContext().getLocationWithinModule(); |
| 163 |
9422
|
Trace.param(CLASS, this, method, "context", context); |
| 164 |
9422
|
if (!checkList(element)) { |
| 165 |
7
|
return; |
| 166 |
|
} |
| 167 |
9415
|
final ElementList list = element.getList(); |
| 168 |
9415
|
final String listContext = context + ".getList()"; |
| 169 |
9415
|
setLocationWithinModule(listContext); |
| 170 |
9415
|
final String operator = list.getOperator(); |
| 171 |
9415
|
if (operator.equals(CONJUNCTION_OPERATOR) |
| 172 |
|
|| operator.equals(DISJUNCTION_OPERATOR) |
| 173 |
|
|| operator.equals(IMPLICATION_OPERATOR) |
| 174 |
|
|| operator.equals(EQUIVALENCE_OPERATOR)) { |
| 175 |
3065
|
Trace.trace(CLASS, this, method, |
| 176 |
|
"one of (and, or, implication, equivalence) operator found"); |
| 177 |
3065
|
if (list.size() <= 1) { |
| 178 |
9
|
handleFormulaCheckException(MORE_THAN_ONE_ARGUMENT_EXPECTED, |
| 179 |
|
MORE_THAN_ONE_ARGUMENT_EXPECTED_TEXT + "\"" |
| 180 |
|
+ operator + "\"", element, getCurrentContext()); |
| 181 |
9
|
return; |
| 182 |
|
} |
| 183 |
3056
|
if (operator.equals(IMPLICATION_OPERATOR) && list.size() != 2) { |
| 184 |
1
|
handleFormulaCheckException(EXACTLY_TWO_ARGUMENTS_EXPECTED, |
| 185 |
|
EXACTLY_TWO_ARGUMENTS_EXPECTED_TEXT + "\"" |
| 186 |
|
+ operator + "\"", element, getCurrentContext()); |
| 187 |
1
|
return; |
| 188 |
|
} |
| 189 |
9924
|
for (int i = 0; i < list.size(); i++) { |
| 190 |
6869
|
setLocationWithinModule(listContext + ".getElement(" + i + ")"); |
| 191 |
6869
|
checkFormula(list.getElement(i)); |
| 192 |
|
} |
| 193 |
3055
|
setLocationWithinModule(listContext); |
| 194 |
3055
|
checkFreeAndBoundDisjunct(0, list); |
| 195 |
6350
|
} else if (operator.equals(NEGATION_OPERATOR)) { |
| 196 |
312
|
Trace.trace(CLASS, this, method, "negation operator found"); |
| 197 |
312
|
setLocationWithinModule(listContext); |
| 198 |
312
|
if (list.size() != 1) { |
| 199 |
2
|
handleFormulaCheckException(EXACTLY_ONE_ARGUMENT_EXPECTED, |
| 200 |
|
EXACTLY_ONE_ARGUMENT_EXPECTED_TEXT + "\"" + operator + "\"", |
| 201 |
|
element, getCurrentContext()); |
| 202 |
2
|
return; |
| 203 |
|
} |
| 204 |
310
|
setLocationWithinModule(listContext + ".getElement(0)"); |
| 205 |
310
|
checkFormula(list.getElement(0)); |
| 206 |
6038
|
} else if (operator.equals(PREDICATE_VARIABLE) |
| 207 |
|
|| operator.equals(PREDICATE_CONSTANT)) { |
| 208 |
5060
|
Trace.trace(CLASS, this, method, "predicate operator found"); |
| 209 |
5060
|
setLocationWithinModule(listContext); |
| 210 |
5060
|
if (list.size() < 1) { |
| 211 |
2
|
handleFormulaCheckException(AT_LEAST_ONE_ARGUMENT_EXPECTED, |
| 212 |
|
AT_LEAST_ONE_ARGUMENT_EXPECTED_TEXT + "\"" + operator + "\"", |
| 213 |
|
element, getCurrentContext()); |
| 214 |
2
|
return; |
| 215 |
|
} |
| 216 |
|
|
| 217 |
5058
|
setLocationWithinModule(listContext + ".getElement(0)"); |
| 218 |
5058
|
if (!checkAtomFirst(list.getElement(0))) { |
| 219 |
8
|
return; |
| 220 |
|
} |
| 221 |
|
|
| 222 |
|
|
| 223 |
10067
|
for (int i = 1; i < list.size(); i++) { |
| 224 |
5017
|
setLocationWithinModule(listContext + ".getElement(" + i + ")"); |
| 225 |
5017
|
checkTerm(list.getElement(i)); |
| 226 |
|
} |
| 227 |
|
|
| 228 |
5050
|
setLocationWithinModule(listContext); |
| 229 |
5050
|
checkFreeAndBoundDisjunct(1, list); |
| 230 |
|
|
| 231 |
|
|
| 232 |
5050
|
if (PREDICATE_CONSTANT.equals(operator) && !existenceChecker.predicateExists( |
| 233 |
|
list.getElement(0).getAtom().getString(), list.size() - 1)) { |
| 234 |
9
|
handleFormulaCheckException(UNKNOWN_PREDICATE_CONSTANT, |
| 235 |
|
UNKNOWN_PREDICATE_CONSTANT_TEXT + "\"" |
| 236 |
|
+ list.getElement(0).getAtom().getString() + "\" [" + (list.size() - 1) + "]", |
| 237 |
|
element, getCurrentContext()); |
| 238 |
|
} |
| 239 |
|
|
| 240 |
978
|
} else if (operator.equals(EXISTENTIAL_QUANTIFIER_OPERATOR) |
| 241 |
|
|| operator.equals(UNIQUE_EXISTENTIAL_QUANTIFIER_OPERATOR) |
| 242 |
|
|| operator.equals(UNIVERSAL_QUANTIFIER_OPERATOR)) { |
| 243 |
972
|
Trace.trace(CLASS, this, method, "quantifier found"); |
| 244 |
972
|
setLocationWithinModule(context); |
| 245 |
972
|
checkQuantifier(element); |
| 246 |
|
} else { |
| 247 |
6
|
setLocationWithinModule(listContext + ".getOperator()"); |
| 248 |
6
|
handleFormulaCheckException(UNKNOWN_LOGICAL_OPERATOR, |
| 249 |
|
UNKNOWN_LOGICAL_OPERATOR_TEXT + "\"" + operator + "\"", |
| 250 |
|
element, getCurrentContext()); |
| 251 |
|
} |
| 252 |
|
|
| 253 |
9393
|
setLocationWithinModule(context); |
| 254 |
9393
|
Trace.end(CLASS, this, method); |
| 255 |
|
} |
| 256 |
|
|
| 257 |
|
|
| 258 |
|
|
| 259 |
|
|
| 260 |
|
@param |
| 261 |
|
@throws |
| 262 |
|
|
| 263 |
|
|
|
|
|
| 79.2% |
Uncovered Elements: 11 (53) |
Complexity: 12 |
Complexity Density: 0.31 |
|
| 264 |
972
|
private void checkQuantifier(final Element element) {... |
| 265 |
972
|
final String method = "checkQuantifier"; |
| 266 |
972
|
Trace.begin(CLASS, this, method); |
| 267 |
972
|
Trace.param(CLASS, this, method, "element", element); |
| 268 |
|
|
| 269 |
972
|
final String context = getCurrentContext().getLocationWithinModule(); |
| 270 |
972
|
Trace.param(CLASS, this, method, "context", context); |
| 271 |
972
|
checkList(element); |
| 272 |
972
|
final ElementList list = element.getList(); |
| 273 |
972
|
final String listContext = context + ".getList()"; |
| 274 |
972
|
setLocationWithinModule(listContext); |
| 275 |
972
|
final String operator = list.getOperator(); |
| 276 |
972
|
if (!operator.equals(EXISTENTIAL_QUANTIFIER_OPERATOR) |
| 277 |
|
&& operator.equals(UNIQUE_EXISTENTIAL_QUANTIFIER_OPERATOR) |
| 278 |
|
&& operator.equals(UNIVERSAL_QUANTIFIER_OPERATOR)) { |
| 279 |
0
|
throw new IllegalArgumentException("quantifier element expected but found: " |
| 280 |
|
+ element.toString()); |
| 281 |
|
} |
| 282 |
972
|
if (list.size() < 2 || list.size() > 3) { |
| 283 |
0
|
handleFormulaCheckException(EXACTLY_TWO_OR_THREE_ARGUMENTS_EXPECTED, |
| 284 |
|
EXACTLY_TWO_OR_THREE_ARGUMENTS_EXPECTED_TEXT, element, getCurrentContext()); |
| 285 |
0
|
return; |
| 286 |
|
} |
| 287 |
|
|
| 288 |
|
|
| 289 |
972
|
if (operator.equals(UNIQUE_EXISTENTIAL_QUANTIFIER_OPERATOR) |
| 290 |
|
&& !existenceChecker.identityOperatorExists()) { |
| 291 |
0
|
setLocationWithinModule(listContext + ".getOperator()"); |
| 292 |
0
|
handleFormulaCheckException(EQUALITY_PREDICATE_NOT_YET_DEFINED, |
| 293 |
|
EQUALITY_PREDICATE_NOT_YET_DEFINED_TEXT, element, getCurrentContext()); |
| 294 |
|
} |
| 295 |
|
|
| 296 |
|
|
| 297 |
972
|
setLocationWithinModule(listContext + ".getElement(" + 0 + ")"); |
| 298 |
972
|
checkSubjectVariable(list.getElement(0)); |
| 299 |
|
|
| 300 |
|
|
| 301 |
972
|
setLocationWithinModule(listContext + ".getElement(" + 1 + ")"); |
| 302 |
972
|
checkFormula(list.getElement(1)); |
| 303 |
|
|
| 304 |
972
|
setLocationWithinModule(listContext); |
| 305 |
|
|
| 306 |
972
|
if (FormulaChecker.getBoundSubjectVariables(list.getElement(1)).contains( |
| 307 |
|
list.getElement(0))) { |
| 308 |
10
|
handleFormulaCheckException(SUBJECT_VARIABLE_ALREADY_BOUND_IN_FORMULA, |
| 309 |
|
SUBJECT_VARIABLE_ALREADY_BOUND_IN_FORMULA_TEXT, list.getElement(1), |
| 310 |
|
getCurrentContext()); |
| 311 |
|
} |
| 312 |
972
|
if (list.size() > 3) { |
| 313 |
0
|
handleFormulaCheckException(EXACTLY_TWO_OR_THREE_ARGUMENTS_EXPECTED, |
| 314 |
|
EXACTLY_TWO_OR_THREE_ARGUMENTS_EXPECTED_TEXT, list, |
| 315 |
|
getCurrentContext()); |
| 316 |
0
|
return; |
| 317 |
|
} |
| 318 |
972
|
if (list.size() > 2) { |
| 319 |
|
|
| 320 |
75
|
setLocationWithinModule(listContext + ".getElement(" + 2 + ")"); |
| 321 |
75
|
checkFormula(list.getElement(2)); |
| 322 |
|
|
| 323 |
|
|
| 324 |
75
|
setLocationWithinModule(listContext); |
| 325 |
75
|
if (FormulaChecker.getBoundSubjectVariables(list.getElement(2)).contains( |
| 326 |
|
list.getElement(0))) { |
| 327 |
3
|
handleFormulaCheckException(SUBJECT_VARIABLE_ALREADY_BOUND_IN_FORMULA, |
| 328 |
|
SUBJECT_VARIABLE_ALREADY_BOUND_IN_FORMULA_TEXT, list.getElement(2), |
| 329 |
|
getCurrentContext()); |
| 330 |
3
|
return; |
| 331 |
|
} |
| 332 |
72
|
setLocationWithinModule(listContext); |
| 333 |
72
|
checkFreeAndBoundDisjunct(1, list); |
| 334 |
|
} |
| 335 |
|
|
| 336 |
969
|
setLocationWithinModule(context); |
| 337 |
969
|
Trace.end(CLASS, this, method); |
| 338 |
|
} |
| 339 |
|
|
| 340 |
|
|
| 341 |
|
@link |
| 342 |
|
|
| 343 |
|
@param |
| 344 |
|
|
|
|
|
| 100% |
Uncovered Elements: 0 (77) |
Complexity: 18 |
Complexity Density: 0.35 |
|
| 345 |
6931
|
private void checkTerm(final Element element) {... |
| 346 |
6931
|
final String method = "checkTerm"; |
| 347 |
6931
|
Trace.begin(CLASS, this, method); |
| 348 |
6931
|
Trace.param(CLASS, this, method, "element", element); |
| 349 |
|
|
| 350 |
6931
|
final String context = getCurrentContext().getLocationWithinModule(); |
| 351 |
6931
|
Trace.param(CLASS, this, method, "context", context); |
| 352 |
6931
|
if (!checkList(element)) { |
| 353 |
4
|
return; |
| 354 |
|
} |
| 355 |
6927
|
final ElementList list = element.getList(); |
| 356 |
6927
|
final String listContext = context + ".getList()"; |
| 357 |
6927
|
setLocationWithinModule(listContext); |
| 358 |
6927
|
final String operator = list.getOperator(); |
| 359 |
6927
|
if (operator.equals(SUBJECT_VARIABLE)) { |
| 360 |
5167
|
checkSubjectVariable(element); |
| 361 |
1760
|
} else if (operator.equals(FUNCTION_CONSTANT) |
| 362 |
|
|| operator.equals(FUNCTION_VARIABLE)) { |
| 363 |
|
|
| 364 |
|
|
| 365 |
1494
|
if (operator.equals(FUNCTION_CONSTANT) && list.size() < 1) { |
| 366 |
1
|
handleTermCheckException(AT_LEAST_ONE_ARGUMENT_EXPECTED, |
| 367 |
|
AT_LEAST_ONE_ARGUMENT_EXPECTED_TEXT, element, getCurrentContext()); |
| 368 |
1
|
return; |
| 369 |
|
} |
| 370 |
|
|
| 371 |
|
|
| 372 |
1493
|
if (operator.equals(FUNCTION_VARIABLE) && list.size() < 2) { |
| 373 |
2
|
handleTermCheckException(MORE_THAN_ONE_ARGUMENT_EXPECTED, |
| 374 |
|
MORE_THAN_ONE_ARGUMENT_EXPECTED_TEXT, element, getCurrentContext()); |
| 375 |
2
|
return; |
| 376 |
|
} |
| 377 |
|
|
| 378 |
|
|
| 379 |
1491
|
setLocationWithinModule(listContext + ".getElement(0)"); |
| 380 |
1491
|
if (!checkAtomFirst(list.getElement(0))) { |
| 381 |
7
|
return; |
| 382 |
|
} |
| 383 |
|
|
| 384 |
|
|
| 385 |
1484
|
setLocationWithinModule(listContext); |
| 386 |
3234
|
for (int i = 1; i < list.size(); i++) { |
| 387 |
1750
|
setLocationWithinModule(listContext + ".getElement(" + i + ")"); |
| 388 |
1750
|
checkTerm(list.getElement(i)); |
| 389 |
|
} |
| 390 |
|
|
| 391 |
1484
|
setLocationWithinModule(listContext); |
| 392 |
1484
|
checkFreeAndBoundDisjunct(1, list); |
| 393 |
|
|
| 394 |
|
|
| 395 |
1484
|
setLocationWithinModule(listContext); |
| 396 |
1484
|
if (FUNCTION_CONSTANT.equals(operator) && !existenceChecker.functionExists( |
| 397 |
|
list.getElement(0).getAtom().getString(), list.size() - 1)) { |
| 398 |
2
|
handleFormulaCheckException(UNKNOWN_FUNCTION_CONSTANT, |
| 399 |
|
UNKNOWN_FUNCTION_CONSTANT_TEXT + "\"" |
| 400 |
|
+ list.getElement(0).getAtom().getString() + "\"", element, |
| 401 |
|
getCurrentContext()); |
| 402 |
|
} |
| 403 |
|
|
| 404 |
266
|
} else if (operator.equals(CLASS_OP)) { |
| 405 |
|
|
| 406 |
255
|
if (list.size() != 2) { |
| 407 |
2
|
handleTermCheckException(EXACTLY_TWO_ARGUMENTS_EXPECTED, |
| 408 |
|
EXACTLY_TWO_ARGUMENTS_EXPECTED_TEXT, element, getCurrentContext()); |
| 409 |
2
|
return; |
| 410 |
|
} |
| 411 |
|
|
| 412 |
253
|
setLocationWithinModule(listContext + ".getElement(" + 0 + ")"); |
| 413 |
253
|
if (!isSubjectVariable(list.getElement(0))) { |
| 414 |
1
|
handleTermCheckException(SUBJECT_VARIABLE_EXPECTED, |
| 415 |
|
SUBJECT_VARIABLE_EXPECTED_TEXT, element, getCurrentContext()); |
| 416 |
|
} |
| 417 |
|
|
| 418 |
|
|
| 419 |
253
|
setLocationWithinModule(listContext + ".getElement(" + 1 + ")"); |
| 420 |
253
|
checkFormula(list.getElement(1)); |
| 421 |
|
|
| 422 |
|
|
| 423 |
253
|
setLocationWithinModule(listContext); |
| 424 |
253
|
if (!existenceChecker.classOperatorExists()) { |
| 425 |
2
|
handleFormulaCheckException(CLASS_OPERATOR_STILL_UNKNOWN, |
| 426 |
|
CLASS_OPERATOR_STILL_UNKNOWN_TEXT, element, getCurrentContext()); |
| 427 |
|
} |
| 428 |
|
|
| 429 |
|
|
| 430 |
253
|
setLocationWithinModule(listContext + ".getElement(" + 0 + ")"); |
| 431 |
253
|
if (FormulaChecker.getBoundSubjectVariables(list.getElement(1)).contains( |
| 432 |
|
list.getElement(0))) { |
| 433 |
1
|
handleTermCheckException(SUBJECT_VARIABLE_ALREADY_BOUND_IN_FORMULA, |
| 434 |
|
SUBJECT_VARIABLE_ALREADY_BOUND_IN_FORMULA_TEXT, list.getElement(0), |
| 435 |
|
getCurrentContext()); |
| 436 |
|
} |
| 437 |
|
|
| 438 |
|
} else { |
| 439 |
11
|
setLocationWithinModule(listContext + ".getOperator()"); |
| 440 |
11
|
handleTermCheckException(UNKNOWN_TERM_OPERATOR, |
| 441 |
|
UNKNOWN_TERM_OPERATOR_TEXT + "\"" + operator + "\"", element, getCurrentContext()); |
| 442 |
|
} |
| 443 |
|
|
| 444 |
6915
|
setLocationWithinModule(context); |
| 445 |
6915
|
Trace.end(CLASS, this, method); |
| 446 |
|
} |
| 447 |
|
|
| 448 |
|
|
| 449 |
|
|
| 450 |
|
|
| 451 |
|
|
| 452 |
|
@param |
| 453 |
|
@param |
| 454 |
|
|
|
|
|
| 100% |
Uncovered Elements: 0 (22) |
Complexity: 4 |
Complexity Density: 0.25 |
|
| 455 |
9661
|
private void checkFreeAndBoundDisjunct(final int start,... |
| 456 |
|
final ElementList list) { |
| 457 |
|
|
| 458 |
9661
|
final String context = getCurrentContext().getLocationWithinModule(); |
| 459 |
9661
|
final ElementSet free = new ElementSet(); |
| 460 |
9661
|
final ElementSet bound = new ElementSet(); |
| 461 |
23441
|
for (int i = start; i < list.size(); i++) { |
| 462 |
13780
|
setLocationWithinModule(context + ".getElement(" + i + ")"); |
| 463 |
13780
|
final ElementSet newFree |
| 464 |
|
= getFreeSubjectVariables(list.getElement(i)); |
| 465 |
13780
|
final ElementSet newBound |
| 466 |
|
= FormulaChecker.getBoundSubjectVariables(list.getElement(i)); |
| 467 |
13780
|
final ElementSet interBound = newFree.newIntersection(bound); |
| 468 |
13780
|
if (!interBound.isEmpty()) { |
| 469 |
20
|
handleFormulaCheckException(FREE_VARIABLE_ALREADY_BOUND, |
| 470 |
|
FREE_VARIABLE_ALREADY_BOUND_TEXT |
| 471 |
|
+ interBound, list.getElement(i), getCurrentContext()); |
| 472 |
|
} |
| 473 |
13780
|
final ElementSet interFree = newBound.newIntersection(free); |
| 474 |
13780
|
if (!interFree.isEmpty()) { |
| 475 |
16
|
handleFormulaCheckException(BOUND_VARIABLE_ALREADY_FREE, |
| 476 |
|
BOUND_VARIABLE_ALREADY_FREE_TEXT |
| 477 |
|
+ interFree, list.getElement(i), getCurrentContext()); |
| 478 |
|
} |
| 479 |
13780
|
bound.union(newBound); |
| 480 |
13780
|
free.union(newFree); |
| 481 |
|
} |
| 482 |
|
|
| 483 |
9661
|
setLocationWithinModule(context); |
| 484 |
|
} |
| 485 |
|
|
| 486 |
|
|
| 487 |
|
|
| 488 |
|
@link |
| 489 |
|
|
| 490 |
|
@param |
| 491 |
|
@return |
| 492 |
|
|
|
|
|
| 75% |
Uncovered Elements: 6 (24) |
Complexity: 12 |
Complexity Density: 0.86 |
|
| 493 |
52308
|
private final boolean isSubjectVariable(final Element element) {... |
| 494 |
52308
|
if (element == null || !element.isList() || element.getList() == null) { |
| 495 |
14876
|
return false; |
| 496 |
|
} |
| 497 |
37432
|
final ElementList list = element.getList(); |
| 498 |
37432
|
if (list.getOperator().equals(SUBJECT_VARIABLE)) { |
| 499 |
16217
|
if (list.size() != 1) { |
| 500 |
0
|
return false; |
| 501 |
|
} |
| 502 |
16217
|
final Element first = element.getList().getElement(0); |
| 503 |
16217
|
if (first == null || !first.isAtom() || first.getAtom() == null) { |
| 504 |
0
|
return false; |
| 505 |
|
} |
| 506 |
16217
|
final Atom atom = first.getAtom(); |
| 507 |
16217
|
if (atom.getString() == null || atom.getAtom().getString() == null |
| 508 |
|
|| atom.getString().length() == 0) { |
| 509 |
0
|
return false; |
| 510 |
|
} |
| 511 |
|
} else { |
| 512 |
21215
|
return false; |
| 513 |
|
} |
| 514 |
16217
|
return true; |
| 515 |
|
} |
| 516 |
|
|
| 517 |
|
|
| 518 |
|
|
| 519 |
|
@link |
| 520 |
|
|
| 521 |
|
@param |
| 522 |
|
@return |
| 523 |
|
|
|
|
|
| 91.7% |
Uncovered Elements: 2 (24) |
Complexity: 5 |
Complexity Density: 0.31 |
|
| 524 |
6139
|
private boolean checkSubjectVariable(final Element element) {... |
| 525 |
|
|
| 526 |
|
|
| 527 |
6139
|
final String context = getCurrentContext().getLocationWithinModule(); |
| 528 |
6139
|
if (!checkList(element)) { |
| 529 |
0
|
return false; |
| 530 |
|
} |
| 531 |
6139
|
setLocationWithinModule(context + ".getList()"); |
| 532 |
6139
|
if (element.getList().getOperator().equals(SUBJECT_VARIABLE)) { |
| 533 |
6136
|
if (element.getList().size() != 1) { |
| 534 |
2
|
handleFormulaCheckException(EXACTLY_ONE_ARGUMENT_EXPECTED, |
| 535 |
|
EXACTLY_ONE_ARGUMENT_EXPECTED_TEXT, element.getList(), getCurrentContext()); |
| 536 |
2
|
return false; |
| 537 |
|
} |
| 538 |
|
|
| 539 |
6134
|
setLocationWithinModule(context + ".getList().getElement(0)"); |
| 540 |
6134
|
if (checkAtomFirst(element.getList().getElement(0))) { |
| 541 |
6133
|
return false; |
| 542 |
|
} |
| 543 |
|
} else { |
| 544 |
3
|
setLocationWithinModule(context + ".getList().getOperator()"); |
| 545 |
3
|
handleFormulaCheckException(SUBJECT_VARIABLE_EXPECTED, |
| 546 |
|
SUBJECT_VARIABLE_EXPECTED_TEXT, element, getCurrentContext()); |
| 547 |
3
|
return false; |
| 548 |
|
} |
| 549 |
|
|
| 550 |
1
|
setLocationWithinModule(context); |
| 551 |
1
|
return true; |
| 552 |
|
} |
| 553 |
|
|
| 554 |
|
|
| 555 |
|
|
| 556 |
|
|
| 557 |
|
|
| 558 |
|
@param |
| 559 |
|
@return |
| 560 |
|
|
|
|
|
| 100% |
Uncovered Elements: 0 (23) |
Complexity: 9 |
Complexity Density: 0.69 |
|
| 561 |
52055
|
private final ElementSet getFreeSubjectVariables(final Element element) {... |
| 562 |
52055
|
final ElementSet free = new ElementSet(); |
| 563 |
52055
|
if (isSubjectVariable(element)) { |
| 564 |
15965
|
free.add(element); |
| 565 |
36090
|
} else if (element.isList()) { |
| 566 |
21214
|
final ElementList list = element.getList(); |
| 567 |
21214
|
final String operator = list.getOperator(); |
| 568 |
21214
|
if (operator.equals(EXISTENTIAL_QUANTIFIER_OPERATOR) |
| 569 |
|
|| operator.equals(UNIQUE_EXISTENTIAL_QUANTIFIER_OPERATOR) |
| 570 |
|
|| operator.equals(UNIVERSAL_QUANTIFIER_OPERATOR) |
| 571 |
|
|| operator.equals(CLASS_OP)) { |
| 572 |
3947
|
for (int i = 1; i < list.size(); i++) { |
| 573 |
1999
|
free.union(getFreeSubjectVariables(list.getElement(i))); |
| 574 |
|
} |
| 575 |
1948
|
free.remove(list.getElement(0)); |
| 576 |
|
} else { |
| 577 |
55542
|
for (int i = 0; i < list.size(); i++) { |
| 578 |
36276
|
free.union(getFreeSubjectVariables(list.getElement(i))); |
| 579 |
|
} |
| 580 |
|
} |
| 581 |
|
} |
| 582 |
52055
|
return free; |
| 583 |
|
} |
| 584 |
|
|
| 585 |
|
|
| 586 |
|
|
| 587 |
|
|
| 588 |
|
@param |
| 589 |
|
@return |
| 590 |
|
|
|
|
|
| 100% |
Uncovered Elements: 0 (19) |
Complexity: 8 |
Complexity Density: 0.73 |
|
| 591 |
79120
|
public static final ElementSet getBoundSubjectVariables(final Element element) {... |
| 592 |
79120
|
final ElementSet bound = new ElementSet(); |
| 593 |
79120
|
if (element.isList()) { |
| 594 |
43187
|
ElementList list = element.getList(); |
| 595 |
43187
|
final String operator = list.getOperator(); |
| 596 |
|
|
| 597 |
43187
|
if (operator.equals(EXISTENTIAL_QUANTIFIER_OPERATOR) |
| 598 |
|
|| operator.equals(UNIQUE_EXISTENTIAL_QUANTIFIER_OPERATOR) |
| 599 |
|
|| operator.equals(UNIVERSAL_QUANTIFIER_OPERATOR) |
| 600 |
|
|| operator.equals(CLASS_OP)) { |
| 601 |
|
|
| 602 |
2221
|
bound.add(list.getElement(0)); |
| 603 |
|
|
| 604 |
4509
|
for (int i = 1; i < list.size(); i++) { |
| 605 |
2288
|
bound.union(FormulaChecker.getBoundSubjectVariables( |
| 606 |
|
list.getElement(i))); |
| 607 |
|
} |
| 608 |
|
} else { |
| 609 |
|
|
| 610 |
102718
|
for (int i = 0; i < list.size(); i++) { |
| 611 |
61752
|
bound.union(FormulaChecker.getBoundSubjectVariables(list.getElement(i))); |
| 612 |
|
} |
| 613 |
|
} |
| 614 |
|
} |
| 615 |
79120
|
return bound; |
| 616 |
|
} |
| 617 |
|
|
| 618 |
|
|
| 619 |
|
|
| 620 |
|
|
| 621 |
|
|
| 622 |
|
@param |
| 623 |
|
@return |
| 624 |
|
|
|
|
|
| 100% |
Uncovered Elements: 0 (32) |
Complexity: 6 |
Complexity Density: 0.27 |
|
| 625 |
23464
|
private boolean checkList(final Element element) {... |
| 626 |
|
|
| 627 |
23464
|
final String context = getCurrentContext().getLocationWithinModule(); |
| 628 |
23464
|
if (element == null) { |
| 629 |
2
|
handleElementCheckException(ELEMENT_MUST_NOT_BE_NULL, |
| 630 |
|
ELEMENT_MUST_NOT_BE_NULL_TEXT, null, getCurrentContext()); |
| 631 |
2
|
return false; |
| 632 |
|
} |
| 633 |
23462
|
if (!element.isList()) { |
| 634 |
2
|
handleElementCheckException(LIST_EXPECTED, |
| 635 |
|
LIST_EXPECTED_TEXT, element, getCurrentContext()); |
| 636 |
2
|
return false; |
| 637 |
|
} |
| 638 |
23460
|
final ElementList list = element.getList(); |
| 639 |
23460
|
setLocationWithinModule(context + ".getList()"); |
| 640 |
23460
|
if (list == null) { |
| 641 |
2
|
handleElementCheckException(LIST_MUST_NOT_BE_NULL, |
| 642 |
|
LIST_MUST_NOT_BE_NULL_TEXT, element, getCurrentContext()); |
| 643 |
2
|
return false; |
| 644 |
|
} |
| 645 |
23458
|
final String operator = list.getOperator(); |
| 646 |
23458
|
setLocationWithinModule(context + ".getList().getOperator()"); |
| 647 |
23458
|
if (operator == null) { |
| 648 |
2
|
handleElementCheckException(OPERATOR_CONTENT_MUST_NOT_BE_NULL, |
| 649 |
|
OPERATOR_CONTENT_MUST_NOT_BE_NULL_TEXT , element, |
| 650 |
|
getCurrentContext()); |
| 651 |
2
|
return false; |
| 652 |
|
} |
| 653 |
23456
|
if (operator.length() == 0) { |
| 654 |
3
|
handleElementCheckException(OPERATOR_CONTENT_MUST_NOT_BE_EMPTY, |
| 655 |
|
OPERATOR_CONTENT_MUST_NOT_BE_EMPTY_TEXT + "\"" |
| 656 |
|
+ operator + "\"", element, getCurrentContext()); |
| 657 |
3
|
return false; |
| 658 |
|
} |
| 659 |
|
|
| 660 |
23453
|
setLocationWithinModule(context); |
| 661 |
23453
|
return true; |
| 662 |
|
} |
| 663 |
|
|
| 664 |
|
|
| 665 |
|
|
| 666 |
|
|
| 667 |
|
|
| 668 |
|
@param |
| 669 |
|
@return |
| 670 |
|
|
|
|
|
| 90% |
Uncovered Elements: 3 (30) |
Complexity: 6 |
Complexity Density: 0.3 |
|
| 671 |
12683
|
private boolean checkAtomFirst(final Element element) {... |
| 672 |
|
|
| 673 |
12683
|
final String context = getCurrentContext().getLocationWithinModule(); |
| 674 |
12683
|
if (element == null) { |
| 675 |
0
|
handleElementCheckException(ELEMENT_MUST_NOT_BE_NULL, |
| 676 |
|
ELEMENT_MUST_NOT_BE_NULL_TEXT, null, getCurrentContext()); |
| 677 |
0
|
return false; |
| 678 |
|
} |
| 679 |
12683
|
if (!element.isAtom()) { |
| 680 |
9
|
handleElementCheckException(FIRST_ARGUMENT_MUST_BE_AN_ATOM, |
| 681 |
|
FIRST_ARGUMENT_MUST_BE_AN_ATOM_TEXT, element, getCurrentContext()); |
| 682 |
9
|
return false; |
| 683 |
|
} |
| 684 |
12674
|
final Atom atom = element.getAtom(); |
| 685 |
12674
|
setLocationWithinModule(context + ".getAtom()"); |
| 686 |
12674
|
if (atom == null) { |
| 687 |
2
|
handleElementCheckException(ATOM_MUST_NOT_BE_NULL, |
| 688 |
|
ATOM_MUST_NOT_BE_NULL_TEXT, element, getCurrentContext()); |
| 689 |
2
|
return false; |
| 690 |
|
} |
| 691 |
12672
|
if (atom.getString() == null) { |
| 692 |
2
|
handleElementCheckException(ATOM_CONTENT_MUST_NOT_BE_NULL, |
| 693 |
|
ATOM_CONTENT_MUST_NOT_BE_NULL_TEXT, element, getCurrentContext()); |
| 694 |
2
|
return false; |
| 695 |
|
} |
| 696 |
12670
|
if (atom.getString().length() == 0) { |
| 697 |
3
|
handleElementCheckException(ATOM_CONTENT_MUST_NOT_BE_EMPTY, |
| 698 |
|
ATOM_CONTENT_MUST_NOT_BE_EMPTY_TEXT, element, getCurrentContext()); |
| 699 |
3
|
return false; |
| 700 |
|
} |
| 701 |
|
|
| 702 |
12667
|
setLocationWithinModule(context); |
| 703 |
12667
|
return true; |
| 704 |
|
} |
| 705 |
|
|
| 706 |
|
|
| 707 |
|
@link |
| 708 |
|
|
| 709 |
|
@param |
| 710 |
|
@param |
| 711 |
|
@param |
| 712 |
|
@param |
| 713 |
|
|
|
|
|
| 100% |
Uncovered Elements: 0 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
|
| 714 |
87
|
private void handleFormulaCheckException(final int code, final String msg,... |
| 715 |
|
final Element element, final ModuleContext context) { |
| 716 |
87
|
final FormulaCheckException ex = new FormulaCheckException(code, msg, element, context); |
| 717 |
87
|
exceptions.add(ex); |
| 718 |
|
} |
| 719 |
|
|
| 720 |
|
|
| 721 |
|
@link |
| 722 |
|
|
| 723 |
|
@param |
| 724 |
|
@param |
| 725 |
|
@param |
| 726 |
|
@param |
| 727 |
|
|
|
|
|
| 100% |
Uncovered Elements: 0 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
|
| 728 |
18
|
private void handleTermCheckException(final int code, final String msg,... |
| 729 |
|
final Element element, final ModuleContext context) { |
| 730 |
18
|
final TermCheckException ex = new TermCheckException(code, msg, element, context); |
| 731 |
18
|
exceptions.add(ex); |
| 732 |
|
} |
| 733 |
|
|
| 734 |
|
|
| 735 |
|
@link |
| 736 |
|
|
| 737 |
|
@param |
| 738 |
|
@param |
| 739 |
|
@param |
| 740 |
|
@param |
| 741 |
|
|
|
|
|
| 100% |
Uncovered Elements: 0 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
|
| 742 |
27
|
private void handleElementCheckException(final int code, final String msg,... |
| 743 |
|
final Element element, final ModuleContext context) { |
| 744 |
27
|
final ElementCheckException ex = new ElementCheckException(code, msg, element, context); |
| 745 |
27
|
exceptions.add(ex); |
| 746 |
|
} |
| 747 |
|
|
| 748 |
|
|
| 749 |
|
|
| 750 |
|
|
| 751 |
|
@param |
| 752 |
|
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 753 |
209584
|
protected void setLocationWithinModule(final String locationWithinModule) {... |
| 754 |
209584
|
getCurrentContext().setLocationWithinModule(locationWithinModule); |
| 755 |
|
} |
| 756 |
|
|
| 757 |
|
|
| 758 |
|
|
| 759 |
|
|
| 760 |
|
@return |
| 761 |
|
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
| 762 |
278988
|
protected final ModuleContext getCurrentContext() {... |
| 763 |
278988
|
return currentContext; |
| 764 |
|
} |
| 765 |
|
|
| 766 |
|
} |