diff --git a/compiler/backend/src/org/jetbrains/jet/codegen/FunctionCodegen.java b/compiler/backend/src/org/jetbrains/jet/codegen/FunctionCodegen.java index 35ce4dc400e..8ce8b0b2631 100644 --- a/compiler/backend/src/org/jetbrains/jet/codegen/FunctionCodegen.java +++ b/compiler/backend/src/org/jetbrains/jet/codegen/FunctionCodegen.java @@ -157,8 +157,8 @@ public class FunctionCodegen extends ParentCodegenAwareImpl { for (int i = 0; i < kotlinParameterTypes.size(); i++) { JvmMethodParameterKind kind = kotlinParameterTypes.get(i).getKind(); - if (kind == JvmMethodParameterKind.ENUM_NAME || kind == JvmMethodParameterKind.ENUM_ORDINAL) { - markEnumConstructorParameterAsSynthetic(mv, i); + if (kind.isSkippedInGenericSignature()) { + markEnumOrInnerConstructorParameterAsSynthetic(mv, i); continue; } @@ -181,8 +181,8 @@ public class FunctionCodegen extends ParentCodegenAwareImpl { for (int i = 0; i < kotlinParameterTypes.size(); i++) { JvmMethodParameterKind kind = kotlinParameterTypes.get(i).getKind(); - if (kind == JvmMethodParameterKind.ENUM_NAME || kind == JvmMethodParameterKind.ENUM_ORDINAL) { - markEnumConstructorParameterAsSynthetic(mv, i); + if (kind.isSkippedInGenericSignature()) { + markEnumOrInnerConstructorParameterAsSynthetic(mv, i); continue; } @@ -223,7 +223,7 @@ public class FunctionCodegen extends ParentCodegenAwareImpl { } } - private void markEnumConstructorParameterAsSynthetic(MethodVisitor mv, int i) { + private void markEnumOrInnerConstructorParameterAsSynthetic(MethodVisitor mv, int i) { // IDEA's ClsPsi builder fails to annotate synthetic parameters if (state.getClassBuilderMode() == ClassBuilderMode.LIGHT_CLASSES) return; diff --git a/compiler/backend/src/org/jetbrains/jet/codegen/signature/BothSignatureWriter.java b/compiler/backend/src/org/jetbrains/jet/codegen/signature/BothSignatureWriter.java index 682c1ed868d..9aa0c2bb99d 100644 --- a/compiler/backend/src/org/jetbrains/jet/codegen/signature/BothSignatureWriter.java +++ b/compiler/backend/src/org/jetbrains/jet/codegen/signature/BothSignatureWriter.java @@ -183,8 +183,8 @@ public class BothSignatureWriter { public void writeParameterType(JvmMethodParameterKind parameterKind) { // This magic mimics the behavior of javac that enum constructor have these synthetic parameters in erased signature, but doesn't - // have them in generic signature. IDEA relies on this behavior. - if (parameterKind == JvmMethodParameterKind.ENUM_NAME || parameterKind == JvmMethodParameterKind.ENUM_ORDINAL) { + // have them in generic signature. IDEA, javac and their friends rely on this behavior. + if (parameterKind.isSkippedInGenericSignature()) { generic = true; // pushing dummy visitor, because we don't want these parameters to appear in generic JVM signature diff --git a/compiler/backend/src/org/jetbrains/jet/codegen/signature/JvmMethodParameterKind.java b/compiler/backend/src/org/jetbrains/jet/codegen/signature/JvmMethodParameterKind.java index eee61502a7e..3de0211e488 100644 --- a/compiler/backend/src/org/jetbrains/jet/codegen/signature/JvmMethodParameterKind.java +++ b/compiler/backend/src/org/jetbrains/jet/codegen/signature/JvmMethodParameterKind.java @@ -16,6 +16,8 @@ package org.jetbrains.jet.codegen.signature; +import java.util.EnumSet; + public enum JvmMethodParameterKind { VALUE, THIS, @@ -24,5 +26,11 @@ public enum JvmMethodParameterKind { SHARED_VAR, ENUM_NAME, ENUM_ORDINAL, - SUPER_CALL_PARAM + SUPER_CALL_PARAM; + + private static final EnumSet SKIPPED_IN_GENERIC_SIGNATURE = EnumSet.of(OUTER, ENUM_NAME, ENUM_ORDINAL); + + public boolean isSkippedInGenericSignature() { + return SKIPPED_IN_GENERIC_SIGNATURE.contains(this); + } } diff --git a/compiler/testData/compileJavaAgainstKotlin/class/InnerClass.java b/compiler/testData/compileJavaAgainstKotlin/class/InnerClass.java new file mode 100644 index 00000000000..87da5d6df54 --- /dev/null +++ b/compiler/testData/compileJavaAgainstKotlin/class/InnerClass.java @@ -0,0 +1,6 @@ +package test; + +class InnerClass { + Outer.Inner1 field1; + Outer.Inner2 field2; +} \ No newline at end of file diff --git a/compiler/testData/compileJavaAgainstKotlin/class/InnerClass.kt b/compiler/testData/compileJavaAgainstKotlin/class/InnerClass.kt new file mode 100644 index 00000000000..647e36c0a79 --- /dev/null +++ b/compiler/testData/compileJavaAgainstKotlin/class/InnerClass.kt @@ -0,0 +1,6 @@ +package test + +class Outer { + inner class Inner1 + inner class Inner2(param: String) +} \ No newline at end of file diff --git a/compiler/testData/compileJavaAgainstKotlin/class/InnerClassConstructors.java b/compiler/testData/compileJavaAgainstKotlin/class/InnerClassConstructors.java new file mode 100644 index 00000000000..0c7d9bef681 --- /dev/null +++ b/compiler/testData/compileJavaAgainstKotlin/class/InnerClassConstructors.java @@ -0,0 +1,8 @@ +package test; + +class InnerClassConstructors { + public static void main(String[] args) { + new Outer().new InnerGeneric(new java.util.ArrayList()); + new Outer().new InnerPrimitive(1); + } +} \ No newline at end of file diff --git a/compiler/testData/compileJavaAgainstKotlin/class/InnerClassConstructors.kt b/compiler/testData/compileJavaAgainstKotlin/class/InnerClassConstructors.kt new file mode 100644 index 00000000000..5e72b6867a6 --- /dev/null +++ b/compiler/testData/compileJavaAgainstKotlin/class/InnerClassConstructors.kt @@ -0,0 +1,7 @@ +package test + +class Outer { + inner class InnerGeneric(param: List) + + inner class InnerPrimitive(param: Int) +} \ No newline at end of file diff --git a/compiler/testData/compileJavaAgainstKotlin/class/InnerClassOfGeneric.java b/compiler/testData/compileJavaAgainstKotlin/class/InnerClassOfGeneric.java new file mode 100644 index 00000000000..4ede201f066 --- /dev/null +++ b/compiler/testData/compileJavaAgainstKotlin/class/InnerClassOfGeneric.java @@ -0,0 +1,8 @@ +package test; + +class InnerClassOfGeneric { + public static void main(String[] args) { + new Outer().new Inner(new java.util.ArrayList()); + new Outer().new InnerSimple(); + } +} \ No newline at end of file diff --git a/compiler/testData/compileJavaAgainstKotlin/class/InnerClassOfGeneric.kt b/compiler/testData/compileJavaAgainstKotlin/class/InnerClassOfGeneric.kt new file mode 100644 index 00000000000..7f4718e12f8 --- /dev/null +++ b/compiler/testData/compileJavaAgainstKotlin/class/InnerClassOfGeneric.kt @@ -0,0 +1,7 @@ +package test + +class Outer { + inner class Inner(list: List) + + inner class InnerSimple() +} \ No newline at end of file diff --git a/compiler/tests/org/jetbrains/jet/codegen/AnnotationGenTest.java b/compiler/tests/org/jetbrains/jet/codegen/AnnotationGenTest.java index c051b873ffe..039c371a47a 100644 --- a/compiler/tests/org/jetbrains/jet/codegen/AnnotationGenTest.java +++ b/compiler/tests/org/jetbrains/jet/codegen/AnnotationGenTest.java @@ -146,8 +146,8 @@ public class AnnotationGenTest extends CodegenTestCase { Class inner = outer.getDeclaredClasses()[0]; Constructor constructor = inner.getDeclaredConstructor(outer, int.class); assertNotNull(constructor); - // Get annotations for first real parameter - Annotation[] annotations = constructor.getParameterAnnotations()[1]; + // Get annotations for first parameter + Annotation[] annotations = constructor.getParameterAnnotations()[0]; assertNotNull(getDeprecatedAnnotationFromList(annotations)); } diff --git a/compiler/tests/org/jetbrains/jet/jvm/compiler/CompileJavaAgainstKotlinTestGenerated.java b/compiler/tests/org/jetbrains/jet/jvm/compiler/CompileJavaAgainstKotlinTestGenerated.java index 4e14f182141..70bee054eb6 100644 --- a/compiler/tests/org/jetbrains/jet/jvm/compiler/CompileJavaAgainstKotlinTestGenerated.java +++ b/compiler/tests/org/jetbrains/jet/jvm/compiler/CompileJavaAgainstKotlinTestGenerated.java @@ -73,6 +73,21 @@ public class CompileJavaAgainstKotlinTestGenerated extends AbstractCompileJavaAg doTest("compiler/testData/compileJavaAgainstKotlin/class/ImplementsMapPP.kt"); } + @TestMetadata("InnerClass.kt") + public void testInnerClass() throws Exception { + doTest("compiler/testData/compileJavaAgainstKotlin/class/InnerClass.kt"); + } + + @TestMetadata("InnerClassConstructors.kt") + public void testInnerClassConstructors() throws Exception { + doTest("compiler/testData/compileJavaAgainstKotlin/class/InnerClassConstructors.kt"); + } + + @TestMetadata("InnerClassOfGeneric.kt") + public void testInnerClassOfGeneric() throws Exception { + doTest("compiler/testData/compileJavaAgainstKotlin/class/InnerClassOfGeneric.kt"); + } + @TestMetadata("kt3561.kt") public void testKt3561() throws Exception { doTest("compiler/testData/compileJavaAgainstKotlin/class/kt3561.kt");