Search in sources :

Example 6 with Result

use of com.intellij.struts2.dom.struts.action.Result in project intellij-plugins by JetBrains.

the class DefaultInterceptorRefResolveConverterImpl method fromString.

public InterceptorStack fromString(@Nullable @NonNls final String name, final ConvertContext context) {
    if (name == null) {
        return null;
    }
    final Condition<InterceptorStack> nameCondition = interceptorStack -> name.equals(interceptorStack.getName().getStringValue());
    final Ref<InterceptorStack> resolveResult = new Ref<>();
    final Processor<StrutsPackage> processor = strutsPackage -> {
        final InterceptorStack result = ContainerUtil.find(strutsPackage.getInterceptorStacks(), nameCondition);
        if (result != null) {
            resolveResult.set(result);
            return false;
        }
        return true;
    };
    final StrutsPackageHierarchyWalker walker = new StrutsPackageHierarchyWalker(getCurrentStrutsPackage(context), processor);
    walker.walkUp();
    return resolveResult.get();
}
Also used : DefaultInterceptorRefResolveConverter(com.intellij.struts2.dom.struts.strutspackage.DefaultInterceptorRefResolveConverter) Collection(java.util.Collection) NonNls(org.jetbrains.annotations.NonNls) ContainerUtil(com.intellij.util.containers.ContainerUtil) StrutsPackageHierarchyWalker(com.intellij.struts2.dom.struts.strutspackage.StrutsPackageHierarchyWalker) Nullable(org.jetbrains.annotations.Nullable) List(java.util.List) SmartList(com.intellij.util.SmartList) Processor(com.intellij.util.Processor) StrutsPackage(com.intellij.struts2.dom.struts.strutspackage.StrutsPackage) InterceptorStack(com.intellij.struts2.dom.struts.strutspackage.InterceptorStack) ConvertContext(com.intellij.util.xml.ConvertContext) NotNull(org.jetbrains.annotations.NotNull) Ref(com.intellij.openapi.util.Ref) DomUtil(com.intellij.util.xml.DomUtil) Condition(com.intellij.openapi.util.Condition) StrutsPackageHierarchyWalker(com.intellij.struts2.dom.struts.strutspackage.StrutsPackageHierarchyWalker) Ref(com.intellij.openapi.util.Ref) InterceptorStack(com.intellij.struts2.dom.struts.strutspackage.InterceptorStack) StrutsPackage(com.intellij.struts2.dom.struts.strutspackage.StrutsPackage)

Example 7 with Result

use of com.intellij.struts2.dom.struts.action.Result 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)

Example 8 with Result

use of com.intellij.struts2.dom.struts.action.Result in project intellij-plugins by JetBrains.

the class Struts2GlobalVariableProvider method getGlobalVariables.

