mirror of
https://github.com/github/codeql.git
synced 2026-05-02 04:05:14 +02:00
Add test
This commit is contained in:
@@ -0,0 +1,22 @@
|
||||
public class JavaUser {
|
||||
|
||||
public static void test() {
|
||||
|
||||
HasCompanion.staticMethod("1");
|
||||
HasCompanion.Companion.nonStaticMethod("2");
|
||||
HasCompanion.setStaticProp(HasCompanion.Companion.getNonStaticProp());
|
||||
HasCompanion.Companion.setNonStaticProp(HasCompanion.getStaticProp());
|
||||
HasCompanion.Companion.setPropWithStaticGetter(HasCompanion.Companion.getPropWithStaticSetter());
|
||||
HasCompanion.setPropWithStaticSetter(HasCompanion.getPropWithStaticGetter());
|
||||
|
||||
// These extract as static methods, since there is no proxy method in the non-companion object case.
|
||||
NonCompanion.staticMethod("1");
|
||||
NonCompanion.INSTANCE.nonStaticMethod("2");
|
||||
NonCompanion.setStaticProp(NonCompanion.INSTANCE.getNonStaticProp());
|
||||
NonCompanion.INSTANCE.setNonStaticProp(NonCompanion.getStaticProp());
|
||||
NonCompanion.INSTANCE.setPropWithStaticGetter(NonCompanion.INSTANCE.getPropWithStaticSetter());
|
||||
NonCompanion.setPropWithStaticSetter(NonCompanion.getPropWithStaticGetter());
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,74 @@
|
||||
staticMembers
|
||||
| JavaUser.java:1:14:1:21 | JavaUser | JavaUser.java:3:22:3:25 | test | Method |
|
||||
| test.kt:0:0:0:0 | TestKt | test.kt:49:1:67:1 | externalUser | Method |
|
||||
| test.kt:9:1:29:1 | HasCompanion | test.kt:11:3:27:3 | Companion | Class |
|
||||
| test.kt:9:1:29:1 | HasCompanion | test.kt:11:3:27:3 | Companion | Field |
|
||||
| test.kt:9:1:29:1 | HasCompanion | test.kt:13:16:13:71 | staticMethod | Method |
|
||||
| test.kt:9:1:29:1 | HasCompanion | test.kt:16:16:16:43 | getStaticProp | Method |
|
||||
| test.kt:9:1:29:1 | HasCompanion | test.kt:16:16:16:43 | setStaticProp | Method |
|
||||
| test.kt:9:1:29:1 | HasCompanion | test.kt:20:18:20:45 | getPropWithStaticGetter | Method |
|
||||
| test.kt:9:1:29:1 | HasCompanion | test.kt:25:18:25:60 | setPropWithStaticSetter | Method |
|
||||
| test.kt:31:1:47:1 | NonCompanion | test.kt:31:1:47:1 | INSTANCE | Field |
|
||||
| test.kt:31:1:47:1 | NonCompanion | test.kt:33:14:33:69 | staticMethod | Method |
|
||||
| test.kt:31:1:47:1 | NonCompanion | test.kt:36:14:36:41 | getStaticProp | Method |
|
||||
| test.kt:31:1:47:1 | NonCompanion | test.kt:36:14:36:41 | setStaticProp | Method |
|
||||
| test.kt:31:1:47:1 | NonCompanion | test.kt:40:16:40:43 | getPropWithStaticGetter | Method |
|
||||
| test.kt:31:1:47:1 | NonCompanion | test.kt:45:16:45:58 | setPropWithStaticSetter | Method |
|
||||
#select
|
||||
| test.kt:9:1:29:1 | HasCompanion | JavaUser.java:5:5:5:34 | staticMethod(...) | JavaUser.java:5:5:5:16 | HasCompanion | static |
|
||||
| test.kt:9:1:29:1 | HasCompanion | JavaUser.java:7:5:7:73 | setStaticProp(...) | JavaUser.java:7:5:7:16 | HasCompanion | static |
|
||||
| test.kt:9:1:29:1 | HasCompanion | JavaUser.java:8:45:8:72 | getStaticProp(...) | JavaUser.java:8:45:8:56 | HasCompanion | static |
|
||||
| test.kt:9:1:29:1 | HasCompanion | JavaUser.java:10:5:10:80 | setPropWithStaticSetter(...) | JavaUser.java:10:5:10:16 | HasCompanion | static |
|
||||
| test.kt:9:1:29:1 | HasCompanion | JavaUser.java:10:42:10:79 | getPropWithStaticGetter(...) | JavaUser.java:10:42:10:53 | HasCompanion | static |
|
||||
| test.kt:11:3:27:3 | Companion | JavaUser.java:6:5:6:47 | nonStaticMethod(...) | JavaUser.java:6:5:6:26 | HasCompanion.Companion | instance |
|
||||
| test.kt:11:3:27:3 | Companion | JavaUser.java:7:32:7:72 | getNonStaticProp(...) | JavaUser.java:7:32:7:53 | HasCompanion.Companion | instance |
|
||||
| test.kt:11:3:27:3 | Companion | JavaUser.java:8:5:8:73 | setNonStaticProp(...) | JavaUser.java:8:5:8:26 | HasCompanion.Companion | instance |
|
||||
| test.kt:11:3:27:3 | Companion | JavaUser.java:9:5:9:100 | setPropWithStaticGetter(...) | JavaUser.java:9:5:9:26 | HasCompanion.Companion | instance |
|
||||
| test.kt:11:3:27:3 | Companion | JavaUser.java:9:52:9:99 | getPropWithStaticSetter(...) | JavaUser.java:9:52:9:73 | HasCompanion.Companion | instance |
|
||||
| test.kt:11:3:27:3 | Companion | test.kt:13:16:13:71 | staticMethod(...) | test.kt:13:16:13:71 | HasCompanion.Companion | instance |
|
||||
| test.kt:11:3:27:3 | Companion | test.kt:13:54:13:71 | nonStaticMethod(...) | test.kt:13:54:13:71 | this | instance |
|
||||
| test.kt:11:3:27:3 | Companion | test.kt:14:46:14:60 | staticMethod(...) | test.kt:14:46:14:60 | this | instance |
|
||||
| test.kt:11:3:27:3 | Companion | test.kt:16:16:16:43 | getStaticProp(...) | test.kt:16:16:16:43 | HasCompanion.Companion | instance |
|
||||
| test.kt:11:3:27:3 | Companion | test.kt:16:16:16:43 | setStaticProp(...) | test.kt:16:16:16:43 | HasCompanion.Companion | instance |
|
||||
| test.kt:11:3:27:3 | Companion | test.kt:20:18:20:45 | getPropWithStaticGetter(...) | test.kt:20:18:20:45 | HasCompanion.Companion | instance |
|
||||
| test.kt:11:3:27:3 | Companion | test.kt:20:26:20:45 | getPropWithStaticSetter(...) | test.kt:20:26:20:45 | this | instance |
|
||||
| test.kt:11:3:27:3 | Companion | test.kt:21:24:21:43 | setPropWithStaticSetter(...) | test.kt:21:24:21:43 | this | instance |
|
||||
| test.kt:11:3:27:3 | Companion | test.kt:24:15:24:34 | getPropWithStaticGetter(...) | test.kt:24:15:24:34 | this | instance |
|
||||
| test.kt:11:3:27:3 | Companion | test.kt:25:18:25:60 | setPropWithStaticSetter(...) | test.kt:25:18:25:60 | HasCompanion.Companion | instance |
|
||||
| test.kt:11:3:27:3 | Companion | test.kt:25:35:25:54 | setPropWithStaticGetter(...) | test.kt:25:35:25:54 | this | instance |
|
||||
| test.kt:11:3:27:3 | Companion | test.kt:52:16:52:32 | staticMethod(...) | test.kt:52:3:52:14 | Companion | instance |
|
||||
| test.kt:11:3:27:3 | Companion | test.kt:53:16:53:35 | nonStaticMethod(...) | test.kt:53:3:53:14 | Companion | instance |
|
||||
| test.kt:11:3:27:3 | Companion | test.kt:54:3:54:25 | setStaticProp(...) | test.kt:54:3:54:14 | Companion | instance |
|
||||
| test.kt:11:3:27:3 | Companion | test.kt:54:42:54:54 | getNonStaticProp(...) | test.kt:54:29:54:40 | Companion | instance |
|
||||
| test.kt:11:3:27:3 | Companion | test.kt:55:3:55:28 | setNonStaticProp(...) | test.kt:55:3:55:14 | Companion | instance |
|
||||
| test.kt:11:3:27:3 | Companion | test.kt:55:45:55:54 | getStaticProp(...) | test.kt:55:32:55:43 | Companion | instance |
|
||||
| test.kt:11:3:27:3 | Companion | test.kt:56:3:56:35 | setPropWithStaticGetter(...) | test.kt:56:3:56:14 | Companion | instance |
|
||||
| test.kt:11:3:27:3 | Companion | test.kt:56:52:56:71 | getPropWithStaticSetter(...) | test.kt:56:39:56:50 | Companion | instance |
|
||||
| test.kt:11:3:27:3 | Companion | test.kt:57:3:57:35 | setPropWithStaticSetter(...) | test.kt:57:3:57:14 | Companion | instance |
|
||||
| test.kt:11:3:27:3 | Companion | test.kt:57:52:57:71 | getPropWithStaticGetter(...) | test.kt:57:39:57:50 | Companion | instance |
|
||||
| test.kt:31:1:47:1 | NonCompanion | JavaUser.java:13:5:13:34 | staticMethod(...) | JavaUser.java:13:5:13:16 | NonCompanion | static |
|
||||
| test.kt:31:1:47:1 | NonCompanion | JavaUser.java:14:5:14:46 | nonStaticMethod(...) | JavaUser.java:14:5:14:25 | NonCompanion.INSTANCE | instance |
|
||||
| test.kt:31:1:47:1 | NonCompanion | JavaUser.java:15:5:15:72 | setStaticProp(...) | JavaUser.java:15:5:15:16 | NonCompanion | static |
|
||||
| test.kt:31:1:47:1 | NonCompanion | JavaUser.java:15:32:15:71 | getNonStaticProp(...) | JavaUser.java:15:32:15:52 | NonCompanion.INSTANCE | instance |
|
||||
| test.kt:31:1:47:1 | NonCompanion | JavaUser.java:16:5:16:72 | setNonStaticProp(...) | JavaUser.java:16:5:16:25 | NonCompanion.INSTANCE | instance |
|
||||
| test.kt:31:1:47:1 | NonCompanion | JavaUser.java:16:44:16:71 | getStaticProp(...) | JavaUser.java:16:44:16:55 | NonCompanion | static |
|
||||
| test.kt:31:1:47:1 | NonCompanion | JavaUser.java:17:5:17:98 | setPropWithStaticGetter(...) | JavaUser.java:17:5:17:25 | NonCompanion.INSTANCE | instance |
|
||||
| test.kt:31:1:47:1 | NonCompanion | JavaUser.java:17:51:17:97 | getPropWithStaticSetter(...) | JavaUser.java:17:51:17:71 | NonCompanion.INSTANCE | instance |
|
||||
| test.kt:31:1:47:1 | NonCompanion | JavaUser.java:18:5:18:80 | setPropWithStaticSetter(...) | JavaUser.java:18:5:18:16 | NonCompanion | static |
|
||||
| test.kt:31:1:47:1 | NonCompanion | JavaUser.java:18:42:18:79 | getPropWithStaticGetter(...) | JavaUser.java:18:42:18:53 | NonCompanion | static |
|
||||
| test.kt:31:1:47:1 | NonCompanion | test.kt:33:52:33:69 | nonStaticMethod(...) | test.kt:33:52:33:69 | NonCompanion.INSTANCE | instance |
|
||||
| test.kt:31:1:47:1 | NonCompanion | test.kt:34:44:34:58 | staticMethod(...) | test.kt:34:44:34:58 | NonCompanion | static |
|
||||
| test.kt:31:1:47:1 | NonCompanion | test.kt:40:24:40:43 | getPropWithStaticSetter(...) | test.kt:40:24:40:43 | NonCompanion.INSTANCE | instance |
|
||||
| test.kt:31:1:47:1 | NonCompanion | test.kt:41:22:41:41 | setPropWithStaticSetter(...) | test.kt:41:22:41:41 | NonCompanion | static |
|
||||
| test.kt:31:1:47:1 | NonCompanion | test.kt:44:13:44:32 | getPropWithStaticGetter(...) | test.kt:44:13:44:32 | NonCompanion | static |
|
||||
| test.kt:31:1:47:1 | NonCompanion | test.kt:45:33:45:52 | setPropWithStaticGetter(...) | test.kt:45:33:45:52 | NonCompanion.INSTANCE | instance |
|
||||
| test.kt:31:1:47:1 | NonCompanion | test.kt:60:16:60:32 | staticMethod(...) | test.kt:60:16:60:32 | NonCompanion | static |
|
||||
| test.kt:31:1:47:1 | NonCompanion | test.kt:61:16:61:35 | nonStaticMethod(...) | test.kt:61:3:61:14 | INSTANCE | instance |
|
||||
| test.kt:31:1:47:1 | NonCompanion | test.kt:62:3:62:25 | setStaticProp(...) | test.kt:62:3:62:25 | NonCompanion | static |
|
||||
| test.kt:31:1:47:1 | NonCompanion | test.kt:62:42:62:54 | getNonStaticProp(...) | test.kt:62:29:62:40 | INSTANCE | instance |
|
||||
| test.kt:31:1:47:1 | NonCompanion | test.kt:63:3:63:28 | setNonStaticProp(...) | test.kt:63:3:63:14 | INSTANCE | instance |
|
||||
| test.kt:31:1:47:1 | NonCompanion | test.kt:63:45:63:54 | getStaticProp(...) | test.kt:63:45:63:54 | NonCompanion | static |
|
||||
| test.kt:31:1:47:1 | NonCompanion | test.kt:64:3:64:35 | setPropWithStaticGetter(...) | test.kt:64:3:64:14 | INSTANCE | instance |
|
||||
| test.kt:31:1:47:1 | NonCompanion | test.kt:64:52:64:71 | getPropWithStaticSetter(...) | test.kt:64:39:64:50 | INSTANCE | instance |
|
||||
| test.kt:31:1:47:1 | NonCompanion | test.kt:65:3:65:35 | setPropWithStaticSetter(...) | test.kt:65:3:65:35 | NonCompanion | static |
|
||||
| test.kt:31:1:47:1 | NonCompanion | test.kt:65:52:65:71 | getPropWithStaticGetter(...) | test.kt:65:52:65:71 | NonCompanion | static |
|
||||
@@ -0,0 +1,67 @@
|
||||
// Test both definining static members, and referring to an object's other static members, in companion object and non-companion object contexts.
|
||||
// For the companion object all the references to other properties and methods should extract as ordinary instance calls and field read and writes,
|
||||
// but those methods / getters / setters that are annotated static should get an additional static proxy method defined on the surrounding class--
|
||||
// for example, we should see (using Java notation) public static String HasCompanion.staticMethod(String s) { return Companion.staticMethod(s); }.
|
||||
// For the non-companion object, the static-annotated methods should themselves be extracted as static members, and calls / gets / sets that use them
|
||||
// should extract as static calls. Static members using non-static ones should extract like staticMethod(...) { INSTANCE.nonStaticMethod(...) },
|
||||
// where the reference to INSTANCE replaces what would normally be a `this` reference.
|
||||
|
||||
public class HasCompanion {
|
||||
|
||||
companion object {
|
||||
|
||||
@JvmStatic fun staticMethod(s: String): String = nonStaticMethod(s)
|
||||
fun nonStaticMethod(s: String): String = staticMethod(s)
|
||||
|
||||
@JvmStatic var staticProp: String = "a"
|
||||
var nonStaticProp: String = "b"
|
||||
|
||||
var propWithStaticGetter: String
|
||||
@JvmStatic get() = propWithStaticSetter
|
||||
set(s: String) { propWithStaticSetter = s }
|
||||
|
||||
var propWithStaticSetter: String
|
||||
get() = propWithStaticGetter
|
||||
@JvmStatic set(s: String) { propWithStaticGetter = s }
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
object NonCompanion {
|
||||
|
||||
@JvmStatic fun staticMethod(s: String): String = nonStaticMethod(s)
|
||||
fun nonStaticMethod(s: String): String = staticMethod(s)
|
||||
|
||||
@JvmStatic var staticProp: String = "a"
|
||||
var nonStaticProp: String = "b"
|
||||
|
||||
var propWithStaticGetter: String
|
||||
@JvmStatic get() = propWithStaticSetter
|
||||
set(s: String) { propWithStaticSetter = s }
|
||||
|
||||
var propWithStaticSetter: String
|
||||
get() = propWithStaticGetter
|
||||
@JvmStatic set(s: String) { propWithStaticGetter = s }
|
||||
|
||||
}
|
||||
|
||||
fun externalUser() {
|
||||
|
||||
// These all extract as instance calls (to HasCompanion.Companion), since a Kotlin caller won't use the static proxy methods generated by the @JvmStatic annotation.
|
||||
HasCompanion.staticMethod("1")
|
||||
HasCompanion.nonStaticMethod("2")
|
||||
HasCompanion.staticProp = HasCompanion.nonStaticProp
|
||||
HasCompanion.nonStaticProp = HasCompanion.staticProp
|
||||
HasCompanion.propWithStaticGetter = HasCompanion.propWithStaticSetter
|
||||
HasCompanion.propWithStaticSetter = HasCompanion.propWithStaticGetter
|
||||
|
||||
// These extract as static methods, since there is no proxy method in the non-companion object case.
|
||||
NonCompanion.staticMethod("1")
|
||||
NonCompanion.nonStaticMethod("2")
|
||||
NonCompanion.staticProp = NonCompanion.nonStaticProp
|
||||
NonCompanion.nonStaticProp = NonCompanion.staticProp
|
||||
NonCompanion.propWithStaticGetter = NonCompanion.propWithStaticSetter
|
||||
NonCompanion.propWithStaticSetter = NonCompanion.propWithStaticGetter
|
||||
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
import java
|
||||
|
||||
query predicate staticMembers(RefType declType, Member m, string kind) {
|
||||
|
||||
m.fromSource() and m.isStatic() and m.getDeclaringType() = declType and kind = m.getAPrimaryQlClass()
|
||||
|
||||
}
|
||||
|
||||
from Call call, Callable callable, RefType declType, Expr qualifier, string callType
|
||||
where call.getCallee() = callable and
|
||||
declType = callable.getDeclaringType() and
|
||||
qualifier = call.getQualifier() and
|
||||
if callable.isStatic() then callType = "static" else callType = "instance"
|
||||
select declType, call, qualifier, callType
|
||||
Reference in New Issue
Block a user