Fixed KT-4085 Usability problem: Can't import protected nested class

#KT-4085 Fixed
This commit is contained in:
Valentin Kipyatkov
2015-01-20 17:45:50 +03:00
parent 974982463c
commit fa779bbdd2
4 changed files with 50 additions and 2 deletions
@@ -20,6 +20,7 @@ import com.google.common.base.Predicate;
import com.google.common.collect.Collections2;
import com.google.common.collect.Lists;
import com.google.common.collect.Sets;
import com.intellij.psi.util.PsiTreeUtil;
import org.jetbrains.annotations.Mutable;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
@@ -486,9 +487,10 @@ public class QualifiedExpressionResolver {
@NotNull JetScope scopeToCheckVisibility
) {
if (!Visibilities.isVisible(ReceiverValue.IRRELEVANT_RECEIVER, descriptor, scopeToCheckVisibility.getContainingDeclaration())) {
Visibility visibility = descriptor.getVisibility();
if (PsiTreeUtil.getParentOfType(referenceExpression, JetImportDirective.class) != null && !visibility.mustCheckInImports()) return;
//noinspection ConstantConditions
trace.report(INVISIBLE_REFERENCE.on(referenceExpression, descriptor, descriptor.getVisibility(),
descriptor.getContainingDeclaration()));
trace.report(INVISIBLE_REFERENCE.on(referenceExpression, descriptor, visibility, descriptor.getContainingDeclaration()));
}
}
@@ -0,0 +1,13 @@
package p
import p.Foo.Nested
open class Foo {
protected class Nested
}
class Bar: Foo() {
fun foo(): Nested? = null
}
fun foo(): <!INVISIBLE_REFERENCE!>Nested<!>? = null
@@ -0,0 +1,27 @@
package
package p {
internal fun foo(): p.Foo.Nested?
internal final class Bar : p.Foo {
public constructor Bar()
public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
internal final fun foo(): p.Foo.Nested?
public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
}
internal open class Foo {
public constructor Foo()
public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
protected final class Nested {
public constructor Nested()
public open override /*1*/ /*fake_override*/ fun equals(/*0*/ other: kotlin.Any?): kotlin.Boolean
public open override /*1*/ /*fake_override*/ fun hashCode(): kotlin.Int
public open override /*1*/ /*fake_override*/ fun toString(): kotlin.String
}
}
}
@@ -4811,6 +4811,12 @@ public class JetDiagnosticsTestGenerated extends AbstractJetDiagnosticsTest {
doTest(fileName);
}
@TestMetadata("ImportProtectedClass.kt")
public void testImportProtectedClass() throws Exception {
String fileName = JetTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/imports/ImportProtectedClass.kt");
doTest(fileName);
}
@TestMetadata("ImportResolutionOrder.kt")
public void testImportResolutionOrder() throws Exception {
String fileName = JetTestUtils.navigationMetadata("compiler/testData/diagnostics/tests/imports/ImportResolutionOrder.kt");