Exemplo n.º 1
0
  /** Find a type by name. */
  @Override
  public Named find(String name) throws SemanticException {
    if (Report.should_report(report_topics, 3)) Report.report(3, "MemberCR.find(" + name + ")");

    if (nocache.contains(name)) {
      throw new NoClassException(name);
    }

    Named n = ts.systemResolver().check(name);

    if (n != null) {
      return n;
    }

    SemanticException error = null;

    // First, just try the long name.
    try {
      if (Report.should_report(report_topics, 2))
        Report.report(2, "MCR: loading " + name + " from " + inner);
      return inner.find(name);
    } catch (SemanticException e) {
      if (Report.should_report(report_topics, 2)) Report.report(2, "MCR: " + e.getMessage());
      if (StringUtil.isNameShort(name)) {
        throw e;
      }
      error = e;
    }

    boolean install = true;

    // Now try the prefix of the name and look for a member class
    // within it named with the suffix.
    String prefix = StringUtil.getPackageComponent(name);
    String suffix = StringUtil.getShortNameComponent(name);

    // Try the full name of the prefix first, then the raw class name,
    // so that encoded type information and source files are preferred
    // to the raw class file.
    try {
      if (Report.should_report(report_topics, 2)) Report.report(2, "MCR: loading prefix " + prefix);

      n = find(prefix);

      // This may be called during deserialization; n's
      // member classes might not be initialized yet.
      if (n instanceof ParsedTypeObject) {
        return findMember(n, suffix);
      }
    } catch (SemanticException e) {
    }

    if (install) {
      nocache.add(name);
    }

    throw error;
  }
Exemplo n.º 2
0
  protected void dumpObject(Object obj, Set<Object> cache) {
    if (obj == null) {
      w.write("null");
      return;
    }

    w.write(StringUtil.getShortNameComponent(obj.getClass().getName()));

    //        w.allowBreak(0, " ");
    //        w.write(obj.toString());

    if (cache.contains(obj)) {
      return;
    }
    cache.add(obj);

    w.allowBreak(1, " ");
    w.begin(0);

    try {
      Field[] fields = obj.getClass().getDeclaredFields();
      java.lang.reflect.AccessibleObject.setAccessible(fields, true);
      for (int i = 0; i < fields.length; i++) {
        Field field = fields[i];
        if ((field.getModifiers() & modifiersMask) != 0) continue;
        w.write("(");
        w.write(field.getName());
        w.allowBreak(1, " ");
        try {
          Object o = field.get(obj);
          dumpObject(o, cache);
        } catch (IllegalAccessException exn) {
          w.write("##[" + exn.getMessage() + "]");
        }
        w.write(")");
        w.newline(0);
      }
    } catch (SecurityException exn) {
    }

    w.end();
  }