本文整理汇总了Java中com.sun.javadoc.Type类的典型用法代码示例。如果您正苦于以下问题:Java Type类的具体用法?Java Type怎么用?Java Type使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
Type类属于com.sun.javadoc包,在下文中一共展示了Type类的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getSimpleTypeName
import com.sun.javadoc.Type; //导入依赖的package包/类
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();
}
示例2: writeMethodFieldInitializers
import com.sun.javadoc.Type; //导入依赖的package包/类
/**
* Writes code to initialize the static fields for each method
* using the Java Reflection API.
**/
private void writeMethodFieldInitializers(IndentingWriter p)
throws IOException
{
for (int i = 0; i < methodFieldNames.length; i++) {
p.p(methodFieldNames[i] + " = ");
/*
* Look up the Method object in the somewhat arbitrary
* interface that we find in the Method object.
*/
RemoteClass.Method method = remoteMethods[i];
MethodDoc methodDoc = method.methodDoc();
String methodName = methodDoc.name();
Type paramTypes[] = method.parameterTypes();
p.p(methodDoc.containingClass().qualifiedName() + ".class.getMethod(\"" +
methodName + "\", new java.lang.Class[] {");
for (int j = 0; j < paramTypes.length; j++) {
if (j > 0)
p.p(", ");
p.p(paramTypes[j].toString() + ".class");
}
p.pln("});");
}
}
示例3: writeUnmarshalArguments
import com.sun.javadoc.Type; //导入依赖的package包/类
/**
* Writes Java statements to unmarshal a series of values in order
* of types as in the "types" array from the java.io.ObjectInput
* stream named "stream" into variables as named in "names" (for
* any element of "names" that is null, the corresponding value is
* unmarshalled and discarded).
**/
private static boolean writeUnmarshalArguments(IndentingWriter p,
String streamName,
Type[] types,
String[] names)
throws IOException
{
assert types.length == names.length;
boolean readObject = false;
for (int i = 0; i < types.length; i++) {
if (writeUnmarshalArgument(p, streamName, types[i], names[i])) {
readObject = true;
}
p.pln(";");
}
return readObject;
}
示例4: wrapArgumentCode
import com.sun.javadoc.Type; //导入依赖的package包/类
/**
* Returns a snippet of Java code to wrap a value named "name" of
* type "type" into an object as appropriate for use by the Java
* Reflection API.
*
* For primitive types, an appropriate wrapper class is
* instantiated with the primitive value. For object types
* (including arrays), no wrapping is necessary, so the value is
* named directly.
**/
private static String wrapArgumentCode(Type type, String name) {
if (type.dimension().length() > 0 || type.asClassDoc() != null) {
return name;
} else if (type.typeName().equals("boolean")) {
return ("(" + name +
" ? java.lang.Boolean.TRUE : java.lang.Boolean.FALSE)");
} else if (type.typeName().equals("byte")) {
return "new java.lang.Byte(" + name + ")";
} else if (type.typeName().equals("char")) {
return "new java.lang.Character(" + name + ")";
} else if (type.typeName().equals("short")) {
return "new java.lang.Short(" + name + ")";
} else if (type.typeName().equals("int")) {
return "new java.lang.Integer(" + name + ")";
} else if (type.typeName().equals("long")) {
return "new java.lang.Long(" + name + ")";
} else if (type.typeName().equals("float")) {
return "new java.lang.Float(" + name + ")";
} else if (type.typeName().equals("double")) {
return "new java.lang.Double(" + name + ")";
} else {
throw new AssertionError(type);
}
}
示例5: unwrapArgumentCode
import com.sun.javadoc.Type; //导入依赖的package包/类
/**
* Returns a snippet of Java code to unwrap a value named "name"
* into a value of type "type", as appropriate for the Java
* Reflection API.
*
* For primitive types, the value is assumed to be of the
* corresponding wrapper class, and a method is called on the
* wrapper to retrieve the primitive value. For object types
* (include arrays), no unwrapping is necessary; the value is
* simply cast to the expected real object type.
**/
private static String unwrapArgumentCode(Type type, String name) {
if (type.dimension().length() > 0 || type.asClassDoc() != null) {
return "((" + type.toString() + ") " + name + ")";
} else if (type.typeName().equals("boolean")) {
return "((java.lang.Boolean) " + name + ").booleanValue()";
} else if (type.typeName().equals("byte")) {
return "((java.lang.Byte) " + name + ").byteValue()";
} else if (type.typeName().equals("char")) {
return "((java.lang.Character) " + name + ").charValue()";
} else if (type.typeName().equals("short")) {
return "((java.lang.Short) " + name + ").shortValue()";
} else if (type.typeName().equals("int")) {
return "((java.lang.Integer) " + name + ").intValue()";
} else if (type.typeName().equals("long")) {
return "((java.lang.Long) " + name + ").longValue()";
} else if (type.typeName().equals("float")) {
return "((java.lang.Float) " + name + ").floatValue()";
} else if (type.typeName().equals("double")) {
return "((java.lang.Double) " + name + ").doubleValue()";
} else {
throw new AssertionError(type);
}
}
示例6: computeOperationString
import com.sun.javadoc.Type; //导入依赖的package包/类
/**
* Computes the string representation of this method
* appropriate for the construction of a
* java.rmi.server.Operation object.
**/
private String computeOperationString() {
/*
* To be consistent with previous implementations, we use
* the deprecated style of placing the "[]" for the return
* type (if any) after the parameter list.
*/
Type returnType = methodDoc.returnType();
String op = returnType.qualifiedTypeName() + " " +
methodDoc.name() + "(";
Parameter[] parameters = methodDoc.parameters();
for (int i = 0; i < parameters.length; i++) {
if (i > 0) {
op += ", ";
}
op += parameters[i].type().toString();
}
op += ")" + returnType.dimension();
return op;
}
示例7: writeTypeTo
import com.sun.javadoc.Type; //导入依赖的package包/类
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;
}