Search in sources :

Example 1 with GotoRelatedItem

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();
}
Also used : Project(com.intellij.openapi.project.Project) PsiClass(com.intellij.psi.PsiClass) PsiFile(com.intellij.psi.PsiFile) GotoRelatedItem(com.intellij.navigation.GotoRelatedItem) NotNull(org.jetbrains.annotations.NotNull)

Example 2 with GotoRelatedItem

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);
        }
    }
}
Also used : PsiFile(com.intellij.psi.PsiFile) GotoRelatedItem(com.intellij.navigation.GotoRelatedItem) PsiElement(com.intellij.psi.PsiElement)

Example 3 with GotoRelatedItem

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);
}
Also used : GotoRelatedProvider(com.intellij.navigation.GotoRelatedProvider) GotoRelatedItem(com.intellij.navigation.GotoRelatedItem) NotNull(org.jetbrains.annotations.NotNull)

Example 4 with GotoRelatedItem

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()));
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) Project(com.intellij.openapi.project.Project) Editor(com.intellij.openapi.editor.Editor) GotoRelatedItem(com.intellij.navigation.GotoRelatedItem) Location(com.intellij.execution.Location) NotNull(org.jetbrains.annotations.NotNull)

Example 5 with GotoRelatedItem

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;
        }
    };
}
Also used : GotoRelatedItem(com.intellij.navigation.GotoRelatedItem) Computable(com.intellij.openapi.util.Computable) Nullable(org.jetbrains.annotations.Nullable)

Aggregations

GotoRelatedItem (com.intellij.navigation.GotoRelatedItem)21 PsiElement (com.intellij.psi.PsiElement)13 NotNull (org.jetbrains.annotations.NotNull)11 PsiFile (com.intellij.psi.PsiFile)9 VirtualFile (com.intellij.openapi.vfs.VirtualFile)4 ArrayList (java.util.ArrayList)3 ResourceBundle (com.intellij.lang.properties.ResourceBundle)2 PropertiesFile (com.intellij.lang.properties.psi.PropertiesFile)2 GotoRelatedProvider (com.intellij.navigation.GotoRelatedProvider)2 DataContext (com.intellij.openapi.actionSystem.DataContext)2 FileEditor (com.intellij.openapi.fileEditor.FileEditor)2 Project (com.intellij.openapi.project.Project)2 Computable (com.intellij.openapi.util.Computable)2 PsiClass (com.intellij.psi.PsiClass)2 LineMarkerProvider (com.intellij.codeInsight.daemon.LineMarkerProvider)1 RelatedItemLineMarkerInfo (com.intellij.codeInsight.daemon.RelatedItemLineMarkerInfo)1 RelatedItemLineMarkerProvider (com.intellij.codeInsight.daemon.RelatedItemLineMarkerProvider)1 DomGotoRelatedItem (com.intellij.codeInsight.navigation.DomGotoRelatedItem)1 Location (com.intellij.execution.Location)1 DefaultPsiElementCellRenderer (com.intellij.ide.util.DefaultPsiElementCellRenderer)1