/** * This method checks if the type describes a simple (single-value) variable (true) or it is an array. * @param typeDoc a field/parameter type * @return true if the type documentation describes a single-value field type, false if it is an array. */ private boolean isSingleValued(Type typeDoc) { return typeDoc.dimension() == null || typeDoc.dimension().equals(""); }
@Override public String dimension() { return this.underlyingType().dimension(); }
/** 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; }
pw.print(parameterType.dimension());
public static MethodIdentity create(MethodDoc method) { final List<String> parameterTypeNames = new ArrayList<String>(); for (Parameter param: method.parameters()) { Type type = param.type(); parameterTypeNames.add(type.qualifiedTypeName() + type.dimension()); } return new MethodIdentity(method.qualifiedName(), parameterTypeNames); }
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; } }
public static Method getMethodByDoc(Class<?> classz, MethodDoc methodDoc) throws Exception { Class<?>[] parameterTypes = new Class<?>[methodDoc.parameters().length]; for (int i = 0; i < methodDoc.parameters().length; i++) { Parameter parameter = methodDoc.parameters()[i]; if (parameter.type().isPrimitive()) { if (parameter.type().simpleTypeName().equals("byte")) parameterTypes[i] = byte.class; else if (parameter.type().simpleTypeName().equals("boolean")) parameterTypes[i] = boolean.class; else if (parameter.type().simpleTypeName().equals("short")) parameterTypes[i] = short.class; else if (parameter.type().simpleTypeName().equals("char")) parameterTypes[i] = char.class; else if (parameter.type().simpleTypeName().equals("int")) parameterTypes[i] = int.class; else if (parameter.type().simpleTypeName().equals("long")) parameterTypes[i] = long.class; else if (parameter.type().simpleTypeName().equals("float")) parameterTypes[i] = float.class; else if (parameter.type().simpleTypeName().equals("double")) parameterTypes[i] = double.class; } else { parameterTypes[i] = Class.forName(parameter.type().qualifiedTypeName()); } if (!StringUtils.isEmpty(parameter.type().dimension())) { int dimension = StringUtil.getStrCount(parameter.type().dimension(), "[]"); parameterTypes[i] = Array.newInstance(parameterTypes[i], (int[])Array.newInstance(int.class, dimension)).getClass(); } } return classz.getDeclaredMethod(methodDoc.name(), parameterTypes); }
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 TypeInfo parseTypeInfo(Type type) { TypeInfo typeInfoNode = objectFactory.createTypeInfo(); typeInfoNode.setQualified(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; }
/** * 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()); } }
type.dimension().equals("[]") ? "0..*" : "1", comment);
type.dimension().equals("[]") ? "0..*" : "1", comment);
annotationArgumentNode.setType(parseTypeInfo(annotationArgumentType)); annotationArgumentNode.setPrimitive(annotationArgumentType.isPrimitive()); annotationArgumentNode.setArray(annotationArgumentType.dimension().length() > 0);
/** * 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); } }
private FieldRelationInfo getFieldRelationInfo(FieldDoc field) { Type type = field.type(); if(type.isPrimitive() || type instanceof WildcardType || type instanceof TypeVariable) return null; if (type.dimension().endsWith("[]")) { return new FieldRelationInfo(type.asClassDoc(), true); } Options opt = optionProvider.getOptionsFor(type.asClassDoc()); if (opt.matchesCollPackageExpression(type.qualifiedTypeName())) { Type[] argTypes = getInterfaceTypeArguments(collectionClassDoc, type); if (argTypes != null && argTypes.length == 1 && !argTypes[0].isPrimitive()) return new FieldRelationInfo(argTypes[0].asClassDoc(), true); argTypes = getInterfaceTypeArguments(mapClassDoc, type); if (argTypes != null && argTypes.length == 2 && !argTypes[1].isPrimitive()) return new FieldRelationInfo(argTypes[1].asClassDoc(), true); } return new FieldRelationInfo(type.asClassDoc(), false); }
private FieldRelationInfo getFieldRelationInfo(FieldDoc field) { Type type = field.type(); if(type.isPrimitive() || type instanceof WildcardType || type instanceof TypeVariable) return null; if (type.dimension().endsWith("[]")) { return new FieldRelationInfo(type.asClassDoc(), true); } Options opt = optionProvider.getOptionsFor(type.asClassDoc()); if (opt.matchesCollPackageExpression(type.qualifiedTypeName())) { Type[] argTypes = getInterfaceTypeArguments(collectionClassDoc, type); if (argTypes != null && argTypes.length == 1 && !argTypes[0].isPrimitive()) return new FieldRelationInfo(argTypes[0].asClassDoc(), true); argTypes = getInterfaceTypeArguments(mapClassDoc, type); if (argTypes != null && argTypes.length == 2 && !argTypes[1].isPrimitive()) return new FieldRelationInfo(argTypes[1].asClassDoc(), true); } return new FieldRelationInfo(type.asClassDoc(), false); }
private Content annotationValueToContent(AnnotationValue annotationValue) { if (annotationValue.value() instanceof Type) { Type type = (Type) annotationValue.value(); if (type.asClassDoc() != null) { LinkInfoImpl linkInfo = new LinkInfoImpl(configuration, LinkInfoImpl.Kind.ANNOTATION, type); linkInfo.label = new StringContent((type.asClassDoc().isIncluded() ? type.typeName() : type.qualifiedTypeName()) + type.dimension() + ".class"); return getLink(linkInfo); } else { return new StringContent(type.typeName() + type.dimension() + ".class"); } } else if (annotationValue.value() instanceof AnnotationDesc) { List<Content> list = getAnnotations(0, new AnnotationDesc[]{(AnnotationDesc) annotationValue.value()}, false); ContentBuilder buf = new ContentBuilder(); for (Content c: list) { buf.addContent(c); } return buf; } else if (annotationValue.value() instanceof MemberDoc) { return getDocLink(LinkInfoImpl.Kind.ANNOTATION, (MemberDoc) annotationValue.value(), ((MemberDoc) annotationValue.value()).name(), false); } else { return new StringContent(annotationValue.toString()); } }