Fix DescriptorUtils.isLocal semantics
Non-member descriptors, e.g. type parameters, value parameters that defined in local function should be local too Otherwise a lot of exceptions happens when resolving references within anonymous objects
This commit is contained in:
@@ -69,8 +69,8 @@ public class DescriptorUtils {
|
|||||||
*/
|
*/
|
||||||
public static boolean isLocal(@NotNull DeclarationDescriptor descriptor) {
|
public static boolean isLocal(@NotNull DeclarationDescriptor descriptor) {
|
||||||
DeclarationDescriptor current = descriptor;
|
DeclarationDescriptor current = descriptor;
|
||||||
while (current instanceof MemberDescriptor) {
|
while (current != null) {
|
||||||
if (isAnonymousObject(current) || ((DeclarationDescriptorWithVisibility) current).getVisibility() == Visibilities.LOCAL) {
|
if (isAnonymousObject(current) || isDescriptorWithLocalVisibility(current)) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
current = current.getContainingDeclaration();
|
current = current.getContainingDeclaration();
|
||||||
@@ -78,6 +78,11 @@ public class DescriptorUtils {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static boolean isDescriptorWithLocalVisibility(DeclarationDescriptor current) {
|
||||||
|
return current instanceof DeclarationDescriptorWithVisibility &&
|
||||||
|
((DeclarationDescriptorWithVisibility) current).getVisibility() == Visibilities.LOCAL;
|
||||||
|
}
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
public static FqNameUnsafe getFqName(@NotNull DeclarationDescriptor descriptor) {
|
public static FqNameUnsafe getFqName(@NotNull DeclarationDescriptor descriptor) {
|
||||||
FqName safe = getFqNameSafeIfPossible(descriptor);
|
FqName safe = getFqNameSafeIfPossible(descriptor);
|
||||||
|
|||||||
@@ -0,0 +1,7 @@
|
|||||||
|
val prop = object {
|
||||||
|
private fun <K> foo(x: <caret>K) {
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// REF: K
|
||||||
@@ -0,0 +1,9 @@
|
|||||||
|
open class B
|
||||||
|
class A
|
||||||
|
val prop = object : B() {
|
||||||
|
private fun foo(x: A): A {
|
||||||
|
return <caret>x
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// REF: x
|
||||||
@@ -347,12 +347,24 @@ public class ReferenceResolveTestGenerated extends AbstractReferenceResolveTest
|
|||||||
doTest(fileName);
|
doTest(fileName);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@TestMetadata("TypeParameterInAnonymousObject.kt")
|
||||||
|
public void testTypeParameterInAnonymousObject() throws Exception {
|
||||||
|
String fileName = JetTestUtils.navigationMetadata("idea/testData/resolve/references/TypeParameterInAnonymousObject.kt");
|
||||||
|
doTest(fileName);
|
||||||
|
}
|
||||||
|
|
||||||
@TestMetadata("TypeParameterInFunctionLiteral.kt")
|
@TestMetadata("TypeParameterInFunctionLiteral.kt")
|
||||||
public void testTypeParameterInFunctionLiteral() throws Exception {
|
public void testTypeParameterInFunctionLiteral() throws Exception {
|
||||||
String fileName = JetTestUtils.navigationMetadata("idea/testData/resolve/references/TypeParameterInFunctionLiteral.kt");
|
String fileName = JetTestUtils.navigationMetadata("idea/testData/resolve/references/TypeParameterInFunctionLiteral.kt");
|
||||||
doTest(fileName);
|
doTest(fileName);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@TestMetadata("ValueParameter.kt")
|
||||||
|
public void testValueParameter() throws Exception {
|
||||||
|
String fileName = JetTestUtils.navigationMetadata("idea/testData/resolve/references/ValueParameter.kt");
|
||||||
|
doTest(fileName);
|
||||||
|
}
|
||||||
|
|
||||||
@TestMetadata("WrongNumberOfTypeArguments.kt")
|
@TestMetadata("WrongNumberOfTypeArguments.kt")
|
||||||
public void testWrongNumberOfTypeArguments() throws Exception {
|
public void testWrongNumberOfTypeArguments() throws Exception {
|
||||||
String fileName = JetTestUtils.navigationMetadata("idea/testData/resolve/references/WrongNumberOfTypeArguments.kt");
|
String fileName = JetTestUtils.navigationMetadata("idea/testData/resolve/references/WrongNumberOfTypeArguments.kt");
|
||||||
|
|||||||
Reference in New Issue
Block a user