Search in sources :

Example 91 with MultiMap

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

the class PsiSearchHelperImpl method collectFiles.

private void collectFiles(@NotNull MultiMap<Set<IdIndexEntry>, RequestWithProcessor> singles, @NotNull ProgressIndicator progress, @NotNull final MultiMap<VirtualFile, RequestWithProcessor> intersectionResult, @NotNull final MultiMap<VirtualFile, RequestWithProcessor> restResult) {
    for (Map.Entry<Set<IdIndexEntry>, Collection<RequestWithProcessor>> entry : singles.entrySet()) {
        final Set<IdIndexEntry> keys = entry.getKey();
        if (keys.isEmpty()) {
            continue;
        }
        final Collection<RequestWithProcessor> processors = entry.getValue();
        final GlobalSearchScope commonScope = uniteScopes(processors);
        final Set<VirtualFile> intersectionWithContainerNameFiles = intersectionWithContainerNameFiles(commonScope, processors, keys);
        List<VirtualFile> result = new ArrayList<>();
        Processor<VirtualFile> processor = Processors.cancelableCollectProcessor(result);
        processFilesContainingAllKeys(myManager.getProject(), commonScope, null, keys, processor);
        for (final VirtualFile file : result) {
            progress.checkCanceled();
            for (final IdIndexEntry indexEntry : keys) {
                DumbService.getInstance(myManager.getProject()).runReadActionInSmartMode(() -> FileBasedIndex.getInstance().processValues(IdIndex.NAME, indexEntry, file, (file1, value) -> {
                    int mask = value.intValue();
                    for (RequestWithProcessor single : processors) {
                        final PsiSearchRequest request = single.request;
                        if ((mask & request.searchContext) != 0 && request.searchScope.contains(file1)) {
                            MultiMap<VirtualFile, RequestWithProcessor> result1 = intersectionWithContainerNameFiles == null || !intersectionWithContainerNameFiles.contains(file1) ? restResult : intersectionResult;
                            result1.putValue(file1, single);
                        }
                    }
                    return true;
                }, commonScope));
            }
        }
    }
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) com.intellij.openapi.util(com.intellij.openapi.util) java.util(java.util) CommentUtilCore(com.intellij.util.codeInsight.CommentUtilCore) JobLauncher(com.intellij.concurrency.JobLauncher) VirtualFile(com.intellij.openapi.vfs.VirtualFile) ApplicationUtil(com.intellij.openapi.application.ex.ApplicationUtil) PsiManagerEx(com.intellij.psi.impl.PsiManagerEx) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) UsageInfo(com.intellij.usageView.UsageInfo) THashSet(gnu.trove.THashSet) ContainerUtil(com.intellij.util.containers.ContainerUtil) THashMap(gnu.trove.THashMap) ReadAction(com.intellij.openapi.application.ReadAction) ApplicationEx(com.intellij.openapi.application.ex.ApplicationEx) StringSearcher(com.intellij.util.text.StringSearcher) ReadActionProcessor(com.intellij.openapi.application.ReadActionProcessor) ProcessCanceledException(com.intellij.openapi.progress.ProcessCanceledException) TooManyUsagesStatus(com.intellij.openapi.progress.util.TooManyUsagesStatus) SmartList(com.intellij.util.SmartList) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) CacheManager(com.intellij.psi.impl.cache.CacheManager) Project(com.intellij.openapi.project.Project) FileIndexFacade(com.intellij.openapi.roots.FileIndexFacade) Logger(com.intellij.openapi.diagnostic.Logger) MultiMap(com.intellij.util.containers.MultiMap) FileBasedIndex(com.intellij.util.indexing.FileBasedIndex) DumbService(com.intellij.openapi.project.DumbService) StringUtil(com.intellij.openapi.util.text.StringUtil) Processors(com.intellij.util.Processors) FileDocumentManager(com.intellij.openapi.fileEditor.FileDocumentManager) IOException(java.io.IOException) IdIndexEntry(com.intellij.psi.impl.cache.impl.id.IdIndexEntry) ProgressIndicatorProvider(com.intellij.openapi.progress.ProgressIndicatorProvider) ExtensionPointName(com.intellij.openapi.extensions.ExtensionPointName) AsyncFuture(com.intellij.concurrency.AsyncFuture) EmptyProgressIndicator(com.intellij.openapi.progress.EmptyProgressIndicator) Nullable(org.jetbrains.annotations.Nullable) ProgressIndicator(com.intellij.openapi.progress.ProgressIndicator) PsiUtilCore(com.intellij.psi.util.PsiUtilCore) com.intellij.psi.search(com.intellij.psi.search) Processor(com.intellij.util.Processor) ApplicationManager(com.intellij.openapi.application.ApplicationManager) IdIndex(com.intellij.psi.impl.cache.impl.id.IdIndex) com.intellij.psi(com.intellij.psi) UsageInfoFactory(com.intellij.usageView.UsageInfoFactory) AsyncUtil(com.intellij.concurrency.AsyncUtil) NotNull(org.jetbrains.annotations.NotNull) THashSet(gnu.trove.THashSet) MultiMap(com.intellij.util.containers.MultiMap) IdIndexEntry(com.intellij.psi.impl.cache.impl.id.IdIndexEntry) THashMap(gnu.trove.THashMap) MultiMap(com.intellij.util.containers.MultiMap)

