Skip to content

Commit 47799ae

Browse files
tamasvajkigfoo
authored andcommitted
Code quality improvements + add dedicated DeadRefTypes test
1 parent cdc7ed0 commit 47799ae

File tree

7 files changed

+25
-5
lines changed

7 files changed

+25
-5
lines changed

java/ql/lib/config/semmlecode.dbscheme

+3-3
Original file line numberDiff line numberDiff line change
@@ -1224,7 +1224,7 @@ ktPropertyDelegates(
12241224
)
12251225

12261226
compiler_generated(
1227-
unique int id: @top ref,
1227+
unique int id: @element ref,
12281228
int kind: int ref
1229-
// 1: Kotlin declaring classes of adapter functions
1230-
);
1229+
// 1: Declaring classes of adapter functions in Kotlin
1230+
)

java/ql/lib/semmle/code/java/Element.qll

+3
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,9 @@ class Element extends @element, Top {
4141

4242
/** Cast this element to a `Documentable`. */
4343
Documentable getDoc() { result = this }
44+
45+
/** Holds if this is an auxiliary program element generated by the compiler. */
46+
predicate isCompilerGenerated() { compiler_generated(this, _) }
4447
}
4548

4649
/**

java/ql/src/Violations of Best Practice/Dead Code/DeadRefTypes.ql

+1-1
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ predicate dead(RefType dead) {
5252
// Insist all source ancestors are dead as well.
5353
forall(RefType t | t.fromSource() and t = getASuperTypePlus(dead) | dead(t)) and
5454
// Exclude compiler generated classes (e.g. declaring type of adapter functions in Kotlin)
55-
not compiler_generated(dead, _)
55+
not dead.isCompilerGenerated()
5656
}
5757

5858
from RefType t, string kind

java/ql/test/kotlin/library-tests/reflection/reflection.ql

+1-1
Original file line numberDiff line numberDiff line change
@@ -87,4 +87,4 @@ query predicate modifiers(ClassInstanceExpr e, Method m, string modifier) {
8787
m.hasModifier(modifier)
8888
}
8989

90-
query predicate compGenerated(Top t, int i) { compiler_generated(t, i) }
90+
query predicate compGenerated(Element e, int i) { compiler_generated(e, i) }
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
| test.kt:1:1:1:20 | C1 | Unused class: C1 is not referenced within this codebase. If not used as an external API it should be removed. |
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Violations of Best Practice/Dead Code/DeadRefTypes.ql
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
private class C1 { }
2+
3+
private class C2 { }
4+
5+
fun fn() {
6+
val c = C2()
7+
}
8+
9+
fun fn1() = 5
10+
11+
fun fn2(f: () -> Unit) = f()
12+
13+
fun adapted() {
14+
fn2(::fn1)
15+
}

0 commit comments

Comments
 (0)