Package com.sun.codemodel

Examples of com.sun.codemodel.JDefinedClass


      convertComplexTypesToSimpleTypes((ClassOutlineImpl) classOutline);
    }
  }

  private void convertComplexTypesToSimpleTypes(final ClassOutlineImpl cc) {
    final JDefinedClass implClass = cc.implClass;
    // if no fields are present return
    if (implClass.fields().isEmpty()) {
      return;
    }

    for (final JFieldVar jFieldVar : implClass.fields().values()) {

      if (jFieldVar.name().equals("coordinates")) {
        LOG.info("1+++ " + cc.implRef.name() + " " + jFieldVar.type().name() + " " + jFieldVar.name());

        final JDefinedClass candidateClass = cc.implClass;
        final JClass newInterfaceClass = candidateClass.owner().ref(interfaceClass).narrow(pool.getClassCoordinate());
        final JClass newCollectionClass = candidateClass.owner().ref(collectionClass).narrow(pool.getClassCoordinate());

        jFieldVar.type(newInterfaceClass);
        // Find original getter and setter methods to remove.
        final ArrayList<JMethod> methodsToRemove = new ArrayList<JMethod>();
        for (final JMethod m : candidateClass.methods()) {
          if (m.name().equals("set" + Util.upperFirst(jFieldVar.name())) || m.name().equals("get" + Util.upperFirst(jFieldVar.name()))) {
            methodsToRemove.add(m);
          }
        }
        // Remove original getter and setter methods.
        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


  }

  private void createArgConstructor(final ClassOutlineImpl cc, final Collection<JFieldVar> required) {
    final StringBuffer debugOut = new StringBuffer();
   
    JDefinedClass nestedBuilderClass ;
    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());
View Full Code Here

    super(outline, opts, errorHandler, pool);
  }

  @Override
  public void execute() {
    JDefinedClass elementType = null;
    for (final ClassOutline classOutline : outline.getClasses()) {
      final ClassOutlineImpl cc = (ClassOutlineImpl) classOutline;
      if (cc.implRef.name().equals("Icon") && cc.implClass._extends().name().equals("BasicLink")) {
        LOG.info(XJCJavaForKmlApiPlugin.PLUGINNAME + " link class found.");
        elementType = cc.implClass;
View Full Code Here

  public void execute() {
 
    // Get the default package from options.
    for (final PackageOutline packageoutline : outline.getAllPackageContexts()) {
      // Get the factory class from the default package.
      final JDefinedClass factoryClass = packageoutline.objectFactory();
      if (factoryClass != null) {
        // LOG.info(XJCJavaForKmlApiPlugin.PLUGINNAME+" pkg:          " + pkg.name());
        LOG.info(XJCJavaForKmlApiPlugin.PLUGINNAME + " factoryClass: " + factoryClass.name());
        LOG.info(XJCJavaForKmlApiPlugin.PLUGINNAME + " factoryClass: " + factoryClass.fullName());
        LOG.info(XJCJavaForKmlApiPlugin.PLUGINNAME + " factoryClass: " + factoryClass.methods().size());
        factoryClass.methods().clear();
        LOG.info(XJCJavaForKmlApiPlugin.PLUGINNAME + " factoryClass: " + factoryClass.methods().size());
//        factoryClass.fields().clear();
        final JPackage parent = (JPackage)factoryClass.parentContainer();
        parent.remove(factoryClass);
      }
    }

    final JPackage rootPackage = Util.getKmlClassPackage(outline);
View Full Code Here

  @Override
  public void execute() {
    LOG.info(XJCJavaForKmlApiPlugin.PLUGINNAME + " generate Fluent API");
    for (final ClassOutline classOutline : outline.getClasses()) {
      final ClassOutlineImpl cc = (ClassOutlineImpl) classOutline;
      final JDefinedClass implClass = classOutline.implClass;

      for (final FieldOutline fieldOutline : classOutline.getDeclaredFields()) {
        JType type = TypeUtil.getCommonBaseType(codeModel, Util.listPossibleTypes(cc, fieldOutline.getPropertyInfo()));
        if (((type.name().equals("BasicLink") || ((type.name().equals("Link")) && Util.upperFirst(fieldOutline.getPropertyInfo().getName(false)).equals("Icon"))))) {
          /*
 
View Full Code Here

            if (mapping != null) {
                typeAnno = mapping.getType();
            }
        }
        if (typeAnno != null && typeAnno.getTypeClass() instanceof JDefinedClass) {
            JDefinedClass dc = (JDefinedClass)typeAnno.getTypeClass();
            if (dc.isAbstract()) {
                //no default values for abstract classes
                typeAnno = null;
            }
        }
        if (typeAnno != null) {
View Full Code Here

                writer.write(" {};");
            } else if (DEFAULT_TYPE_MAP.contains(tp.fullName())) {
                writeDefaultType(writer, tp, path);
                writer.write(";");
            } else if (tp instanceof JDefinedClass) {
                JDefinedClass jdc = (JDefinedClass)tp;
                if (jdc.getClassType() == ClassType.ENUM) {
                    //no way to get the field list as it's private with
                    //no accessors :-(
                    try {
                        Field f = jdc.getClass().getDeclaredField("enumConstantsByName");
                        f.setAccessible(true);
                        Map map = (Map)f.get(jdc);
                        Set<String> values = CastUtils.cast(map.keySet());
                        String first = defaultValues.chooseEnumValue(path, values);
                        writer.write(tp.fullName());
                        writer.write(".");                       
                        writer.write(first);                       
                        writer.write(";");
                    } catch (Exception e) {
                        IOException ex = new IOException(e.getMessage());
                        ex.initCause(e);
                        throw ex;
                    }
                } else if (jdc.isAbstract()) {
                    writer.write("null;");
                } else {
                    writer.write("new ");
                    writer.write(tp.fullName());
                    writer.write("();");
View Full Code Here

            if (mapping != null) {
                typeAnno = mapping.getType();
            }
        }
        if (typeAnno != null && typeAnno.getTypeClass() instanceof JDefinedClass) {
            JDefinedClass dc = (JDefinedClass)typeAnno.getTypeClass();
            if (dc.isAbstract()) {
                //no default values for abstract classes
                typeAnno = null;
            }
        }
        if (typeAnno != null) {
View Full Code Here

                writer.write(" {};");
            } else if (DEFAULT_TYPE_MAP.contains(tp.fullName())) {
                writeDefaultType(writer, tp, path);
                writer.write(";");
            } else if (tp instanceof JDefinedClass) {
                JDefinedClass jdc = (JDefinedClass)tp;
                if (jdc.getClassType() == ClassType.ENUM) {
                    //no way to get the field list as it's private with
                    //no accessors :-(
                    try {
                        Field f = jdc.getClass().getDeclaredField("enumConstantsByName");
                        f.setAccessible(true);
                        Map map = (Map)f.get(jdc);
                        Set<String> values = CastUtils.cast(map.keySet());
                        String first = defaultValues.chooseEnumValue(path, values);
                        writer.write(tp.fullName());
                        writer.write(".");
                        writer.write(first);
                        writer.write(";");
                    } catch (Exception e) {
                        IOException ex = new IOException(e.getMessage());
                        ex.initCause(e);
                        throw ex;
                    }
                } else if (jdc.isAbstract()) {
                    writer.write("null;");
                } else {
                    writer.write("new ");
                    writer.write(tp.fullName());
                    writer.write("();");
View Full Code Here

            if (mapping != null) {
                typeAnno = mapping.getType();
            }
        }
        if (typeAnno != null && typeAnno.getTypeClass() instanceof JDefinedClass) {
            JDefinedClass dc = (JDefinedClass)typeAnno.getTypeClass();
            if (dc.isAbstract()) {
                //no default values for abstract classes
                typeAnno = null;
            }
        }
        if (typeAnno != null) {
View Full Code Here

TOP

Related Classes of com.sun.codemodel.JDefinedClass

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.