Example 92 with MultiMap

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

the class IntroduceVariableBase method invokeImpl.

protected boolean invokeImpl(final Project project, final PsiExpression expr, final Editor editor) {
    if (expr != null) {
        final String errorMessage = getErrorMessage(expr);
        if (errorMessage != null) {
            showErrorMessage(project, editor, RefactoringBundle.getCannotRefactorMessage(errorMessage));
            return false;
        }
    }
    if (expr != null && expr.getParent() instanceof PsiExpressionStatement) {
        FeatureUsageTracker.getInstance().triggerFeatureUsed("refactoring.introduceVariable.incompleteStatement");
    }
    if (LOG.isDebugEnabled()) {
        LOG.debug("expression:" + expr);
    }
    if (expr == null || !expr.isPhysical()) {
        if (ReassignVariableUtil.reassign(editor))
            return false;
        if (expr == null) {
            String message = RefactoringBundle.getCannotRefactorMessage(RefactoringBundle.message("selected.block.should.represent.an.expression"));
            showErrorMessage(project, editor, message);
            return false;
        }
    }
    final PsiType originalType = RefactoringUtil.getTypeByExpressionWithExpectedType(expr);
    if (originalType == null || LambdaUtil.notInferredType(originalType)) {
        String message = RefactoringBundle.getCannotRefactorMessage(RefactoringBundle.message("unknown.expression.type"));
        showErrorMessage(project, editor, message);
        return false;
    }
    if (PsiType.VOID.equals(originalType)) {
        String message = RefactoringBundle.getCannotRefactorMessage(RefactoringBundle.message("selected.expression.has.void.type"));
        showErrorMessage(project, editor, message);
        return false;
    }
    final PsiElement physicalElement = expr.getUserData(ElementToWorkOn.PARENT);
    final PsiElement anchorStatement = RefactoringUtil.getParentStatement(physicalElement != null ? physicalElement : expr, false);
    if (anchorStatement == null) {
        return parentStatementNotFound(project, editor);
    }
    if (checkAnchorBeforeThisOrSuper(project, editor, anchorStatement, REFACTORING_NAME, HelpID.INTRODUCE_VARIABLE))
        return false;
    final PsiElement tempContainer = anchorStatement.getParent();
    if (!(tempContainer instanceof PsiCodeBlock) && !RefactoringUtil.isLoopOrIf(tempContainer) && !(tempContainer instanceof PsiLambdaExpression) && (tempContainer.getParent() instanceof PsiLambdaExpression)) {
        String message = RefactoringBundle.message("refactoring.is.not.supported.in.the.current.context", REFACTORING_NAME);
        showErrorMessage(project, editor, message);
        return false;
    }
    if (!NotInSuperCallOccurrenceFilter.INSTANCE.isOK(expr)) {
        String message = RefactoringBundle.getCannotRefactorMessage(RefactoringBundle.message("cannot.introduce.variable.in.super.constructor.call"));
        showErrorMessage(project, editor, message);
        return false;
    }
    final PsiFile file = anchorStatement.getContainingFile();
    LOG.assertTrue(file != null, "expr.getContainingFile() == null");
    final PsiElement nameSuggestionContext = editor == null ? null : file.findElementAt(editor.getCaretModel().getOffset());
    final RefactoringSupportProvider supportProvider = LanguageRefactoringSupport.INSTANCE.forLanguage(expr.getLanguage());
    final boolean isInplaceAvailableOnDataContext = supportProvider != null && editor.getSettings().isVariableInplaceRenameEnabled() && supportProvider.isInplaceIntroduceAvailable(expr, nameSuggestionContext) && (!ApplicationManager.getApplication().isUnitTestMode() || isInplaceAvailableInTestMode()) && !isInJspHolderMethod(expr);
    if (isInplaceAvailableOnDataContext) {
        final MultiMap<PsiElement, String> conflicts = new MultiMap<>();
        checkInLoopCondition(expr, conflicts);
        if (!conflicts.isEmpty()) {
            showErrorMessage(project, editor, StringUtil.join(conflicts.values(), "<br>"));
            return false;
        }
    }
    final ExpressionOccurrenceManager occurrenceManager = createOccurrenceManager(expr, tempContainer);
    final PsiExpression[] occurrences = occurrenceManager.getOccurrences();
    final PsiElement anchorStatementIfAll = occurrenceManager.getAnchorStatementForAll();
    OccurrencesInfo occurrencesInfo = new OccurrencesInfo(occurrences);
    if (!CommonRefactoringUtil.checkReadOnlyStatus(project, file))
        return false;
    final LinkedHashMap<JavaReplaceChoice, List<PsiExpression>> occurrencesMap = occurrencesInfo.buildOccurrencesMap(expr);
    final boolean inFinalContext = occurrenceManager.isInFinalContext();
    final InputValidator validator = new InputValidator(this, project, anchorStatementIfAll, anchorStatement, occurrenceManager);
    final TypeSelectorManagerImpl typeSelectorManager = new TypeSelectorManagerImpl(project, originalType, expr, occurrences);
    final boolean[] wasSucceed = new boolean[] { true };
    final Pass<JavaReplaceChoice> callback = new Pass<JavaReplaceChoice>() {

        @Override
        public void pass(final JavaReplaceChoice choice) {
            boolean hasWriteAccess = occurrencesInfo.myHasWriteAccess;
            List<PsiExpression> nonWrite = occurrencesInfo.myNonWrite;
            if (choice != null) {
                final boolean noWriteChoice = choice == JavaReplaceChoice.NO_WRITE;
                final boolean allChoice = choice.isAll();
                final boolean replaceAll = allChoice || noWriteChoice;
                typeSelectorManager.setAllOccurrences(replaceAll);
                final PsiElement chosenAnchor = chooseAnchor(replaceAll, noWriteChoice, nonWrite, anchorStatementIfAll, anchorStatement);
                final IntroduceVariableSettings settings = getSettings(project, editor, expr, occurrences, typeSelectorManager, inFinalContext, hasWriteAccess, validator, chosenAnchor, choice);
                final boolean cantChangeFinalModifier = (hasWriteAccess || inFinalContext) && allChoice;
                PsiExpression[] allOccurrences = Arrays.stream(occurrences).filter(occurrence -> !(expr.equals(occurrence) && expr.getParent() instanceof PsiExpressionStatement)).filter(occurrence -> allChoice || (noWriteChoice && !PsiUtil.isAccessedForWriting(occurrence)) || expr.equals(occurrence)).toArray(PsiExpression[]::new);
                if (choice.isChain()) {
                    myInplaceIntroducer = new ChainCallInplaceIntroducer(project, settings, chosenAnchor, editor, expr, allOccurrences, typeSelectorManager, REFACTORING_NAME);
                } else {
                    myInplaceIntroducer = new JavaVariableInplaceIntroducer(project, settings, chosenAnchor, editor, expr, cantChangeFinalModifier, allOccurrences, typeSelectorManager, REFACTORING_NAME);
                }
                if (myInplaceIntroducer.startInplaceIntroduceTemplate()) {
                    return;
                }
            }
            CommandProcessor.getInstance().executeCommand(project, () -> {
                if (!anchorStatement.isValid()) {
                    return;
                }
                final Editor topLevelEditor;
                if (!InjectedLanguageManager.getInstance(project).isInjectedFragment(anchorStatement.getContainingFile())) {
                    topLevelEditor = InjectedLanguageUtil.getTopLevelEditor(editor);
                } else {
                    topLevelEditor = editor;
                }
                PsiVariable variable = null;
                try {
                    final IntroduceVariableSettings settings = getSettings(project, topLevelEditor, expr, occurrences, typeSelectorManager, inFinalContext, hasWriteAccess, validator, anchorStatement, choice);
                    if (!settings.isOK()) {
                        wasSucceed[0] = false;
                        return;
                    }
                    final RefactoringEventData beforeData = new RefactoringEventData();
                    beforeData.addElement(expr);
                    project.getMessageBus().syncPublisher(RefactoringEventListener.REFACTORING_EVENT_TOPIC).refactoringStarted(REFACTORING_ID, beforeData);
                    final PsiElement chosenAnchor = chooseAnchor(settings.isReplaceAllOccurrences(), hasWriteAccess, nonWrite, anchorStatementIfAll, anchorStatement);
                    variable = introduce(project, expr, topLevelEditor, chosenAnchor, occurrences, settings);
                } finally {
                    final RefactoringEventData afterData = new RefactoringEventData();
                    afterData.addElement(variable);
                    project.getMessageBus().syncPublisher(RefactoringEventListener.REFACTORING_EVENT_TOPIC).refactoringDone(REFACTORING_ID, afterData);
                }
            }, REFACTORING_NAME, null);
        }
    };
    if (!isInplaceAvailableOnDataContext) {
        callback.pass(null);
    } else {
        JavaReplaceChoice choice = getOccurrencesChoice();
        if (choice != null) {
            callback.pass(choice);
        } else {
            String title = occurrencesInfo.myChainMethodName != null && occurrences.length == 1 ? "Lambda chain detected" : OccurrencesChooser.DEFAULT_CHOOSER_TITLE;
            OccurrencesChooser.<PsiExpression>simpleChooser(editor).showChooser(callback, occurrencesMap, title);
        }
    }
    return wasSucceed[0];
}
Also used : InjectedLanguageManager(com.intellij.lang.injection.InjectedLanguageManager) com.intellij.refactoring(com.intellij.refactoring) RefactoringUIUtil(com.intellij.refactoring.util.RefactoringUIUtil) EditorColorsManager(com.intellij.openapi.editor.colors.EditorColorsManager) NullableNotNullManager(com.intellij.codeInsight.NullableNotNullManager) HighlightManager(com.intellij.codeInsight.highlighting.HighlightManager) FeatureUsageTracker(com.intellij.featureStatistics.FeatureUsageTracker) RefactoringEventData(com.intellij.refactoring.listeners.RefactoringEventData) Logger(com.intellij.openapi.diagnostic.Logger) MultiMap(com.intellij.util.containers.MultiMap) ReferencesSearch(com.intellij.psi.search.searches.ReferencesSearch) PropertiesComponent(com.intellij.ide.util.PropertiesComponent) JspCodeBlock(com.intellij.psi.impl.source.jsp.jspJava.JspCodeBlock) FieldConflictsResolver(com.intellij.refactoring.util.FieldConflictsResolver) IncorrectOperationException(com.intellij.util.IncorrectOperationException) ChainCallExtractor(com.intellij.refactoring.chainCall.ChainCallExtractor) WindowManager(com.intellij.openapi.wm.WindowManager) LookupManager(com.intellij.codeInsight.lookup.LookupManager) TextRange(com.intellij.openapi.util.TextRange) CodeStyleSettingsManager(com.intellij.psi.codeStyle.CodeStyleSettingsManager) RefactoringSupportProvider(com.intellij.lang.refactoring.RefactoringSupportProvider) ReplaceExpressionUtil(com.intellij.psi.impl.source.tree.java.ReplaceExpressionUtil) AbstractInplaceIntroducer(com.intellij.refactoring.introduce.inplace.AbstractInplaceIntroducer) Nullable(org.jetbrains.annotations.Nullable) ExpressionOccurrenceManager(com.intellij.refactoring.util.occurrences.ExpressionOccurrenceManager) TextAttributes(com.intellij.openapi.editor.markup.TextAttributes) Pass(com.intellij.openapi.util.Pass) OccurrencesChooser(com.intellij.refactoring.introduce.inplace.OccurrencesChooser) VariableKind(com.intellij.psi.codeStyle.VariableKind) ScopeHighlighter(com.intellij.codeInsight.unwrap.ScopeHighlighter) JspHolderMethod(com.intellij.psi.impl.source.jsp.jspJava.JspHolderMethod) Processor(com.intellij.util.Processor) ApplicationManager(com.intellij.openapi.application.ApplicationManager) Registry(com.intellij.openapi.util.registry.Registry) com.intellij.psi(com.intellij.psi) NotNull(org.jetbrains.annotations.NotNull) SuggestedNameInfo(com.intellij.psi.codeStyle.SuggestedNameInfo) java.util(java.util) TypeSelectorManagerImpl(com.intellij.refactoring.ui.TypeSelectorManagerImpl) DataContext(com.intellij.openapi.actionSystem.DataContext) com.intellij.openapi.editor(com.intellij.openapi.editor) NonNls(org.jetbrains.annotations.NonNls) Computable(com.intellij.openapi.util.Computable) ElementToWorkOn(com.intellij.refactoring.introduceField.ElementToWorkOn) ArrayUtilRt(com.intellij.util.ArrayUtilRt) RefactoringEventListener(com.intellij.refactoring.listeners.RefactoringEventListener) ContainerUtil(com.intellij.util.containers.ContainerUtil) CodeInsightUtil(com.intellij.codeInsight.CodeInsightUtil) JavaCodeStyleManager(com.intellij.psi.codeStyle.JavaCodeStyleManager) MessageFormat(java.text.MessageFormat) LanguageRefactoringSupport(com.intellij.lang.LanguageRefactoringSupport) Project(com.intellij.openapi.project.Project) InjectedLanguageUtil(com.intellij.psi.impl.source.tree.injected.InjectedLanguageUtil) NotInSuperCallOccurrenceFilter(com.intellij.refactoring.util.occurrences.NotInSuperCallOccurrenceFilter) ProductivityFeatureNames(com.intellij.featureStatistics.ProductivityFeatureNames) StringUtil(com.intellij.openapi.util.text.StringUtil) com.intellij.psi.util(com.intellij.psi.util) Key(com.intellij.openapi.util.Key) FileDocumentManager(com.intellij.openapi.fileEditor.FileDocumentManager) CommandProcessor(com.intellij.openapi.command.CommandProcessor) CommonRefactoringUtil(com.intellij.refactoring.util.CommonRefactoringUtil) EditorColors(com.intellij.openapi.editor.colors.EditorColors) JavaCompletionUtil(com.intellij.codeInsight.completion.JavaCompletionUtil) PsiDiamondTypeUtil(com.intellij.psi.impl.PsiDiamondTypeUtil) RefactoringUtil(com.intellij.refactoring.util.RefactoringUtil) MultiMap(com.intellij.util.containers.MultiMap) RefactoringSupportProvider(com.intellij.lang.refactoring.RefactoringSupportProvider) Pass(com.intellij.openapi.util.Pass) TypeSelectorManagerImpl(com.intellij.refactoring.ui.TypeSelectorManagerImpl) RefactoringEventData(com.intellij.refactoring.listeners.RefactoringEventData) ExpressionOccurrenceManager(com.intellij.refactoring.util.occurrences.ExpressionOccurrenceManager)

