Java 类com.sun.javadoc.TypeVariable 实例源码

项目:marklet    文件:MarkletDocumentBuilder.java   
/**
 * Appends to the current document the given type parameter
 * as a valid markdown link.
 * 
 * @param source Source package to start URL from.
 * @param type Target type parameter to reach from this package.
 */
private void parameterLink(final PackageDoc source, final Type type) {
    final WildcardType wildcard = type.asWildcardType();
    if (wildcard != null) {
        character('?');
    }
    else {
        final TypeVariable variableType = type.asTypeVariable();
        if (variableType != null) {
            final Type [] bounds = variableType.bounds();
            if (bounds.length > 0) {
                text("? extends ");
                for (int i = 0; i < bounds.length; i++) {
                    typeLink(source, bounds[i]);
                    if (i < bounds.length - 1) {
                        text(" & ");
                    }
                }
            }
        }
        else {
            typeLink(source, type);
        }
    }
}
项目:xml-doclet    文件:Parser.java   
private String parseIdentifier(Type type) {
  if (type instanceof TypeVariable) {
    return parseIdentifier((Doc) type.asClassDoc()) + "#" + type.simpleTypeName();
  } else {
    return parseIdentifier((Doc) type.asClassDoc());
  }
}
项目:xml-doclet    文件:Parser.java   
/**
 * Parse type variables for generics
 * 
 * @param typeVariable
 * @return
 */
protected Generic parseGeneric(TypeVariable typeVariable) {
  Generic genericNode = objectFactory.createGeneric();
  genericNode.setName(typeVariable.typeName());
  genericNode.setIdentifier(parseIdentifier((Type) typeVariable));
  genericNode.setId(typeVariable.simpleTypeName());

  for (Type bound : typeVariable.bounds()) {
    genericNode.getBound().add(parseTypeInfo(bound));
  }

  return genericNode;
}
项目:javadoc-json-doclet    文件:JsonDoclet.java   
/**
 * @return full JSON objects for the given TypeVariable[]
 */
protected JSONArray processTypeVariables( TypeVariable[] typeVariables) {

    JSONArray retMe = new JSONArray();

    for (TypeVariable typeVariable : typeVariables) {
        retMe.add( processTypeVariable(typeVariable) );
    }

    return retMe;
}
项目:javadoc-json-doclet    文件:JsonDoclet.java   
/**
 * 
 * @return the full JSON for the given TypeVariable
 */
protected JSONObject processTypeVariable(TypeVariable typeVariable) {
    if (typeVariable == null) {
        return null;
    }

    JSONObject retMe = processType(typeVariable);

    retMe.put("bounds", processTypes(typeVariable.bounds()));

    return retMe;
}
项目:javaontracks    文件:JOTDocletNavView.java   
private boolean sameName(String name, TypeVariable type)
{
    if (name == null || type == null)
    {
        return true;
    }
    if (type.asClassDoc() == null || type.asClassDoc().name() == null)
    {
        return true;
    }
    return name.equals(type.asClassDoc().name());
}
项目:xml-doclet    文件:Parser.java   
protected Interface parseInterface(ClassDoc classDoc) {

    Interface interfaceNode = objectFactory.createInterface();
    interfaceNode.setName(classDoc.name());
    interfaceNode.setDisplayName(classDoc.simpleTypeName());
    interfaceNode.setIdentifier(parseIdentifier((Doc) classDoc));
    interfaceNode.setFull(classDoc.qualifiedName());
    interfaceNode.setComment(parseComment(classDoc));
    interfaceNode.setScope(parseScope(classDoc));

    for (TypeVariable typeVariable : classDoc.typeParameters()) {
      interfaceNode.getGeneric().add(parseGeneric(typeVariable));
    }

    for (Type interfaceType : classDoc.interfaceTypes()) {
      interfaceNode.getInterface().add(parseTypeInfo(interfaceType));
    }

    for (MethodDoc method : classDoc.methods()) {
      interfaceNode.getMethod().add(parseMethod(method));
    }

    Tag[] tags;
    SeeTag[] seeTags;

    tags = classDoc.tags("@deprecated");
    if (tags.length > 0) {
      interfaceNode.setDeprecated(parseComment(tags[0]));
    }

    tags = classDoc.tags("@since");
    if (tags.length > 0) {
      interfaceNode.setSince(tags[0].text());
    }

    tags = classDoc.tags("@version");
    if (tags.length > 0) {
      interfaceNode.setVersion(tags[0].text());
    }

    seeTags = classDoc.seeTags();
    for (int i = 0; i < seeTags.length; i++) {
      interfaceNode.getLink().add(parseLink(seeTags[i]));
    }

    return interfaceNode;
  }
