< prev index next >

src/java.base/share/classes/jdk/internal/org/objectweb/asm/Type.java

Print this page




 637      *         argument), argSize, and the size of the return value, retSize,
 638      *         packed into a single
 639      *         int i = <tt>(argSize &lt;&lt; 2) | retSize</tt>
 640      *         (argSize is therefore equal to <tt>i &gt;&gt; 2</tt>,
 641      *         and retSize to <tt>i &amp; 0x03</tt>).
 642      */
 643     public int getArgumentsAndReturnSizes() {
 644         return getArgumentsAndReturnSizes(getDescriptor());
 645     }
 646 
 647     // ------------------------------------------------------------------------
 648     // Conversion to type descriptors
 649     // ------------------------------------------------------------------------
 650 
 651     /**
 652      * Returns the descriptor corresponding to this Java type.
 653      *
 654      * @return the descriptor corresponding to this Java type.
 655      */
 656     public String getDescriptor() {
 657         StringBuffer buf = new StringBuffer();
 658         getDescriptor(buf);
 659         return buf.toString();
 660     }
 661 
 662     /**
 663      * Returns the descriptor corresponding to the given argument and return
 664      * types.
 665      *
 666      * @param returnType
 667      *            the return type of the method.
 668      * @param argumentTypes
 669      *            the argument types of the method.
 670      * @return the descriptor corresponding to the given argument and return
 671      *         types.
 672      */
 673     public static String getMethodDescriptor(final Type returnType,
 674             final Type... argumentTypes) {
 675         StringBuffer buf = new StringBuffer();
 676         buf.append('(');
 677         for (int i = 0; i < argumentTypes.length; ++i) {
 678             argumentTypes[i].getDescriptor(buf);
 679         }
 680         buf.append(')');
 681         returnType.getDescriptor(buf);
 682         return buf.toString();
 683     }
 684 
 685     /**
 686      * Appends the descriptor corresponding to this Java type to the given
 687      * string buffer.
 688      *
 689      * @param buf
 690      *            the string buffer to which the descriptor must be appended.
 691      */
 692     private void getDescriptor(final StringBuffer buf) {
 693         if (this.buf == null) {
 694             // descriptor is in byte 3 of 'off' for primitive types (buf ==
 695             // null)
 696             buf.append((char) ((off & 0xFF000000) >>> 24));
 697         } else if (sort == OBJECT) {
 698             buf.append('L');
 699             buf.append(this.buf, off, len);
 700             buf.append(';');
 701         } else { // sort == ARRAY || sort == METHOD
 702             buf.append(this.buf, off, len);
 703         }
 704     }
 705 
 706     // ------------------------------------------------------------------------
 707     // Direct conversion from classes to type descriptors,
 708     // without intermediate Type objects
 709     // ------------------------------------------------------------------------
 710 
 711     /**
 712      * Returns the internal name of the given class. The internal name of a
 713      * class is its fully qualified name, as returned by Class.getName(), where
 714      * '.' are replaced by '/'.
 715      *
 716      * @param c
 717      *            an object or array class.
 718      * @return the internal name of the given class.
 719      */
 720     public static String getInternalName(final Class<?> c) {
 721         return c.getName().replace('.', '/');
 722     }
 723 
 724     /**
 725      * Returns the descriptor corresponding to the given Java type.
 726      *
 727      * @param c
 728      *            an object class, a primitive class or an array class.
 729      * @return the descriptor corresponding to the given class.
 730      */
 731     public static String getDescriptor(final Class<?> c) {
 732         StringBuffer buf = new StringBuffer();
 733         getDescriptor(buf, c);
 734         return buf.toString();
 735     }
 736 
 737     /**
 738      * Returns the descriptor corresponding to the given constructor.
 739      *
 740      * @param c
 741      *            a {@link Constructor Constructor} object.
 742      * @return the descriptor of the given constructor.
 743      */
 744     public static String getConstructorDescriptor(final Constructor<?> c) {
 745         Class<?>[] parameters = c.getParameterTypes();
 746         StringBuffer buf = new StringBuffer();
 747         buf.append('(');
 748         for (int i = 0; i < parameters.length; ++i) {
 749             getDescriptor(buf, parameters[i]);
 750         }
 751         return buf.append(")V").toString();
 752     }
 753 
 754     /**
 755      * Returns the descriptor corresponding to the given method.
 756      *
 757      * @param m
 758      *            a {@link Method Method} object.
 759      * @return the descriptor of the given method.
 760      */
 761     public static String getMethodDescriptor(final Method m) {
 762         Class<?>[] parameters = m.getParameterTypes();
 763         StringBuffer buf = new StringBuffer();
 764         buf.append('(');
 765         for (int i = 0; i < parameters.length; ++i) {
 766             getDescriptor(buf, parameters[i]);
 767         }
 768         buf.append(')');
 769         getDescriptor(buf, m.getReturnType());
 770         return buf.toString();
 771     }
 772 
 773     /**
 774      * Appends the descriptor of the given class to the given string buffer.
 775      *
 776      * @param buf
 777      *            the string buffer to which the descriptor must be appended.
 778      * @param c
 779      *            the class whose descriptor must be computed.
 780      */
 781     private static void getDescriptor(final StringBuffer buf, final Class<?> c) {
 782         Class<?> d = c;
 783         while (true) {
 784             if (d.isPrimitive()) {
 785                 char car;
 786                 if (d == Integer.TYPE) {
 787                     car = 'I';
 788                 } else if (d == Void.TYPE) {
 789                     car = 'V';
 790                 } else if (d == Boolean.TYPE) {
 791                     car = 'Z';
 792                 } else if (d == Byte.TYPE) {
 793                     car = 'B';
 794                 } else if (d == Character.TYPE) {
 795                     car = 'C';
 796                 } else if (d == Short.TYPE) {
 797                     car = 'S';
 798                 } else if (d == Double.TYPE) {
 799                     car = 'D';
 800                 } else if (d == Float.TYPE) {
 801                     car = 'F';




 637      *         argument), argSize, and the size of the return value, retSize,
 638      *         packed into a single
 639      *         int i = <tt>(argSize &lt;&lt; 2) | retSize</tt>
 640      *         (argSize is therefore equal to <tt>i &gt;&gt; 2</tt>,
 641      *         and retSize to <tt>i &amp; 0x03</tt>).
 642      */
 643     public int getArgumentsAndReturnSizes() {
 644         return getArgumentsAndReturnSizes(getDescriptor());
 645     }
 646 
 647     // ------------------------------------------------------------------------
 648     // Conversion to type descriptors
 649     // ------------------------------------------------------------------------
 650 
 651     /**
 652      * Returns the descriptor corresponding to this Java type.
 653      *
 654      * @return the descriptor corresponding to this Java type.
 655      */
 656     public String getDescriptor() {
 657         StringBuilder buf = new StringBuilder();
 658         getDescriptor(buf);
 659         return buf.toString();
 660     }
 661 
 662     /**
 663      * Returns the descriptor corresponding to the given argument and return
 664      * types.
 665      *
 666      * @param returnType
 667      *            the return type of the method.
 668      * @param argumentTypes
 669      *            the argument types of the method.
 670      * @return the descriptor corresponding to the given argument and return
 671      *         types.
 672      */
 673     public static String getMethodDescriptor(final Type returnType,
 674             final Type... argumentTypes) {
 675         StringBuilder buf = new StringBuilder();
 676         buf.append('(');
 677         for (int i = 0; i < argumentTypes.length; ++i) {
 678             argumentTypes[i].getDescriptor(buf);
 679         }
 680         buf.append(')');
 681         returnType.getDescriptor(buf);
 682         return buf.toString();
 683     }
 684 
 685     /**
 686      * Appends the descriptor corresponding to this Java type to the given
 687      * string buffer.
 688      *
 689      * @param buf
 690      *            the string buffer to which the descriptor must be appended.
 691      */
 692     private void getDescriptor(final StringBuilder buf) {
 693         if (this.buf == null) {
 694             // descriptor is in byte 3 of 'off' for primitive types (buf ==
 695             // null)
 696             buf.append((char) ((off & 0xFF000000) >>> 24));
 697         } else if (sort == OBJECT) {
 698             buf.append('L');
 699             buf.append(this.buf, off, len);
 700             buf.append(';');
 701         } else { // sort == ARRAY || sort == METHOD
 702             buf.append(this.buf, off, len);
 703         }
 704     }
 705 
 706     // ------------------------------------------------------------------------
 707     // Direct conversion from classes to type descriptors,
 708     // without intermediate Type objects
 709     // ------------------------------------------------------------------------
 710 
 711     /**
 712      * Returns the internal name of the given class. The internal name of a
 713      * class is its fully qualified name, as returned by Class.getName(), where
 714      * '.' are replaced by '/'.
 715      *
 716      * @param c
 717      *            an object or array class.
 718      * @return the internal name of the given class.
 719      */
 720     public static String getInternalName(final Class<?> c) {
 721         return c.getName().replace('.', '/');
 722     }
 723 
 724     /**
 725      * Returns the descriptor corresponding to the given Java type.
 726      *
 727      * @param c
 728      *            an object class, a primitive class or an array class.
 729      * @return the descriptor corresponding to the given class.
 730      */
 731     public static String getDescriptor(final Class<?> c) {
 732         StringBuilder buf = new StringBuilder();
 733         getDescriptor(buf, c);
 734         return buf.toString();
 735     }
 736 
 737     /**
 738      * Returns the descriptor corresponding to the given constructor.
 739      *
 740      * @param c
 741      *            a {@link Constructor Constructor} object.
 742      * @return the descriptor of the given constructor.
 743      */
 744     public static String getConstructorDescriptor(final Constructor<?> c) {
 745         Class<?>[] parameters = c.getParameterTypes();
 746         StringBuilder buf = new StringBuilder();
 747         buf.append('(');
 748         for (int i = 0; i < parameters.length; ++i) {
 749             getDescriptor(buf, parameters[i]);
 750         }
 751         return buf.append(")V").toString();
 752     }
 753 
 754     /**
 755      * Returns the descriptor corresponding to the given method.
 756      *
 757      * @param m
 758      *            a {@link Method Method} object.
 759      * @return the descriptor of the given method.
 760      */
 761     public static String getMethodDescriptor(final Method m) {
 762         Class<?>[] parameters = m.getParameterTypes();
 763         StringBuilder buf = new StringBuilder();
 764         buf.append('(');
 765         for (int i = 0; i < parameters.length; ++i) {
 766             getDescriptor(buf, parameters[i]);
 767         }
 768         buf.append(')');
 769         getDescriptor(buf, m.getReturnType());
 770         return buf.toString();
 771     }
 772 
 773     /**
 774      * Appends the descriptor of the given class to the given string buffer.
 775      *
 776      * @param buf
 777      *            the string buffer to which the descriptor must be appended.
 778      * @param c
 779      *            the class whose descriptor must be computed.
 780      */
 781     private static void getDescriptor(final StringBuilder buf, final Class<?> c) {
 782         Class<?> d = c;
 783         while (true) {
 784             if (d.isPrimitive()) {
 785                 char car;
 786                 if (d == Integer.TYPE) {
 787                     car = 'I';
 788                 } else if (d == Void.TYPE) {
 789                     car = 'V';
 790                 } else if (d == Boolean.TYPE) {
 791                     car = 'Z';
 792                 } else if (d == Byte.TYPE) {
 793                     car = 'B';
 794                 } else if (d == Character.TYPE) {
 795                     car = 'C';
 796                 } else if (d == Short.TYPE) {
 797                     car = 'S';
 798                 } else if (d == Double.TYPE) {
 799                     car = 'D';
 800                 } else if (d == Float.TYPE) {
 801                     car = 'F';


< prev index next >