Example 93 with MultiMap

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

the class MoveClassesOrPackagesImpl method doRearrangePackage.

public static void doRearrangePackage(final Project project, final PsiDirectory[] directories) {
    if (!CommonRefactoringUtil.checkReadOnlyStatusRecursively(project, Arrays.asList(directories), true)) {
        return;
    }
    List<PsiDirectory> sourceRootDirectories = buildRearrangeTargetsList(project, directories);
    DirectoryChooser chooser = new DirectoryChooser(project);
    chooser.setTitle(RefactoringBundle.message("select.source.root.chooser.title"));
    chooser.fillList(sourceRootDirectories.toArray(new PsiDirectory[sourceRootDirectories.size()]), null, project, "");
    if (!chooser.showAndGet()) {
        return;
    }
    final PsiDirectory selectedTarget = chooser.getSelectedDirectory();
    if (selectedTarget == null)
        return;
    final MultiMap<PsiElement, String> conflicts = new MultiMap<>();
    final Runnable analyzeConflicts = () -> ApplicationManager.getApplication().runReadAction(() -> RefactoringConflictsUtil.analyzeModuleConflicts(project, Arrays.asList(directories), UsageInfo.EMPTY_ARRAY, selectedTarget, conflicts));
    if (!ProgressManager.getInstance().runProcessWithProgressSynchronously(analyzeConflicts, "Analyze Module Conflicts...", true, project)) {
        return;
    }
    if (!conflicts.isEmpty()) {
        if (ApplicationManager.getApplication().isUnitTestMode()) {
            throw new BaseRefactoringProcessor.ConflictsInTestsException(conflicts.values());
        } else {
            final ConflictsDialog conflictsDialog = new ConflictsDialog(project, conflicts);
            if (!conflictsDialog.showAndGet()) {
                return;
            }
        }
    }
    final Ref<IncorrectOperationException> ex = Ref.create(null);
    final String commandDescription = RefactoringBundle.message("moving.directories.command");
    Runnable runnable = () -> ApplicationManager.getApplication().runWriteAction(() -> {
        LocalHistoryAction a = LocalHistory.getInstance().startAction(commandDescription);
        try {
            rearrangeDirectoriesToTarget(directories, selectedTarget);
        } catch (IncorrectOperationException e) {
            ex.set(e);
        } finally {
            a.finish();
        }
    });
    CommandProcessor.getInstance().executeCommand(project, runnable, commandDescription, null);
    if (ex.get() != null) {
        RefactoringUIUtil.processIncorrectOperation(project, ex.get());
    }
}
Also used : MultiMap(com.intellij.util.containers.MultiMap) ConflictsDialog(com.intellij.refactoring.ui.ConflictsDialog) LocalHistoryAction(com.intellij.history.LocalHistoryAction) IncorrectOperationException(com.intellij.util.IncorrectOperationException) DirectoryChooser(com.intellij.ide.util.DirectoryChooser)

