Mercurial > hg > graal-jvmci-8
diff graal/com.oracle.graal.api.meta/src/com/oracle/graal/api/meta/Signature.java @ 16483:3c3cd36a3836
moved signatureToMethodDescriptor(Signature sig) from MetaUtil to be a default method in Signature
author | Doug Simon <doug.simon@oracle.com> |
---|---|
date | Thu, 10 Jul 2014 23:02:34 +0200 |
parents | ca9061b6694c |
children | 27f2ee618883 |
line wrap: on
line diff
--- a/graal/com.oracle.graal.api.meta/src/com/oracle/graal/api/meta/Signature.java Thu Jul 10 22:51:38 2014 +0200 +++ b/graal/com.oracle.graal.api.meta/src/com/oracle/graal/api/meta/Signature.java Thu Jul 10 23:02:34 2014 +0200 @@ -24,7 +24,7 @@ /** * Represents a method signature provided by the runtime. - * + * * @see <a href="http://docs.oracle.com/javase/specs/jvms/se7/html/jvms-4.html#jvms-4.3.3">Method * Descriptors</a> */ @@ -32,7 +32,7 @@ /** * Returns the number of parameters in this signature, adding 1 for a receiver if requested. - * + * * @param receiver true if 1 is to be added to the result for a receiver * @return the number of parameters; + 1 iff {@code receiver == true} */ @@ -42,7 +42,7 @@ * Gets the parameter type at the specified position. This method returns a * {@linkplain ResolvedJavaType resolved} type if possible but without triggering any class * loading or resolution. - * + * * @param index the index into the parameters, with {@code 0} indicating the first parameter * @param accessingClass the context of the type lookup. If accessing class is provided, its * class loader is used to retrieve an existing resolved type. This value can be @@ -54,7 +54,7 @@ /** * Gets the parameter kind at the specified position. This is the same as calling * {@link #getParameterType}. {@link JavaType#getKind getKind}. - * + * * @param index the index into the parameters, with {@code 0} indicating the first parameter * @return the kind of the parameter at the specified position */ @@ -64,7 +64,7 @@ * Gets the return type of this signature. This method will return a * {@linkplain ResolvedJavaType resolved} type if possible but without triggering any class * loading or resolution. - * + * * @param accessingClass the context of the type lookup. If accessing class is provided, its * class loader is used to retrieve an existing resolved type. This value can be * {@code null} if the caller does not care for a resolved type. @@ -80,10 +80,31 @@ /** * Gets the size, in Java slots, of the parameters to this signature. - * + * * @param withReceiver {@code true} if to add a slot for a receiver object; {@code false} not to * include the receiver * @return the size of the parameters in slots */ int getParameterSlots(boolean withReceiver); + + /** + * Gets the <a + * href="http://docs.oracle.com/javase/specs/jvms/se7/html/jvms-4.html#jvms-4.3.3">method + * descriptor</a> corresponding to this signature. For example: + * + * <pre> + * (ILjava/lang/String;D)V + * </pre> + * + * @return the signature as a string + */ + default String toMethodDescriptor() { + StringBuilder sb = new StringBuilder("("); + for (int i = 0; i < getParameterCount(false); ++i) { + sb.append(getParameterType(i, null).getName()); + } + sb.append(')').append(getReturnType(null).getName()); + return sb.toString(); + } + }