From 6fb345af8c777dc2eb0769a38f01e57ae1d61fc7 Mon Sep 17 00:00:00 2001 From: Dmitry Jemerov Date: Sat, 13 Nov 2010 18:52:10 +0300 Subject: [PATCH] use Boolean.TRUE and Boolean.FALSE values when generating boolean client properties to bytecode (IDEA-46372) --- .../uiDesigner/compiler/AsmCodeGenerator.java | 20 ++++++++++------ .../ui-designer/testData/TestClientProp.form | 24 +++++++++++++++++++ .../uiDesigner/core/AsmCodeGeneratorTest.java | 7 ++++++ 3 files changed, 44 insertions(+), 7 deletions(-) create mode 100644 plugins/ui-designer/testData/TestClientProp.form diff --git a/java/compiler/forms-compiler/src/com/intellij/uiDesigner/compiler/AsmCodeGenerator.java b/java/compiler/forms-compiler/src/com/intellij/uiDesigner/compiler/AsmCodeGenerator.java index 90ce96e87899..961cc862e538 100644 --- a/java/compiler/forms-compiler/src/com/intellij/uiDesigner/compiler/AsmCodeGenerator.java +++ b/java/compiler/forms-compiler/src/com/intellij/uiDesigner/compiler/AsmCodeGenerator.java @@ -618,20 +618,26 @@ public class AsmCodeGenerator { if (value instanceof StringDescriptor) { generator.push(((StringDescriptor) value).getValue()); } + else if (value instanceof Boolean) { + boolean boolValue = ((Boolean) value).booleanValue(); + Type booleanType = Type.getType(Boolean.class); + if (boolValue) { + generator.getStatic(booleanType, "TRUE", booleanType); + } + else { + generator.getStatic(booleanType, "FALSE", booleanType); + } + } else { Type valueType = Type.getType(value.getClass()); generator.newInstance(valueType); generator.dup(); - if (value instanceof Boolean) { - generator.push(((Boolean) value).booleanValue()); - generator.invokeConstructor(valueType, Method.getMethod("void (boolean)")); - } - else if (value instanceof Integer) { - generator.push(((Integer) value).intValue()); + if (value instanceof Integer) { + generator.push(((Integer)value).intValue()); generator.invokeConstructor(valueType, Method.getMethod("void (int)")); } else if (value instanceof Double) { - generator.push(((Double) value).doubleValue()); + generator.push(((Double)value).doubleValue()); generator.invokeConstructor(valueType, Method.getMethod("void (double)")); } else { diff --git a/plugins/ui-designer/testData/TestClientProp.form b/plugins/ui-designer/testData/TestClientProp.form new file mode 100644 index 000000000000..e627b1247a19 --- /dev/null +++ b/plugins/ui-designer/testData/TestClientProp.form @@ -0,0 +1,24 @@ + +
+ + + + + + + + + + + + + + + + + + + + + +
diff --git a/plugins/ui-designer/testSrc/com/intellij/uiDesigner/core/AsmCodeGeneratorTest.java b/plugins/ui-designer/testSrc/com/intellij/uiDesigner/core/AsmCodeGeneratorTest.java index eb3ce4d3f83c..974741fb3d4f 100644 --- a/plugins/ui-designer/testSrc/com/intellij/uiDesigner/core/AsmCodeGeneratorTest.java +++ b/plugins/ui-designer/testSrc/com/intellij/uiDesigner/core/AsmCodeGeneratorTest.java @@ -308,6 +308,13 @@ public class AsmCodeGeneratorTest extends TestCase { assertEquals(1, instance.getContentPane().getComponentCount()); } + public void testClientProp() throws Exception { // IDEA-46372 + JComponent rootComponent = getInstrumentedRootComponent("TestClientProp.form", "BindingTest"); + assertEquals(1, rootComponent.getComponentCount()); + JTable table = (JTable) rootComponent.getComponent(0); + assertSame(Boolean.TRUE, table.getClientProperty("terminateEditOnFocusLost")); + } + public void testIdeadev14081() throws Exception { // NOTE: That doesn't really reproduce the bug as it's dependent on a particular instrumentation sequence used during form preview // (the nested form is instrumented with a new AsmCodeGenerator instance directly in the middle of instrumentation of the current form)