Search in sources :

Example 1 with DomGotoRelatedItem

use of com.intellij.codeInsight.navigation.DomGotoRelatedItem in project intellij-plugins by JetBrains.

the class GotoRelatedActionProvider method getItems.

@NotNull
@Override
public List<? extends GotoRelatedItem> getItems(@NotNull final PsiElement psiElement) {
    PsiFile psiFile = psiElement.getContainingFile();
    if (psiFile == null)
        return Collections.emptyList();
    final PsiFile containingFile = psiFile.getOriginalFile();
    final String filename = containingFile.getName();
    final String extension = FileUtilRt.getExtension(filename);
    if (!SUPPORTED_EXTENSIONS.contains(extension)) {
        return Collections.emptyList();
    }
    final StrutsManager strutsManager = StrutsManager.getInstance(psiElement.getProject());
    final StrutsModel strutsModel = strutsManager.getCombinedModel(psiElement);
    if (strutsModel == null) {
        return Collections.emptyList();
    }
    final List<PsiFile> allFiles = containingFile.getViewProvider().getAllFiles();
    final Set<Action> actions = new HashSet<>();
    final List<GotoRelatedItem> items = new ArrayList<>();
    strutsModel.processActions(action -> {
        for (final Result result : action.getResults()) {
            final PathReference pathReference = result.getValue();
            if (pathReference == null) {
                continue;
            }
            final String path = pathReference.getPath();
            if (!path.endsWith(filename)) {
                continue;
            }
            final PsiElement resolve = pathReference.resolve();
            if (ContainerUtil.find(allFiles, resolve) == null) {
                continue;
            }
            if (!actions.contains(action)) {
                items.add(new DomGotoRelatedItem(action));
                actions.add(action);
            }
            final PsiClass actionClass = action.searchActionClass();
            if (actionClass == null) {
                continue;
            }
            final PsiMethod actionMethod = action.searchActionMethod();
            items.add(new GotoRelatedItem(actionMethod != null ? actionMethod : actionClass));
        }
        return true;
    });
    return items;
}
Also used : PathReference(com.intellij.openapi.paths.PathReference) Action(com.intellij.struts2.dom.struts.action.Action) PsiMethod(com.intellij.psi.PsiMethod) StrutsManager(com.intellij.struts2.dom.struts.model.StrutsManager) PsiClass(com.intellij.psi.PsiClass) Result(com.intellij.struts2.dom.struts.action.Result) DomGotoRelatedItem(com.intellij.codeInsight.navigation.DomGotoRelatedItem) StrutsModel(com.intellij.struts2.dom.struts.model.StrutsModel) PsiFile(com.intellij.psi.PsiFile) DomGotoRelatedItem(com.intellij.codeInsight.navigation.DomGotoRelatedItem) GotoRelatedItem(com.intellij.navigation.GotoRelatedItem) PsiElement(com.intellij.psi.PsiElement) NotNull(org.jetbrains.annotations.NotNull)

Aggregations

DomGotoRelatedItem (com.intellij.codeInsight.navigation.DomGotoRelatedItem)1 GotoRelatedItem (com.intellij.navigation.GotoRelatedItem)1 PathReference (com.intellij.openapi.paths.PathReference)1 PsiClass (com.intellij.psi.PsiClass)1 PsiElement (com.intellij.psi.PsiElement)1 PsiFile (com.intellij.psi.PsiFile)1 PsiMethod (com.intellij.psi.PsiMethod)1 Action (com.intellij.struts2.dom.struts.action.Action)1 Result (com.intellij.struts2.dom.struts.action.Result)1 StrutsManager (com.intellij.struts2.dom.struts.model.StrutsManager)1 StrutsModel (com.intellij.struts2.dom.struts.model.StrutsModel)1 NotNull (org.jetbrains.annotations.NotNull)1