use of com.intellij.util.containers.FactoryMap 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;
}
use of com.intellij.util.containers.FactoryMap 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;
}
use of com.intellij.util.containers.FactoryMap in project intellij-community by JetBrains.
the class DependencyInspectionBase method checkFile.
@Override
@Nullable
public ProblemDescriptor[] checkFile(@NotNull final PsiFile file, @NotNull final InspectionManager manager, final boolean isOnTheFly) {
if (file.getViewProvider().getPsi(JavaLanguage.INSTANCE) == null) {
return null;
}
final DependencyValidationManager validationManager = DependencyValidationManager.getInstance(file.getProject());
if (!validationManager.hasRules() || validationManager.getApplicableRules(file).length == 0) {
return null;
}
final List<ProblemDescriptor> problems = ContainerUtil.newSmartList();
DependenciesBuilder.analyzeFileDependencies(file, new DependenciesBuilder.DependencyProcessor() {
@SuppressWarnings("MismatchedQueryAndUpdateOfCollection")
private final Map<PsiFile, DependencyRule[]> violations = new FactoryMap<PsiFile, DependencyRule[]>() {
@Nullable
@Override
protected DependencyRule[] create(PsiFile dependencyFile) {
return validationManager.getViolatorDependencyRules(file, dependencyFile);
}
};
@Override
public void process(PsiElement place, PsiElement dependency) {
PsiFile dependencyFile = dependency.getContainingFile();
if (dependencyFile != null && dependencyFile.isPhysical() && dependencyFile.getVirtualFile() != null) {
for (DependencyRule dependencyRule : violations.get(dependencyFile)) {
String message = InspectionsBundle.message("inspection.dependency.violator.problem.descriptor", dependencyRule.getDisplayText());
LocalQuickFix[] fixes = createEditDependencyFixes(dependencyRule);
problems.add(manager.createProblemDescriptor(place, message, isOnTheFly, fixes, ProblemHighlightType.GENERIC_ERROR_OR_WARNING));
}
}
}
});
return problems.isEmpty() ? null : problems.toArray(new ProblemDescriptor[problems.size()]);
}
use of com.intellij.util.containers.FactoryMap in project intellij-community by JetBrains.
the class DeleteUtil method generateWarningMessage.
public static String generateWarningMessage(String messageTemplate, final PsiElement[] elements) {
if (elements.length == 1) {
String name = ElementDescriptionUtil.getElementDescription(elements[0], DeleteNameDescriptionLocation.INSTANCE);
String type = ElementDescriptionUtil.getElementDescription(elements[0], DeleteTypeDescriptionLocation.SINGULAR);
return MessageFormat.format(messageTemplate, type + " \"" + name + "\"");
}
FactoryMap<String, Integer> countMap = new FactoryMap<String, Integer>() {
@Override
protected Integer create(final String key) {
return 0;
}
};
Map<String, String> pluralToSingular = new HashMap<>();
int directoryCount = 0;
String containerType = null;
for (final PsiElement elementToDelete : elements) {
String type = ElementDescriptionUtil.getElementDescription(elementToDelete, DeleteTypeDescriptionLocation.PLURAL);
pluralToSingular.put(type, ElementDescriptionUtil.getElementDescription(elementToDelete, DeleteTypeDescriptionLocation.SINGULAR));
int oldCount = countMap.get(type).intValue();
countMap.put(type, oldCount + 1);
if (elementToDelete instanceof PsiDirectoryContainer) {
containerType = type;
directoryCount += ((PsiDirectoryContainer) elementToDelete).getDirectories().length;
}
}
StringBuilder buffer = new StringBuilder();
for (Map.Entry<String, Integer> entry : countMap.entrySet()) {
if (buffer.length() > 0) {
if (buffer.length() > 0) {
buffer.append(" ").append(IdeBundle.message("prompt.delete.and")).append(" ");
}
}
final int count = entry.getValue().intValue();
buffer.append(count).append(" ");
if (count == 1) {
buffer.append(pluralToSingular.get(entry.getKey()));
} else {
buffer.append(entry.getKey());
}
if (entry.getKey().equals(containerType)) {
buffer.append(" ").append(IdeBundle.message("prompt.delete.directory.paren", directoryCount));
}
}
return MessageFormat.format(messageTemplate, buffer.toString());
}
use of com.intellij.util.containers.FactoryMap in project intellij-plugins by JetBrains.
the class FlexTestUtils method createConfigEditor.
public static FlexProjectConfigurationEditor createConfigEditor(final Module... modules) {
@SuppressWarnings("MismatchedQueryAndUpdateOfCollection") final Map<Module, ModifiableRootModel> models = new FactoryMap<Module, ModifiableRootModel>() {
@Override
protected ModifiableRootModel create(final Module module) {
final ModifiableRootModel result = ModuleRootManager.getInstance(module).getModifiableModel();
Disposer.register(module, new Disposable() {
@Override
public void dispose() {
if (!result.isDisposed()) {
result.dispose();
}
}
});
return result;
}
};
return new FlexProjectConfigurationEditor(modules[0].getProject(), new FlexProjectConfigurationEditor.ProjectModifiableModelProvider() {
@Override
public Module[] getModules() {
return modules;
}
@Override
public ModifiableRootModel getModuleModifiableModel(Module module) {
return models.get(module);
}
@Override
public void addListener(FlexBCConfigurator.Listener listener, Disposable parentDisposable) {
// ignore
}
@Override
public void commitModifiableModels() throws ConfigurationException {
ApplicationManager.getApplication().runWriteAction(() -> {
for (ModifiableRootModel model : models.values()) {
if (model.isChanged()) {
model.commit();
}
}
});
}
public Library findSourceLibraryForLiveName(final String name, final String level) {
return findSourceLibrary(name, level);
}
public Library findSourceLibrary(final String name, final String level) {
return getLibrariesTable(level).getLibraryByName(name);
}
private LibraryTable getLibrariesTable(final String level) {
if (LibraryTablesRegistrar.APPLICATION_LEVEL.equals(level)) {
return ApplicationLibraryTable.getApplicationTable();
} else {
assert LibraryTablesRegistrar.PROJECT_LEVEL.equals(level);
return ProjectLibraryTable.getInstance(modules[0].getProject());
}
}
});
}
Aggregations