Skip to content

Commit 3546431

Browse files
committed
Migrate calls from deprecated API LineMarkerInfo constructors
This reduces the number of deprecated API usages by the verifier violations by 4.
1 parent 73ce02b commit 3546431

File tree

3 files changed

+111
-82
lines changed

3 files changed

+111
-82
lines changed

third_party/src/main/java/com/jetbrains/lang/dart/ide/marker/DartMethodLineMarkerProvider.java

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
import com.intellij.psi.PsiWhiteSpace;
1515
import com.intellij.psi.util.PsiTreeUtil;
1616
import com.intellij.util.FunctionUtil;
17+
import com.intellij.util.IconUtil;
1718
import com.jetbrains.lang.dart.psi.*;
1819
import com.jetbrains.lang.dart.psi.impl.AbstractDartMethodDeclarationImpl;
1920
import org.jetbrains.annotations.NotNull;
@@ -54,9 +55,14 @@ public LineMarkerInfo<?> getLineMarkerInfo(final @NotNull PsiElement element) {
5455

5556
PsiElement anchor = PsiTreeUtil.getDeepestFirst(markerLocation);
5657
// finally, create the marker
57-
LineMarkerInfo info = new LineMarkerInfo<>(anchor, anchor.getTextRange(), null, FunctionUtil.<Object, String>nullConstant(), null,
58-
GutterIconRenderer.Alignment.RIGHT);
59-
EditorColorsScheme scheme = EditorColorsManager.getInstance().getGlobalScheme();
58+
LineMarkerInfo<PsiElement> info = new LineMarkerInfo<>(anchor,
59+
anchor.getTextRange(),
60+
IconUtil.getEmptyIcon(true),
61+
FunctionUtil.<Object, String>nullConstant(),
62+
null,
63+
GutterIconRenderer.Alignment.RIGHT,
64+
() -> "Method separator");
65+
EditorColorsScheme scheme = EditorColorsManager.getInstance().getGlobalScheme();
6066
info.separatorColor = scheme.getColor(CodeInsightColors.METHOD_SEPARATORS_COLOR);
6167
info.separatorPlacement = SeparatorPlacement.TOP;
6268
return info;

third_party/src/main/java/com/jetbrains/lang/dart/ide/marker/DartServerImplementationsMarkerProvider.java

Lines changed: 58 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -63,43 +63,63 @@ public LineMarkerInfo<?> getLineMarkerInfo(final @NotNull PsiElement element) {
6363
return null;
6464
}
6565

66-
private static @NotNull LineMarkerInfo createMarkerClass(final @NotNull DartComponentName name) {
67-
final VirtualFile file = name.getContainingFile().getVirtualFile();
68-
PsiElement anchor = PsiTreeUtil.getDeepestFirst(name);
69-
return new LineMarkerInfo<>(anchor, anchor.getTextRange(), AllIcons.Gutter.OverridenMethod,
70-
element -> DaemonBundle.message("class.is.subclassed.too.many"), (e, __) -> {
71-
DartAnalysisServerService das = DartAnalysisServerService.getInstance(name.getProject());
72-
final List<TypeHierarchyItem> items = das.search_getTypeHierarchy(file, anchor.getTextRange().getStartOffset(), false);
73-
if (items.isEmpty()) {
74-
return;
75-
}
76-
// TODO(scheglov) Consider using just Element(s), not PsiElement(s) for better performance
77-
final Set<DartComponent> components =
78-
DartInheritorsSearcher.getSubClasses(name.getProject(), GlobalSearchScope.allScope(name.getProject()), items);
79-
String popupTitle = DaemonBundle.message("navigation.title.subclass", name.getName(), components.size(), "");
80-
String findUsagesTitle = DartBundle.message("tab.title.subclasses.of.0", name.getName());
81-
PsiElementListNavigator.openTargets(e, DartResolveUtil.getComponentNameArray(components), popupTitle, findUsagesTitle,
82-
new DefaultPsiElementCellRenderer());
83-
}, GutterIconRenderer.Alignment.RIGHT);
84-
}
66+
private static @NotNull LineMarkerInfo createMarkerClass(final @NotNull DartComponentName name) {
67+
final VirtualFile file = name.getContainingFile().getVirtualFile();
68+
PsiElement anchor = PsiTreeUtil.getDeepestFirst(name);
69+
String accessibleName = DaemonBundle.message("class.is.subclassed.too.many");
70+
71+
return new LineMarkerInfo<>(
72+
anchor,
73+
anchor.getTextRange(),
74+
AllIcons.Gutter.OverridenMethod,
75+
element -> accessibleName,
76+
(e, __) -> {
77+
DartAnalysisServerService das = DartAnalysisServerService.getInstance(name.getProject());
78+
final List<TypeHierarchyItem> items = das.search_getTypeHierarchy(file, anchor.getTextRange().getStartOffset(), false);
79+
if (items.isEmpty()) {
80+
return;
81+
}
82+
// TODO(scheglov) Consider using just Element(s), not PsiElement(s) for better performance
83+
final Set<DartComponent> components =
84+
DartInheritorsSearcher.getSubClasses(name.getProject(), GlobalSearchScope.allScope(name.getProject()), items);
85+
String popupTitle = DaemonBundle.message("navigation.title.subclass", name.getName(), components.size(), "");
86+
String findUsagesTitle = DartBundle.message("tab.title.subclasses.of.0", name.getName());
87+
PsiElementListNavigator.openTargets(e, DartResolveUtil.getComponentNameArray(components), popupTitle, findUsagesTitle,
88+
new DefaultPsiElementCellRenderer());
89+
},
90+
GutterIconRenderer.Alignment.RIGHT,
91+
() -> accessibleName
92+
);
93+
}
94+
95+
96+
private static @NotNull LineMarkerInfo createMarkerMember(final @NotNull DartComponentName name) {
97+
final VirtualFile file = name.getContainingFile().getVirtualFile();
98+
PsiElement anchor = PsiTreeUtil.getDeepestFirst(name);
99+
String accessibleName = DaemonBundle.message("method.is.overridden.too.many");
100+
101+
return new LineMarkerInfo<>(
102+
anchor,
103+
anchor.getTextRange(),
104+
AllIcons.Gutter.OverridenMethod,
105+
element -> accessibleName,
106+
(e, __) -> {
107+
DartAnalysisServerService das = DartAnalysisServerService.getInstance(name.getProject());
108+
final List<TypeHierarchyItem> items = das.search_getTypeHierarchy(file, anchor.getTextRange().getStartOffset(), false);
109+
if (items.isEmpty()) {
110+
return;
111+
}
112+
// TODO(scheglov) Consider using just Element(s), not PsiElement(s) for better performance
113+
final Set<DartComponent> components =
114+
DartInheritorsSearcher.getSubMembers(name.getProject(), GlobalSearchScope.allScope(name.getProject()), items);
115+
String popupTitle = DaemonBundle.message("navigation.title.overrider.method", name.getName(), components.size());
116+
String findUsagesTitle = DartBundle.message("tab.title.overriding.methods.of.0", name.getName());
117+
PsiElementListNavigator.openTargets(e, DartResolveUtil.getComponentNameArray(components), popupTitle, findUsagesTitle,
118+
new DefaultPsiElementCellRenderer());
119+
},
120+
GutterIconRenderer.Alignment.RIGHT,
121+
() -> accessibleName
122+
);
123+
}
85124

86-
private static @NotNull LineMarkerInfo createMarkerMember(final @NotNull DartComponentName name) {
87-
final VirtualFile file = name.getContainingFile().getVirtualFile();
88-
PsiElement anchor = PsiTreeUtil.getDeepestFirst(name);
89-
return new LineMarkerInfo<>(anchor, anchor.getTextRange(), AllIcons.Gutter.OverridenMethod,
90-
element -> DaemonBundle.message("method.is.overridden.too.many"), (e, __) -> {
91-
DartAnalysisServerService das = DartAnalysisServerService.getInstance(name.getProject());
92-
final List<TypeHierarchyItem> items = das.search_getTypeHierarchy(file, anchor.getTextRange().getStartOffset(), false);
93-
if (items.isEmpty()) {
94-
return;
95-
}
96-
// TODO(scheglov) Consider using just Element(s), not PsiElement(s) for better performance
97-
final Set<DartComponent> components =
98-
DartInheritorsSearcher.getSubMembers(name.getProject(), GlobalSearchScope.allScope(name.getProject()), items);
99-
String popupTitle = DaemonBundle.message("navigation.title.overrider.method", name.getName(), components.size());
100-
String findUsagesTitle = DartBundle.message("tab.title.overriding.methods.of.0", name.getName());
101-
PsiElementListNavigator.openTargets(e, DartResolveUtil.getComponentNameArray(components), popupTitle, findUsagesTitle,
102-
new DefaultPsiElementCellRenderer());
103-
}, GutterIconRenderer.Alignment.RIGHT);
104-
}
105125
}

