use of com.intellij.util.containers.hash.HashMap in project intellij-community by JetBrains.
the class ChangeSignatureProcessorBase method filterUsages.
protected static List<UsageInfo> filterUsages(List<UsageInfo> infos) {
Map<PsiElement, MoveRenameUsageInfo> moveRenameInfos = new HashMap<>();
Set<PsiElement> usedElements = new HashSet<>();
List<UsageInfo> result = new ArrayList<>(infos.size() / 2);
for (UsageInfo info : infos) {
LOG.assertTrue(info != null);
PsiElement element = info.getElement();
if (info instanceof MoveRenameUsageInfo) {
if (usedElements.contains(element))
continue;
moveRenameInfos.put(element, (MoveRenameUsageInfo) info);
} else {
moveRenameInfos.remove(element);
usedElements.add(element);
if (!(info instanceof PossiblyIncorrectUsage) || ((PossiblyIncorrectUsage) info).isCorrect()) {
result.add(info);
}
}
}
result.addAll(moveRenameInfos.values());
return result;
}
use of com.intellij.util.containers.hash.HashMap in project intellij-community by JetBrains.
the class VcsDiffUtil method showDiffFor.
@CalledInAwt
public static void showDiffFor(@NotNull Project project, @NotNull final Collection<Change> changes, @NotNull final String revNumTitle1, @NotNull final String revNumTitle2, @NotNull final FilePath filePath) {
if (filePath.isDirectory()) {
showChangesDialog(project, getDialogTitle(filePath, revNumTitle1, revNumTitle2), ContainerUtil.newArrayList(changes));
} else {
if (changes.isEmpty()) {
DiffManager.getInstance().showDiff(project, new MessageDiffRequest("No Changes Found"));
} else {
final HashMap<Key, Object> revTitlesMap = new HashMap<>(2);
revTitlesMap.put(VCS_DIFF_LEFT_CONTENT_TITLE, revNumTitle1);
revTitlesMap.put(VCS_DIFF_RIGHT_CONTENT_TITLE, revNumTitle2);
ShowDiffContext showDiffContext = new ShowDiffContext() {
@NotNull
@Override
public Map<Key, Object> getChangeContext(@NotNull Change change) {
return revTitlesMap;
}
};
ShowDiffAction.showDiffForChange(project, changes, 0, showDiffContext);
}
}
}
use of com.intellij.util.containers.hash.HashMap in project intellij-community by JetBrains.
the class DarculaLaf method loadDefaults.
@SuppressWarnings("IOResourceOpenedButNotSafelyClosed")
protected void loadDefaults(UIDefaults defaults) {
final Properties properties = new Properties();
final String osSuffix = SystemInfo.isMac ? "mac" : SystemInfo.isWindows ? "windows" : "linux";
try {
InputStream stream = getClass().getResourceAsStream(getPrefix() + ".properties");
properties.load(stream);
stream.close();
stream = getClass().getResourceAsStream(getPrefix() + "_" + osSuffix + ".properties");
properties.load(stream);
stream.close();
HashMap<String, Object> darculaGlobalSettings = new HashMap<>();
final String prefix = getPrefix() + ".";
for (String key : properties.stringPropertyNames()) {
if (key.startsWith(prefix)) {
Object value = parseValue(key, properties.getProperty(key));
String darculaKey = key.substring(prefix.length());
if (value == SYSTEM) {
darculaGlobalSettings.remove(darculaKey);
} else {
darculaGlobalSettings.put(darculaKey, value);
}
}
}
for (Object key : defaults.keySet()) {
if (key instanceof String && ((String) key).contains(".")) {
final String s = (String) key;
final String darculaKey = s.substring(s.lastIndexOf('.') + 1);
if (darculaGlobalSettings.containsKey(darculaKey)) {
defaults.put(key, darculaGlobalSettings.get(darculaKey));
}
}
}
for (String key : properties.stringPropertyNames()) {
final String value = properties.getProperty(key);
defaults.put(key, parseValue(key, value));
}
} catch (IOException e) {
log(e);
}
}
use of com.intellij.util.containers.hash.HashMap in project intellij-community by JetBrains.
the class FoldingAnchorsOverlayStrategy method getAnchorsToDisplay.
@NotNull
Collection<DisplayedFoldingAnchor> getAnchorsToDisplay(int firstVisibleOffset, int lastVisibleOffset, FoldRegion activeFoldRegion) {
Map<Integer, DisplayedFoldingAnchor> result = new HashMap<>();
FoldRegion[] visibleFoldRegions = myEditor.getFoldingModel().fetchVisible();
for (FoldRegion region : visibleFoldRegions) {
if (!region.isValid())
continue;
final int startOffset = region.getStartOffset();
if (startOffset > lastVisibleOffset)
continue;
final int endOffset = getEndOffset(region);
if (endOffset < firstVisibleOffset)
continue;
if (!isFoldingPossible(startOffset, endOffset))
continue;
final FoldingGroup group = region.getGroup();
if (group != null && myEditor.getFoldingModel().getFirstRegion(group, region) != region)
continue;
//offset = Math.min(myEditor.getDocument().getTextLength() - 1, offset);
int foldStart = myEditor.offsetToVisualLine(startOffset);
if (!region.isExpanded()) {
tryAdding(result, region, foldStart, 0, DisplayedFoldingAnchor.Type.COLLAPSED, activeFoldRegion);
} else {
//offset = Math.min(myEditor.getDocument().getTextLength() - 1, offset);
int foldEnd = myEditor.offsetToVisualLine(endOffset);
tryAdding(result, region, foldStart, foldEnd - foldStart, DisplayedFoldingAnchor.Type.EXPANDED_TOP, activeFoldRegion);
tryAdding(result, region, foldEnd, foldEnd - foldStart, DisplayedFoldingAnchor.Type.EXPANDED_BOTTOM, activeFoldRegion);
}
}
return result.values();
}
use of com.intellij.util.containers.hash.HashMap in project intellij-community by JetBrains.
the class PropertiesCopyHandler method copyPropertyToAnotherBundle.
private static void copyPropertyToAnotherBundle(@NotNull Collection<IProperty> properties, @NotNull final String newName, @NotNull ResourceBundle targetResourceBundle) {
final Map<IProperty, PropertiesFile> propertiesFileMapping = new HashMap<>();
for (IProperty property : properties) {
final PropertiesFile containingFile = property.getPropertiesFile();
final PropertiesFile matched = findWithMatchedSuffix(containingFile, targetResourceBundle);
if (matched != null) {
propertiesFileMapping.put(property, matched);
}
}
final Project project = targetResourceBundle.getProject();
if (properties.size() != propertiesFileMapping.size() && Messages.NO == Messages.showYesNoDialog(project, "Source and target resource bundles properties files are not matched correctly. Copy properties anyway?", "Resource Bundles Are not Matched", null)) {
return;
}
if (!propertiesFileMapping.isEmpty()) {
WriteCommandAction.runWriteCommandAction(project, () -> {
if (!FileModificationService.getInstance().preparePsiElementsForWrite(ContainerUtil.map(propertiesFileMapping.values(), (Function<PropertiesFile, PsiElement>) PropertiesFile::getContainingFile)))
return;
for (Map.Entry<IProperty, PropertiesFile> entry : propertiesFileMapping.entrySet()) {
final String value = entry.getKey().getValue();
final PropertiesFile target = entry.getValue();
target.addProperty(newName, value);
}
});
final IProperty representativeFromSourceBundle = ContainerUtil.getFirstItem(properties);
LOG.assertTrue(representativeFromSourceBundle != null);
final ResourceBundle sourceResourceBundle = representativeFromSourceBundle.getPropertiesFile().getResourceBundle();
if (sourceResourceBundle.equals(targetResourceBundle)) {
DataManager.getInstance().getDataContextFromFocus().doWhenDone((Consumer<DataContext>) context -> {
final FileEditor fileEditor = PlatformDataKeys.FILE_EDITOR.getData(context);
if (fileEditor instanceof ResourceBundleEditor) {
final ResourceBundleEditor resourceBundleEditor = (ResourceBundleEditor) fileEditor;
resourceBundleEditor.updateTreeRoot();
resourceBundleEditor.selectProperty(newName);
}
});
} else {
for (FileEditor editor : FileEditorManager.getInstance(project).openFile(new ResourceBundleAsVirtualFile(targetResourceBundle), true)) {
((ResourceBundleEditor) editor).updateTreeRoot();
((ResourceBundleEditor) editor).selectProperty(newName);
}
}
}
}
Aggregations