Exemple #1
0
  public Method getMethod(String name, Class<?>... parameterTypes)
      throws NoSuchMethodException, SecurityException {
    checkMemberAccess(Member.PUBLIC);

    if (!type.isClassType()) throwNoSuchMethodException(name, parameterTypes);

    if (name == null) {
      throwNoSuchMethodException(name, parameterTypes);
    }
    Atom aName = Atom.findOrCreateUnicodeAtom(name);
    if (aName == RVMClassLoader.StandardClassInitializerMethodName
        || aName == RVMClassLoader.StandardObjectInitializerMethodName) {
      // <init> and <clinit> are not methods.
      throwNoSuchMethodException(name, parameterTypes);
    }

    // (1) Scan the declared public methods of this class and each of its superclasses
    RVMMethod answer = getMethodInternal1(aName, parameterTypes);
    if (answer == null) {
      // (2) Now we need to consider methods inherited from interfaces.
      //     Because we inject the requisite Miranda methods, we can do this simply
      //     by looking at this class's virtual methods instead of searching interface hierarchies.
      answer = getMethodInternal2(aName, parameterTypes);
    }
    if (answer == null) {
      throwNoSuchMethodException(name, parameterTypes);
    }
    return JikesRVMSupport.createMethod(answer);
  }
Exemple #2
0
  public Method getDeclaredMethod(String name, Class<?>... parameterTypes)
      throws NoSuchMethodException, SecurityException {
    checkMemberAccess(Member.DECLARED);

    if (!type.isClassType()) throwNoSuchMethodException(name, parameterTypes);

    if (name == null) {
      throwNoSuchMethodException(name, parameterTypes);
    }
    Atom aName = Atom.findOrCreateUnicodeAtom(name);
    if (aName == RVMClassLoader.StandardClassInitializerMethodName
        || aName == RVMClassLoader.StandardObjectInitializerMethodName) {
      // <init> and <clinit> are not methods.
      throwNoSuchMethodException(name, parameterTypes);
    }

    RVMMethod[] methods = type.asClass().getDeclaredMethods();
    RVMMethod answer = null;
    for (RVMMethod meth : methods) {
      if (meth.getName() == aName && parametersMatch(meth.getParameterTypes(), parameterTypes)) {
        if (answer == null) {
          answer = meth;
        } else {
          RVMMethod m2 = meth;
          if (answer.getReturnType().resolve().isAssignableFrom(m2.getReturnType().resolve())) {
            answer = m2;
          }
        }
      }
    }
    if (answer == null) {
      throwNoSuchMethodException(name, parameterTypes);
    }
    return JikesRVMSupport.createMethod(answer);
  }
Exemple #3
0
  public Method[] getMethods() throws SecurityException {
    checkMemberAccess(Member.PUBLIC);

    RVMMethod[] static_methods = type.getStaticMethods();
    RVMMethod[] virtual_methods = type.getVirtualMethods();
    ArrayList<Method> coll = new ArrayList<Method>(static_methods.length + virtual_methods.length);
    for (RVMMethod meth : static_methods) {
      if (meth.isPublic()) {
        coll.add(JikesRVMSupport.createMethod(meth));
      }
    }
    for (RVMMethod meth : virtual_methods) {
      if (meth.isPublic()) {
        coll.add(JikesRVMSupport.createMethod(meth));
      }
    }
    return coll.toArray(new Method[coll.size()]);
  }
Exemple #4
0
  public Field[] getFields() throws SecurityException {
    checkMemberAccess(Member.PUBLIC);

    RVMField[] static_fields = type.getStaticFields();
    RVMField[] instance_fields = type.getInstanceFields();
    ArrayList<Field> coll = new ArrayList<Field>(static_fields.length + instance_fields.length);
    for (RVMField field : static_fields) {
      if (field.isPublic()) {
        coll.add(JikesRVMSupport.createField(field));
      }
    }
    for (RVMField field : instance_fields) {
      if (field.isPublic()) {
        coll.add(JikesRVMSupport.createField(field));
      }
    }

    return coll.toArray(new Field[coll.size()]);
  }
