Example #1
0
 /**
  * Appends names of the specified array classes to the buffer. The array elements may represent a
  * simple type, a reference type or an array type. Output format: java.lang.Object[],
  * java.io.File, void
  *
  * @param sb buffer
  * @param objs array of classes to print the names
  * @throws NullPointerException if any of the arguments is null
  */
 void appendArrayGenericType(StringBuilder sb, Type[] objs) {
   if (objs.length > 0) {
     appendGenericType(sb, objs[0]);
     for (int i = 1; i < objs.length; i++) {
       sb.append(',');
       appendGenericType(sb, objs[i]);
     }
   }
 }
Example #2
0
 /**
  * Appends the generic type representation to the buffer.
  *
  * @param sb buffer
  * @param obj the generic type which representation should be appended to the buffer
  * @throws NullPointerException if any of the arguments is null
  */
 void appendGenericType(StringBuilder sb, Type obj) {
   if (obj instanceof TypeVariable) {
     sb.append(((TypeVariable) obj).getName());
   } else if (obj instanceof ParameterizedType) {
     sb.append(obj.toString());
   } else if (obj instanceof GenericArrayType) { // XXX: is it a working branch?
     Type simplified = ((GenericArrayType) obj).getGenericComponentType();
     appendGenericType(sb, simplified);
     sb.append("[]");
   } else if (obj instanceof Class) {
     Class c = ((Class<?>) obj);
     if (c.isArray()) {
       String as[] = c.getName().split("\\[");
       int len = as.length - 1;
       if (as[len].length() > 1) {
         sb.append(as[len].substring(1, as[len].length() - 1));
       } else {
         char ch = as[len].charAt(0);
         if (ch == 'I') sb.append("int");
         else if (ch == 'B') sb.append("byte");
         else if (ch == 'J') sb.append("long");
         else if (ch == 'F') sb.append("float");
         else if (ch == 'D') sb.append("double");
         else if (ch == 'S') sb.append("short");
         else if (ch == 'C') sb.append("char");
         else if (ch == 'Z') sb.append("boolean");
         else if (ch == 'V') // XXX: is it a working branch?
         sb.append("void");
       }
       for (int i = 0; i < len; i++) {
         sb.append("[]");
       }
     } else {
       sb.append(c.getName());
     }
   }
 }