Search in sources :

Example 1 with CodeGenerationException

use of com.intellij.uiDesigner.compiler.CodeGenerationException in project intellij-community by JetBrains.

the class PreviewNestedFormLoader method generateStubClass.

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());
    }
    FileUtil.writeToFile(new File(myTempPath, generatedClassName + ".class"), data);
}
Also used : NonNls(org.jetbrains.annotations.NonNls) CodeGenerationException(com.intellij.uiDesigner.compiler.CodeGenerationException) ByteArrayInputStream(java.io.ByteArrayInputStream) PsiClassWriter(com.intellij.compiler.PsiClassWriter) FormErrorInfo(com.intellij.uiDesigner.compiler.FormErrorInfo) AsmCodeGenerator(com.intellij.uiDesigner.compiler.AsmCodeGenerator) File(java.io.File) ClassWriter(org.jetbrains.org.objectweb.asm.ClassWriter) PsiClassWriter(com.intellij.compiler.PsiClassWriter) MethodVisitor(org.jetbrains.org.objectweb.asm.MethodVisitor)

Aggregations

PsiClassWriter (com.intellij.compiler.PsiClassWriter)1 AsmCodeGenerator (com.intellij.uiDesigner.compiler.AsmCodeGenerator)1 CodeGenerationException (com.intellij.uiDesigner.compiler.CodeGenerationException)1 FormErrorInfo (com.intellij.uiDesigner.compiler.FormErrorInfo)1 ByteArrayInputStream (java.io.ByteArrayInputStream)1 File (java.io.File)1 NonNls (org.jetbrains.annotations.NonNls)1 ClassWriter (org.jetbrains.org.objectweb.asm.ClassWriter)1 MethodVisitor (org.jetbrains.org.objectweb.asm.MethodVisitor)1