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

Skip to content

Commit 1926bef

Browse files
atorralbaigfoo
authored andcommitted
Don't extract static init when the class already contains an anonymous init
1 parent 3920b64 commit 1926bef

2 files changed

Lines changed: 5 additions & 4 deletions

File tree

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,8 @@ open class KotlinFileExtractor(
9999
if (isExternalDeclaration(declaration)) {
100100
extractExternalClassLater(declaration)
101101
} else {
102-
extractClassSource(declaration, true, true)
102+
val extractStaticInit = declaration.declarations.none { it is IrAnonymousInitializer }
103+
extractClassSource(declaration, true, extractStaticInit)
103104
}
104105
}
105106
is IrFunction -> {

java/ql/test/kotlin/library-tests/classes/PrintAst.expected

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ classes.kt:
7878
# 29| 5: [BlockStmt] { ... }
7979
# 29| 0: [ThisConstructorInvocationStmt] this(...)
8080
# 34| 10: [Class] ClassSeven
81-
# 35| 2: [Constructor] ClassSeven
81+
# 35| 1: [Constructor] ClassSeven
8282
#-----| 4: (Parameters)
8383
# 35| 0: [Parameter] i
8484
# 35| 5: [BlockStmt] { ... }
@@ -96,12 +96,12 @@ classes.kt:
9696
# 36| 2: [ExprStmt] <Expr>;
9797
# 36| 0: [MethodAccess] f(...)
9898
# 36| 0: [VarAccess] i
99-
# 42| 3: [Method] getX
99+
# 42| 2: [Method] getX
100100
# 42| 5: [BlockStmt] { ... }
101101
# 42| 0: [ReturnStmt] return ...
102102
# 42| 0: [VarAccess] this.x
103103
# 42| -1: [ThisAccess] this
104-
# 42| 3: [FieldDeclaration] int x;
104+
# 42| 2: [FieldDeclaration] int x;
105105
# 42| -1: [TypeAccess] int
106106
# 42| 0: [IntegerLiteral] 3
107107
# 49| 11: [Class] Direction

0 commit comments

Comments
 (0)