sun.tools.java.Type Java Examples

The following examples show how to use sun.tools.java.Type. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: RMIGenerator.java    From hottub with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Write 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
{
    if (types.length != names.length) {
        throw new Error("parameter type and name arrays different sizes");
    }

    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;
}
 
Example #2
Source File: RMIGenerator.java    From dragonwell8_jdk with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Write 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
{
    if (types.length != names.length) {
        throw new Error("parameter type and name arrays different sizes");
    }

    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;
}
 
Example #3
Source File: RMIGenerator.java    From jdk8u-dev-jdk with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Generate a readable string representing the given type suitable
 * for embedding within a Java identifier.
 */
private static String generateNameFromType(Type type) {
    int typeCode = type.getTypeCode();
    switch (typeCode) {
    case TC_BOOLEAN:
    case TC_BYTE:
    case TC_CHAR:
    case TC_SHORT:
    case TC_INT:
    case TC_LONG:
    case TC_FLOAT:
    case TC_DOUBLE:
        return type.toString();
    case TC_ARRAY:
        return "arrayOf_" + generateNameFromType(type.getElementType());
    case TC_CLASS:
        return Names.mangleClass(type.getClassName().getName()).toString();
    default:
        throw new Error("unexpected type code: " + typeCode);
    }
}
 
Example #4
Source File: RMIGenerator.java    From dragonwell8_jdk with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Generate a readable string representing the given type suitable
 * for embedding within a Java identifier.
 */
private static String generateNameFromType(Type type) {
    int typeCode = type.getTypeCode();
    switch (typeCode) {
    case TC_BOOLEAN:
    case TC_BYTE:
    case TC_CHAR:
    case TC_SHORT:
    case TC_INT:
    case TC_LONG:
    case TC_FLOAT:
    case TC_DOUBLE:
        return type.toString();
    case TC_ARRAY:
        return "arrayOf_" + generateNameFromType(type.getElementType());
    case TC_CLASS:
        return Names.mangleClass(type.getClassName().getName()).toString();
    default:
        throw new Error("unexpected type code: " + typeCode);
    }
}
 
Example #5
Source File: RMIGenerator.java    From jdk8u_jdk with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Generate a readable string representing the given type suitable
 * for embedding within a Java identifier.
 */
private static String generateNameFromType(Type type) {
    int typeCode = type.getTypeCode();
    switch (typeCode) {
    case TC_BOOLEAN:
    case TC_BYTE:
    case TC_CHAR:
    case TC_SHORT:
    case TC_INT:
    case TC_LONG:
    case TC_FLOAT:
    case TC_DOUBLE:
        return type.toString();
    case TC_ARRAY:
        return "arrayOf_" + generateNameFromType(type.getElementType());
    case TC_CLASS:
        return Names.mangleClass(type.getClassName().getName()).toString();
    default:
        throw new Error("unexpected type code: " + typeCode);
    }
}
 
Example #6
Source File: RMIGenerator.java    From hottub with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Generate a readable string representing the given type suitable
 * for embedding within a Java identifier.
 */
private static String generateNameFromType(Type type) {
    int typeCode = type.getTypeCode();
    switch (typeCode) {
    case TC_BOOLEAN:
    case TC_BYTE:
    case TC_CHAR:
    case TC_SHORT:
    case TC_INT:
    case TC_LONG:
    case TC_FLOAT:
    case TC_DOUBLE:
        return type.toString();
    case TC_ARRAY:
        return "arrayOf_" + generateNameFromType(type.getElementType());
    case TC_CLASS:
        return Names.mangleClass(type.getClassName().getName()).toString();
    default:
        throw new Error("unexpected type code: " + typeCode);
    }
}
 
Example #7
Source File: RMIGenerator.java    From openjdk-8-source with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Generate a readable string representing the given type suitable
 * for embedding within a Java identifier.
 */
private static String generateNameFromType(Type type) {
    int typeCode = type.getTypeCode();
    switch (typeCode) {
    case TC_BOOLEAN:
    case TC_BYTE:
    case TC_CHAR:
    case TC_SHORT:
    case TC_INT:
    case TC_LONG:
    case TC_FLOAT:
    case TC_DOUBLE:
        return type.toString();
    case TC_ARRAY:
        return "arrayOf_" + generateNameFromType(type.getElementType());
    case TC_CLASS:
        return Names.mangleClass(type.getClassName().getName()).toString();
    default:
        throw new Error("unexpected type code: " + typeCode);
    }
}
 
