Skip to content

Commit 7f93605

Browse files
joewizclaude
andcommitted
[refactor] Address Codacy findings from PR eXist-db#6344 review
Per reinhapa's review: - FunReplace, FunTokenize: drop fully-qualified RegexUtil.* prefixes since `import static org.exist.xquery.regex.RegexUtil.*` already pulls hasXPath4Lookaround / translateXPath4Lookaround / validateXPathRegex into scope. - SequenceType: drop redundant `= null` initializers on the two new function-test fields; combine the two pairs of nested-if checks in checkType / checkFunctionType into single conjunctions. - ContainsTokenEmptyCollationTest: rename test methods to lowerCamelCase (drop underscores) to satisfy JUnit 4 name pattern. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
1 parent 9fcba75 commit 7f93605

4 files changed

Lines changed: 15 additions & 18 deletions

File tree

exist-core/src/main/java/org/exist/xquery/functions/fn/FunReplace.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -134,8 +134,8 @@ public Sequence eval(final Sequence[] args, final Sequence contextSequence) thro
134134
final boolean isXQuery40 = context.getXQueryVersion() >= 40;
135135

136136
// XQ4: translate (*positive_lookahead:...) etc. to Java regex (?=...) syntax
137-
if (isXQuery40 && org.exist.xquery.regex.RegexUtil.hasXPath4Lookaround(pattern)) {
138-
pattern = org.exist.xquery.regex.RegexUtil.translateXPath4Lookaround(pattern);
137+
if (isXQuery40 && hasXPath4Lookaround(pattern)) {
138+
pattern = translateXPath4Lookaround(pattern);
139139
}
140140

141141
// Pre-validate: reject constructs not valid in XPath regex

exist-core/src/main/java/org/exist/xquery/functions/fn/FunTokenize.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -98,13 +98,13 @@ public Sequence eval(final Sequence[] args, final Sequence contextSequence) thro
9898
String rawPattern = args[1].itemAt(0).getStringValue();
9999

100100
// XQ4: translate (*positive_lookahead:...) etc. to Java regex
101-
if (isXQuery40 && org.exist.xquery.regex.RegexUtil.hasXPath4Lookaround(rawPattern)) {
102-
rawPattern = org.exist.xquery.regex.RegexUtil.translateXPath4Lookaround(rawPattern);
101+
if (isXQuery40 && hasXPath4Lookaround(rawPattern)) {
102+
rawPattern = translateXPath4Lookaround(rawPattern);
103103
}
104104

105105
// Pre-validate: reject constructs not valid in XPath regex
106106
if (!hasLiteral(flags)) {
107-
org.exist.xquery.regex.RegexUtil.validateXPathRegex(this, rawPattern, isXQuery40);
107+
validateXPathRegex(this, rawPattern, isXQuery40);
108108
}
109109

110110
if (hasLiteral(flags)) {

exist-core/src/main/java/org/exist/xquery/value/SequenceType.java

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,8 @@ public class SequenceType {
4242
private int primaryType = Type.ITEM;
4343
private Cardinality cardinality = Cardinality.EXACTLY_ONE;
4444
private QName nodeName = null;
45-
private SequenceType[] functionParamTypes = null;
46-
private SequenceType functionReturnType = null;
45+
private SequenceType[] functionParamTypes;
46+
private SequenceType functionReturnType;
4747

4848
public SequenceType() {
4949
}
@@ -178,10 +178,9 @@ public boolean checkType(final Item item) {
178178
}
179179

180180
// For function types, check parameter and return type compatibility
181-
if (Type.subTypeOf(primaryType, Type.FUNCTION) && item instanceof FunctionReference) {
182-
if (!checkFunctionType((FunctionReference) item)) {
183-
return false;
184-
}
181+
if (Type.subTypeOf(primaryType, Type.FUNCTION) && item instanceof FunctionReference
182+
&& !checkFunctionType((FunctionReference) item)) {
183+
return false;
185184
}
186185

187186
if (nodeName == null) {
@@ -217,10 +216,8 @@ private boolean checkFunctionType(final FunctionReference funcRef) {
217216
final FunctionSignature sig = funcRef.getSignature();
218217

219218
// Check arity: if we have typed parameter info, check against it
220-
if (functionParamTypes != null) {
221-
if (sig.getArgumentCount() != functionParamTypes.length) {
222-
return false;
223-
}
219+
if (functionParamTypes != null && sig.getArgumentCount() != functionParamTypes.length) {
220+
return false;
224221
}
225222

226223
// Check return type: function's return type must be a subtype of required return type (covariant)

exist-core/src/test/java/org/exist/xquery/functions/fn/ContainsTokenEmptyCollationTest.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,21 +48,21 @@ public class ContainsTokenEmptyCollationTest {
4848
public static final ExistEmbeddedServer existEmbeddedServer = new ExistEmbeddedServer(true, true);
4949

5050
@Test
51-
public void emptyCollation_emptySequenceLiteral() throws Exception {
51+
public void emptyCollationEmptySequenceLiteral() throws Exception {
5252
// contains-token-80: third arg is ()
5353
assertEquals("true",
5454
executeStringValue("fn:contains-token('a b c', 'b', ())"));
5555
}
5656

5757
@Test
58-
public void emptyCollation_emptyStringSequence() throws Exception {
58+
public void emptyCollationEmptyStringSequence() throws Exception {
5959
// contains-token-82: third arg comes from a let returning empty sequence
6060
assertEquals("true",
6161
executeStringValue("let $c := () return fn:contains-token('a b c', 'b', $c)"));
6262
}
6363

6464
@Test
65-
public void presentCollation_stillWorks() throws Exception {
65+
public void presentCollationStillWorks() throws Exception {
6666
assertEquals("true",
6767
executeStringValue("fn:contains-token('a b c', 'B', " +
6868
"'http://www.w3.org/2005/xpath-functions/collation/html-ascii-case-insensitive')"));

0 commit comments

Comments
 (0)