Search in sources :

Example 26 with StrutsModel

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

Aggregations

StrutsModel (com.intellij.struts2.dom.struts.model.StrutsModel)24 StrutsManager (com.intellij.struts2.dom.struts.model.StrutsManager)10 Action (com.intellij.struts2.dom.struts.action.Action)8 NotNull (org.jetbrains.annotations.NotNull)8 Module (com.intellij.openapi.module.Module)6 PsiElement (com.intellij.psi.PsiElement)6 PsiFile (com.intellij.psi.PsiFile)6 Nullable (org.jetbrains.annotations.Nullable)6 XmlFile (com.intellij.psi.xml.XmlFile)5 PathReference (com.intellij.openapi.paths.PathReference)4 PsiReference (com.intellij.psi.PsiReference)4 Result (com.intellij.struts2.dom.struts.action.Result)4 VirtualFile (com.intellij.openapi.vfs.VirtualFile)3 PsiClass (com.intellij.psi.PsiClass)3 StrutsRoot (com.intellij.struts2.dom.struts.StrutsRoot)3 ArrayList (java.util.ArrayList)3 NavigationItem (com.intellij.navigation.NavigationItem)2 ModuleUtilCore (com.intellij.openapi.module.ModuleUtilCore)2 PsiManager (com.intellij.psi.PsiManager)2 XmlTag (com.intellij.psi.xml.XmlTag)2