use of com.intellij.codeInsight.daemon.GutterIconNavigationHandler in project kotlin by JetBrains.
the class AbstractLineMarkersTest method assertNavigationElements.
private void assertNavigationElements(List<LineMarkerInfo> markers) {
List<String> navigationDataComments = KotlinTestUtils.getLastCommentsInFile((KtFile) myFixture.getFile(), KotlinTestUtils.CommentType.BLOCK_COMMENT, false);
if (navigationDataComments.isEmpty())
return;
for (String navigationComment : navigationDataComments) {
final String description = getLineMarkerDescription(navigationComment);
LineMarkerInfo navigateMarker = ContainerUtil.find(markers, new Condition<LineMarkerInfo>() {
@Override
public boolean value(LineMarkerInfo marker) {
String tooltip = marker.getLineMarkerTooltip();
return tooltip != null && tooltip.startsWith(description);
}
});
assertNotNull(String.format("Can't find marker for navigation check with description \"%s\"", description), navigateMarker);
GutterIconNavigationHandler handler = navigateMarker.getNavigationHandler();
if (handler instanceof SuperDeclarationMarkerNavigationHandler) {
PsiElement element = navigateMarker.getElement();
//noinspection unchecked
handler.navigate(null, element);
List<NavigatablePsiElement> navigateElements = ((SuperDeclarationMarkerNavigationHandler) handler).getNavigationElements();
Collections.sort(navigateElements, new Comparator<NavigatablePsiElement>() {
@Override
public int compare(@NotNull NavigatablePsiElement first, @NotNull NavigatablePsiElement second) {
String elementFirstStr = ReferenceUtils.renderAsGotoImplementation(first);
String elementSecondStr = ReferenceUtils.renderAsGotoImplementation(second);
return elementFirstStr.compareTo(elementSecondStr);
}
});
String actualNavigationData = NavigationTestUtils.getNavigateElementsText(myFixture.getProject(), navigateElements);
assertSameLines(getExpectedNavigationText(navigationComment), actualNavigationData);
} else {
Assert.fail("Only SuperDeclarationMarkerNavigationHandler are supported in navigate check");
}
}
}
use of com.intellij.codeInsight.daemon.GutterIconNavigationHandler in project intellij-community by JetBrains.
the class DevKitGutterTargetsChecker method checkGutterTargets.
public static void checkGutterTargets(final GutterMark gutterMark, final String tooltip, final Icon icon, final String... expectedTargets) {
assertNotNull(gutterMark);
assertEquals(tooltip, gutterMark.getTooltipText());
assertEquals(icon, gutterMark.getIcon());
final Collection<PsiElement> targetElements;
if (gutterMark instanceof LineMarkerInfo.LineMarkerGutterIconRenderer) {
final LineMarkerInfo.LineMarkerGutterIconRenderer renderer = UsefulTestCase.assertInstanceOf(gutterMark, LineMarkerInfo.LineMarkerGutterIconRenderer.class);
final LineMarkerInfo lineMarkerInfo = renderer.getLineMarkerInfo();
GutterIconNavigationHandler handler = lineMarkerInfo.getNavigationHandler();
if (handler instanceof NavigationGutterIconRenderer) {
targetElements = ((NavigationGutterIconRenderer) handler).getTargetElements();
} else {
throw new IllegalArgumentException(handler + ": handler not supported");
}
} else {
throw new IllegalArgumentException(gutterMark.getClass() + ": gutter not supported");
}
UsefulTestCase.assertSameElements(ContainerUtil.map(targetElements, element -> SymbolPresentationUtil.getSymbolPresentableText(element)), expectedTargets);
}
use of com.intellij.codeInsight.daemon.GutterIconNavigationHandler in project intellij-plugins by JetBrains.
the class DartServerOverrideMarkerProvider method tryCreateOverrideMarker.
@Nullable
private static LineMarkerInfo tryCreateOverrideMarker(@NotNull final DartComponentName componentName, @Nullable final DartComponent superclassComponent, @NotNull final 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.iterator().next();
}
final Icon icon = overrides ? AllIcons.Gutter.OverridingMethod : AllIcons.Gutter.ImplementingMethod;
return new LineMarkerInfo<>(componentName, componentName.getTextRange(), icon, Pass.LINE_MARKERS, element -> {
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());
}, (GutterIconNavigationHandler<PsiElement>) (e, elt) -> {
List<DartComponent> superComponents = Lists.newArrayList();
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);
}
use of com.intellij.codeInsight.daemon.GutterIconNavigationHandler in project intellij-plugins by JetBrains.
the class DartServerImplementationsMarkerProvider method createMarkerMember.
@NotNull
private static LineMarkerInfo createMarkerMember(@NotNull final DartComponentName name) {
final VirtualFile file = name.getContainingFile().getVirtualFile();
final int nameOffset = name.getTextRange().getStartOffset();
return new LineMarkerInfo<>(name, name.getTextRange(), AllIcons.Gutter.OverridenMethod, Pass.LINE_MARKERS, element -> DaemonBundle.message("method.is.overridden.too.many"), (GutterIconNavigationHandler<PsiElement>) (e, elt) -> {
final List<TypeHierarchyItem> items = DartAnalysisServerService.getInstance(name.getProject()).search_getTypeHierarchy(file, nameOffset, false);
if (items.isEmpty()) {
return;
}
final List<DartComponent> components = DartInheritorsSearcher.getSubMembers(name.getProject(), GlobalSearchScope.allScope(name.getProject()), items);
PsiElementListNavigator.openTargets(e, DartResolveUtil.getComponentNameArray(components), DaemonBundle.message("navigation.title.overrider.method", name.getName(), components.size()), "Overriding methods of " + name.getName(), new DefaultPsiElementCellRenderer());
}, GutterIconRenderer.Alignment.RIGHT);
}
use of com.intellij.codeInsight.daemon.GutterIconNavigationHandler in project intellij-plugins by JetBrains.
the class DartServerImplementationsMarkerProvider method createMarkerClass.
@NotNull
private static LineMarkerInfo createMarkerClass(@NotNull final DartComponentName name) {
final VirtualFile file = name.getContainingFile().getVirtualFile();
final int nameOffset = name.getTextRange().getStartOffset();
return new LineMarkerInfo<>(name, name.getTextRange(), AllIcons.Gutter.OverridenMethod, Pass.LINE_MARKERS, element -> DaemonBundle.message("class.is.subclassed.too.many"), (GutterIconNavigationHandler<PsiElement>) (e, elt) -> {
final List<TypeHierarchyItem> items = DartAnalysisServerService.getInstance(name.getProject()).search_getTypeHierarchy(file, nameOffset, false);
if (items.isEmpty()) {
return;
}
final List<DartComponent> components = DartInheritorsSearcher.getSubClasses(name.getProject(), GlobalSearchScope.allScope(name.getProject()), items);
PsiElementListNavigator.openTargets(e, DartResolveUtil.getComponentNameArray(components), DaemonBundle.message("navigation.title.subclass", name.getName(), components.size(), ""), "Subclasses of " + name.getName(), new DefaultPsiElementCellRenderer());
}, GutterIconRenderer.Alignment.RIGHT);
}
Aggregations