From 056bb3f83375a76ffd2afa1e62ddacd7fac70887 Mon Sep 17 00:00:00 2001 From: Alexander Udalov Date: Thu, 1 Oct 2015 18:13:52 +0300 Subject: [PATCH] Deprecate and don't write KotlinSyntheticClass$Kind, to be removed later --- .../org/jetbrains/kotlin/codegen/AsmUtil.java | 7 +--- .../kotlin/codegen/ClosureCodegen.java | 6 +-- .../kotlin/codegen/ExpressionCodegen.java | 24 ++++-------- .../codegen/InterfaceImplBodyCodegen.kt | 3 +- .../codegen/PropertyReferenceCodegen.kt | 3 +- .../kotlin/codegen/SamWrapperCodegen.java | 4 +- .../MappingClassesForWhenByEnumCodegen.java | 3 +- .../nullabilityAnnotations/Generic.java | 2 +- .../nullabilityAnnotations/Primitives.java | 2 +- .../PrivateInTrait.java | 2 +- .../nullabilityAnnotations/Trait.java | 2 +- .../TraitClassObjectField.java | 2 +- .../kotlin/codegen/InlineTestUtil.kt | 4 +- .../KotlinSyntheticClassAnnotationTest.java | 38 +++++++------------ .../kotlin/load/java/JvmAnnotationNames.java | 16 -------- .../load/kotlin/header/KotlinClassHeader.kt | 3 +- ...eadKotlinClassHeaderAnnotationVisitor.java | 4 +- .../jvm/internal/KotlinSyntheticClass.java | 4 +- .../kotlin/idea/decompiler/DecompiledUtils.kt | 10 +---- .../AbstractInternalCompiledClassesTest.kt | 35 ++++------------- .../decompiler/InternalCompiledClassesTest.kt | 13 +------ .../DecompiledTextForWrongAbiVersionTest.kt | 20 ++++------ .../jps/incremental/IncrementalCacheImpl.kt | 9 +---- 23 files changed, 58 insertions(+), 158 deletions(-) diff --git a/compiler/backend/src/org/jetbrains/kotlin/codegen/AsmUtil.java b/compiler/backend/src/org/jetbrains/kotlin/codegen/AsmUtil.java index 1f51e9a1fa4..c1dd07a8f9e 100644 --- a/compiler/backend/src/org/jetbrains/kotlin/codegen/AsmUtil.java +++ b/compiler/backend/src/org/jetbrains/kotlin/codegen/AsmUtil.java @@ -834,14 +834,9 @@ public class AsmUtil { } } - public static void writeKotlinSyntheticClassAnnotation(@NotNull ClassBuilder v, @NotNull KotlinSyntheticClass.Kind kind) { + public static void writeKotlinSyntheticClassAnnotation(@NotNull ClassBuilder v) { AnnotationVisitor av = v.newAnnotation(Type.getObjectType(KotlinSyntheticClass.CLASS_NAME.getInternalName()).getDescriptor(), true); JvmCodegenUtil.writeAbiVersion(av); - av.visitEnum( - JvmAnnotationNames.KIND_FIELD_NAME, - Type.getObjectType(KotlinSyntheticClass.KIND_INTERNAL_NAME).getDescriptor(), - kind.toString() - ); av.visitEnd(); } diff --git a/compiler/backend/src/org/jetbrains/kotlin/codegen/ClosureCodegen.java b/compiler/backend/src/org/jetbrains/kotlin/codegen/ClosureCodegen.java index 1e03b39e9ae..a75721606ff 100644 --- a/compiler/backend/src/org/jetbrains/kotlin/codegen/ClosureCodegen.java +++ b/compiler/backend/src/org/jetbrains/kotlin/codegen/ClosureCodegen.java @@ -60,7 +60,6 @@ import static org.jetbrains.kotlin.codegen.ExpressionCodegen.generateClassLitera import static org.jetbrains.kotlin.codegen.JvmCodegenUtil.isConst; import static org.jetbrains.kotlin.codegen.binding.CodegenBinding.CLOSURE; import static org.jetbrains.kotlin.codegen.binding.CodegenBinding.asmTypeForAnonymousClass; -import static org.jetbrains.kotlin.load.java.JvmAnnotationNames.KotlinSyntheticClass; import static org.jetbrains.kotlin.resolve.descriptorUtil.DescriptorUtilPackage.getBuiltIns; import static org.jetbrains.kotlin.resolve.jvm.AsmTypes.*; import static org.jetbrains.kotlin.resolve.jvm.diagnostics.DiagnosticsPackage.OtherOrigin; @@ -78,7 +77,6 @@ public class ClosureCodegen extends MemberCodegen { private final CalculatedClosure closure; private final Type asmType; private final int visibilityFlag; - private final KotlinSyntheticClass.Kind syntheticClassKind; private Method constructor; private Type superClassAsmType; @@ -88,7 +86,6 @@ public class ClosureCodegen extends MemberCodegen { @NotNull JetElement element, @Nullable SamType samType, @NotNull ClosureContext context, - @NotNull KotlinSyntheticClass.Kind syntheticClassKind, @Nullable FunctionDescriptor functionReferenceTarget, @NotNull FunctionGenerationStrategy strategy, @NotNull MemberCodegen parentCodegen, @@ -99,7 +96,6 @@ public class ClosureCodegen extends MemberCodegen { this.funDescriptor = context.getFunctionDescriptor(); this.classDescriptor = context.getContextDescriptor(); this.samType = samType; - this.syntheticClassKind = syntheticClassKind; this.functionReferenceTarget = functionReferenceTarget; this.strategy = strategy; @@ -223,7 +219,7 @@ public class ClosureCodegen extends MemberCodegen { @Override protected void generateKotlinAnnotation() { - writeKotlinSyntheticClassAnnotation(v, syntheticClassKind); + writeKotlinSyntheticClassAnnotation(v); DescriptorSerializer serializer = DescriptorSerializer.createTopLevel(new JvmSerializerExtension(v.getSerializationBindings(), typeMapper)); diff --git a/compiler/backend/src/org/jetbrains/kotlin/codegen/ExpressionCodegen.java b/compiler/backend/src/org/jetbrains/kotlin/codegen/ExpressionCodegen.java index c1f0cf909bf..a16011ba56b 100644 --- a/compiler/backend/src/org/jetbrains/kotlin/codegen/ExpressionCodegen.java +++ b/compiler/backend/src/org/jetbrains/kotlin/codegen/ExpressionCodegen.java @@ -94,7 +94,6 @@ import static org.jetbrains.kotlin.builtins.KotlinBuiltIns.isInt; import static org.jetbrains.kotlin.codegen.AsmUtil.*; import static org.jetbrains.kotlin.codegen.JvmCodegenUtil.*; import static org.jetbrains.kotlin.codegen.binding.CodegenBinding.*; -import static org.jetbrains.kotlin.load.java.JvmAnnotationNames.KotlinSyntheticClass; import static org.jetbrains.kotlin.psi.PsiPackage.JetPsiFactory; import static org.jetbrains.kotlin.resolve.BindingContext.*; import static org.jetbrains.kotlin.resolve.BindingContextUtils.*; @@ -1380,7 +1379,7 @@ public class ExpressionCodegen extends JetVisitor implem return StackValue.none(); } - StackValue closure = genClosure(function, null, KotlinSyntheticClass.Kind.LOCAL_FUNCTION); + StackValue closure = genClosure(function, null); if (isStatement) { DeclarationDescriptor descriptor = bindingContext.get(DECLARATION_TO_DESCRIPTOR, function); int index = lookupLocalIndex(descriptor); @@ -1399,21 +1398,17 @@ public class ExpressionCodegen extends JetVisitor implem return gen(expression.getFunctionLiteral().getBodyExpression()); } else { - return genClosure(expression.getFunctionLiteral(), null, KotlinSyntheticClass.Kind.ANONYMOUS_FUNCTION); + return genClosure(expression.getFunctionLiteral(), null); } } @NotNull - private StackValue genClosure( - JetDeclarationWithBody declaration, - @Nullable SamType samType, - @NotNull KotlinSyntheticClass.Kind kind - ) { + private StackValue genClosure(JetDeclarationWithBody declaration, @Nullable SamType samType) { FunctionDescriptor descriptor = bindingContext.get(FUNCTION, declaration); assert descriptor != null : "Function is not resolved to descriptor: " + declaration.getText(); return genClosure( - declaration, descriptor, new FunctionGenerationStrategy.FunctionDefault(state, descriptor, declaration), samType, kind, null + declaration, descriptor, new FunctionGenerationStrategy.FunctionDefault(state, descriptor, declaration), samType, null ); } @@ -1423,7 +1418,6 @@ public class ExpressionCodegen extends JetVisitor implem @NotNull FunctionDescriptor descriptor, @NotNull FunctionGenerationStrategy strategy, @Nullable SamType samType, - @NotNull KotlinSyntheticClass.Kind kind, @Nullable FunctionDescriptor functionReferenceTarget ) { ClassBuilder cv = state.getFactory().newVisitor( @@ -1433,7 +1427,7 @@ public class ExpressionCodegen extends JetVisitor implem ); ClosureCodegen closureCodegen = new ClosureCodegen( - state, declaration, samType, context.intoClosure(descriptor, this, typeMapper), kind, + state, declaration, samType, context.intoClosure(descriptor, this, typeMapper), functionReferenceTarget, strategy, parentCodegen, cv ); @@ -2298,12 +2292,11 @@ public class ExpressionCodegen extends JetVisitor implem if (samType == null || expression == null) return null; if (expression instanceof JetFunctionLiteralExpression) { - return genClosure(((JetFunctionLiteralExpression) expression).getFunctionLiteral(), samType, - KotlinSyntheticClass.Kind.SAM_LAMBDA); + return genClosure(((JetFunctionLiteralExpression) expression).getFunctionLiteral(), samType); } if (expression instanceof JetNamedFunction) { - return genClosure((JetNamedFunction) expression, samType, KotlinSyntheticClass.Kind.SAM_LAMBDA); + return genClosure((JetNamedFunction) expression, samType); } final Type asmType = @@ -2773,8 +2766,7 @@ public class ExpressionCodegen extends JetVisitor implem FunctionDescriptor functionDescriptor = bindingContext.get(FUNCTION, expression); if (functionDescriptor != null) { FunctionReferenceGenerationStrategy strategy = new FunctionReferenceGenerationStrategy(state, functionDescriptor, resolvedCall); - return genClosure(expression, functionDescriptor, strategy, null, KotlinSyntheticClass.Kind.CALLABLE_REFERENCE_WRAPPER, - (FunctionDescriptor) resolvedCall.getResultingDescriptor()); + return genClosure(expression, functionDescriptor, strategy, null, (FunctionDescriptor) resolvedCall.getResultingDescriptor()); } VariableDescriptor variableDescriptor = bindingContext.get(VARIABLE, expression); diff --git a/compiler/backend/src/org/jetbrains/kotlin/codegen/InterfaceImplBodyCodegen.kt b/compiler/backend/src/org/jetbrains/kotlin/codegen/InterfaceImplBodyCodegen.kt index cdd12ef601d..8722cfa1001 100644 --- a/compiler/backend/src/org/jetbrains/kotlin/codegen/InterfaceImplBodyCodegen.kt +++ b/compiler/backend/src/org/jetbrains/kotlin/codegen/InterfaceImplBodyCodegen.kt @@ -26,7 +26,6 @@ import org.jetbrains.kotlin.descriptors.impl.ClassDescriptorImpl import org.jetbrains.kotlin.load.java.JvmAbi import org.jetbrains.kotlin.load.java.JvmAnnotationNames import org.jetbrains.kotlin.load.java.JvmAnnotationNames.KOTLIN_INTERFACE_DEFAULT_IMPLS -import org.jetbrains.kotlin.load.java.JvmAnnotationNames.KotlinSyntheticClass.Kind.TRAIT_IMPL import org.jetbrains.kotlin.load.java.descriptors.JavaMethodDescriptor import org.jetbrains.kotlin.name.Name import org.jetbrains.kotlin.psi.JetClassOrObject @@ -149,6 +148,6 @@ public class InterfaceImplBodyCodegen( val av = v.newAnnotation(AsmUtil.asmDescByFqNameWithoutInnerClasses(KOTLIN_INTERFACE_DEFAULT_IMPLS), true) av.visit(JvmAnnotationNames.VERSION_FIELD_NAME, JvmAbi.VERSION.toArray()) av.visitEnd() - AsmUtil.writeKotlinSyntheticClassAnnotation(v, TRAIT_IMPL) + AsmUtil.writeKotlinSyntheticClassAnnotation(v) } } diff --git a/compiler/backend/src/org/jetbrains/kotlin/codegen/PropertyReferenceCodegen.kt b/compiler/backend/src/org/jetbrains/kotlin/codegen/PropertyReferenceCodegen.kt index 5282696ae83..f07d83937a5 100644 --- a/compiler/backend/src/org/jetbrains/kotlin/codegen/PropertyReferenceCodegen.kt +++ b/compiler/backend/src/org/jetbrains/kotlin/codegen/PropertyReferenceCodegen.kt @@ -24,7 +24,6 @@ import org.jetbrains.kotlin.descriptors.* import org.jetbrains.kotlin.descriptors.annotations.Annotations import org.jetbrains.kotlin.descriptors.impl.SimpleFunctionDescriptorImpl import org.jetbrains.kotlin.load.java.JvmAbi -import org.jetbrains.kotlin.load.java.JvmAnnotationNames.KotlinSyntheticClass import org.jetbrains.kotlin.name.Name import org.jetbrains.kotlin.psi.JetCallableReferenceExpression import org.jetbrains.kotlin.resolve.DescriptorFactory @@ -192,7 +191,7 @@ public class PropertyReferenceCodegen( } override fun generateKotlinAnnotation() { - writeKotlinSyntheticClassAnnotation(v, KotlinSyntheticClass.Kind.CALLABLE_REFERENCE_WRAPPER) + writeKotlinSyntheticClassAnnotation(v) } public fun putInstanceOnStack(): StackValue = diff --git a/compiler/backend/src/org/jetbrains/kotlin/codegen/SamWrapperCodegen.java b/compiler/backend/src/org/jetbrains/kotlin/codegen/SamWrapperCodegen.java index 3b8d505e64b..915517e8d89 100644 --- a/compiler/backend/src/org/jetbrains/kotlin/codegen/SamWrapperCodegen.java +++ b/compiler/backend/src/org/jetbrains/kotlin/codegen/SamWrapperCodegen.java @@ -17,7 +17,6 @@ package org.jetbrains.kotlin.codegen; import org.jetbrains.annotations.NotNull; -import org.jetbrains.kotlin.codegen.context.CodegenContext; import org.jetbrains.kotlin.codegen.state.GenerationState; import org.jetbrains.kotlin.codegen.state.JetTypeMapper; import org.jetbrains.kotlin.descriptors.*; @@ -40,7 +39,6 @@ import org.jetbrains.org.objectweb.asm.commons.InstructionAdapter; import java.util.Collections; import static org.jetbrains.kotlin.codegen.AsmUtil.*; -import static org.jetbrains.kotlin.load.java.JvmAnnotationNames.KotlinSyntheticClass; import static org.jetbrains.kotlin.resolve.jvm.AsmTypes.OBJECT_TYPE; import static org.jetbrains.kotlin.resolve.jvm.diagnostics.DiagnosticsPackage.OtherOrigin; import static org.jetbrains.org.objectweb.asm.Opcodes.*; @@ -95,7 +93,7 @@ public class SamWrapperCodegen { ); cv.visitSource(file.getName(), null); - writeKotlinSyntheticClassAnnotation(cv, KotlinSyntheticClass.Kind.SAM_WRAPPER); + writeKotlinSyntheticClassAnnotation(cv); // e.g. ASM type for Function2 Type functionAsmType = typeMapper.mapType(functionType); diff --git a/compiler/backend/src/org/jetbrains/kotlin/codegen/when/MappingClassesForWhenByEnumCodegen.java b/compiler/backend/src/org/jetbrains/kotlin/codegen/when/MappingClassesForWhenByEnumCodegen.java index 076efdc846e..ff25f5a9f33 100644 --- a/compiler/backend/src/org/jetbrains/kotlin/codegen/when/MappingClassesForWhenByEnumCodegen.java +++ b/compiler/backend/src/org/jetbrains/kotlin/codegen/when/MappingClassesForWhenByEnumCodegen.java @@ -31,7 +31,6 @@ import java.util.List; import java.util.Map; import static org.jetbrains.kotlin.codegen.AsmUtil.writeKotlinSyntheticClassAnnotation; -import static org.jetbrains.kotlin.load.java.JvmAnnotationNames.KotlinSyntheticClass.Kind.WHEN_ON_ENUM_MAPPINGS; import static org.jetbrains.kotlin.resolve.jvm.AsmTypes.OBJECT_TYPE; import static org.jetbrains.org.objectweb.asm.Opcodes.*; @@ -58,7 +57,7 @@ public class MappingClassesForWhenByEnumCodegen { generateFields(cb, mappings); generateInitialization(cb, mappings); - writeKotlinSyntheticClassAnnotation(cb, WHEN_ON_ENUM_MAPPINGS); + writeKotlinSyntheticClassAnnotation(cb); cb.done(); } diff --git a/compiler/testData/asJava/lightClasses/nullabilityAnnotations/Generic.java b/compiler/testData/asJava/lightClasses/nullabilityAnnotations/Generic.java index aa3337f3398..86771672dda 100644 --- a/compiler/testData/asJava/lightClasses/nullabilityAnnotations/Generic.java +++ b/compiler/testData/asJava/lightClasses/nullabilityAnnotations/Generic.java @@ -10,7 +10,7 @@ public interface Generic { @org.jetbrains.annotations.Nullable NN b1(@org.jetbrains.annotations.Nullable NN nn); - @kotlin.jvm.internal.KotlinSyntheticClass(version = {0, 27, 0}, abiVersion = 27, kind = kotlin.jvm.internal.KotlinSyntheticClass.Kind.TRAIT_IMPL) + @kotlin.jvm.internal.KotlinSyntheticClass(version = {0, 27, 0}, abiVersion = 27) static final class DefaultImpls { } } \ No newline at end of file diff --git a/compiler/testData/asJava/lightClasses/nullabilityAnnotations/Primitives.java b/compiler/testData/asJava/lightClasses/nullabilityAnnotations/Primitives.java index de71d90c24a..cbfcae60bff 100644 --- a/compiler/testData/asJava/lightClasses/nullabilityAnnotations/Primitives.java +++ b/compiler/testData/asJava/lightClasses/nullabilityAnnotations/Primitives.java @@ -41,7 +41,7 @@ public interface Primitives { double getDouble(); - @kotlin.jvm.internal.KotlinSyntheticClass(version = {0, 27, 0}, abiVersion = 27, kind = kotlin.jvm.internal.KotlinSyntheticClass.Kind.TRAIT_IMPL) + @kotlin.jvm.internal.KotlinSyntheticClass(version = {0, 27, 0}, abiVersion = 27) static final class DefaultImpls { } } \ No newline at end of file diff --git a/compiler/testData/asJava/lightClasses/nullabilityAnnotations/PrivateInTrait.java b/compiler/testData/asJava/lightClasses/nullabilityAnnotations/PrivateInTrait.java index 727d6356453..45f39d0c405 100644 --- a/compiler/testData/asJava/lightClasses/nullabilityAnnotations/PrivateInTrait.java +++ b/compiler/testData/asJava/lightClasses/nullabilityAnnotations/PrivateInTrait.java @@ -1,5 +1,5 @@ public interface PrivateInTrait { - @kotlin.jvm.internal.KotlinSyntheticClass(version = {0, 27, 0}, abiVersion = 27, kind = kotlin.jvm.internal.KotlinSyntheticClass.Kind.TRAIT_IMPL) + @kotlin.jvm.internal.KotlinSyntheticClass(version = {0, 27, 0}, abiVersion = 27) static final class DefaultImpls { @org.jetbrains.annotations.NotNull static java.lang.String getNn(PrivateInTrait $this) { /* compiled code */ } diff --git a/compiler/testData/asJava/lightClasses/nullabilityAnnotations/Trait.java b/compiler/testData/asJava/lightClasses/nullabilityAnnotations/Trait.java index decb4ff3cbd..ab7bbc78305 100644 --- a/compiler/testData/asJava/lightClasses/nullabilityAnnotations/Trait.java +++ b/compiler/testData/asJava/lightClasses/nullabilityAnnotations/Trait.java @@ -35,7 +35,7 @@ public interface Trait { void setNotNullVar(@org.jetbrains.annotations.NotNull java.lang.String p); - @kotlin.jvm.internal.KotlinSyntheticClass(version = {0, 27, 0}, abiVersion = 27, kind = kotlin.jvm.internal.KotlinSyntheticClass.Kind.TRAIT_IMPL) + @kotlin.jvm.internal.KotlinSyntheticClass(version = {0, 27, 0}, abiVersion = 27) static final class DefaultImpls { } } \ No newline at end of file diff --git a/compiler/testData/asJava/lightClasses/nullabilityAnnotations/TraitClassObjectField.java b/compiler/testData/asJava/lightClasses/nullabilityAnnotations/TraitClassObjectField.java index 6501c03d518..6aef8bf2be0 100644 --- a/compiler/testData/asJava/lightClasses/nullabilityAnnotations/TraitClassObjectField.java +++ b/compiler/testData/asJava/lightClasses/nullabilityAnnotations/TraitClassObjectField.java @@ -16,7 +16,7 @@ public interface TraitClassObjectField { private Companion() { /* compiled code */ } } - @kotlin.jvm.internal.KotlinSyntheticClass(version = {0, 27, 0}, abiVersion = 27, kind = kotlin.jvm.internal.KotlinSyntheticClass.Kind.TRAIT_IMPL) + @kotlin.jvm.internal.KotlinSyntheticClass(version = {0, 27, 0}, abiVersion = 27) static final class DefaultImpls { } } \ No newline at end of file diff --git a/compiler/tests/org/jetbrains/kotlin/codegen/InlineTestUtil.kt b/compiler/tests/org/jetbrains/kotlin/codegen/InlineTestUtil.kt index 7befe7fc776..3c09b0e4d37 100644 --- a/compiler/tests/org/jetbrains/kotlin/codegen/InlineTestUtil.kt +++ b/compiler/tests/org/jetbrains/kotlin/codegen/InlineTestUtil.kt @@ -185,9 +185,7 @@ public object InlineTestUtil { } private fun isClassOrPackagePartKind(header: KotlinClassHeader): Boolean { - return header.classKind == JvmAnnotationNames.KotlinClass.Kind.CLASS - || header.syntheticClassKind == JvmAnnotationNames.KotlinSyntheticClass.Kind.PACKAGE_PART - || header.isInterfaceDefaultImpls + return header.classKind == JvmAnnotationNames.KotlinClass.Kind.CLASS || header.isInterfaceDefaultImpls } private fun getClassHeader(file: OutputFile): KotlinClassHeader { diff --git a/compiler/tests/org/jetbrains/kotlin/codegen/KotlinSyntheticClassAnnotationTest.java b/compiler/tests/org/jetbrains/kotlin/codegen/KotlinSyntheticClassAnnotationTest.java index 98e799f3235..c02e8d2ff2a 100644 --- a/compiler/tests/org/jetbrains/kotlin/codegen/KotlinSyntheticClassAnnotationTest.java +++ b/compiler/tests/org/jetbrains/kotlin/codegen/KotlinSyntheticClassAnnotationTest.java @@ -19,6 +19,7 @@ package org.jetbrains.kotlin.codegen; import com.google.common.base.Predicate; import com.google.common.collect.Collections2; import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; import org.jetbrains.kotlin.backend.common.output.OutputFile; import org.jetbrains.kotlin.load.java.AbiVersionUtil; import org.jetbrains.kotlin.load.java.JvmAbi; @@ -36,7 +37,6 @@ import java.util.List; import static org.jetbrains.kotlin.load.java.JvmAnnotationNames.KIND_FIELD_NAME; import static org.jetbrains.kotlin.load.java.JvmAnnotationNames.KotlinClass.Kind.ANONYMOUS_OBJECT; import static org.jetbrains.kotlin.load.java.JvmAnnotationNames.KotlinClass.Kind.LOCAL_CLASS; -import static org.jetbrains.kotlin.load.java.JvmAnnotationNames.KotlinSyntheticClass.Kind.*; import static org.jetbrains.kotlin.load.java.JvmAnnotationNames.VERSION_FIELD_NAME; public class KotlinSyntheticClassAnnotationTest extends CodegenTestCase { @@ -51,48 +51,42 @@ public class KotlinSyntheticClassAnnotationTest extends CodegenTestCase { public void testTraitImpl() { doTestKotlinSyntheticClass( "interface A { fun foo() = 42 }", - JvmAbi.DEFAULT_IMPLS_SUFFIX, - TRAIT_IMPL + JvmAbi.DEFAULT_IMPLS_SUFFIX ); } public void testSamWrapper() { doTestKotlinSyntheticClass( "val f = {}\nval foo = Thread(f)", - "$sam", - SAM_WRAPPER + "$sam" ); } public void testSamLambda() { doTestKotlinSyntheticClass( "val foo = Thread { }", - "$1", - SAM_LAMBDA + "$1" ); } public void testCallableReferenceWrapper() { doTestKotlinSyntheticClass( "val f = String::get", - "$1", - CALLABLE_REFERENCE_WRAPPER + "$1" ); } public void testLocalFunction() { doTestKotlinSyntheticClass( "fun foo() { fun bar() {} }", - "$1", - LOCAL_FUNCTION + "$1" ); } public void testAnonymousFunction() { doTestKotlinSyntheticClass( "val f = {}", - "$1", - ANONYMOUS_FUNCTION + "$1" ); } @@ -107,8 +101,7 @@ public class KotlinSyntheticClassAnnotationTest extends CodegenTestCase { public void testLocalTraitImpl() { doTestKotlinSyntheticClass( "fun foo() { interface Local { fun bar() = 42 } }", - "Local$DefaultImpls.class", - LOCAL_TRAIT_IMPL + "Local$DefaultImpls.class" ); } @@ -140,17 +133,12 @@ public class KotlinSyntheticClassAnnotationTest extends CodegenTestCase { doTestKotlinSyntheticClass( "enum class E { A }\n" + "val x = when (E.A) { E.A -> 1; else -> 0; }", - "WhenMappings", - WHEN_ON_ENUM_MAPPINGS + "WhenMappings" ); } - private void doTestKotlinSyntheticClass( - @NotNull String code, - @NotNull String classFilePart, - @NotNull KotlinSyntheticClass.Kind expectedKind - ) { - doTest(code, classFilePart, KotlinSyntheticClass.CLASS_NAME, expectedKind.toString()); + private void doTestKotlinSyntheticClass(@NotNull String code, @NotNull String classFilePart) { + doTest(code, classFilePart, KotlinSyntheticClass.CLASS_NAME, null); } private void doTestKotlinClass( @@ -165,7 +153,7 @@ public class KotlinSyntheticClassAnnotationTest extends CodegenTestCase { @NotNull String code, @NotNull final String classFilePart, @NotNull JvmClassName annotationName, - @NotNull String expectedKind + @Nullable String expectedKind ) { loadText("package " + PACKAGE_NAME + "\n\n" + code); List output = generateClassesInFile().asList(); @@ -187,7 +175,7 @@ public class KotlinSyntheticClassAnnotationTest extends CodegenTestCase { private void assertAnnotatedWithKind( @NotNull Class aClass, @NotNull String annotationFqName, - @NotNull String expectedKind + @Nullable String expectedKind ) { Class annotationClass = loadAnnotationClassQuietly(annotationFqName); assertTrue("No annotation " + annotationFqName + " found in " + aClass, aClass.isAnnotationPresent(annotationClass)); diff --git a/core/descriptor.loader.java/src/org/jetbrains/kotlin/load/java/JvmAnnotationNames.java b/core/descriptor.loader.java/src/org/jetbrains/kotlin/load/java/JvmAnnotationNames.java index ab8f109babf..c690ccb0d14 100644 --- a/core/descriptor.loader.java/src/org/jetbrains/kotlin/load/java/JvmAnnotationNames.java +++ b/core/descriptor.loader.java/src/org/jetbrains/kotlin/load/java/JvmAnnotationNames.java @@ -90,22 +90,6 @@ public final class JvmAnnotationNames { public static final ClassId KIND_CLASS_ID = ClassId.topLevel(CLASS_NAME.getFqNameForClassNameWithoutDollars()).createNestedClassId(Name.identifier("Kind")); public static final String KIND_INTERNAL_NAME = JvmClassName.byClassId(KIND_CLASS_ID).getInternalName(); - - /** - * This enum duplicates {@link kotlin.jvm.internal.KotlinSyntheticClass.Kind}. Both places should be updated simultaneously. - */ - public enum Kind { - PACKAGE_PART, - TRAIT_IMPL, - LOCAL_TRAIT_IMPL, - SAM_WRAPPER, - SAM_LAMBDA, - CALLABLE_REFERENCE_WRAPPER, - LOCAL_FUNCTION, - ANONYMOUS_FUNCTION, - WHEN_ON_ENUM_MAPPINGS, - ; - } } @Deprecated diff --git a/core/descriptor.loader.java/src/org/jetbrains/kotlin/load/kotlin/header/KotlinClassHeader.kt b/core/descriptor.loader.java/src/org/jetbrains/kotlin/load/kotlin/header/KotlinClassHeader.kt index 9d2a5c4b167..f12bc55a7a6 100644 --- a/core/descriptor.loader.java/src/org/jetbrains/kotlin/load/kotlin/header/KotlinClassHeader.kt +++ b/core/descriptor.loader.java/src/org/jetbrains/kotlin/load/kotlin/header/KotlinClassHeader.kt @@ -27,7 +27,7 @@ public class KotlinClassHeader( public val annotationData: Array?, public val strings: Array?, public val classKind: KotlinClass.Kind?, - public val syntheticClassKind: KotlinSyntheticClass.Kind?, + public val syntheticClassKind: String?, public val filePartClassNames: Array?, public val multifileClassName: String?, public val isInterfaceDefaultImpls: Boolean @@ -55,4 +55,3 @@ public fun KotlinClassHeader.isCompatiblePackageFacadeKind(): Boolean = isCompat public fun KotlinClassHeader.isCompatibleFileFacadeKind(): Boolean = isCompatibleAbiVersion && kind == KotlinClassHeader.Kind.FILE_FACADE public fun KotlinClassHeader.isCompatibleMultifileClassKind(): Boolean = isCompatibleAbiVersion && kind == KotlinClassHeader.Kind.MULTIFILE_CLASS public fun KotlinClassHeader.isCompatibleMultifileClassPartKind(): Boolean = isCompatibleAbiVersion && kind == KotlinClassHeader.Kind.MULTIFILE_CLASS_PART -public fun KotlinClassHeader.isCompatibleSyntheticClassKind(): Boolean = isCompatibleAbiVersion && kind == KotlinClassHeader.Kind.SYNTHETIC_CLASS diff --git a/core/descriptor.loader.java/src/org/jetbrains/kotlin/load/kotlin/header/ReadKotlinClassHeaderAnnotationVisitor.java b/core/descriptor.loader.java/src/org/jetbrains/kotlin/load/kotlin/header/ReadKotlinClassHeaderAnnotationVisitor.java index 6a0a9d91c84..ecbb2d71eff 100644 --- a/core/descriptor.loader.java/src/org/jetbrains/kotlin/load/kotlin/header/ReadKotlinClassHeaderAnnotationVisitor.java +++ b/core/descriptor.loader.java/src/org/jetbrains/kotlin/load/kotlin/header/ReadKotlinClassHeaderAnnotationVisitor.java @@ -67,7 +67,7 @@ public class ReadKotlinClassHeaderAnnotationVisitor implements AnnotationVisitor private String[] strings = null; private KotlinClassHeader.Kind headerKind = null; private KotlinClass.Kind classKind = null; - private KotlinSyntheticClass.Kind syntheticClassKind = null; + private String syntheticClassKind = null; private boolean isInterfaceDefaultImpls = false; @Nullable @@ -312,7 +312,7 @@ public class ReadKotlinClassHeaderAnnotationVisitor implements AnnotationVisitor @Override public void visitEnum(@NotNull Name name, @NotNull ClassId enumClassId, @NotNull Name enumEntryName) { if (KotlinSyntheticClass.KIND_CLASS_ID.equals(enumClassId) && KIND_FIELD_NAME.equals(name.asString())) { - syntheticClassKind = valueOfOrNull(KotlinSyntheticClass.Kind.class, enumEntryName.asString()); + syntheticClassKind = enumEntryName.asString(); } } } diff --git a/core/runtime.jvm/src/kotlin/jvm/internal/KotlinSyntheticClass.java b/core/runtime.jvm/src/kotlin/jvm/internal/KotlinSyntheticClass.java index d29cd040e73..29281657929 100644 --- a/core/runtime.jvm/src/kotlin/jvm/internal/KotlinSyntheticClass.java +++ b/core/runtime.jvm/src/kotlin/jvm/internal/KotlinSyntheticClass.java @@ -29,8 +29,10 @@ public @interface KotlinSyntheticClass { int[] version() default {}; - Kind kind(); + @Deprecated + Kind kind() default Kind.LOCAL_FUNCTION; + @Deprecated enum Kind { PACKAGE_PART, TRAIT_IMPL, diff --git a/idea/idea-analysis/src/org/jetbrains/kotlin/idea/decompiler/DecompiledUtils.kt b/idea/idea-analysis/src/org/jetbrains/kotlin/idea/decompiler/DecompiledUtils.kt index 536d719e59c..091bf3d5230 100644 --- a/idea/idea-analysis/src/org/jetbrains/kotlin/idea/decompiler/DecompiledUtils.kt +++ b/idea/idea-analysis/src/org/jetbrains/kotlin/idea/decompiler/DecompiledUtils.kt @@ -22,7 +22,6 @@ import com.intellij.psi.ClassFileViewProvider import org.jetbrains.kotlin.idea.caches.JarUserDataManager import org.jetbrains.kotlin.idea.decompiler.textBuilder.DirectoryBasedClassFinder import org.jetbrains.kotlin.load.java.JvmAnnotationNames.KotlinClass -import org.jetbrains.kotlin.load.java.JvmAnnotationNames.KotlinSyntheticClass import org.jetbrains.kotlin.load.kotlin.KotlinBinaryClassCache import org.jetbrains.kotlin.load.kotlin.KotlinJvmBinaryClass import org.jetbrains.kotlin.load.kotlin.header.KotlinClassHeader @@ -71,15 +70,10 @@ public fun isKotlinInternalCompiledFile(file: VirtualFile): Boolean { } val header = KotlinBinaryClassCache.getKotlinBinaryClass(file)?.classHeader ?: return false - if (header.syntheticClassKind == KotlinSyntheticClass.Kind.PACKAGE_PART) { - // Old package parts should not be decompiled and shown anywhere - val version = header.version - return version.major < 0 || (version.major == 0 && version.minor < 24) - } - return header.kind == KotlinClassHeader.Kind.SYNTHETIC_CLASS || (header.kind == KotlinClassHeader.Kind.CLASS && header.classKind != null && header.classKind != KotlinClass.Kind.CLASS) || - (header.kind == KotlinClassHeader.Kind.MULTIFILE_CLASS_PART) + header.kind == KotlinClassHeader.Kind.MULTIFILE_CLASS_PART || + header.syntheticClassKind == "PACKAGE_PART" } public fun isKotlinJavaScriptInternalCompiledFile(file: VirtualFile): Boolean = diff --git a/idea/tests/org/jetbrains/kotlin/idea/decompiler/AbstractInternalCompiledClassesTest.kt b/idea/tests/org/jetbrains/kotlin/idea/decompiler/AbstractInternalCompiledClassesTest.kt index f935a825ca8..974a0a30eaa 100644 --- a/idea/tests/org/jetbrains/kotlin/idea/decompiler/AbstractInternalCompiledClassesTest.kt +++ b/idea/tests/org/jetbrains/kotlin/idea/decompiler/AbstractInternalCompiledClassesTest.kt @@ -17,16 +17,10 @@ package org.jetbrains.kotlin.idea.decompiler import com.intellij.openapi.vfs.VirtualFile -import com.intellij.psi.PsiCompiledFile -import com.intellij.psi.PsiJavaFile import com.intellij.psi.PsiManager -import com.intellij.psi.impl.compiled.ClsFileImpl -import org.jetbrains.kotlin.idea.test.JetLightCodeInsightFixtureTestCase import org.jetbrains.kotlin.idea.decompiler.navigation.NavigateToDecompiledLibraryTest -import org.jetbrains.kotlin.load.java.JvmAbi +import org.jetbrains.kotlin.idea.test.JetLightCodeInsightFixtureTestCase import org.jetbrains.kotlin.load.java.JvmAnnotationNames.KotlinClass -import org.jetbrains.kotlin.load.java.JvmAnnotationNames.KotlinSyntheticClass -import org.jetbrains.kotlin.load.java.JvmAnnotationNames.KotlinSyntheticClass.Kind.TRAIT_IMPL import org.jetbrains.kotlin.load.kotlin.KotlinBinaryClassCache import org.jetbrains.kotlin.load.kotlin.header.KotlinClassHeader import org.junit.Assert @@ -37,31 +31,17 @@ public abstract class AbstractInternalCompiledClassesTest : JetLightCodeInsightF header != null && predicate(header) } - private fun isSyntheticClassOfKind(kind: KotlinSyntheticClass.Kind) : VirtualFile.() -> Boolean = - isFileWithHeader { it.syntheticClassKind == kind } + protected fun isSyntheticClass(): VirtualFile.() -> Boolean = + isFileWithHeader { it.kind == KotlinClassHeader.Kind.SYNTHETIC_CLASS } - private fun isClassOfKind(kind: KotlinClass.Kind) : VirtualFile.() -> Boolean = + private fun isClassOfKind(kind: KotlinClass.Kind): VirtualFile.() -> Boolean = isFileWithHeader { it.classKind == kind } - protected fun doTestNoFilesAreBuiltForSyntheticClass(kind: KotlinSyntheticClass.Kind): Unit = - doTestNoClassFilesAreBuiltFor(kind.toString(), isSyntheticClassOfKind(kind)) - - protected fun doTestNoClassFilesAreBuiltFor(fileKind: String, acceptFile: VirtualFile.() -> Boolean) { - val root = NavigateToDecompiledLibraryTest.findTestLibraryRoot(myModule!!)!! - val files = arrayListOf() - root.checkRecursively { - if (acceptFile()) { - files.add(this) - } - } - assert(files.isEmpty()) { "No class files should be built for $fileKind; found ${files.size()} files: $files" } - } - protected fun doTestNoPsiFilesAreBuiltForLocalClass(kind: KotlinClass.Kind): Unit = - doTestNoPsiFilesAreBuiltFor(kind.toString(), isClassOfKind(kind)) + doTestNoPsiFilesAreBuiltFor(kind.name(), isClassOfKind(kind)) - protected fun doTestNoPsiFilesAreBuiltForSyntheticClass(kind: KotlinSyntheticClass.Kind): Unit = - doTestNoPsiFilesAreBuiltFor(kind.toString(), isSyntheticClassOfKind(kind)) + protected fun doTestNoPsiFilesAreBuiltForSyntheticClasses(): Unit = + doTestNoPsiFilesAreBuiltFor("synthetic", isSyntheticClass()) protected fun doTestNoPsiFilesAreBuiltFor(fileKind: String, acceptFile: VirtualFile.() -> Boolean) { val project = getProject() @@ -69,7 +49,6 @@ public abstract class AbstractInternalCompiledClassesTest : JetLightCodeInsightF val psiFile = PsiManager.getInstance(project).findFile(this) Assert.assertNull("PSI files for $fileKind classes should not be build, is was build for: ${this.getPresentableName()}", psiFile) - } } diff --git a/idea/tests/org/jetbrains/kotlin/idea/decompiler/InternalCompiledClassesTest.kt b/idea/tests/org/jetbrains/kotlin/idea/decompiler/InternalCompiledClassesTest.kt index a64814445b1..37b930949c5 100644 --- a/idea/tests/org/jetbrains/kotlin/idea/decompiler/InternalCompiledClassesTest.kt +++ b/idea/tests/org/jetbrains/kotlin/idea/decompiler/InternalCompiledClassesTest.kt @@ -22,22 +22,11 @@ import org.jetbrains.kotlin.idea.test.JdkAndMockLibraryProjectDescriptor import org.jetbrains.kotlin.idea.test.PluginTestCaseBase import org.jetbrains.kotlin.load.java.JvmAnnotationNames.KotlinClass.Kind.ANONYMOUS_OBJECT import org.jetbrains.kotlin.load.java.JvmAnnotationNames.KotlinClass.Kind.LOCAL_CLASS -import org.jetbrains.kotlin.load.java.JvmAnnotationNames.KotlinSyntheticClass.Kind.* public class InternalCompiledClassesTest : AbstractInternalCompiledClassesTest() { private val TEST_DATA_PATH = PluginTestCaseBase.getTestDataPathBase() + "/decompiler/internalClasses" - fun testNoPackagePartClassesAreBuilt() = doTestNoFilesAreBuiltForSyntheticClass(PACKAGE_PART) - - fun testSamWrapperIsInvisible() = doTestNoPsiFilesAreBuiltForSyntheticClass(SAM_WRAPPER) - - fun testSamLambdaIsInvisible() = doTestNoPsiFilesAreBuiltForSyntheticClass(SAM_LAMBDA) - - fun testCallableReferenceWrapperIsInvisible() = doTestNoPsiFilesAreBuiltForSyntheticClass(CALLABLE_REFERENCE_WRAPPER) - - fun testLocalFunctionIsInvisible() = doTestNoPsiFilesAreBuiltForSyntheticClass(LOCAL_FUNCTION) - - fun testAnonymousFunctionIsInvisible() = doTestNoPsiFilesAreBuiltForSyntheticClass(ANONYMOUS_FUNCTION) + fun testSyntheticClassesAreInvisible() = doTestNoPsiFilesAreBuiltForSyntheticClasses() fun testLocalClassIsInvisible() = doTestNoPsiFilesAreBuiltForLocalClass(LOCAL_CLASS) diff --git a/idea/tests/org/jetbrains/kotlin/idea/decompiler/textBuilder/DecompiledTextForWrongAbiVersionTest.kt b/idea/tests/org/jetbrains/kotlin/idea/decompiler/textBuilder/DecompiledTextForWrongAbiVersionTest.kt index 6ac8a89a780..6474edac6f6 100644 --- a/idea/tests/org/jetbrains/kotlin/idea/decompiler/textBuilder/DecompiledTextForWrongAbiVersionTest.kt +++ b/idea/tests/org/jetbrains/kotlin/idea/decompiler/textBuilder/DecompiledTextForWrongAbiVersionTest.kt @@ -16,19 +16,17 @@ package org.jetbrains.kotlin.idea.decompiler.textBuilder -import com.intellij.testFramework.LightProjectDescriptor -import com.intellij.psi.PsiManager -import org.junit.Assert -import org.jetbrains.kotlin.idea.test.JetJdkAndLibraryProjectDescriptor -import java.io.File import com.intellij.openapi.vfs.VirtualFile -import org.jetbrains.kotlin.idea.decompiler.navigation.NavigateToDecompiledLibraryTest -import org.jetbrains.kotlin.load.java.JvmAnnotationNames.KotlinSyntheticClass.Kind.PACKAGE_PART -import org.jetbrains.kotlin.load.java.JvmAnnotationNames.KotlinSyntheticClass.Kind.ANONYMOUS_FUNCTION +import com.intellij.psi.PsiManager +import com.intellij.testFramework.LightProjectDescriptor import org.jetbrains.kotlin.idea.decompiler.AbstractInternalCompiledClassesTest -import org.jetbrains.kotlin.idea.decompiler.stubBuilder.findClassFileByName import org.jetbrains.kotlin.idea.decompiler.JetClsFile +import org.jetbrains.kotlin.idea.decompiler.navigation.NavigateToDecompiledLibraryTest +import org.jetbrains.kotlin.idea.decompiler.stubBuilder.findClassFileByName +import org.jetbrains.kotlin.idea.test.JetJdkAndLibraryProjectDescriptor import org.jetbrains.kotlin.test.JetTestUtils +import org.junit.Assert +import java.io.File public class DecompiledTextForWrongAbiVersionTest : AbstractInternalCompiledClassesTest() { @@ -36,9 +34,7 @@ public class DecompiledTextForWrongAbiVersionTest : AbstractInternalCompiledClas return JetJdkAndLibraryProjectDescriptor(File(JetTestUtils.getTestDataPathBase() + "/cli/jvm/wrongAbiVersionLib/bin")) } - fun testPackagePartIsInvisibleWrongAbiVersion() = doTestNoPsiFilesAreBuiltForSyntheticClass(PACKAGE_PART) - - fun testAnonymousFunctionIsInvisibleWrongAbiVersion() = doTestNoPsiFilesAreBuiltForSyntheticClass(ANONYMOUS_FUNCTION) + fun testSyntheticClassIsInvisibleWrongAbiVersion() = doTestNoPsiFilesAreBuiltForSyntheticClasses() fun testClassWithWrongAbiVersion() = doTest("ClassWithWrongAbiVersion") diff --git a/jps-plugin/src/org/jetbrains/kotlin/jps/incremental/IncrementalCacheImpl.kt b/jps-plugin/src/org/jetbrains/kotlin/jps/incremental/IncrementalCacheImpl.kt index bcebe353b7a..6a1573694f0 100644 --- a/jps-plugin/src/org/jetbrains/kotlin/jps/incremental/IncrementalCacheImpl.kt +++ b/jps-plugin/src/org/jetbrains/kotlin/jps/incremental/IncrementalCacheImpl.kt @@ -37,8 +37,8 @@ import org.jetbrains.kotlin.load.kotlin.ModuleMapping import org.jetbrains.kotlin.load.kotlin.PackageClassUtils import org.jetbrains.kotlin.load.kotlin.header.* import org.jetbrains.kotlin.load.kotlin.incremental.components.IncrementalCache -import org.jetbrains.kotlin.name.Name import org.jetbrains.kotlin.load.kotlin.incremental.components.JvmPackagePartProto +import org.jetbrains.kotlin.name.Name import org.jetbrains.kotlin.resolve.jvm.JvmClassName import org.jetbrains.kotlin.resolve.jvm.JvmClassName.byInternalName import org.jetbrains.kotlin.serialization.jvm.BitEncoding @@ -220,13 +220,6 @@ public class IncrementalCacheImpl( protoMap.process(kotlinClass, isPackage = false) + constantsMap.process(kotlinClass) + inlineFunctionsMap.process(kotlinClass) - header.syntheticClassKind == JvmAnnotationNames.KotlinSyntheticClass.Kind.PACKAGE_PART -> { - assert(sourceFiles.size() == 1) { "Package part from several source files: $sourceFiles" } - packagePartMap.addPackagePart(className) - - constantsMap.process(kotlinClass) + - inlineFunctionsMap.process(kotlinClass) - } else -> ChangesInfo.NO_CHANGES }