Search in sources :

Example 6 with StrutsModel

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

the class Struts2ModelValidator method getFilesToProcess.

public Collection<VirtualFile> getFilesToProcess(final Project project, final CompileContext context) {
    final StrutsManager strutsManager = StrutsManager.getInstance(project);
    final PsiManager psiManager = PsiManager.getInstance(project);
    // cache validation settings per module
    @SuppressWarnings("MismatchedQueryAndUpdateOfCollection") final FactoryMap<Module, Boolean> enabledForModule = new FactoryMap<Module, Boolean>() {

        protected Boolean create(final Module module) {
            return isEnabledForModule(module);
        }
    };
    final Set<VirtualFile> files = new THashSet<>();
    for (final VirtualFile file : context.getCompileScope().getFiles(StdFileTypes.XML, false)) {
        final Module module = context.getModuleByFile(file);
        if (module != null && enabledForModule.get(module)) {
            final PsiFile psiFile = psiManager.findFile(file);
            if (psiFile instanceof XmlFile) {
                final StrutsModel model = strutsManager.getModelByFile((XmlFile) psiFile);
                if (model != null) {
                    for (final XmlFile configFile : model.getConfigFiles()) {
                        ContainerUtil.addIfNotNull(files, configFile.getVirtualFile());
                    }
                }
            }
        }
    }
    InspectionValidatorUtil.expandCompileScopeIfNeeded(files, context);
    return files;
}
Also used : FactoryMap(com.intellij.util.containers.FactoryMap) VirtualFile(com.intellij.openapi.vfs.VirtualFile) XmlFile(com.intellij.psi.xml.XmlFile) StrutsManager(com.intellij.struts2.dom.struts.model.StrutsManager) PsiManager(com.intellij.psi.PsiManager) THashSet(gnu.trove.THashSet) StrutsModel(com.intellij.struts2.dom.struts.model.StrutsModel) PsiFile(com.intellij.psi.PsiFile) Module(com.intellij.openapi.module.Module)

Example 7 with StrutsModel

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

the class ActionPathResultContributor 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 TextRange rangeInElement = ElementManipulators.getManipulator(psiElement).getRangeInElement(psiElement);
    final String fullPath = psiElement.getText();
    final String trimmedPath = rangeInElement.substring(fullPath);
    final TextRange trimmedPathRange = TextRange.from(rangeInElement.getStartOffset(), PathReference.trimPath(trimmedPath).length());
    final PsiReference actionReference = new ActionPathReference((XmlTag) psiElement, trimmedPathRange, currentPackage, model);
    references.add(actionReference);
    return false;
}
Also used : StrutsModel(com.intellij.struts2.dom.struts.model.StrutsModel) PsiReference(com.intellij.psi.PsiReference) TextRange(com.intellij.openapi.util.TextRange)

Example 8 with StrutsModel

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

the class StrutsPackageExtendsResolveConverterImpl method getReferenceVariants.

@Override
protected Object[] getReferenceVariants(ConvertContext context, GenericDomValue<List<StrutsPackage>> genericDomValue) {
    final StrutsModel strutsModel = ConverterUtil.getStrutsModel(context);
    if (strutsModel == null) {
        return ArrayUtil.EMPTY_OBJECT_ARRAY;
    }
    final Collection<StrutsPackage> variants = removeCurrentElementFromVariants(context, strutsModel.getStrutsPackages());
    return ElementPresentationManager.getInstance().createVariants(variants);
}
Also used : StrutsModel(com.intellij.struts2.dom.struts.model.StrutsModel) StrutsPackage(com.intellij.struts2.dom.struts.strutspackage.StrutsPackage)

Example 9 with StrutsModel

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

the class ActionLinkReferenceProvider method createReferences.

protected PsiReference[] createReferences(@NotNull final PsiElement psiElement, final int offset, final String text, @Nullable final ServletMappingInfo info, final boolean soft) {
    final StrutsModel strutsModel = StrutsManager.getInstance(psiElement.getProject()).getCombinedModel(psiElement);
    if (strutsModel == null) {
        return PsiReference.EMPTY_ARRAY;
    }
    final List<String> actionExtensions = StrutsConstantHelper.getActionExtensions(psiElement);
    if (actionExtensions.isEmpty()) {
        return PsiReference.EMPTY_ARRAY;
    }
    if (text.indexOf('/') != -1) {
        return new PsiReference[] { new ActionLinkPackageReference(psiElement, offset, text, soft, strutsModel), new ActionLinkReference(psiElement, offset, text, soft, strutsModel, actionExtensions) };
    } else {
        return new PsiReference[] { new ActionLinkReference(psiElement, offset, text, soft, strutsModel, actionExtensions) };
    }
}
Also used : StrutsModel(com.intellij.struts2.dom.struts.model.StrutsModel) PsiReference(com.intellij.psi.PsiReference)

Example 10 with StrutsModel

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

the class NamespaceReferenceProvider 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;
    }
    return new PsiReference[] { new NamespaceReference((XmlAttributeValue) psiElement, strutsModel) };
}
Also used : StrutsManager(com.intellij.struts2.dom.struts.model.StrutsManager) StrutsModel(com.intellij.struts2.dom.struts.model.StrutsModel) 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