diff --git a/compiler/frontend.java/src/org/jetbrains/jet/lang/resolve/java/resolver/JavaConstructorResolver.java b/compiler/frontend.java/src/org/jetbrains/jet/lang/resolve/java/resolver/JavaConstructorResolver.java index 98741950adb..cf1bc025f06 100644 --- a/compiler/frontend.java/src/org/jetbrains/jet/lang/resolve/java/resolver/JavaConstructorResolver.java +++ b/compiler/frontend.java/src/org/jetbrains/jet/lang/resolve/java/resolver/JavaConstructorResolver.java @@ -27,6 +27,7 @@ import org.jetbrains.jet.lang.resolve.BindingTrace; import org.jetbrains.jet.lang.resolve.DescriptorResolver; import org.jetbrains.jet.lang.resolve.java.*; import org.jetbrains.jet.lang.resolve.java.kotlinSignature.AlternativeMethodSignatureData; +import org.jetbrains.jet.lang.resolve.java.kt.JetConstructorAnnotation; import org.jetbrains.jet.lang.resolve.java.provider.ClassPsiDeclarationProvider; import org.jetbrains.jet.lang.resolve.java.wrapper.PsiMethodWrapper; import org.jetbrains.jet.lang.resolve.name.Name; @@ -167,8 +168,14 @@ public final class JavaConstructorResolver { ) { PsiMethodWrapper constructor = new PsiMethodWrapper(psiConstructor); + JetConstructorAnnotation constructorAnnotation = constructor.getJetConstructorAnnotation(); //noinspection deprecation - if (constructor.getJetConstructorAnnotation().hidden()) { + if (constructorAnnotation.hidden()) { + return null; + } + + // Do not resolve kotlin constructors without JetConstructorAnnotation + if (DescriptorResolverUtils.isKotlinClass(psiClass) && !constructorAnnotation.isDefined()) { return null; } @@ -205,7 +212,7 @@ public final class JavaConstructorResolver { constructorDescriptor.initialize(classDescriptor.getTypeConstructor().getParameters(), valueParameterDescriptors.getDescriptors(), - DescriptorResolverUtils.resolveVisibility(psiConstructor, constructor.getJetConstructorAnnotation()), + DescriptorResolverUtils.resolveVisibility(psiConstructor, constructorAnnotation), aStatic); trace.record(BindingContext.CONSTRUCTOR, psiConstructor, constructorDescriptor); return constructorDescriptor; diff --git a/compiler/testData/loadKotlin/constructor/Constructor2WithOneParamDefaultValue.kt b/compiler/testData/loadKotlin/constructor/Constructor2WithOneParamDefaultValue.kt new file mode 100644 index 00000000000..06ae0c79395 --- /dev/null +++ b/compiler/testData/loadKotlin/constructor/Constructor2WithOneParamDefaultValue.kt @@ -0,0 +1,3 @@ +package test + +class TestConstructor(p: Int = 1, s: Int) diff --git a/compiler/testData/loadKotlin/constructor/Constructor2WithOneParamDefaultValue.txt b/compiler/testData/loadKotlin/constructor/Constructor2WithOneParamDefaultValue.txt new file mode 100644 index 00000000000..57f26eb8a70 --- /dev/null +++ b/compiler/testData/loadKotlin/constructor/Constructor2WithOneParamDefaultValue.txt @@ -0,0 +1,5 @@ +namespace test + +internal final class test.TestConstructor : jet.Any { + public final /*primary constructor*/ fun (/*0*/ p: jet.Int = ?, /*1*/ s: jet.Int): test.TestConstructor +} diff --git a/compiler/testData/loadKotlin/constructor/ConstructorWithTwoDefArgs.kt b/compiler/testData/loadKotlin/constructor/ConstructorWithTwoDefArgs.kt new file mode 100644 index 00000000000..11a050c2b65 --- /dev/null +++ b/compiler/testData/loadKotlin/constructor/ConstructorWithTwoDefArgs.kt @@ -0,0 +1,3 @@ +package test + +class TestConstructor(p: Int = 1, d: Int = 1) \ No newline at end of file diff --git a/compiler/testData/loadKotlin/constructor/ConstructorWithTwoDefArgs.txt b/compiler/testData/loadKotlin/constructor/ConstructorWithTwoDefArgs.txt new file mode 100644 index 00000000000..7c2ae3799ba --- /dev/null +++ b/compiler/testData/loadKotlin/constructor/ConstructorWithTwoDefArgs.txt @@ -0,0 +1,5 @@ +namespace test + +internal final class test.TestConstructor : jet.Any { + public final /*primary constructor*/ fun (/*0*/ p: jet.Int = ?, /*1*/ d: jet.Int = ?): test.TestConstructor +} diff --git a/compiler/testData/loadKotlin/constructor/InnerClassConstructorWithDefArgs.kt b/compiler/testData/loadKotlin/constructor/InnerClassConstructorWithDefArgs.kt new file mode 100644 index 00000000000..c06245ceaa0 --- /dev/null +++ b/compiler/testData/loadKotlin/constructor/InnerClassConstructorWithDefArgs.kt @@ -0,0 +1,5 @@ +package test + +class A { + class TestConstructor(p: Int = 1) +} diff --git a/compiler/testData/loadKotlin/constructor/InnerClassConstructorWithDefArgs.txt b/compiler/testData/loadKotlin/constructor/InnerClassConstructorWithDefArgs.txt new file mode 100644 index 00000000000..f4efe81b0dd --- /dev/null +++ b/compiler/testData/loadKotlin/constructor/InnerClassConstructorWithDefArgs.txt @@ -0,0 +1,8 @@ +namespace test + +internal final class test.A : jet.Any { + public final /*primary constructor*/ fun (): test.A + internal final class test.A.TestConstructor : jet.Any { + public final /*primary constructor*/ fun (/*0*/ p: jet.Int = ?): test.A.TestConstructor + } +} diff --git a/compiler/testData/loadKotlin/constructor/PrivateConstructor1WithParamDefaultValue.kt b/compiler/testData/loadKotlin/constructor/PrivateConstructor1WithParamDefaultValue.kt new file mode 100644 index 00000000000..a37d4e7ad8b --- /dev/null +++ b/compiler/testData/loadKotlin/constructor/PrivateConstructor1WithParamDefaultValue.kt @@ -0,0 +1,3 @@ +package test + +class TestConstructor private(p: Int = 1) diff --git a/compiler/testData/loadKotlin/constructor/PrivateConstructor1WithParamDefaultValue.txt b/compiler/testData/loadKotlin/constructor/PrivateConstructor1WithParamDefaultValue.txt new file mode 100644 index 00000000000..75da0da795e --- /dev/null +++ b/compiler/testData/loadKotlin/constructor/PrivateConstructor1WithParamDefaultValue.txt @@ -0,0 +1,5 @@ +namespace test + +internal final class test.TestConstructor : jet.Any { + private final /*primary constructor*/ fun (/*0*/ p: jet.Int = ?): test.TestConstructor +} diff --git a/compiler/tests/org/jetbrains/jet/jvm/compiler/LoadCompiledKotlinTestGenerated.java b/compiler/tests/org/jetbrains/jet/jvm/compiler/LoadCompiledKotlinTestGenerated.java index 24dee60bc97..09971468640 100644 --- a/compiler/tests/org/jetbrains/jet/jvm/compiler/LoadCompiledKotlinTestGenerated.java +++ b/compiler/tests/org/jetbrains/jet/jvm/compiler/LoadCompiledKotlinTestGenerated.java @@ -264,11 +264,21 @@ public class LoadCompiledKotlinTestGenerated extends AbstractLoadCompiledKotlinT doTest("compiler/testData/loadKotlin/constructor/Constructor1WithParamDefaultValue.kt"); } + @TestMetadata("Constructor2WithOneParamDefaultValue.kt") + public void testConstructor2WithOneParamDefaultValue() throws Exception { + doTest("compiler/testData/loadKotlin/constructor/Constructor2WithOneParamDefaultValue.kt"); + } + @TestMetadata("ConstructorCollectionParameter.kt") public void testConstructorCollectionParameter() throws Exception { doTest("compiler/testData/loadKotlin/constructor/ConstructorCollectionParameter.kt"); } + @TestMetadata("ConstructorWithTwoDefArgs.kt") + public void testConstructorWithTwoDefArgs() throws Exception { + doTest("compiler/testData/loadKotlin/constructor/ConstructorWithTwoDefArgs.kt"); + } + @TestMetadata("ConstructorWithTwoTypeParameters.kt") public void testConstructorWithTwoTypeParameters() throws Exception { doTest("compiler/testData/loadKotlin/constructor/ConstructorWithTwoTypeParameters.kt"); @@ -294,6 +304,16 @@ public class LoadCompiledKotlinTestGenerated extends AbstractLoadCompiledKotlinT doTest("compiler/testData/loadKotlin/constructor/ConstructorWithTypeParametersEAndOnePValueParameter.kt"); } + @TestMetadata("InnerClassConstructorWithDefArgs.kt") + public void testInnerClassConstructorWithDefArgs() throws Exception { + doTest("compiler/testData/loadKotlin/constructor/InnerClassConstructorWithDefArgs.kt"); + } + + @TestMetadata("PrivateConstructor1WithParamDefaultValue.kt") + public void testPrivateConstructor1WithParamDefaultValue() throws Exception { + doTest("compiler/testData/loadKotlin/constructor/PrivateConstructor1WithParamDefaultValue.kt"); + } + } @TestMetadata("compiler/testData/loadKotlin/dataClass") diff --git a/compiler/tests/org/jetbrains/jet/lang/resolve/lazy/LazyResolveNamespaceComparingTestGenerated.java b/compiler/tests/org/jetbrains/jet/lang/resolve/lazy/LazyResolveNamespaceComparingTestGenerated.java index 61bc4bc40a5..031ad5767d7 100644 --- a/compiler/tests/org/jetbrains/jet/lang/resolve/lazy/LazyResolveNamespaceComparingTestGenerated.java +++ b/compiler/tests/org/jetbrains/jet/lang/resolve/lazy/LazyResolveNamespaceComparingTestGenerated.java @@ -266,11 +266,21 @@ public class LazyResolveNamespaceComparingTestGenerated extends AbstractLazyReso doTestCheckingPrimaryConstructors("compiler/testData/loadKotlin/constructor/Constructor1WithParamDefaultValue.kt"); } + @TestMetadata("Constructor2WithOneParamDefaultValue.kt") + public void testConstructor2WithOneParamDefaultValue() throws Exception { + doTestCheckingPrimaryConstructors("compiler/testData/loadKotlin/constructor/Constructor2WithOneParamDefaultValue.kt"); + } + @TestMetadata("ConstructorCollectionParameter.kt") public void testConstructorCollectionParameter() throws Exception { doTestCheckingPrimaryConstructors("compiler/testData/loadKotlin/constructor/ConstructorCollectionParameter.kt"); } + @TestMetadata("ConstructorWithTwoDefArgs.kt") + public void testConstructorWithTwoDefArgs() throws Exception { + doTestCheckingPrimaryConstructors("compiler/testData/loadKotlin/constructor/ConstructorWithTwoDefArgs.kt"); + } + @TestMetadata("ConstructorWithTwoTypeParameters.kt") public void testConstructorWithTwoTypeParameters() throws Exception { doTestCheckingPrimaryConstructors("compiler/testData/loadKotlin/constructor/ConstructorWithTwoTypeParameters.kt"); @@ -296,6 +306,16 @@ public class LazyResolveNamespaceComparingTestGenerated extends AbstractLazyReso doTestCheckingPrimaryConstructors("compiler/testData/loadKotlin/constructor/ConstructorWithTypeParametersEAndOnePValueParameter.kt"); } + @TestMetadata("InnerClassConstructorWithDefArgs.kt") + public void testInnerClassConstructorWithDefArgs() throws Exception { + doTestCheckingPrimaryConstructors("compiler/testData/loadKotlin/constructor/InnerClassConstructorWithDefArgs.kt"); + } + + @TestMetadata("PrivateConstructor1WithParamDefaultValue.kt") + public void testPrivateConstructor1WithParamDefaultValue() throws Exception { + doTestCheckingPrimaryConstructors("compiler/testData/loadKotlin/constructor/PrivateConstructor1WithParamDefaultValue.kt"); + } + } @TestMetadata("compiler/testData/loadKotlin/dataClass")