use of com.intellij.navigation.GotoRelatedItem in project intellij-plugins by JetBrains.
the class CucumberGoToRelatedProvider method getItems.
@NotNull
@Override
public List<? extends GotoRelatedItem> getItems(@NotNull PsiElement psiElement) {
final PsiFile file = psiElement.getContainingFile();
if (file instanceof GherkinFile) {
final List<GherkinStep> steps = new ArrayList<>();
final GherkinFile gherkinFile = (GherkinFile) file;
final GherkinFeature[] features = gherkinFile.getFeatures();
for (GherkinFeature feature : features) {
final GherkinStepsHolder[] stepHolders = feature.getScenarios();
for (GherkinStepsHolder stepHolder : stepHolders) {
Collections.addAll(steps, stepHolder.getSteps());
}
}
final CucumberStepsIndex index = CucumberStepsIndex.getInstance(file.getProject());
final List<PsiFile> resultFiles = new ArrayList<>();
final List<GotoRelatedItem> result = new ArrayList<>();
for (GherkinStep step : steps) {
AbstractStepDefinition stepDef = index.findStepDefinition(gherkinFile, step);
final PsiElement stepDefMethod = stepDef != null ? stepDef.getElement() : null;
if (stepDefMethod != null) {
final PsiFile stepDefFile = stepDefMethod.getContainingFile();
if (!resultFiles.contains(stepDefFile)) {
resultFiles.add(stepDefFile);
result.add(new GotoRelatedItem(stepDefFile, "Step definition file"));
}
}
}
return result;
}
return Collections.emptyList();
}
use of com.intellij.navigation.GotoRelatedItem in project intellij-plugins by JetBrains.
the class CucumberGotoRelatedFileTest method testGotoRelated.
public void testGotoRelated() {
CucumberStepsIndex.getInstance(getProject()).reset();
myFixture.copyDirectoryToProject("gotoRelated", "");
myFixture.configureByFile("gotoRelated/test.feature");
List<GotoRelatedItem> items = GotoRelatedSymbolAction.getItems(myFixture.getFile(), myFixture.getEditor(), null);
assertEquals(1, items.size());
PsiElement gotoElement = items.get(0).getElement();
assertTrue(gotoElement instanceof PsiJavaFile);
assertEquals("ShoppingStepdefs.java", ((PsiJavaFile) gotoElement).getName());
}
use of com.intellij.navigation.GotoRelatedItem in project intellij-community by JetBrains.
the class GotoRelatedSymbolAction method actionPerformed.
@Override
public void actionPerformed(@NotNull AnActionEvent e) {
final DataContext dataContext = e.getDataContext();
final PsiElement element = getContextElement(dataContext);
if (element == null)
return;
List<GotoRelatedItem> items = NavigationUtil.collectRelatedItems(element, dataContext);
if (items.isEmpty()) {
final JComponent label = HintUtil.createErrorLabel("No related symbols");
label.setBorder(IdeBorderFactory.createEmptyBorder(2, 7, 2, 7));
JBPopupFactory.getInstance().createBalloonBuilder(label).setFadeoutTime(3000).setFillColor(HintUtil.getErrorColor()).createBalloon().show(JBPopupFactory.getInstance().guessBestPopupLocation(dataContext), Balloon.Position.above);
return;
}
if (items.size() == 1 && items.get(0).getElement() != null) {
items.get(0).navigate();
return;
}
NavigationUtil.getRelatedItemsPopup(items, "Choose Target").showInBestPositionFor(dataContext);
}
use of com.intellij.navigation.GotoRelatedItem in project intellij-community by JetBrains.
the class RelatedItemLineMarkerGotoAdapter method getItems.
@NotNull
@Override
public List<? extends GotoRelatedItem> getItems(@NotNull PsiElement context) {
List<PsiElement> parents = new ArrayList<>();
PsiElement current = context;
Set<Language> languages = new HashSet<>();
while (current != null) {
parents.add(current);
languages.add(current.getLanguage());
if (current instanceof PsiFile)
break;
current = current.getParent();
}
List<LineMarkerProvider> providers = new ArrayList<>();
for (Language language : languages) {
providers.addAll(LineMarkersPass.getMarkerProviders(language, context.getProject()));
}
List<GotoRelatedItem> items = new ArrayList<>();
for (LineMarkerProvider provider : providers) {
if (provider instanceof RelatedItemLineMarkerProvider) {
List<RelatedItemLineMarkerInfo> markers = new ArrayList<>();
RelatedItemLineMarkerProvider relatedItemLineMarkerProvider = (RelatedItemLineMarkerProvider) provider;
for (PsiElement parent : parents) {
ContainerUtil.addIfNotNull(markers, relatedItemLineMarkerProvider.getLineMarkerInfo(parent));
}
relatedItemLineMarkerProvider.collectNavigationMarkers(parents, markers, true);
addItemsForMarkers(markers, items);
}
}
return items;
}
use of com.intellij.navigation.GotoRelatedItem in project intellij-community by JetBrains.
the class NavigationUtil method getRelatedItemsPopup.
/**
* Returns navigation popup that shows list of related items from {@code items} list
* @param items
* @param title
* @param showContainingModules Whether the popup should show additional information that aligned at the right side of the dialog.<br>
* It's usually a module name or library name of corresponding navigation item.<br>
* {@code false} by default
* @return
*/
@NotNull
public static JBPopup getRelatedItemsPopup(final List<? extends GotoRelatedItem> items, String title, boolean showContainingModules) {
Object[] elements = new Object[items.size()];
//todo[nik] move presentation logic to GotoRelatedItem class
final Map<PsiElement, GotoRelatedItem> itemsMap = new HashMap<>();
for (int i = 0; i < items.size(); i++) {
GotoRelatedItem item = items.get(i);
elements[i] = item.getElement() != null ? item.getElement() : item;
itemsMap.put(item.getElement(), item);
}
return getPsiElementPopup(elements, itemsMap, title, showContainingModules, element -> {
if (element instanceof PsiElement) {
itemsMap.get(element).navigate();
} else {
((GotoRelatedItem) element).navigate();
}
return true;
});
}
Aggregations