third_party/src/main/java/com/jetbrains/lang/dart/ide/marker/DartServerOverrideMarkerProvider.java

Lines changed: 44 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ private static void addDartComponent(List<DartComponent> components, Project pro
4949
}
5050
}
5151

52-
private static @Nullable LineMarkerInfo createOverrideMarker(DartComponentName componentName) {
52+
private static @Nullable LineMarkerInfo createOverrideMarker(final DartComponentName componentName) {
5353
final VirtualFile virtualFile = componentName.getContainingFile().getVirtualFile();
5454
if (virtualFile == null || !virtualFile.isInLocalFileSystem()) {
5555
return null;
@@ -75,46 +75,49 @@ private static void addDartComponent(List<DartComponent> components, Project pro
7575
return tryCreateOverrideMarker(componentName, superclassComponent, interfaceComponents);
7676
}
7777

78-
private static @Nullable LineMarkerInfo tryCreateOverrideMarker(final @NotNull DartComponentName componentName,
79-
final @Nullable DartComponent superclassComponent,
80-
final @NotNull List<DartComponent> interfaceComponents) {
81-
if (superclassComponent == null && interfaceComponents.isEmpty()) {
82-
return null;
83-
}
84-
final String name = componentName.getName();
85-
final boolean overrides;
86-
final DartComponent superComponent;
87-
if (superclassComponent != null) {
88-
overrides = true;
89-
superComponent = superclassComponent;
90-
}
91-
else {
92-
overrides = false;
93-
superComponent = interfaceComponents.getFirst();
78+
private static @Nullable LineMarkerInfo tryCreateOverrideMarker(final @NotNull DartComponentName componentName,
79+
final @Nullable DartComponent superclassComponent,
80+
final @NotNull List<DartComponent> interfaceComponents) {
81+
if (superclassComponent == null && interfaceComponents.isEmpty()) {
82+
return null;
83+
}
84+
final String name = componentName.getName();
85+
final boolean overrides;
86+
final DartComponent superComponent;
87+
if (superclassComponent != null) {
88+
overrides = true;
89+
superComponent = superclassComponent;
90+
}
91+
else {
92+
overrides = false;
93+
superComponent = interfaceComponents.getFirst();
94+
}
95+
96+
// Generate the tooltip/accessible name string once
97+
final String accessibleName;
98+
final DartClass superClass = PsiTreeUtil.getParentOfType(superComponent, DartClass.class);
99+
if (superClass == null) {
100+
accessibleName = "null";
101+
} else if (overrides) {
102+
accessibleName = DartBundle.message(superclassComponent.isOperator() ? "overrides.operator.in" : "overrides.method.in", name, superClass.getName());
103+
} else {
104+
accessibleName = DartBundle.message("implements.method.in", name, superClass.getName());
105+
}
106+
107+
final Icon icon = overrides ? AllIcons.Gutter.OverridingMethod : AllIcons.Gutter.ImplementingMethod;
108+
PsiElement anchor = PsiTreeUtil.getDeepestFirst(componentName);
109+
110+
return new LineMarkerInfo<>(anchor, anchor.getTextRange(), icon, __ -> accessibleName, (e, __) -> {
111+
List<DartComponent> superComponents = new ArrayList<>();
112+
if (superclassComponent != null) {
113+
superComponents.add(superclassComponent);
114+
}
115+
superComponents.addAll(interfaceComponents);
116+
PsiElementListNavigator.openTargets(e, DartResolveUtil.getComponentNameArray(superComponents),
117+
DaemonBundle.message("navigation.title.super.method", name),
118+
DaemonBundle.message("navigation.findUsages.title.super.method", name),
119+
new DefaultPsiElementCellRenderer());
120+
}, GutterIconRenderer.Alignment.LEFT, () -> accessibleName);
94121
}
95-
final Icon icon = overrides ? AllIcons.Gutter.OverridingMethod : AllIcons.Gutter.ImplementingMethod;
96-
PsiElement anchor = PsiTreeUtil.getDeepestFirst(componentName);
97122

98-
return new LineMarkerInfo<>(anchor, anchor.getTextRange(), icon, __ -> {
99-
final DartClass superClass = PsiTreeUtil.getParentOfType(superComponent, DartClass.class);
100-
if (superClass == null) return "null";
101-
if (overrides) {
102-
return DartBundle.message(superclassComponent.isOperator() ? "overrides.operator.in"
103-
: "overrides.method.in",
104-
name,
105-
superClass.getName());
106-
}
107-
return DartBundle.message("implements.method.in", name, superClass.getName());
108-
}, (e, __) -> {
109-
List<DartComponent> superComponents = new ArrayList<>();
110-
if (superclassComponent != null) {
111-
superComponents.add(superclassComponent);
112-
}
113-
superComponents.addAll(interfaceComponents);
114-
PsiElementListNavigator.openTargets(e, DartResolveUtil.getComponentNameArray(superComponents),
115-
DaemonBundle.message("navigation.title.super.method", name),
116-
DaemonBundle.message("navigation.findUsages.title.super.method", name),
117-
new DefaultPsiElementCellRenderer());
118-
}, GutterIconRenderer.Alignment.LEFT);
119-
}
120123
}

0 commit comments

Comments
 (0)