示例#1
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);
  }
示例#2
0
 @Pure
 private RVMMethod getDefaultConstructor() {
   if (this.defaultConstructor == null) {
     RVMMethod defaultConstructor = null;
     RVMMethod[] methods = type.asClass().getConstructorMethods();
     for (RVMMethod method : methods) {
       if (method.getParameterTypes().length == 0) {
         defaultConstructor = method;
         break;
       }
     }
     this.defaultConstructor = defaultConstructor;
   }
   return this.defaultConstructor;
 }
示例#3
0
 @Pure
 private RVMMethod getMethodInternal2(Atom aName, Class<?>... parameterTypes) {
   RVMMethod answer = null;
   RVMMethod[] methods = type.asClass().getVirtualMethods();
   for (RVMMethod meth : methods) {
     if (meth.getName() == aName
         && meth.isPublic()
         && parametersMatch(meth.getParameterTypes(), parameterTypes)) {
       if (answer == null) {
         answer = meth;
       } else {
         RVMMethod m2 = meth;
         if (answer.getReturnType().resolve().isAssignableFrom(m2.getReturnType().resolve())) {
           answer = m2;
         }
       }
     }
   }
   return answer;
 }
示例#4
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);
  }
示例#5
0
 @Pure
 private RVMMethod getMethodInternal1(Atom aName, Class<?>... parameterTypes) {
   RVMMethod answer = null;
   for (RVMClass current = type.asClass();
       current != null && answer == null;
       current = current.getSuperClass()) {
     RVMMethod[] methods = current.getDeclaredMethods();
     for (RVMMethod meth : methods) {
       if (meth.getName() == aName
           && meth.isPublic()
           && parametersMatch(meth.getParameterTypes(), parameterTypes)) {
         if (answer == null) {
           answer = meth;
         } else {
           RVMMethod m2 = meth;
           if (answer.getReturnType().resolve().isAssignableFrom(m2.getReturnType().resolve())) {
             answer = m2;
           }
         }
       }
     }
   }
   return answer;
 }
示例#6
0
 Class<?>[] getParameterTypes() {
   return VMCommonLibrarySupport.typesToClasses(method.getParameterTypes());
 }