Skip to content

Commit

Permalink
Enable super-pedantic parenthesis checks
Browse files Browse the repository at this point in the history
  • Loading branch information
gbrail committed Jul 18, 2024
1 parent 3b7bd1c commit 5ca94cb
Show file tree
Hide file tree
Showing 25 changed files with 74 additions and 73 deletions.
4 changes: 2 additions & 2 deletions buildSrc/src/main/groovy/rhino.library-conventions.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,8 @@ tasks.withType(JavaCompile).configureEach {
"JavaUtilDate",
// Less important for now, more stylistic than bug
"InlineMeSuggester",
"NonApiType",
"UnnecessaryParentheses",
// This one either alerts for parameters that we don't use,
// or spuriously for local variables in my opinion.
"UnusedVariable")
options.errorprone.excludedPaths = '.+/src/test/java/.+'
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,7 @@ private String loadSource(String sourceUrl) {
}
}

is = (new URL(sourceUrl)).openStream();
is = new URL(sourceUrl).openStream();
}

try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -304,7 +304,7 @@ String getClassName(String name) {
s[j] = '_';
}
}
return (new String(s)).trim();
return new String(s).trim();
}

private static void p(String s) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -409,7 +409,7 @@ final boolean matches(XML node) {
return false;
}
} else {
if (this.uri() == null || ((node.isElement()) && this.uri().equals(nodeUri))) {
if (this.uri() == null || (node.isElement() && this.uri().equals(nodeUri))) {
if (localName().equals("*")) return true;
if (node.isElement()) {
if (localName().equals(qname.getLocalName())) return true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ void initAsDotQuery() {
if (prototype instanceof XMLList) {
XMLList xl = (XMLList) prototype;
if (xl.length() > 0) {
setPrototype((Scriptable) (xl.get(0, null)));
setPrototype((Scriptable) xl.get(0, null));
}
}
// Always return the outer-most type of XML lValue of
Expand Down Expand Up @@ -70,7 +70,7 @@ protected Object updateDotQuery(boolean value) {
// reset the expression to run with this object as
// the WITH selector.
_currIndex = idx;
setPrototype((Scriptable) (orgXmlL.get(idx, null)));
setPrototype((Scriptable) orgXmlL.get(idx, null));

// continue looping
return null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -501,7 +501,7 @@ final void setLocalName(String localName) {
}

final QName getQname() {
String uri = (dom.getNamespaceURI()) == null ? "" : dom.getNamespaceURI();
String uri = dom.getNamespaceURI() == null ? "" : dom.getNamespaceURI();
String prefix = (dom.getPrefix() == null) ? "" : dom.getPrefix();
return QName.create(uri, dom.getLocalName(), prefix);
}
Expand Down Expand Up @@ -830,10 +830,10 @@ void addToList(Object toAdd) {
if (toAdd instanceof XMLList) {
XMLList xmlSrc = (XMLList) toAdd;
for (int i = 0; i < xmlSrc.length(); i++) {
this._add((xmlSrc.item(i)).getAnnotation());
this._add(xmlSrc.item(i).getAnnotation());
}
} else if (toAdd instanceof XML) {
this._add(((XML) (toAdd)).getAnnotation());
this._add(((XML) toAdd).getAnnotation());
} else if (toAdd instanceof XmlNode) {
this._add((XmlNode) toAdd);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -461,7 +461,7 @@ final String ecmaToXmlString(Node node) {
if (node instanceof Text) {
String data = ((Text) node).getData();
// TODO Does Java trim() work same as XMLWhitespace?
String v = (prettyPrint) ? data.trim() : data;
String v = prettyPrint ? data.trim() : data;
s.append(escapeElementValue(v));
return s.toString();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2719,12 +2719,12 @@ private int getWriteSize() {

size += 2; // writeShort(itsFields.size());
for (int i = 0; i < itsFields.size(); i++) {
size += ((ClassFileField) (itsFields.get(i))).getWriteSize();
size += ((ClassFileField) itsFields.get(i)).getWriteSize();
}

size += 2; // writeShort(itsMethods.size());
for (int i = 0; i < itsMethods.size(); i++) {
size += ((ClassFileMethod) (itsMethods.get(i))).getWriteSize();
size += ((ClassFileMethod) itsMethods.get(i)).getWriteSize();
}

size += 2; // writeShort(1); attributes count, could be zero
Expand Down Expand Up @@ -2774,7 +2774,7 @@ public byte[] toByteArray() {
offset = putInt16(itsSuperClassIndex, data, offset);
offset = putInt16(itsInterfaces.size(), data, offset);
for (int i = 0; i < itsInterfaces.size(); i++) {
int interfaceIndex = ((Short) (itsInterfaces.get(i))).shortValue();
int interfaceIndex = ((Short) itsInterfaces.get(i)).shortValue();
offset = putInt16(interfaceIndex, data, offset);
}
offset = putInt16(itsFields.size(), data, offset);
Expand Down
10 changes: 5 additions & 5 deletions rhino/src/main/java/org/mozilla/classfile/ConstantPool.java
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ int addConstant(int k) {
itsPool[itsTop++] = CONSTANT_Integer;
itsTop = ClassFileWriter.putInt32(k, itsPool, itsTop);
itsPoolTypes.put(itsTopIndex, CONSTANT_Integer);
return (short) (itsTopIndex++);
return (short) itsTopIndex++;
}

int addConstant(long k) {
Expand Down Expand Up @@ -219,7 +219,7 @@ private short addNameAndType(String name, String type) {
itsTop = ClassFileWriter.putInt16(nameIndex, itsPool, itsTop);
itsTop = ClassFileWriter.putInt16(typeIndex, itsPool, itsTop);
itsPoolTypes.put(itsTopIndex, CONSTANT_NameAndType);
return (short) (itsTopIndex++);
return (short) itsTopIndex++;
}

short addClass(String className) {
Expand Down Expand Up @@ -298,7 +298,7 @@ short addInterfaceMethodRef(String className, String methodName, String methodTy
FieldOrMethodRef r = new FieldOrMethodRef(className, methodName, methodType);
setConstantData(itsTopIndex, r);
itsPoolTypes.put(itsTopIndex, CONSTANT_InterfaceMethodref);
return (short) (itsTopIndex++);
return (short) itsTopIndex++;
}

short addInvokeDynamic(String methodName, String methodType, int bootstrapIndex) {
Expand All @@ -317,7 +317,7 @@ short addInvokeDynamic(String methodName, String methodType, int bootstrapIndex)
setConstantData(theIndex, methodType);
itsPoolTypes.put(theIndex, CONSTANT_InvokeDynamic);
}
return (short) (theIndex);
return (short) theIndex;
}

short addMethodHandle(ClassFileWriter.MHandle mh) {
Expand All @@ -341,7 +341,7 @@ short addMethodHandle(ClassFileWriter.MHandle mh) {
itsConstantHash.put(mh, theIndex);
itsPoolTypes.put(theIndex, CONSTANT_MethodHandle);
}
return (short) (theIndex);
return (short) theIndex;
}

Object getConstantData(int index) {
Expand Down
16 changes: 8 additions & 8 deletions rhino/src/main/java/org/mozilla/javascript/DToA.java
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ private static void stuffBits(byte[] bits, int offset, int val) {
bits[offset] = (byte) (val >> 24);
bits[offset + 1] = (byte) (val >> 16);
bits[offset + 2] = (byte) (val >> 8);
bits[offset + 3] = (byte) (val);
bits[offset + 3] = (byte) val;
}

/* Convert d into the form b*2^e, where b is an odd integer. b is the returned
Expand All @@ -153,7 +153,7 @@ private static BigInteger d2b(double d, int[] e, int[] bits) {
int i, k, y, z, de;
long dBits = Double.doubleToLongBits(d);
int d0 = (int) (dBits >>> 32);
int d1 = (int) (dBits);
int d1 = (int) dBits;

z = d0 & Frac_mask;
d0 &= 0x7fffffff; /* clear sign bit, which we ignore */
Expand Down Expand Up @@ -217,7 +217,7 @@ static String JS_dtobasestr(int base, double d) {
long lfloor = (long) dfloor;
if (lfloor == dfloor) {
// int part fits long
intDigits = Long.toString((negative) ? -lfloor : lfloor, base);
intDigits = Long.toString(negative ? -lfloor : lfloor, base);
} else {
// BigInteger should be used
long floorBits = Double.doubleToLongBits(dfloor);
Expand Down Expand Up @@ -258,7 +258,7 @@ static String JS_dtobasestr(int base, double d) {

long dBits = Double.doubleToLongBits(d);
int word0 = (int) (dBits >> 32);
int word1 = (int) (dBits);
int word1 = (int) dBits;

int[] e = new int[1];
int[] bbits = new int[1];
Expand Down Expand Up @@ -298,7 +298,7 @@ static String JS_dtobasestr(int base, double d) {
b = b.multiply(bigBase);
BigInteger[] divResult = b.divideAndRemainder(s);
b = divResult[1];
digit = (char) (divResult[0].intValue());
digit = (char) divResult[0].intValue();
if (Objects.equals(mlo, mhi)) mlo = mhi = mlo.multiply(bigBase);
else {
mlo = mlo.multiply(bigBase);
Expand Down Expand Up @@ -384,7 +384,7 @@ static double setWord0(double d, int i) {

static int word1(double d) {
long dBits = Double.doubleToLongBits(d);
return (int) (dBits);
return (int) dBits;
}

/* Return b * 5^k. k must be nonnegative. */
Expand Down Expand Up @@ -782,7 +782,7 @@ static int JS_dtoa(
mhi = mlo = null;
if (leftright) {
if (mode < 2) {
i = (denorm) ? be[0] + (Bias + (P - 1) - 1 + 1) : 1 + P - bbits[0];
i = denorm ? be[0] + (Bias + (P - 1) - 1 + 1) : 1 + P - bbits[0];
/* i is 1 plus the number of trailing zero bits in d's significand. Thus,
(2^m2 * 5^m5) / (2^(s2+i) * 5^s5) = (1/2 lsb of d)/10^k. */
} else {
Expand Down Expand Up @@ -893,7 +893,7 @@ static int JS_dtoa(
Output either zero or the minimum nonzero output depending on which is closer to d. */
if ((ilim < 0)
|| ((i = b.compareTo(S = S.multiply(BigInteger.valueOf(5)))) < 0)
|| ((i == 0 && !biasUp))) {
|| (i == 0 && !biasUp)) {
/* Always emit at least one digit. If the number appears to be zero
using the current mode, then emit one '0' digit and set decpt to 1. */
/*no_digits:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -363,7 +363,7 @@ public Object call(Context cx, Scriptable scope, Scriptable thisObj, Object[] ar
Boolean b = inNewExpr ? Boolean.TRUE : Boolean.FALSE;
Object[] invokeArgs = {cx, args, this, b};
result =
(member.isCtor())
member.isCtor()
? member.newInstance(invokeArgs)
: member.invoke(null, invokeArgs);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ public ImporterTopLevel(Context cx, boolean sealed) {

@Override
public String getClassName() {
return (topScopeFlag) ? "global" : "JavaImporter";
return topScopeFlag ? "global" : "JavaImporter";
}

public static void init(Context cx, Scriptable scope, boolean sealed) {
Expand Down
5 changes: 3 additions & 2 deletions rhino/src/main/java/org/mozilla/javascript/JavaAdapter.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,9 @@
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
import org.mozilla.classfile.ByteCode;
import org.mozilla.classfile.ClassFileWriter;

Expand Down Expand Up @@ -460,8 +462,7 @@ static Method[] getOverridableMethods(Class<?> clazz) {
return list.toArray(new Method[0]);
}

private static void appendOverridableMethods(
Class<?> c, ArrayList<Method> list, HashSet<String> skip) {
private static void appendOverridableMethods(Class<?> c, List<Method> list, Set<String> skip) {
Method[] methods = c.isInterface() ? c.getMethods() : c.getDeclaredMethods();

for (Method method : methods) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ static void init(Scriptable scope, boolean sealed) {

static NativeCallSite make(Scriptable scope, Scriptable ctorObj) {
NativeCallSite cs = new NativeCallSite();
Scriptable proto = (Scriptable) (ctorObj.get("prototype", ctorObj));
Scriptable proto = (Scriptable) ctorObj.get("prototype", ctorObj);
cs.setParentScope(scope);
cs.setPrototype(proto);
return cs;
Expand Down
8 changes: 4 additions & 4 deletions rhino/src/main/java/org/mozilla/javascript/NativeDate.java
Original file line number Diff line number Diff line change
Expand Up @@ -529,10 +529,10 @@ private static boolean IsLeapYear(int year) {
* floor((1968 - 1969) / 4) == -1
*/
private static double DayFromYear(double y) {
return ((365 * ((y) - 1970)
+ Math.floor(((y) - 1969) / 4.0)
- Math.floor(((y) - 1901) / 100.0)
+ Math.floor(((y) - 1601) / 400.0)));
return (365 * (y - 1970)
+ Math.floor((y - 1969) / 4.0)
- Math.floor((y - 1901) / 100.0)
+ Math.floor((y - 1601) / 400.0));
}

private static double TimeFromYear(double y) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ static void init(Scriptable scope, boolean sealed) {
}

static NativeError make(Context cx, Scriptable scope, IdFunctionObject ctorObj, Object[] args) {
Scriptable proto = (Scriptable) (ctorObj.get("prototype", ctorObj));
Scriptable proto = (Scriptable) ctorObj.get("prototype", ctorObj);

NativeError obj = new NativeError();
obj.setPrototype(proto);
Expand Down
2 changes: 1 addition & 1 deletion rhino/src/main/java/org/mozilla/javascript/NativeJSON.java
Original file line number Diff line number Diff line change
Expand Up @@ -579,7 +579,7 @@ private static boolean isObjectArrayLike(Object o) {
}
if (o instanceof NativeJavaObject) {
Object unwrapped = ((NativeJavaObject) o).unwrap();
return (unwrapped instanceof Collection) || (unwrapped.getClass().isArray());
return (unwrapped instanceof Collection) || unwrapped.getClass().isArray();
}
return false;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ public Object intern(Object keyArg) {
}
int index = ensureIndex(keyArg);
values[index] = 0;
return (nullKey) ? null : keys[index];
return nullKey ? null : keys[index];
}

public void remove(Object key) {
Expand Down
6 changes: 3 additions & 3 deletions rhino/src/main/java/org/mozilla/javascript/ScriptRuntime.java
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ public static ScriptableObject initSafeStandardObjects(
}

scope.associateValue(LIBRARY_SCOPE_KEY, scope);
(new ClassCache()).associate(scope);
new ClassCache().associate(scope);

BaseFunction.init(cx, scope, sealed);
NativeObject.init(scope, sealed);
Expand Down Expand Up @@ -2965,7 +2965,7 @@ public static boolean isObject(Object value) {
return "object".equals(type) || "function".equals(type);
}
if (value instanceof Scriptable) {
return (!(value instanceof Callable));
return !(value instanceof Callable);
}
return false;
}
Expand Down Expand Up @@ -4982,7 +4982,7 @@ static boolean isGeneratedScript(String sourceUrl) {
* just by using an "instanceof" check.
*/
static boolean isSymbol(Object obj) {
return (((obj instanceof NativeSymbol) && ((NativeSymbol) obj).isSymbol()))
return ((obj instanceof NativeSymbol) && ((NativeSymbol) obj).isSymbol())
|| (obj instanceof SymbolKey);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public int size() {

@Override
public int dirtySize() {
assert (lock.isReadLocked());
assert lock.isReadLocked();
return map.size();
}

Expand Down Expand Up @@ -140,7 +140,7 @@ public void unlockRead(long stamp) {

@Override
public Iterator<Slot> iterator() {
assert (lock.isReadLocked());
assert lock.isReadLocked();
return map.iterator();
}

Expand All @@ -150,7 +150,7 @@ public Iterator<Slot> iterator() {
*/
@Override
protected void checkMapSize() {
assert (lock.isWriteLocked());
assert lock.isWriteLocked();
super.checkMapSize();
}
}
Loading

0 comments on commit 5ca94cb

Please sign in to comment.