< prev index next >

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

Print this page




1347                                      Map<String, Module> nameToModule,
1348                                      List<ModuleLayer> parents) {
1349         Module m = nameToSource.get(target);
1350         if (m == null) {
1351             m = nameToModule.get(target);
1352             if (m == null) {
1353                 for (ModuleLayer parent : parents) {
1354                     m = parent.findModule(target).orElse(null);
1355                     if (m != null) break;
1356                 }
1357             }
1358         }
1359         return m;
1360     }
1361 
1362 
1363     // -- annotations --
1364 
1365     /**
1366      * {@inheritDoc}

1367      * This method returns {@code null} when invoked on an unnamed module.
1368      */
1369     @Override
1370     public <T extends Annotation> T getAnnotation(Class<T> annotationClass) {
1371         return moduleInfoClass().getDeclaredAnnotation(annotationClass);
1372     }
1373 
1374     /**
1375      * {@inheritDoc}

1376      * This method returns an empty array when invoked on an unnamed module.
1377      */
1378     @Override
1379     public Annotation[] getAnnotations() {
1380         return moduleInfoClass().getAnnotations();
1381     }
1382 
1383     /**
1384      * {@inheritDoc}

1385      * This method returns an empty array when invoked on an unnamed module.
1386      */
1387     @Override
1388     public Annotation[] getDeclaredAnnotations() {
1389         return moduleInfoClass().getDeclaredAnnotations();
1390     }
1391 
1392     // cached class file with annotations
1393     private volatile Class<?> moduleInfoClass;
1394 
1395     private Class<?> moduleInfoClass() {
1396         Class<?> clazz = this.moduleInfoClass;
1397         if (clazz != null)
1398             return clazz;
1399 
1400         synchronized (this) {
1401             clazz = this.moduleInfoClass;
1402             if (clazz == null) {
1403                 if (isNamed()) {
1404                     PrivilegedAction<Class<?>> pa = this::loadModuleInfoClass;




1347                                      Map<String, Module> nameToModule,
1348                                      List<ModuleLayer> parents) {
1349         Module m = nameToSource.get(target);
1350         if (m == null) {
1351             m = nameToModule.get(target);
1352             if (m == null) {
1353                 for (ModuleLayer parent : parents) {
1354                     m = parent.findModule(target).orElse(null);
1355                     if (m != null) break;
1356                 }
1357             }
1358         }
1359         return m;
1360     }
1361 
1362 
1363     // -- annotations --
1364 
1365     /**
1366      * {@inheritDoc}
1367      * <p>Any annotation returned by this method is a declaration annotation.
1368      * This method returns {@code null} when invoked on an unnamed module.
1369      */
1370     @Override
1371     public <T extends Annotation> T getAnnotation(Class<T> annotationClass) {
1372         return moduleInfoClass().getDeclaredAnnotation(annotationClass);
1373     }
1374 
1375     /**
1376      * {@inheritDoc}
1377      * <p>Any annotations returned by this method are declaration annotations.
1378      * This method returns an empty array when invoked on an unnamed module.
1379      */
1380     @Override
1381     public Annotation[] getAnnotations() {
1382         return moduleInfoClass().getAnnotations();
1383     }
1384 
1385     /**
1386      * {@inheritDoc}
1387      * <p>Any annotations returned by this method are declaration annotations.
1388      * This method returns an empty array when invoked on an unnamed module.
1389      */
1390     @Override
1391     public Annotation[] getDeclaredAnnotations() {
1392         return moduleInfoClass().getDeclaredAnnotations();
1393     }
1394 
1395     // cached class file with annotations
1396     private volatile Class<?> moduleInfoClass;
1397 
1398     private Class<?> moduleInfoClass() {
1399         Class<?> clazz = this.moduleInfoClass;
1400         if (clazz != null)
1401             return clazz;
1402 
1403         synchronized (this) {
1404             clazz = this.moduleInfoClass;
1405             if (clazz == null) {
1406                 if (isNamed()) {
1407                     PrivilegedAction<Class<?>> pa = this::loadModuleInfoClass;


< prev index next >