< prev index next >

src/jdk.jdeps/share/classes/com/sun/tools/javap/AttributeWriter.java

Print this page

 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
 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 jdk.internal.classfile.*;
 33 import java.lang.reflect.AccessFlag;
 34 import jdk.internal.classfile.constantpool.*;
 35 import jdk.internal.classfile.attribute.*;
 36 import static jdk.internal.classfile.Classfile.*;
 37 import static jdk.internal.classfile.attribute.StackMapFrameInfo.*;
 38 



 39 /*
 40  *  A writer for writing Attributes as text.
 41  *
 42  *  <p><b>This is NOT part of any supported API.
 43  *  If you write code that depends on this, you do so at your own risk.
 44  *  This code and its internal interfaces are subject to change or
 45  *  deletion without notice.</b>
 46  */
 47 public class AttributeWriter extends BasicWriter {
 48 
 49     public static AttributeWriter instance(Context context) {
 50         AttributeWriter instance = context.get(AttributeWriter.class);
 51         if (instance == null)
 52             instance = new AttributeWriter(context);
 53         return instance;
 54     }
 55 
 56     protected AttributeWriter(Context context) {
 57         super(context);
 58         context.put(AttributeWriter.class, this);

507             case RuntimeVisibleTypeAnnotationsAttribute attr ->
508                 printTypeAnnotations("RuntimeVisibleTypeAnnotations:",
509                         attr.annotations(), lr);
510             case RuntimeInvisibleTypeAnnotationsAttribute attr ->
511                 printTypeAnnotations("RuntimeInvisibleTypeAnnotations:",
512                         attr.annotations(), lr);
513             case RuntimeVisibleParameterAnnotationsAttribute attr ->
514                 printParameterAnnotations("RuntimeVisibleParameterAnnotations:",
515                         attr.parameterAnnotations());
516             case RuntimeInvisibleParameterAnnotationsAttribute attr ->
517                 printParameterAnnotations("RuntimeInvisibleParameterAnnotations:",
518                         attr.parameterAnnotations());
519             case PermittedSubclassesAttribute attr -> {
520                 println("PermittedSubclasses:");
521                 indent(+1);
522                 for (var sc : attr.permittedSubclasses()) {
523                     println(constantWriter.stringValue(sc));
524                 }
525                 indent(-1);
526             }








527             case SignatureAttribute attr -> {
528                 print("Signature: #" + attr.signature().index());
529                 tab();
530                 println("// " + attr.signature().stringValue());
531             }
532             case SourceDebugExtensionAttribute attr -> {
533                 println("SourceDebugExtension:");
534                 indent(+1);
535                 for (String s: new String(attr.contents(), StandardCharsets.UTF_8)
536                         .split("[\r\n]+")) {
537                     println(s);
538                 }
539                 indent(-1);
540             }
541             case SourceFileAttribute attr ->
542                 println("SourceFile: \"" + attr.sourceFile().stringValue() + "\"");
543             case SourceIDAttribute attr ->
544                 constantWriter.write(attr.sourceId().index());
545             case StackMapTableAttribute attr -> {
546                 var entries = attr.entries();

 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
 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 jdk.internal.classfile.*;
 33 import java.lang.reflect.AccessFlag;
 34 import jdk.internal.classfile.constantpool.*;
 35 import jdk.internal.classfile.attribute.*;
 36 import static jdk.internal.classfile.Classfile.*;
 37 import static jdk.internal.classfile.attribute.StackMapFrameInfo.*;
 38 
 39 import com.sun.tools.javac.util.Assert;
 40 import com.sun.tools.javac.util.StringUtils;
 41 
 42 /*
 43  *  A writer for writing Attributes as text.
 44  *
 45  *  <p><b>This is NOT part of any supported API.
 46  *  If you write code that depends on this, you do so at your own risk.
 47  *  This code and its internal interfaces are subject to change or
 48  *  deletion without notice.</b>
 49  */
 50 public class AttributeWriter extends BasicWriter {
 51 
 52     public static AttributeWriter instance(Context context) {
 53         AttributeWriter instance = context.get(AttributeWriter.class);
 54         if (instance == null)
 55             instance = new AttributeWriter(context);
 56         return instance;
 57     }
 58 
 59     protected AttributeWriter(Context context) {
 60         super(context);
 61         context.put(AttributeWriter.class, this);

510             case RuntimeVisibleTypeAnnotationsAttribute attr ->
511                 printTypeAnnotations("RuntimeVisibleTypeAnnotations:",
512                         attr.annotations(), lr);
513             case RuntimeInvisibleTypeAnnotationsAttribute attr ->
514                 printTypeAnnotations("RuntimeInvisibleTypeAnnotations:",
515                         attr.annotations(), lr);
516             case RuntimeVisibleParameterAnnotationsAttribute attr ->
517                 printParameterAnnotations("RuntimeVisibleParameterAnnotations:",
518                         attr.parameterAnnotations());
519             case RuntimeInvisibleParameterAnnotationsAttribute attr ->
520                 printParameterAnnotations("RuntimeInvisibleParameterAnnotations:",
521                         attr.parameterAnnotations());
522             case PermittedSubclassesAttribute attr -> {
523                 println("PermittedSubclasses:");
524                 indent(+1);
525                 for (var sc : attr.permittedSubclasses()) {
526                     println(constantWriter.stringValue(sc));
527                 }
528                 indent(-1);
529             }
530             case PreloadAttribute attr -> {
531                 println("Preload:");
532                 indent(+1);
533                 for (var sc : attr.preloads()) {
534                     println(constantWriter.stringValue(sc));
535                 }
536                 indent(-1);
537             }
538             case SignatureAttribute attr -> {
539                 print("Signature: #" + attr.signature().index());
540                 tab();
541                 println("// " + attr.signature().stringValue());
542             }
543             case SourceDebugExtensionAttribute attr -> {
544                 println("SourceDebugExtension:");
545                 indent(+1);
546                 for (String s: new String(attr.contents(), StandardCharsets.UTF_8)
547                         .split("[\r\n]+")) {
548                     println(s);
549                 }
550                 indent(-1);
551             }
552             case SourceFileAttribute attr ->
553                 println("SourceFile: \"" + attr.sourceFile().stringValue() + "\"");
554             case SourceIDAttribute attr ->
555                 constantWriter.write(attr.sourceId().index());
556             case StackMapTableAttribute attr -> {
557                 var entries = attr.entries();
< prev index next >