MCPcopy Create free account
hub / github.com/BaseXdb/basex / simplify

Method simplify

basex-core/src/main/java/org/basex/query/expr/Catch.java:118–147  ·  view source on GitHub ↗

Removes redundant tests. @param list current tests @param cc compilation context @return if catch clause contains relevant tests

(final ArrayList<Test> list, final CompileContext cc)

Source from the content-addressed store, hash-verified

116 * @return if catch clause contains relevant tests
117 */
118 boolean simplify(final ArrayList<Test> list, final CompileContext cc) {
119 final Checks<Test> wildcard = t -> t instanceof final NameTest nt &&
120 nt.scope == NameTest.Scope.ALL;
121
122 // check if all errors are already caught
123 if(wildcard.any(list)) {
124 cc.info(OPTSIMPLE_X_X, (Supplier<?>) this::description, "*");
125 return false;
126 }
127
128 // drop remaining tests in favor or wildcard test
129 if(wildcard.any(tests) && tests.size() != 1) {
130 tests.clear();
131 tests.add(NodeTest.ELEMENT);
132 cc.info(OPTSIMPLE_X_X, (Supplier<?>) this::description, "*");
133 }
134
135 // remove redundant tests
136 final Iterator<Test> iter = tests.iterator();
137 while(iter.hasNext()) {
138 final Test test = iter.next();
139 if(list.contains(test)) {
140 cc.info(OPTREMOVE_X_X, test, (Supplier<?>) this::description);
141 iter.remove();
142 } else {
143 list.add(test);
144 }
145 }
146 return !tests.isEmpty();
147 }
148
149 /**
150 * Checks if all errors are caught by this cause.

Callers 1

optimizeMethod · 0.95

Calls 11

anyMethod · 0.80
infoMethod · 0.65
sizeMethod · 0.65
addMethod · 0.65
nextMethod · 0.65
containsMethod · 0.65
removeMethod · 0.65
clearMethod · 0.45
iteratorMethod · 0.45
hasNextMethod · 0.45
isEmptyMethod · 0.45

Tested by

no test coverage detected