Search in sources :

Example 31 with HashSet

use of com.intellij.util.containers.HashSet in project intellij-community by JetBrains.

the class ExtractSuperClassTest method doTest.

private void doTest(MemberInfo[] members, @NonNls String newClassName, String targetPackageName, VirtualFile rootDir, PsiClass psiClass, String[] conflicts) throws IOException {
    PsiDirectory targetDirectory;
    if (targetPackageName == null) {
        targetDirectory = psiClass.getContainingFile().getContainingDirectory();
    } else {
        final PsiPackage aPackage = myJavaFacade.findPackage(targetPackageName);
        assertNotNull(aPackage);
        targetDirectory = aPackage.getDirectories()[0];
    }
    ExtractSuperClassProcessor processor = new ExtractSuperClassProcessor(myProject, targetDirectory, newClassName, psiClass, members, false, new DocCommentPolicy<>(DocCommentPolicy.ASIS));
    final PsiPackage targetPackage;
    if (targetDirectory != null) {
        targetPackage = JavaDirectoryService.getInstance().getPackage(targetDirectory);
    } else {
        targetPackage = null;
    }
    final PsiClass superClass = psiClass.getExtendsListTypes().length > 0 ? psiClass.getSuperClass() : null;
    final MultiMap<PsiElement, String> conflictsMap = PullUpConflictsUtil.checkConflicts(members, psiClass, superClass, targetPackage, targetDirectory, psiMethod -> PullUpProcessor.checkedInterfacesContain(Arrays.asList(members), psiMethod), false);
    if (conflicts != null) {
        if (conflictsMap.isEmpty()) {
            fail("Conflicts were not detected");
        }
        final HashSet<String> expectedConflicts = new HashSet<>(Arrays.asList(conflicts));
        final HashSet<String> actualConflicts = new HashSet<>(conflictsMap.values());
        assertEquals(expectedConflicts.size(), actualConflicts.size());
        for (String actualConflict : actualConflicts) {
            if (!expectedConflicts.contains(actualConflict)) {
                fail("Unexpected conflict: " + actualConflict);
            }
        }
    } else if (!conflictsMap.isEmpty()) {
        fail("Unexpected conflicts!!!");
    }
    processor.run();
    PsiDocumentManager.getInstance(myProject).commitAllDocuments();
    FileDocumentManager.getInstance().saveAllDocuments();
    String rootAfter = getRoot() + "/after";
    VirtualFile rootDir2 = LocalFileSystem.getInstance().findFileByPath(rootAfter.replace(File.separatorChar, '/'));
    myProject.getComponent(PostprocessReformattingAspect.class).doPostponedFormatting();
    IdeaTestUtil.assertDirectoriesEqual(rootDir2, rootDir);
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) ExtractSuperClassProcessor(com.intellij.refactoring.extractSuperclass.ExtractSuperClassProcessor) PostprocessReformattingAspect(com.intellij.psi.impl.source.PostprocessReformattingAspect) HashSet(com.intellij.util.containers.HashSet)

Example 32 with HashSet

use of com.intellij.util.containers.HashSet in project intellij-community by JetBrains.

the class SuperClassHasFrequentlyUsedInheritorsInspectionTest method doTest.

private void doTest(final int expectedSize) {
    myFixture.configureByFile(getTestName(false) + ".java");
    myFixture.enableInspections(SuperClassHasFrequentlyUsedInheritorsInspection.class);
    final Set<Pair<String, Integer>> actualSet = new HashSet<Pair<String, Integer>>();
    for (IntentionAction intentionAction : myFixture.getAvailableIntentions()) {
        if (intentionAction instanceof QuickFixWrapper) {
            ChangeSuperClassFix changeSuperClassFix = getQuickFixFromWrapper((QuickFixWrapper) intentionAction);
            if (changeSuperClassFix != null) {
                actualSet.add(Pair.create(changeSuperClassFix.getNewSuperClass().getQualifiedName(), changeSuperClassFix.getPercent()));
            }
        }
    }
    assertSize(expectedSize, actualSet);
}
Also used : ChangeSuperClassFix(com.intellij.codeInspection.inheritance.ChangeSuperClassFix) IntentionAction(com.intellij.codeInsight.intention.IntentionAction) QuickFixWrapper(com.intellij.codeInspection.ex.QuickFixWrapper) HashSet(com.intellij.util.containers.HashSet) Pair(com.intellij.openapi.util.Pair)

