Refactor JetLineMarkerProvider
This commit is contained in:
@@ -21,6 +21,7 @@ import com.intellij.codeHighlighting.Pass;
|
|||||||
import com.intellij.codeInsight.daemon.GutterIconNavigationHandler;
|
import com.intellij.codeInsight.daemon.GutterIconNavigationHandler;
|
||||||
import com.intellij.codeInsight.daemon.LineMarkerInfo;
|
import com.intellij.codeInsight.daemon.LineMarkerInfo;
|
||||||
import com.intellij.codeInsight.daemon.LineMarkerProvider;
|
import com.intellij.codeInsight.daemon.LineMarkerProvider;
|
||||||
|
import com.intellij.codeInsight.daemon.impl.LineMarkerNavigator;
|
||||||
import com.intellij.codeInsight.daemon.impl.MarkerType;
|
import com.intellij.codeInsight.daemon.impl.MarkerType;
|
||||||
import com.intellij.codeInsight.hint.HintUtil;
|
import com.intellij.codeInsight.hint.HintUtil;
|
||||||
import com.intellij.codeInsight.navigation.NavigationUtil;
|
import com.intellij.codeInsight.navigation.NavigationUtil;
|
||||||
@@ -34,8 +35,10 @@ import com.intellij.psi.search.searches.ClassInheritorsSearch;
|
|||||||
import com.intellij.psi.util.PsiUtilCore;
|
import com.intellij.psi.util.PsiUtilCore;
|
||||||
import com.intellij.ui.awt.RelativePoint;
|
import com.intellij.ui.awt.RelativePoint;
|
||||||
import com.intellij.util.Function;
|
import com.intellij.util.Function;
|
||||||
|
import com.intellij.util.NullableFunction;
|
||||||
import com.intellij.util.PsiNavigateUtil;
|
import com.intellij.util.PsiNavigateUtil;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
import org.jetbrains.annotations.Nullable;
|
||||||
import org.jetbrains.jet.asJava.LightClassUtil;
|
import org.jetbrains.jet.asJava.LightClassUtil;
|
||||||
import org.jetbrains.jet.lang.descriptors.CallableMemberDescriptor;
|
import org.jetbrains.jet.lang.descriptors.CallableMemberDescriptor;
|
||||||
import org.jetbrains.jet.lang.descriptors.DeclarationDescriptor;
|
import org.jetbrains.jet.lang.descriptors.DeclarationDescriptor;
|
||||||
@@ -65,38 +68,51 @@ public class JetLineMarkerProvider implements LineMarkerProvider {
|
|||||||
|
|
||||||
private static final Function<PsiElement, String> SUBCLASSED_CLASS_TOOLTIP_ADAPTER = new Function<PsiElement, String>() {
|
private static final Function<PsiElement, String> SUBCLASSED_CLASS_TOOLTIP_ADAPTER = new Function<PsiElement, String>() {
|
||||||
@Override
|
@Override
|
||||||
public String fun(PsiElement element) {
|
public String fun(@NotNull PsiElement element) {
|
||||||
PsiElement child = getPsiClassFirstChild(element);
|
PsiClass psiClass = getPsiClass(element);
|
||||||
// Java puts its marker on a child of the PsiClass, so we must find a child of our own class too
|
return psiClass != null ? SUBCLASSED_CLASS.getTooltip().fun(psiClass) : null;
|
||||||
return child != null ? MarkerType.SUBCLASSED_CLASS.getTooltip().fun(child) : null;
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
private static PsiElement getPsiClassFirstChild(PsiElement element) {
|
private static final GutterIconNavigationHandler<PsiElement> SUBCLASSED_CLASS_NAVIGATION_HANDLER = new GutterIconNavigationHandler<PsiElement>() {
|
||||||
|
@Override
|
||||||
|
public void navigate(@Nullable MouseEvent e, @Nullable PsiElement elt) {
|
||||||
|
if (elt == null) return;
|
||||||
|
PsiElement psiClass = getPsiClass(elt);
|
||||||
|
if (psiClass != null) {
|
||||||
|
SUBCLASSED_CLASS.getNavigationHandler().navigate(e, psiClass);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
private static final MarkerType SUBCLASSED_CLASS = new MarkerType(
|
||||||
|
new NullableFunction<PsiElement, String>() {
|
||||||
|
@Override
|
||||||
|
public String fun(@Nullable PsiElement element) {
|
||||||
|
if (!(element instanceof PsiClass)) return null;
|
||||||
|
return MarkerType.getSubclassedClassTooltip((PsiClass) element);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
new LineMarkerNavigator() {
|
||||||
|
@Override
|
||||||
|
public void browse(@Nullable MouseEvent e, @Nullable PsiElement element) {
|
||||||
|
if (!(element instanceof PsiClass)) return;
|
||||||
|
MarkerType.navigateToSubclassedClass(e, (PsiClass) element);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
@Nullable
|
||||||
|
private static PsiClass getPsiClass(@NotNull PsiElement element) {
|
||||||
if (!(element instanceof JetClass)) {
|
if (!(element instanceof JetClass)) {
|
||||||
element = element.getParent();
|
element = element.getParent();
|
||||||
if (!(element instanceof JetClass)) {
|
if (!(element instanceof JetClass)) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
PsiClass lightClass = LightClassUtil.getPsiClass((JetClass) element);
|
return LightClassUtil.getPsiClass((JetClass) element);
|
||||||
if (lightClass == null) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
PsiElement[] children = lightClass.getChildren();
|
|
||||||
return children.length > 0 ? children[0] : null;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private static final GutterIconNavigationHandler<PsiElement> SUBCLASSED_CLASS_NAVIGATION_HANDLER = new GutterIconNavigationHandler<PsiElement>() {
|
|
||||||
@Override
|
|
||||||
public void navigate(MouseEvent e, PsiElement elt) {
|
|
||||||
PsiElement child = getPsiClassFirstChild(elt);
|
|
||||||
if (child != null) {
|
|
||||||
MarkerType.SUBCLASSED_CLASS.getNavigationHandler().navigate(e, child);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public LineMarkerInfo getLineMarkerInfo(@NotNull PsiElement element) {
|
public LineMarkerInfo getLineMarkerInfo(@NotNull PsiElement element) {
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user