Skip to content

Commit a423f5f

Browse files
committed
Kotlin: Enable java/misnamed-type query
We used to get alerts for the class around a local function, a lambda, or a function reference, which we give name "". Now those are marked as compiler-generated, and the query ignores compiler-generated types.
1 parent 3c7f751 commit a423f5f

File tree

5 files changed

+11
-1
lines changed

5 files changed

+11
-1
lines changed

java/kotlin-extractor/src/main/kotlin/KotlinFileExtractor.kt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5396,6 +5396,7 @@ open class KotlinFileExtractor(
53965396
val id = ids.type.javaResult.id.cast<DbClass>()
53975397
val pkgId = extractPackage("")
53985398
tw.writeClasses(id, "", pkgId, id)
5399+
tw.writeCompiler_generated(id, CompilerGeneratedKinds.CALLABLE_CLASS.kind)
53995400
tw.writeHasLocation(id, locId)
54005401

54015402
// Extract constructor
@@ -5520,5 +5521,6 @@ open class KotlinFileExtractor(
55205521
DEFAULT_ARGUMENTS_METHOD(10),
55215522
INTERFACE_FORWARDER(11),
55225523
ENUM_CONSTRUCTOR_ARGUMENT(12),
5524+
CALLABLE_CLASS(13),
55235525
}
55245526
}

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,8 @@ class Element extends @element, Top {
7171
i = 11 and result = "Forwarder for a Kotlin class inheriting an interface default method"
7272
or
7373
i = 12 and result = "Argument for enum constructor call"
74+
or
75+
i = 13 and result = "The class around a local function, a lambda, or a function reference"
7476
)
7577
}
7678
}

java/ql/src/Advisory/Naming/NamingConventionsRefTypes.ql

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

1313
from RefType t
1414
where
15-
t.getFile().isJavaSourceFile() and
15+
t.fromSource() and
1616
not t instanceof AnonymousClass and
17+
not t.isCompilerGenerated() and
1718
not t.getName().substring(0, 1).toUpperCase() = t.getName().substring(0, 1)
1819
select t, "Class and interface names should start in uppercase."
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
---
2+
category: minorAnalysis
3+
---
4+
* The query `java/misnamed-type` is now enabled for Kotlin.
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
| Test.kt:12:1:12:13 | aaaa | Class and interface names should start in uppercase. |

0 commit comments

Comments
 (0)