Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 2f0b983

Browse files
committed
Java: Autoformat most of semmle.code.java.
1 parent bc7ea93 commit 2f0b983

32 files changed

Lines changed: 1747 additions & 1863 deletions

java/ql/src/semmle/code/java/Annotation.qll

Lines changed: 27 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -38,14 +38,10 @@ class Annotation extends @annotation, Expr {
3838
Expr getAValue() { filteredAnnotValue(this, _, result) }
3939

4040
/** Gets the value of the annotation element with the specified `name`. */
41-
Expr getValue(string name) {
42-
filteredAnnotValue(this, this.getAnnotationElement(name), result)
43-
}
41+
Expr getValue(string name) { filteredAnnotValue(this, this.getAnnotationElement(name), result) }
4442

4543
/** Gets the element being annotated. */
46-
Element getTarget() {
47-
exprs(this, _, _, result, _)
48-
}
44+
Element getTarget() { exprs(this, _, _, result, _) }
4945

5046
override string toString() { result = this.getType().getName() }
5147

@@ -63,35 +59,28 @@ class Annotation extends @annotation, Expr {
6359
Expr getAValue(string name) {
6460
getType().getAnnotationElement(name).getType() instanceof Array and
6561
exists(Expr value | value = getValue(name) |
66-
if value instanceof ArrayInit then
67-
result = value.(ArrayInit).getAnInit()
68-
else
69-
result = value
62+
if value instanceof ArrayInit then result = value.(ArrayInit).getAnInit() else result = value
7063
)
7164
}
7265
}
7366

7467
/** An `Annotation` that applies to a declaration. */
75-
class DeclAnnotation extends @declannotation, Annotation {
76-
}
68+
class DeclAnnotation extends @declannotation, Annotation { }
7769

7870
/** An `Annotation` that applies to a type. */
79-
class TypeAnnotation extends @typeannotation, Annotation {
80-
}
71+
class TypeAnnotation extends @typeannotation, Annotation { }
8172

8273
/**
8374
* There may be duplicate entries in annotValue(...) - one entry for
8475
* information populated from bytecode, and one for information populated
8576
* from source. This removes the duplication.
8677
*/
87-
private
88-
predicate filteredAnnotValue(Annotation a, Method m, Expr val) {
78+
private predicate filteredAnnotValue(Annotation a, Method m, Expr val) {
8979
annotValue(a, m, val) and
9080
(sourceAnnotValue(a, m, val) or not sourceAnnotValue(a, m, _))
9181
}
9282

93-
private
94-
predicate sourceAnnotValue(Annotation a, Method m, Expr val) {
83+
private predicate sourceAnnotValue(Annotation a, Method m, Expr val) {
9584
annotValue(a, m, val) and
9685
val.getFile().getExtension() = "java"
9786
}
@@ -103,7 +92,9 @@ class Annotatable extends Element {
10392

10493
/** Holds if this element has the specified annotation. */
10594
predicate hasAnnotation(string package, string name) {
106-
exists(AnnotationType at | at = getAnAnnotation().getType() | at.nestedName() = name and at.getPackage().getName() = package)
95+
exists(AnnotationType at | at = getAnAnnotation().getType() |
96+
at.nestedName() = name and at.getPackage().getName() = package
97+
)
10798
}
10899

109100
/** Gets an annotation that applies to this element. */
@@ -114,14 +105,20 @@ class Annotatable extends Element {
114105
* annotation attached to it for the specified `category`.
115106
*/
116107
predicate suppressesWarningsAbout(string category) {
117-
exists(string withQuotes
118-
| withQuotes = ((SuppressWarningsAnnotation) getAnAnnotation()).getASuppressedWarning()
119-
| category = withQuotes.substring(1, withQuotes.length() - 1)
120-
) or
121-
this.(Member).getDeclaringType().suppressesWarningsAbout(category) or
122-
this.(Expr).getEnclosingCallable().suppressesWarningsAbout(category) or
123-
this.(Stmt).getEnclosingCallable().suppressesWarningsAbout(category) or
124-
this.(NestedClass).getEnclosingType().suppressesWarningsAbout(category) or
108+
exists(string withQuotes |
109+
withQuotes = (getAnAnnotation().(SuppressWarningsAnnotation)).getASuppressedWarning()
110+
|
111+
category = withQuotes.substring(1, withQuotes.length() - 1)
112+
)
113+
or
114+
this.(Member).getDeclaringType().suppressesWarningsAbout(category)
115+
or
116+
this.(Expr).getEnclosingCallable().suppressesWarningsAbout(category)
117+
or
118+
this.(Stmt).getEnclosingCallable().suppressesWarningsAbout(category)
119+
or
120+
this.(NestedClass).getEnclosingType().suppressesWarningsAbout(category)
121+
or
125122
this.(LocalVariableDecl).getCallable().suppressesWarningsAbout(category)
126123
}
127124
}
@@ -132,13 +129,11 @@ class AnnotationType extends Interface {
132129

133130
/** Gets the annotation element with the specified `name`. */
134131
AnnotationElement getAnnotationElement(string name) {
135-
methods(result,_,_,_,this,_) and result.hasName(name)
132+
methods(result, _, _, _, this, _) and result.hasName(name)
136133
}
137134

138135
/** Gets an annotation element that is a member of this annotation type. */
139-
AnnotationElement getAnAnnotationElement() {
140-
methods(result,_,_,_,this,_)
141-
}
136+
AnnotationElement getAnAnnotationElement() { methods(result, _, _, _, this, _) }
142137

143138
/** Holds if this annotation type is annotated with the meta-annotation `@Inherited`. */
144139
predicate isInherited() {
@@ -154,5 +149,5 @@ class AnnotationElement extends Member {
154149
AnnotationElement() { isAnnotElem(this) }
155150

156151
/** Gets the type of this annotation element. */
157-
Type getType() { methods(this,_,_,result,_,_) }
152+
Type getType() { methods(this, _, _, result, _, _) }
158153
}

java/ql/src/semmle/code/java/Collections.qll

Lines changed: 12 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,11 @@ import java
99
* `List<T>`, instantiating the type parameter to `Object`.
1010
*/
1111
predicate instantiates(RefType t, GenericType g, int i, RefType arg) {
12-
t = g.getAParameterizedType() and exists(g.getTypeParameter(i)) and
12+
t = g.getAParameterizedType() and
13+
exists(g.getTypeParameter(i)) and
1314
(
14-
arg = t.(ParameterizedType).getTypeArgument(i) or
15+
arg = t.(ParameterizedType).getTypeArgument(i)
16+
or
1517
t instanceof RawType and arg instanceof TypeObject
1618
)
1719
}
@@ -40,7 +42,7 @@ predicate indirectlyInstantiates(RefType t, GenericType g, int i, RefType arg) {
4042
(extendsReftype(tsrc, sup) or implInterface(tsrc, sup)) and
4143
// check whether the subtype instantiates `g`
4244
indirectlyInstantiates(sup, g, i, suparg)
43-
|
45+
|
4446
// if `t` is itself an instantiation of `tsrc` and `sup` instantiates
4547
// `g` to one of the type parameters of `tsrc`, we return the corresponding
4648
// instantiation in `t`
@@ -63,7 +65,7 @@ class CollectionType extends RefType {
6365
CollectionType() {
6466
exists(ParameterizedInterface coll |
6567
coll.getSourceDeclaration().hasQualifiedName("java.util", "Collection")
66-
|
68+
|
6769
this.hasSupertype*(coll)
6870
)
6971
}
@@ -78,9 +80,7 @@ class CollectionType extends RefType {
7880

7981
/** A method declared in a collection type. */
8082
class CollectionMethod extends Method {
81-
CollectionMethod() {
82-
this.getDeclaringType() instanceof CollectionType
83-
}
83+
CollectionMethod() { this.getDeclaringType() instanceof CollectionType }
8484

8585
/** Gets the type of elements of the collection to which this method belongs. */
8686
RefType getReceiverElementType() {
@@ -90,34 +90,24 @@ class CollectionMethod extends Method {
9090

9191
/** The `size` method on `java.util.Collection`. */
9292
class CollectionSizeMethod extends CollectionMethod {
93-
CollectionSizeMethod() {
94-
this.hasName("size") and this.hasNoParameters()
95-
}
93+
CollectionSizeMethod() { this.hasName("size") and this.hasNoParameters() }
9694
}
9795

9896
/** A method that mutates the collection it belongs to. */
9997
class CollectionMutator extends CollectionMethod {
100-
CollectionMutator() {
101-
this.getName().regexpMatch("add.*|remove.*|push|pop|clear")
102-
}
98+
CollectionMutator() { this.getName().regexpMatch("add.*|remove.*|push|pop|clear") }
10399
}
104100

105101
/** A method call that mutates a collection. */
106102
class CollectionMutation extends MethodAccess {
107-
CollectionMutation() {
108-
this.getMethod() instanceof CollectionMutator
109-
}
103+
CollectionMutation() { this.getMethod() instanceof CollectionMutator }
110104

111-
predicate resultIsChecked() {
112-
not this.getParent() instanceof ExprStmt
113-
}
105+
predicate resultIsChecked() { not this.getParent() instanceof ExprStmt }
114106
}
115107

116108
/** A method that queries the contents of a collection without mutating it. */
117109
class CollectionQueryMethod extends CollectionMethod {
118-
CollectionQueryMethod() {
119-
this.getName().regexpMatch("contains|containsAll|get|size|peek")
120-
}
110+
CollectionQueryMethod() { this.getName().regexpMatch("contains|containsAll|get|size|peek") }
121111
}
122112

123113
/** A `new` expression that allocates a fresh, empty collection. */

java/ql/src/semmle/code/java/CompilationUnit.qll

Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -10,29 +10,21 @@ import semmle.code.FileSystem
1010
* A compilation unit is a `.java` or `.class` file.
1111
*/
1212
class CompilationUnit extends Element, File {
13-
CompilationUnit() {
14-
cupackage(this,_)
15-
}
13+
CompilationUnit() { cupackage(this, _) }
1614

1715
/** Gets the name of the compilation unit (not including its extension). */
18-
override string getName() {
19-
result = Element.super.getName()
20-
}
16+
override string getName() { result = Element.super.getName() }
2117

2218
/**
2319
* Holds if this compilation unit has the specified `name`,
2420
* which must not include the file extension.
2521
*/
26-
override predicate hasName(string name) {
27-
Element.super.hasName(name)
28-
}
22+
override predicate hasName(string name) { Element.super.hasName(name) }
2923

30-
override string toString() {
31-
result = Element.super.toString()
32-
}
24+
override string toString() { result = Element.super.toString() }
3325

3426
/** Gets the declared package of this compilation unit. */
35-
Package getPackage() { cupackage(this,result) }
27+
Package getPackage() { cupackage(this, result) }
3628

3729
/**
3830
* Gets the module associated with this compilation unit, if any.

java/ql/src/semmle/code/java/Completion.qll

Lines changed: 10 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,12 @@ import java
2424
*/
2525
newtype Label = MkLabel(string l) { exists(LabeledStmt lbl | l = lbl.getLabel()) }
2626

27-
2827
/**
2928
* Either a `Label` or nothing.
3029
*/
31-
newtype MaybeLabel = JustLabel(Label l) or NoLabel()
32-
30+
newtype MaybeLabel =
31+
JustLabel(Label l) or
32+
NoLabel()
3333

3434
/**
3535
* A completion of a statement or an expression.
@@ -48,7 +48,8 @@ newtype Completion =
4848
* flow node having value `innerValue`.
4949
*/
5050
BooleanCompletion(boolean outerValue, boolean innerValue) {
51-
(outerValue = true or outerValue = false) and (innerValue = true or innerValue = false)
51+
(outerValue = true or outerValue = false) and
52+
(innerValue = true or innerValue = false)
5253
} or
5354
/**
5455
* The expression or statement completes via a `break` statement.
@@ -63,25 +64,13 @@ newtype Completion =
6364
*/
6465
ThrowCompletion(ThrowableType tt)
6566

67+
ContinueCompletion anonymousContinueCompletion() { result = ContinueCompletion(NoLabel()) }
6668

67-
ContinueCompletion anonymousContinueCompletion() {
68-
result = ContinueCompletion(NoLabel())
69-
}
69+
ContinueCompletion labelledContinueCompletion(Label l) { result = ContinueCompletion(JustLabel(l)) }
7070

71-
ContinueCompletion labelledContinueCompletion(Label l) {
72-
result = ContinueCompletion(JustLabel(l))
73-
}
71+
BreakCompletion anonymousBreakCompletion() { result = BreakCompletion(NoLabel()) }
7472

75-
BreakCompletion anonymousBreakCompletion() {
76-
result = BreakCompletion(NoLabel())
77-
}
78-
79-
BreakCompletion labelledBreakCompletion(Label l) {
80-
result = BreakCompletion(JustLabel(l))
81-
}
73+
BreakCompletion labelledBreakCompletion(Label l) { result = BreakCompletion(JustLabel(l)) }
8274

8375
/** Gets the completion `booleanCompletion(value, value)`. */
84-
Completion basicBooleanCompletion(boolean value) {
85-
result = BooleanCompletion(value, value)
86-
}
87-
76+
Completion basicBooleanCompletion(boolean value) { result = BooleanCompletion(value, value) }

java/ql/src/semmle/code/java/Concurrency.qll

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
21
import java
32

43
/**

0 commit comments

Comments
 (0)