Search in sources :

Example 6 with PathReference

use of com.intellij.openapi.paths.PathReference in project intellij-plugins by JetBrains.

the class StrutsDataModel method updateDataModel.

private void updateDataModel() {
    final StrutsModel model = StrutsManager.getInstance(myProject).getModelByFile(myFile);
    if (model == null) {
        return;
    }
    for (final StrutsPackage strutsPackage : model.getStrutsPackages()) {
        for (final Action action : strutsPackage.getActions()) {
            final ActionNode actionNode = new ActionNode(action, action.getName().getStringValue());
            addNode(actionNode);
            for (final Result result : action.getResults()) {
                final PathReference pathReference = result.getValue();
                final String path = pathReference != null ? pathReference.getPath() : UNKNOWN;
                final ResultNode resultNode = new ResultNode(result, path);
                addNode(resultNode);
                final String resultName = result.getName().getStringValue();
                addEdge(new BasicStrutsEdge(actionNode, resultNode, resultName != null ? resultName : Result.DEFAULT_NAME));
            }
        }
    }
}
Also used : PathReference(com.intellij.openapi.paths.PathReference) Action(com.intellij.struts2.dom.struts.action.Action) BasicStrutsEdge(com.intellij.struts2.graph.beans.BasicStrutsEdge) ResultNode(com.intellij.struts2.graph.beans.ResultNode) StrutsModel(com.intellij.struts2.dom.struts.model.StrutsModel) ActionNode(com.intellij.struts2.graph.beans.ActionNode) StrutsPackage(com.intellij.struts2.dom.struts.strutspackage.StrutsPackage) Result(com.intellij.struts2.dom.struts.action.Result)

Example 7 with PathReference

use of com.intellij.openapi.paths.PathReference in project intellij-plugins by JetBrains.

the class Struts2UrlConverter method getTargetPaths.

public Collection<String> getTargetPaths(@NotNull final PsiFile sourceFile, @NotNull final WebFacet webFacet) {
    final StrutsModel combinedModel = StrutsManager.getInstance(sourceFile.getProject()).getCombinedModel(webFacet.getModule());
    if (combinedModel == null) {
        return Collections.emptyList();
    }
    final List<String> actionExtensions = StrutsConstantHelper.getActionExtensions(sourceFile);
    if (actionExtensions.isEmpty()) {
        return Collections.emptyList();
    }
    final String actionExtension = actionExtensions.get(0);
    @NonNls final ArrayList<String> list = new ArrayList<>();
    combinedModel.processActions(action -> {
        for (final Result result : action.getResults()) {
            final PathReference pathReference = result.getValue();
            if (pathReference != null) {
                final PsiElement psiElement = pathReference.resolve();
                if (psiElement != null && psiElement.equals(sourceFile)) {
                    String namespace = action.getNamespace();
                    if (!Comparing.equal(namespace, StrutsPackage.DEFAULT_NAMESPACE)) {
                        namespace += "/";
                    }
                    list.add(namespace + action.getName().getStringValue() + actionExtension);
                }
            }
        }
        return true;
    });
    return list;
}
Also used : PathReference(com.intellij.openapi.paths.PathReference) NonNls(org.jetbrains.annotations.NonNls) StrutsModel(com.intellij.struts2.dom.struts.model.StrutsModel) ArrayList(java.util.ArrayList) PsiElement(com.intellij.psi.PsiElement) Result(com.intellij.struts2.dom.struts.action.Result)

Example 8 with PathReference

use of com.intellij.openapi.paths.PathReference in project intellij-plugins by JetBrains.

the class ActionAnnotatorBase method installActionMethods.

/**
   * Annotate action-methods of this class with result(s).
   *
   * @param lineMarkerInfos Current line markers.
   * @param clazz           Class to annotate.
   * @param actions         Corresponding Actions.
   */
private static void installActionMethods(final Collection<? super RelatedItemLineMarkerInfo> lineMarkerInfos, final PsiClass clazz, final List<Action> actions) {
    final Map<PsiMethod, Set<PathReference>> pathReferenceMap = new HashMap<>();
    for (final Action action : actions) {
        final PsiMethod method = action.searchActionMethod();
        if (method == null || !clazz.equals(method.getContainingClass())) {
            continue;
        }
        final Set<PathReference> pathReferences = new HashSet<>();
        final List<Result> results = action.getResults();
        for (final Result result : results) {
            final PathReference pathReference = result.getValue();
            ContainerUtil.addIfNotNull(pathReferences, pathReference);
        }
        final Set<PathReference> toStore = ContainerUtil.getOrCreate(pathReferenceMap, method, new HashSet<>());
        toStore.addAll(pathReferences);
        pathReferenceMap.put(method, toStore);
    }
    for (final Map.Entry<PsiMethod, Set<PathReference>> entries : pathReferenceMap.entrySet()) {
        final NavigationGutterIconBuilder<PathReference> gutterIconBuilder = NavigationGutterIconBuilder.create(AllIcons.Hierarchy.Base, PATH_REFERENCE_CONVERTER, PATH_REFERENCE_GOTO_RELATED_ITEM_PROVIDER).setAlignment(GutterIconRenderer.Alignment.LEFT).setPopupTitle(StrutsBundle.message("annotators.action.goto.result")).setTargets(entries.getValue()).setTooltipTitle(StrutsBundle.message("annotators.action.goto.result.tooltip"));
        lineMarkerInfos.add(gutterIconBuilder.createLineMarkerInfo(entries.getKey()));
    }
}
Also used : PathReference(com.intellij.openapi.paths.PathReference) Action(com.intellij.struts2.dom.struts.action.Action) Result(com.intellij.struts2.dom.struts.action.Result)

Aggregations

PathReference (com.intellij.openapi.paths.PathReference)8 Result (com.intellij.struts2.dom.struts.action.Result)6 Action (com.intellij.struts2.dom.struts.action.Action)4 StrutsModel (com.intellij.struts2.dom.struts.model.StrutsModel)4 PsiElement (com.intellij.psi.PsiElement)3 ArrayList (java.util.ArrayList)3 NotNull (org.jetbrains.annotations.NotNull)3 XmlFile (com.intellij.psi.xml.XmlFile)2 StrutsManager (com.intellij.struts2.dom.struts.model.StrutsManager)2 NonNls (org.jetbrains.annotations.NonNls)2 Nullable (org.jetbrains.annotations.Nullable)2 DomGotoRelatedItem (com.intellij.codeInsight.navigation.DomGotoRelatedItem)1 FtlType (com.intellij.freemarker.psi.FtlType)1 FtlFile (com.intellij.freemarker.psi.files.FtlFile)1 FtlGlobalVariableProvider (com.intellij.freemarker.psi.files.FtlGlobalVariableProvider)1 FtlXmlNamespaceType (com.intellij.freemarker.psi.files.FtlXmlNamespaceType)1 FtlLightVariable (com.intellij.freemarker.psi.variables.FtlLightVariable)1 FtlPsiType (com.intellij.freemarker.psi.variables.FtlPsiType)1 FtlVariable (com.intellij.freemarker.psi.variables.FtlVariable)1 WebCommonClassNames (com.intellij.javaee.web.WebCommonClassNames)1