< prev index next >

src/jdk.jdi/share/classes/com/sun/tools/jdi/JNITypeParser.java

Print this page
rev 58565 : 8238358: Implementation of JEP 371: Hidden Classes
Reviewed-by: duke
Contributed-by: mandy.chung@oracle.com, lois.foltan@oracle.com, david.holmes@oracle.com, harold.seigel@oracle.com, serguei.spitsyn@oracle.com, alex.buckley@oracle.com, jamsheed.c.m@oracle.com
   1 /*
   2  * Copyright (c) 1998, 2017, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   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
   7  * published by the Free Software Foundation.  Oracle designates this
   8  * particular file as subject to the "Classpath" exception as provided
   9  * by Oracle in the LICENSE file that accompanied this code.
  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any


  26 package com.sun.tools.jdi;
  27 
  28 import java.util.ArrayList;
  29 import java.util.List;
  30 
  31 public class JNITypeParser {
  32 
  33     static final char SIGNATURE_ENDCLASS = ';';
  34     static final char SIGNATURE_FUNC = '(';
  35     static final char SIGNATURE_ENDFUNC = ')';
  36 
  37     private String signature;
  38     private List<String> typeNameList;
  39     private List<String> signatureList;
  40     private int currentIndex;
  41 
  42     JNITypeParser(String signature) {
  43         this.signature = signature;
  44     }
  45 
  46     static String typeNameToSignature(String signature) {
  47         StringBuilder sb = new StringBuilder();
  48         int firstIndex = signature.indexOf('[');
  49         int index = firstIndex;
  50         while (index != -1) {
  51             sb.append('[');
  52             index = signature.indexOf('[', index + 1);
  53         }
  54 
  55         if (firstIndex != -1) {
  56             signature = signature.substring(0, firstIndex);
  57         }
  58 
  59         if (signature.equals("boolean")) {
  60             sb.append('Z');
  61         } else if (signature.equals("byte")) {
  62             sb.append('B');
  63         } else if (signature.equals("char")) {
  64             sb.append('C');
  65         } else if (signature.equals("short")) {
  66             sb.append('S');
  67         } else if (signature.equals("int")) {
  68             sb.append('I');
  69         } else if (signature.equals("long")) {
  70             sb.append('J');
  71         } else if (signature.equals("float")) {
  72             sb.append('F');
  73         } else if (signature.equals("double")) {
  74             sb.append('D');
  75         } else {
  76             sb.append('L');
  77             sb.append(signature.replace('.', '/'));







  78             sb.append(';');
  79         }
  80 
  81         return sb.toString();
  82     }
  83 
  84     String typeName() {
  85         return typeNameList().get(typeNameList().size()-1);
  86     }
  87 
  88     List<String> argumentTypeNames() {
  89         return typeNameList().subList(0, typeNameList().size() - 1);
  90     }
  91 
  92     String signature() {
  93         return signatureList().get(signatureList().size()-1);
  94     }
  95 
  96     List<String> argumentSignatures() {
  97         return signatureList().subList(0, signatureList().size() - 1);


 186     }
 187 
 188     private String nextTypeName() {
 189         char key = signature.charAt(currentIndex++);
 190 
 191         switch(key) {
 192             case (JDWP.Tag.ARRAY):
 193                 return  nextTypeName() + "[]";
 194 
 195             case (JDWP.Tag.BYTE):
 196                 return "byte";
 197 
 198             case (JDWP.Tag.CHAR):
 199                 return "char";
 200 
 201             case (JDWP.Tag.OBJECT):
 202                 int endClass = signature.indexOf(SIGNATURE_ENDCLASS,
 203                                                  currentIndex);
 204                 String retVal = signature.substring(currentIndex,
 205                                                     endClass);
 206                 retVal = retVal.replace('/','.');






 207                 currentIndex = endClass + 1;
 208                 return retVal;
 209 
 210             case (JDWP.Tag.FLOAT):
 211                 return "float";
 212 
 213             case (JDWP.Tag.DOUBLE):
 214                 return "double";
 215 
 216             case (JDWP.Tag.INT):
 217                 return "int";
 218 
 219             case (JDWP.Tag.LONG):
 220                 return "long";
 221 
 222             case (JDWP.Tag.SHORT):
 223                 return "short";
 224 
 225             case (JDWP.Tag.VOID):
 226                 return "void";
   1 /*
   2  * Copyright (c) 1998, 2020, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   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
   7  * published by the Free Software Foundation.  Oracle designates this
   8  * particular file as subject to the "Classpath" exception as provided
   9  * by Oracle in the LICENSE file that accompanied this code.
  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any


  26 package com.sun.tools.jdi;
  27 
  28 import java.util.ArrayList;
  29 import java.util.List;
  30 
  31 public class JNITypeParser {
  32 
  33     static final char SIGNATURE_ENDCLASS = ';';
  34     static final char SIGNATURE_FUNC = '(';
  35     static final char SIGNATURE_ENDFUNC = ')';
  36 
  37     private String signature;
  38     private List<String> typeNameList;
  39     private List<String> signatureList;
  40     private int currentIndex;
  41 
  42     JNITypeParser(String signature) {
  43         this.signature = signature;
  44     }
  45 
  46     static String typeNameToSignature(String typeName) {
  47         StringBuilder sb = new StringBuilder();
  48         int firstIndex = typeName.indexOf('[');
  49         int index = firstIndex;
  50         while (index != -1) {
  51             sb.append('[');
  52             index = typeName.indexOf('[', index + 1);
  53         }
  54 
  55         if (firstIndex != -1) {
  56             typeName = typeName.substring(0, firstIndex);
  57         }
  58 
  59         if (typeName.equals("boolean")) {
  60             sb.append('Z');
  61         } else if (typeName.equals("byte")) {
  62             sb.append('B');
  63         } else if (typeName.equals("char")) {
  64             sb.append('C');
  65         } else if (typeName.equals("short")) {
  66             sb.append('S');
  67         } else if (typeName.equals("int")) {
  68             sb.append('I');
  69         } else if (typeName.equals("long")) {
  70             sb.append('J');
  71         } else if (typeName.equals("float")) {
  72             sb.append('F');
  73         } else if (typeName.equals("double")) {
  74             sb.append('D');
  75         } else {
  76             sb.append('L');
  77             index = typeName.indexOf("/");   // check if it's a hidden class
  78             if (index < 0) {
  79                 sb.append(typeName.replace('.', '/'));
  80             } else {
  81                 sb.append(typeName.substring(0, index).replace('.', '/'));
  82                 sb.append(".");
  83                 sb.append(typeName.substring(index+1, typeName.length()));
  84             }
  85             sb.append(';');
  86         }
  87 
  88         return sb.toString();
  89     }
  90 
  91     String typeName() {
  92         return typeNameList().get(typeNameList().size()-1);
  93     }
  94 
  95     List<String> argumentTypeNames() {
  96         return typeNameList().subList(0, typeNameList().size() - 1);
  97     }
  98 
  99     String signature() {
 100         return signatureList().get(signatureList().size()-1);
 101     }
 102 
 103     List<String> argumentSignatures() {
 104         return signatureList().subList(0, signatureList().size() - 1);


 193     }
 194 
 195     private String nextTypeName() {
 196         char key = signature.charAt(currentIndex++);
 197 
 198         switch(key) {
 199             case (JDWP.Tag.ARRAY):
 200                 return  nextTypeName() + "[]";
 201 
 202             case (JDWP.Tag.BYTE):
 203                 return "byte";
 204 
 205             case (JDWP.Tag.CHAR):
 206                 return "char";
 207 
 208             case (JDWP.Tag.OBJECT):
 209                 int endClass = signature.indexOf(SIGNATURE_ENDCLASS,
 210                                                  currentIndex);
 211                 String retVal = signature.substring(currentIndex,
 212                                                     endClass);
 213                 int index = retVal.indexOf(".");
 214                 if (index < 0) {
 215                     retVal = retVal.replace('/', '.');
 216                 } else {
 217                     retVal = retVal.substring(0, index).replace('/', '.') + "/" +
 218                              retVal.substring(index + 1, retVal.length());
 219                 }
 220                 currentIndex = endClass + 1;
 221                 return retVal;
 222 
 223             case (JDWP.Tag.FLOAT):
 224                 return "float";
 225 
 226             case (JDWP.Tag.DOUBLE):
 227                 return "double";
 228 
 229             case (JDWP.Tag.INT):
 230                 return "int";
 231 
 232             case (JDWP.Tag.LONG):
 233                 return "long";
 234 
 235             case (JDWP.Tag.SHORT):
 236                 return "short";
 237 
 238             case (JDWP.Tag.VOID):
 239                 return "void";
< prev index next >