private void generateStubClass(final LwRootContainer rootContainer, final String generatedClassName) throws IOException, CodeGenerationException { @NonNls ClassWriter cw = new ClassWriter(ClassWriter.COMPUTE_FRAMES); cw.visit(Opcodes.V1_1, Opcodes.ACC_PUBLIC, generatedClassName, null, "java/lang/Object", ArrayUtil.EMPTY_STRING_ARRAY); cw.visitField(Opcodes.ACC_PUBLIC, PreviewFormAction.PREVIEW_BINDING_FIELD, "Ljavax/swing/JComponent;", null, null); @NonNls MethodVisitor mv = cw.visitMethod(Opcodes.ACC_PUBLIC, "<init>", "()V", null, null); mv.visitCode(); mv.visitVarInsn(Opcodes.ALOAD, 0); mv.visitMethodInsn(Opcodes.INVOKESPECIAL, "java/lang/Object", "<init>", "()V", false); mv.visitInsn(Opcodes.RETURN); mv.visitMaxs(1, 1); mv.visitEnd(); cw.visitEnd(); ByteArrayInputStream bais = new ByteArrayInputStream(cw.toByteArray()); AsmCodeGenerator acg = new AsmCodeGenerator(rootContainer, myFinder, this, true, new PsiClassWriter(myModule)); byte[] data = acg.patchClass(bais); FormErrorInfo[] errors = acg.getErrors(); if (errors.length > 0) { throw new CodeGenerationException(errors [0].getComponentId(), errors [0].getErrorMessage()); } FileOutputStream fos = new FileOutputStream(new File(myTempPath, generatedClassName + ".class")); try { fos.write(data); } finally { fos.close(); } }
private void generateStubClass(final LwRootContainer rootContainer, final String generatedClassName) throws IOException, CodeGenerationException { @NonNls ClassWriter cw = new ClassWriter(ClassWriter.COMPUTE_FRAMES); cw.visit(Opcodes.V1_1, Opcodes.ACC_PUBLIC, generatedClassName, null, "java/lang/Object", ArrayUtil.EMPTY_STRING_ARRAY); cw.visitField(Opcodes.ACC_PUBLIC, PreviewFormAction.PREVIEW_BINDING_FIELD, "Ljavax/swing/JComponent;", null, null); @NonNls MethodVisitor mv = cw.visitMethod(Opcodes.ACC_PUBLIC, "<init>", "()V", null, null); mv.visitCode(); mv.visitVarInsn(Opcodes.ALOAD, 0); mv.visitMethodInsn(Opcodes.INVOKESPECIAL, "java/lang/Object", "<init>", "()V"); mv.visitInsn(Opcodes.RETURN); mv.visitMaxs(1, 1); mv.visitEnd(); cw.visitEnd(); ByteArrayInputStream bais = new ByteArrayInputStream(cw.toByteArray()); AsmCodeGenerator acg = new AsmCodeGenerator(rootContainer, myFinder, this, true, new PsiClassWriter(myModule)); byte[] data = acg.patchClass(bais); FormErrorInfo[] errors = acg.getErrors(); if (errors.length > 0) { throw new CodeGenerationException(errors [0].getComponentId(), errors [0].getErrorMessage()); } FileOutputStream fos = new FileOutputStream(new File(myTempPath, generatedClassName + ".class")); try { fos.write(data); } finally { fos.close(); } }
private static String getNestedFormClass(Module module, final LwNestedForm nestedForm) throws CodeGenerationException { final LwRootContainer container; try { container = new PsiNestedFormLoader(module).loadForm(nestedForm.getFormFileName()); return container.getClassToBind(); } catch(Exception e) { throw new CodeGenerationException(nestedForm.getId(), e.getMessage()); } }
private void generateClientProperties(final LwComponent component, final String variable) throws CodeGenerationException { HashMap props = component.getDelegeeClientProperties(); for(final Object o : props.entrySet()) { Map.Entry e = (Map.Entry) o; startMethodCall(variable, "putClientProperty"); push((String) e.getKey()); Object value = e.getValue(); if(value instanceof StringDescriptor) { push(((StringDescriptor) value).getValue()); } else if(value instanceof Boolean) { if(((Boolean) value).booleanValue()) { pushVar("Boolean.TRUE"); } else { pushVar("Boolean.FALSE"); } } else { startConstructor(value.getClass().getName()); if(value instanceof Integer) { push(((Integer) value).intValue()); } else if(value instanceof Double) { push(((Double) value).doubleValue()); } else { throw new CodeGenerationException(component.getId(), "Unknown client property value type"); } endConstructor(); } endMethod(); } }