< prev index next >

src/jdk.jdeps/share/classes/com/sun/tools/classfile/Module_attribute.java

Print this page




  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  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.classfile;
  27 
  28 import java.io.IOException;
  29 


  30 /**
  31  * See Jigsaw.
  32  *
  33  *  <p><b>This is NOT part of any supported API.
  34  *  If you write code that depends on this, you do so at your own risk.
  35  *  This code and its internal interfaces are subject to change or
  36  *  deletion without notice.</b>
  37  */
  38 public class Module_attribute extends Attribute {
  39     public static final int ACC_TRANSITIVE      =   0x10;
  40     public static final int ACC_STATIC_PHASE    =   0x20;
  41     public static final int ACC_OPEN            =   0x20;
  42     public static final int ACC_SYNTHETIC       = 0x1000;
  43     public static final int ACC_MANDATED        = 0x8000;
  44 
  45     Module_attribute(ClassReader cr, int name_index, int length) throws IOException {
  46         super(name_index, length);
  47 
  48         module_name = cr.readUnsignedShort();
  49         module_flags = cr.readUnsignedShort();
  50 


  51         requires_count = cr.readUnsignedShort();
  52         requires = new RequiresEntry[requires_count];
  53         for (int i = 0; i < requires_count; i++)
  54             requires[i] = new RequiresEntry(cr);
  55 
  56         exports_count = cr.readUnsignedShort();
  57         exports = new ExportsEntry[exports_count];
  58         for (int i = 0; i < exports_count; i++)
  59             exports[i] = new ExportsEntry(cr);
  60 
  61         opens_count = cr.readUnsignedShort();
  62         opens = new OpensEntry[opens_count];
  63         for (int i = 0; i < opens_count; i++)
  64             opens[i] = new OpensEntry(cr);
  65 
  66         uses_count = cr.readUnsignedShort();
  67         uses_index = new int[uses_count];
  68         for (int i = 0; i < uses_count; i++)
  69             uses_index[i] = cr.readUnsignedShort();
  70 
  71         provides_count = cr.readUnsignedShort();
  72         provides = new ProvidesEntry[provides_count];
  73         for (int i = 0; i < provides_count; i++)
  74             provides[i] = new ProvidesEntry(cr);
  75     }
  76 
  77     public Module_attribute(int name_index,
  78             int module_name,
  79             int module_flags,

  80             RequiresEntry[] requires,
  81             ExportsEntry[] exports,
  82             OpensEntry[] opens,
  83             int[] uses,
  84             ProvidesEntry[] provides) {
  85         super(name_index, 2);
  86         this.module_name = module_name;
  87         this.module_flags = module_flags;

  88         requires_count = requires.length;
  89         this.requires = requires;
  90         exports_count = exports.length;
  91         this.exports = exports;
  92         opens_count = opens.length;
  93         this.opens = opens;
  94         uses_count = uses.length;
  95         this.uses_index = uses;
  96         provides_count = provides.length;
  97         this.provides = provides;
  98     }
  99 
 100     public String getUses(int index, ConstantPool constant_pool) throws ConstantPoolException {
 101         int i = uses_index[index];
 102         return constant_pool.getClassInfo(i).getName();
 103     }
 104 
 105     @Override
 106     public <R, D> R accept(Visitor<R, D> visitor, D data) {
 107         return visitor.visitModule(this, data);
 108     }
 109 
 110     public final int module_name;
 111     public final int module_flags;

 112     public final int requires_count;
 113     public final RequiresEntry[] requires;
 114     public final int exports_count;
 115     public final ExportsEntry[] exports;
 116     public final int opens_count;
 117     public final OpensEntry[] opens;
 118     public final int uses_count;
 119     public final int[] uses_index;
 120     public final int provides_count;
 121     public final ProvidesEntry[] provides;
 122 
 123     public static class RequiresEntry {
 124         RequiresEntry(ClassReader cr) throws IOException {
 125             requires_index = cr.readUnsignedShort();
 126             requires_flags = cr.readUnsignedShort();

 127         }
 128 
 129         public RequiresEntry(int index, int flags) {
 130             this.requires_index = index;
 131             this.requires_flags = flags;

 132         }
 133 
 134         public String getRequires(ConstantPool constant_pool) throws ConstantPoolException {
 135             return constant_pool.getUTF8Value(requires_index);

 136         }
 137 
 138         public static final int length = 4;
 139 
 140         public final int requires_index;
 141         public final int requires_flags;

 142     }
 143 
 144     public static class ExportsEntry {
 145         ExportsEntry(ClassReader cr) throws IOException {
 146             exports_index = cr.readUnsignedShort();
 147             exports_flags = cr.readUnsignedShort();
 148             exports_to_count = cr.readUnsignedShort();
 149             exports_to_index = new int[exports_to_count];
 150             for (int i = 0; i < exports_to_count; i++)
 151                 exports_to_index[i] = cr.readUnsignedShort();
 152         }
 153 
 154         public ExportsEntry(int index, int flags, int[] to) {
 155             this.exports_index = index;
 156             this.exports_flags = flags;
 157             this.exports_to_count = to.length;
 158             this.exports_to_index = to;
 159         }
 160 
 161         public int length() {




  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  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.classfile;
  27 
  28 import java.io.IOException;
  29 
  30 import com.sun.tools.classfile.ConstantPool.CONSTANT_Module_info;
  31 
  32 /**
  33  * See Jigsaw.
  34  *
  35  *  <p><b>This is NOT part of any supported API.
  36  *  If you write code that depends on this, you do so at your own risk.
  37  *  This code and its internal interfaces are subject to change or
  38  *  deletion without notice.</b>
  39  */
  40 public class Module_attribute extends Attribute {
  41     public static final int ACC_TRANSITIVE      =   0x10;
  42     public static final int ACC_STATIC_PHASE    =   0x20;
  43     public static final int ACC_OPEN            =   0x20;
  44     public static final int ACC_SYNTHETIC       = 0x1000;
  45     public static final int ACC_MANDATED        = 0x8000;
  46 
  47     Module_attribute(ClassReader cr, int name_index, int length) throws IOException {
  48         super(name_index, length);
  49 
  50         module_name = cr.readUnsignedShort();
  51         module_flags = cr.readUnsignedShort();
  52 
  53         module_version_index = cr.readUnsignedShort();
  54 
  55         requires_count = cr.readUnsignedShort();
  56         requires = new RequiresEntry[requires_count];
  57         for (int i = 0; i < requires_count; i++)
  58             requires[i] = new RequiresEntry(cr);
  59 
  60         exports_count = cr.readUnsignedShort();
  61         exports = new ExportsEntry[exports_count];
  62         for (int i = 0; i < exports_count; i++)
  63             exports[i] = new ExportsEntry(cr);
  64 
  65         opens_count = cr.readUnsignedShort();
  66         opens = new OpensEntry[opens_count];
  67         for (int i = 0; i < opens_count; i++)
  68             opens[i] = new OpensEntry(cr);
  69 
  70         uses_count = cr.readUnsignedShort();
  71         uses_index = new int[uses_count];
  72         for (int i = 0; i < uses_count; i++)
  73             uses_index[i] = cr.readUnsignedShort();
  74 
  75         provides_count = cr.readUnsignedShort();
  76         provides = new ProvidesEntry[provides_count];
  77         for (int i = 0; i < provides_count; i++)
  78             provides[i] = new ProvidesEntry(cr);
  79     }
  80 
  81     public Module_attribute(int name_index,
  82             int module_name,
  83             int module_flags,
  84             int module_version_index,
  85             RequiresEntry[] requires,
  86             ExportsEntry[] exports,
  87             OpensEntry[] opens,
  88             int[] uses,
  89             ProvidesEntry[] provides) {
  90         super(name_index, 2);
  91         this.module_name = module_name;
  92         this.module_flags = module_flags;
  93         this.module_version_index = module_version_index;
  94         requires_count = requires.length;
  95         this.requires = requires;
  96         exports_count = exports.length;
  97         this.exports = exports;
  98         opens_count = opens.length;
  99         this.opens = opens;
 100         uses_count = uses.length;
 101         this.uses_index = uses;
 102         provides_count = provides.length;
 103         this.provides = provides;
 104     }
 105 
 106     public String getUses(int index, ConstantPool constant_pool) throws ConstantPoolException {
 107         int i = uses_index[index];
 108         return constant_pool.getClassInfo(i).getName();
 109     }
 110 
 111     @Override
 112     public <R, D> R accept(Visitor<R, D> visitor, D data) {
 113         return visitor.visitModule(this, data);
 114     }
 115 
 116     public final int module_name;
 117     public final int module_flags;
 118     public final int module_version_index;
 119     public final int requires_count;
 120     public final RequiresEntry[] requires;
 121     public final int exports_count;
 122     public final ExportsEntry[] exports;
 123     public final int opens_count;
 124     public final OpensEntry[] opens;
 125     public final int uses_count;
 126     public final int[] uses_index;
 127     public final int provides_count;
 128     public final ProvidesEntry[] provides;
 129 
 130     public static class RequiresEntry {
 131         RequiresEntry(ClassReader cr) throws IOException {
 132             requires_index = cr.readUnsignedShort();
 133             requires_flags = cr.readUnsignedShort();
 134             requires_version_index = cr.readUnsignedShort();
 135         }
 136 
 137         public RequiresEntry(int index, int flags, int version_index) {
 138             this.requires_index = index;
 139             this.requires_flags = flags;
 140             this.requires_version_index = version_index;
 141         }
 142 
 143         public String getRequires(ConstantPool constant_pool) throws ConstantPoolException {
 144             CONSTANT_Module_info info = constant_pool.getModuleInfo(requires_index);
 145             return info.getName();
 146         }
 147 
 148         public static final int length = 4;
 149 
 150         public final int requires_index;
 151         public final int requires_flags;
 152         public final int requires_version_index;
 153     }
 154 
 155     public static class ExportsEntry {
 156         ExportsEntry(ClassReader cr) throws IOException {
 157             exports_index = cr.readUnsignedShort();
 158             exports_flags = cr.readUnsignedShort();
 159             exports_to_count = cr.readUnsignedShort();
 160             exports_to_index = new int[exports_to_count];
 161             for (int i = 0; i < exports_to_count; i++)
 162                 exports_to_index[i] = cr.readUnsignedShort();
 163         }
 164 
 165         public ExportsEntry(int index, int flags, int[] to) {
 166             this.exports_index = index;
 167             this.exports_flags = flags;
 168             this.exports_to_count = to.length;
 169             this.exports_to_index = to;
 170         }
 171 
 172         public int length() {


< prev index next >