Esempio n. 1
0
  /** get the n-th constant from the constant pool */
  public Object getConstant(int n, Environment env) {
    int constant_type = getConstantType(n);
    switch (constant_type) {
      case CONSTANT_INTEGER:
      case CONSTANT_FLOAT:
      case CONSTANT_LONG:
      case CONSTANT_DOUBLE:
        return getValue(n);

      case CONSTANT_CLASS:
        return getDeclaration(env, n);

      case CONSTANT_STRING:
        return getString(getInteger(n));

      case CONSTANT_FIELD:
      case CONSTANT_METHOD:
      case CONSTANT_INTERFACEMETHOD:
        try {
          int key = getInteger(n);
          ClassDefinition clazz = getDeclaration(env, key >> 16).getClassDefinition(env);
          int name_and_type = getInteger(key & 0xFFFF);
          Identifier id = getIdentifier(name_and_type >> 16);
          Type type = getType(name_and_type & 0xFFFF);

          for (MemberDefinition field = clazz.getFirstMatch(id);
              field != null;
              field = field.getNextMatch()) {
            Type field_type = field.getType();
            if ((constant_type == CONSTANT_FIELD)
                ? (field_type == type)
                : (field_type.equalArguments(type))) return field;
          }
        } catch (ClassNotFound e) {
        }
        return null;

      default:
        throw new ClassFormatError("invalid constant type: " + constant_type);
    }
  }