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

项目:PrivacyStreams    文件:Utils.java   
public static String getSimpleTypeName(Type type) {
    if (type instanceof ParameterizedType) {
        String typeName = type.typeName() + "<";
        boolean firstParameter = true;
        for (Type parameter : ((ParameterizedType) type).typeArguments()) {
            if (firstParameter) {
                typeName += getSimpleTypeName(parameter);
                firstParameter = false;
            }
            else {
                typeName += "," + getSimpleTypeName(parameter);
            }
        }
        typeName += ">";
        return typeName;
    }
    return type.typeName();
}
项目:umldoclet    文件:Renderer.java   
protected static IndentingPrintWriter writeTypeTo(IndentingPrintWriter out, Type type) {
    if (type != null) {
        out.append(type.typeName());
        final ParameterizedType parameterizedType = type.asParameterizedType();
        if (parameterizedType != null) {
            final Type[] generics = parameterizedType.typeArguments();
            if (generics.length > 0) {
                out.append("<");
                String sep = "";
                for (Type generic : generics) {
                    writeTypeTo(out.append(sep), generic);
                    sep = ", ";
                }
                out.append(">");
            }
        }
        out.append(type.dimension());
    }
    return out;
}
项目:xml-doclet    文件:ClassTree.java   
private void addAllInterfaceTypes(Map results, Type type,
        Type[] interfaceTypes, boolean raw) {
    for (int i = 0; i < interfaceTypes.length; i++) {
        Type interfaceType = interfaceTypes[i];
        ClassDoc interfaceClassDoc = interfaceType.asClassDoc();
        if (! (interfaceClassDoc.isPublic() ||
            interfaceClassDoc.isIncluded())) {
            continue;
        }
        if (raw)
            interfaceType = interfaceType.asClassDoc();
        results.put(interfaceClassDoc, interfaceType);
        List superInterfaces = getAllInterfaces(interfaceType);
        for (Iterator iter = superInterfaces.iterator(); iter.hasNext(); ) {
            Type superInterface = (Type) iter.next();
            results.put(superInterface.asClassDoc(), superInterface);
        }
    }
    if (type instanceof ParameterizedType)
        findAllInterfaceTypes(results, (ParameterizedType) type);
    else if (((ClassDoc) type).typeParameters().length == 0)
        findAllInterfaceTypes(results, (ClassDoc) type, raw);
    else
        findAllInterfaceTypes(results, (ClassDoc) type, true);
}
项目:marklet    文件:MarkletDocumentBuilder.java   
/**
 * Appends to the current document the list of parameters
 * from the given ``type`` if any.
 * 
 * @param source Source package to start URL from.
 * @param type Target type to append parameters from.
 */
private void parameterLinks(final PackageDoc source, final Type type) {
    final ParameterizedType invocation = type.asParameterizedType();
    if (invocation != null) {
        final Type [] types = invocation.typeArguments();
        if (types.length > 0) {
            character('<');
            for (int i = 0; i < types.length; i++) {
                parameterLink(source, types[i]);
                if (i < types.length - 1) {
                    text(", ");
                }
            }
            character('>');
        }
    }
}
项目:rest-doclet    文件:TypeUtils.java   
/**
 * This will grab the internal type from an array or a parameterized container.
 * @param type
 * @return
 */
