< prev index next >

src/java.base/share/classes/java/lang/Module.java

Print this page
rev 52456 : imported patch asm.additional


1416 
1417     private Class<?> loadModuleInfoClass() {
1418         Class<?> clazz = null;
1419         try (InputStream in = getResourceAsStream("module-info.class")) {
1420             if (in != null)
1421                 clazz = loadModuleInfoClass(in);
1422         } catch (Exception ignore) { }
1423         return clazz;
1424     }
1425 
1426     /**
1427      * Loads module-info.class as a package-private interface in a class loader
1428      * that is a child of this module's class loader.
1429      */
1430     private Class<?> loadModuleInfoClass(InputStream in) throws IOException {
1431         final String MODULE_INFO = "module-info";
1432 
1433         ClassWriter cw = new ClassWriter(ClassWriter.COMPUTE_MAXS
1434                                          + ClassWriter.COMPUTE_FRAMES);
1435 
1436         ClassVisitor cv = new ClassVisitor(Opcodes.ASM6, cw) {
1437             @Override
1438             public void visit(int version,
1439                               int access,
1440                               String name,
1441                               String signature,
1442                               String superName,
1443                               String[] interfaces) {
1444                 cw.visit(version,
1445                         Opcodes.ACC_INTERFACE
1446                             + Opcodes.ACC_ABSTRACT
1447                             + Opcodes.ACC_SYNTHETIC,
1448                         MODULE_INFO,
1449                         null,
1450                         "java/lang/Object",
1451                         null);
1452             }
1453             @Override
1454             public AnnotationVisitor visitAnnotation(String desc, boolean visible) {
1455                 // keep annotations
1456                 return super.visitAnnotation(desc, visible);




1416 
1417     private Class<?> loadModuleInfoClass() {
1418         Class<?> clazz = null;
1419         try (InputStream in = getResourceAsStream("module-info.class")) {
1420             if (in != null)
1421                 clazz = loadModuleInfoClass(in);
1422         } catch (Exception ignore) { }
1423         return clazz;
1424     }
1425 
1426     /**
1427      * Loads module-info.class as a package-private interface in a class loader
1428      * that is a child of this module's class loader.
1429      */
1430     private Class<?> loadModuleInfoClass(InputStream in) throws IOException {
1431         final String MODULE_INFO = "module-info";
1432 
1433         ClassWriter cw = new ClassWriter(ClassWriter.COMPUTE_MAXS
1434                                          + ClassWriter.COMPUTE_FRAMES);
1435 
1436         ClassVisitor cv = new ClassVisitor(Opcodes.ASM7, cw) {
1437             @Override
1438             public void visit(int version,
1439                               int access,
1440                               String name,
1441                               String signature,
1442                               String superName,
1443                               String[] interfaces) {
1444                 cw.visit(version,
1445                         Opcodes.ACC_INTERFACE
1446                             + Opcodes.ACC_ABSTRACT
1447                             + Opcodes.ACC_SYNTHETIC,
1448                         MODULE_INFO,
1449                         null,
1450                         "java/lang/Object",
1451                         null);
1452             }
1453             @Override
1454             public AnnotationVisitor visitAnnotation(String desc, boolean visible) {
1455                 // keep annotations
1456                 return super.visitAnnotation(desc, visible);


< prev index next >