< prev index next >

src/java.base/share/classes/jdk/internal/module/ModuleInfoExtender.java

Print this page

        

@@ -41,10 +41,11 @@
 import jdk.internal.org.objectweb.asm.ClassVisitor;
 import jdk.internal.org.objectweb.asm.ClassWriter;
 import jdk.internal.org.objectweb.asm.Opcodes;
 
 import static jdk.internal.module.ClassFileAttributes.*;
+import static jdk.internal.module.WarnIfResolvedReason.NONE;
 
 /**
  * Utility class to extend a module-info.class with additional attributes.
  */
 

@@ -68,10 +69,14 @@
     private String osVersion;
 
     // the hashes for the Hashes attribute
     private ModuleHashes hashes;
 
+    // ModuleResolution flags
+    private boolean doNotResolveByDefault;
+    private WarnIfResolvedReason warnIfResolvedReason = NONE;
+
     private ModuleInfoExtender(InputStream in) {
         this.in = in;
     }
 
     /**

@@ -119,10 +124,20 @@
         this.hashes = hashes;
         return this;
     }
 
     /**
+     * Sets the value for the ModuleResolution attribute.
+     */
+    public ModuleInfoExtender moduleResolution(boolean doNotResolveByDefault,
+                                               WarnIfResolvedReason reason) {
+        this.doNotResolveByDefault = doNotResolveByDefault;
+        this.warnIfResolvedReason = reason;
+        return this;
+    }
+
+    /**
      * A ClassVisitor that supports adding class file attributes. If an
      * attribute already exists then the first occurence of the attribute
      * is replaced.
      */
     private static class AttributeAddingClassVisitor extends ClassVisitor {

@@ -189,10 +204,14 @@
             cv.addAttribute(new ModuleMainClassAttribute(mainClass));
         if (osName != null || osArch != null || osVersion != null)
             cv.addAttribute(new ModuleTargetAttribute(osName, osArch, osVersion));
         if (hashes != null)
             cv.addAttribute(new ModuleHashesAttribute(hashes));
+        if (doNotResolveByDefault || warnIfResolvedReason != NONE)
+            cv.addAttribute(new ModuleResolution(doNotResolveByDefault,
+                                                 warnIfResolvedReason));
+
 
         List<Attribute> attrs = new ArrayList<>();
 
         // prototypes of attributes that should be parsed
         attrs.add(new ModuleAttribute());
< prev index next >