Example #8
Source File: RMIGenerator.java    From TencentKona-8 with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Generate a readable string representing the given type suitable
 * for embedding within a Java identifier.
 */
private static String generateNameFromType(Type type) {
    int typeCode = type.getTypeCode();
    switch (typeCode) {
    case TC_BOOLEAN:
    case TC_BYTE:
    case TC_CHAR:
    case TC_SHORT:
    case TC_INT:
    case TC_LONG:
    case TC_FLOAT:
    case TC_DOUBLE:
        return type.toString();
    case TC_ARRAY:
        return "arrayOf_" + generateNameFromType(type.getElementType());
    case TC_CLASS:
        return Names.mangleClass(type.getClassName().getName()).toString();
    default:
        throw new Error("unexpected type code: " + typeCode);
    }
}
 
Example #9
Source File: RMIGenerator.java    From openjdk-8-source with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Write 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
{
    if (types.length != names.length) {
        throw new Error("parameter type and name arrays different sizes");
    }

    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;
}
 
Example #10
Source File: RMIGenerator.java    From jdk8u-jdk with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Generate a readable string representing the given type suitable
 * for embedding within a Java identifier.
 */
private static String generateNameFromType(Type type) {
    int typeCode = type.getTypeCode();
    switch (typeCode) {
    case TC_BOOLEAN:
    case TC_BYTE:
    case TC_CHAR:
    case TC_SHORT:
    case TC_INT:
    case TC_LONG:
    case TC_FLOAT:
    case TC_DOUBLE:
        return type.toString();
    case TC_ARRAY:
        return "arrayOf_" + generateNameFromType(type.getElementType());
    case TC_CLASS:
        return Names.mangleClass(type.getClassName().getName()).toString();
    default:
        throw new Error("unexpected type code: " + typeCode);
    }
}
 
Example #11
Source File: RMIGenerator.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Write 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
{
    if (types.length != names.length) {
        throw new Error("parameter type and name arrays different sizes");
    }

    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;
}
 
Example #12
Source File: RMIGenerator.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Generate a readable string representing the given type suitable
 * for embedding within a Java identifier.
 */
private static String generateNameFromType(Type type) {
    int typeCode = type.getTypeCode();
    switch (typeCode) {
    case TC_BOOLEAN:
    case TC_BYTE:
    case TC_CHAR:
    case TC_SHORT:
    case TC_INT:
    case TC_LONG:
    case TC_FLOAT:
    case TC_DOUBLE:
        return type.toString();
    case TC_ARRAY:
        return "arrayOf_" + generateNameFromType(type.getElementType());
    case TC_CLASS:
        return Names.mangleClass(type.getClassName().getName()).toString();
    default:
        throw new Error("unexpected type code: " + typeCode);
    }
}
 
Example #13
Source File: RMIGenerator.java    From jdk8u_jdk with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Write 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
{
    if (types.length != names.length) {
        throw new Error("parameter type and name arrays different sizes");
    }

    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;
}
 
Example #14
Source File: RMIGenerator.java    From jdk8u60 with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Write 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
{
    if (types.length != names.length) {
        throw new Error("parameter type and name arrays different sizes");
    }

    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;
}
 
Example #15
Source File: RMIGenerator.java    From openjdk-8 with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Write 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
{
    if (types.length != names.length) {
        throw new Error("parameter type and name arrays different sizes");
    }

    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;
}
 
Example #16
Source File: RMIGenerator.java    From openjdk-jdk8u with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Write 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
{
    if (types.length != names.length) {
        throw new Error("parameter type and name arrays different sizes");
    }

    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;
}
 
Example #17
Source File: RMIGenerator.java    From jdk8u-dev-jdk with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Write 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
{
    if (types.length != names.length) {
        throw new Error("parameter type and name arrays different sizes");
    }

    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;
}
 
