Caller Hierarchy: NPE fix
#EA-66031 Fixed
This commit is contained in:
@@ -37,7 +37,10 @@ public class KotlinCallHierarchyProvider implements HierarchyProvider {
|
|||||||
Project project = CommonDataKeys.PROJECT.getData(dataContext);
|
Project project = CommonDataKeys.PROJECT.getData(dataContext);
|
||||||
if (project == null) return null;
|
if (project == null) return null;
|
||||||
|
|
||||||
return HierarchyUtils.getCallHierarchyElement(getCurrentElement(dataContext, project));
|
PsiElement element = getCurrentElement(dataContext, project);
|
||||||
|
if (element == null) return null;
|
||||||
|
|
||||||
|
return HierarchyUtils.getCallHierarchyElement(element);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static PsiElement getCurrentElement(DataContext dataContext, Project project) {
|
private static PsiElement getCurrentElement(DataContext dataContext, Project project) {
|
||||||
|
|||||||
+3
@@ -0,0 +1,3 @@
|
|||||||
|
<node text="foo()" base="true">
|
||||||
|
|
||||||
|
</node>
|
||||||
@@ -0,0 +1,3 @@
|
|||||||
|
fun test() {
|
||||||
|
<caret>foo()
|
||||||
|
}
|
||||||
@@ -0,0 +1 @@
|
|||||||
|
Cannot apply action for element at caret
|
||||||
@@ -30,6 +30,7 @@ import com.intellij.psi.PsiClass;
|
|||||||
import com.intellij.psi.PsiDocumentManager;
|
import com.intellij.psi.PsiDocumentManager;
|
||||||
import com.intellij.psi.PsiElement;
|
import com.intellij.psi.PsiElement;
|
||||||
import com.intellij.psi.PsiFile;
|
import com.intellij.psi.PsiFile;
|
||||||
|
import com.intellij.refactoring.util.CommonRefactoringUtil.RefactoringErrorHintException;
|
||||||
import com.intellij.testFramework.MapDataContext;
|
import com.intellij.testFramework.MapDataContext;
|
||||||
import com.intellij.util.ArrayUtil;
|
import com.intellij.util.ArrayUtil;
|
||||||
import com.intellij.util.Processor;
|
import com.intellij.util.Processor;
|
||||||
@@ -162,7 +163,7 @@ public abstract class AbstractHierarchyTest extends KotlinHierarchyViewTestBase
|
|||||||
|
|
||||||
private PsiElement getElementAtCaret(HierarchyProvider provider) {
|
private PsiElement getElementAtCaret(HierarchyProvider provider) {
|
||||||
PsiElement target = provider.getTarget(getDataContext());
|
PsiElement target = provider.getTarget(getDataContext());
|
||||||
assert target != null : "Cannot apply action for element at caret";
|
if (target == null) throw new RefactoringErrorHintException("Cannot apply action for element at caret");
|
||||||
return target;
|
return target;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -195,6 +196,17 @@ public abstract class AbstractHierarchyTest extends KotlinHierarchyViewTestBase
|
|||||||
return ArrayUtil.toStringArray(files);
|
return ArrayUtil.toStringArray(files);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void doHierarchyTest(Computable<HierarchyTreeStructure> treeStructureComputable, String... fileNames) throws Exception {
|
||||||
|
try {
|
||||||
|
super.doHierarchyTest(treeStructureComputable, fileNames);
|
||||||
|
}
|
||||||
|
catch (RefactoringErrorHintException e) {
|
||||||
|
String expectedMessage = FileUtil.loadFile(new File(folderName, "messages.txt"), true);
|
||||||
|
assertEquals(expectedMessage, e.getLocalizedMessage());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected String getBasePath() {
|
protected String getBasePath() {
|
||||||
return folderName.substring("idea/testData/".length());
|
return folderName.substring("idea/testData/".length());
|
||||||
|
|||||||
@@ -390,6 +390,12 @@ public class HierarchyTestGenerated extends AbstractHierarchyTest {
|
|||||||
String fileName = JetTestUtils.navigationMetadata("idea/testData/hierarchy/calls/callers/kotlinProperty/");
|
String fileName = JetTestUtils.navigationMetadata("idea/testData/hierarchy/calls/callers/kotlinProperty/");
|
||||||
doCallerHierarchyTest(fileName);
|
doCallerHierarchyTest(fileName);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@TestMetadata("kotlinUnresolvedFunction")
|
||||||
|
public void testKotlinUnresolvedFunction() throws Exception {
|
||||||
|
String fileName = JetTestUtils.navigationMetadata("idea/testData/hierarchy/calls/callers/kotlinUnresolvedFunction/");
|
||||||
|
doCallerHierarchyTest(fileName);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@TestMetadata("idea/testData/hierarchy/calls/callees")
|
@TestMetadata("idea/testData/hierarchy/calls/callees")
|
||||||
|
|||||||
Reference in New Issue
Block a user