Пример #1
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()]);
  }
Пример #2
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()]);
  }
Пример #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
  @Inline(
      value = Inline.When.ArgumentsAreConstant,
      arguments = {0})
  public T newInstance()
      throws IllegalAccessException, InstantiationException, ExceptionInInitializerError,
          SecurityException {

    // Basic checks
    checkMemberAccess(Member.PUBLIC);
    if (!type.isClassType()) throw new InstantiationException();

    RVMClass cls = type.asClass();

    if (cls.isAbstract() || cls.isInterface()) throw new InstantiationException();

    // Ensure that the class is initialized
    if (!cls.isInitialized()) {
      RuntimeEntrypoints.initializeClassForDynamicLink(cls);
    }

    // Find the defaultConstructor
    RVMMethod defaultConstructor = getDefaultConstructor();
    if (defaultConstructor == null) throw new InstantiationException();

    // Check that caller is allowed to access it
    if (!defaultConstructor.isPublic()) {
      RVMClass accessingClass = RVMClass.getClassFromStackFrame(1);
      VMCommonLibrarySupport.checkAccess(defaultConstructor, accessingClass);
    }

    // Allocate an uninitialized instance;
    @SuppressWarnings("unchecked") // yes, we're giving an anonymous object a type.
    T obj = (T) RuntimeEntrypoints.resolvedNewScalar(cls);

    // Run the default constructor on the it.
    Reflection.invoke(defaultConstructor, null, obj, null, true);

    return obj;
  }
Пример #5
0
  public Constructor<T> getConstructor(Class<?>... parameterTypes)
      throws NoSuchMethodException, SecurityException {
    checkMemberAccess(Member.PUBLIC);
    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 (method.isPublic() && parametersMatch(method.getParameterTypes(), parameterTypes)) {
          answer = method;
          break;
        }
      }
    }
    if (answer == null) {
      throwNoSuchMethodException("<init>", parameterTypes);
    }
    return JikesRVMSupport.createConstructor(answer);
  }
Пример #6
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;
 }