Skip to content

Commit ae44b90

Browse files
committed
Java: Normalize parentheses.
1 parent 41edd61 commit ae44b90

File tree

84 files changed

+644
-871
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

84 files changed

+644
-871
lines changed

java/ql/src/Advisory/Documentation/JavadocCommon.qll

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,9 +49,9 @@ class DocuCallable extends Callable {
4949
predicate hasAcceptableDocText() { acceptableDocText(this.getDoc().getJavadoc()) }
5050

5151
string toMethodOrConstructorString() {
52-
(this instanceof Method and result = "method")
52+
this instanceof Method and result = "method"
5353
or
54-
(this instanceof Constructor and result = "constructor")
54+
this instanceof Constructor and result = "constructor"
5555
}
5656
}
5757

java/ql/src/Advisory/Documentation/SpuriousJavadocParam.ql

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ where
1515
callable.(Documentable).getJavadoc().getAChild() = paramTag and
1616
(if callable instanceof Constructor then what = "constructor" else what = "method") and
1717
if exists(paramTag.getParamName())
18-
then (
18+
then
1919
// The tag's value is neither matched by a callable parameter name ...
2020
not callable.getAParameter().getName() = paramTag.getParamName() and
2121
// ... nor by a type parameter name.
@@ -24,7 +24,7 @@ where
2424
) and
2525
msg = "@param tag \"" + paramTag.getParamName() + "\" does not match any actual parameter of " +
2626
what + " \"" + callable.getName() + "()\"."
27-
) else
27+
else
2828
// The tag has no value at all.
2929
msg = "This @param tag does not have a value."
3030
select paramTag, msg