项目:xml-doclet    文件:Parser.java   
protected Class parseClass(ClassDoc classDoc) {

    Class classNode = objectFactory.createClass();
    classNode.setName(classDoc.name());
    classNode.setDisplayName(classDoc.simpleTypeName());
    classNode.setIdentifier(parseIdentifier((Doc) classDoc));
    classNode.setFull(classDoc.qualifiedName());
    classNode.setComment(parseComment(classDoc));
    classNode.setAbstract(classDoc.isAbstract());
    classNode.setError(classDoc.isError());
    classNode.setException(classDoc.isException());
    classNode.setExternalizable(classDoc.isExternalizable());
    classNode.setSerializable(classDoc.isSerializable());
    classNode.setScope(parseScope(classDoc));

    for (TypeVariable typeVariable : classDoc.typeParameters()) {
      classNode.getGeneric().add(parseGeneric(typeVariable));
    }

    Type superClassType = classDoc.superclassType();
    if (superClassType != null) {
      classNode.setClazz(parseTypeInfo(superClassType));
    }

    for (Type interfaceType : classDoc.interfaceTypes()) {
      classNode.getInterface().add(parseTypeInfo(interfaceType));
    }

    for (MethodDoc method : classDoc.methods()) {
      classNode.getMethod().add(parseMethod(method));
    }

    for (ConstructorDoc constructor : classDoc.constructors()) {
      classNode.getConstructor().add(parseConstructor(constructor));
    }

    for (FieldDoc field : classDoc.fields()) {
      classNode.getField().add(parseField(field));
    }

    Tag[] tags;
    SeeTag[] seeTags;

    tags = classDoc.tags("@deprecated");
    if (tags.length > 0) {
      classNode.setDeprecated(parseComment(tags[0]));
    }

    tags = classDoc.tags("@since");
    if (tags.length > 0) {
      classNode.setSince(tags[0].text());
    }

    tags = classDoc.tags("@version");
    if (tags.length > 0) {
      classNode.setVersion(tags[0].text());
    }

    tags = classDoc.tags("@author");
    for (int i = 0; i < tags.length; i++) {
      classNode.getAuthor().add(tags[i].text());
    }

    seeTags = classDoc.seeTags();
    for (int i = 0; i < seeTags.length; i++) {
      classNode.getLink().add(parseLink(seeTags[i]));
    }

    return classNode;
  }
项目:Solr-Javadoc    文件:Analyzer.java   
public static boolean start(RootDoc root) throws IOException {
        Map<String, List<String>> packageMap = new TreeMap<>();

        for (ClassDoc classDoc : root.classes()) {
            String fromPackage = classDoc.containingPackage().name();
            List<String> packageRefs = packageMap.get(fromPackage);
            if (packageRefs == null) {
                packageRefs = new LinkedList<String>();
                packageMap.put(fromPackage, packageRefs);
            }
            Set<ClassDoc> relatedClasses = new TreeSet<>();

            addIfPresent(relatedClasses, classDoc.superclass());
            addIfPresent(relatedClasses, classDoc.containingClass());
            addIfPresent(relatedClasses, classDoc.interfaces());

            //TODO: This may not do what I think it does
            for (TypeVariable typeVariable : classDoc.typeParameters()) {
                for (Type bound : typeVariable.bounds()) {
                    System.out.print("Found bound parameter: " + bound.toString());
                    addIfPresent(relatedClasses, bound.asClassDoc());
                }
            }

//            boolean relationsFound = false;
            for (ClassDoc relatedClass : relatedClasses) {
                String toPackage = relatedClass.containingPackage().name();
                if (toPackage.startsWith("org.apache") && !toPackage.equals(fromPackage)) {
                    packageRefs.add(toPackage);
//                    WRITER.write(String.format("\"%s\" -> \"%s\";\n", fromName, toName));
//                    relationsFound = true;
                }
            };
//            if (!relationsFound) {
//                WRITER.write(String.format("\"%s\";\n", fromName)); //single node
//            }

        }

        //write out package links
        for (String fromPackageName : packageMap.keySet()) {
            List<String> toPackageList = packageMap.get(fromPackageName);
            if (toPackageList.isEmpty()) {
                WRITER.write(String.format("\"%s\";\n", fromPackageName)); //single node
                continue;
            }

            //get the packages and number of times they occur
            Map<String, Long> toPackageCounts = toPackageList.stream()
                    .collect(
                            Collectors.groupingBy(p -> p,
                                    Collectors.counting())
                    );

            for (String toPackageName : toPackageCounts.keySet()) {
                WRITER.write(String.format("\"%s\" -> \"%s\" [weight=\"%d\"]\n",
                        fromPackageName, toPackageName,
                        toPackageCounts.get(toPackageName)));
            }

        }

        return true;
    }
