[OC-23442] fix move multiple psi preview html

GitOrigin-RevId: 57e19c65b66cc7fdb52f13b5b07405f81ba2b38c
This commit is contained in:
Jan Kleprlik
2023-03-28 19:10:47 +02:00
committed by intellij-monorepo-bot
parent e288f74d8e
commit 43a43dfadd
3 changed files with 34 additions and 18 deletions

View File

@@ -1 +1 @@
<p><icon src="source"/>&nbsp;doSmth &rarr; <icon src="target"/>&nbsp;beforeAbstractMethodNoClass</p>
<p><icon src="source_doSmth"/>&nbsp;doSmth &rarr; <icon src="target_beforeAbstractMethodNoClass"/>&nbsp;beforeAbstractMethodNoClass</p>

View File

@@ -231,7 +231,7 @@ public class IntentionPreviewTest extends LightJavaCodeInsightFixtureTestCase {
myFixture.configureByText("Test.java", "public class Test {} void <caret>method() {}");
IntentionAction action = myFixture.findSingleIntention("Move member into class");
myFixture.checkIntentionPreviewHtml(action,
"<p><icon src=\"source\"/>&nbsp;method &rarr; <icon src=\"target\"/>&nbsp;Test</p>");
"<p><icon src=\"source_method\"/>&nbsp;method &rarr; <icon src=\"target_Test\"/>&nbsp;Test</p>");
}
public void testNavigate() {

View File

@@ -269,25 +269,42 @@ public interface IntentionPreviewInfo {
HtmlBuilder builder = new HtmlBuilder();
sources.forEach((source) -> {
Icon sourceIcon = source.getIcon(0);
if (sourceIcon instanceof DeferredIcon) {
sourceIcon = ((DeferredIcon)sourceIcon).evaluate();
}
Icon targetIcon = target.getIcon(0);
if (targetIcon instanceof DeferredIcon) {
targetIcon = ((DeferredIcon)targetIcon).evaluate();
}
if (sources.isEmpty()) return new Html(builder.wrapWith("p"));
var source = sources.get(0);
Icon targetIcon = getIcon(target);
Icon sourceIcon = getIcon(source);
builder.append(getHtmlMoveFragment(
sourceIcon,
targetIcon,
source.getName(),
explicitTargetName == null ? target.getName() : explicitTargetName));
for (int i = 1; i < sources.size(); i++) {
source = sources.get(i);
sourceIcon = getIcon(source);
builder
.append(HtmlChunk.br())
.append(getHtmlMoveFragment(
sourceIcon,
targetIcon,
source.getName(),
explicitTargetName == null ? target.getName() : explicitTargetName));
}
builder.append(getHtmlMoveFragment(
sourceIcon,
targetIcon,
source.getName(),
explicitTargetName == null ? target.getName() : explicitTargetName));
});
return new Html(builder.wrapWith("p"));
}
private static Icon getIcon(@NotNull PsiNamedElement source) {
Icon icon = source.getIcon(0);
if (icon instanceof DeferredIcon) {
icon = ((DeferredIcon)icon).evaluate();
}
return icon;
}
@NotNull
private static HtmlChunk getHtmlMoveFragment(@Nullable Icon sourceIcon,
@Nullable Icon targetIcon,
@@ -299,7 +316,6 @@ public interface IntentionPreviewInfo {
.append(" ").append(HtmlChunk.htmlEntity("&rarr;")).append(" ")
.append(getIconChunk(targetIcon, "target_" + targetName))
.append(Objects.requireNonNull(targetName))
.append(HtmlChunk.br())
.toFragment();
}