Search in sources :

Example 6 with HashMap

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;
}
Also used : HashMap(com.intellij.util.containers.hash.HashMap) MoveRenameUsageInfo(com.intellij.refactoring.util.MoveRenameUsageInfo) PsiElement(com.intellij.psi.PsiElement) UsageInfo(com.intellij.usageView.UsageInfo) MoveRenameUsageInfo(com.intellij.refactoring.util.MoveRenameUsageInfo) HashSet(com.intellij.util.containers.hash.HashSet)

Example 7 with HashMap

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);
        }
    }
}
Also used : MessageDiffRequest(com.intellij.diff.requests.MessageDiffRequest) HashMap(com.intellij.util.containers.hash.HashMap) ShowDiffContext(com.intellij.openapi.vcs.changes.actions.diff.ShowDiffContext) Change(com.intellij.openapi.vcs.changes.Change) NotNull(org.jetbrains.annotations.NotNull) Key(com.intellij.openapi.util.Key) CalledInAwt(org.jetbrains.annotations.CalledInAwt)

Example 8 with HashMap

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);
    }
}
Also used : HashMap(com.intellij.util.containers.hash.HashMap) InputStream(java.io.InputStream) IOException(java.io.IOException)

Example 9 with HashMap

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();
}
Also used : FoldingGroup(com.intellij.openapi.editor.FoldingGroup) HashMap(com.intellij.util.containers.hash.HashMap) FoldRegion(com.intellij.openapi.editor.FoldRegion) NotNull(org.jetbrains.annotations.NotNull)

Example 10 with HashMap

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);
            }
        }
    }
}
Also used : UIUtil(com.intellij.util.ui.UIUtil) AllIcons(com.intellij.icons.AllIcons) VirtualFile(com.intellij.openapi.vfs.VirtualFile) CopyHandlerDelegateBase(com.intellij.refactoring.copy.CopyHandlerDelegateBase) ItemListener(java.awt.event.ItemListener) PsiManager(com.intellij.psi.PsiManager) JBTextField(com.intellij.ui.components.JBTextField) Map(java.util.Map) WriteCommandAction(com.intellij.openapi.command.WriteCommandAction) Messages(com.intellij.openapi.ui.Messages) FileUtil(com.intellij.openapi.util.io.FileUtil) Logger(com.intellij.openapi.diagnostic.Logger) ValidationInfo(com.intellij.openapi.ui.ValidationInfo) ItemEvent(java.awt.event.ItemEvent) SyntheticFileSystemItem(com.intellij.psi.impl.SyntheticFileSystemItem) FileModificationService(com.intellij.codeInsight.FileModificationService) GotoFileCellRenderer(com.intellij.ide.util.gotoByName.GotoFileCellRenderer) Collection(java.util.Collection) NullableFunction(com.intellij.util.NullableFunction) GlobalSearchScope(com.intellij.psi.search.GlobalSearchScope) FileEditor(com.intellij.openapi.fileEditor.FileEditor) Collectors(java.util.stream.Collectors) Nullable(org.jetbrains.annotations.Nullable) List(java.util.List) ComboboxSpeedSearch(com.intellij.ui.ComboboxSpeedSearch) Function(com.intellij.util.Function) PsiDirectory(com.intellij.psi.PsiDirectory) ProjectScope(com.intellij.psi.search.ProjectScope) NotNull(org.jetbrains.annotations.NotNull) PsiFileSystemItem(com.intellij.psi.PsiFileSystemItem) DocumentAdapter(com.intellij.ui.DocumentAdapter) FormBuilder(com.intellij.util.ui.FormBuilder) Consumer(com.intellij.util.Consumer) PropertiesFile(com.intellij.lang.properties.psi.PropertiesFile) DataContext(com.intellij.openapi.actionSystem.DataContext) PsiElementProcessor(com.intellij.psi.search.PsiElementProcessor) ContainerUtil(com.intellij.util.containers.ContainerUtil) ArrayList(java.util.ArrayList) FileEditorManager(com.intellij.openapi.fileEditor.FileEditorManager) PlatformDataKeys(com.intellij.openapi.actionSystem.PlatformDataKeys) Comparing(com.intellij.openapi.util.Comparing) DialogWrapper(com.intellij.openapi.ui.DialogWrapper) PsiElement(com.intellij.psi.PsiElement) Project(com.intellij.openapi.project.Project) DocumentEvent(javax.swing.event.DocumentEvent) DataManager(com.intellij.ide.DataManager) HashMap(com.intellij.util.containers.hash.HashMap) ComboBox(com.intellij.openapi.ui.ComboBox) StringUtil(com.intellij.openapi.util.text.StringUtil) com.intellij.lang.properties(com.intellij.lang.properties) java.awt(java.awt) javax.swing(javax.swing) FileEditor(com.intellij.openapi.fileEditor.FileEditor) HashMap(com.intellij.util.containers.hash.HashMap) Project(com.intellij.openapi.project.Project) DataContext(com.intellij.openapi.actionSystem.DataContext) PropertiesFile(com.intellij.lang.properties.psi.PropertiesFile) Map(java.util.Map) HashMap(com.intellij.util.containers.hash.HashMap) PsiElement(com.intellij.psi.PsiElement)

Aggregations

HashMap (com.intellij.util.containers.hash.HashMap)11 ArrayList (java.util.ArrayList)5 NotNull (org.jetbrains.annotations.NotNull)5 Project (com.intellij.openapi.project.Project)3 PsiElement (com.intellij.psi.PsiElement)3 DataContext (com.intellij.openapi.actionSystem.DataContext)2 VirtualFile (com.intellij.openapi.vfs.VirtualFile)2 FileModificationService (com.intellij.codeInsight.FileModificationService)1 DiffContent (com.intellij.diff.contents.DiffContent)1 MessageDiffRequest (com.intellij.diff.requests.MessageDiffRequest)1 AllIcons (com.intellij.icons.AllIcons)1 DataManager (com.intellij.ide.DataManager)1 DnDAwareTree (com.intellij.ide.dnd.aware.DnDAwareTree)1 GotoFileCellRenderer (com.intellij.ide.util.gotoByName.GotoFileCellRenderer)1 AbstractTreeNode (com.intellij.ide.util.treeView.AbstractTreeNode)1 com.intellij.lang.properties (com.intellij.lang.properties)1 PropertiesFile (com.intellij.lang.properties.psi.PropertiesFile)1 PlatformDataKeys (com.intellij.openapi.actionSystem.PlatformDataKeys)1 WriteCommandAction (com.intellij.openapi.command.WriteCommandAction)1 Logger (com.intellij.openapi.diagnostic.Logger)1