Skip to content

Commit 62d74da

Browse files
committed
Sonarqube: Reduce visibility of final String[] and provide accessors
1 parent 47e4284 commit 62d74da

File tree

3 files changed

+21
-6
lines changed

3 files changed

+21
-6
lines changed

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/modules/TruffleCextBuiltins.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -496,7 +496,7 @@ PString run(PString str) {
496496
@GenerateNodeFactory
497497
abstract static class RichCompareNode extends PythonBuiltinNode {
498498
protected static BinaryComparisonNode create(int op) {
499-
return BinaryComparisonNode.create(SpecialMethodNames.COMPARE_OPNAMES[op], SpecialMethodNames.COMPARE_REVERSALS[op], SpecialMethodNames.COMPARE_OPSTRINGS[op]);
499+
return BinaryComparisonNode.create(SpecialMethodNames.getCompareName(op), SpecialMethodNames.getCompareReversal(op), SpecialMethodNames.getCompareOpString(op));
500500
}
501501

502502
@Specialization(guards = "op == 0")

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/builtins/objects/cext/CExtNodes.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -984,8 +984,8 @@ public boolean execute(@SuppressWarnings("unused") String opName, PythonNativeVo
984984
}
985985

986986
public static int findOp(String specialMethodName) {
987-
for (int i = 0; i < SpecialMethodNames.COMPARE_OPNAMES.length; i++) {
988-
if (SpecialMethodNames.COMPARE_OPNAMES[i].equals(specialMethodName)) {
987+
for (int i = 0; i < SpecialMethodNames.COMPARE_OP_COUNT; i++) {
988+
if (SpecialMethodNames.getCompareName(i).equals(specialMethodName)) {
989989
return i;
990990
}
991991
}

graalpython/com.oracle.graal.python/src/com/oracle/graal/python/nodes/SpecialMethodNames.java

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,8 @@
4040
*/
4141
package com.oracle.graal.python.nodes;
4242

43+
import com.oracle.truffle.api.CompilerDirectives.CompilationFinal;
44+
4345
public abstract class SpecialMethodNames {
4446

4547
public static final String __NEW__ = "__new__";
@@ -168,7 +170,20 @@ public abstract class SpecialMethodNames {
168170

169171
// (tfel): The order of these matches the one in CPython, and thus is assumed to remain the same
170172
// in various places
171-
public static final String[] COMPARE_OPSTRINGS = new String[]{"<", "<=", "==", "!=", ">", ">="};
172-
public static final String[] COMPARE_OPNAMES = new String[]{__LT__, __LE__, __EQ__, __NE__, __GT__, __GE__};
173-
public static final String[] COMPARE_REVERSALS = new String[]{__GT__, __GE__, __EQ__, __NE__, __GT__, __GE__};
173+
@CompilationFinal(dimensions = 1) private static final String[] COMPARE_OPSTRINGS = new String[]{"<", "<=", "==", "!=", ">", ">="};
174+
@CompilationFinal(dimensions = 1) private static final String[] COMPARE_OPNAMES = new String[]{__LT__, __LE__, __EQ__, __NE__, __GT__, __GE__};
175+
@CompilationFinal(dimensions = 1) private static final String[] COMPARE_REVERSALS = new String[]{__GT__, __GE__, __EQ__, __NE__, __GT__, __GE__};
176+
public static final int COMPARE_OP_COUNT = COMPARE_OPNAMES.length;
177+
178+
public static String getCompareOpString(int op) {
179+
return COMPARE_OPSTRINGS[op];
180+
}
181+
182+
public static String getCompareName(int op) {
183+
return COMPARE_OPNAMES[op];
184+
}
185+
186+
public static String getCompareReversal(int op) {
187+
return COMPARE_REVERSALS[op];
188+
}
174189
}

0 commit comments

Comments
 (0)