UI Designer: source generator should work exactly as ASM one

SCL-16962, SCL-16928

GitOrigin-RevId: e3ef354294726b8ed4594dbfcd9339298c6b29f1
This commit is contained in:
Nikolay.Tropin
2020-01-29 17:33:08 +00:00
committed by intellij-monorepo-bot
parent b0be129291
commit 37808e3208
3 changed files with 16 additions and 22 deletions
@@ -882,15 +882,14 @@ public final class FormSourceCodeGenerator {
final boolean borderNone = borderType.equals(BorderType.NONE);
if (!borderNone || borderTitle != null) {
if (Boolean.valueOf(System.getProperty("idea.is.internal")).booleanValue()) {
generateIdeaTitledBorder(variable, borderTitle);
return;
}
startMethodCall(variable, "setBorder");
startStaticMethodCall(BorderFactory.class, "createTitledBorder");
boolean isInternal = Boolean.valueOf(System.getProperty("idea.is.internal")).booleanValue();
Class<?> titledBorderFactoryClass = isInternal ? IdeBorderFactory.PlainSmallWithIndent.class
: BorderFactory.class;
startStaticMethodCall(titledBorderFactoryClass, "createTitledBorder");
if (!borderNone) {
startStaticMethodCall(BorderFactory.class, borderFactoryMethodName);
@@ -938,15 +937,6 @@ public final class FormSourceCodeGenerator {
}
}
private void generateIdeaTitledBorder(String variable, StringDescriptor borderTitle) {
startMethodCall(variable, "setBorder");
startStaticMethodCall(IdeBorderFactory.class, "createTitledBorder");
push(borderTitle);
endMethod();
endMethod();
}
private static boolean isCustomBorder(final LwContainer container) {
return container.getBorderTitleJustification() != 0 || container.getBorderTitlePosition() != 0 ||
container.getBorderTitleColor() != null || container.getBorderTitleFont() != null;
@@ -42,7 +42,7 @@ public class BindingTest {
private void $$$setupUI$$$() {
myRootComponent = new JPanel();
myRootComponent.setLayout(new com.intellij.uiDesigner.core.GridLayoutManager(1, 1, new java.awt.Insets(0, 0, 0, 0), -1, -1));
myRootComponent.setBorder(com.intellij.ui.IdeBorderFactory.createTitledBorder("MyTitle"));
myRootComponent.setBorder(com.intellij.ui.IdeBorderFactory$PlainSmallWithIndent.createTitledBorder(javax.swing.BorderFactory.createEtchedBorder(), "MyTitle"));
}
/**
@@ -14,6 +14,7 @@ import com.intellij.psi.search.ProjectScope;
import com.intellij.testFramework.IdeaTestUtil;
import com.intellij.testFramework.JavaPsiTestCase;
import com.intellij.testFramework.PsiTestUtil;
import com.intellij.util.ThrowableRunnable;
import java.io.IOException;
@@ -85,9 +86,7 @@ public class FormSourceCodeGeneratorTest extends JavaPsiTestCase {
}
public void testTitledBorderInternal() throws IOException {
setInternal(true);
doTest();
setInternal(false);
inInternalMode(() -> doTest());
}
public void testTitleFromBundle() throws IOException {
@@ -117,7 +116,12 @@ public class FormSourceCodeGeneratorTest extends JavaPsiTestCase {
assertEquals(expectedText, text);
}
private static void setInternal(boolean value) {
System.getProperties().setProperty("idea.is.internal", Boolean.toString(value));
private static void inInternalMode(ThrowableRunnable<IOException> runnable) throws IOException {
System.getProperties().setProperty("idea.is.internal", "true");
try {
runnable.run();
} finally {
System.getProperties().setProperty("idea.is.internal", "false");
}
}
}