Exemple #5
0
  public Constructor<?>[] getDeclaredConstructors() throws SecurityException {
    checkMemberAccess(Member.DECLARED);
    if (!type.isClassType()) return new Constructor[0];

    RVMMethod[] methods = type.asClass().getConstructorMethods();
    Constructor<?>[] ans = new Constructor[methods.length];
    for (int i = 0; i < methods.length; i++) {
      ans[i] = JikesRVMSupport.createConstructor(methods[i]);
    }
    return ans;
  }
Exemple #6
0
  public Field[] getDeclaredFields() throws SecurityException {
    checkMemberAccess(Member.DECLARED);
    if (!type.isClassType()) return new Field[0];

    RVMField[] fields = type.asClass().getDeclaredFields();
    Field[] ans = new Field[fields.length];
    for (int i = 0; i < fields.length; i++) {
      ans[i] = JikesRVMSupport.createField(fields[i]);
    }
    return ans;
  }
Exemple #7
0
  public Field getDeclaredField(String name) throws NoSuchFieldException, SecurityException {
    checkMemberAccess(Member.DECLARED);
    if (!type.isClassType() || name == null) throwNoSuchFieldException(name);

    Atom aName = Atom.findOrCreateUnicodeAtom(name);
    RVMField answer = type.asClass().findDeclaredField(aName);
    if (answer == null) {
      throwNoSuchFieldException(name);
    }
    return JikesRVMSupport.createField(answer);
  }
Exemple #8
0
  public Method[] getDeclaredMethods() throws SecurityException {
    checkMemberAccess(Member.DECLARED);
    if (!type.isClassType()) return new Method[0];

    RVMMethod[] methods = type.asClass().getDeclaredMethods();
    ArrayList<Method> coll = new ArrayList<Method>(methods.length);
    for (RVMMethod meth : methods) {
      if (!meth.isClassInitializer() && !meth.isObjectInitializer()) {
        coll.add(JikesRVMSupport.createMethod(meth));
      }
    }
    return coll.toArray(new Method[coll.size()]);
  }
Exemple #9
0
  public Field getField(String name) throws NoSuchFieldException, SecurityException {
    checkMemberAccess(Member.PUBLIC);
    if (!type.isClassType()) throw new NoSuchFieldException();

    Atom aName = Atom.findUnicodeAtom(name);
    if (aName == null) throwNoSuchFieldException(name);

    RVMField answer = getFieldInternal(aName);

    if (answer == null) {
      throwNoSuchFieldException(name);
    }
    return JikesRVMSupport.createField(answer);
  }
Exemple #10
0
  public Constructor<?>[] getConstructors() throws SecurityException {
    checkMemberAccess(Member.PUBLIC);
    if (!type.isClassType()) return new Constructor[0];

    RVMMethod[] methods = type.asClass().getConstructorMethods();
    ArrayList<Constructor<T>> coll = new ArrayList<Constructor<T>>(methods.length);
    for (RVMMethod method : methods) {
      if (method.isPublic()) {
        @SuppressWarnings("unchecked")
        Constructor<T> x = (Constructor<T>) JikesRVMSupport.createConstructor(method);
        coll.add(x);
      }
    }
    return coll.toArray(new Constructor[coll.size()]);
  }
Exemple #11
0
  public Constructor<T> getDeclaredConstructor(Class<?>... parameterTypes)
      throws NoSuchMethodException, SecurityException {
    checkMemberAccess(Member.DECLARED);
    if (!type.isClassType()) throwNoSuchMethodException("<init>", parameterTypes);

    RVMMethod answer = null;
    if (parameterTypes == null || parameterTypes.length == 0) {
      answer = getDefaultConstructor();
    } else {
      RVMMethod[] methods = type.asClass().getConstructorMethods();
      for (RVMMethod method : methods) {
        if (parametersMatch(method.getParameterTypes(), parameterTypes)) {
          answer = method;
          break;
        }
      }
    }
    if (answer == null) {
      throwNoSuchMethodException("<init>", parameterTypes);
    }
    return JikesRVMSupport.createConstructor(answer);
  }