Example #18
Source File: RMIGenerator.java    From jdk8u-dev-jdk with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Write 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] + " = ");
        /*
         * Here we look up the Method object in the arbitrary interface
         * that we find in the RemoteClass.Method object.
         * REMIND: Is this arbitrary choice OK?
         * REMIND: Should this access be part of RemoteClass.Method's
         * abstraction?
         */
        RemoteClass.Method method = remoteMethods[i];
        MemberDefinition def = method.getMemberDefinition();
        Identifier methodName = method.getName();
        Type methodType = method.getType();
        Type paramTypes[] = methodType.getArgumentTypes();

        p.p(def.getClassDefinition().getName() + ".class.getMethod(\"" +
            methodName + "\", new java.lang.Class[] {");
        for (int j = 0; j < paramTypes.length; j++) {
            if (j > 0)
                p.p(", ");
            p.p(paramTypes[j] + ".class");
        }
        p.pln("});");
    }
}
 
Example #19
Source File: RMIGenerator.java    From jdk8u_jdk with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Return 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 type, and a method is called on the wrapper type 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) {
    int typeCode = type.getTypeCode();
    switch (typeCode) {
    case TC_BOOLEAN:
        return "((java.lang.Boolean) " + name + ").booleanValue()";
    case TC_BYTE:
        return "((java.lang.Byte) " + name + ").byteValue()";
    case TC_CHAR:
        return "((java.lang.Character) " + name + ").charValue()";
    case TC_SHORT:
        return "((java.lang.Short) " + name + ").shortValue()";
    case TC_INT:
        return "((java.lang.Integer) " + name + ").intValue()";
    case TC_LONG:
        return "((java.lang.Long) " + name + ").longValue()";
    case TC_FLOAT:
        return "((java.lang.Float) " + name + ").floatValue()";
    case TC_DOUBLE:
        return "((java.lang.Double) " + name + ").doubleValue()";
    case TC_ARRAY:
    case TC_CLASS:
        return "((" + type + ") " + name + ")";
    default:
        throw new Error("unexpected type code: " + typeCode);
    }
}
 
Example #20
Source File: RMIGenerator.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Write a snippet of Java code to marshal a value named "name" of
 * type "type" to the java.io.ObjectOutput stream named "stream".
 *
 * Primitive types are marshalled with their corresponding methods
 * in the java.io.DataOutput interface, and objects (including arrays)
 * are marshalled using the writeObject method.
 */
private static void writeMarshalArgument(IndentingWriter p,
                                         String streamName,
                                         Type type, String name)
    throws IOException
{
    int typeCode = type.getTypeCode();
    switch (typeCode) {
    case TC_BOOLEAN:
        p.p(streamName + ".writeBoolean(" + name + ")");
        break;
    case TC_BYTE:
        p.p(streamName + ".writeByte(" + name + ")");
        break;
    case TC_CHAR:
        p.p(streamName + ".writeChar(" + name + ")");
        break;
    case TC_SHORT:
        p.p(streamName + ".writeShort(" + name + ")");
        break;
    case TC_INT:
        p.p(streamName + ".writeInt(" + name + ")");
        break;
    case TC_LONG:
        p.p(streamName + ".writeLong(" + name + ")");
        break;
    case TC_FLOAT:
        p.p(streamName + ".writeFloat(" + name + ")");
        break;
    case TC_DOUBLE:
        p.p(streamName + ".writeDouble(" + name + ")");
        break;
    case TC_ARRAY:
    case TC_CLASS:
        p.p(streamName + ".writeObject(" + name + ")");
        break;
    default:
        throw new Error("unexpected type code: " + typeCode);
    }
}
 
Example #21
Source File: RMIGenerator.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Write Java statements to marshal a series of values in order as
 * named in the "names" array, with types as specified in the "types"
 * array", to the java.io.ObjectOutput stream named "stream".
 */
private static void writeMarshalArguments(IndentingWriter p,
                                          String streamName,
                                          Type[] types, String[] names)
    throws IOException
{
    if (types.length != names.length) {
        throw new Error("parameter type and name arrays different sizes");
    }

    for (int i = 0; i < types.length; i++) {
        writeMarshalArgument(p, streamName, types[i], names[i]);
        p.pln(";");
    }
}
 
