示例#1
0
  private static void findFields(
      ThreadContext context,
      RubyModule topModule,
      IRubyObject args[],
      boolean asReader,
      boolean asWriter) {
    Map<String, String> fieldMap = getFieldListFromArgs(args);

    for (RubyModule module = topModule; module != null; module = module.getSuperClass()) {
      Class<?> javaClass = getJavaClass(context, module);

      // Hit a non-java proxy class (included Modules can be a cause of this...skip)
      if (javaClass == null) continue;

      Field[] fields = JavaClass.getDeclaredFields(javaClass);
      for (int j = 0; j < fields.length; j++) {
        installField(context, fieldMap, fields[j], module, asReader, asWriter);
      }
    }

    // We could not find all of them print out first one (we could print them all?)
    if (!fieldMap.isEmpty()) {
      throw JavaClass.undefinedFieldError(
          context.getRuntime(), topModule.getName(), fieldMap.keySet().iterator().next());
    }
  }
示例#2
0
  /**
   * Calculate, based on given RubyModule, which class in its hierarchy should be used to determine
   * protected access.
   *
   * @param cls The class from which to calculate
   * @return The class to be used for protected access checking.
   */
  protected static RubyModule calculateProtectedClass(RubyModule cls) {
    // singleton classes don't get their own visibility domain
    if (cls.isSingleton()) cls = cls.getSuperClass();

    while (cls.isIncluded()) cls = cls.getMetaClass();

    // For visibility we need real meta class and not anonymous one from class << self
    if (cls instanceof MetaClass) cls = ((MetaClass) cls).getRealClass();

    return cls;
  }