Search in sources :

Example 6 with Action

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

the class ActionLinkReferenceProviderTest method checkActionReference.

/**
   * Checks the Action-reference.
   *
   * @param filename   File to check.
   * @param actionName Name of the Action to resolve to.
   * @throws Throwable On errors.
   */
private void checkActionReference(@NonNls final String filename, @NonNls final String actionName) {
    final PsiReference psiReference = myFixture.getReferenceAtCaretPositionWithAssertion(filename);
    final PsiElement psiElement = psiReference.resolve();
    assertNotNull("no resolve element " + actionName, psiElement);
    assertTrue(psiElement instanceof XmlTag);
    final DomElement actionElement = DomManager.getDomManager(getProject()).getDomElement((XmlTag) psiElement);
    assertNotNull(actionElement);
    assertInstanceOf(actionElement, Action.class);
    assertEquals("Action name differs for " + actionName, actionName, ((Action) actionElement).getName().getStringValue());
}
Also used : Action(com.intellij.struts2.dom.struts.action.Action) DomElement(com.intellij.util.xml.DomElement) PsiReference(com.intellij.psi.PsiReference) PsiElement(com.intellij.psi.PsiElement) XmlTag(com.intellij.psi.xml.XmlTag)

Example 7 with Action

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

the class ActionPropertyReferenceProvider method getReferencesByElement.

@NotNull
@Override
public PsiReference[] getReferencesByElement(@NotNull final PsiElement psiElement, @NotNull final ProcessingContext processingContext) {
    if (TaglibUtil.isDynamicExpression(((XmlAttributeValue) psiElement).getValue())) {
        return PsiReference.EMPTY_ARRAY;
    }
    final XmlTag tag = PsiTreeUtil.getParentOfType(psiElement, XmlTag.class);
    assert tag != null;
    final XmlTag actionTag = findEnclosingTag(tag, tag.getNamespacePrefix());
    if (actionTag == null) {
        return PsiReference.EMPTY_ARRAY;
    }
    final String actionName = Comparing.equal(actionTag.getLocalName(), "action") ? actionTag.getAttributeValue("name") : actionTag.getAttributeValue("action");
    if (actionName == null || TaglibUtil.isDynamicExpression(actionName)) {
        return PsiReference.EMPTY_ARRAY;
    }
    final StrutsManager strutsManager = StrutsManager.getInstance(psiElement.getProject());
    final StrutsModel strutsModel = strutsManager.getCombinedModel(psiElement);
    if (strutsModel == null) {
        return PsiReference.EMPTY_ARRAY;
    }
    final List<Action> actions = strutsModel.findActionsByName(actionName, actionTag.getAttributeValue("namespace"));
    if (actions.size() != 1) {
        return PsiReference.EMPTY_ARRAY;
    }
    final Action action = actions.get(0);
    return new BeanPropertyPathReferenceSet(psiElement, action.searchActionClass(), supportsReadOnlyProperties) {

        // TODO CTOR creates references eagerly, so we have to subclass here
        @Override
        public boolean isSoft() {
            return false;
        }
    }.getPsiReferences();
}
Also used : Action(com.intellij.struts2.dom.struts.action.Action) StrutsManager(com.intellij.struts2.dom.struts.model.StrutsManager) StrutsModel(com.intellij.struts2.dom.struts.model.StrutsModel) BeanPropertyPathReferenceSet(com.intellij.struts2.reference.common.BeanPropertyPathReferenceSet) XmlTag(com.intellij.psi.xml.XmlTag) NotNull(org.jetbrains.annotations.NotNull)

Example 8 with Action

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

the class ActionReferenceProvider method getReferencesByElement.

