Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import com.intellij.psi.PsiWhiteSpace;
import com.intellij.psi.util.PsiTreeUtil;
import com.intellij.util.FunctionUtil;
import com.intellij.util.IconUtil;
import com.jetbrains.lang.dart.psi.*;
import com.jetbrains.lang.dart.psi.impl.AbstractDartMethodDeclarationImpl;
import org.jetbrains.annotations.NotNull;
Expand Down Expand Up @@ -54,9 +55,14 @@ public LineMarkerInfo<?> getLineMarkerInfo(final @NotNull PsiElement element) {

PsiElement anchor = PsiTreeUtil.getDeepestFirst(markerLocation);
// finally, create the marker
LineMarkerInfo info = new LineMarkerInfo<>(anchor, anchor.getTextRange(), null, FunctionUtil.<Object, String>nullConstant(), null,
GutterIconRenderer.Alignment.RIGHT);
EditorColorsScheme scheme = EditorColorsManager.getInstance().getGlobalScheme();
LineMarkerInfo<PsiElement> info = new LineMarkerInfo<>(anchor,
anchor.getTextRange(),
IconUtil.getEmptyIcon(true),
FunctionUtil.<Object, String>nullConstant(),
null,
GutterIconRenderer.Alignment.RIGHT,
() -> "Method separator");
EditorColorsScheme scheme = EditorColorsManager.getInstance().getGlobalScheme();
info.separatorColor = scheme.getColor(CodeInsightColors.METHOD_SEPARATORS_COLOR);
info.separatorPlacement = SeparatorPlacement.TOP;
return info;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,43 +63,63 @@ public LineMarkerInfo<?> getLineMarkerInfo(final @NotNull PsiElement element) {
return null;
}

private static @NotNull LineMarkerInfo createMarkerClass(final @NotNull DartComponentName name) {
final VirtualFile file = name.getContainingFile().getVirtualFile();
PsiElement anchor = PsiTreeUtil.getDeepestFirst(name);
return new LineMarkerInfo<>(anchor, anchor.getTextRange(), AllIcons.Gutter.OverridenMethod,
element -> DaemonBundle.message("class.is.subclassed.too.many"), (e, __) -> {
DartAnalysisServerService das = DartAnalysisServerService.getInstance(name.getProject());
final List<TypeHierarchyItem> items = das.search_getTypeHierarchy(file, anchor.getTextRange().getStartOffset(), false);
if (items.isEmpty()) {
return;
}
// TODO(scheglov) Consider using just Element(s), not PsiElement(s) for better performance
final Set<DartComponent> components =
DartInheritorsSearcher.getSubClasses(name.getProject(), GlobalSearchScope.allScope(name.getProject()), items);
String popupTitle = DaemonBundle.message("navigation.title.subclass", name.getName(), components.size(), "");
String findUsagesTitle = DartBundle.message("tab.title.subclasses.of.0", name.getName());
PsiElementListNavigator.openTargets(e, DartResolveUtil.getComponentNameArray(components), popupTitle, findUsagesTitle,
new DefaultPsiElementCellRenderer());
}, GutterIconRenderer.Alignment.RIGHT);
}
private static @NotNull LineMarkerInfo createMarkerClass(final @NotNull DartComponentName name) {
final VirtualFile file = name.getContainingFile().getVirtualFile();
PsiElement anchor = PsiTreeUtil.getDeepestFirst(name);
String accessibleName = DaemonBundle.message("class.is.subclassed.too.many");

return new LineMarkerInfo<>(
anchor,
anchor.getTextRange(),
AllIcons.Gutter.OverridenMethod,
element -> accessibleName,
(e, __) -> {
DartAnalysisServerService das = DartAnalysisServerService.getInstance(name.getProject());
final List<TypeHierarchyItem> items = das.search_getTypeHierarchy(file, anchor.getTextRange().getStartOffset(), false);
if (items.isEmpty()) {
return;
}
// TODO(scheglov) Consider using just Element(s), not PsiElement(s) for better performance
final Set<DartComponent> components =
DartInheritorsSearcher.getSubClasses(name.getProject(), GlobalSearchScope.allScope(name.getProject()), items);
String popupTitle = DaemonBundle.message("navigation.title.subclass", name.getName(), components.size(), "");
String findUsagesTitle = DartBundle.message("tab.title.subclasses.of.0", name.getName());
PsiElementListNavigator.openTargets(e, DartResolveUtil.getComponentNameArray(components), popupTitle, findUsagesTitle,
new DefaultPsiElementCellRenderer());
},
GutterIconRenderer.Alignment.RIGHT,
() -> accessibleName
);
}


private static @NotNull LineMarkerInfo createMarkerMember(final @NotNull DartComponentName name) {
final VirtualFile file = name.getContainingFile().getVirtualFile();
PsiElement anchor = PsiTreeUtil.getDeepestFirst(name);
String accessibleName = DaemonBundle.message("method.is.overridden.too.many");

return new LineMarkerInfo<>(
anchor,
anchor.getTextRange(),
AllIcons.Gutter.OverridenMethod,
element -> accessibleName,
(e, __) -> {
DartAnalysisServerService das = DartAnalysisServerService.getInstance(name.getProject());
final List<TypeHierarchyItem> items = das.search_getTypeHierarchy(file, anchor.getTextRange().getStartOffset(), false);
if (items.isEmpty()) {
return;
}
// TODO(scheglov) Consider using just Element(s), not PsiElement(s) for better performance
final Set<DartComponent> components =
DartInheritorsSearcher.getSubMembers(name.getProject(), GlobalSearchScope.allScope(name.getProject()), items);
String popupTitle = DaemonBundle.message("navigation.title.overrider.method", name.getName(), components.size());
String findUsagesTitle = DartBundle.message("tab.title.overriding.methods.of.0", name.getName());
PsiElementListNavigator.openTargets(e, DartResolveUtil.getComponentNameArray(components), popupTitle, findUsagesTitle,
new DefaultPsiElementCellRenderer());
},
GutterIconRenderer.Alignment.RIGHT,
() -> accessibleName
);
}

private static @NotNull LineMarkerInfo createMarkerMember(final @NotNull DartComponentName name) {
final VirtualFile file = name.getContainingFile().getVirtualFile();
PsiElement anchor = PsiTreeUtil.getDeepestFirst(name);
return new LineMarkerInfo<>(anchor, anchor.getTextRange(), AllIcons.Gutter.OverridenMethod,
element -> DaemonBundle.message("method.is.overridden.too.many"), (e, __) -> {
DartAnalysisServerService das = DartAnalysisServerService.getInstance(name.getProject());
final List<TypeHierarchyItem> items = das.search_getTypeHierarchy(file, anchor.getTextRange().getStartOffset(), false);
if (items.isEmpty()) {
return;
}
// TODO(scheglov) Consider using just Element(s), not PsiElement(s) for better performance
final Set<DartComponent> components =
DartInheritorsSearcher.getSubMembers(name.getProject(), GlobalSearchScope.allScope(name.getProject()), items);
String popupTitle = DaemonBundle.message("navigation.title.overrider.method", name.getName(), components.size());
String findUsagesTitle = DartBundle.message("tab.title.overriding.methods.of.0", name.getName());
PsiElementListNavigator.openTargets(e, DartResolveUtil.getComponentNameArray(components), popupTitle, findUsagesTitle,
new DefaultPsiElementCellRenderer());
}, GutterIconRenderer.Alignment.RIGHT);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ private static void addDartComponent(List<DartComponent> components, Project pro
}
}

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

private static @Nullable LineMarkerInfo tryCreateOverrideMarker(final @NotNull DartComponentName componentName,
final @Nullable DartComponent superclassComponent,
final @NotNull List<DartComponent> interfaceComponents) {
if (superclassComponent == null && interfaceComponents.isEmpty()) {
return null;
}
final String name = componentName.getName();
final boolean overrides;
final DartComponent superComponent;
if (superclassComponent != null) {
overrides = true;
superComponent = superclassComponent;
}
else {
overrides = false;
superComponent = interfaceComponents.getFirst();
private static @Nullable LineMarkerInfo tryCreateOverrideMarker(final @NotNull DartComponentName componentName,
final @Nullable DartComponent superclassComponent,
final @NotNull List<DartComponent> interfaceComponents) {
if (superclassComponent == null && interfaceComponents.isEmpty()) {
return null;
}
final String name = componentName.getName();
final boolean overrides;
final DartComponent superComponent;
if (superclassComponent != null) {
overrides = true;
superComponent = superclassComponent;
}
else {
overrides = false;
superComponent = interfaceComponents.getFirst();
}

// Generate the tooltip/accessible name string once
final String accessibleName;
final DartClass superClass = PsiTreeUtil.getParentOfType(superComponent, DartClass.class);
if (superClass == null) {
accessibleName = "null";
} else if (overrides) {
accessibleName = DartBundle.message(superclassComponent.isOperator() ? "overrides.operator.in" : "overrides.method.in", name, superClass.getName());
} else {
accessibleName = DartBundle.message("implements.method.in", name, superClass.getName());
}

final Icon icon = overrides ? AllIcons.Gutter.OverridingMethod : AllIcons.Gutter.ImplementingMethod;
PsiElement anchor = PsiTreeUtil.getDeepestFirst(componentName);

return new LineMarkerInfo<>(anchor, anchor.getTextRange(), icon, __ -> accessibleName, (e, __) -> {
List<DartComponent> superComponents = new ArrayList<>();
if (superclassComponent != null) {
superComponents.add(superclassComponent);
}
superComponents.addAll(interfaceComponents);
PsiElementListNavigator.openTargets(e, DartResolveUtil.getComponentNameArray(superComponents),
DaemonBundle.message("navigation.title.super.method", name),
DaemonBundle.message("navigation.findUsages.title.super.method", name),
new DefaultPsiElementCellRenderer());
}, GutterIconRenderer.Alignment.LEFT, () -> accessibleName);
}
final Icon icon = overrides ? AllIcons.Gutter.OverridingMethod : AllIcons.Gutter.ImplementingMethod;
PsiElement anchor = PsiTreeUtil.getDeepestFirst(componentName);

return new LineMarkerInfo<>(anchor, anchor.getTextRange(), icon, __ -> {
final DartClass superClass = PsiTreeUtil.getParentOfType(superComponent, DartClass.class);
if (superClass == null) return "null";
if (overrides) {
return DartBundle.message(superclassComponent.isOperator() ? "overrides.operator.in"
: "overrides.method.in",
name,
superClass.getName());
}
return DartBundle.message("implements.method.in", name, superClass.getName());
}, (e, __) -> {
List<DartComponent> superComponents = new ArrayList<>();
if (superclassComponent != null) {
superComponents.add(superclassComponent);
}
superComponents.addAll(interfaceComponents);
PsiElementListNavigator.openTargets(e, DartResolveUtil.getComponentNameArray(superComponents),
DaemonBundle.message("navigation.title.super.method", name),
DaemonBundle.message("navigation.findUsages.title.super.method", name),
new DefaultPsiElementCellRenderer());
}, GutterIconRenderer.Alignment.LEFT);
}
}
Loading