Package org.codehaus.jam

Examples of org.codehaus.jam.JClass


                      mJoust.getExpressionFactory().
                      createString(clazz.getQualifiedName()));

    for(int i=0; i<methods.length; i++) {
      String fieldName = FIELD_PREFIX+ methods[i].getSimpleName();
      JClass type = methods[i].getReturnType();
      String typeName = (!mImplementAnnotationTypes) ?
        getImplClassForIfGenerated(type) : type.getQualifiedName();
      Variable fieldVar =
        mJoust.writeField(Modifier.PRIVATE,typeName,fieldName,null);
      { // write the 'getter' implementation
        mJoust.startMethod(Modifier.PUBLIC,
                           typeName,
                           methods[i].getSimpleName(),
                           null, // no parameters
                           null, // no parameters
                           null // no throws
                           );
        mJoust.writeReturnStatement(fieldVar);
        mJoust.endMethodOrConstructor();
      }
      { // write the 'setter' implementation
        String[] paramTypeNames = new String[] {typeName};
        String[] paramNames = new String[] {"in"};
        Variable[] params = mJoust.startMethod(Modifier.PUBLIC,
                                               "void",
                                               SETTER_PREFIX+ methods[i].getSimpleName(),
                                               paramTypeNames,
                                               paramNames,
                                               null // no throws
        );
        mJoust.writeAssignmentStatement(fieldVar,params[0]);
        mJoust.endMethodOrConstructor();
      }
      { // check to see if we need to also do annogen for the field's type
        JClass c = clazz.forName(typeName);
        if (c.isAnnotationType()) {
          if (!mClassesLeftTodo.contains(c) && !mClassesDone.contains(c)) {
            mClassesLeftTodo.add(c);
          }
        }
      }
View Full Code Here


  // ========================================================================
  // Private methods

  private String getImplClassForIfGenerated(JClass clazz) {
    if (clazz.isArrayType()) {
      JClass comp = clazz.getArrayComponentType();
      StringWriter out = new StringWriter();
      out.write(getImplClassForIfGenerated(comp));
      for(int i=0; i<clazz.getArrayDimensions(); i++) out.write("[]");
      return out.toString();
    } else if (mClassesLeftTodo.contains(clazz) || mClassesDone.contains(clazz)) {
View Full Code Here

      //
      // process getters
      //
      if (name.startsWith("get") && name.length() > 3 ||
        name.startsWith("is") && name.length() > 2) {
        JClass typ = methods[i].getReturnType();
        //FIXME we just want the name - this forces the whole thing to be resolved
        // need to either getReturnTypeRef() or change ClassImpl so that it lazily builds itself
        if (typ == null) continue; // must have a typ and have
        if (methods[i].getParameters().length > 0) continue; //no params
        if (name.startsWith("get")) {
          name = name.substring(3);
        } else {
          name = name.substring(2);
        }
        JProperty prop = (JProperty)name2prop.get(name);
        if (prop == null) {
          prop = declared ? clazz.addNewDeclaredProperty(name,methods[i],null) :
            clazz.addNewProperty(name,methods[i],null);
          name2prop.put(name,prop);
        } else {
          if (typ.equals(prop.getType())) {
            ((PropertyImpl)prop).setGetter(methods[i]); // cheater
          }
        }
      }

      //
      // process setters
      //
      if (name.startsWith("set") && name.length() > 3) {
        if (methods[i].getParameters().length != 1) continue; //1 param reqd
        JClass type = methods[i].getParameters()[0].getType();
        name = name.substring(3);
        JProperty prop = (JProperty)name2prop.get(name);
        if (prop == null) {
          prop = declared ? clazz.addNewDeclaredProperty(name,null,methods[i]) :
            clazz.addNewProperty(name,null,methods[i]);
          name2prop.put(name,prop);
        } else {
          if (type.equals(prop.getType())) {
            // if it's the same type, cool - just add the getter
            ((PropertyImpl)prop).setSetter(methods[i]); // with a sneaky cast
          }
        }
      }
View Full Code Here

  // JamClassLoader implementation

  public final JClass loadClass(String fd)
  {
    fd = fd.trim();
    JClass out = cacheGet(fd);
    if (out != null) return out;
    if (fd.indexOf('[') != -1) { // must be some kind of array name
      String normalFd = ArrayClassImpl.normalizeArrayName(fd);
      out = cacheGet(normalFd); // an array by any other name?
      if (out == null) {
View Full Code Here

    builders.toArray(barray);
    JamClassBuilder out = new CompositeJamClassBuilder(barray);
    out.init((ElementContext)ctx);
    if (log.isVerbose(this)) {
      log.verbose("returning a composite of "+barray.length+" class builders.");
      JClass c = out.build("java.lang","Object");
      c = out.build("javax.ejb","SessionBean");
    }
    return out;

  }
View Full Code Here

    if (valueObj instanceof AnnotationDesc) {
      MAnnotation nested = dest.createNestedValue(memberName,typeName);
      populateAnnotation(nested,(AnnotationDesc)valueObj,sp);
    } else if (valueObj instanceof Number || valueObj instanceof Boolean) {
      String tn = JavadocClassBuilder.getFdFor(returnType);
      JClass type = mContext.getClassLoader().loadClass(tn);
      dest.setSimpleValue(memberName,valueObj,type);
    } else if (valueObj instanceof FieldDoc) {
      String tn = JavadocClassBuilder.getFdFor(((FieldDoc)valueObj).containingClass());
      // this means it's an enum constant
      JClass type = mContext.getClassLoader().loadClass(tn);
      String val = ((FieldDoc)valueObj).name(); //REVIEW is this right?
      dest.setSimpleValue(memberName,val,type);
    } else if (valueObj instanceof ClassDoc) {
      String tn = JavadocClassBuilder.getFdFor(((FieldDoc)valueObj).containingClass());
       JClass clazz = mContext.getClassLoader().loadClass(tn);
      dest.setSimpleValue(memberName,clazz,loadClass(JClass.class));
    } else if (valueObj instanceof String) {
      String v = ((String)valueObj).trim();
      if (v.startsWith("\"") && v.endsWith("\"")) {
        //javadoc gives us the quotes, which seems kinda dumb.  just deal.
View Full Code Here

        (memberName, annType, valueArray.length);
      for(int i=0; i<anns.length; i++) {
        populateAnnotation(anns[i],(AnnotationDesc)valueArray[i],sp);
      }
    } else if (valueArray[0] instanceof Number || valueArray[0] instanceof Boolean) {
      JClass type = loadClass(returnType);
      dest.setSimpleValue(memberName,annValueArray,type);
    } else if (valueArray[0] instanceof FieldDoc) {
      // this means it's an array of an enum constants
      String enumTypeName = JavadocClassBuilder.getFdFor(
        ((FieldDoc)valueArray[0]).containingClass());
      JClass memberType = loadClass("[L"+enumTypeName+";");
      String[] value = new String[valueArray.length];
      for(int i=0; i<valueArray.length; i++) {
        value[i] = ((FieldDoc)valueArray[i]).name(); //REVIEW is this right?
      }
      dest.setSimpleValue(memberName,value,memberType);
View Full Code Here

    print(root, 0, out);
  }

  public void print(JamClassIterator iter, PrintWriter out) {
    while(iter.hasNext()) {
      JClass clazz = iter.nextClass();
      out.println("------------------------------");
      out.println(clazz.getQualifiedName());
      out.println("------------------------------");
      print(clazz,out);
      out.println();
    }
  }
View Full Code Here

            (methods[i].getName(),
             methods[i].getReturnType().getComponentType().getName(),
             anns.length);
          for(int j=0; j<anns.length; j++) populateAnnotation(nested[j],anns[j]);
        } else {
          JClass type = mContext.getClassLoader().
            loadClass(methods[i].getReturnType().getName());
          dest.setSimpleValue(methods[i].getName(),value,type);
        }
      } catch (IllegalAccessException e) {
        mLogger.warning(e);
View Full Code Here

                                           arrayFD+"' is malformed");
      }
    } else {
      int dims = arrayFD.lastIndexOf("[")+1;
      String compFd = arrayFD.substring(dims,dims+1);
      JClass primType = loader.loadClass(compFd);
      if (primType == null) {
        // if it didn't end with ';', it has to be a valid primitive
        // type name or it's effed
        throw new IllegalArgumentException("array type field descriptor '"+
                                           arrayFD+"' is malformed");
View Full Code Here

TOP

Related Classes of org.codehaus.jam.JClass

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.