项目:docdown    文件:ClassNameRenderable.java   
@Override
public void renderOn(HtmlCanvas html) throws IOException {
    if (type.isPrimitive()) {
        html.write(type.typeName() + type.dimension());
    } else {
        String name;
        ClassDoc classDoc = type.asClassDoc();
        DocReferenceable referenceable = generator.getRefLocator().getClassDocRef(classDoc);
        String ref = PageRenderer.getPage(html).getReferenceTo(referenceable);
        if ((flags & FQN) != 0) {
            name = classDoc.qualifiedName();
        } else {
            name = referenceable.getName();
        }
        if ((flags & LINK) != 0 && ref != null) {
            html.a(href(PageRenderer.getPage(html).getReferenceTo(referenceable))).content(name,
                    HtmlCanvas.NO_ESCAPE);
        } else {
            html.write(name);
        }
    }

    ParameterizedType parameterizedType = type.asParameterizedType();
    if (parameterizedType != null) {
        Type[] typeArguments = parameterizedType.typeArguments();
        if (typeArguments.length > 0) {
            html.write("<");
            for (int typeVarCount = 0; typeVarCount < typeArguments.length; typeVarCount++) {
                Type typeArgument = typeArguments[typeVarCount];
                if (typeVarCount > 0) {
                    html.write(", ");
                }
                renderReferenceable(generator.getRefLocator().getClassDocRef(typeArgument.asClassDoc()), html);
            }
            html.write(">");
        }
    } else if (!type.isPrimitive()) {
        TypeVariable[] typeVariables = type.asClassDoc().typeParameters();
        if (typeVariables.length > 0) {
            html.write("<");
            for (int typeVarCount = 0; typeVarCount < typeVariables.length; typeVarCount++) {
                TypeVariable typeVariable = typeVariables[typeVarCount];
                if (typeVarCount > 0) {
                    html.write(", ");
                }
                html.write(typeVariable.typeName());
                if ((flags & BOUNDS) != 0) {
                    Type[] bounds = typeVariable.bounds();
                    if (bounds.length > 0) {
                        html.write(" extends ");
                        for (int boundCnt = 0; boundCnt < bounds.length; boundCnt++) {
                            ClassDoc boundClass = bounds[boundCnt].asClassDoc();
                            if (boundCnt > 0) {
                                html.write(" & ");
                            }
                            renderReferenceable(generator.getRefLocator().getClassDocRef(boundClass), html);
                        }
                    }
                }
            }
            html.write(">");
        }
    }
}
项目:bazooka-wo-xmldoclet    文件:XMLDoclet.java   
/**
 * Generates a child node for each generic type parameter.
 * @param  doc [description]
 * @return     [description]
 */
private static XMLNode toTypeParametersNode(ClassDoc doc) {
  TypeVariable[] typeParameters = doc.typeParameters();
  ParamTag[] typeParameterTags = doc.typeParamTags();

  XMLNode node = null;

  if (typeParameters != null && typeParameters.length > 0) {
    node = new XMLNode("typeParameters");

    for (TypeVariable i : typeParameters) {
      XMLNode paramNode = new XMLNode("parameter");
      paramNode.attribute("name", i.typeName());

      Type[] bounds = i.bounds();

      if (bounds != null && bounds.length > 0) {
        XMLNode boundsNode = new XMLNode("bounds");

        for (Type t : bounds) {
          XMLNode typeNode = new XMLNode("type");

          typeNode.attribute("fulltype", t.toString());
          typeNode.attribute("type", t.typeName());
          typeNode.attribute("name", t.qualifiedTypeName());

          boundsNode.child(typeNode);
        }

        paramNode.child(boundsNode);
      }

      if (typeParameterTags != null && typeParameterTags.length > 0) {
        ParamTag tag = null;

        for (ParamTag j : typeParameterTags) {
          // take the first one
          if (j.isTypeParameter() && j.parameterName().equals(i.typeName())) {
            tag = j;
            break;
          }
        }

        if (tag != null) {
          XMLNode commentNode = new XMLNode("comment");
          commentNode.text(toComment(tag));
          paramNode.child(commentNode);
        }
      }

      node.child(paramNode);
    }
  }

  return node;
}
项目:classpath    文件:ClassDocReflectedImpl.java   
public TypeVariable asTypeVariable() { return null; }
项目:classpath    文件:ClassDocReflectedImpl.java   
public TypeVariable[] typeParameters() { return new TypeVariable[0]; }