src/jdk.jdeps/share/classes/com/sun/tools/javap/ConstantWriter.java
changeset 47875 93bba74ed8a3
parent 47216 71c04702a3d5
child 48826 c4d9d1b08e2e
equal deleted inserted replaced
47873:7944849362f3 47875:93bba74ed8a3
     1 /*
     1 /*
     2  * Copyright (c) 2007, 2016, Oracle and/or its affiliates. All rights reserved.
     2  * Copyright (c) 2007, 2017, 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
   251             default:
   251             default:
   252                 return "(unknown tag " + tag + ")";
   252                 return "(unknown tag " + tag + ")";
   253         }
   253         }
   254     }
   254     }
   255 
   255 
       
   256     String booleanValue(int constant_pool_index) {
       
   257         ClassFile classFile = classWriter.getClassFile();
       
   258         try {
       
   259             CPInfo info = classFile.constant_pool.get(constant_pool_index);
       
   260             if (info instanceof CONSTANT_Integer_info) {
       
   261                 int value = ((CONSTANT_Integer_info) info).value;
       
   262                switch (value) {
       
   263                    case 0: return "false";
       
   264                    case 1: return "true";
       
   265                }
       
   266             }
       
   267             return "#" + constant_pool_index;
       
   268         } catch (ConstantPool.InvalidIndex e) {
       
   269             return report(e);
       
   270         }
       
   271     }
       
   272 
       
   273     String charValue(int constant_pool_index) {
       
   274         ClassFile classFile = classWriter.getClassFile();
       
   275         try {
       
   276             CPInfo info = classFile.constant_pool.get(constant_pool_index);
       
   277             if (info instanceof CONSTANT_Integer_info) {
       
   278                 int value = ((CONSTANT_Integer_info) info).value;
       
   279                 return String.valueOf((char) value);
       
   280             } else {
       
   281                 return "#" + constant_pool_index;
       
   282             }
       
   283         } catch (ConstantPool.InvalidIndex e) {
       
   284             return report(e);
       
   285         }
       
   286     }
       
   287 
   256     String stringValue(int constant_pool_index) {
   288     String stringValue(int constant_pool_index) {
   257         ClassFile classFile = classWriter.getClassFile();
   289         ClassFile classFile = classWriter.getClassFile();
   258         try {
   290         try {
   259             return stringValue(classFile.constant_pool.get(constant_pool_index));
   291             return stringValue(classFile.constant_pool.get(constant_pool_index));
   260         } catch (ConstantPool.InvalidIndex e) {
   292         } catch (ConstantPool.InvalidIndex e) {