Skip to content

Commit

Permalink
[refactor] Address further SonarCloud static analysis issues
Browse files Browse the repository at this point in the history
  • Loading branch information
adamretter committed Oct 29, 2023
1 parent 49d16e5 commit d118a3b
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 28 deletions.
5 changes: 0 additions & 5 deletions exist-core/src/main/java/org/exist/xquery/ForExpr.java
Original file line number Diff line number Diff line change
Expand Up @@ -325,11 +325,6 @@ public String toString() {
return result.toString();
}

@Override
public void resetState(final boolean postOptimization) {
super.resetState(postOptimization);
}

@Override
public void accept(final ExpressionVisitor visitor) {
visitor.visitForExpression(this);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ public Sequence eval(Sequence contextSequence, Item contextItem)
{context.getProfiler().message(this, Profiler.START_SEQUENCES, "CONTEXT ITEM", contextItem.toSequence());}
}

final LocalVariable var = new LocalVariable(varName);
final LocalVariable localVariable = new LocalVariable(varName);

final Sequence inSeq = inputSequence.eval(contextSequence, contextItem);
if (sequenceType != null) {
Expand All @@ -108,16 +108,17 @@ public Sequence eval(Sequence contextSequence, Item contextItem)

final Item item = i.nextItem();
// set variable value to current item
var.setValue(item.toSequence());
if (sequenceType == null)
{var.checkType();} //... because is makes some conversions
localVariable.setValue(item.toSequence());
if (sequenceType == null) {
localVariable.checkType(); //... because is makes some conversions
}

Sequence satisfiesSeq = null;

//Binds the variable : now in scope
final LocalVariable mark = context.markLocalVariables(false);
try {
context.declareVariableBinding(var);
context.declareVariableBinding(localVariable);
//Evaluate the return clause for the current value of the variable
satisfiesSeq = returnExpr.eval(contextSequence, contextItem);
} finally {
Expand All @@ -139,7 +140,7 @@ public Sequence eval(Sequence contextSequence, Item contextItem)
Type.getTypeName(Type.NODE) +
" (or more specific), got " + Type.getTypeName(item.getType()), inSeq);}
//trigger the old behaviour
else {var.checkType();}
else {localVariable.checkType();}
}

