use of com.intellij.navigation.GotoRelatedItem in project intellij-community by JetBrains.
the class FormRelatedFilesProvider method getItems.
@NotNull
@Override
public List<? extends GotoRelatedItem> getItems(@NotNull PsiElement context) {
PsiClass psiClass = PsiTreeUtil.getParentOfType(context, PsiClass.class, false);
if (psiClass != null) {
while (psiClass != null) {
List<PsiFile> forms = FormClassIndex.findFormsBoundToClass(psiClass.getProject(), psiClass);
if (!forms.isEmpty()) {
return GotoRelatedItem.createItems(forms, "UI Forms");
}
psiClass = PsiTreeUtil.getParentOfType(psiClass, PsiClass.class);
}
} else {
PsiFile file = context.getContainingFile();
if (file != null && file.getFileType() == GuiFormFileType.INSTANCE) {
try {
String className = Utils.getBoundClassName(file.getText());
if (className != null) {
Project project = file.getProject();
PsiClass aClass = JavaPsiFacade.getInstance(project).findClass(className, GlobalSearchScope.allScope(project));
if (aClass != null) {
return Collections.singletonList(new GotoRelatedItem(aClass, "Java"));
}
}
} catch (Exception ignore) {
}
}
}
return Collections.emptyList();
}
use of com.intellij.navigation.GotoRelatedItem in project intellij-community by JetBrains.
the class RelatedItemLineMarkerGotoAdapter method addItemsForMarkers.
private static void addItemsForMarkers(List<RelatedItemLineMarkerInfo> markers, List<GotoRelatedItem> result) {
Set<PsiFile> addedFiles = new HashSet<>();
for (RelatedItemLineMarkerInfo<?> marker : markers) {
Collection<? extends GotoRelatedItem> items = marker.createGotoRelatedItems();
for (GotoRelatedItem item : items) {
PsiElement element = item.getElement();
if (element instanceof PsiFile) {
PsiFile file = (PsiFile) element;
if (addedFiles.contains(file)) {
continue;
}
}
if (element != null) {
ContainerUtil.addIfNotNull(addedFiles, element.getContainingFile());
}
result.add(item);
}
}
}
use of com.intellij.navigation.GotoRelatedItem in project intellij-community by JetBrains.
the class NavigationUtil method collectRelatedItems.
@NotNull
public static List<GotoRelatedItem> collectRelatedItems(@NotNull PsiElement contextElement, @Nullable DataContext dataContext) {
Set<GotoRelatedItem> items = ContainerUtil.newLinkedHashSet();
for (GotoRelatedProvider provider : Extensions.getExtensions(GotoRelatedProvider.EP_NAME)) {
items.addAll(provider.getItems(contextElement));
if (dataContext != null) {
items.addAll(provider.getItems(dataContext));
}
}
GotoRelatedItem[] result = items.toArray(new GotoRelatedItem[items.size()]);
Arrays.sort(result, (i1, i2) -> {
String o1 = i1.getGroup();
String o2 = i2.getGroup();
return StringUtil.isEmpty(o1) ? 1 : StringUtil.isEmpty(o2) ? -1 : o1.compareTo(o2);
});
return Arrays.asList(result);
}
use of com.intellij.navigation.GotoRelatedItem in project intellij-community by JetBrains.
the class TestCaseAsRelatedFileProvider method getItems.
@NotNull
@Override
public List<? extends GotoRelatedItem> getItems(@NotNull DataContext context) {
final Editor editor = context.getData(CommonDataKeys.EDITOR);
final Project project = context.getData(CommonDataKeys.PROJECT);
final VirtualFile file = context.getData(CommonDataKeys.VIRTUAL_FILE);
if (editor == null || file == null || project == null) {
return Collections.emptyList();
}
final List<Location> locations = TestLocationDataRule.collectRelativeLocations(project, file);
if (locations.isEmpty()) {
return Collections.emptyList();
}
return ContainerUtil.map(locations, location -> new GotoRelatedItem(location.getPsiElement()));
}
use of com.intellij.navigation.GotoRelatedItem in project android by JetBrains.
the class AndroidGotoRelatedProvider method getLazyItemsForClass.
@Nullable
static Computable<List<GotoRelatedItem>> getLazyItemsForClass(@NotNull PsiClass aClass, @NotNull AndroidFacet facet, boolean addDeclarationInManifest) {
final GotoRelatedItem item = findDeclarationInManifest(aClass);
final boolean isContextClass = isInheritorOfContextClass(aClass, facet.getModule());
if (!isContextClass && item == null) {
return null;
}
final List<GotoRelatedItem> items;
if (isContextClass) {
items = new ArrayList<GotoRelatedItem>(collectRelatedLayoutFiles(facet, aClass));
if (addDeclarationInManifest) {
if (item != null) {
items.add(item);
}
}
if (items.isEmpty()) {
return null;
}
} else {
items = Collections.singletonList(item);
}
return new Computable<List<GotoRelatedItem>>() {
@Override
public List<GotoRelatedItem> compute() {
return items;
}
};
}
Aggregations