< prev index next >

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

Print this page
*** 36,10 ***
--- 36,12 ---
  
  import java.lang.constant.ClassDesc;
  import java.lang.reflect.Modifier;
  import java.util.ArrayList;
  import java.util.LinkedHashSet;
+ 
+ import com.sun.tools.javac.code.Source;
  import java.lang.classfile.AccessFlags;
  import java.lang.classfile.Attributes;
  import java.lang.classfile.ClassModel;
  import java.lang.classfile.ClassSignature;
  import java.lang.classfile.ClassFile;

*** 149,11 ***
  
          if (options.sysInfo || options.verbose) {
              indent(-1);
          }
  
!         writeModifiers(getClassModifiers(cm.flags()));
  
          if ((classModel.flags().flagsMask() & ACC_MODULE) != 0) {
              var attr = classModel.findAttribute(Attributes.module());
              if (attr.isPresent()) {
                  var modAttr = attr.get();
--- 151,11 ---
  
          if (options.sysInfo || options.verbose) {
              indent(-1);
          }
  
!         writeModifiers(getClassModifiers(cm.flags(), classModel.majorVersion(), classModel.minorVersion()));
  
          if ((classModel.flags().flagsMask() & ACC_MODULE) != 0) {
              var attr = classModel.findAttribute(Attributes.module());
              if (attr.isPresent()) {
                  var modAttr = attr.get();

*** 446,11 ***
              print("descriptor: ");println(() -> f.fieldType().stringValue());
          }
  
          if (options.verbose)
              writeList(String.format("flags: (0x%04x) ", flags.flagsMask()),
!                     flagsReportUnknown(flags).stream().map(fl -> "ACC_" + fl.name()).toList(),
                      "\n");
  
          if (options.showAllAttrs) {
              attrWriter.write(f.attributes());
              showBlank = true;
--- 448,11 ---
              print("descriptor: ");println(() -> f.fieldType().stringValue());
          }
  
          if (options.verbose)
              writeList(String.format("flags: (0x%04x) ", flags.flagsMask()),
!                     flagsReportUnknown(flags).stream().map(fl -> "ACC_" + fl.toString()).toList(),
                      "\n");
  
          if (options.showAllAttrs) {
              attrWriter.write(f.attributes());
              showBlank = true;

*** 806,10 ***
--- 808,24 ---
              set = flagSet;
          }
          return getModifiers(set);
      }
  
+     private static Set<String> getClassModifiers(AccessFlags flags, int majorVersion, int minorVersion) {
+         boolean previewClassFile = minorVersion == ClassFile.PREVIEW_MINOR_VERSION;
+         Set<AccessFlag> flagSet = flags.flags();
+         if (flagSet.contains(AccessFlag.INTERFACE)) {
+             flagSet = EnumSet.copyOf(flagSet);
+             flagSet.remove(AccessFlag.ABSTRACT);
+         } else if (Source.isSupported(Source.Feature.VALUE_CLASSES, majorVersion) && previewClassFile) {
+           Set<String> classModifers = getModifiers(flagSet);
+           classModifers.add("value");
+           return classModifers;
+         }
+         return getModifiers(flagSet);
+     }
+ 
      private static Set<String> getModifiers(Set<java.lang.reflect.AccessFlag> flags) {
          Set<String> s = new LinkedHashSet<>();
          for (var f : flags)
              if (f.sourceModifier()) s.add(Modifier.toString(f.mask()));
          return s;
< prev index next >