Skip to content

Commit e9835ec

Browse files
authored
Merge pull request github#10756 from tamasvajk/kotlin-fix-java-modifier
Kotlin: extract `protected` modifier from java class files
2 parents 66c2de8 + f2e2e3b commit e9835ec

File tree

6 files changed

+31
-1
lines changed

6 files changed

+31
-1
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -231,7 +231,7 @@ open class KotlinFileExtractor(
231231
// default java visibility (top level)
232232
}
233233
JavaVisibilities.ProtectedAndPackage -> {
234-
// default java visibility (member level)
234+
addModifiers(id, "protected")
235235
}
236236
else -> logger.errorElement("Unexpected delegated visibility: $v", elementForLocation)
237237
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
package extlib;
2+
3+
public class A {
4+
protected void m() {}
5+
}
6+
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
| extlib.jar/extlib/A.class:0:0:0:0 | m | protected |
2+
| test.kt:4:12:4:22 | m | override, protected |
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
import extlib.A;
2+
3+
class B : A() {
4+
override fun m() { }
5+
}
6+
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
from create_database_utils import *
2+
import glob
3+
4+
# Compile Java untraced. Note the Java source is hidden under `javasrc` so the Kotlin compiler
5+
# will certainly reference the jar, not the source or class file for extlib.Lib
6+
7+
os.mkdir('build')
8+
runSuccessfully(["javac"] + glob.glob("libsrc/extlib/*.java") + ["-d", "build"])
9+
runSuccessfully(["jar", "cf", "extlib.jar", "-C", "build", "extlib"])
10+
run_codeql_database_create(["kotlinc test.kt -cp extlib.jar"], lang="java")
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
import java
2+
3+
query predicate mods(Method m, string modifiers) {
4+
m.getName() = "m" and
5+
modifiers = concat(string s | m.hasModifier(s) | s, ", ")
6+
}

0 commit comments

Comments
 (0)