private static byte[] getVerifiedPatchedData(final AsmCodeGenerator codeGenerator) {
   byte[] patchedData = codeGenerator.getPatchedData();
   FormErrorInfo[] errors = codeGenerator.getErrors();
   FormErrorInfo[] warnings = codeGenerator.getWarnings();
   if (errors.length == 0 && warnings.length == 0) {
     assertNotNull("Class patching failed but no errors or warnings were returned", patchedData);
   } else if (errors.length > 0) {
     assertTrue(errors[0].getErrorMessage(), false);
   } else {
     assertTrue(warnings[0].getErrorMessage(), false);
   }
   return patchedData;
 }
  private AsmCodeGenerator initCodeGenerator(
      final String formFileName, final String className, final String testDataPath)
      throws Exception {
    String tmpPath = FileUtil.getTempDirectory();
    String formPath = testDataPath + formFileName;
    String javaPath = testDataPath + className + ".java";
    final int rc = Main.compile(new String[] {"-d", tmpPath, javaPath});

    assertEquals(0, rc);

    final String classPath = tmpPath + "/" + className + ".class";
    final File classFile = new File(classPath);

    assertTrue(classFile.exists());

    final LwRootContainer rootContainer = loadFormData(formPath);
    final AsmCodeGenerator codeGenerator =
        new AsmCodeGenerator(
            rootContainer,
            myClassFinder,
            myNestedFormLoader,
            false,
            new ClassWriter(ClassWriter.COMPUTE_FRAMES));
    final FileInputStream classStream = new FileInputStream(classFile);
    try {
      codeGenerator.patchClass(classStream);
    } finally {
      classStream.close();
      FileUtil.delete(classFile);
      final File[] inners =
          new File(tmpPath)
              .listFiles(
                  new FilenameFilter() {
                    @Override
                    public boolean accept(File dir, String name) {
                      return name.startsWith(className + "$") && name.endsWith(".class");
                    }
                  });
      if (inners != null) {
        for (File file : inners) FileUtil.delete(file);
      }
    }
    return codeGenerator;
  }
 public void testIncompatibleTypeField() throws Exception {
   AsmCodeGenerator generator = initCodeGenerator("TestIncompatibleTypeField.form", "BindingTest");
   assertEquals(
       "Cannot bind: Incompatible types. Cannot assign javax.swing.JPanel to field BindingTest.myStringField",
       generator.getErrors()[0].getErrorMessage());
 }
 public void testPrimitiveField() throws Exception {
   AsmCodeGenerator generator = initCodeGenerator("TestPrimitiveField.form", "BindingTest");
   assertEquals(
       "Cannot bind: field is of primitive type: BindingTest.myIntField",
       generator.getErrors()[0].getErrorMessage());
 }
 public void testFinalField() throws Exception {
   AsmCodeGenerator generator = initCodeGenerator("TestFinalField.form", "BindingTest");
   assertEquals(
       "Cannot bind: field is final: BindingTest.myFinalField",
       generator.getErrors()[0].getErrorMessage());
 }
 public void testNoSuchField() throws Exception {
   AsmCodeGenerator generator = initCodeGenerator("TestNoSuchField.form", "BindingTest");
   assertEquals(
       "Cannot bind: field does not exist: BindingTest.myNoSuchField",
       generator.getErrors()[0].getErrorMessage());
 }