protected boolean showConflicts( @NotNull MultiMap<PsiElement, String> conflicts, @Nullable final UsageInfo[] usages) { if (!conflicts.isEmpty() && ApplicationManager.getApplication().isUnitTestMode()) { if (!ConflictsInTestsException.isTestIgnore()) throw new ConflictsInTestsException(conflicts.values()); return true; } if (myPrepareSuccessfulSwingThreadCallback != null && !conflicts.isEmpty()) { final String refactoringId = getRefactoringId(); if (refactoringId != null) { RefactoringEventData conflictUsages = new RefactoringEventData(); conflictUsages.putUserData(RefactoringEventData.CONFLICTS_KEY, conflicts.values()); myProject .getMessageBus() .syncPublisher(RefactoringEventListener.REFACTORING_EVENT_TOPIC) .conflictsDetected(refactoringId, conflictUsages); } final ConflictsDialog conflictsDialog = prepareConflictsDialog(conflicts, usages); if (!conflictsDialog.showAndGet()) { if (conflictsDialog.isShowConflicts()) prepareSuccessful(); return false; } } prepareSuccessful(); return true; }
private void performAction( String from, String to, final int docCommentPolicy, String[] expectedConflicts, final String[] toPullUp) { final JSClassResolver resolver = JSDialectSpecificHandlersFactory.forLanguage(JavaScriptSupportLoader.ECMA_SCRIPT_L4) .getClassResolver(); final JSClass sourceClass = (JSClass) resolver.findClassByQName(from, GlobalSearchScope.projectScope(getProject())); assertNotNull("source class not found: " + sourceClass, sourceClass); final JSClass targetClass = (JSClass) resolver.findClassByQName(to, GlobalSearchScope.projectScope(getProject())); assertNotNull("target class not found: " + targetClass, targetClass); assertTrue( "Source should be a subclass of target", JSInheritanceUtil.isParentClass(sourceClass, targetClass)); final List<JSMemberInfo> memberInfos = getMemberInfos(toPullUp, sourceClass, false); final JSMemberInfo[] infosArray = JSMemberInfo.getSelected(memberInfos, sourceClass, Conditions.<JSMemberInfo>alwaysTrue()); MultiMap<PsiElement, String> conflicts = JSPullUpConflictsUtil.checkConflicts( infosArray, sourceClass, targetClass, new JSInterfaceContainmentVerifier() { @Override public boolean checkedInterfacesContain(JSFunction psiMethod) { return JSPullUpHelper.checkedInterfacesContain(memberInfos, psiMethod); } }, JSVisibilityUtil.DEFAULT_OPTIONS); ArrayList<String> messages = new ArrayList<String>(conflicts.values()); for (int i = 0; i < messages.size(); i++) { messages.set(i, messages.get(i).replaceAll("<[^>]+>", "")); } assertSameElements(messages, expectedConflicts); if (conflicts.isEmpty()) { WriteCommandAction.runWriteCommandAction( null, new Runnable() { public void run() { new JSPullUpHelper(sourceClass, targetClass, infosArray, docCommentPolicy) .moveMembersToBase(); myProject.getComponent(PostprocessReformattingAspect.class).doPostponedFormatting(); } }); FileDocumentManager.getInstance().saveAllDocuments(); } }
public List<X509Certificate> getCertificates() { return ContainerUtil.map( myCertificates.values(), new Function<CertificateWrapper, X509Certificate>() { @Override public X509Certificate fun(CertificateWrapper wrapper) { return wrapper.getCertificate(); } }); }
@NotNull public static Set<PsiElement> findRedundantImportIdentifiers( @NotNull MultiMap<String, GoImportSpec> importMap) { Set<PsiElement> importIdentifiersToDelete = ContainerUtil.newLinkedHashSet(); for (PsiElement importEntry : importMap.values()) { GoImportSpec importSpec = getImportSpec(importEntry); if (importSpec != null) { String localPackageName = importSpec.getLocalPackageName(); if (!StringUtil.isEmpty(localPackageName)) { if (Comparing.equal(importSpec.getAlias(), localPackageName)) { importIdentifiersToDelete.add(importSpec.getIdentifier()); } } } } return importIdentifiersToDelete; }
public Collection<String> findConflicts( @NotNull final PsiElement element, @NotNull final PsiElement[] allElementsToDelete) { if (element instanceof PsiMethod) { final PsiClass containingClass = ((PsiMethod) element).getContainingClass(); if (containingClass != null && !containingClass.hasModifierProperty(PsiModifier.ABSTRACT)) { final PsiMethod[] superMethods = ((PsiMethod) element).findSuperMethods(); for (PsiMethod superMethod : superMethods) { if (isInside(superMethod, allElementsToDelete)) continue; if (superMethod.hasModifierProperty(PsiModifier.ABSTRACT)) { String message = RefactoringBundle.message( "0.implements.1", RefactoringUIUtil.getDescription(element, true), RefactoringUIUtil.getDescription(superMethod, true)); return Collections.singletonList(message); } } } } else if (element instanceof PsiParameter) { final PsiElement scope = ((PsiParameter) element).getDeclarationScope(); if (scope instanceof PsiMethod) { final PsiMethod method = (PsiMethod) scope; final PsiClass containingClass = method.getContainingClass(); if (containingClass != null) { final int parameterIndex = method.getParameterList().getParameterIndex((PsiParameter) element); final PsiMethod methodCopy = (PsiMethod) method.copy(); methodCopy.getParameterList().getParameters()[parameterIndex].delete(); final MultiMap<PsiElement, String> conflicts = new MultiMap<>(); ConflictsUtil.checkMethodConflicts(containingClass, method, methodCopy, conflicts); return (Collection<String>) conflicts.values(); } } } return null; }
public boolean preprocessUsages(final Ref<UsageInfo[]> refUsages) { UsageInfo[] usagesIn = refUsages.get(); MultiMap<PsiElement, String> conflicts = new MultiMap<PsiElement, String>(); RenameUtil.addConflictDescriptions(usagesIn, conflicts); RenamePsiElementProcessor.forElement(myPrimaryElement) .findExistingNameConflicts(myPrimaryElement, myNewName, conflicts); if (!conflicts.isEmpty()) { if (ApplicationManager.getApplication().isUnitTestMode()) { throw new ConflictsInTestsException(conflicts.values()); } ConflictsDialog conflictsDialog = prepareConflictsDialog(conflicts, refUsages.get()); conflictsDialog.show(); if (!conflictsDialog.isOK()) { if (conflictsDialog.isShowConflicts()) prepareSuccessful(); return false; } } final List<UsageInfo> variableUsages = new ArrayList<UsageInfo>(); if (!myRenamers.isEmpty()) { if (!findRenamedVariables(variableUsages)) return false; final LinkedHashMap<PsiElement, String> renames = new LinkedHashMap<PsiElement, String>(); for (final AutomaticRenamer renamer : myRenamers) { final List<? extends PsiNamedElement> variables = renamer.getElements(); for (final PsiNamedElement variable : variables) { final String newName = renamer.getNewName(variable); if (newName != null) { addElement(variable, newName); prepareRenaming(variable, newName, renames); } } } if (!renames.isEmpty()) { myAllRenames.putAll(renames); final Runnable runnable = new Runnable() { public void run() { for (Map.Entry<PsiElement, String> entry : renames.entrySet()) { final UsageInfo[] usages = RenameUtil.findUsages( entry.getKey(), entry.getValue(), mySearchInComments, mySearchTextOccurrences, myAllRenames); Collections.addAll(variableUsages, usages); } } }; if (!ProgressManager.getInstance() .runProcessWithProgressSynchronously( runnable, RefactoringBundle.message("searching.for.variables"), true, myProject)) { return false; } } } final Set<UsageInfo> usagesSet = new HashSet<UsageInfo>(Arrays.asList(usagesIn)); usagesSet.addAll(variableUsages); final List<UnresolvableCollisionUsageInfo> conflictUsages = RenameUtil.removeConflictUsages(usagesSet); if (conflictUsages != null) { mySkippedUsages.addAll(conflictUsages); } refUsages.set(usagesSet.toArray(new UsageInfo[usagesSet.size()])); prepareSuccessful(); return true; }
@NotNull public Collection<VcsRef> getAllRefs() { return new ArrayList<VcsRef>(myRefsToHashes.values()); }