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
23 * questions.
24 */
25
26 package com.sun.tools.javap;
27
28 import java.lang.reflect.Modifier;
29 import java.nio.charset.StandardCharsets;
30 import java.util.List;
31 import java.util.Locale;
32 import java.lang.classfile.*;
33 import java.lang.reflect.AccessFlag;
34 import java.lang.classfile.constantpool.*;
35 import java.lang.classfile.attribute.*;
36 import static java.lang.classfile.ClassFile.*;
37 import static java.lang.classfile.attribute.StackMapFrameInfo.*;
38 import static java.lang.classfile.instruction.CharacterRange.*;
39
40 /*
41 * A writer for writing Attributes as text.
42 *
43 * <p><b>This is NOT part of any supported API.
44 * If you write code that depends on this, you do so at your own risk.
45 * This code and its internal interfaces are subject to change or
46 * deletion without notice.</b>
47 */
48 public class AttributeWriter extends BasicWriter {
49
50 public static AttributeWriter instance(Context context) {
51 AttributeWriter instance = context.get(AttributeWriter.class);
52 if (instance == null)
53 instance = new AttributeWriter(context);
54 return instance;
55 }
56
57 protected AttributeWriter(Context context) {
58 super(context);
59 context.put(AttributeWriter.class, this);
508 case RuntimeVisibleTypeAnnotationsAttribute attr ->
509 printTypeAnnotations("RuntimeVisibleTypeAnnotations:",
510 attr.annotations(), lr);
511 case RuntimeInvisibleTypeAnnotationsAttribute attr ->
512 printTypeAnnotations("RuntimeInvisibleTypeAnnotations:",
513 attr.annotations(), lr);
514 case RuntimeVisibleParameterAnnotationsAttribute attr ->
515 printParameterAnnotations("RuntimeVisibleParameterAnnotations:",
516 attr.parameterAnnotations());
517 case RuntimeInvisibleParameterAnnotationsAttribute attr ->
518 printParameterAnnotations("RuntimeInvisibleParameterAnnotations:",
519 attr.parameterAnnotations());
520 case PermittedSubclassesAttribute attr -> {
521 println("PermittedSubclasses:");
522 indent(+1);
523 for (var sc : attr.permittedSubclasses()) {
524 println(constantWriter.stringValue(sc));
525 }
526 indent(-1);
527 }
528 case SignatureAttribute attr -> {
529 print("Signature: #" + attr.signature().index());
530 tab();
531 println("// " + attr.signature().stringValue());
532 }
533 case SourceDebugExtensionAttribute attr -> {
534 println("SourceDebugExtension:");
535 indent(+1);
536 for (String s: new String(attr.contents(), StandardCharsets.UTF_8)
537 .split("[\r\n]+")) {
538 println(s);
539 }
540 indent(-1);
541 }
542 case SourceFileAttribute attr ->
543 println("SourceFile: \"" + attr.sourceFile().stringValue() + "\"");
544 case SourceIDAttribute attr ->
545 constantWriter.write(attr.sourceId().index());
546 case StackMapTableAttribute attr -> {
547 var entries = attr.entries();
|
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
23 * questions.
24 */
25
26 package com.sun.tools.javap;
27
28 import java.lang.reflect.Modifier;
29 import java.nio.charset.StandardCharsets;
30 import java.util.List;
31 import java.util.Locale;
32 import java.lang.classfile.*;
33 import java.lang.reflect.AccessFlag;
34 import java.lang.classfile.constantpool.*;
35 import java.lang.classfile.attribute.*;
36 import static java.lang.classfile.ClassFile.*;
37 import static java.lang.classfile.attribute.StackMapFrameInfo.*;
38 import static java.lang.classfile.instruction.CharacterRange.*;
39
40 import com.sun.tools.javac.util.Assert;
41 import com.sun.tools.javac.util.StringUtils;
42
43 /*
44 * A writer for writing Attributes as text.
45 *
46 * <p><b>This is NOT part of any supported API.
47 * If you write code that depends on this, you do so at your own risk.
48 * This code and its internal interfaces are subject to change or
49 * deletion without notice.</b>
50 */
51 public class AttributeWriter extends BasicWriter {
52
53 public static AttributeWriter instance(Context context) {
54 AttributeWriter instance = context.get(AttributeWriter.class);
55 if (instance == null)
56 instance = new AttributeWriter(context);
57 return instance;
58 }
59
60 protected AttributeWriter(Context context) {
61 super(context);
62 context.put(AttributeWriter.class, this);
511 case RuntimeVisibleTypeAnnotationsAttribute attr ->
512 printTypeAnnotations("RuntimeVisibleTypeAnnotations:",
513 attr.annotations(), lr);
514 case RuntimeInvisibleTypeAnnotationsAttribute attr ->
515 printTypeAnnotations("RuntimeInvisibleTypeAnnotations:",
516 attr.annotations(), lr);
517 case RuntimeVisibleParameterAnnotationsAttribute attr ->
518 printParameterAnnotations("RuntimeVisibleParameterAnnotations:",
519 attr.parameterAnnotations());
520 case RuntimeInvisibleParameterAnnotationsAttribute attr ->
521 printParameterAnnotations("RuntimeInvisibleParameterAnnotations:",
522 attr.parameterAnnotations());
523 case PermittedSubclassesAttribute attr -> {
524 println("PermittedSubclasses:");
525 indent(+1);
526 for (var sc : attr.permittedSubclasses()) {
527 println(constantWriter.stringValue(sc));
528 }
529 indent(-1);
530 }
531 case LoadableDescriptorsAttribute attr -> {
532 println("LoadableDescriptors:");
533 indent(+1);
534 for (var sc : attr.loadableDescriptors()) {
535 println(constantWriter.stringValue(sc));
536 }
537 indent(-1);
538 }
539 case SignatureAttribute attr -> {
540 print("Signature: #" + attr.signature().index());
541 tab();
542 println("// " + attr.signature().stringValue());
543 }
544 case SourceDebugExtensionAttribute attr -> {
545 println("SourceDebugExtension:");
546 indent(+1);
547 for (String s: new String(attr.contents(), StandardCharsets.UTF_8)
548 .split("[\r\n]+")) {
549 println(s);
550 }
551 indent(-1);
552 }
553 case SourceFileAttribute attr ->
554 println("SourceFile: \"" + attr.sourceFile().stringValue() + "\"");
555 case SourceIDAttribute attr ->
556 constantWriter.write(attr.sourceId().index());
557 case StackMapTableAttribute attr -> {
558 var entries = attr.entries();
|