Example 94 with MultiMap

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

the class MakeMethodOrClassStaticProcessor method getConflictDescriptions.

protected MultiMap<PsiElement, String> getConflictDescriptions(UsageInfo[] usages) {
    MultiMap<PsiElement, String> conflicts = new MultiMap<>();
    HashSet<PsiElement> processed = new HashSet<>();
    String typeString = StringUtil.capitalize(UsageViewUtil.getType(myMember));
    for (UsageInfo usageInfo : usages) {
        if (usageInfo instanceof InternalUsageInfo && !(usageInfo instanceof SelfUsageInfo)) {
            PsiElement referencedElement = ((InternalUsageInfo) usageInfo).getReferencedElement();
            if (!mySettings.isMakeClassParameter()) {
                if (referencedElement instanceof PsiModifierListOwner) {
                    if (((PsiModifierListOwner) referencedElement).hasModifierProperty(PsiModifier.STATIC)) {
                        continue;
                    }
                }
                if (processed.contains(referencedElement))
                    continue;
                processed.add(referencedElement);
                if (referencedElement instanceof PsiField) {
                    PsiField field = (PsiField) referencedElement;
                    if (mySettings.getNameForField(field) == null) {
                        String message = RefactoringBundle.message("0.uses.non.static.1.which.is.not.passed.as.a.parameter", typeString, RefactoringUIUtil.getDescription(field, true));
                        conflicts.putValue(field, message);
                    }
                } else {
                    String message = RefactoringBundle.message("0.uses.1.which.needs.class.instance", typeString, RefactoringUIUtil.getDescription(referencedElement, true));
                    conflicts.putValue(referencedElement, message);
                }
            }
        }
        if (usageInfo instanceof OverridingMethodUsageInfo) {
            LOG.assertTrue(myMember instanceof PsiMethod);
            final PsiMethod overridingMethod = ((PsiMethod) usageInfo.getElement());
            String message = RefactoringBundle.message("method.0.is.overridden.by.1", RefactoringUIUtil.getDescription(myMember, false), RefactoringUIUtil.getDescription(overridingMethod, true));
            conflicts.putValue(overridingMethod, message);
        } else {
            PsiElement element = usageInfo.getElement();
            PsiElement container = ConflictsUtil.getContainer(element);
            if (processed.contains(container))
                continue;
            processed.add(container);
            List<Settings.FieldParameter> fieldParameters = mySettings.getParameterOrderList();
            ArrayList<PsiField> inaccessible = new ArrayList<>();
            for (final Settings.FieldParameter fieldParameter : fieldParameters) {
                if (!PsiUtil.isAccessible(fieldParameter.field, element, null)) {
                    inaccessible.add(fieldParameter.field);
                }
            }
            if (inaccessible.isEmpty())
                continue;
            createInaccessibleFieldsConflictDescription(inaccessible, container, conflicts);
        }
    }
    return conflicts;
}
Also used : MultiMap(com.intellij.util.containers.MultiMap) UsageInfo(com.intellij.usageView.UsageInfo)

