예제 #1
0
 public String toString(final NamedParameterNode<?> n) {
   final StringBuilder sb =
       new StringBuilder("Name: " + n.getSimpleArgName() + " " + n.getFullName());
   final String[] instances = n.getDefaultInstanceAsStrings();
   if (instances.length != 0) {
     sb.append(" = ");
     sb.append(join(",", instances));
   }
   if (!n.getDocumentation().equals("")) {
     sb.append(" //" + n.getDocumentation());
   }
   return sb.toString();
 }
  private static ClassHierarchyProto.Node serializeNode(Node n) {
    List<ClassHierarchyProto.Node> children = new ArrayList<>();
    for (Node child : n.getChildren()) {
      children.add(serializeNode(child));
    }
    if (n instanceof ClassNode) {
      ClassNode<?> cn = (ClassNode<?>) n;
      ConstructorDef<?>[] injectable = cn.getInjectableConstructors();
      ConstructorDef<?>[] all = cn.getAllConstructors();
      List<ConstructorDef<?>> others = new ArrayList<>(Arrays.asList(all));
      others.removeAll(Arrays.asList(injectable));

      List<ClassHierarchyProto.ConstructorDef> injectableConstructors = new ArrayList<>();
      for (ConstructorDef<?> inj : injectable) {
        injectableConstructors.add(serializeConstructorDef(inj));
      }
      List<ClassHierarchyProto.ConstructorDef> otherConstructors = new ArrayList<>();
      for (ConstructorDef<?> other : others) {
        otherConstructors.add(serializeConstructorDef(other));
      }
      List<String> implFullNames = new ArrayList<>();
      for (ClassNode<?> impl : cn.getKnownImplementations()) {
        implFullNames.add(impl.getFullName());
      }
      return newClassNode(
          cn.getName(),
          cn.getFullName(),
          cn.isInjectionCandidate(),
          cn.isExternalConstructor(),
          cn.isUnit(),
          injectableConstructors,
          otherConstructors,
          implFullNames,
          children);
    } else if (n instanceof NamedParameterNode) {
      NamedParameterNode<?> np = (NamedParameterNode<?>) n;
      return newNamedParameterNode(
          np.getName(),
          np.getFullName(),
          np.getSimpleArgName(),
          np.getFullArgName(),
          np.isSet(),
          np.isList(),
          np.getDocumentation(),
          np.getShortName(),
          np.getDefaultInstanceAsStrings(),
          children);
    } else if (n instanceof PackageNode) {
      return newPackageNode(n.getName(), n.getFullName(), children);
    } else {
      throw new IllegalStateException("Encountered unknown type of Node: " + n);
    }
  }
예제 #3
0
  public String toHtmlString(final NamedParameterNode<?> n, final String pack) {
    final String fullName = stripPrefix(n.getFullName(), pack);
    final StringBuffer sb = new StringBuffer();

    sb.append("<div id='" + n.getFullName() + "' class='decl-margin'>");
    sb.append("<div class='decl'>");

    sb.append(cell(n.getSimpleArgName(), "simpleName") + cell(fullName, FULLNAME));
    final String instance;
    final String[] instances = n.getDefaultInstanceAsStrings();
    if (instances.length != 0) {
      final StringBuffer sb2 = new StringBuffer(" = " + stripPrefix(instances[0], pack));
      for (int i = 1; i < instances.length; i++) {
        sb2.append("," + stripPrefix(instances[i], pack));
      }
      instance = sb2.toString();
    } else {
      instance = "";
    }
    sb.append(cell(instance, "instance"));
    final StringBuffer doc = new StringBuffer();
    if (!n.getDocumentation().equals("")) {
      doc.append(n.getDocumentation());
    }
    sb.append(cell(doc, "doc"));
    final StringBuffer uses = new StringBuffer();
    for (final String u : getUsesOf(n)) {
      uses.append("<a href='#" + u + "'>" + stripPrefix(u, pack) + "</a> ");
    }
    sb.append(cell(uses, USES));
    final StringBuffer settersStr = new StringBuffer();
    for (final String f : getSettersOf(n)) {
      settersStr.append("<a href='#" + f + "'>" + stripPrefix(f, pack) + "</a> ");
    }
    sb.append(cell(settersStr, SETTERS));
    sb.append("</div>");
    sb.append("</div>");
    return row(sb);
  }
  @Override
  public ClassHierarchy merge(ClassHierarchy ch) {
    if (this == ch) {
      return this;
    }
    if (!(ch instanceof ProtocolBufferClassHierarchy)) {
      throw new UnsupportedOperationException(
          "Cannot merge with class hierarchies of type: " + ch.getClass().getName());
    }

    final ProtocolBufferClassHierarchy pch = (ProtocolBufferClassHierarchy) ch;
    for (final String key : pch.lookupTable.keySet()) {
      if (!this.lookupTable.containsKey(key)) {
        this.lookupTable.put(key, pch.lookupTable.get(key));
      }

      for (final Node n : ch.getNamespace().getChildren()) {
        if (!this.namespace.contains(n.getFullName())) {
          if (n instanceof NamedParameter) {
            final NamedParameterNode np = (NamedParameterNode) n;
            new NamedParameterNodeImpl<>(
                this.namespace,
                np.getName(),
                np.getFullName(),
                np.getFullArgName(),
                np.getSimpleArgName(),
                np.isSet(),
                np.isList(),
                np.getDocumentation(),
                np.getShortName(),
                np.getDefaultInstanceAsStrings());
          } else if (n instanceof ClassNode) {
            final ClassNode cn = (ClassNode) n;
            new ClassNodeImpl(
                namespace,
                cn.getName(),
                cn.getFullName(),
                cn.isUnit(),
                cn.isInjectionCandidate(),
                cn.isExternalConstructor(),
                cn.getInjectableConstructors(),
                cn.getAllConstructors(),
                cn.getDefaultImplementation());
          }
        }
      }
    }
    return this;
  }