Example #22
Source File: RMIGenerator.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Return 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 type, and a method is called on the wrapper type 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) {
    int typeCode = type.getTypeCode();
    switch (typeCode) {
    case TC_BOOLEAN:
        return "((java.lang.Boolean) " + name + ").booleanValue()";
    case TC_BYTE:
        return "((java.lang.Byte) " + name + ").byteValue()";
    case TC_CHAR:
        return "((java.lang.Character) " + name + ").charValue()";
    case TC_SHORT:
        return "((java.lang.Short) " + name + ").shortValue()";
    case TC_INT:
        return "((java.lang.Integer) " + name + ").intValue()";
    case TC_LONG:
        return "((java.lang.Long) " + name + ").longValue()";
    case TC_FLOAT:
        return "((java.lang.Float) " + name + ").floatValue()";
    case TC_DOUBLE:
        return "((java.lang.Double) " + name + ").doubleValue()";
    case TC_ARRAY:
    case TC_CLASS:
        return "((" + type + ") " + name + ")";
    default:
        throw new Error("unexpected type code: " + typeCode);
    }
}
 
Example #23
Source File: RMIGenerator.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Write 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] + " = ");
        /*
         * Here we look up the Method object in the arbitrary interface
         * that we find in the RemoteClass.Method object.
         * REMIND: Is this arbitrary choice OK?
         * REMIND: Should this access be part of RemoteClass.Method's
         * abstraction?
         */
        RemoteClass.Method method = remoteMethods[i];
        MemberDefinition def = method.getMemberDefinition();
        Identifier methodName = method.getName();
        Type methodType = method.getType();
        Type paramTypes[] = methodType.getArgumentTypes();

        p.p(def.getClassDefinition().getName() + ".class.getMethod(\"" +
            methodName + "\", new java.lang.Class[] {");
        for (int j = 0; j < paramTypes.length; j++) {
            if (j > 0)
                p.p(", ");
            p.p(paramTypes[j] + ".class");
        }
        p.pln("});");
    }
}
 
Example #24
Source File: RMIGenerator.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Return 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 type, and a method is called on the wrapper type 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) {
    int typeCode = type.getTypeCode();
    switch (typeCode) {
    case TC_BOOLEAN:
        return "((java.lang.Boolean) " + name + ").booleanValue()";
    case TC_BYTE:
        return "((java.lang.Byte) " + name + ").byteValue()";
    case TC_CHAR:
        return "((java.lang.Character) " + name + ").charValue()";
    case TC_SHORT:
        return "((java.lang.Short) " + name + ").shortValue()";
    case TC_INT:
        return "((java.lang.Integer) " + name + ").intValue()";
    case TC_LONG:
        return "((java.lang.Long) " + name + ").longValue()";
    case TC_FLOAT:
        return "((java.lang.Float) " + name + ").floatValue()";
    case TC_DOUBLE:
        return "((java.lang.Double) " + name + ").doubleValue()";
    case TC_ARRAY:
    case TC_CLASS:
        return "((" + type + ") " + name + ")";
    default:
        throw new Error("unexpected type code: " + typeCode);
    }
}
 
Example #25
Source File: RMIGenerator.java    From jdk8u-dev-jdk with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Write Java statements to marshal a series of values in order as
 * named in the "names" array, with types as specified in the "types"
 * array", to the java.io.ObjectOutput stream named "stream".
 */
private static void writeMarshalArguments(IndentingWriter p,
                                          String streamName,
                                          Type[] types, String[] names)
    throws IOException
{
    if (types.length != names.length) {
        throw new Error("parameter type and name arrays different sizes");
    }

    for (int i = 0; i < types.length; i++) {
        writeMarshalArgument(p, streamName, types[i], names[i]);
        p.pln(";");
    }
}
 
Example #26
Source File: RMIGenerator.java    From hottub with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Write Java statements to marshal a series of values in order as
 * named in the "names" array, with types as specified in the "types"
 * array", to the java.io.ObjectOutput stream named "stream".
 */
private static void writeMarshalArguments(IndentingWriter p,
                                          String streamName,
                                          Type[] types, String[] names)
    throws IOException
{
    if (types.length != names.length) {
        throw new Error("parameter type and name arrays different sizes");
    }

    for (int i = 0; i < types.length; i++) {
        writeMarshalArgument(p, streamName, types[i], names[i]);
        p.pln(";");
    }
}
 
