use of org.eclipse.ceylon.langtools.classfile.Attribute in project ceylon by eclipse.
the class Java9Util method generateModuleDescriptor.
private static ClassFile generateModuleDescriptor(Java9ModuleDescriptor module) {
CPInfo[] pool = new ConstantPool.CPInfo[1 + 7 + (module.imports.size() * 2) + (module.getPackagesSize() * 2) + (module.main != null ? 3 : 0)];
ConstantPool constantPool = new ConstantPool(pool);
int cp = 1;
// 1: this_class name
pool[cp++] = new ConstantPool.CONSTANT_Utf8_info("module-info");
// 2: this_class
pool[cp++] = new ConstantPool.CONSTANT_Class_info(constantPool, 1);
// 3: module attr
pool[cp++] = new ConstantPool.CONSTANT_Utf8_info(Attribute.Module);
// 4: module pkgs attr
pool[cp++] = new ConstantPool.CONSTANT_Utf8_info(Attribute.ModulePackages);
// 5: version
pool[cp++] = new ConstantPool.CONSTANT_Utf8_info(module.version);
// 6: module name
pool[cp++] = new ConstantPool.CONSTANT_Utf8_info(module.name);
// 7: module info
pool[cp++] = new ConstantPool.CONSTANT_Module_info(constantPool, 6);
if (module.main != null) {
// 8: main attr
pool[cp++] = new ConstantPool.CONSTANT_Utf8_info(Attribute.ModuleMainClass);
// 9: main class name
pool[cp++] = new ConstantPool.CONSTANT_Utf8_info(module.main.replace('.', '/'));
// 10: main class
pool[cp++] = new ConstantPool.CONSTANT_Class_info(constantPool, 9);
}
int i = 0;
// now imports
Module_attribute.RequiresEntry[] requires = new Module_attribute.RequiresEntry[module.imports.size()];
for (Java9ModuleImport imp : module.imports) {
pool[cp] = new ConstantPool.CONSTANT_Utf8_info(imp.name);
pool[cp + 1] = new ConstantPool.CONSTANT_Module_info(constantPool, cp);
int flag = 0;
if (imp.exported)
flag |= Module_attribute.ACC_TRANSITIVE;
// FIXME: add version info!
requires[i] = new Module_attribute.RequiresEntry(cp + 1, flag, 0);
i++;
cp += 2;
}
Module_attribute.ExportsEntry[] exports = new Module_attribute.ExportsEntry[module.exportedPackages.size()];
i = 0;
int[] modulePackages = new int[module.exportedPackages.size() + module.concealedPackages.size()];
int m = 0;
for (String pkg : module.exportedPackages) {
pool[cp] = new ConstantPool.CONSTANT_Utf8_info(pkg.replace('.', '/'));
pool[cp + 1] = new ConstantPool.CONSTANT_Package_info(constantPool, cp);
exports[i++] = new Module_attribute.ExportsEntry(cp + 1, 0, new int[0]);
modulePackages[m++] = cp + 1;
cp += 2;
}
for (String pkg : module.concealedPackages) {
pool[cp] = new ConstantPool.CONSTANT_Utf8_info(pkg.replace('.', '/'));
pool[cp + 1] = new ConstantPool.CONSTANT_Package_info(constantPool, cp);
modulePackages[m++] = cp + 1;
cp += 2;
}
Attribute[] attributesArray = new Attribute[2 + (module.main != null ? 1 : 0)];
attributesArray[0] = new Module_attribute(3, // module name index
7, // flags
0, // version
5, requires, exports, new Module_attribute.OpensEntry[0], new int[0], new Module_attribute.ProvidesEntry[0]);
attributesArray[1] = new ModulePackages_attribute(4, modulePackages);
if (module.main != null)
attributesArray[2] = new ModuleMainClass_attribute(8, 10);
Attributes attributes = new Attributes(constantPool, attributesArray);
return new ClassFile(org.eclipse.ceylon.langtools.tools.javac.jvm.ClassFile.JAVA_MAGIC, org.eclipse.ceylon.langtools.tools.javac.jvm.ClassFile.Version.V53.minor, org.eclipse.ceylon.langtools.tools.javac.jvm.ClassFile.Version.V53.major, constantPool, new org.eclipse.ceylon.langtools.classfile.AccessFlags(org.eclipse.ceylon.langtools.classfile.AccessFlags.ACC_MODULE), 2, 0, new int[0], new org.eclipse.ceylon.langtools.classfile.Field[0], new org.eclipse.ceylon.langtools.classfile.Method[0], attributes);
}
Aggregations