/** * Get type name of this parameter. * For example if parameter is the short 'index', returns "short". */ public String typeName() { return (type instanceof ClassDoc || type instanceof TypeVariable) ? type.typeName() // omit formal type params or bounds : type.toString(); }
@Override public String typeName() { return this.underlyingType().typeName(); }
/** * Return unqualified name of type excluding any dimension information. * <p> * For example, a two dimensional array of String returns 'String'. */ public String typeName() { return skipArrays().typeName(); }
/** * Returns the fully qualified class name from a {@link Type} that will work with {@link Class#forName(String)}. * <p> * This method correctly handles nested classes such that they can be fed into {@link Class#forName(String)}. * * @param type The type that you wish to derive the fully qualified path name for. * @return The fully qualified class name for the type. */ private static String getClassForNameFromType(Type type) { final String fullClassName = type.typeName(); final String fullClassForName = fullClassName.replace(".", "$"); return type.qualifiedTypeName().replace(fullClassName, fullClassForName); }
/** Annotate an field/argument with its type t */ private String typeAnnotation(Options opt, Type t) { if (t.typeName().equals("void")) return ""; return " : " + type(opt, t, false) + t.dimension(); }
/** Annotate an field/argument with its type t */ private String typeAnnotation(Options opt, Type t) { String ta = ""; if (t.typeName().equals("void")) return ta; ta += " : "; ta += type(opt, t); ta += t.dimension(); return ta; }
/** Print a a basic type t */ private String type(Options opt, Type t, boolean generics) { return ((generics ? opt.showQualifiedGenerics : opt.showQualified) ? // t.qualifiedTypeName() : t.typeName()) // + (opt.hideGenerics ? "" : typeParameters(opt, t.asParameterizedType())); }
/** Print a a basic type t */ private String type(Options opt, Type t) { String type = ""; if (opt.showQualified) type = t.qualifiedTypeName(); else type = t.typeName(); type += typeParameters(opt, t.asParameterizedType()); return type; }
protected int getReturnTypeLength(ExecutableMemberDoc member) { if (member instanceof MethodDoc) { MethodDoc method = (MethodDoc)member; Type rettype = method.returnType(); if (rettype.isPrimitive()) { return rettype.typeName().length() + rettype.dimension().length(); } else { LinkInfoImpl linkInfo = new LinkInfoImpl( LinkInfoImpl.CONTEXT_MEMBER, rettype); writer.getLink(linkInfo); return linkInfo.displayLength; } } else { // it's a constructordoc return -1; } }
/** * For backward compatibility, include an anchor using the erasures of the * parameters. NOTE: We won't need this method anymore after we fix * see tags so that they use the type instead of the erasure. * * @param emd the ExecutableMemberDoc to anchor to. * @return the 1.4.x style anchor for the ExecutableMemberDoc. */ protected String getErasureAnchor(ExecutableMemberDoc emd) { StringBuffer buf = new StringBuffer(emd.name() + "("); Parameter[] params = emd.parameters(); boolean foundTypeVariable = false; for (int i = 0; i < params.length; i++) { if (i > 0) { buf.append(","); } Type t = params[i].type(); foundTypeVariable = foundTypeVariable || t.asTypeVariable() != null; buf.append(t.isPrimitive() ? t.typeName() : t.asClassDoc().qualifiedName()); buf.append(t.dimension()); } buf.append(")"); return foundTypeVariable ? buf.toString() : null; } }
/** * For backward compatibility, include an anchor using the erasures of the * parameters. NOTE: We won't need this method anymore after we fix * see tags so that they use the type instead of the erasure. * * @param emd the ExecutableMemberDoc to anchor to. * @return the 1.4.x style anchor for the ExecutableMemberDoc. */ protected String getErasureAnchor(ExecutableMemberDoc emd) { StringBuilder buf = new StringBuilder(emd.name() + "("); Parameter[] params = emd.parameters(); boolean foundTypeVariable = false; for (int i = 0; i < params.length; i++) { if (i > 0) { buf.append(","); } Type t = params[i].type(); foundTypeVariable = foundTypeVariable || t.asTypeVariable() != null; buf.append(t.isPrimitive() ? t.typeName() : t.asClassDoc().qualifiedName()); buf.append(t.dimension()); } buf.append(")"); return foundTypeVariable ? writer.getName(buf.toString()) : null; } }
/** * Inherit throws documentation for exceptions that were declared but not * documented. */ private Content inheritThrowsDocumentation(Doc holder, Type[] declaredExceptionTypes, Set<String> alreadyDocumented, TagletWriter writer) { Content result = writer.getOutputInstance(); if (holder instanceof MethodDoc) { Set<Tag> declaredExceptionTags = new LinkedHashSet<Tag>(); for (int j = 0; j < declaredExceptionTypes.length; j++) { DocFinder.Output inheritedDoc = DocFinder.search(new DocFinder.Input((MethodDoc) holder, this, declaredExceptionTypes[j].typeName())); if (inheritedDoc.tagList.size() == 0) { inheritedDoc = DocFinder.search(new DocFinder.Input( (MethodDoc) holder, this, declaredExceptionTypes[j].qualifiedTypeName())); } declaredExceptionTags.addAll(inheritedDoc.tagList); } result.addContent(throwsTagsOutput( declaredExceptionTags.toArray(new ThrowsTag[] {}), writer, alreadyDocumented, false)); } return result; }
public static void returnDoc(ApiDoc apiDoc, ClassDoc classDoc, MethodDoc methodDoc) throws Exception { Method method = DocletUtil.getMethodByDoc(Class.forName(classDoc.qualifiedTypeName()), methodDoc); Type returnType = method.getGenericReturnType(); if (returnType.toString().equalsIgnoreCase("void")) { return; } ResultDoc resultDoc = new ResultDoc(); Tag[] tags = methodDoc.tags("return"); if (tags != null && tags.length == 1) { String[] returnTexts = tags[0].text().split("(e.g|eg|e.g.|example|exam|例如|如)(:|:)", 2); resultDoc.setDesc(returnTexts[0]); resultDoc.setExampleValue(returnTexts.length==2 ? returnTexts[1] : ""); resultDoc.setName(""); resultDoc.setType(methodDoc.returnType().typeName() + methodDoc.returnType().dimension()); } addRefType(classDoc, returnType, resultDoc); apiDoc.setResultDoc(resultDoc); }
protected void printTypeLinkNoDimension(Type type) { ClassDoc cd = type.asClassDoc(); if (type.isPrimitive() || cd.isPackagePrivate()) { print(type.typeName()); } else { writer.printLink(new LinkInfoImpl( LinkInfoImpl.CONTEXT_SERIAL_MEMBER,type)); } } }
protected void printTypeLinkNoDimension(Type type) { ClassDoc cd = type.asClassDoc(); //Linking to package private classes in serialized for causes //broken links. Don't link to them. if (type.isPrimitive() || cd.isPackagePrivate()) { print(type.typeName()); } else { writer.printLink(new LinkInfoImpl( LinkInfoImpl.CONTEXT_SERIAL_MEMBER, type)); } }
/** * Build the field sub header. */ public void buildFieldSubHeader() { if (! currentClass.definesSerializableFields() ){ FieldDoc field = (FieldDoc) currentMember; fieldWriter.writeMemberHeader(field.type().asClassDoc(), field.type().typeName(), field.type().dimension(), field.name()); } }
/** * {@inheritDoc} */ public TagletOutput getTagletOutput(Doc holder, TagletWriter writer) { Type returnType = ((MethodDoc) holder).returnType(); Tag[] tags = holder.tags(name); //Make sure we are not using @return tag on method with void return type. if (returnType.isPrimitive() && returnType.typeName().equals("void")) { if (tags.length > 0) { writer.getMsgRetriever().warning(holder.position(), "doclet.Return_tag_on_void_method"); } return null; } //Inherit @return tag if necessary. if (tags.length == 0) { DocFinder.Output inheritedDoc = DocFinder.search(new DocFinder.Input((MethodDoc) holder, this)); tags = inheritedDoc.holderTag == null ? tags : new Tag[] {inheritedDoc.holderTag}; } return tags.length > 0 ? writer.returnTagOutput(tags[0]) : null; } }
/** * {@inheritDoc} */ public Content getTagletOutput(Doc holder, TagletWriter writer) { Type returnType = ((MethodDoc) holder).returnType(); Tag[] tags = holder.tags(name); //Make sure we are not using @return tag on method with void return type. if (returnType.isPrimitive() && returnType.typeName().equals("void")) { if (tags.length > 0) { writer.getMsgRetriever().warning(holder.position(), "doclet.Return_tag_on_void_method"); } return null; } //Inherit @return tag if necessary. if (tags.length == 0) { DocFinder.Output inheritedDoc = DocFinder.search(new DocFinder.Input((MethodDoc) holder, this)); tags = inheritedDoc.holderTag == null ? tags : new Tag[] {inheritedDoc.holderTag}; } return tags.length > 0 ? writer.returnTagOutput(tags[0]) : null; } }
/** * Build the field sub header. * * @param node the XML element that specifies which components to document * @param fieldsContentTree content tree to which the documentation will be added */ public void buildFieldSubHeader(XMLNode node, Content fieldsContentTree) { if (!currentClass.definesSerializableFields()) { FieldDoc field = (FieldDoc) currentMember; fieldWriter.addMemberHeader(field.type().asClassDoc(), field.type().typeName(), field.type().dimension(), field.name(), fieldsContentTree); } }
/** * Add the receiver annotations information. * * @param member the member to write receiver annotations for. * @param rcvrType the receiver type. * @param descList list of annotation description. * @param tree the content tree to which the information will be added. */ protected void addReceiverAnnotations(ExecutableMemberDoc member, Type rcvrType, AnnotationDesc[] descList, Content tree) { writer.addReceiverAnnotationInfo(member, descList, tree); tree.addContent(writer.getSpace()); tree.addContent(rcvrType.typeName()); LinkInfoImpl linkInfo = new LinkInfoImpl(configuration, LinkInfoImpl.Kind.CLASS_SIGNATURE, rcvrType); tree.addContent(writer.getTypeParameterLinks(linkInfo)); tree.addContent(writer.getSpace()); tree.addContent("this"); }