@NotNull
public PsiReference[] getReferencesByElement(@NotNull final PsiElement psiElement, @NotNull final ProcessingContext context) {
    final StrutsManager strutsManager = StrutsManager.getInstance(psiElement.getProject());
    final StrutsModel strutsModel = strutsManager.getCombinedModel(psiElement);
    if (strutsModel == null) {
        return PsiReference.EMPTY_ARRAY;
    }
    final XmlAttributeValue xmlAttributeValue = (XmlAttributeValue) psiElement;
    final String path = xmlAttributeValue.getValue();
    // resolve to <action>
    final String actionName = TaglibUtil.trimActionPath(path);
    final String namespace = getNamespace(xmlAttributeValue);
    final List<Action> actions = strutsModel.findActionsByName(actionName, namespace);
    final Action action = actions.isEmpty() ? null : actions.get(0);
    final int bangIndex = path.indexOf(TaglibUtil.BANG_SYMBOL);
    if (bangIndex == -1) {
        return new PsiReference[] { new ActionReference(xmlAttributeValue, action, namespace, strutsModel) };
    }
    return new PsiReference[] { new ActionReference(xmlAttributeValue, action, namespace, strutsModel), new ActionMethodReference(xmlAttributeValue, action, bangIndex) };
}
Also used : Action(com.intellij.struts2.dom.struts.action.Action) StrutsManager(com.intellij.struts2.dom.struts.model.StrutsManager) StrutsModel(com.intellij.struts2.dom.struts.model.StrutsModel) PsiReference(com.intellij.psi.PsiReference) XmlAttributeValue(com.intellij.psi.xml.XmlAttributeValue) NotNull(org.jetbrains.annotations.NotNull)

Example 9 with Action

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

the class ExceptionMappingResultResolveConverter method getVariants.

@NotNull
public Collection<? extends HasResultType> getVariants(final ConvertContext context) {
    final DomElement invocationElement = context.getInvocationElement();
    final Action action = invocationElement.getParentOfType(Action.class, true);
    if (action == null) {
        return Collections.emptySet();
    }
    final List<HasResultType> variants = new ArrayList<>();
    // Action-local first
    variants.addAll(action.getResults());
    final StrutsPackage strutsPackage = action.getStrutsPackage();
    final GlobalResults globalResults = strutsPackage.getGlobalResults();
    variants.addAll(globalResults.getResults());
    return variants;
}
Also used : DomElement(com.intellij.util.xml.DomElement) HasResultType(com.intellij.struts2.dom.struts.HasResultType) GlobalResults(com.intellij.struts2.dom.struts.strutspackage.GlobalResults) ArrayList(java.util.ArrayList) StrutsPackage(com.intellij.struts2.dom.struts.strutspackage.StrutsPackage) NotNull(org.jetbrains.annotations.NotNull)

Example 10 with Action

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

Aggregations

Action (com.intellij.struts2.dom.struts.action.Action)15 StrutsModel (com.intellij.struts2.dom.struts.model.StrutsModel)10 Result (com.intellij.struts2.dom.struts.action.Result)8 NotNull (org.jetbrains.annotations.NotNull)8 PathReference (com.intellij.openapi.paths.PathReference)5 StrutsManager (com.intellij.struts2.dom.struts.model.StrutsManager)5 Module (com.intellij.openapi.module.Module)4 PsiElement (com.intellij.psi.PsiElement)4 PsiReference (com.intellij.psi.PsiReference)3 XmlFile (com.intellij.psi.xml.XmlFile)3 XmlTag (com.intellij.psi.xml.XmlTag)3 ArrayList (java.util.ArrayList)3 PsiElementBaseIntentionAction (com.intellij.codeInsight.intention.PsiElementBaseIntentionAction)2 WriteCommandAction (com.intellij.openapi.command.WriteCommandAction)2 HasResultType (com.intellij.struts2.dom.struts.HasResultType)2 ResultType (com.intellij.struts2.dom.struts.strutspackage.ResultType)2 StrutsPackage (com.intellij.struts2.dom.struts.strutspackage.StrutsPackage)2 DomElement (com.intellij.util.xml.DomElement)2 NonNls (org.jetbrains.annotations.NonNls)2 DomGotoRelatedItem (com.intellij.codeInsight.navigation.DomGotoRelatedItem)1