mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-18 09:34:34 +07:00
IDEA-73251 Mark recursive method calls on gutter partially implemented. Multiple calls on the same line generate multiple icons to be fixed.
This commit is contained in:
@@ -60,6 +60,8 @@ public class JavaLineMarkerProvider implements LineMarkerProvider, DumbAware {
|
||||
private static final Icon IMPLEMENTED_INTERFACE_MARKER_RENDERER = IMPLEMENTED_METHOD_MARKER_RENDERER;
|
||||
private static final Icon SUBCLASSED_CLASS_MARKER_RENDERER = OVERRIDEN_METHOD_MARKER_RENDERER;
|
||||
|
||||
private static final Icon RECURSIVE_METHOD_ICON = IconLoader.getIcon("/gutter/recursiveMethod.png");
|
||||
|
||||
protected final DaemonCodeAnalyzerSettings myDaemonSettings;
|
||||
protected final EditorColorsManager myColorsManager;
|
||||
|
||||
@@ -164,6 +166,11 @@ public class JavaLineMarkerProvider implements LineMarkerProvider, DumbAware {
|
||||
}
|
||||
else if (element instanceof PsiClass && !(element instanceof PsiTypeParameter)) {
|
||||
collectInheritingClasses((PsiClass)element, result);
|
||||
} else if(element instanceof PsiMethodCallExpression){
|
||||
final PsiMethodCallExpression methodCall = (PsiMethodCallExpression)element;
|
||||
if (isRecursiveMethodCall(methodCall)){
|
||||
result.add(new RecursiveMethodCallMarkerInfo(methodCall));
|
||||
}
|
||||
}
|
||||
}
|
||||
if (!methods.isEmpty()) {
|
||||
@@ -171,6 +178,12 @@ public class JavaLineMarkerProvider implements LineMarkerProvider, DumbAware {
|
||||
}
|
||||
}
|
||||
|
||||
private static boolean isRecursiveMethodCall(@NotNull PsiMethodCallExpression methodCall){
|
||||
final PsiMethod referencedMethod = (PsiMethod)methodCall.getMethodExpression().resolve();
|
||||
|
||||
return referencedMethod.getTextRange().contains(methodCall.getTextRange());
|
||||
}
|
||||
|
||||
private static void collectInheritingClasses(PsiClass aClass, Collection<LineMarkerInfo> result) {
|
||||
if (aClass.hasModifierProperty(PsiModifier.FINAL)) {
|
||||
return;
|
||||
@@ -276,4 +289,36 @@ public class JavaLineMarkerProvider implements LineMarkerProvider, DumbAware {
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
private static class RecursiveMethodCallMarkerInfo extends MergeableLineMarkerInfo<PsiMethodCallExpression> {
|
||||
private RecursiveMethodCallMarkerInfo(@NotNull PsiMethodCallExpression methodCall) {
|
||||
super(methodCall,
|
||||
methodCall.getTextRange(),
|
||||
RECURSIVE_METHOD_ICON,
|
||||
Pass.UPDATE_OVERRIDEN_MARKERS,
|
||||
FunctionUtil.<PsiMethodCallExpression, String>constant("Recursive call"),
|
||||
null,
|
||||
GutterIconRenderer.Alignment.RIGHT
|
||||
);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canMergeWith(@NotNull MergeableLineMarkerInfo<?> info) {
|
||||
if (!(info instanceof RecursiveMethodCallMarkerInfo)) return false;
|
||||
PsiElement otherElement = info.getElement();
|
||||
PsiElement myElement = getElement();
|
||||
return otherElement != null && myElement != null;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public Icon getCommonIcon(@NotNull List<MergeableLineMarkerInfo> infos) {
|
||||
return myIcon;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Function<? super PsiElement, String> getCommonTooltip(@NotNull List<MergeableLineMarkerInfo> infos) {
|
||||
return FunctionUtil.<PsiElement, String>constant("Multiple recursive calls");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user