@NotNull
public List<? extends FtlVariable> getGlobalVariables(final FtlFile file) {
    final Module module = ModuleUtilCore.findModuleForPsiElement(file);
    if (module == null) {
        return Collections.emptyList();
    }
    if (StrutsFacet.getInstance(module) == null) {
        return Collections.emptyList();
    }
    final List<FtlVariable> result = new ArrayList<>();
    result.add(new MyFtlLightVariable("stack", file, (FtlType) null));
    result.add(new MyFtlLightVariable("response", file, WebCommonClassNames.HTTP_SERVLET_RESPONSE));
    result.add(new MyFtlLightVariable("res", file, WebCommonClassNames.HTTP_SERVLET_RESPONSE));
    result.add(new MyFtlLightVariable("request", file, WebCommonClassNames.HTTP_SERVLET_REQUEST));
    result.add(new MyFtlLightVariable("req", file, WebCommonClassNames.HTTP_SERVLET_REQUEST));
    result.add(new MyFtlLightVariable("session", file, WebCommonClassNames.HTTP_SESSION));
    result.add(new MyFtlLightVariable("application", file, WebCommonClassNames.SERVLET_CONTEXT));
    result.add(new MyFtlLightVariable("base", file, CommonClassNames.JAVA_LANG_STRING));
    installTaglibSupport(result, module, StrutsConstants.TAGLIB_STRUTS_UI_URI, StrutsConstants.TAGLIB_STRUTS_UI_PREFIX);
    installTaglibSupport(result, module, StrutsConstants.TAGLIB_JQUERY_PLUGIN_URI, StrutsConstants.TAGLIB_JQUERY_PLUGIN_PREFIX);
    installTaglibSupport(result, module, StrutsConstants.TAGLIB_JQUERY_RICHTEXT_PLUGIN_URI, StrutsConstants.TAGLIB_JQUERY_RICHTEXT_PLUGIN_PREFIX);
    installTaglibSupport(result, module, StrutsConstants.TAGLIB_JQUERY_CHART_PLUGIN_URI, StrutsConstants.TAGLIB_JQUERY_CHART_PLUGIN_PREFIX);
    installTaglibSupport(result, module, StrutsConstants.TAGLIB_JQUERY_TREE_PLUGIN_URI, StrutsConstants.TAGLIB_JQUERY_TREE_PLUGIN_PREFIX);
    installTaglibSupport(result, module, StrutsConstants.TAGLIB_JQUERY_GRID_PLUGIN_URI, StrutsConstants.TAGLIB_JQUERY_GRID_PLUGIN_PREFIX);
    installTaglibSupport(result, module, StrutsConstants.TAGLIB_JQUERY_MOBILE_PLUGIN_URI, StrutsConstants.TAGLIB_JQUERY_MOBILE_PLUGIN_PREFIX);
    installTaglibSupport(result, module, StrutsConstants.TAGLIB_BOOTSTRAP_PLUGIN_URI, StrutsConstants.TAGLIB_BOOTSTRAP_PLUGIN_PREFIX);
    final Processor<Action> processor = action -> {
        final PsiClass actionClass = action.searchActionClass();
        if (actionClass != null) {
            for (final Result result1 : action.getResults()) {
                final ResultType resultType = result1.getEffectiveResultType();
                if (resultType != null && FreeMarkerStrutsResultContributor.FREEMARKER.equals(resultType.getName().getStringValue())) {
                    final PathReference reference = result1.getValue();
                    final PsiElement target = reference == null ? null : reference.resolve();
                    if (target != null && (file.getManager().areElementsEquivalent(file, target) || file.getManager().areElementsEquivalent(file.getOriginalFile(), target))) {
                        final PsiClassType actionType = PsiTypesUtil.getClassType(actionClass);
                        final FtlPsiType ftlPsiType = FtlPsiType.wrap(actionType);
                        result.add(new MyFtlLightVariable("", action.getXmlTag(), ftlPsiType));
                        result.add(new MyFtlLightVariable("action", action.getXmlTag(), ftlPsiType));
                        return false;
                    }
                }
            }
        }
        return true;
    };
    for (final StrutsModel model : StrutsManager.getInstance(file.getProject()).getAllModels(module)) {
        model.processActions(processor);
    }
    return result;
}
Also used : PsiTypesUtil(com.intellij.psi.util.PsiTypesUtil) PathReference(com.intellij.openapi.paths.PathReference) XmlFile(com.intellij.psi.xml.XmlFile) StrutsManager(com.intellij.struts2.dom.struts.model.StrutsManager) NonNls(org.jetbrains.annotations.NonNls) Action(com.intellij.struts2.dom.struts.action.Action) StrutsModel(com.intellij.struts2.dom.struts.model.StrutsModel) FtlPsiType(com.intellij.freemarker.psi.variables.FtlPsiType) Result(com.intellij.struts2.dom.struts.action.Result) FtlFile(com.intellij.freemarker.psi.files.FtlFile) ArrayList(java.util.ArrayList) StrutsFacet(com.intellij.struts2.facet.StrutsFacet) FtlXmlNamespaceType(com.intellij.freemarker.psi.files.FtlXmlNamespaceType) FtlGlobalVariableProvider(com.intellij.freemarker.psi.files.FtlGlobalVariableProvider) XmlDocument(com.intellij.psi.xml.XmlDocument) FtlLightVariable(com.intellij.freemarker.psi.variables.FtlLightVariable) Module(com.intellij.openapi.module.Module) StrutsConstants(com.intellij.struts2.StrutsConstants) FtlVariable(com.intellij.freemarker.psi.variables.FtlVariable) ModuleUtilCore(com.intellij.openapi.module.ModuleUtilCore) XmlNSDescriptor(com.intellij.xml.XmlNSDescriptor) StrutsIcons(com.intellij.struts2.StrutsIcons) Nullable(org.jetbrains.annotations.Nullable) List(java.util.List) WebCommonClassNames(com.intellij.javaee.web.WebCommonClassNames) ResultType(com.intellij.struts2.dom.struts.strutspackage.ResultType) Processor(com.intellij.util.Processor) FtlType(com.intellij.freemarker.psi.FtlType) com.intellij.psi(com.intellij.psi) NotNull(org.jetbrains.annotations.NotNull) Collections(java.util.Collections) JspManager(com.intellij.psi.impl.source.jsp.JspManager) javax.swing(javax.swing) PathReference(com.intellij.openapi.paths.PathReference) Action(com.intellij.struts2.dom.struts.action.Action) ArrayList(java.util.ArrayList) ResultType(com.intellij.struts2.dom.struts.strutspackage.ResultType) Result(com.intellij.struts2.dom.struts.action.Result) FtlVariable(com.intellij.freemarker.psi.variables.FtlVariable) FtlPsiType(com.intellij.freemarker.psi.variables.FtlPsiType) StrutsModel(com.intellij.struts2.dom.struts.model.StrutsModel) FtlType(com.intellij.freemarker.psi.FtlType) Module(com.intellij.openapi.module.Module) NotNull(org.jetbrains.annotations.NotNull)

