diff --git a/compiler/backend/src/org/jetbrains/kotlin/codegen/DefaultParameterValueSubstitutor.kt b/compiler/backend/src/org/jetbrains/kotlin/codegen/DefaultParameterValueSubstitutor.kt index 12f55b2d305..a139c96dbc2 100644 --- a/compiler/backend/src/org/jetbrains/kotlin/codegen/DefaultParameterValueSubstitutor.kt +++ b/compiler/backend/src/org/jetbrains/kotlin/codegen/DefaultParameterValueSubstitutor.kt @@ -114,7 +114,7 @@ public class DefaultParameterValueSubstitutor(val state: GenerationState) { val flags = AsmUtil.getVisibilityAccessFlag(functionDescriptor) or (if (isStatic) Opcodes.ACC_STATIC else 0) val remainingParameters = getRemainingParameters(functionDescriptor.getOriginal(), substituteCount) val signature = typeMapper.mapSignature(functionDescriptor, context.getContextKind(), remainingParameters) - val mv = classBuilder.newMethod(OtherOrigin(functionDescriptor), flags, + val mv = classBuilder.newMethod(OtherOrigin(methodElement, functionDescriptor), flags, signature.getAsmMethod().getName(), signature.getAsmMethod().getDescriptor(), signature.getGenericsSignature(), diff --git a/compiler/light-classes/src/org/jetbrains/kotlin/asJava/KotlinLightMethodForDeclaration.kt b/compiler/light-classes/src/org/jetbrains/kotlin/asJava/KotlinLightMethodForDeclaration.kt index 499ce559f4a..6a1381f2958 100644 --- a/compiler/light-classes/src/org/jetbrains/kotlin/asJava/KotlinLightMethodForDeclaration.kt +++ b/compiler/light-classes/src/org/jetbrains/kotlin/asJava/KotlinLightMethodForDeclaration.kt @@ -94,14 +94,6 @@ open public class KotlinLightMethodForDeclaration( } } - override fun isEquivalentTo(another: PsiElement?): Boolean { - if (another is KotlinLightMethod && origin == another.getOrigin()) { - return true - } - - return super.isEquivalentTo(another) - } - override fun getParameterList(): PsiParameterList = paramsList.getValue()!! override fun getTypeParameterList(): PsiTypeParameterList? = typeParamsList.getValue() @@ -127,13 +119,22 @@ open public class KotlinLightMethodForDeclaration( return getTypeParameters().all { processor.execute(it, state) } } + override fun isEquivalentTo(another: PsiElement?): Boolean { + if (another is KotlinLightMethod && origin == another.getOrigin() && delegate == another.getDelegate()) { + return true + } + + return super.isEquivalentTo(another) + } + override fun equals(other: Any?): Boolean = other is KotlinLightMethodForDeclaration && getName() == other.getName() && origin == other.origin && - getContainingClass() == other.getContainingClass() + getContainingClass() == other.getContainingClass() && + delegate == other.getDelegate() - override fun hashCode(): Int = (getName().hashCode() * 31 + origin.hashCode()) * 31 + getContainingClass()!!.hashCode() + override fun hashCode(): Int = ((getName().hashCode() * 31 + origin.hashCode()) * 31 + getContainingClass()!!.hashCode()) * 31 + delegate.hashCode() override fun toString(): String = "KotlinLightMethodForDeclaration:" + getName() } diff --git a/compiler/testData/diagnostics/testsWithStdLib/duplicateJvmSignature/jvmOverloads.kt b/compiler/testData/diagnostics/testsWithStdLib/duplicateJvmSignature/jvmOverloads.kt index 973fb3486aa..a55f377bb47 100644 --- a/compiler/testData/diagnostics/testsWithStdLib/duplicateJvmSignature/jvmOverloads.kt +++ b/compiler/testData/diagnostics/testsWithStdLib/duplicateJvmSignature/jvmOverloads.kt @@ -1,6 +1,6 @@ // !DIAGNOSTICS: -UNUSED_PARAMETER -class A { - [kotlin.jvm.overloads] fun foo(s: String = "") { +class A { + [kotlin.jvm.overloads] fun foo(s: String = "") { } fun foo() { diff --git a/idea/testData/kotlinAndJavaChecker/JvmOverloadsFunctions.java b/idea/testData/kotlinAndJavaChecker/JvmOverloadsFunctions.java new file mode 100644 index 00000000000..eb064fc4584 --- /dev/null +++ b/idea/testData/kotlinAndJavaChecker/JvmOverloadsFunctions.java @@ -0,0 +1,13 @@ +import test.kotlin.A; + +import static test.kotlin.KotlinPackage.foo; + +class JvmOverloadsFunctions { + public static void main(String[] args) { + A a = new A() { }; + + foo(a.getClass(), a, true, "Some"); + foo(a.getClass(), a, true); + foo(a.getClass(), a); + } +} diff --git a/idea/testData/kotlinAndJavaChecker/JvmOverloadsFunctions.kt b/idea/testData/kotlinAndJavaChecker/JvmOverloadsFunctions.kt new file mode 100644 index 00000000000..0c2ad9d36c5 --- /dev/null +++ b/idea/testData/kotlinAndJavaChecker/JvmOverloadsFunctions.kt @@ -0,0 +1,9 @@ +package test.kotlin + +trait A + +kotlin.jvm.overloads +public fun foo(k: Class, a: A, b: Boolean = false, s: String="hello"): List { + println("$b $s") + return listOf() +} diff --git a/idea/testData/kotlinAndJavaChecker/JvmOverloadsFunctions.txt b/idea/testData/kotlinAndJavaChecker/JvmOverloadsFunctions.txt new file mode 100644 index 00000000000..fc3b677841d --- /dev/null +++ b/idea/testData/kotlinAndJavaChecker/JvmOverloadsFunctions.txt @@ -0,0 +1 @@ +// WITH_RUNTIME \ No newline at end of file diff --git a/idea/testData/resolve/referenceInJava/AutoGeneratedOverloads.java b/idea/testData/resolve/referenceInJava/AutoGeneratedOverloads.java new file mode 100644 index 00000000000..ce1610b8c0a --- /dev/null +++ b/idea/testData/resolve/referenceInJava/AutoGeneratedOverloads.java @@ -0,0 +1,7 @@ +public class AutoGeneratedOverloads { + public static void foo() { + k.KPackage.withJvmOverloads(0); + } +} + +// REF: (in k).withJvmOverloads(Int,Boolean,String) diff --git a/idea/testData/resolve/referenceInJava/dependencies.kt b/idea/testData/resolve/referenceInJava/dependencies.kt index 1830e1f1349..035fb64b0fc 100644 --- a/idea/testData/resolve/referenceInJava/dependencies.kt +++ b/idea/testData/resolve/referenceInJava/dependencies.kt @@ -47,4 +47,9 @@ trait TraitWithImpl { fun foo() = 1 } -public class TraitWithDelegatedWithImpl(f: TraitWithImpl): TraitWithImpl by f +public class TraitWithDelegatedWithImpl(f: TraitWithImpl) : TraitWithImpl by f + +kotlin.jvm.overloads +public fun withJvmOverloads(i: Int, b: Boolean = false, s: String="hello") {} + + diff --git a/idea/tests/org/jetbrains/kotlin/checkers/KotlinAndJavaCheckerTest.java b/idea/tests/org/jetbrains/kotlin/checkers/KotlinAndJavaCheckerTest.java index 7b8d0d097f0..f1325156a3f 100644 --- a/idea/tests/org/jetbrains/kotlin/checkers/KotlinAndJavaCheckerTest.java +++ b/idea/tests/org/jetbrains/kotlin/checkers/KotlinAndJavaCheckerTest.java @@ -19,6 +19,7 @@ package org.jetbrains.kotlin.checkers; import com.intellij.codeInspection.LocalInspectionTool; import com.intellij.codeInspection.dataFlow.DataFlowInspection; import com.intellij.codeInspection.nullable.NullableStuffInspection; +import com.intellij.openapi.module.Module; import com.intellij.openapi.projectRoots.Sdk; import com.intellij.openapi.util.io.FileUtil; import com.intellij.util.ArrayUtil; @@ -26,7 +27,9 @@ import com.siyeh.ig.bugs.StaticCallOnSubclassInspection; import com.siyeh.ig.bugs.StaticFieldReferenceOnSubclassInspection; import kotlin.Function1; import kotlin.KotlinPackage; +import org.jetbrains.annotations.Nullable; import org.jetbrains.kotlin.idea.KotlinDaemonAnalyzerTestCase; +import org.jetbrains.kotlin.idea.test.ConfigLibraryUtil; import org.jetbrains.kotlin.idea.test.PluginTestCaseBase; import org.jetbrains.kotlin.test.InTextDirectivesUtils; import org.jetbrains.kotlin.utils.UtilsPackage; @@ -55,30 +58,56 @@ public class KotlinAndJavaCheckerTest extends KotlinDaemonAnalyzerTestCase { throw new IllegalArgumentException("Can't find inspection tool with identifier: " + toolString); } - @Override - protected LocalInspectionTool[] configureLocalInspectionTools() { + @Nullable + protected String getConfigFileText() { File configureFile = new File(getTestDataPath(), getTestName(false) + ".txt"); - - if (!configureFile.exists()) return DEFAULT_TOOLS; + if (!configureFile.exists()) return null; try { - String configureText = FileUtil.loadFile(configureFile, true); - - InTextDirectivesUtils.assertHasUnknownPrefixes(configureText, KotlinPackage.listOf("TOOL:")); - List toolsStrings = InTextDirectivesUtils.findListWithPrefixes(configureText, "TOOL:"); - - return ArrayUtil.toObjectArray(KotlinPackage.map(toolsStrings, new Function1() { - @Override - public LocalInspectionTool invoke(String toolString) { - return mapStringToTool(toolString); - } - }), LocalInspectionTool.class); + return FileUtil.loadFile(configureFile, true); } catch (IOException e) { throw UtilsPackage.rethrow(e); } } + @Override + protected LocalInspectionTool[] configureLocalInspectionTools() { + String configFileText = getConfigFileText(); + if (configFileText == null) return DEFAULT_TOOLS; + + List toolsStrings = InTextDirectivesUtils.findListWithPrefixes(configFileText, "TOOL:"); + + return ArrayUtil.toObjectArray(KotlinPackage.map(toolsStrings, new Function1() { + @Override + public LocalInspectionTool invoke(String toolString) { + return mapStringToTool(toolString); + } + }), LocalInspectionTool.class); + } + + @Override + protected Module createMainModule() throws IOException { + Module module = super.createMainModule(); + + String configFileText = getConfigFileText(); + if (configFileText != null && InTextDirectivesUtils.isDirectiveDefined(configFileText, "// WITH_RUNTIME")) { + ConfigLibraryUtil.configureKotlinRuntime(module); + } + + return module; + } + + @Override + protected void setUp() throws Exception { + super.setUp(); + } + + @Override + protected void tearDown() throws Exception { + super.tearDown(); + } + @Override protected Sdk getTestProjectJdk() { return PluginTestCaseBase.mockJdk(); @@ -121,6 +150,10 @@ public class KotlinAndJavaCheckerTest extends KotlinDaemonAnalyzerTestCase { doTest(); } + public void testJvmOverloadsFunctions() throws Exception { + doTest(); + } + public void testEnumAutoGeneratedMethods() throws Exception { doTest(); } diff --git a/idea/tests/org/jetbrains/kotlin/idea/resolve/ReferenceResolveInJavaTestGenerated.java b/idea/tests/org/jetbrains/kotlin/idea/resolve/ReferenceResolveInJavaTestGenerated.java index 0f8c51eafd0..2f28ae5f55d 100644 --- a/idea/tests/org/jetbrains/kotlin/idea/resolve/ReferenceResolveInJavaTestGenerated.java +++ b/idea/tests/org/jetbrains/kotlin/idea/resolve/ReferenceResolveInJavaTestGenerated.java @@ -35,6 +35,12 @@ public class ReferenceResolveInJavaTestGenerated extends AbstractReferenceResolv JetTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("idea/testData/resolve/referenceInJava"), Pattern.compile("^(.+)\\.java$"), true); } + @TestMetadata("AutoGeneratedOverloads.java") + public void testAutoGeneratedOverloads() throws Exception { + String fileName = JetTestUtils.navigationMetadata("idea/testData/resolve/referenceInJava/AutoGeneratedOverloads.java"); + doTest(fileName); + } + @TestMetadata("Class.java") public void testClass() throws Exception { String fileName = JetTestUtils.navigationMetadata("idea/testData/resolve/referenceInJava/Class.java");