Search in sources :

Example 1 with StrutsManager

use of com.intellij.struts2.dom.struts.model.StrutsManager 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 2 with StrutsManager

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

Example 3 with StrutsManager

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

the class StrutsJamUtils method getStrutsModel.

/**
   * Gets the model for the given attribute element.
   *
   * @param attributeElement Attribute element.
   * @return {@code null} if no StrutsModel could be determined.
   */
@Nullable
public static StrutsModel getStrutsModel(final JamAttributeElement attributeElement) {
    final PsiElement value = attributeElement.getPsiElement();
    if (value == null) {
        return null;
    }
    final StrutsManager instance = StrutsManager.getInstance(value.getProject());
    return instance.getCombinedModel(value);
}
Also used : StrutsManager(com.intellij.struts2.dom.struts.model.StrutsManager) PsiElement(com.intellij.psi.PsiElement) Nullable(org.jetbrains.annotations.Nullable)

Example 4 with StrutsManager

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

the class StrutsFileSetCheckingAnnotator method annotate.

public void annotate(@NotNull final PsiElement psiElement, @NotNull final AnnotationHolder holder) {
    if (!(psiElement instanceof XmlFile)) {
        return;
    }
    if (psiElement instanceof JspFile) {
        return;
    }
    final Module module = ModuleUtilCore.findModuleForPsiElement(psiElement);
    if (module == null) {
        return;
    }
    // do not run when facet not enabled
    if (StrutsFacet.getInstance(module) == null) {
        return;
    }
    final XmlFile xmlFile = (XmlFile) psiElement;
    final Project project = psiElement.getProject();
    final StrutsManager strutsManager = StrutsManager.getInstance(project);
    if (!strutsManager.isStruts2ConfigFile(xmlFile)) {
        return;
    }
    final VirtualFile currentVirtualFile = xmlFile.getVirtualFile();
    assert currentVirtualFile != null;
    final Set<StrutsFileSet> allConfigFileSets = strutsManager.getAllConfigFileSets(module);
    for (final StrutsFileSet configFileSet : allConfigFileSets) {
        if (configFileSet.hasFile(currentVirtualFile)) {
            return;
        }
    }
    final boolean fileSetAvailable = allConfigFileSets.size() != 0;
    final Annotation annotation = holder.createWarningAnnotation(xmlFile, fileSetAvailable ? StrutsBundle.message("annotators.fileset.file.not.registered") : StrutsBundle.message("annotators.fileset.no.file.sets"));
    annotation.setFileLevelAnnotation(true);
    if (fileSetAvailable) {
        final AddToFileSetFix addToFileSetFix = new AddToFileSetFix(xmlFile.getName());
        annotation.registerFix(addToFileSetFix);
    } else {
        annotation.registerFix(new IntentionAction() {

            @SuppressWarnings("DialogTitleCapitalization")
            @NotNull
            public String getText() {
                return StrutsBundle.message("annotators.fileset.edit.facet.settings");
            }

            @NotNull
            public String getFamilyName() {
                return StrutsBundle.message("intentions.family.name");
            }

            public boolean isAvailable(@NotNull final Project project, final Editor editor, final PsiFile psiFile) {
                return true;
            }

            public void invoke(@NotNull final Project project, final Editor editor, final PsiFile psiFile) throws IncorrectOperationException {
                final StrutsFacet strutsFacet = StrutsFacet.getInstance(module);
                assert strutsFacet != null;
                ModulesConfigurator.showFacetSettingsDialog(strutsFacet, null);
            }

            public boolean startInWriteAction() {
                return false;
            }
        });
    }
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) XmlFile(com.intellij.psi.xml.XmlFile) StrutsManager(com.intellij.struts2.dom.struts.model.StrutsManager) NotNull(org.jetbrains.annotations.NotNull) StrutsFileSet(com.intellij.struts2.facet.ui.StrutsFileSet) Annotation(com.intellij.lang.annotation.Annotation) Project(com.intellij.openapi.project.Project) JspFile(com.intellij.psi.jsp.JspFile) BaseIntentionAction(com.intellij.codeInsight.intention.impl.BaseIntentionAction) IntentionAction(com.intellij.codeInsight.intention.IntentionAction) PsiFile(com.intellij.psi.PsiFile) IncorrectOperationException(com.intellij.util.IncorrectOperationException) Module(com.intellij.openapi.module.Module) Editor(com.intellij.openapi.editor.Editor) StrutsFacet(com.intellij.struts2.facet.StrutsFacet)

Example 5 with StrutsManager

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

Aggregations

StrutsManager (com.intellij.struts2.dom.struts.model.StrutsManager)10 StrutsModel (com.intellij.struts2.dom.struts.model.StrutsModel)7 PsiFile (com.intellij.psi.PsiFile)5 XmlFile (com.intellij.psi.xml.XmlFile)5 NotNull (org.jetbrains.annotations.NotNull)5 Module (com.intellij.openapi.module.Module)4 Action (com.intellij.struts2.dom.struts.action.Action)4 VirtualFile (com.intellij.openapi.vfs.VirtualFile)3 PsiElement (com.intellij.psi.PsiElement)2 PsiManager (com.intellij.psi.PsiManager)2 StrutsFileSet (com.intellij.struts2.facet.ui.StrutsFileSet)2 Nullable (org.jetbrains.annotations.Nullable)2 IntentionAction (com.intellij.codeInsight.intention.IntentionAction)1 BaseIntentionAction (com.intellij.codeInsight.intention.impl.BaseIntentionAction)1 DomGotoRelatedItem (com.intellij.codeInsight.navigation.DomGotoRelatedItem)1 Annotation (com.intellij.lang.annotation.Annotation)1 GotoRelatedItem (com.intellij.navigation.GotoRelatedItem)1 Editor (com.intellij.openapi.editor.Editor)1 PathReference (com.intellij.openapi.paths.PathReference)1 Project (com.intellij.openapi.project.Project)1