示例#1
0
 /**
  * Returns a list containing each {@link Method} declared directly in this type. Inherited methods
  * are not included. Constructors, the initialization method if any, and any synthetic methods
  * created by the compiler are included in the list.
  *
  * <p>For arrays and primitive classes, the returned list is always empty.
  *
  * @return a list {@link Method} objects; the list has length 0 if no methods exist.
  */
 public List getMethods() {
   if (methods == null) {
     if (klass.isArray()) {
       methods = Collections.EMPTY_LIST;
     } else {
       methods = new ArrayList();
       addMethods(methods, true);
       addMethods(methods, false);
     }
   }
   return methods;
 }
示例#2
0
  /**
   * Gets the fully qualified name of this type. The returned name is formatted as it might appear
   * in a Java programming language declaration for objects of this type.
   *
   * <p>For primitive classes the returned name is the name of the corresponding primitive type; for
   * example, "int" is returned as the name of the class represented by {@link
   * java.lang.Integer#TYPE Integer.TYPE}.
   *
   * @return a string containing the type name.
   */
  public String getName() {
    String name = klass.getName();
    if (!klass.isArray()) {
      return name;
    }

    int dimensions = 0;
    while (name.charAt(dimensions) == '[') {
      ++dimensions;
    }

    name = name.substring(dimensions);
    char first = name.charAt(0);
    if (first == 'L') {
      name = name.substring(1, name.length() - 2).replace('/', '.');
    } else {
      switch (first) {
        case 'I':
          name = "int";
          break;
        case 'J':
          name = "long";
          break;
        case 'F':
          name = "float";
          break;
        case 'D':
          name = "double";
          break;
        case 'Z':
          name = "boolean";
          break;
        case 'C':
          name = "char";
          break;
        case 'S':
          name = "short";
          break;
        case 'B':
          name = "byte";
          break;
        case 'V':
          name = "void";
          break;
      }
    }
    while (dimensions-- != 0) {
      name += "[]";
    }
    return name;
  }