Example 9 with Result

use of com.intellij.struts2.dom.struts.action.Result in project intellij-plugins by JetBrains.

the class GoToActionSymbolProvider method addNames.

protected void addNames(@NotNull final Module module, final Set<String> result) {
    final StrutsModel strutsModel = StrutsManager.getInstance(module.getProject()).getCombinedModel(module);
    if (strutsModel == null) {
        return;
    }
    strutsModel.processActions(action -> {
        result.add(action.getName().getStringValue());
        return true;
    });
}
Also used : StrutsModel(com.intellij.struts2.dom.struts.model.StrutsModel)

Example 10 with Result

use of com.intellij.struts2.dom.struts.action.Result in project intellij-plugins by JetBrains.

the class GoToActionSymbolProvider method addItems.

protected void addItems(@NotNull final Module module, final String name, final List<NavigationItem> result) {
    final StrutsModel strutsModel = StrutsManager.getInstance(module.getProject()).getCombinedModel(module);
    if (strutsModel == null) {
        return;
    }
    final List<Action> actions = strutsModel.findActionsByName(name, null);
    for (final Action action : actions) {
        final NavigationItem item = createNavigationItem(action.getXmlTag(), action.getName().getStringValue() + " [" + action.getNamespace() + "]", Struts2Icons.Action);
        result.add(item);
    }
}
Also used : Action(com.intellij.struts2.dom.struts.action.Action) NavigationItem(com.intellij.navigation.NavigationItem) StrutsModel(com.intellij.struts2.dom.struts.model.StrutsModel)

Aggregations

NotNull (org.jetbrains.annotations.NotNull)10 Result (com.intellij.struts2.dom.struts.action.Result)9 Action (com.intellij.struts2.dom.struts.action.Action)8 StrutsModel (com.intellij.struts2.dom.struts.model.StrutsModel)8 PathReference (com.intellij.openapi.paths.PathReference)6 Ref (com.intellij.openapi.util.Ref)6 StrutsPackage (com.intellij.struts2.dom.struts.strutspackage.StrutsPackage)6 StrutsPackageHierarchyWalker (com.intellij.struts2.dom.struts.strutspackage.StrutsPackageHierarchyWalker)6 Nullable (org.jetbrains.annotations.Nullable)6 Processor (com.intellij.util.Processor)5 List (java.util.List)5 NonNls (org.jetbrains.annotations.NonNls)5 ResultType (com.intellij.struts2.dom.struts.strutspackage.ResultType)4 Condition (com.intellij.openapi.util.Condition)3 DefaultClassRef (com.intellij.struts2.dom.struts.strutspackage.DefaultClassRef)3 SmartList (com.intellij.util.SmartList)3 ContainerUtil (com.intellij.util.containers.ContainerUtil)3 ConvertContext (com.intellij.util.xml.ConvertContext)3 Collection (java.util.Collection)3 NavigationItem (com.intellij.navigation.NavigationItem)2