8156694: javap should render annotations in a friendly way

Reviewed-by: mcimadamore
This commit is contained in:
Jonathan Gibbons 2017-11-21 13:06:43 -08:00
parent 905ead0ac3
commit 3b8e460a1a
4 changed files with 288 additions and 22 deletions

View file

@ -1,5 +1,5 @@
/*
* Copyright (c) 2007, 2016, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2007, 2017, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@ -253,6 +253,38 @@ public class ConstantWriter extends BasicWriter {
}
}
String booleanValue(int constant_pool_index) {
ClassFile classFile = classWriter.getClassFile();
try {
CPInfo info = classFile.constant_pool.get(constant_pool_index);
if (info instanceof CONSTANT_Integer_info) {
int value = ((CONSTANT_Integer_info) info).value;
switch (value) {
case 0: return "false";
case 1: return "true";
}
}
return "#" + constant_pool_index;
} catch (ConstantPool.InvalidIndex e) {
return report(e);
}
}
String charValue(int constant_pool_index) {
ClassFile classFile = classWriter.getClassFile();
try {
CPInfo info = classFile.constant_pool.get(constant_pool_index);
if (info instanceof CONSTANT_Integer_info) {
int value = ((CONSTANT_Integer_info) info).value;
return String.valueOf((char) value);
} else {
return "#" + constant_pool_index;
}
} catch (ConstantPool.InvalidIndex e) {
return report(e);
}
}
String stringValue(int constant_pool_index) {
ClassFile classFile = classWriter.getClassFile();
try {