Package com.sun.codemodel

Examples of com.sun.codemodel.JMethod.body()


        final JDefinedClass implementation = co.implClass;
        final JMethod toStringMethod = implementation.method(JMod.PUBLIC, String.class, "toString");
        final JInvocation invoke = delegateImpl.staticInvoke("valueOf");
        invoke.arg(JExpr._this());
        invoke.arg(toStringDelegateStyleParam);
        toStringMethod.body()._return(invoke);
       
        JDocComment doc = toStringMethod.javadoc();
        doc.add("Generates a String representation of the contents of this type.");
        doc.add("\nThis is an extension method, produced by the 'ts' xjc plugin");
        toStringMethod.annotate(Override.class);
View Full Code Here


  }

  private JMethod generateValidateMethod(final ClassOutlineImpl cc) {
    final JMethod generateValidate = cc.implClass.method(JMod.PRIVATE | JMod.STATIC, cc.implClass.owner().BOOLEAN, "validate");
    final JVar unmarshallValidateVar = generateValidate.param(JMod.FINAL, jaxbUnmarshallerClass, "unmarshaller");
    final JTryBlock tryValidateBlock = generateValidate.body()._try();
    final JVar schemaFactoryVar = tryValidateBlock.body().decl(schemaFactoryClass, "sf",
        schemaFactoryClass.boxify().staticInvoke("newInstance").arg(xmlConstantsClass.boxify().staticRef("W3C_XML_SCHEMA_NS_URI")));
    final JVar schemaFileVar = tryValidateBlock.body().decl(fileClass, "schemaFile", JExpr._new(fileClass).arg(schemaLocationVar));
    final JVar schemaVar = tryValidateBlock.body().decl(schemaClass, "schema", schemaFactoryVar.invoke("newSchema").arg(schemaFileVar));
    tryValidateBlock.body().add(unmarshallValidateVar.invoke("setSchema").arg(schemaVar));
View Full Code Here

    final JVar schemaVar = tryValidateBlock.body().decl(schemaClass, "schema", schemaFactoryVar.invoke("newSchema").arg(schemaFileVar));
    tryValidateBlock.body().add(unmarshallValidateVar.invoke("setSchema").arg(schemaVar));
    tryValidateBlock.body()._return(JExpr.TRUE);
    final JBlock catchValidateBlock = tryValidateBlock._catch(saxExceptionClass.boxify()).body();
    catchValidateBlock.directStatement("_x.printStackTrace();");
    generateValidate.body()._return(JExpr.FALSE);
    return generateValidate;
  }

  /**
   * Generates an expression that evaluates to "new QName(...)"
View Full Code Here

    // annotate with @Override
    clone.annotate(Override.class);
    // clone._throws(CloneNotSupportedException.class);

    final JVar copy = clone.body().decl(implClass, "copy");

    if (extends1.fullName().equals("java.lang.Object")) {
      final JTryBlock ctry = clone.body()._try();
      ctry.body().assign(copy, JExpr.cast(implClass, JExpr._super().invoke("clone")));
      ctry._catch(cloneNotSupportedException.boxify()).body()._throw(JExpr._new(internalError.boxify()).arg(JExpr.direct("_x.toString()")));
View Full Code Here

    // clone._throws(CloneNotSupportedException.class);

    final JVar copy = clone.body().decl(implClass, "copy");

    if (extends1.fullName().equals("java.lang.Object")) {
      final JTryBlock ctry = clone.body()._try();
      ctry.body().assign(copy, JExpr.cast(implClass, JExpr._super().invoke("clone")));
      ctry._catch(cloneNotSupportedException.boxify()).body()._throw(JExpr._new(internalError.boxify()).arg(JExpr.direct("_x.toString()")));
    } else {
      clone.body().assign(copy, JExpr.cast(implClass, JExpr._super().invoke("clone")));
    }
View Full Code Here

    if (extends1.fullName().equals("java.lang.Object")) {
      final JTryBlock ctry = clone.body()._try();
      ctry.body().assign(copy, JExpr.cast(implClass, JExpr._super().invoke("clone")));
      ctry._catch(cloneNotSupportedException.boxify()).body()._throw(JExpr._new(internalError.boxify()).arg(JExpr.direct("_x.toString()")));
    } else {
      clone.body().assign(copy, JExpr.cast(implClass, JExpr._super().invoke("clone")));
    }

    for (final JFieldVar jFieldVar : fields) {
      if (jFieldVar.type().fullName().equals("java.lang.String")) {
        continue;
View Full Code Here

              LOG.info("333b>>>>>>>" + clazz.fullName());
            }
          }
        }

        clone.body().assign(copy.ref(jFieldVar),
            JExpr._new(arrayList.narrow(clazz)).arg(JExpr.direct("get" + Util.upperFirst(jFieldVar.name()) + "().size()")));
        final JForEach forEach = clone.body().forEach(clazz, "iter", jFieldVar);
        if (forEach.var().type().fullName().equals("java.lang.Object") || enums.contains(forEach.var().type().fullName()) || forEach.var().type().fullName().equals("java.lang.String") ){
          forEach.body().add(copy.ref(jFieldVar).invoke("add").arg(forEach.var()));
          LOG.info("444a>>>>>>>" + forEach.var().type().fullName());
View Full Code Here

          }
        }

        clone.body().assign(copy.ref(jFieldVar),
            JExpr._new(arrayList.narrow(clazz)).arg(JExpr.direct("get" + Util.upperFirst(jFieldVar.name()) + "().size()")));
        final JForEach forEach = clone.body().forEach(clazz, "iter", jFieldVar);
        if (forEach.var().type().fullName().equals("java.lang.Object") || enums.contains(forEach.var().type().fullName()) || forEach.var().type().fullName().equals("java.lang.String") ){
          forEach.body().add(copy.ref(jFieldVar).invoke("add").arg(forEach.var()));
          LOG.info("444a>>>>>>>" + forEach.var().type().fullName());
        } else {
          forEach.body().add(copy.ref(jFieldVar).invoke("add").arg(forEach.var().invoke("clone")));
View Full Code Here

          forEach.body().add(copy.ref(jFieldVar).invoke("add").arg(forEach.var().invoke("clone")));
          LOG.info("444b>>>>>>>" + forEach.var().type().fullName()+".clone()");
        }
      } else {
        final JExpression cond = JOp.cond(jFieldVar.eq(JExpr._null()), JExpr._null(), JExpr.cast(jFieldVar.type(), jFieldVar.invoke("clone")));
        clone.body().assign(copy.ref(jFieldVar), cond);
        LOG.info(jFieldVar.type().fullName());
      }
    }
    clone.body()._return(copy);
  }
View Full Code Here

        final JExpression cond = JOp.cond(jFieldVar.eq(JExpr._null()), JExpr._null(), JExpr.cast(jFieldVar.type(), jFieldVar.invoke("clone")));
        clone.body().assign(copy.ref(jFieldVar), cond);
        LOG.info(jFieldVar.type().fullName());
      }
    }
    clone.body()._return(copy);
  }
}
View Full Code Here

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.