< prev index next >

test/jdk/lib/testlibrary/bytecode/jdk/experimental/bytecode/BasicTypeHelper.java

Print this page

 28 /**
 29  * Helper to create and manipulate type descriptors, where type descriptors
 30  * are represented as JVM type descriptor strings and symbols are represented
 31  * as name strings
 32  */
 33 public class BasicTypeHelper implements TypeHelper<String, String> {
 34 
 35     @Override
 36     public String elemtype(String s) {
 37         if (!s.startsWith("[")) {
 38             throw new IllegalStateException();
 39         }
 40         return s.substring(1);
 41     }
 42 
 43     @Override
 44     public String arrayOf(String s) {
 45         return "[" + s;
 46     }
 47 





 48     @Override
 49     public String type(String s) {
 50         return "L" + s + ";";
 51     }
 52 





 53     @Override
 54     public TypeTag tag(String s) {
 55         switch (s.charAt(0)) {
 56             case '[':
 57             case 'L':

 58                 return TypeTag.A;
 59             case 'B':
 60             case 'C':
 61             case 'Z':
 62             case 'S':
 63             case 'I':
 64                 return TypeTag.I;
 65             case 'F':
 66                 return TypeTag.F;
 67             case 'J':
 68                 return TypeTag.J;
 69             case 'D':
 70                 return TypeTag.D;
 71             case 'V':
 72                 return TypeTag.V;
 73             case 'Q':
 74                 return TypeTag.Q;
 75             default:



 76                 throw new IllegalStateException("Bad type: " + s);
 77         }
 78     }
 79 
 80     @Override
 81     public String nullType() {
 82         // Needed in TypedCodeBuilder; ACONST_NULL pushes a 'null' onto the stack,
 83         // and stack maps handle null differently
 84         return "<null>";
 85     }
 86 
 87     @Override
 88     public String commonSupertype(String t1, String t2) {
 89         if (t1.equals(t2)) {
 90             return t1;
 91         } else {
 92             try {
 93                 Class<?> c1 = from(t1);
 94                 Class<?> c2 = from(t2);
 95                 if (c1.isAssignableFrom(c2)) {

 28 /**
 29  * Helper to create and manipulate type descriptors, where type descriptors
 30  * are represented as JVM type descriptor strings and symbols are represented
 31  * as name strings
 32  */
 33 public class BasicTypeHelper implements TypeHelper<String, String> {
 34 
 35     @Override
 36     public String elemtype(String s) {
 37         if (!s.startsWith("[")) {
 38             throw new IllegalStateException();
 39         }
 40         return s.substring(1);
 41     }
 42 
 43     @Override
 44     public String arrayOf(String s) {
 45         return "[" + s;
 46     }
 47 
 48     @Override
 49     public boolean isInlineClass(String t) {
 50         return t.charAt(0) == 'Q' && t.endsWith(";");
 51     }
 52 
 53     @Override
 54     public String type(String s) {
 55         return "L" + s + ";";
 56     }
 57 
 58     @Override
 59     public String valueType(String s) {
 60         return "Q" + s + ";";
 61     }
 62 
 63     @Override
 64     public TypeTag tag(String s) {
 65         switch (s.charAt(0)) {
 66             case '[':
 67             case 'L':
 68             case 'Q':
 69                 return TypeTag.A;
 70             case 'B':
 71             case 'C':
 72             case 'Z':
 73             case 'S':
 74             case 'I':
 75                 return TypeTag.I;
 76             case 'F':
 77                 return TypeTag.F;
 78             case 'J':
 79                 return TypeTag.J;
 80             case 'D':
 81                 return TypeTag.D;
 82             case 'V':
 83                 return TypeTag.V;


 84             default:
 85                 if (s == nullType()) {
 86                     return TypeTag.A;
 87                 }
 88                 throw new IllegalStateException("Bad type: " + s);
 89         }
 90     }
 91 
 92     @Override
 93     public String nullType() {
 94         // Needed in TypedCodeBuilder; ACONST_NULL pushes a 'null' onto the stack,
 95         // and stack maps handle null differently
 96         return "<null>";
 97     }
 98 
 99     @Override
100     public String commonSupertype(String t1, String t2) {
101         if (t1.equals(t2)) {
102             return t1;
103         } else {
104             try {
105                 Class<?> c1 = from(t1);
106                 Class<?> c2 = from(t2);
107                 if (c1.isAssignableFrom(c2)) {
< prev index next >