Example 95 with MultiMap

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

the class GrIntroduceValidatorEngine method isOKImpl.

private MultiMap<PsiElement, String> isOKImpl(String varName, boolean replaceAllOccurrences) {
    PsiElement firstOccurrence = getFirstOccurrence(replaceAllOccurrences);
    final MultiMap<PsiElement, String> conflicts = new MultiMap<>();
    assert varName != null;
    final int offset = firstOccurrence.getTextRange().getStartOffset();
    validateOccurrencesDown(myContext.getScope(), conflicts, varName, offset);
    if (!(myContext.getScope() instanceof GroovyFileBase)) {
        validateVariableOccurrencesUp(myContext.getScope(), conflicts, varName, offset);
    }
    if (replaceAllOccurrences) {
        for (PsiElement element : myContext.getOccurrences()) {
            if (element == firstOccurrence)
                continue;
            validateVariableOccurrencesUp(element, conflicts, varName, element.getTextRange().getStartOffset());
        }
    }
    return conflicts;
}
Also used : MultiMap(com.intellij.util.containers.MultiMap) GroovyFileBase(org.jetbrains.plugins.groovy.lang.psi.GroovyFileBase) PsiElement(com.intellij.psi.PsiElement)

Aggregations

MultiMap (com.intellij.util.containers.MultiMap)138 NotNull (org.jetbrains.annotations.NotNull)37 UsageInfo (com.intellij.usageView.UsageInfo)26 VirtualFile (com.intellij.openapi.vfs.VirtualFile)25 Project (com.intellij.openapi.project.Project)18 PsiElement (com.intellij.psi.PsiElement)18 ConflictsDialog (com.intellij.refactoring.ui.ConflictsDialog)16 Collection (java.util.Collection)16 Nullable (org.jetbrains.annotations.Nullable)15 Map (java.util.Map)14 File (java.io.File)11 HashSet (com.intellij.util.containers.HashSet)10 ContainerUtil (com.intellij.util.containers.ContainerUtil)9 THashSet (gnu.trove.THashSet)9 java.util (java.util)9 Module (com.intellij.openapi.module.Module)8 com.intellij.psi (com.intellij.psi)8 Pair (com.intellij.openapi.util.Pair)7 PsiFile (com.intellij.psi.PsiFile)7 ArrayList (java.util.ArrayList)7