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

Skip to content

Commit 70bed04

Browse files
committed
Extract container of adapter function as compiler generated
1 parent 2bdcc10 commit 70bed04

5 files changed

Lines changed: 17 additions & 1 deletion

File tree

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -941,6 +941,10 @@ open class KotlinFileExtractor(
941941
extractLocalTypeDeclStmt(classId, s, callable, parent, idx)
942942
val ids = getLocallyVisibleFunctionLabels(s)
943943
tw.writeKtLocalFunction(ids.function)
944+
945+
if (s.origin == IrDeclarationOrigin.ADAPTER_FOR_CALLABLE_REFERENCE) {
946+
tw.writeCompiler_generated(classId, 1)
947+
}
944948
} else {
945949
logger.errorElement("Expected to find local function", s)
946950
}

java/ql/lib/config/semmlecode.dbscheme

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1220,3 +1220,9 @@ ktPropertyDelegates(
12201220
unique int id: @kt_property ref,
12211221
unique int variableId: @variable ref
12221222
)
1223+
1224+
compiler_generated(
1225+
unique int id: @top ref,
1226+
int kind: int ref
1227+
// 1: Kotlin declaring classes of adapter functions
1228+
);

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,9 @@ predicate dead(RefType dead) {
5050
// Exclude classes that look like they may be reflectively constructed.
5151
not dead.getAnAnnotation() instanceof ReflectiveAccessAnnotation and
5252
// Insist all source ancestors are dead as well.
53-
forall(RefType t | t.fromSource() and t = getASuperTypePlus(dead) | dead(t))
53+
forall(RefType t | t.fromSource() and t = getASuperTypePlus(dead) | dead(t)) and
54+
// Exclude compiler generated classes (e.g. declaring type of adapter functions in Kotlin)
55+
not compiler_generated(dead, _)
5456
}
5557

5658
from RefType t, string kind

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -184,3 +184,5 @@ memberVisibility
184184
| reflection.kt:109:17:109:27 | ...::... | reflection.kt:109:17:109:27 | set | public |
185185
| reflection.kt:116:40:116:44 | ...::... | reflection.kt:116:40:116:44 | invoke | public |
186186
| reflection.kt:126:9:126:13 | ...::... | reflection.kt:126:9:126:13 | invoke | public |
187+
compGenerated
188+
| reflection.kt:126:9:126:13 | | 1 |

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,3 +86,5 @@ query predicate memberVisibility(ClassInstanceExpr e, Method m, string modifier)
8686
e.getAnonymousClass().getAMethod() = m and
8787
m.hasModifier(modifier)
8888
}
89+
90+
query predicate compGenerated(Top t, int i) { compiler_generated(t, i) }

0 commit comments

Comments
 (0)