found = satisfiesSeq.effectiveBooleanValue();
Expand Down
24 changes: 12 additions & 12 deletions exist-core/src/test/java/org/exist/xquery/WindowClauseTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
public class WindowClauseTest {

@Test
public void simpleWindowConditions() throws RecognitionException, XPathException, TokenStreamException {
void simpleWindowConditions() throws RecognitionException, XPathException, TokenStreamException {
final String query = "xquery version \"3.1\";\n" +
"for tumbling window $w in (2, 4, 6, 8, 10, 12, 14)\n" +
" start at $s when fn:true()\n" +
Expand Down Expand Up @@ -75,7 +75,7 @@ public void simpleWindowConditions() throws RecognitionException, XPathException
}

@Test
public void complexWindowCondition() throws RecognitionException, XPathException, TokenStreamException {
void complexWindowCondition() throws RecognitionException, XPathException, TokenStreamException {
final String query = "xquery version \"3.1\";\n" +
"for tumbling window $w in (2, 4, 6, 8, 10, 12, 14)\n" +
" start $first next $second when $first/price < $second/price\n" +
Expand Down Expand Up @@ -104,7 +104,7 @@ public void complexWindowCondition() throws RecognitionException, XPathException
}

@Test
public void noEndWindowCondition() throws RecognitionException, XPathException, TokenStreamException {
void noEndWindowCondition() throws RecognitionException, XPathException, TokenStreamException {
final String query = "xquery version \"3.1\";\n" +
"for tumbling window $w in (2, 4, 6, 8, 10, 12, 14)\n" +
" start $first next $second when $first/price < $second/price\n" +
Expand Down Expand Up @@ -132,7 +132,7 @@ public void noEndWindowCondition() throws RecognitionException, XPathException,
}

@Test
public void slidingWindowClause() throws RecognitionException, XPathException, TokenStreamException {
void slidingWindowClause() throws RecognitionException, XPathException, TokenStreamException {
final String query = "xquery version \"3.1\";\n" +
"for sliding window $w in (2, 4, 6, 8, 10, 12, 14)\n" +
" start at $s when fn:true()\n" +
Expand Down Expand Up @@ -163,7 +163,7 @@ public void slidingWindowClause() throws RecognitionException, XPathException, T
}

@Test
public void allWindowsVars() throws RecognitionException, XPathException, TokenStreamException, QName.IllegalQNameException {
void allWindowsVars() throws RecognitionException, XPathException, TokenStreamException, QName.IllegalQNameException {
final String query = "xquery version \"3.1\";\n" +
"for tumbling window $w in (2, 4, 6, 8, 10, 12, 14)\n" +
"start $first at $s previous $start-previous next $start-next when fn:true()\n" +
Expand Down Expand Up @@ -203,7 +203,7 @@ public void allWindowsVars() throws RecognitionException, XPathException, TokenS
}

@Test
public void tumblingWindowAllWindowVarsNoOnly() throws RecognitionException, XPathException, TokenStreamException, QName.IllegalQNameException {
void tumblingWindowAllWindowVarsNoOnly() throws RecognitionException, XPathException, TokenStreamException, QName.IllegalQNameException {
final String query = "xquery version \"3.1\";\n" +
"for tumbling window $w in (2, 4, 6, 8, 10)\n" +
" start $s at $spos previous $sprev next $snext when fn:true() \n" +
Expand Down Expand Up @@ -244,7 +244,7 @@ public void tumblingWindowAllWindowVarsNoOnly() throws RecognitionException, XPa
}

@Test
public void tumblingWindowAvgReturn() throws RecognitionException, XPathException, TokenStreamException, QName.IllegalQNameException {
void tumblingWindowAvgReturn() throws RecognitionException, XPathException, TokenStreamException, QName.IllegalQNameException {
final String query = "xquery version \"3.1\";\n" +
"for tumbling window $w in (2, 4, 6, 8, 10, 12, 14)\n" +
" start at $s when fn:true()\n" +
Expand Down Expand Up @@ -283,7 +283,7 @@ public void tumblingWindowAvgReturn() throws RecognitionException, XPathExceptio
}

@Test
public void tumblingWindowNoEndWindowConditionPositional() throws RecognitionException, XPathException, TokenStreamException, QName.IllegalQNameException {
void tumblingWindowNoEndWindowConditionPositional() throws RecognitionException, XPathException, TokenStreamException, QName.IllegalQNameException {
final String query = "xquery version \"3.1\";\n" +
"for tumbling window $w in (2, 4, 6, 8, 10, 12, 14)\n" +
" start at $s when $s mod 3 = 1\n" +
Expand Down Expand Up @@ -316,7 +316,7 @@ public void tumblingWindowNoEndWindowConditionPositional() throws RecognitionExc
}

@Test
public void tumblingWindowNoEndWindowConditionCurrentItem() throws RecognitionException, XPathException, TokenStreamException {
void tumblingWindowNoEndWindowConditionCurrentItem() throws RecognitionException, XPathException, TokenStreamException {
final String query = "xquery version \"3.1\";\n" +
"for tumbling window $w in (2, 4, 6, 8, 10, 12, 14)\n" +
" start $first when $first mod 3 = 0\n" +
Expand Down Expand Up @@ -349,7 +349,7 @@ public void tumblingWindowNoEndWindowConditionCurrentItem() throws RecognitionEx
}

@Test
public void slidingWindowAvgReturn() throws RecognitionException, XPathException, TokenStreamException, QName.IllegalQNameException {
void slidingWindowAvgReturn() throws RecognitionException, XPathException, TokenStreamException, QName.IllegalQNameException {
final String query = "xquery version \"3.1\";\n" +
"for sliding window $w in (2, 4, 6, 8, 10, 12, 14)\n" +
" start at $s when fn:true()\n" +
Expand Down Expand Up @@ -388,7 +388,7 @@ public void slidingWindowAvgReturn() throws RecognitionException, XPathException
}

@Test
public void slidingWindowEndWithoutOnly() throws RecognitionException, XPathException, TokenStreamException, QName.IllegalQNameException {
void slidingWindowEndWithoutOnly() throws RecognitionException, XPathException, TokenStreamException, QName.IllegalQNameException {
final String query = "xquery version \"3.1\";\n" +
"for sliding window $w in (2, 4, 6, 8, 10, 12, 14)\n" +
" start at $s when fn:true()\n" +
Expand Down Expand Up @@ -427,7 +427,7 @@ public void slidingWindowEndWithoutOnly() throws RecognitionException, XPathExce
}

@Test
public void tumblingWindowRunUp() throws RecognitionException, XPathException, TokenStreamException, QName.IllegalQNameException {
void tumblingWindowRunUp() throws RecognitionException, XPathException, TokenStreamException, QName.IllegalQNameException {
final String query = "xquery version \"3.1\";\n" +
"for tumbling window $w in $closings\n" +
" start $first next $second when $first/price < $second/price\n" +
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
public class BinaryValueFromBinaryStringTest {

@Test
public void getInputStream() throws XPathException, IOException {
void getInputStream() throws XPathException, IOException {

final String testData = "test data";
final String base64TestData = Base64.encodeBase64String(testData.getBytes()).trim();
Expand All @@ -57,7 +57,7 @@ public void getInputStream() throws XPathException, IOException {
}

@Test
public void castBase64ToHexBinary() throws XPathException, IOException {
void castBase64ToHexBinary() throws XPathException, IOException {

final String testData = "testdata";
final String expectedResult = Hex.encodeHexString(testData.getBytes()).trim();
Expand All @@ -71,7 +71,7 @@ public void castBase64ToHexBinary() throws XPathException, IOException {
}

@Test
public void castHexBinaryToBase64() throws XPathException, IOException {
void castHexBinaryToBase64() throws XPathException, IOException {
final String testData = "testdata";
final String expectedResult = Base64.encodeBase64String(testData.getBytes()).trim();

Expand All @@ -84,7 +84,7 @@ public void castHexBinaryToBase64() throws XPathException, IOException {
}

@Test
public void base64StreamBinaryTo() throws XPathException, IOException {
void base64StreamBinaryTo() throws XPathException, IOException {
try (final BinaryValue binaryValue = new BinaryValueFromBinaryString(new Base64BinaryValueType(), "yv4=");
final UnsynchronizedByteArrayOutputStream baos = new UnsynchronizedByteArrayOutputStream()) {

Expand All @@ -99,7 +99,7 @@ public void base64StreamBinaryTo() throws XPathException, IOException {

@ParameterizedTest
@ValueSource(strings = {"CAFE", "cafe"})
public void hexStreamBinaryTo(final String hexString) throws XPathException, IOException {
void hexStreamBinaryTo(final String hexString) throws XPathException, IOException {
try (final BinaryValue binaryValue = new BinaryValueFromBinaryString(new HexBinaryValueType(), hexString);
final UnsynchronizedByteArrayOutputStream baos = new UnsynchronizedByteArrayOutputStream()) {

Expand Down

0 comments on commit d118a3b

Please sign in to comment.