Search in sources :

Example 1 with ValidatorManager

use of com.intellij.struts2.dom.validator.ValidatorManager in project intellij-plugins by JetBrains.

the class ValidatorModelValidator method getFilesToProcess.

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

        protected Boolean create(final Module module) {
            return isEnabledForModule(module) && StrutsFacet.getInstance(module) != null;
        }
    };
    // collect all validation.xml files located in sources of S2-modules
    final Set<VirtualFile> files = new THashSet<>();
    for (final VirtualFile file : context.getProjectCompileScope().getFiles(StdFileTypes.XML, true)) {
        if (StringUtil.endsWith(file.getName(), FILENAME_EXTENSION_VALIDATION_XML)) {
            final PsiFile psiFile = psiManager.findFile(file);
            if (psiFile instanceof XmlFile && validatorManager.isValidatorsFile((XmlFile) psiFile)) {
                final Module module = ModuleUtilCore.findModuleForFile(file, project);
                if (module != null && enabledForModule.get(module)) {
                    files.add(file);
                }
            }
        }
    }
    // add validator-config.xml if not default one from xwork.jar
    final Set<VirtualFile> descriptorFiles = new THashSet<>();
    for (final Module module : ModuleManager.getInstance(project).getModules()) {
        if (enabledForModule.get(module)) {
            final PsiFile psiFile = validatorManager.getValidatorConfigFile(module);
            if (psiFile != null && validatorManager.isCustomValidatorConfigFile(psiFile)) {
                InspectionValidatorUtil.addFile(descriptorFiles, psiFile);
            }
        }
    }
    files.addAll(InspectionValidatorUtil.expandCompileScopeIfNeeded(descriptorFiles, context));
    return files;
}
Also used : FactoryMap(com.intellij.util.containers.FactoryMap) VirtualFile(com.intellij.openapi.vfs.VirtualFile) ValidatorManager(com.intellij.struts2.dom.validator.ValidatorManager) XmlFile(com.intellij.psi.xml.XmlFile) PsiManager(com.intellij.psi.PsiManager) PsiFile(com.intellij.psi.PsiFile) Module(com.intellij.openapi.module.Module) THashSet(gnu.trove.THashSet)

Example 2 with ValidatorManager

use of com.intellij.struts2.dom.validator.ValidatorManager in project intellij-plugins by JetBrains.

the class ValidatorConfigResolveConverterImpl method getVariants.

@NotNull
public Collection<? extends ValidatorConfig> getVariants(final ConvertContext context) {
    final Module module = context.getModule();
    if (module == null) {
        return Collections.emptyList();
    }
    final ValidatorManager validatorManager = ValidatorManager.getInstance(module.getProject());
    return validatorManager.getValidators(module);
}
Also used : ValidatorManager(com.intellij.struts2.dom.validator.ValidatorManager) Module(com.intellij.openapi.module.Module) NotNull(org.jetbrains.annotations.NotNull)

Aggregations

Module (com.intellij.openapi.module.Module)2 ValidatorManager (com.intellij.struts2.dom.validator.ValidatorManager)2 VirtualFile (com.intellij.openapi.vfs.VirtualFile)1 PsiFile (com.intellij.psi.PsiFile)1 PsiManager (com.intellij.psi.PsiManager)1 XmlFile (com.intellij.psi.xml.XmlFile)1 FactoryMap (com.intellij.util.containers.FactoryMap)1 THashSet (gnu.trove.THashSet)1 NotNull (org.jetbrains.annotations.NotNull)1