From 77f74a929aad0d31fdb4cc390fc5a67e3a638cb9 Mon Sep 17 00:00:00 2001 From: "Pavel V. Talanov" Date: Thu, 25 Feb 2016 14:08:33 +0300 Subject: [PATCH] Revert 06215ca93210022c141b3f825c75dccb05fc9a6c It led to parameter names missing in parameter info and completion for compiled java code used from kotlin See KT-11039 --- .../structure/impl/JavaValueParameterImpl.java | 10 ++-------- .../kotlin/generators/tests/GenerateTests.kt | 4 ++-- .../withLib/sharedLib/p/JavaClass.java | 5 +++++ .../parameterInfo/withLib/useJavaFromLib.kt | 10 ++++++++++ .../parameterInfo/AbstractParameterInfoTest.kt | 17 +++++++++++++++-- .../ParameterInfoTestGenerated.java | 17 ++++++++++++++++- 6 files changed, 50 insertions(+), 13 deletions(-) create mode 100644 idea/testData/parameterInfo/withLib/sharedLib/p/JavaClass.java create mode 100644 idea/testData/parameterInfo/withLib/useJavaFromLib.kt diff --git a/compiler/frontend.java/src/org/jetbrains/kotlin/load/java/structure/impl/JavaValueParameterImpl.java b/compiler/frontend.java/src/org/jetbrains/kotlin/load/java/structure/impl/JavaValueParameterImpl.java index ea82ef004e1..ab54fec64bc 100644 --- a/compiler/frontend.java/src/org/jetbrains/kotlin/load/java/structure/impl/JavaValueParameterImpl.java +++ b/compiler/frontend.java/src/org/jetbrains/kotlin/load/java/structure/impl/JavaValueParameterImpl.java @@ -1,5 +1,5 @@ /* - * Copyright 2010-2015 JetBrains s.r.o. + * Copyright 2010-2016 JetBrains s.r.o. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -19,7 +19,6 @@ package org.jetbrains.kotlin.load.java.structure.impl; import com.intellij.psi.PsiAnnotationOwner; import com.intellij.psi.PsiParameter; import com.intellij.psi.impl.compiled.ClsParameterImpl; -import com.intellij.psi.impl.java.stubs.impl.PsiParameterStubImpl; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; import org.jetbrains.kotlin.descriptors.Visibilities; @@ -86,7 +85,7 @@ public class JavaValueParameterImpl extends JavaElementImpl @Nullable public Name getName() { PsiParameter psi = getPsi(); - if (isParameterWithAutoGeneratedName(psi)) { + if (psi instanceof ClsParameterImpl && ((ClsParameterImpl) psi).isAutoGeneratedName()) { return null; } @@ -94,11 +93,6 @@ public class JavaValueParameterImpl extends JavaElementImpl return name == null ? null : Name.identifier(name); } - private static boolean isParameterWithAutoGeneratedName(PsiParameter psi) { - // see com.intellij.psi.impl.compiled.ClsParameterImpl.calcName() - return psi instanceof ClsParameterImpl && ((PsiParameterStubImpl) ((ClsParameterImpl) psi).getStub()).isAutoGeneratedName(); - } - @Override @NotNull public JavaType getType() { diff --git a/generators/src/org/jetbrains/kotlin/generators/tests/GenerateTests.kt b/generators/src/org/jetbrains/kotlin/generators/tests/GenerateTests.kt index 6fbf9a75680..429bb3d4d9f 100644 --- a/generators/src/org/jetbrains/kotlin/generators/tests/GenerateTests.kt +++ b/generators/src/org/jetbrains/kotlin/generators/tests/GenerateTests.kt @@ -1,5 +1,5 @@ /* - * Copyright 2010-2015 JetBrains s.r.o. + * Copyright 2010-2016 JetBrains s.r.o. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -426,7 +426,7 @@ fun main(args: Array) { } testClass() { - model("parameterInfo", recursive = true) + model("parameterInfo", recursive = true, excludeDirs = listOf("withLib/sharedLib")) } testClass() { diff --git a/idea/testData/parameterInfo/withLib/sharedLib/p/JavaClass.java b/idea/testData/parameterInfo/withLib/sharedLib/p/JavaClass.java new file mode 100644 index 00000000000..d8ca0bd742f --- /dev/null +++ b/idea/testData/parameterInfo/withLib/sharedLib/p/JavaClass.java @@ -0,0 +1,5 @@ +package p; + +public class JavaClass { + public void foo(int myParamName1, String myParamName2) {} +} \ No newline at end of file diff --git a/idea/testData/parameterInfo/withLib/useJavaFromLib.kt b/idea/testData/parameterInfo/withLib/useJavaFromLib.kt new file mode 100644 index 00000000000..591b6eb07e9 --- /dev/null +++ b/idea/testData/parameterInfo/withLib/useJavaFromLib.kt @@ -0,0 +1,10 @@ +package test + + +fun main() { + p.JavaClass().foo() +} + +/* +Text: (myParamName1: Int, myParamName2: String!), Disabled: false, Strikeout: false, Green: true +*/ \ No newline at end of file diff --git a/idea/tests/org/jetbrains/kotlin/idea/parameterInfo/AbstractParameterInfoTest.kt b/idea/tests/org/jetbrains/kotlin/idea/parameterInfo/AbstractParameterInfoTest.kt index 0a91b5b23d4..58a49a4c232 100644 --- a/idea/tests/org/jetbrains/kotlin/idea/parameterInfo/AbstractParameterInfoTest.kt +++ b/idea/tests/org/jetbrains/kotlin/idea/parameterInfo/AbstractParameterInfoTest.kt @@ -1,5 +1,5 @@ /* - * Copyright 2010-2015 JetBrains s.r.o. + * Copyright 2010-2016 JetBrains s.r.o. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -21,18 +21,31 @@ import com.intellij.codeInsight.hint.ShowParameterInfoHandler import com.intellij.psi.PsiDocumentManager import com.intellij.psi.PsiElement import com.intellij.psi.PsiWhiteSpace +import com.intellij.testFramework.LightProjectDescriptor import com.intellij.testFramework.fixtures.LightCodeInsightFixtureTestCase import org.jetbrains.kotlin.idea.KotlinLanguage +import org.jetbrains.kotlin.idea.test.JdkAndMockLibraryProjectDescriptor import org.jetbrains.kotlin.idea.test.PluginTestCaseBase import org.jetbrains.kotlin.idea.test.ProjectDescriptorWithStdlibSources import org.jetbrains.kotlin.lexer.KtTokens import org.jetbrains.kotlin.psi.KtFile import org.jetbrains.kotlin.psi.psiUtil.allChildren import org.jetbrains.kotlin.test.InTextDirectivesUtils +import org.jetbrains.kotlin.test.KotlinTestUtils +import org.jetbrains.kotlin.test.TestMetadata import org.junit.Assert abstract class AbstractParameterInfoTest : LightCodeInsightFixtureTestCase() { - override fun getProjectDescriptor() = ProjectDescriptorWithStdlibSources.INSTANCE + override fun getProjectDescriptor(): LightProjectDescriptor { + val root = KotlinTestUtils.getTestsRoot(this.javaClass) + if (root.endsWith("Lib")) { + return JdkAndMockLibraryProjectDescriptor( + "$root/sharedLib", true, true, false, false + ) + + } + return ProjectDescriptorWithStdlibSources.INSTANCE + } override fun setUp() { super.setUp() diff --git a/idea/tests/org/jetbrains/kotlin/idea/parameterInfo/ParameterInfoTestGenerated.java b/idea/tests/org/jetbrains/kotlin/idea/parameterInfo/ParameterInfoTestGenerated.java index 11589264541..22924f453b7 100644 --- a/idea/tests/org/jetbrains/kotlin/idea/parameterInfo/ParameterInfoTestGenerated.java +++ b/idea/tests/org/jetbrains/kotlin/idea/parameterInfo/ParameterInfoTestGenerated.java @@ -32,7 +32,7 @@ import java.util.regex.Pattern; @RunWith(JUnit3RunnerWithInners.class) public class ParameterInfoTestGenerated extends AbstractParameterInfoTest { public void testAllFilesPresentInParameterInfo() throws Exception { - KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("idea/testData/parameterInfo"), Pattern.compile("^(.+)\\.kt$"), true); + KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("idea/testData/parameterInfo"), Pattern.compile("^(.+)\\.kt$"), true, "withLib/sharedLib"); } @TestMetadata("idea/testData/parameterInfo/arrayAccess") @@ -361,4 +361,19 @@ public class ParameterInfoTestGenerated extends AbstractParameterInfoTest { doTest(fileName); } } + + @TestMetadata("idea/testData/parameterInfo/withLib") + @TestDataPath("$PROJECT_ROOT") + @RunWith(JUnit3RunnerWithInners.class) + public static class WithLib extends AbstractParameterInfoTest { + public void testAllFilesPresentInWithLib() throws Exception { + KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("idea/testData/parameterInfo/withLib"), Pattern.compile("^(.+)\\.kt$"), true, "sharedLib"); + } + + @TestMetadata("useJavaFromLib.kt") + public void testUseJavaFromLib() throws Exception { + String fileName = KotlinTestUtils.navigationMetadata("idea/testData/parameterInfo/withLib/useJavaFromLib.kt"); + doTest(fileName); + } + } }