Kapt: Enums inside enum values should be forbidden (KT-22582)
This commit is contained in:
+34
@@ -22,6 +22,7 @@ import com.sun.tools.javac.parser.Tokens
|
|||||||
import com.sun.tools.javac.tree.JCTree
|
import com.sun.tools.javac.tree.JCTree
|
||||||
import com.sun.tools.javac.tree.JCTree.*
|
import com.sun.tools.javac.tree.JCTree.*
|
||||||
import com.sun.tools.javac.tree.TreeMaker
|
import com.sun.tools.javac.tree.TreeMaker
|
||||||
|
import com.sun.tools.javac.tree.TreeScanner
|
||||||
import kotlinx.kapt.KaptIgnored
|
import kotlinx.kapt.KaptIgnored
|
||||||
import org.jetbrains.kotlin.codegen.state.GenerationState
|
import org.jetbrains.kotlin.codegen.state.GenerationState
|
||||||
import org.jetbrains.kotlin.descriptors.*
|
import org.jetbrains.kotlin.descriptors.*
|
||||||
@@ -182,9 +183,42 @@ class ClassFileToSourceStubConverter(
|
|||||||
_bindings[clazz.name] = this
|
_bindings[clazz.name] = this
|
||||||
}
|
}
|
||||||
|
|
||||||
|
postProcess(topLevel)
|
||||||
|
|
||||||
return KaptStub(topLevel, lineMappings.serialize())
|
return KaptStub(topLevel, lineMappings.serialize())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private fun postProcess(topLevel: JCCompilationUnit) {
|
||||||
|
topLevel.accept(object : TreeScanner() {
|
||||||
|
override fun visitClassDef(clazz: JCClassDecl) {
|
||||||
|
// Delete enums inside enum values
|
||||||
|
if (clazz.isEnum()) {
|
||||||
|
for (child in clazz.defs) {
|
||||||
|
if (child is JCVariableDecl) {
|
||||||
|
deleteAllEnumsInside(child)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
super.visitClassDef(clazz)
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun JCClassDecl.isEnum() = mods.flags and Opcodes.ACC_ENUM.toLong() != 0L
|
||||||
|
|
||||||
|
private fun deleteAllEnumsInside(def: JCTree) {
|
||||||
|
def.accept(object : TreeScanner() {
|
||||||
|
override fun visitClassDef(clazz: JCClassDecl) {
|
||||||
|
clazz.defs = mapJList(clazz.defs) { child ->
|
||||||
|
if (child is JCClassDecl && child.isEnum()) null else child
|
||||||
|
}
|
||||||
|
|
||||||
|
super.visitClassDef(clazz)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
private fun convertImports(file: KtFile, classDeclaration: JCClassDecl): JavacList<JCTree> {
|
private fun convertImports(file: KtFile, classDeclaration: JCClassDecl): JavacList<JCTree> {
|
||||||
val imports = mutableListOf<JCTree.JCImport>()
|
val imports = mutableListOf<JCTree.JCImport>()
|
||||||
val importedShortNames = mutableSetOf<String>()
|
val importedShortNames = mutableSetOf<String>()
|
||||||
|
|||||||
@@ -10,4 +10,14 @@ enum class Enum2(@Anno1("first") val col: String, @Anno1("second") val col2: Int
|
|||||||
|
|
||||||
private fun privateEnumFun() {}
|
private fun privateEnumFun() {}
|
||||||
public fun publicEnumFun() {}
|
public fun publicEnumFun() {}
|
||||||
|
}
|
||||||
|
|
||||||
|
enum class Nested1 {
|
||||||
|
WHITE {
|
||||||
|
enum class Nested2 {
|
||||||
|
BLACK {
|
||||||
|
enum class Nested3 { RED }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
}
|
}
|
||||||
@@ -60,3 +60,16 @@ public enum Enum2 {
|
|||||||
int col2) {
|
int col2) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
////////////////////
|
||||||
|
|
||||||
|
|
||||||
|
import java.lang.System;
|
||||||
|
|
||||||
|
@kotlin.Metadata()
|
||||||
|
public enum Nested1 {
|
||||||
|
/*public static final*/ WHITE /* = new Nested1() */;
|
||||||
|
|
||||||
|
Nested1() {
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user