use of com.intellij.util.containers.FactoryMap in project intellij-community by JetBrains.
the class InconsistentResourceBundleInspection method checkFile.
@Override
public void checkFile(@NotNull PsiFile file, @NotNull InspectionManager manager, @NotNull ProblemsHolder problemsHolder, @NotNull GlobalInspectionContext globalContext, @NotNull ProblemDescriptionsProcessor problemDescriptionsProcessor) {
Set<ResourceBundle> visitedBundles = globalContext.getUserData(VISITED_BUNDLES_KEY);
if (!(file instanceof PropertiesFile))
return;
final PropertiesFile propertiesFile = (PropertiesFile) file;
ResourceBundle resourceBundle = propertiesFile.getResourceBundle();
assert visitedBundles != null;
if (!visitedBundles.add(resourceBundle))
return;
List<PropertiesFile> files = resourceBundle.getPropertiesFiles();
if (files.size() < 2)
return;
BidirectionalMap<PropertiesFile, PropertiesFile> parents = new BidirectionalMap<>();
for (PropertiesFile f : files) {
PropertiesFile parent = PropertiesUtil.getParent(f, files);
if (parent != null) {
parents.put(f, parent);
}
}
final FactoryMap<PropertiesFile, Map<String, String>> propertiesFilesNamesMaps = new FactoryMap<PropertiesFile, Map<String, String>>() {
@Nullable
@Override
protected Map<String, String> create(PropertiesFile key) {
return key.getNamesMap();
}
};
Map<PropertiesFile, Set<String>> keysUpToParent = new THashMap<>();
for (PropertiesFile f : files) {
Set<String> keys = new THashSet<>(propertiesFilesNamesMaps.get(f).keySet());
PropertiesFile parent = parents.get(f);
while (parent != null) {
keys.addAll(propertiesFilesNamesMaps.get(parent).keySet());
parent = parents.get(parent);
}
keysUpToParent.put(f, keys);
}
for (final InconsistentResourceBundleInspectionProvider provider : myInspectionProviders.getValue()) {
if (isProviderEnabled(provider.getName())) {
provider.check(parents, files, keysUpToParent, propertiesFilesNamesMaps, manager, globalContext.getRefManager(), problemDescriptionsProcessor);
}
}
}
use of com.intellij.util.containers.FactoryMap in project intellij-community by JetBrains.
the class ExternalSystemTaskActivator method runTasks.
public boolean runTasks(@NotNull Collection<String> modules, @NotNull Phase... phases) {
final ExternalProjectsStateProvider stateProvider = ExternalProjectsManager.getInstance(myProject).getStateProvider();
final Queue<Pair<ProjectSystemId, ExternalSystemTaskExecutionSettings>> tasksQueue = new LinkedList<>();
//noinspection MismatchedQueryAndUpdateOfCollection
Map<ProjectSystemId, Map<String, RunnerAndConfigurationSettings>> lazyConfigurationsMap = new FactoryMap<ProjectSystemId, Map<String, RunnerAndConfigurationSettings>>() {
@Nullable
@Override
protected Map<String, RunnerAndConfigurationSettings> create(ProjectSystemId key) {
final AbstractExternalSystemTaskConfigurationType configurationType = ExternalSystemUtil.findConfigurationType(key);
if (configurationType == null)
return null;
return ContainerUtil.map2Map(RunManager.getInstance(myProject).getConfigurationSettingsList(configurationType), configurationSettings -> Pair.create(configurationSettings.getName(), configurationSettings));
}
};
for (final ExternalProjectsStateProvider.TasksActivation activation : stateProvider.getAllTasksActivation()) {
final boolean hashPath = modules.contains(activation.projectPath);
final Set<String> tasks = ContainerUtil.newLinkedHashSet();
for (Phase phase : phases) {
List<String> activationTasks = activation.state.getTasks(phase);
if (hashPath || (phase.isSyncPhase() && !activationTasks.isEmpty() && isShareSameRootPath(modules, activation))) {
ContainerUtil.addAll(tasks, activationTasks);
}
}
if (tasks.isEmpty())
continue;
for (Iterator<String> iterator = tasks.iterator(); iterator.hasNext(); ) {
String task = iterator.next();
if (task.length() > RUN_CONFIGURATION_TASK_PREFIX.length() && task.startsWith(RUN_CONFIGURATION_TASK_PREFIX)) {
iterator.remove();
final String configurationName = task.substring(RUN_CONFIGURATION_TASK_PREFIX.length());
Map<String, RunnerAndConfigurationSettings> settings = lazyConfigurationsMap.get(activation.systemId);
if (settings == null)
continue;
RunnerAndConfigurationSettings configurationSettings = settings.get(configurationName);
if (configurationSettings == null)
continue;
final RunConfiguration runConfiguration = configurationSettings.getConfiguration();
if (configurationName.equals(configurationSettings.getName()) && runConfiguration instanceof ExternalSystemRunConfiguration) {
tasksQueue.add(Pair.create(activation.systemId, ((ExternalSystemRunConfiguration) runConfiguration).getSettings()));
}
}
}
if (tasks.isEmpty())
continue;
if (ExternalProjectsManager.getInstance(myProject).isIgnored(activation.systemId, activation.projectPath))
continue;
ExternalSystemTaskExecutionSettings executionSettings = new ExternalSystemTaskExecutionSettings();
executionSettings.setExternalSystemIdString(activation.systemId.toString());
executionSettings.setExternalProjectPath(activation.projectPath);
executionSettings.getTaskNames().addAll(tasks);
tasksQueue.add(Pair.create(activation.systemId, executionSettings));
}
return runTasksQueue(tasksQueue);
}
use of com.intellij.util.containers.FactoryMap in project intellij-community by JetBrains.
the class KeymapsTestCase method testValidActionIds.
public void testValidActionIds() {
THashSet<String> unknownActions = new THashSet<>();
collectUnknownActions(unknownActions);
@SuppressWarnings("MismatchedQueryAndUpdateOfCollection") Map<String, List<String>> missingActions = new FactoryMap<String, List<String>>() {
@Override
protected Map<String, List<String>> createMap() {
return new LinkedHashMap<>();
}
@Nullable
@Override
protected List<String> create(String key) {
return new ArrayList<>();
}
};
for (Keymap keymap : KeymapManagerEx.getInstanceEx().getAllKeymaps()) {
List<String> ids = new ArrayList<>(keymap.getActionIdList());
ids.sort(null);
assertThat(ids).isEqualTo(new ArrayList<>(new LinkedHashSet<>(ids)));
for (String cid : ids) {
if (unknownActions.contains(cid))
continue;
AnAction action = ActionManager.getInstance().getAction(cid);
if (action == null) {
if (OUTPUT_TEST_DATA) {
System.out.print("\"" + cid + "\", ");
} else {
missingActions.get(keymap.getName()).add(cid);
}
}
}
}
List<String> reappearedAction = new ArrayList<>();
for (String id : unknownActions) {
AnAction action = ActionManager.getInstance().getAction(id);
if (action != null) {
reappearedAction.add(id);
}
}
if (!missingActions.isEmpty() || !reappearedAction.isEmpty()) {
StringBuilder message = new StringBuilder();
if (!missingActions.isEmpty()) {
for (Map.Entry<String, List<String>> keymapAndActions : missingActions.entrySet()) {
message.append("Unknown actions in keymap ").append(keymapAndActions.getKey()).append(", add them to unknown actions list:\n");
for (String action : keymapAndActions.getValue()) {
message.append("\"").append(action).append("\",").append("\n");
}
}
}
if (!reappearedAction.isEmpty()) {
message.append("The following actions have reappeared, remove them from unknown action list:\n");
for (String action : reappearedAction) {
message.append(action).append("\n");
}
}
fail("\n" + message);
}
}
use of com.intellij.util.containers.FactoryMap in project intellij-community by JetBrains.
the class KeymapsTestCase method testIdsListIsConsistent.
@SuppressWarnings({ "HardCodedStringLiteral" })
public void testIdsListIsConsistent() {
Map<String, Map<String, List<String>>> duplicates = getKnownDuplicates();
Set<String> allMaps = new THashSet<>(ContainerUtil.map(KeymapManagerEx.getInstanceEx().getAllKeymaps(), keymap -> keymap.getName()));
assertThat(ContainerUtil.subtract(allMaps, duplicates.keySet())).overridingErrorMessage("Modify 'known duplicates list' test data. Keymaps were added: %s", ContainerUtil.subtract(allMaps, duplicates.keySet())).isEmpty();
assertThat(ContainerUtil.subtract(duplicates.keySet(), allMaps)).overridingErrorMessage("Modify 'known duplicates list' test data. Keymaps were removed: %s", ContainerUtil.subtract(duplicates.keySet(), allMaps)).isEmpty();
@SuppressWarnings("MismatchedQueryAndUpdateOfCollection") Map<Keymap, List<Shortcut>> reassignedShortcuts = new FactoryMap<Keymap, List<Shortcut>>() {
@Override
protected Map<Keymap, List<Shortcut>> createMap() {
return new LinkedHashMap<>();
}
@Nullable
@Override
protected List<Shortcut> create(Keymap key) {
return new ArrayList<>();
}
};
for (String name : duplicates.keySet()) {
Keymap keymap = KeymapManagerEx.getInstanceEx().getKeymap(name);
assertThat(keymap).overridingErrorMessage("KeyMap %s not found", name).isNotNull();
Map<String, List<String>> duplicateIdsList = duplicates.get(name);
Set<String> mentionedShortcuts = new THashSet<>();
for (Map.Entry<String, List<String>> shortcutMappings : duplicateIdsList.entrySet()) {
String shortcutString = shortcutMappings.getKey();
if (!mentionedShortcuts.add(shortcutString)) {
TestCase.fail("Shortcut '" + shortcutString + "' duplicate in keymap '" + keymap + "'. Please modify 'known duplicates list'");
}
Shortcut shortcut = parse(shortcutString);
String[] ids = keymap.getActionIds(shortcut);
Set<String> actualSc = new HashSet<>(Arrays.asList(ids));
removeBoundActionIds(actualSc);
Set<String> expectedSc = new HashSet<>(shortcutMappings.getValue());
for (String s : actualSc) {
if (!expectedSc.contains(s)) {
reassignedShortcuts.get(keymap).add(shortcut);
}
}
for (String s : expectedSc) {
if (!actualSc.contains(s)) {
System.out.println("Expected action '" + s + "' does not reassign shortcut " + getText(shortcut) + " in keymap " + keymap + " or is not registered");
}
}
}
}
if (!reassignedShortcuts.isEmpty()) {
StringBuilder message = new StringBuilder();
for (Map.Entry<Keymap, List<Shortcut>> keymapToShortcuts : reassignedShortcuts.entrySet()) {
Keymap keymap = keymapToShortcuts.getKey();
message.append("The following shortcuts was reassigned in keymap ").append(keymap.getName()).append(". Please modify known duplicates list:\n");
for (Shortcut eachShortcut : keymapToShortcuts.getValue()) {
message.append(" { ").append(StringUtil.wrapWithDoubleQuote(getText(eachShortcut))).append(",\t").append(StringUtil.join(keymap.getActionIds(eachShortcut), s -> StringUtil.wrapWithDoubleQuote(s), ", ")).append("},\n");
}
}
TestCase.fail("\n" + message.toString());
}
}
use of com.intellij.util.containers.FactoryMap in project intellij-community by JetBrains.
the class GradleResourceCompilerConfigurationGenerator method generateAffectedGradleModulesConfiguration.
@NotNull
private Map<String, GradleModuleResourceConfiguration> generateAffectedGradleModulesConfiguration(@NotNull CompileContext context) {
final Map<String, GradleModuleResourceConfiguration> affectedGradleModuleConfigurations = ContainerUtil.newTroveMap();
//noinspection MismatchedQueryAndUpdateOfCollection
final Map<String, ExternalProject> lazyExternalProjectMap = new FactoryMap<String, ExternalProject>() {
@Nullable
@Override
protected ExternalProject create(String gradleProjectPath) {
return externalProjectDataCache.getRootExternalProject(GradleConstants.SYSTEM_ID, new File(gradleProjectPath));
}
};
for (Module module : context.getCompileScope().getAffectedModules()) {
if (!ExternalSystemApiUtil.isExternalSystemAwareModule(GradleConstants.SYSTEM_ID, module))
continue;
final String gradleProjectPath = ExternalSystemApiUtil.getExternalRootProjectPath(module);
assert gradleProjectPath != null;
if (shouldBeBuiltByExternalSystem(module))
continue;
final ExternalProject externalRootProject = lazyExternalProjectMap.get(gradleProjectPath);
if (externalRootProject == null) {
context.addMessage(CompilerMessageCategory.ERROR, String.format("Unable to make the module: %s, related gradle configuration was not found. " + "Please, re-import the Gradle project and try again.", module.getName()), VfsUtilCore.pathToUrl(gradleProjectPath), -1, -1);
continue;
}
Map<String, ExternalSourceSet> externalSourceSets = externalProjectDataCache.findExternalProject(externalRootProject, module);
if (externalSourceSets.isEmpty()) {
LOG.debug("Unable to find source sets config for module: " + module.getName());
continue;
}
GradleModuleResourceConfiguration resourceConfig = new GradleModuleResourceConfiguration();
resourceConfig.id = new ModuleVersion(ExternalSystemApiUtil.getExternalProjectGroup(module), ExternalSystemApiUtil.getExternalProjectId(module), ExternalSystemApiUtil.getExternalProjectVersion(module));
for (ExternalSourceSet sourceSet : externalSourceSets.values()) {
addResources(resourceConfig.resources, sourceSet.getSources().get(ExternalSystemSourceType.RESOURCE), sourceSet.getSources().get(ExternalSystemSourceType.SOURCE));
addResources(resourceConfig.testResources, sourceSet.getSources().get(ExternalSystemSourceType.TEST_RESOURCE), sourceSet.getSources().get(ExternalSystemSourceType.TEST));
}
final CompilerModuleExtension compilerModuleExtension = CompilerModuleExtension.getInstance(module);
if (compilerModuleExtension != null && compilerModuleExtension.isCompilerOutputPathInherited()) {
String outputPath = VfsUtilCore.urlToPath(compilerModuleExtension.getCompilerOutputUrl());
for (ResourceRootConfiguration resource : resourceConfig.resources) {
resource.targetPath = outputPath;
}
String testOutputPath = VfsUtilCore.urlToPath(compilerModuleExtension.getCompilerOutputUrlForTests());
for (ResourceRootConfiguration resource : resourceConfig.testResources) {
resource.targetPath = testOutputPath;
}
}
affectedGradleModuleConfigurations.put(module.getName(), resourceConfig);
}
return affectedGradleModuleConfigurations;
}
Aggregations