Search in sources :

Example 21 with StrutsModel

use of com.intellij.struts2.dom.struts.model.StrutsModel in project intellij-plugins by JetBrains.

the class IncludeFileResolvingConverterImpl method createReferences.

@NotNull
public PsiReference[] createReferences(@NotNull final GenericDomValue genericDomValue, @NotNull final PsiElement element, @NotNull final ConvertContext context) {
    final String s = genericDomValue.getStringValue();
    if (s == null) {
        return PsiReference.EMPTY_ARRAY;
    }
    final StrutsModel model = ConverterUtil.getStrutsModel(context);
    if (model == null) {
        return PsiReference.EMPTY_ARRAY;
    }
    final int offset = ElementManipulators.getOffsetInElement(element);
    return new FilePathReferenceProvider() {

        protected boolean isPsiElementAccepted(final PsiElement element) {
            return super.isPsiElementAccepted(element) && (!(element instanceof PsiFile) || isFileAccepted(model, (PsiFile) element));
        }
    }.getReferencesByElement(element, s, offset, true);
}
Also used : FilePathReferenceProvider(com.intellij.psi.impl.source.resolve.reference.impl.providers.FilePathReferenceProvider) StrutsModel(com.intellij.struts2.dom.struts.model.StrutsModel) PsiFile(com.intellij.psi.PsiFile) PsiElement(com.intellij.psi.PsiElement) NotNull(org.jetbrains.annotations.NotNull)

Example 22 with StrutsModel

use of com.intellij.struts2.dom.struts.model.StrutsModel in project intellij-plugins by JetBrains.

the class ActionChainOrRedirectResultContributor method createReferences.

public boolean createReferences(@NotNull final PsiElement psiElement, @NotNull final List<PsiReference> references, final boolean soft) {
    final StrutsModel model = StrutsManager.getInstance(psiElement.getProject()).getModelByFile((XmlFile) psiElement.getContainingFile());
    if (model == null) {
        return false;
    }
    final String currentPackage = getNamespace(psiElement);
    if (currentPackage == null) {
        return false;
    }
    final PsiReference chainReference = new ActionChainReference((XmlTag) psiElement, currentPackage, model);
    references.add(chainReference);
    return true;
}
Also used : StrutsModel(com.intellij.struts2.dom.struts.model.StrutsModel) PsiReference(com.intellij.psi.PsiReference)

Example 23 with StrutsModel

use of com.intellij.struts2.dom.struts.model.StrutsModel in project intellij-plugins by JetBrains.

the class StrutsModelFactory method computeAllModels.

protected List<StrutsModel> computeAllModels(@NotNull final Module module) {
    final PsiManager psiManager = PsiManager.getInstance(module.getProject());
    final StrutsManager strutsManager = StrutsManager.getInstance(module.getProject());
    final Set<StrutsFileSet> fileSets = strutsManager.getAllConfigFileSets(module);
    final List<StrutsModel> models = new ArrayList<>(fileSets.size());
    for (final StrutsFileSet set : fileSets) {
        if (set.isRemoved()) {
            continue;
        }
        final Set<XmlFile> files = new LinkedHashSet<>(set.getFiles().size());
        for (final VirtualFilePointer filePointer : set.getFiles()) {
            if (!filePointer.isValid())
                continue;
            final VirtualFile file = filePointer.getFile();
            if (file == null) {
                continue;
            }
            final PsiFile psiFile = psiManager.findFile(file);
            if (psiFile instanceof XmlFile) {
                final StrutsRoot strutsRootDom = getDom((XmlFile) psiFile);
                if (strutsRootDom != null) {
                    files.add((XmlFile) psiFile);
                // TODO           addIncludes(files, strutsRootDom);
                }
            }
        }
        if (!files.isEmpty()) {
            final DomFileElement<StrutsRoot> element = createMergedModelRoot(files);
            final StrutsModel model;
            if (element != null) {
                model = new StrutsModelImpl(element, files);
                models.add(model);
            }
        }
    }
    return models;
}
Also used : LinkedHashSet(java.util.LinkedHashSet) VirtualFile(com.intellij.openapi.vfs.VirtualFile) XmlFile(com.intellij.psi.xml.XmlFile) ArrayList(java.util.ArrayList) PsiManager(com.intellij.psi.PsiManager) StrutsFileSet(com.intellij.struts2.facet.ui.StrutsFileSet) VirtualFilePointer(com.intellij.openapi.vfs.pointers.VirtualFilePointer) PsiFile(com.intellij.psi.PsiFile) StrutsRoot(com.intellij.struts2.dom.struts.StrutsRoot)

Example 24 with StrutsModel

use of com.intellij.struts2.dom.struts.model.StrutsModel in project intellij-plugins by JetBrains.

the class ActionAnnotatorBase method collectNavigationMarkers.

@Override
protected void collectNavigationMarkers(@NotNull final PsiElement element, final Collection<? super RelatedItemLineMarkerInfo> lineMarkerInfos) {
    if (!(element instanceof PsiIdentifier))
        return;
    final PsiClass clazz = getActionPsiClass(element.getParent());
    if (clazz == null || clazz.getNameIdentifier() != element) {
        return;
    }
    // do not run on non-public, abstract classes or interfaces
    if (clazz.isInterface() || clazz.isAnnotationType() || !clazz.hasModifierProperty(PsiModifier.PUBLIC) || clazz.hasModifierProperty(PsiModifier.ABSTRACT)) {
        return;
    }
    // short exit if Struts Facet not present
    final Module module = ModuleUtilCore.findModuleForPsiElement(clazz);
    if (module == null || StrutsFacet.getInstance(module) == null) {
        return;
    }
    final StrutsManager strutsManager = StrutsManager.getInstance(element.getProject());
    final StrutsModel strutsModel = strutsManager.getCombinedModel(module);
    if (strutsModel == null) {
        return;
    }
    installValidationTargets(element, lineMarkerInfos, clazz);
    final List<Action> actions = strutsModel.findActionsByClass(clazz);
    if (actions.isEmpty()) {
        return;
    }
    installActionTargets(element, lineMarkerInfos, actions);
    installActionMethods(lineMarkerInfos, clazz, actions);
}
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) Module(com.intellij.openapi.module.Module)

Example 25 with StrutsModel

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

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