Package com.sun.codemodel

Examples of com.sun.codemodel.JDefinedClass.method()


    private void addToStringMethod(ClassOutline co,
                                   JClass delegateImpl,
                                   JFieldRef toStringDelegateStyleParam) {
        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);
       
View Full Code Here


    final JClass xmladapter = outline.getCodeModel().ref(XmlAdapter.class).narrow(Integer.class).narrow(Boolean.class);
    booleanConverter._extends(xmladapter);
   
    // toString
    final JMethod unmarshal = booleanConverter.method(JMod.PUBLIC, Boolean.class, "unmarshal");
    final JVar stringConstructorArg = unmarshal.param(JMod.FINAL, Integer.class, "i");
    unmarshal.annotate(Override.class);
    unmarshal._throws(Exception.class);
    unmarshal.body()._return(JOp.cond(stringConstructorArg.eq(JExpr._null()), JExpr._null(), stringConstructorArg.eq(JExpr.lit(1))));
   
View Full Code Here

    unmarshal.annotate(Override.class);
    unmarshal._throws(Exception.class);
    unmarshal.body()._return(JOp.cond(stringConstructorArg.eq(JExpr._null()), JExpr._null(), stringConstructorArg.eq(JExpr.lit(1))));
   
    // toString
    final JMethod marshal = booleanConverter.method(JMod.PUBLIC, Integer.class, "marshal");
    final JVar unmarshallparam = marshal.param(JMod.FINAL, Boolean.class, "b");
    marshal.annotate(Override.class);
    marshal._throws(Exception.class);
    marshal.body()._return(JOp.cond(unmarshallparam.eq(JExpr._null()), JExpr._null(), JOp.cond(unmarshallparam, JExpr.lit(1), JExpr.lit(0))));
View Full Code Here

  private JDefinedClass createNestedPrefixCustomizer(final ClassOutlineImpl cc) throws JClassAlreadyExistsException {
    final JDefinedClass namespacebeautyfier = cc.implClass._class(JMod.PRIVATE | JMod.STATIC | JMod.FINAL, "NameSpaceBeautyfier");
    namespacebeautyfier._extends(NamespacePrefixMapper.class);

    final JMethod namespacebeautyfiergetpreferredprefix = namespacebeautyfier.method(JMod.PUBLIC, stringClass, "getPreferredPrefix");
    namespacebeautyfiergetpreferredprefix.annotate(Override.class);
    namespacebeautyfiergetpreferredprefix.javadoc().append("Internal method!\n");
    namespacebeautyfiergetpreferredprefix.javadoc().append(
        "<p>Customizing Namespace Prefixes During Marshalling to a more readable format.</p>\n");
    namespacebeautyfiergetpreferredprefix.javadoc().append("<p>The default output is like:</p>\n");
View Full Code Here

        JExpr.ref("Double").invoke("parseDouble").arg(JExpr.direct("coords[1]")));
    stringArgConstructor.body()._if(JExpr.ref(varCoords.name()).ref("length").eq(JExpr.lit(3)))._then().assign(
        JExpr.refthis(altitude.name()), JExpr.ref("Double").invoke("parseDouble").arg(JExpr.direct("coords[2]")));

    // toString
    final JMethod toString = coordinateClass.method(JMod.PUBLIC, stringClass, "toString");
    toString.annotate(Override.class);
    final JVar sbVar = toString.body().decl(stringBuilderClass, "sb", JExpr._new(stringBuilderClass));
    toString.body().add(sbVar.invoke("append").arg(longitude));
    toString.body().add(sbVar.invoke("append").arg(","));
    toString.body().add(sbVar.invoke("append").arg(latitude));
View Full Code Here

        for (final JMethod m : methodsToRemove) {
          candidateClass.methods().remove(m);
        }
        // Add a new getter method returning the (wrapped) field added.
        // CODE: public I<T> getFieldname() { ... };
        final JMethod method = candidateClass.method(JMod.PUBLIC, newInterfaceClass, "get" + Util.upperFirst(jFieldVar.name()));

        // CODE: if (fieldName == null) fieldName = new C<T>();
        method.body()._if(JExpr.ref(jFieldVar.name()).eq(JExpr._null()))._then().assign(JExpr.ref(jFieldVar.name()),
            JExpr._new(newCollectionClass));
View Full Code Here

   protected void createWithMethod(FieldOutline fieldOutline) {
      final JDefinedClass implClass = fieldOutline.parent().implClass;
      final String fieldName = fieldOutline.getPropertyInfo().getName(false);
      final String propertyName = fieldOutline.getPropertyInfo().getName(true);

      JMethod method = implClass.method(JMod.PUBLIC, fieldOutline.getRawType(), "with" + propertyName);

      JBlock body = method.body();

      JConditional _if = body._if(JExpr.refthis(fieldName).eq(JExpr._null()));
      JBlock _then = _if._then();
View Full Code Here

      final JDefinedClass implClass = fieldOutline.parent().implClass;
      final String propertyName = fieldOutline.getPropertyInfo().getName(true);
      final JClass elementClass = fieldOutline.getRawType().boxify().getTypeParameters().get(0);
      final JPrimitiveType INT = fieldOutline.parent().parent().getCodeModel().INT;

      JMethod method = implClass.method(JMod.PUBLIC, elementClass, "with" + propertyName);
      JVar index = method.param(INT, "index");

      JBlock body = method.body();

      JVar list = body.decl(fieldOutline.getRawType(), "list", JExpr._this().invoke("get" + propertyName));
View Full Code Here

   protected void createListWithNewMethod(FieldOutline fieldOutline) {
      final JDefinedClass implClass = fieldOutline.parent().implClass;
      final String propertyName = fieldOutline.getPropertyInfo().getName(true);
      final JClass elementClass = fieldOutline.getRawType().boxify().getTypeParameters().get(0);

      JMethod method = implClass.method(JMod.PUBLIC, elementClass, "withNew" + propertyName);

      JBlock body = method.body();

      JVar element = body.decl(elementClass, "value", JExpr._new(elementClass));
View Full Code Here

    private void generateAdapterMethods( final JCodeModel cm, final PackageOutline p )
    {
        final JDefinedClass of = p.objectFactory();

        // createCalendar
        final JMethod createCalendar = of.method( JMod.STATIC, cm.ref( Calendar.class ), "createCalendar" );
        JVar value = createCalendar.param( JMod.FINAL, XMLGregorianCalendar.class, "value" );
        createCalendar.body().directStatement( "// " + getMessage( "title" ) );
        createCalendar.body()._return(
            JOp.cond( value.eq( JExpr._null() ), JExpr._null(), value.invoke( "toGregorianCalendar" ) ) );
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.