diff --git a/platform/testFramework/src/com/intellij/testFramework/propertyBased/InvokeIntention.java b/platform/testFramework/src/com/intellij/testFramework/propertyBased/InvokeIntention.java index 58872c15a2ad..4c4629eb0680 100644 --- a/platform/testFramework/src/com/intellij/testFramework/propertyBased/InvokeIntention.java +++ b/platform/testFramework/src/com/intellij/testFramework/propertyBased/InvokeIntention.java @@ -181,7 +181,7 @@ public class InvokeIntention extends ActionOnFile { if (elementsToWrap.isEmpty()) return intentions; Project project = getProject(); - Set names = StreamEx.of(intentions).map(IntentionAction::getText).toSet(); + Map names = StreamEx.of(intentions).toMap(IntentionAction::getText, Function.identity(), (a,b) -> a); PsiElement elementToWrap = env.generateValue(Generator.sampledFrom(elementsToWrap).noShrink(), null); String text = elementToWrap.getText(); String prefix = myPolicy.getWrapPrefix(); @@ -209,25 +209,25 @@ public class InvokeIntention extends ActionOnFile { } } intentions = getAvailableIntentions(editor, file); - Set namesWithParentheses = StreamEx.of(intentions).map(IntentionAction::getText).toSet(); - Set added = new HashSet<>(namesWithParentheses); - added.removeAll(names); - Set removed = new HashSet<>(names); - removed.removeAll(namesWithParentheses); + Map namesWithParentheses = StreamEx.of(intentions).toMap(IntentionAction::getText, Function.identity(), (a,b) -> a); + Map added = new HashMap<>(namesWithParentheses); + added.keySet().removeAll(names.keySet()); + Map removed = new HashMap<>(names); + removed.keySet().removeAll(namesWithParentheses.keySet()); Function cleaner = name -> name.replace(prefix, "").replace(suffix, ""); // Exclude pairs like "Extract if (!foo)" and "Extract if (!(foo))" - for (Iterator iterator = added.iterator(); iterator.hasNext(); ) { + for (Iterator iterator = added.keySet().iterator(); iterator.hasNext(); ) { String newName = iterator.next(); String stripped = cleaner.apply(newName); - if (removed.removeIf(n -> cleaner.apply(n).equals(stripped))) { + if (removed.keySet().removeIf(n -> cleaner.apply(n).equals(stripped))) { iterator.remove(); } } if (!added.isEmpty()) { - messages.add("Intentions added after parenthesizing:\n" + StreamEx.of(added).map("\t"::concat).joining("\n")); + messages.add("Intentions added after parenthesizing:\n" + describeIntentions(added)); } if (!removed.isEmpty()) { - messages.add("Intentions removed after parenthesizing:\n" + StreamEx.of(removed).map("\t"::concat).joining("\n")); + messages.add("Intentions removed after parenthesizing:\n" + describeIntentions(removed)); } if (!messages.isEmpty()) { throw new AssertionError(String.join("\n", messages)); @@ -235,14 +235,23 @@ public class InvokeIntention extends ActionOnFile { return intentions; } + private static String describeIntentions(Map intentionMap) { + return StreamEx.ofValues(intentionMap) + .map(MadTestingUtil::getIntentionDescription) + .map("\t"::concat).joining("\n"); + } + private void restoreAfterPotentialPsiTextInconsistency() { PushedFilePropertiesUpdater.getInstance(getProject()).filePropertiesChanged(getVirtualFile(), Conditions.alwaysTrue()); } protected List extractCommentsReformattedToSingleWhitespace(PsiFile file) { return PsiTreeUtil.findChildrenOfType(file, PsiComment.class) - .stream() - .filter(comment -> myPolicy.trackComment(comment)).map(comment -> comment.getText().replaceAll("[\\s*]+", " ")).collect(Collectors.toList()); + .stream() + .filter(myPolicy::trackComment) + .map(PsiElement::getText) + .map(text -> text.replaceAll("[\\s*]+", " ")) + .collect(Collectors.toList()); } private static void checkNoNewErrors(Project project, Editor editor, String intentionString) { @@ -250,7 +259,7 @@ public class InvokeIntention extends ActionOnFile { if (!errors.isEmpty()) { throw new AssertionError("New highlighting errors introduced after invoking " + intentionString + "\nIf this is correct, add it to IntentionPolicy#mayBreakCode." + - "\nErrors found: " + StringUtil.join(errors, i -> shortInfoText(i), ",")); + "\nErrors found: " + StringUtil.join(errors, InvokeIntention::shortInfoText, ",")); } }