Package com.sun.codemodel

Examples of com.sun.codemodel.JMethod


    coordinateClassConverter._extends(xmladapter);

    // final JMethod stringArgConstructor = coordinateClassConverter.constructor(JMod.PRIVATE);

    // toString
    final JMethod marshall = coordinateClassConverter.method(JMod.PUBLIC, String.class, "marshal");
    final JVar stringConstructorArg = marshall.param(JMod.FINAL, listGenericsCoordinates, "dt");
    marshall._throws(Exception.class);
    marshall.annotate(Override.class);
    final JVar sbVarMarshall = marshall.body().decl(stringBuilderClass, "sb", JExpr._new(stringBuilderClass));
    final JForEach forMarshall = marshall.body().forEach(coordinateClass, "coord", stringConstructorArg);
    // forMarshall.body().add(sbVarMarshall.invoke("append").arg(forMarshall.var().name() + " + \" \""));
    forMarshall.body().add(sbVarMarshall.invoke("append").arg(JExpr.direct("coord + \" \"")));
    marshall.body()._return(sbVarMarshall.invoke("toString").invoke("trim"));

    // toString
    final JMethod unmarshall = coordinateClassConverter.method(JMod.PUBLIC, listGenericsCoordinates, "unmarshal");
    final JVar unmarshallparam = unmarshall.param(JMod.FINAL, String.class, "s");
    unmarshall._throws(Exception.class);
    unmarshall.annotate(Override.class);

    //    http://code.google.com/p/javaapiforkml/issues/detail?id=10
    //    changed:
    //      String[] coords = s.replaceAll(",[ ]+?", ",").trim().split(" ");
    //      to:
    //      String[] coords = s.replaceAll(",\\s+", ",").trim().split("\\s+");
    final JVar varCoords1 = unmarshall.body().decl(stringClass.array(), "coords",
        unmarshallparam.invoke("replaceAll").arg(",[\\s]+").arg(",").invoke("trim").invoke("split").arg("\\s+"));

    final JVar coordinateslist = unmarshall.body().decl(listGenericsCoordinates, "coordinates", JExpr._new(arraylistGenericsCoordinates));
    unmarshall.body()._if(JExpr.ref(varCoords1.name()).ref("length").lte(JExpr.lit(0)))._then().block()._return(coordinateslist);

    final JForEach forUnMarshall = unmarshall.body().forEach(stringClass, "string", varCoords1);
    forUnMarshall.body().add(coordinateslist.invoke("add").arg(JExpr._new(coordinateClass).arg(forUnMarshall.var())));
    unmarshall.body()._return(coordinateslist);
  }
View Full Code Here


      coordinateCreateMethods.add(altitude);
      createArgFactoryMethod(cc, coordinateCreateMethods, sigType, methodName);
     
      coordinateCreateMethods.clear();
     
      final JMethod m = objectFactory.method(JMod.PUBLIC | JMod.STATIC, sigType, "create" + methodName);
      m.javadoc().append("Create an instance of ").append(cc.ref);
      final JInvocation returntype = JExpr._new(cc.implRef);
      final JVar arg = m.param(JMod.FINAL, String.class, "coordinates");
      m.javadoc().addParam(arg).append("required parameter");
      returntype.arg(arg);
      m.body()._return(returntype);
      return;
    }
   
   
    final Collection<JFieldVar> requiredConstructorFields = Util.getConstructorRequiredFields(cc);
View Full Code Here

    //
    // generate methods like:
    // public static final SIGTYPE createFoo() {
    // return new FooImpl();
    // }
    final JMethod m = objectFactory.method(JMod.PUBLIC | JMod.STATIC, sigType, "create" + methodName);
    m.body()._return(JExpr._new(cc.implRef));
    m.javadoc().append("Create an instance of ").append(cc.ref);
  }
View Full Code Here

    }
  }
 
  private void createNoArgConstructor(final ClassOutline classOutline, final int mods) {
    // Create the default, no-arg constructor
    final JMethod defaultConstructor = classOutline.implClass.constructor(mods);
    if (mods == JMod.PRIVATE) {
    defaultConstructor.annotate(Deprecated.class);
    }
    defaultConstructor.javadoc().add("Default no-arg constructor is private. Use overloaded constructor instead! ");
    defaultConstructor.javadoc().add("(Temporary solution, till a better and more suitable ObjectFactory is created.) ");
    defaultConstructor.body().invoke("super");
  }
