jdk/src/java.base/share/classes/sun/invoke/util/BytecodeDescriptor.java
changeset 32986 ea54ac8672e7
parent 32649 2ee9017c7597
child 34384 439c06c76808
equal deleted inserted replaced
32985:5f78762b773b 32986:ea54ac8672e7
     1 /*
     1 /*
     2  * Copyright (c) 2008, 2011, Oracle and/or its affiliates. All rights reserved.
     2  * Copyright (c) 2008, 2015, Oracle and/or its affiliates. All rights reserved.
     3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     4  *
     4  *
     5  * This code is free software; you can redistribute it and/or modify it
     5  * This code is free software; you can redistribute it and/or modify it
     6  * under the terms of the GNU General Public License version 2 only, as
     6  * under the terms of the GNU General Public License version 2 only, as
     7  * published by the Free Software Foundation.  Oracle designates this
     7  * published by the Free Software Foundation.  Oracle designates this
    35  */
    35  */
    36 public class BytecodeDescriptor {
    36 public class BytecodeDescriptor {
    37 
    37 
    38     private BytecodeDescriptor() { }  // cannot instantiate
    38     private BytecodeDescriptor() { }  // cannot instantiate
    39 
    39 
       
    40     /**
       
    41      * @param loader the class loader in which to look up the types (null means
       
    42      *               bootstrap class loader)
       
    43      */
    40     public static List<Class<?>> parseMethod(String bytecodeSignature, ClassLoader loader) {
    44     public static List<Class<?>> parseMethod(String bytecodeSignature, ClassLoader loader) {
    41         return parseMethod(bytecodeSignature, 0, bytecodeSignature.length(), loader);
    45         return parseMethod(bytecodeSignature, 0, bytecodeSignature.length(), loader);
    42     }
    46     }
    43 
    47 
       
    48     /**
       
    49      * @param loader the class loader in which to look up the types (null means
       
    50      *               bootstrap class loader)
       
    51      */
    44     static List<Class<?>> parseMethod(String bytecodeSignature,
    52     static List<Class<?>> parseMethod(String bytecodeSignature,
    45             int start, int end, ClassLoader loader) {
    53             int start, int end, ClassLoader loader) {
    46         if (loader == null)
       
    47             loader = ClassLoader.getSystemClassLoader();
       
    48         String str = bytecodeSignature;
    54         String str = bytecodeSignature;
    49         int[] i = {start};
    55         int[] i = {start};
    50         ArrayList<Class<?>> ptypes = new ArrayList<Class<?>>();
    56         ArrayList<Class<?>> ptypes = new ArrayList<Class<?>>();
    51         if (i[0] < end && str.charAt(i[0]) == '(') {
    57         if (i[0] < end && str.charAt(i[0]) == '(') {
    52             ++i[0];  // skip '('
    58             ++i[0];  // skip '('
    69 
    75 
    70     private static void parseError(String str, String msg) {
    76     private static void parseError(String str, String msg) {
    71         throw new IllegalArgumentException("bad signature: "+str+": "+msg);
    77         throw new IllegalArgumentException("bad signature: "+str+": "+msg);
    72     }
    78     }
    73 
    79 
       
    80     /**
       
    81      * @param loader the class loader in which to look up the types (null means
       
    82      *               bootstrap class loader)
       
    83      */
    74     private static Class<?> parseSig(String str, int[] i, int end, ClassLoader loader) {
    84     private static Class<?> parseSig(String str, int[] i, int end, ClassLoader loader) {
    75         if (i[0] == end)  return null;
    85         if (i[0] == end)  return null;
    76         char c = str.charAt(i[0]++);
    86         char c = str.charAt(i[0]++);
    77         if (c == 'L') {
    87         if (c == 'L') {
    78             int begc = i[0], endc = str.indexOf(';', begc);
    88             int begc = i[0], endc = str.indexOf(';', begc);
    79             if (endc < 0)  return null;
    89             if (endc < 0)  return null;
    80             i[0] = endc+1;
    90             i[0] = endc+1;
    81             String name = str.substring(begc, endc).replace('/', '.');
    91             String name = str.substring(begc, endc).replace('/', '.');
    82             try {
    92             try {
    83                 return loader.loadClass(name);
    93                 return (loader == null)
       
    94                     ? Class.forName(name, false, null)
       
    95                     : loader.loadClass(name);
    84             } catch (ClassNotFoundException ex) {
    96             } catch (ClassNotFoundException ex) {
    85                 throw new TypeNotPresentException(name, ex);
    97                 throw new TypeNotPresentException(name, ex);
    86             }
    98             }
    87         } else if (c == '[') {
    99         } else if (c == '[') {
    88             Class<?> t = parseSig(str, i, end, loader);
   100             Class<?> t = parseSig(str, i, end, loader);