Deprecate and don't write KotlinSyntheticClass$Kind, to be removed later

This commit is contained in:
Alexander Udalov
2015-10-01 18:13:52 +03:00
parent 5bb47c8365
commit 056bb3f833
23 changed files with 58 additions and 158 deletions
@@ -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();
}
@@ -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<JetElement> {
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<JetElement> {
@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<JetElement> {
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<JetElement> {
@Override
protected void generateKotlinAnnotation() {
writeKotlinSyntheticClassAnnotation(v, syntheticClassKind);
writeKotlinSyntheticClassAnnotation(v);
DescriptorSerializer serializer =
DescriptorSerializer.createTopLevel(new JvmSerializerExtension(v.getSerializationBindings(), typeMapper));
@@ -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<StackValue, StackValue> 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<StackValue, StackValue> 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<StackValue, StackValue> 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<StackValue, StackValue> 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<StackValue, StackValue> 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<StackValue, StackValue> 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);
@@ -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)
}
}
@@ -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 =
@@ -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);
@@ -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();
}
@@ -10,7 +10,7 @@ public interface Generic <N, NN> {
@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 {
}
}
@@ -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 {
}
}
@@ -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 */ }
@@ -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 {
}
}
@@ -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 {
}
}
@@ -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 {
@@ -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<OutputFile> 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<? extends Annotation> annotationClass = loadAnnotationClassQuietly(annotationFqName);
assertTrue("No annotation " + annotationFqName + " found in " + aClass, aClass.isAnnotationPresent(annotationClass));
@@ -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
@@ -27,7 +27,7 @@ public class KotlinClassHeader(
public val annotationData: Array<String>?,
public val strings: Array<String>?,
public val classKind: KotlinClass.Kind?,
public val syntheticClassKind: KotlinSyntheticClass.Kind?,
public val syntheticClassKind: String?,
public val filePartClassNames: Array<String>?,
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
@@ -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();
}
}
}
@@ -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,
@@ -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 =
@@ -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<VirtualFile>()
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)
}
}
@@ -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)
@@ -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")
@@ -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
}