Example 33 with HashSet

use of com.intellij.util.containers.HashSet in project intellij-community by JetBrains.

the class ActionMacroConfigurationPanel method apply.

public void apply() {
    if (myRenamingList != null) {
        for (Couple<String> pair : myRenamingList) {
            Keymap[] allKeymaps = KeymapManagerEx.getInstanceEx().getAllKeymaps();
            for (Keymap keymap : allKeymaps) {
                keymap.removeAllActionShortcuts(ActionMacro.MACRO_ACTION_PREFIX + pair.getSecond());
                for (Shortcut shortcut : keymap.getShortcuts(ActionMacro.MACRO_ACTION_PREFIX + pair.getFirst())) {
                    keymap.addShortcut(ActionMacro.MACRO_ACTION_PREFIX + pair.getSecond(), shortcut);
                }
                keymap.removeAllActionShortcuts(ActionMacro.MACRO_ACTION_PREFIX + pair.getFirst());
            }
        }
    }
    final ActionMacroManager manager = ActionMacroManager.getInstance();
    ActionMacro[] macros = manager.getAllMacros();
    HashSet<String> removedIds = new HashSet<>();
    for (ActionMacro macro1 : macros) {
        removedIds.add(macro1.getActionId());
    }
    manager.removeAllMacros();
    final Enumeration newMacros = myMacrosModel.elements();
    while (newMacros.hasMoreElements()) {
        ActionMacro macro = (ActionMacro) newMacros.nextElement();
        manager.addMacro(macro);
        removedIds.remove(macro.getActionId());
    }
    manager.registerActions();
    for (String id : removedIds) {
        Keymap[] allKeymaps = KeymapManagerEx.getInstanceEx().getAllKeymaps();
        for (Keymap keymap : allKeymaps) {
            keymap.removeAllActionShortcuts(id);
        }
    }
}
Also used : Enumeration(java.util.Enumeration) Shortcut(com.intellij.openapi.actionSystem.Shortcut) Keymap(com.intellij.openapi.keymap.Keymap) HashSet(com.intellij.util.containers.HashSet)

Example 34 with HashSet

use of com.intellij.util.containers.HashSet in project intellij-community by JetBrains.

the class FeaturesUsageCollector method getUsages.

@NotNull
@Override
public Set<UsageDescriptor> getUsages() {
    Set<UsageDescriptor> usages = new HashSet<>();
    final ProductivityFeaturesRegistry registry = ProductivityFeaturesRegistry.getInstance();
    for (String featureId : registry.getFeatureIds()) {
        final FeatureDescriptor featureDescriptor = registry.getFeatureDescriptor(featureId);
        if (featureDescriptor != null) {
            usages.add(new UsageDescriptor(featureId, featureDescriptor.getUsageCount()));
        }
    }
    return usages;
}
Also used : UsageDescriptor(com.intellij.internal.statistic.beans.UsageDescriptor) HashSet(com.intellij.util.containers.HashSet) NotNull(org.jetbrains.annotations.NotNull)

Example 35 with HashSet

use of com.intellij.util.containers.HashSet in project intellij-plugins by JetBrains.

the class CfmlAttributeNamesCompletionProvider method addCompletions.

