avoid INRE causing holes in java structure view (IDEA-142210)

This commit is contained in:
peter
2015-07-28 20:39:20 +02:00
parent dc5691ec16
commit 6755b5e5a1
3 changed files with 26 additions and 16 deletions

View File

@@ -17,15 +17,17 @@ package com.intellij.ide.structureView.impl.java;
import com.intellij.ide.structureView.StructureViewTreeElement;
import com.intellij.ide.util.treeView.smartTree.SortableTreeElement;
import com.intellij.openapi.project.DumbService;
import com.intellij.openapi.util.text.StringUtil;
import com.intellij.psi.PsiField;
import com.intellij.psi.PsiSubstitutor;
import com.intellij.psi.util.PsiFormatUtil;
import org.jetbrains.annotations.NotNull;
import java.util.Collection;
import java.util.Collections;
import static com.intellij.psi.util.PsiFormatUtil.*;
public class PsiFieldTreeElement extends JavaClassTreeElementBase<PsiField> implements SortableTreeElement {
public PsiFieldTreeElement(PsiField field, boolean isInherited) {
super(isInherited,field);
@@ -39,9 +41,13 @@ public class PsiFieldTreeElement extends JavaClassTreeElementBase<PsiField> impl
@Override
public String getPresentableText() {
return StringUtil.replace(PsiFormatUtil.formatVariable(
getElement(),
PsiFormatUtil.SHOW_NAME | PsiFormatUtil.SHOW_TYPE | PsiFormatUtil.TYPE_AFTER | PsiFormatUtil.SHOW_INITIALIZER,
final PsiField field = getElement();
if (field == null) return "";
final boolean dumb = DumbService.isDumb(field.getProject());
return StringUtil.replace(formatVariable(
field,
SHOW_NAME | (dumb ? 0 : SHOW_TYPE) | TYPE_AFTER | (dumb ? 0 : SHOW_INITIALIZER),
PsiSubstitutor.EMPTY
), ":", ": ");
}

View File

@@ -19,6 +19,7 @@ import com.intellij.ide.structureView.StructureViewTreeElement;
import com.intellij.ide.util.treeView.smartTree.SortableTreeElement;
import com.intellij.openapi.editor.colors.CodeInsightColors;
import com.intellij.openapi.editor.colors.TextAttributesKey;
import com.intellij.openapi.project.DumbService;
import com.intellij.openapi.project.IndexNotReadyException;
import com.intellij.openapi.util.TextRange;
import com.intellij.openapi.util.registry.Registry;
@@ -73,10 +74,13 @@ public class PsiMethodTreeElement extends JavaClassTreeElementBase<PsiMethod> im
@Override
public String getPresentableText() {
String method = PsiFormatUtil.formatMethod(getElement(),
final PsiMethod psiMethod = getElement();
if (psiMethod == null) return "";
final boolean dumb = DumbService.isDumb(psiMethod.getProject());
String method = PsiFormatUtil.formatMethod(psiMethod,
PsiSubstitutor.EMPTY,
SHOW_NAME | SHOW_TYPE | TYPE_AFTER | SHOW_PARAMETERS,
SHOW_TYPE);
SHOW_NAME | TYPE_AFTER | SHOW_PARAMETERS | (dumb ? 0 : SHOW_TYPE),
dumb ? SHOW_NAME : SHOW_TYPE);
return StringUtil.replace(method, ":", ": ");
}
@@ -85,7 +89,7 @@ public class PsiMethodTreeElement extends JavaClassTreeElementBase<PsiMethod> im
public String getLocationString() {
if (!Registry.is("show.method.base.class.in.java.file.structure")) return null;
final PsiMethod method = getElement();
if (myLocation == null) {
if (myLocation == null && method != null && !DumbService.isDumb(method.getProject())) {
if (isInherited()) {
return super.getLocationString();
} else {