Add origin for generated jvm overloads and tweak equals methods to distinguish them
- KT-7586 Strange navigation issue #KT-7586 Fixed
This commit is contained in:
+1
-1
@@ -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(),
|
||||
|
||||
+11
-10
@@ -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<LightMethod>.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<LightMethod>.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()
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
// !DIAGNOSTICS: -UNUSED_PARAMETER
|
||||
class <!CONFLICTING_JVM_DECLARATIONS!>A<!> {
|
||||
[kotlin.jvm.overloads] fun foo(s: String = "") {
|
||||
class A {
|
||||
<!CONFLICTING_JVM_DECLARATIONS!>[kotlin.jvm.overloads] fun foo(s: String = "")<!> {
|
||||
}
|
||||
|
||||
<!CONFLICTING_JVM_DECLARATIONS!>fun foo()<!> {
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
package test.kotlin
|
||||
|
||||
trait A
|
||||
|
||||
kotlin.jvm.overloads
|
||||
public fun foo<T : A>(k: Class<T>, a: A, b: Boolean = false, s: String="hello"): List<T> {
|
||||
println("$b $s")
|
||||
return listOf()
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
// WITH_RUNTIME
|
||||
@@ -0,0 +1,7 @@
|
||||
public class AutoGeneratedOverloads {
|
||||
public static void foo() {
|
||||
k.KPackage.<caret>withJvmOverloads(0);
|
||||
}
|
||||
}
|
||||
|
||||
// REF: (in k).withJvmOverloads(Int,Boolean,String)
|
||||
@@ -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") {}
|
||||
|
||||
|
||||
|
||||
@@ -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<String> toolsStrings = InTextDirectivesUtils.findListWithPrefixes(configureText, "TOOL:");
|
||||
|
||||
return ArrayUtil.toObjectArray(KotlinPackage.map(toolsStrings, new Function1<String, LocalInspectionTool>() {
|
||||
@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<String> toolsStrings = InTextDirectivesUtils.findListWithPrefixes(configFileText, "TOOL:");
|
||||
|
||||
return ArrayUtil.toObjectArray(KotlinPackage.map(toolsStrings, new Function1<String, LocalInspectionTool>() {
|
||||
@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();
|
||||
}
|
||||
|
||||
@@ -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");
|
||||
|
||||
Reference in New Issue
Block a user