Example #27
Source File: RMIGenerator.java    From jdk8u-dev-jdk with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Return 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 type, and a method is called on the wrapper type 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) {
    int typeCode = type.getTypeCode();
    switch (typeCode) {
    case TC_BOOLEAN:
        return "((java.lang.Boolean) " + name + ").booleanValue()";
    case TC_BYTE:
        return "((java.lang.Byte) " + name + ").byteValue()";
    case TC_CHAR:
        return "((java.lang.Character) " + name + ").charValue()";
    case TC_SHORT:
        return "((java.lang.Short) " + name + ").shortValue()";
    case TC_INT:
        return "((java.lang.Integer) " + name + ").intValue()";
    case TC_LONG:
        return "((java.lang.Long) " + name + ").longValue()";
    case TC_FLOAT:
        return "((java.lang.Float) " + name + ").floatValue()";
    case TC_DOUBLE:
        return "((java.lang.Double) " + name + ").doubleValue()";
    case TC_ARRAY:
    case TC_CLASS:
        return "((" + type + ") " + name + ")";
    default:
        throw new Error("unexpected type code: " + typeCode);
    }
}
 
Example #28
Source File: RMIGenerator.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Write a snippet of Java code to marshal a value named "name" of
 * type "type" to the java.io.ObjectOutput stream named "stream".
 *
 * Primitive types are marshalled with their corresponding methods
 * in the java.io.DataOutput interface, and objects (including arrays)
 * are marshalled using the writeObject method.
 */
private static void writeMarshalArgument(IndentingWriter p,
                                         String streamName,
                                         Type type, String name)
    throws IOException
{
    int typeCode = type.getTypeCode();
    switch (typeCode) {
    case TC_BOOLEAN:
        p.p(streamName + ".writeBoolean(" + name + ")");
        break;
    case TC_BYTE:
        p.p(streamName + ".writeByte(" + name + ")");
        break;
    case TC_CHAR:
        p.p(streamName + ".writeChar(" + name + ")");
        break;
    case TC_SHORT:
        p.p(streamName + ".writeShort(" + name + ")");
        break;
    case TC_INT:
        p.p(streamName + ".writeInt(" + name + ")");
        break;
    case TC_LONG:
        p.p(streamName + ".writeLong(" + name + ")");
        break;
    case TC_FLOAT:
        p.p(streamName + ".writeFloat(" + name + ")");
        break;
    case TC_DOUBLE:
        p.p(streamName + ".writeDouble(" + name + ")");
        break;
    case TC_ARRAY:
    case TC_CLASS:
        p.p(streamName + ".writeObject(" + name + ")");
        break;
    default:
        throw new Error("unexpected type code: " + typeCode);
    }
}
 
Example #29
Source File: RMIGenerator.java    From dragonwell8_jdk with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Write 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] + " = ");
        /*
         * Here we look up the Method object in the arbitrary interface
         * that we find in the RemoteClass.Method object.
         * REMIND: Is this arbitrary choice OK?
         * REMIND: Should this access be part of RemoteClass.Method's
         * abstraction?
         */
        RemoteClass.Method method = remoteMethods[i];
        MemberDefinition def = method.getMemberDefinition();
        Identifier methodName = method.getName();
        Type methodType = method.getType();
        Type paramTypes[] = methodType.getArgumentTypes();

        p.p(def.getClassDefinition().getName() + ".class.getMethod(\"" +
            methodName + "\", new java.lang.Class[] {");
        for (int j = 0; j < paramTypes.length; j++) {
            if (j > 0)
                p.p(", ");
            p.p(paramTypes[j] + ".class");
        }
        p.pln("});");
    }
}
 
Example #30
Source File: RMIGenerator.java    From jdk8u-dev-jdk with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Return 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 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) {
    int typeCode = type.getTypeCode();
    switch (typeCode) {
    case TC_BOOLEAN:
        return ("(" + name +
                " ? java.lang.Boolean.TRUE : java.lang.Boolean.FALSE)");
    case TC_BYTE:
        return "new java.lang.Byte(" + name + ")";
    case TC_CHAR:
        return "new java.lang.Character(" + name + ")";
    case TC_SHORT:
        return "new java.lang.Short(" + name + ")";
    case TC_INT:
        return "new java.lang.Integer(" + name + ")";
    case TC_LONG:
        return "new java.lang.Long(" + name + ")";
    case TC_FLOAT:
        return "new java.lang.Float(" + name + ")";
    case TC_DOUBLE:
        return "new java.lang.Double(" + name + ")";
    case TC_ARRAY:
    case TC_CLASS:
        return name;
    default:
        throw new Error("unexpected type code: " + typeCode);
    }
}