View Full Code Here

    forUnMarshall.body().add(coordinateslist.invoke("add").arg(JExpr._new(coordinateClass).arg(forUnMarshall.var())));
    unmarshall.body()._return(coordinateslist);
  }

  private void addSimpleSetterAndGetter(final JDefinedClass coordinateClass, final JFieldVar arg) {
    final JMethod getMethod = coordinateClass.method(JMod.PUBLIC, cm.DOUBLE, "get" + Util.upperFirst(arg.name()));
    getMethod.body()._return(arg);

    final JMethod setMethod = coordinateClass.method(JMod.PUBLIC, coordinateClass, "set" + Util.upperFirst(arg.name()));
    addConstructorParam(setMethod, arg);
    setMethod.body()._return(JExpr._this());

  }
View Full Code Here

    m.body()._return(JExpr._new(cc.implRef));
    m.javadoc().append("Create an instance of ").append(cc.ref);
  }

  private void createArgFactoryMethod(final ClassOutlineImpl cc, final Collection<JFieldVar> required, final JClass sigType, final String methodName) {
    final JMethod m = objectFactory.method(JMod.PUBLIC | JMod.STATIC, sigType, "create" + methodName);
    final Map<String, FieldOutline> fieldOutlineasMap = Util.getRequiredFieldsAsMap(cc);
    m.javadoc().append("Create an instance of ").append(cc.ref);
    final JInvocation returntype = JExpr._new(cc.implRef);
    for (final JFieldVar field : required) {

      final JVar arg = m.param(JMod.FINAL, field.type(), field.name());
      m.javadoc().addParam(arg).append("required parameter");
      returntype.arg(arg);
    }
    m.body()._return(returntype);
  }
View Full Code Here

    try {
       nestedBuilderClass = cc.implClass._class(JMod.PUBLIC | JMod.STATIC, "Builder");
 
    final Map<String, FieldOutline> fieldOutlineasMap = Util.getRequiredFieldsAsMap(cc);

    final JMethod defaultConstructor = nestedBuilderClass.constructor(JMod.PUBLIC);
    defaultConstructor.javadoc().add("Value constructor with only mandatory fields");
    defaultConstructor.body().invoke("super");

    for (final JFieldVar field : required) {
//      FieldOutline fo = fieldOutlineasMap.get(field.name());
//      if (fo == null) {
//        continue;
//      }
//      if (fo.getPropertyInfo().isCollection()) {
//        continue;
//      }
     
      final JVar arg = defaultConstructor.param(JMod.FINAL, field.type(), field.name());
      defaultConstructor.javadoc().addParam(arg).append("required parameter");
      defaultConstructor.body().assign(JExpr.refthis(field.name()), arg);
    }
   
    debugOut.append("c> " + cc.implRef.name() + " :: public " + cc.target.shortName + "(");
    for (final JFieldVar field : required) {
      debugOut.append(field.type().name() + ", ");
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));

        // CODE: return "fieldName";
        method.body()._return(JExpr.ref(jFieldVar.name()));

      }
    }
  }
View Full Code Here

    }
  }

  private void createNoArgConstructor(final ClassOutline classOutline, final int mods) {
    // Create the default, no-arg constructor
    final JMethod defaultConstructor = classOutline.implClass.constructor(mods);
    if (mods == JMod.PRIVATE) {
      defaultConstructor.annotate(Deprecated.class);
      defaultConstructor.javadoc().add("Default no-arg constructor is private. Use overloaded constructor instead! ");
      defaultConstructor.javadoc().add("(Temporary solution, till a better and more suitable ObjectFactory is created.) ");
    }
    defaultConstructor.body().invoke("super");
  }
View Full Code Here

  private void createArgConstructor(final ClassOutlineImpl cc, final Collection<JFieldVar> required) {
    final StringBuffer debugOut = new StringBuffer();
    final Map<String, FieldOutline> fieldOutlineasMap = Util.getRequiredFieldsAsMap(cc);

    final JMethod defaultConstructor = cc.implClass.constructor(JMod.PUBLIC);
    defaultConstructor.javadoc().add("Value constructor with only mandatory fields");
    defaultConstructor.body().invoke("super");

    for (final JFieldVar field : required) {
      // FieldOutline fo = fieldOutlineasMap.get(field.name());
      // if (fo == null) {
      // continue;
      // }
      // if (fo.getPropertyInfo().isCollection()) {
      // LOG.info("!!!!! " + cc.implClass.name() + " is collection " + field.name() );
      // continue;
      // }

      final JVar arg = defaultConstructor.param(JMod.FINAL, Util.removeJAXBElement(cm, field.type()), field.name());
      defaultConstructor.javadoc().addParam(arg).append("required parameter");
      defaultConstructor.body().assign(JExpr.refthis(field.name()), arg);
    }

    debugOut.append("c> " + cc.implRef.name() + " :: public " + cc.target.shortName + "(");
    for (final JFieldVar field : required) {
      debugOut.append(field.type().name() + ", ");
View Full Code Here

TOP

Related Classes of com.sun.codemodel.JMethod

Copyright © 2018 www.massapicom. 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.