Supported navigation to source of named object and its members.
This commit is contained in:
@@ -197,6 +197,13 @@ public class DecompiledDataFactory {
|
|||||||
PsiElement clsMember = BindingContextUtils.descriptorToDeclaration(bindingContext, descriptor);
|
PsiElement clsMember = BindingContextUtils.descriptorToDeclaration(bindingContext, descriptor);
|
||||||
if (clsMember != null) {
|
if (clsMember != null) {
|
||||||
clsMembersToRanges.put(clsMember, new TextRange(startOffset, endOffset));
|
clsMembersToRanges.put(clsMember, new TextRange(startOffset, endOffset));
|
||||||
|
|
||||||
|
if (descriptor instanceof ClassDescriptor && ((ClassDescriptor) descriptor).getKind() == ClassKind.OBJECT) {
|
||||||
|
assert clsMember instanceof PsiClass;
|
||||||
|
PsiField instanceField = ((PsiClass) clsMember).findFieldByName(JvmAbi.INSTANCE_FIELD, false);
|
||||||
|
assert instanceField != null;
|
||||||
|
clsMembersToRanges.put(instanceField, new TextRange(startOffset, endOffset));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -73,6 +73,12 @@ public class JetClsNavigationPolicy implements ClsCustomNavigationPolicy {
|
|||||||
return sourceProperty;
|
return sourceProperty;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
else if (jetDeclaration instanceof JetClassOrObject) {
|
||||||
|
JetClassOrObject sourceClass = JetSourceNavigationHelper.getSourceClassOrObject((JetClassOrObject) jetDeclaration);
|
||||||
|
if (sourceClass != null) {
|
||||||
|
return sourceClass;
|
||||||
|
}
|
||||||
|
}
|
||||||
return jetDeclaration;
|
return jetDeclaration;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -188,13 +188,12 @@ public class JetSourceNavigationHelper {
|
|||||||
}
|
}
|
||||||
else if (declarationContainer instanceof JetClassBody) {
|
else if (declarationContainer instanceof JetClassBody) {
|
||||||
JetClassOrObject parent = (JetClassOrObject)declarationContainer.getParent();
|
JetClassOrObject parent = (JetClassOrObject)declarationContainer.getParent();
|
||||||
boolean isClassObject = parent instanceof JetObjectDeclaration;
|
boolean isClassObject = parent instanceof JetObjectDeclaration && parent.getParent() instanceof JetClassObject;
|
||||||
JetClass jetClass =
|
JetClassOrObject classOrObject = isClassObject ? PsiTreeUtil.getParentOfType(parent, JetClass.class) : parent;
|
||||||
isClassObject ? PsiTreeUtil.getParentOfType(parent, JetClass.class) : (JetClass)parent;
|
if (classOrObject == null) {
|
||||||
if (jetClass == null) {
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
Pair<BindingContext, ClassDescriptor> bindingContextAndClassDescriptor = getBindingContextAndClassDescriptor(jetClass);
|
Pair<BindingContext, ClassDescriptor> bindingContextAndClassDescriptor = getBindingContextAndClassDescriptor(classOrObject);
|
||||||
if (bindingContextAndClassDescriptor != null) {
|
if (bindingContextAndClassDescriptor != null) {
|
||||||
BindingContext bindingContext = bindingContextAndClassDescriptor.first;
|
BindingContext bindingContext = bindingContextAndClassDescriptor.first;
|
||||||
ClassDescriptor classDescriptor = bindingContextAndClassDescriptor.second;
|
ClassDescriptor classDescriptor = bindingContextAndClassDescriptor.second;
|
||||||
|
|||||||
@@ -3,6 +3,6 @@
|
|||||||
|
|
||||||
package testData.libraries
|
package testData.libraries
|
||||||
|
|
||||||
[public object NamedObject {
|
[[public object NamedObject {
|
||||||
[public final val objectMember : jet.Int] /* compiled code */
|
[public final val objectMember : jet.Int] /* compiled code */
|
||||||
}]
|
}]]
|
||||||
@@ -0,0 +1,7 @@
|
|||||||
|
import testData.libraries.*
|
||||||
|
|
||||||
|
val x = NamedObject.objectMember
|
||||||
|
|
||||||
|
// main.kt
|
||||||
|
//public object <1>NamedObject {
|
||||||
|
// public val <2>objectMember: Int = 1
|
||||||
@@ -76,6 +76,10 @@ public class NavigateToLibrarySourceTest extends AbstractNavigateToLibraryTest {
|
|||||||
doTest();
|
doTest();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void testNamedObject() {
|
||||||
|
doTest();
|
||||||
|
}
|
||||||
|
|
||||||
private void doTest() {
|
private void doTest() {
|
||||||
userFile = LocalFileSystem.getInstance().findFileByPath(TEST_DATA_PATH + "/usercode/" + getTestName(false) + ".kt");
|
userFile = LocalFileSystem.getInstance().findFileByPath(TEST_DATA_PATH + "/usercode/" + getTestName(false) + ".kt");
|
||||||
assertNotNull(userFile);
|
assertNotNull(userFile);
|
||||||
|
|||||||
Reference in New Issue
Block a user