Deprecate visibility of static members inherited from Java
Now they are not visible by short name through companion objects, just like classifiers in KT-21515 ^KT-25333 In progress
This commit is contained in:
committed by
Dmitry Savvinov
parent
63202fe560
commit
76c651421b
@@ -122,9 +122,11 @@ class KotlinImportOptimizer : ImportOptimizer {
|
||||
return when (target) {
|
||||
is FunctionDescriptor ->
|
||||
scope.findFunction(target.name, NoLookupLocation.FROM_IDE) { it == target } != null
|
||||
&& bindingContext[BindingContext.DEPRECATED_SHORT_NAME_ACCESS, place] != true
|
||||
|
||||
is PropertyDescriptor ->
|
||||
scope.findVariable(target.name, NoLookupLocation.FROM_IDE) { it == target } != null
|
||||
&& bindingContext[BindingContext.DEPRECATED_SHORT_NAME_ACCESS, place] != true
|
||||
|
||||
is ClassDescriptor ->
|
||||
scope.findClassifier(target.name, NoLookupLocation.FROM_IDE) == target
|
||||
|
||||
@@ -0,0 +1,4 @@
|
||||
public class Java {
|
||||
public static int field = 42;
|
||||
public static void method() { }
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
import Java.field;
|
||||
import Java.method;
|
||||
|
||||
open class Base {
|
||||
companion object : Java()
|
||||
}
|
||||
|
||||
class Derived : Base() {
|
||||
fun test() {
|
||||
val x = field;
|
||||
val y = method();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
import Java.field;
|
||||
import Java.method;
|
||||
|
||||
open class Base {
|
||||
companion object : Java()
|
||||
}
|
||||
|
||||
class Derived : Base() {
|
||||
fun test() {
|
||||
val x = field;
|
||||
val y = method();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,43 @@
|
||||
// LANGUAGE_VERSION: 1.3
|
||||
// FILE: first.before.kt
|
||||
// "Import" "true"
|
||||
// ERROR: Unresolved reference: foobar
|
||||
import foo.Bar
|
||||
|
||||
open class Base {
|
||||
companion object : Bar() {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
class Derived : Base() {
|
||||
fun test() {
|
||||
val x = foobar<caret>
|
||||
}
|
||||
}
|
||||
|
||||
// FILE: foo/Bar.java
|
||||
package foo;
|
||||
|
||||
public class Bar {
|
||||
public static final String foobar = "foobar";
|
||||
}
|
||||
|
||||
// FILE: first.after.kt
|
||||
// "Import" "true"
|
||||
// ERROR: Unresolved reference: foobar
|
||||
import foo.Bar
|
||||
import foo.Bar.foobar
|
||||
|
||||
open class Base {
|
||||
companion object : Bar() {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
class Derived : Base() {
|
||||
fun test() {
|
||||
val x = foobar<caret>
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,4 @@
|
||||
public class Java {
|
||||
public static int field = 42;
|
||||
public static void method() { }
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
open class Base {
|
||||
companion object : Java()
|
||||
}
|
||||
|
||||
class Derived : Base() {
|
||||
fun test() {
|
||||
val x = <selection>Java.field</selection>;
|
||||
val y = <selection>Java.method()</selection>;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
open class Base {
|
||||
companion object : Java()
|
||||
}
|
||||
|
||||
class Derived : Base() {
|
||||
fun test() {
|
||||
val x = Java.field;
|
||||
val y = Java.method();
|
||||
}
|
||||
}
|
||||
+5
@@ -131,6 +131,11 @@ public class JvmOptimizeImportsTestGenerated extends AbstractJvmOptimizeImportsT
|
||||
runTest("idea/testData/editor/optimizeImports/jvm/SamConstructor.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("staticFromJava.kt")
|
||||
public void testStaticFromJava() throws Exception {
|
||||
runTest("idea/testData/editor/optimizeImports/jvm/staticFromJava.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("StaticMethodFromSuper.kt")
|
||||
public void testStaticMethodFromSuper() throws Exception {
|
||||
runTest("idea/testData/editor/optimizeImports/jvm/StaticMethodFromSuper.kt");
|
||||
|
||||
@@ -127,11 +127,10 @@ abstract class AbstractQuickFixMultiFileTest : KotlinLightCodeInsightFixtureTest
|
||||
multifileText,
|
||||
object : KotlinTestUtils.TestFileFactoryNoModules<TestFile>() {
|
||||
override fun create(fileName: String, text: String, directives: Map<String, String>): TestFile {
|
||||
if (text.startsWith("// FILE")) {
|
||||
// Drop the first line
|
||||
return TestFile(fileName, StringUtil.substringAfter(text, "\n")!!)
|
||||
val linesWithoutDirectives = text.lines().filter {
|
||||
!it.startsWith("// LANGUAGE_VERSION") && !it.startsWith("// FILE")
|
||||
}
|
||||
return TestFile(fileName, text)
|
||||
return TestFile(fileName, linesWithoutDirectives.joinToString(separator = "\n"))
|
||||
}
|
||||
}, "")
|
||||
|
||||
@@ -144,6 +143,7 @@ abstract class AbstractQuickFixMultiFileTest : KotlinLightCodeInsightFixtureTest
|
||||
}
|
||||
|
||||
configureMultiFileTest(subFiles, beforeFile)
|
||||
configureCompilerOptions(multifileText, project, module)
|
||||
|
||||
CommandProcessor.getInstance().executeCommand(project, {
|
||||
try {
|
||||
@@ -167,6 +167,10 @@ abstract class AbstractQuickFixMultiFileTest : KotlinLightCodeInsightFixtureTest
|
||||
TestCase.assertNotNull(".after file should exist", afterFile)
|
||||
if (afterText != afterFile!!.content) {
|
||||
val actualTestFile = StringBuilder()
|
||||
if (multifileText.startsWith("// LANGUAGE_VERSION")) {
|
||||
actualTestFile.append(multifileText.lineSequence().first())
|
||||
}
|
||||
|
||||
actualTestFile.append("// FILE: ").append(beforeFile.path).append("\n").append(beforeFile.content)
|
||||
for (file in subFiles) {
|
||||
actualTestFile.append("// FILE: ").append(file.path).append("\n").append(file.content)
|
||||
|
||||
+5
@@ -892,6 +892,11 @@ public class QuickFixMultiFileTestGenerated extends AbstractQuickFixMultiFileTes
|
||||
public void testAllFilesPresentInKt21515() throws Exception {
|
||||
KotlinTestUtils.assertAllTestsPresentByMetadata(this.getClass(), new File("idea/testData/quickfix/autoImports/kt21515"), Pattern.compile("^(\\w+)\\.((before\\.Main\\.\\w+)|(test))$"), TargetBackend.ANY, true);
|
||||
}
|
||||
|
||||
@TestMetadata("staticFromJava.test")
|
||||
public void testStaticFromJava() throws Exception {
|
||||
runTest("idea/testData/quickfix/autoImports/kt21515/staticFromJava.test");
|
||||
}
|
||||
}
|
||||
|
||||
@TestMetadata("idea/testData/quickfix/autoImports/mismatchingArgs")
|
||||
|
||||
@@ -335,6 +335,11 @@ public class ShortenRefsTestGenerated extends AbstractShortenRefsTest {
|
||||
runTest("idea/testData/shortenRefs/kt21515/constructor.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("staticFromJava.kt")
|
||||
public void testStaticFromJava() throws Exception {
|
||||
runTest("idea/testData/shortenRefs/kt21515/staticFromJava.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("typeReference.kt")
|
||||
public void testTypeReference() throws Exception {
|
||||
runTest("idea/testData/shortenRefs/kt21515/typeReference.kt");
|
||||
|
||||
Reference in New Issue
Block a user