Introduce KotlinSyntheticClass.Kind.LOCAL_TRAIT_IMPL
This commit is contained in:
@@ -54,10 +54,8 @@ public class TraitImplBodyCodegen extends ClassBodyCodegen {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void generateKotlinAnnotation() {
|
protected void generateKotlinAnnotation() {
|
||||||
// We write LOCAL_CLASS to local trait-impl, because we don't want PSI classes to be constructed for such files
|
|
||||||
// (currently PSI for synthetic class is built only if this class is a trait-impl, see DecompiledUtils.kt)
|
|
||||||
writeKotlinSyntheticClassAnnotation(v, DescriptorUtils.isTopLevelOrInnerClass(descriptor)
|
writeKotlinSyntheticClassAnnotation(v, DescriptorUtils.isTopLevelOrInnerClass(descriptor)
|
||||||
? KotlinSyntheticClass.Kind.TRAIT_IMPL
|
? KotlinSyntheticClass.Kind.TRAIT_IMPL
|
||||||
: KotlinSyntheticClass.Kind.LOCAL_CLASS);
|
: KotlinSyntheticClass.Kind.LOCAL_TRAIT_IMPL);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+19
-21
@@ -45,92 +45,90 @@ public class KotlinSyntheticClassAnnotationTest extends CodegenTestCase {
|
|||||||
public void testPackagePart() {
|
public void testPackagePart() {
|
||||||
doTest("fun foo() = 42",
|
doTest("fun foo() = 42",
|
||||||
"$",
|
"$",
|
||||||
PACKAGE_PART, false);
|
PACKAGE_PART);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testTraitImpl() {
|
public void testTraitImpl() {
|
||||||
doTest("trait A { fun foo() = 42 }",
|
doTest("trait A { fun foo() = 42 }",
|
||||||
JvmAbi.TRAIT_IMPL_SUFFIX,
|
JvmAbi.TRAIT_IMPL_SUFFIX,
|
||||||
TRAIT_IMPL, true);
|
TRAIT_IMPL);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testSamWrapper() {
|
public void testSamWrapper() {
|
||||||
doTest("val f = {}\nval foo = Thread(f)",
|
doTest("val f = {}\nval foo = Thread(f)",
|
||||||
"$sam",
|
"$sam",
|
||||||
SAM_WRAPPER, false);
|
SAM_WRAPPER);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testSamLambda() {
|
public void testSamLambda() {
|
||||||
doTest("val foo = Thread { }",
|
doTest("val foo = Thread { }",
|
||||||
"$1",
|
"$1",
|
||||||
SAM_LAMBDA, true);
|
SAM_LAMBDA);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testCallableReferenceWrapper() {
|
public void testCallableReferenceWrapper() {
|
||||||
doTest("val f = String::get",
|
doTest("val f = String::get",
|
||||||
"$1",
|
"$1",
|
||||||
CALLABLE_REFERENCE_WRAPPER, true);
|
CALLABLE_REFERENCE_WRAPPER);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testLocalFunction() {
|
public void testLocalFunction() {
|
||||||
doTest("fun foo() { fun bar() {} }",
|
doTest("fun foo() { fun bar() {} }",
|
||||||
"$1",
|
"$1",
|
||||||
LOCAL_FUNCTION, true);
|
LOCAL_FUNCTION);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testAnonymousFunction() {
|
public void testAnonymousFunction() {
|
||||||
doTest("val f = {}",
|
doTest("val f = {}",
|
||||||
"$1",
|
"$1",
|
||||||
ANONYMOUS_FUNCTION, true);
|
ANONYMOUS_FUNCTION);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testLocalClass() {
|
public void testLocalClass() {
|
||||||
doTest("fun foo() { class Local }",
|
doTest("fun foo() { class Local }",
|
||||||
"Local",
|
"Local",
|
||||||
LOCAL_CLASS, true);
|
LOCAL_CLASS);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testLocalTraitImpl() {
|
public void testLocalTraitImpl() {
|
||||||
doTest("fun foo() { trait Local { fun bar() = 42 } }",
|
doTest("fun foo() { trait Local { fun bar() = 42 } }",
|
||||||
"Local$$TImpl",
|
"Local$$TImpl.class",
|
||||||
LOCAL_CLASS, true);
|
LOCAL_TRAIT_IMPL);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testLocalTraitInterface() {
|
public void testLocalTraitInterface() {
|
||||||
doTest("fun foo() { trait Local { fun bar() = 42 } }",
|
doTest("fun foo() { trait Local { fun bar() = 42 } }",
|
||||||
"Local",
|
"Local.class",
|
||||||
LOCAL_CLASS, true);
|
LOCAL_CLASS);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testInnerClassOfLocalClass() {
|
public void testInnerClassOfLocalClass() {
|
||||||
doTest("fun foo() { class Local { inner class Inner } }",
|
doTest("fun foo() { class Local { inner class Inner } }",
|
||||||
"Inner",
|
"Inner",
|
||||||
LOCAL_CLASS, true);
|
LOCAL_CLASS);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testAnonymousObject() {
|
public void testAnonymousObject() {
|
||||||
doTest("val o = object {}",
|
doTest("val o = object {}",
|
||||||
"$1",
|
"$1",
|
||||||
ANONYMOUS_OBJECT, true);
|
ANONYMOUS_OBJECT);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void doTest(
|
private void doTest(
|
||||||
@NotNull String code,
|
@NotNull String code,
|
||||||
@NotNull final String classNamePart,
|
@NotNull final String classFilePart,
|
||||||
@NotNull KotlinSyntheticClass.Kind expectedKind,
|
@NotNull KotlinSyntheticClass.Kind expectedKind
|
||||||
final boolean endWithNotContains
|
|
||||||
) {
|
) {
|
||||||
loadText("package " + PACKAGE_NAME + "\n\n" + code);
|
loadText("package " + PACKAGE_NAME + "\n\n" + code);
|
||||||
List<OutputFile> output = generateClassesInFile().asList();
|
List<OutputFile> output = generateClassesInFile().asList();
|
||||||
Collection<OutputFile> files = Collections2.filter(output, new Predicate<OutputFile>() {
|
Collection<OutputFile> files = Collections2.filter(output, new Predicate<OutputFile>() {
|
||||||
@Override
|
@Override
|
||||||
public boolean apply(OutputFile file) {
|
public boolean apply(OutputFile file) {
|
||||||
String path = file.getRelativePath();
|
return file.getRelativePath().contains(classFilePart);
|
||||||
return endWithNotContains ? path.endsWith(classNamePart + ".class") : path.contains(classNamePart);
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
assertFalse("No files with \"" + classNamePart + "\" in the name are found: " + output, files.isEmpty());
|
assertFalse("No files with \"" + classFilePart + "\" in the name are found: " + output, files.isEmpty());
|
||||||
assertTrue("Exactly one file with \"" + classNamePart + "\" in the name should be found: " + files, files.size() == 1);
|
assertTrue("Exactly one file with \"" + classFilePart + "\" in the name should be found: " + files, files.size() == 1);
|
||||||
|
|
||||||
String path = files.iterator().next().getRelativePath();
|
String path = files.iterator().next().getRelativePath();
|
||||||
String fqName = path.substring(0, path.length() - ".class".length()).replace('/', '.');
|
String fqName = path.substring(0, path.length() - ".class".length()).replace('/', '.');
|
||||||
|
|||||||
@@ -59,6 +59,7 @@ public final class JvmAnnotationNames {
|
|||||||
public enum Kind {
|
public enum Kind {
|
||||||
PACKAGE_PART,
|
PACKAGE_PART,
|
||||||
TRAIT_IMPL,
|
TRAIT_IMPL,
|
||||||
|
LOCAL_TRAIT_IMPL,
|
||||||
SAM_WRAPPER,
|
SAM_WRAPPER,
|
||||||
SAM_LAMBDA,
|
SAM_LAMBDA,
|
||||||
CALLABLE_REFERENCE_WRAPPER,
|
CALLABLE_REFERENCE_WRAPPER,
|
||||||
|
|||||||
@@ -26,10 +26,10 @@ public @interface KotlinSyntheticClass {
|
|||||||
Kind kind();
|
Kind kind();
|
||||||
|
|
||||||
// Inner classes of local classes have kind LOCAL_CLASS
|
// Inner classes of local classes have kind LOCAL_CLASS
|
||||||
// Local trait-impl also has kind LOCAL_CLASS
|
|
||||||
public static enum Kind {
|
public static enum Kind {
|
||||||
PACKAGE_PART,
|
PACKAGE_PART,
|
||||||
TRAIT_IMPL,
|
TRAIT_IMPL,
|
||||||
|
LOCAL_TRAIT_IMPL,
|
||||||
SAM_WRAPPER,
|
SAM_WRAPPER,
|
||||||
SAM_LAMBDA,
|
SAM_LAMBDA,
|
||||||
CALLABLE_REFERENCE_WRAPPER,
|
CALLABLE_REFERENCE_WRAPPER,
|
||||||
|
|||||||
@@ -29,7 +29,9 @@ public fun isKotlinCompiledFile(file: VirtualFile): Boolean {
|
|||||||
}
|
}
|
||||||
|
|
||||||
val header = KotlinBinaryClassCache.getKotlinBinaryClass(file)?.getClassHeader()
|
val header = KotlinBinaryClassCache.getKotlinBinaryClass(file)?.getClassHeader()
|
||||||
return header != null && header.syntheticClassKind != KotlinSyntheticClass.Kind.TRAIT_IMPL
|
return header != null &&
|
||||||
|
header.syntheticClassKind != KotlinSyntheticClass.Kind.TRAIT_IMPL &&
|
||||||
|
header.syntheticClassKind != KotlinSyntheticClass.Kind.LOCAL_TRAIT_IMPL
|
||||||
}
|
}
|
||||||
|
|
||||||
public fun isKotlinWithCompatibleAbiVersion(file: VirtualFile): Boolean {
|
public fun isKotlinWithCompatibleAbiVersion(file: VirtualFile): Boolean {
|
||||||
|
|||||||
@@ -23,6 +23,9 @@ fun f() {
|
|||||||
class MyLocalClass {
|
class MyLocalClass {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
trait MyLocalTrait {
|
||||||
|
}
|
||||||
|
|
||||||
val myAnonymousObject = object {
|
val myAnonymousObject = object {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+3
-3
@@ -37,7 +37,7 @@ public abstract class AbstractInternalCompiledClassesTest : JetLightCodeInsightF
|
|||||||
}
|
}
|
||||||
|
|
||||||
protected fun doTestTraitImplClassIsVisibleAsJavaClass() {
|
protected fun doTestTraitImplClassIsVisibleAsJavaClass() {
|
||||||
val project = getProject()!!
|
val project = getProject()
|
||||||
doTest("trait impl", isSyntheticClassOfKind(TRAIT_IMPL)) {
|
doTest("trait impl", isSyntheticClassOfKind(TRAIT_IMPL)) {
|
||||||
val psiFile = PsiManager.getInstance(project).findFile(this)!!
|
val psiFile = PsiManager.getInstance(project).findFile(this)!!
|
||||||
Assert.assertTrue("Should not be kotlin file",
|
Assert.assertTrue("Should not be kotlin file",
|
||||||
@@ -50,7 +50,7 @@ public abstract class AbstractInternalCompiledClassesTest : JetLightCodeInsightF
|
|||||||
decompiledPsiFile is PsiJavaFile)
|
decompiledPsiFile is PsiJavaFile)
|
||||||
val classes = (decompiledPsiFile as PsiJavaFile).getClasses()
|
val classes = (decompiledPsiFile as PsiJavaFile).getClasses()
|
||||||
Assert.assertTrue("Should have some decompiled text",
|
Assert.assertTrue("Should have some decompiled text",
|
||||||
classes.size == 1 && classes[0].getName()!!.endsWith(JvmAbi.TRAIT_IMPL_SUFFIX))
|
classes.size() == 1 && classes[0].getName()!!.endsWith(JvmAbi.TRAIT_IMPL_SUFFIX))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -58,7 +58,7 @@ public abstract class AbstractInternalCompiledClassesTest : JetLightCodeInsightF
|
|||||||
doTestNoPsiFilesAreBuiltFor(kind.toString(), isSyntheticClassOfKind(kind))
|
doTestNoPsiFilesAreBuiltFor(kind.toString(), isSyntheticClassOfKind(kind))
|
||||||
|
|
||||||
protected fun doTestNoPsiFilesAreBuiltFor(fileKind: String, acceptFile: VirtualFile.() -> Boolean) {
|
protected fun doTestNoPsiFilesAreBuiltFor(fileKind: String, acceptFile: VirtualFile.() -> Boolean) {
|
||||||
val project = getProject()!!
|
val project = getProject()
|
||||||
doTest(fileKind, acceptFile) {
|
doTest(fileKind, acceptFile) {
|
||||||
val psiFile = PsiManager.getInstance(project).findFile(this)
|
val psiFile = PsiManager.getInstance(project).findFile(this)
|
||||||
Assert.assertNull("PSI files for $fileKind classes should not be build, is was build for: ${this.getPresentableName()}",
|
Assert.assertNull("PSI files for $fileKind classes should not be build, is was build for: ${this.getPresentableName()}",
|
||||||
|
|||||||
Reference in New Issue
Block a user