public void addCompletions(@NotNull final CompletionParameters parameters, final ProcessingContext context, @NotNull final CompletionResultSet result) {
    PsiElement element = parameters.getPosition();
    String tagName = "";
    while (element != null && !(element instanceof CfmlTag) && !(element instanceof CfmlComponent) && !(element instanceof CfmlPropertyImpl)) {
        PsiElement prevNode = element.getPrevSibling();
        PsiElement superPrevNode = prevNode != null ? prevNode.getPrevSibling() : null;
        if (superPrevNode != null && superPrevNode.getText().equalsIgnoreCase("property")) {
            tagName = "cfproperty";
            break;
        }
        element = element.getParent();
    }
    if (element == null) {
        return;
    }
    if (tagName.isEmpty()) {
        tagName = element instanceof CfmlTag ? ((CfmlTag) element).getTagName() : element instanceof CfmlPropertyImpl ? "cfproperty" : "cfcomponent";
    }
    Set<String> excluded = new HashSet<>();
    final CfmlAttributeImpl[] attributes = PsiTreeUtil.getChildrenOfType(element, CfmlAttributeImpl.class);
    if (attributes != null) {
        for (CfmlAttributeImpl attribute : attributes) {
            excluded.add(attribute.getAttributeName());
        }
    }
    for (CfmlAttributeDescription s : CfmlUtil.getAttributes(tagName, element.getProject())) {
        if (s.getName() == null) {
            continue;
        }
        if (excluded.contains(s.getName())) {
            continue;
        }
        result.addElement(TailTypeDecorator.withTail(LookupElementBuilder.create(s.getName()).withCaseSensitivity(false), new TailType() {

            public int processTail(Editor editor, int tailOffset) {
                HighlighterIterator iterator = ((EditorEx) editor).getHighlighter().createIterator(tailOffset);
                if (!iterator.atEnd() && iterator.getTokenType() == CfmlTokenTypes.WHITE_SPACE)
                    iterator.advance();
                if (!iterator.atEnd() && iterator.getTokenType() == CfmlTokenTypes.ASSIGN) {
                    iterator.advance();
                } else {
                    editor.getDocument().insertString(tailOffset, "=\"\"");
                    return moveCaret(editor, tailOffset, 2);
                }
                int offset = iterator.getStart();
                if (!iterator.atEnd() && iterator.getTokenType() == CfmlTokenTypes.WHITE_SPACE)
                    iterator.advance();
                if (!iterator.atEnd() && CfmlTokenTypes.STRING_ELEMENTS.contains(iterator.getTokenType())) {
                    return tailOffset;
                }
                editor.getDocument().insertString(offset, "\"\"");
                return moveCaret(editor, tailOffset, offset - tailOffset + 1);
            }
        }));
    }
}
Also used : TailType(com.intellij.codeInsight.TailType) CfmlAttributeDescription(com.intellij.coldFusion.model.info.CfmlAttributeDescription) CfmlAttributeImpl(com.intellij.coldFusion.model.psi.impl.CfmlAttributeImpl) CfmlComponent(com.intellij.coldFusion.model.psi.CfmlComponent) CfmlPropertyImpl(com.intellij.coldFusion.model.psi.impl.CfmlPropertyImpl) CfmlTag(com.intellij.coldFusion.model.psi.CfmlTag) Editor(com.intellij.openapi.editor.Editor) PsiElement(com.intellij.psi.PsiElement) HighlighterIterator(com.intellij.openapi.editor.highlighter.HighlighterIterator) HashSet(com.intellij.util.containers.HashSet)

Aggregations

HashSet (com.intellij.util.containers.HashSet)162 NotNull (org.jetbrains.annotations.NotNull)50 VirtualFile (com.intellij.openapi.vfs.VirtualFile)31 File (java.io.File)22 PsiElement (com.intellij.psi.PsiElement)20 Module (com.intellij.openapi.module.Module)19 ArrayList (java.util.ArrayList)18 Project (com.intellij.openapi.project.Project)17 THashSet (gnu.trove.THashSet)15 Nullable (org.jetbrains.annotations.Nullable)14 HashMap (com.intellij.util.containers.HashMap)13 IOException (java.io.IOException)13 PsiFile (com.intellij.psi.PsiFile)12 UsageInfo (com.intellij.usageView.UsageInfo)12 GlobalSearchScope (com.intellij.psi.search.GlobalSearchScope)11 MultiMap (com.intellij.util.containers.MultiMap)11 Pair (com.intellij.openapi.util.Pair)7 GrExpression (org.jetbrains.plugins.groovy.lang.psi.api.statements.expressions.GrExpression)7 ConflictsDialog (com.intellij.refactoring.ui.ConflictsDialog)6 Document (com.intellij.openapi.editor.Document)5