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

Skip to content

Commit 55b8e44

Browse files
tamasvajkigfoo
authored andcommitted
Code quality improvements
1 parent b6e5e19 commit 55b8e44

4 files changed

Lines changed: 52 additions & 33 deletions

File tree

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

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ open class KotlinFileExtractor(
141141
// The containing class is `private`.
142142
addModifiers(id, "public")
143143
} else {
144-
addModifiers(id, "private")
144+
addVisibilityModifierToLocalOrAnonymousClass(id)
145145
}
146146
is DelegatedDescriptorVisibility -> {
147147
when (v.delegate) {
@@ -155,7 +155,7 @@ open class KotlinFileExtractor(
155155
JavaVisibilities.ProtectedAndPackage -> {
156156
// default java visibility (member level)
157157
}
158-
else -> logger.warnElement(Severity.ErrorSevere, "Unexpected visibility: $v", elementForLocation)
158+
else -> logger.warnElement(Severity.ErrorSevere, "Unexpected delegated visibility: $v", elementForLocation)
159159
}
160160
}
161161
else -> logger.warnElement(Severity.ErrorSevere, "Unexpected visibility: $v", elementForLocation)
@@ -2486,6 +2486,10 @@ open class KotlinFileExtractor(
24862486
private val IrType.isAnonymous: Boolean
24872487
get() = ((this as? IrSimpleType)?.classifier?.owner as? IrClass)?.isAnonymousObject ?: false
24882488

2489+
private fun addVisibilityModifierToLocalOrAnonymousClass(id: Label<out DbModifiable>) {
2490+
addModifiers(id, "private")
2491+
}
2492+
24892493
/**
24902494
* Extracts the class around a local function, a lambda, or a function reference.
24912495
*/
@@ -2506,6 +2510,7 @@ open class KotlinFileExtractor(
25062510
val unitType = useType(pluginContext.irBuiltIns.unitType)
25072511
tw.writeConstrs(ids.constructor, "", "", unitType.javaResult.id, unitType.kotlinResult.id, id, ids.constructor)
25082512
tw.writeHasLocation(ids.constructor, locId)
2513+
addModifiers(ids.constructor, "public")
25092514

25102515
// Constructor body
25112516
val constructorBlockId = ids.constructorBlock
@@ -2525,7 +2530,8 @@ open class KotlinFileExtractor(
25252530

25262531
// TODO: We might need to add an `<obinit>` function, and a call to it to match other classes
25272532

2528-
addModifiers(id, "private", "final")
2533+
addModifiers(id, "final")
2534+
addVisibilityModifierToLocalOrAnonymousClass(id)
25292535
extractClassSupertypes(superTypes, listOf(), id)
25302536

25312537
var parent: IrDeclarationParent? = currentDeclaration.parent
Lines changed: 38 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,38 @@
1-
| modifiers.kt:1:1:21:1 | X | public |
2-
| modifiers.kt:1:6:21:1 | X | public |
3-
| modifiers.kt:2:5:2:21 | a | private |
4-
| modifiers.kt:2:5:2:21 | a | private |
5-
| modifiers.kt:2:13:2:21 | getA | private |
6-
| modifiers.kt:3:5:3:23 | b | private |
7-
| modifiers.kt:3:5:3:23 | b | protected |
8-
| modifiers.kt:3:15:3:23 | getB | protected |
9-
| modifiers.kt:4:5:4:22 | c | internal |
10-
| modifiers.kt:4:5:4:22 | c | private |
11-
| modifiers.kt:4:14:4:22 | getC | internal |
12-
| modifiers.kt:5:5:5:34 | d | private |
13-
| modifiers.kt:5:5:5:34 | d | public |
14-
| modifiers.kt:5:5:5:34 | getD | public |
15-
| modifiers.kt:7:5:9:5 | Nested | final |
16-
| modifiers.kt:7:5:9:5 | Nested | protected |
17-
| modifiers.kt:7:15:9:5 | Nested | public |
18-
| modifiers.kt:8:9:8:29 | e | private |
19-
| modifiers.kt:8:9:8:29 | e | public |
20-
| modifiers.kt:8:16:8:29 | getE | public |
21-
| modifiers.kt:11:5:15:5 | fn1 | public |
22-
| modifiers.kt:12:16:14:9 | | public |
23-
| modifiers.kt:12:16:14:9 | new Object(...) { ... } | final |
24-
| modifiers.kt:12:16:14:9 | new Object(...) { ... } | private |
25-
| modifiers.kt:13:13:13:23 | fn | public |
26-
| modifiers.kt:17:5:20:5 | fn2 | public |
27-
| modifiers.kt:18:9:18:24 | fnLocal | public |
28-
| modifiers.kt:18:9:18:24 | new Object(...) { ... } | final |
29-
| modifiers.kt:18:9:18:24 | new Object(...) { ... } | private |
1+
| modifiers.kt:1:1:25:1 | X | Class | public |
2+
| modifiers.kt:1:6:25:1 | X | Constructor | public |
3+
| modifiers.kt:2:5:2:21 | a | Field | private |
4+
| modifiers.kt:2:5:2:21 | a | Property | private |
5+
| modifiers.kt:2:13:2:21 | getA | Method | private |
6+
| modifiers.kt:3:5:3:23 | b | Field | private |
7+
| modifiers.kt:3:5:3:23 | b | Property | protected |
8+
| modifiers.kt:3:15:3:23 | getB | Method | protected |
9+
| modifiers.kt:4:5:4:22 | c | Field | private |
10+
| modifiers.kt:4:5:4:22 | c | Property | internal |
11+
| modifiers.kt:4:14:4:22 | getC | Method | internal |
12+
| modifiers.kt:5:5:5:34 | d | Field | private |
13+
| modifiers.kt:5:5:5:34 | d | Property | public |
14+
| modifiers.kt:5:5:5:34 | getD | Method | public |
15+
| modifiers.kt:7:5:9:5 | Nested | Class | final |
16+
| modifiers.kt:7:5:9:5 | Nested | Class | protected |
17+
| modifiers.kt:7:15:9:5 | Nested | Constructor | public |
18+
| modifiers.kt:8:9:8:29 | e | Field | private |
19+
| modifiers.kt:8:9:8:29 | e | Property | public |
20+
| modifiers.kt:8:16:8:29 | getE | Method | public |
21+
| modifiers.kt:11:5:15:5 | fn1 | Method | public |
22+
| modifiers.kt:12:16:14:9 | | Constructor | public |
23+
| modifiers.kt:12:16:14:9 | new Object(...) { ... } | AnonymousClass | final |
24+
| modifiers.kt:12:16:14:9 | new Object(...) { ... } | AnonymousClass | private |
25+
| modifiers.kt:12:16:14:9 | new Object(...) { ... } | LocalClass | final |
26+
| modifiers.kt:12:16:14:9 | new Object(...) { ... } | LocalClass | private |
27+
| modifiers.kt:13:13:13:23 | fn | Method | public |
28+
| modifiers.kt:17:5:20:5 | fn2 | Method | public |
29+
| modifiers.kt:18:9:18:24 | | Constructor | public |
30+
| modifiers.kt:18:9:18:24 | fnLocal | Method | public |
31+
| modifiers.kt:18:9:18:24 | new Object(...) { ... } | AnonymousClass | final |
32+
| modifiers.kt:18:9:18:24 | new Object(...) { ... } | AnonymousClass | private |
33+
| modifiers.kt:18:9:18:24 | new Object(...) { ... } | LocalClass | final |
34+
| modifiers.kt:18:9:18:24 | new Object(...) { ... } | LocalClass | private |
35+
| modifiers.kt:22:5:24:5 | fn3 | Method | public |
36+
| modifiers.kt:23:9:23:27 | localClass | Constructor | public |
37+
| modifiers.kt:23:9:23:27 | localClass | LocalClass | final |
38+
| modifiers.kt:23:9:23:27 | localClass | LocalClass | private |

java/ql/test/kotlin/library-tests/modifiers/modifiers.kt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,4 +18,8 @@ open class X {
1818
fun fnLocal() {}
1919
fnLocal()
2020
}
21+
22+
fun fn3() {
23+
class localClass {}
24+
}
2125
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,4 @@ import java
22

33
from Modifiable m, string mod
44
where m.fromSource() and m.hasModifier(mod)
5-
select m, mod
5+
select m, m.getAPrimaryQlClass(), mod

0 commit comments

Comments
 (0)