public static String internalContainerType(Type type) {
    //treat arrays first
    if (type.dimension() != null && !type.dimension().isEmpty())
        return basicType(type);

    ParameterizedType pType = type.asParameterizedType();
    if (pType != null) {
        Type[] paramTypes = ((ParameterizedType)type).typeArguments();
        if (!isEmpty(paramTypes))
            return basicType(paramTypes[0]);
    }

    //TODO look into supporting models.
    return "Object";
}
项目:wrdocletbase    文件:AbstractDocBuilder.java   
protected boolean isParameterizedTypeInStopClasses(Type type) {
    if (!this.isInStopClasses(type.asClassDoc())) {
        return false;
    }
    ParameterizedType pt = type.asParameterizedType();
    if (pt != null) {
        for (Type arg : pt.typeArguments()) {
            if (!this.isParameterizedTypeInStopClasses(arg)) {
                return false;
            }
        }
    }
    return true;
}
项目:wrdocletbase    文件:AbstractDocBuilder.java   
protected List<APIParameter> getFields(Type type, ParameterType paramType, HashSet<String> processingClasses) {
    processingClasses.add(type.toString());
    List<APIParameter> result = new LinkedList<APIParameter>();
    if (!type.isPrimitive()) {
        ParameterizedType pt = type.asParameterizedType();
        if (pt != null && pt.typeArguments().length > 0) {
            for (Type arg : pt.typeArguments()) {
                if (!this.isParameterizedTypeInStopClasses(arg)) {
                    APIParameter tmp = new APIParameter();
                    tmp.setName(arg.simpleTypeName());
                    tmp.setType(this.getTypeName(arg, false));
                    tmp.setDescription("");
                    tmp.setParentTypeArgument(true);
                    if (!processingClasses.contains(arg.qualifiedTypeName())) {
                        tmp.setFields(this.getFields(arg, paramType, processingClasses));
                    }
                    result.add(tmp);
                }
            }
        }

        ClassDoc classDoc = this.wrDoc.getConfiguration().root.classNamed(type.qualifiedTypeName());
        if (classDoc != null) {
            result.addAll(this.getFields(classDoc, paramType, processingClasses));
        }
    }
    return result;
}
项目:xml-doclet    文件:ClassTree.java   
private void findAllInterfaceTypes(Map results, ClassDoc c, boolean raw) {
    Type superType = c.superclassType();
    if (superType == null)
        return;
    addAllInterfaceTypes(results, superType,
            superType instanceof ClassDoc ?
            ((ClassDoc) superType).interfaceTypes() :
            ((ParameterizedType) superType).interfaceTypes(),
            raw);
}
项目:xml-doclet    文件:ClassTree.java   
private void findAllInterfaceTypes(Map results, ParameterizedType p) {
    Type superType = p.superclassType();
    if (superType == null)
        return;
    addAllInterfaceTypes(results, superType,
            superType instanceof ClassDoc ?
            ((ClassDoc) superType).interfaceTypes() :
            ((ParameterizedType) superType).interfaceTypes(),
            false);
}
项目:xml-doclet    文件:Parser.java   
protected TypeInfo parseTypeInfo(Type type) {
  TypeInfo typeInfoNode = objectFactory.createTypeInfo();
  typeInfoNode.setName(type.simpleTypeName());
  typeInfoNode.setDisplayName(type.simpleTypeName());
  if (type.isPrimitive()) {
    typeInfoNode.setIdentifier(type.qualifiedTypeName());
  } else {
    typeInfoNode.setIdentifier(parseIdentifier(type));
  }
  typeInfoNode.setFull(type.qualifiedTypeName());
  String dimension = type.dimension();
  if (dimension.length() > 0) {
    typeInfoNode.setDimension(dimension);
  }

  WildcardType wildcard = type.asWildcardType();
  if (wildcard != null) {
    typeInfoNode.setWildcard(parseWildcard(wildcard));
  }

  ParameterizedType parameterized = type.asParameterizedType();
  if (parameterized != null) {
    for (Type typeArgument : parameterized.typeArguments()) {
      typeInfoNode.getGeneric().add(parseTypeInfo(typeArgument));
    }
  }

  return typeInfoNode;
}
项目:byps    文件:BConvert.java   
/**
 * Convert generic type args from javadoc to my TypeInfo objects.
 * @param errInfo
 * @param ptype
 * @param errorContext
 * @return List of TypeInfo objects
 * @throws GeneratorException
 */
private List<TypeInfo> getParameterizedTypeArgs(ErrorInfo errInfo, ParameterizedType ptype, String errorContext) throws GeneratorException {
    errInfo = errInfo.copy();
    List<TypeInfo> argInfos = null;
    if (ptype != null) {
        Type[] targs = ptype.typeArguments();
        argInfos = new ArrayList<TypeInfo>(targs.length);
        for (int i = 0; i < targs.length; i++) {
            errInfo.typeArg = "<" + targs[i] + ">";
            argInfos.add( makeElementTypeInfo(errInfo, targs[i], errorContext) );
        }
    }
    return argInfos;
}
项目:qtaste    文件:HTMLFileWriter.java   
/**
 * Returns type string.
 *
 * @param type type for which to return type string
 * @return type string, including parametrized types, dimensions and links.
 */