java/ql/src/Compatibility/JDK9/JdkInternalAccess.ql

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ predicate jdkPackage(Package p) {
127127
from JdkInternalAccess ta, string repl, string msg
128128
where
129129
repl = ta.getReplacement() and
130-
(if (repl = "unknown") then msg = "" else msg = " (" + repl + ")") and
130+
(if repl = "unknown" then msg = "" else msg = " (" + repl + ")") and
131131
not jdkInternalApi(ta.getCompilationUnit().getPackage().getName()) and
132132
not jdkPackage(ta.getCompilationUnit().getPackage())
133133
select ta, "Access to unsupported JDK-internal API '" + ta.getAccessedApi() + "'." + msg

java/ql/src/Frameworks/Spring/Architecture/Refactoring Opportunities/UnusedBean.ql

Lines changed: 21 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -39,13 +39,11 @@ class ImpureStmt extends Stmt {
3939
ImpureStmt() {
4040
exists(Expr e | e.getEnclosingStmt() = this |
4141
// Only permit calls to set of whitelisted targets.
42-
(
43-
e instanceof Call and
44-
not e.(Call).getCallee().getDeclaringType().hasQualifiedName("java.util", "Collections")
45-
)
42+
e instanceof Call and
43+
not e.(Call).getCallee().getDeclaringType().hasQualifiedName("java.util", "Collections")
4644
or
4745
// Writing to a field that is not an instance field is a no-no
48-
(e instanceof FieldWrite and not e instanceof InstanceFieldWrite)
46+
e instanceof FieldWrite and not e instanceof InstanceFieldWrite
4947
)
5048
}
5149
}
@@ -68,22 +66,20 @@ private Stmt getANestedStmt(Block block) {
6866
*/
6967
class SpringPureClass extends Class {
7068
SpringPureClass() {
71-
(
72-
// The only permitted statement in static initializers is the initialization of a static
73-
// final or effectively final logger fields, or effectively immutable types.
74-
forall(Stmt s | s = getANestedStmt(getAMember().(StaticInitializer).getBody()) |
75-
exists(Field f | f = s.(ExprStmt).getExpr().(AssignExpr).getDest().(FieldWrite).getField() |
76-
(
77-
// A logger field
78-
f.getName().toLowerCase() = "logger" or
79-
f.getName().toLowerCase() = "log" or
80-
// An immutable type
81-
f.getType() instanceof ImmutableType
82-
) and
83-
f.isStatic() and
84-
// Only written to in this statement e.g. final or effectively final
85-
forall(FieldWrite fw | fw = f.getAnAccess() | fw.getEnclosingStmt() = s)
86-
)
69+
// The only permitted statement in static initializers is the initialization of a static
70+
// final or effectively final logger fields, or effectively immutable types.
71+
forall(Stmt s | s = getANestedStmt(getAMember().(StaticInitializer).getBody()) |
72+
exists(Field f | f = s.(ExprStmt).getExpr().(AssignExpr).getDest().(FieldWrite).getField() |
73+
(
74+
// A logger field
75+
f.getName().toLowerCase() = "logger" or
76+
f.getName().toLowerCase() = "log" or
77+
// An immutable type
78+
f.getType() instanceof ImmutableType
79+
) and
80+
f.isStatic() and
81+
// Only written to in this statement e.g. final or effectively final
82+
forall(FieldWrite fw | fw = f.getAnAccess() | fw.getEnclosingStmt() = s)
8783
)
8884
) and
8985
// No constructor, instance initializer or Spring bean init or setter method that is impure.
@@ -145,12 +141,10 @@ class SpringBeanFactory extends ClassOrInterface {
145141
class LiveSpringBean extends SpringBean {
146142
LiveSpringBean() {
147143
// Must not be needed for side effects due to construction
148-
(
149-
// Only loaded by the container when required, so construction cannot have any useful side-effects
150-
not isLazyInit() and
151-
// or has no side-effects when constructed
152-
not getClass() instanceof SpringPureClass
153-
)
144+
// Only loaded by the container when required, so construction cannot have any useful side-effects
145+
not isLazyInit() and
146+
// or has no side-effects when constructed
147+
not getClass() instanceof SpringPureClass
154148
or
155149
(
156150
// If the class does not exist for this bean, or the class is not a source bean, then this is

java/ql/src/Language Abuse/EmptyStatement.ql

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,6 @@ import java
1414
from EmptyStmt empty, string action
1515
where
1616
if exists(LoopStmt l | l.getBody() = empty)
17-
then (
18-
action = "turned into '{}'"
19-
) else (
20-
action = "deleted"
21-
)
17+
then action = "turned into '{}'"
18+
else action = "deleted"
2219
select empty, "This empty statement should be " + action + "."

java/ql/src/Language Abuse/TypeVariableHidesType.ql

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ RefType aTypeVisibleFrom(TypeVariable var) {
2727
result = i.getImportedType()
2828
)
2929
or
30-
(var.getPackage() = result.getPackage() and result instanceof TopLevelType)
30+
var.getPackage() = result.getPackage() and result instanceof TopLevelType
3131
}
3232

3333
from RefType hidden, TypeVariable var

java/ql/src/Language Abuse/WrappedIterator.ql

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,8 @@ predicate iteratorWrapper(Iterable it, Field f, boolean wrap) {
2121
(
2222
f.isFinal()
2323
or
24-
(
25-
strictcount(f.getAnAssignedValue()) = 1 and
26-
f.getAnAssignedValue().getEnclosingCallable() instanceof InitializerMethod
27-
)
24+
strictcount(f.getAnAssignedValue()) = 1 and
25+
f.getAnAssignedValue().getEnclosingCallable() instanceof InitializerMethod
2826
) and
2927
// ... whose type is a sub-type of `java.util.Iterator` and ...
3028
f

java/ql/src/Likely Bugs/Arithmetic/ConstantExpAppearsNonConstant.ql

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
import java
1313

1414
int integralTypeWidth(IntegralType t) {
15-
if (t.hasName("long") or t.hasName("Long")) then result = 64 else result = 32
15+
if t.hasName("long") or t.hasName("Long") then result = 64 else result = 32
1616
}
1717

1818
int eval(Expr e) { result = e.(CompileTimeConstantExpr).getIntValue() }

java/ql/src/Likely Bugs/Arithmetic/WhitespaceContradictsPrecedence.ql

Lines changed: 13 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -71,26 +71,24 @@ class AssocNestedExpr extends BinaryExpr {
7171
exists(BinaryExpr parent, int idx | this.isNthChildOf(parent, idx) |
7272
// `+`, `*`, `&&`, `||` and the bitwise operations are associative.
7373
(
74-
(
75-
this instanceof AddExpr or
76-
this instanceof MulExpr or
77-
this instanceof BitwiseExpr or
78-
this instanceof LogicalExpr
79-
) and
80-
parent.getKind() = this.getKind()
81-
)
74+
this instanceof AddExpr or
75+
this instanceof MulExpr or
76+
this instanceof BitwiseExpr or
77+
this instanceof LogicalExpr
78+
) and
79+
parent.getKind() = this.getKind()
8280
or
8381
// Equality tests are associate over each other.
84-
(this instanceof EqualityTest and parent instanceof EqualityTest)
82+
this instanceof EqualityTest and parent instanceof EqualityTest
8583
or
8684
// (x*y)/z = x*(y/z)
87-
(this instanceof MulExpr and parent instanceof DivExpr and idx = 0)
85+
this instanceof MulExpr and parent instanceof DivExpr and idx = 0
8886
or
8987
// (x/y)%z = x/(y%z)
90-
(this instanceof DivExpr and parent instanceof RemExpr and idx = 0)
88+
this instanceof DivExpr and parent instanceof RemExpr and idx = 0
9189
or
9290
// (x+y)-z = x+(y-z)
93-
(this instanceof AddExpr and parent instanceof SubExpr and idx = 0)
91+
this instanceof AddExpr and parent instanceof SubExpr and idx = 0
9492
)
9593
}
9694
}
@@ -102,12 +100,10 @@ class AssocNestedExpr extends BinaryExpr {
102100
class HarmlessNestedExpr extends BinaryExpr {
103101
HarmlessNestedExpr() {
104102
exists(BinaryExpr parent | this = parent.getAChildExpr() |
105-
(
106-
parent instanceof RelationExpr and
107-
(this instanceof ArithmeticExpr or this instanceof ShiftExpr)
108-
)
103+
parent instanceof RelationExpr and
104+
(this instanceof ArithmeticExpr or this instanceof ShiftExpr)
109105
or
110-
(parent instanceof LogicalExpr and this instanceof RelationExpr)
106+
parent instanceof LogicalExpr and this instanceof RelationExpr
111107
)
112108
}
113109
}

java/ql/src/Likely Bugs/Collections/IteratorRemoveMayFail.ql

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,10 @@ class SpecialCollectionCreation extends MethodAccess {
1818
exists(Method m, RefType rt |
1919
m = this.(MethodAccess).getCallee() and rt = m.getDeclaringType()
2020
|
21-
(rt.hasQualifiedName("java.util", "Arrays") and m.hasName("asList"))
21+
rt.hasQualifiedName("java.util", "Arrays") and m.hasName("asList")
2222
or
23-
(
24-
rt.hasQualifiedName("java.util", "Collections") and
25-
m.getName().regexpMatch("singleton.*|unmodifiable.*")
26-
)
23+
rt.hasQualifiedName("java.util", "Collections") and
24+
m.getName().regexpMatch("singleton.*|unmodifiable.*")
2725
)
2826
}
2927
}

0 commit comments

Comments
 (0)