private String getTypeString(Type type) {
    String typeQualifiedName = type.qualifiedTypeName().replaceFirst("^java\\.lang\\.", "");
    typeQualifiedName = typeQualifiedName.replaceFirst("^com\\.qspin\\.qtaste\\.testsuite\\.(QTaste\\w*Exception)", "$1");
    String typeDocFileName = null;
    if (typeQualifiedName.startsWith("com.qspin.")) {
        String javaDocDir = typeQualifiedName.startsWith("com.qspin.qtaste.") ? QTaste_JAVADOC_URL_PREFIX :
              SUT_JAVADOC_URL_PREFIX;
        typeDocFileName = javaDocDir + typeQualifiedName.replace('.', '/') + ".html";
    }
    String typeString = typeQualifiedName;
    if (typeDocFileName != null) {
        typeString = "<A HREF=\"" + typeDocFileName + "\">" + typeString + "</A>";
    }
    if (type.asParameterizedType() != null) {
        ParameterizedType parametrizedType = type.asParameterizedType();
        final Type[] parameterTypes = parametrizedType.typeArguments();
        if (parameterTypes.length > 0) {
            String[] parametersTypeStrings = new String[parameterTypes.length];
            for (int i = 0; i < parameterTypes.length; i++) {
                parametersTypeStrings[i] = getTypeString(parameterTypes[i]);
            }
            typeString += "&lt;" + Strings.join(parametersTypeStrings, ",") + "&gt;";
        }
    }
    typeString += type.dimension();

    return typeString;
}
项目:xml-doclet    文件:ClassTree.java   
public List getAllInterfaces(Type type) {
    Map results = new TreeMap();
    Type[] interfaceTypes = null;
    Type superType = null;
    if (type instanceof ParameterizedType) {
        interfaceTypes = ((ParameterizedType) type).interfaceTypes();
        superType = ((ParameterizedType) type).superclassType();
    } else if (type instanceof ClassDoc) {
        interfaceTypes = ((ClassDoc) type).interfaceTypes();
        superType = ((ClassDoc) type).superclassType();
    } else {
        interfaceTypes = type.asClassDoc().interfaceTypes();
        superType = type.asClassDoc().superclassType();
    }

    for (int i = 0; i < interfaceTypes.length; i++) {
        Type interfaceType = interfaceTypes[i];
        ClassDoc interfaceClassDoc = interfaceType.asClassDoc();
        if (! (interfaceClassDoc.isPublic() ||
               interfaceClassDoc.isIncluded())) {
            continue;
        }
        results.put(interfaceClassDoc, interfaceType);
        List superInterfaces = getAllInterfaces(interfaceType);
        for (Iterator iter = superInterfaces.iterator(); iter.hasNext(); ) {
            Type t = (Type) iter.next();
            results.put(t.asClassDoc(), t);
        }
    }
    if (superType == null)
        return new ArrayList(results.values());
    //Try walking the tree.
    addAllInterfaceTypes(results,
        superType,
        superType instanceof ClassDoc ?
            ((ClassDoc) superType).interfaceTypes() :
            ((ParameterizedType) superType).interfaceTypes(),
        false);
    List resultsList = new ArrayList(results.values());
    Collections.sort(resultsList, new TypeComparator());
    return resultsList;
}
项目: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(">");
        }
    }
}
项目:byps    文件:BConvert.java   
/**
 * Convert a javadoc Type object into an object of my TypeInfo class.
 * @param errInfo
 * @param type
 * @param errorContext
 * @return TypeInfo object
 * @throws GeneratorException
 */
private TypeInfo makeElementTypeInfo(ErrorInfo errInfo, Type type, String errorContext) throws GeneratorException {
    errInfo = errInfo.copy();

    if (type == null) return null;

    TypeInfo tinfo = null;

    WildcardType wtype = type.asWildcardType();

    String qname = type.qualifiedTypeName();
    if (wtype != null) {

        // Wildcard Parameter machen keinen Sinn.
        // Die Elemente werden sowohl als Konsument als auch als Produzent verwendet.
        // http://www.torsten-horn.de/techdocs/java-generics.htm#Wildcard-extends-versus-T-extends
        errInfo.msg = "Wildcard parameter types are unsupported, please replace type=\"" + type +"\" by \"Object\".";
        throw new GeneratorException(errInfo);

    }
    else {
        ParameterizedType ptype = type.asParameterizedType();
        List<TypeInfo> argInfos = getParameterizedTypeArgs(errInfo, ptype, errorContext);

        ClassDoc cls = type.asClassDoc();
        boolean isEnum = false;
        boolean isInline = false; 
        boolean isFinal = false;

        if (cls != null) {
            isEnum = cls.isEnum() || cls.isEnumConstant();
            isInline = isInline(cls);
            isFinal = cls.isFinal();
        }

        tinfo = classDB.createTypeInfo(
                type.simpleTypeName(),
                qname,
                type.dimension(),
                argInfos,
                isEnum, 
                isFinal, 
                isInline);

        makeSerialInfoForCollectionType(errInfo, tinfo);
    }


    return tinfo;
}
项目:javadoc-json-doclet    文件:JsonDoclet.java   
/**
 * @return the full JSON for the given Type
 */
protected JSONObject processParameterizedType(ParameterizedType parameterizedType) {

    if (parameterizedType == null) {
        return null;
    }

    JSONObject retMe = new JSONObject();

    retMe.put("typeArguments", processTypes( parameterizedType.typeArguments() ) );

    return retMe;
}