Exemple #1
0
 private void processConfigurationModules(final Class<?> cmb) {
   for (final Field f : cmb.getFields()) {
     if (ReflectionUtilities.isCoercable(ConfigurationModule.class, f.getType())) {
       final int mod = f.getModifiers();
       boolean ok = true;
       if (Modifier.isPrivate(mod)) {
         System.err.println("Found private ConfigurationModule " + f);
         ok = false;
       }
       if (!Modifier.isFinal(mod)) {
         System.err.println("Found non-final ConfigurationModule " + f);
         ok = false;
       }
       if (!Modifier.isStatic(f.getModifiers())) {
         System.err.println("Found non-static ConfigurationModule " + f);
         ok = false;
       }
       if (ok) {
         //          System.err.println("OK: " + f);
         try {
           f.setAccessible(true);
           final String fS = ReflectionUtilities.getFullName(f);
           if (!modules.containsKey(f)) {
             modules.put(f, (ConfigurationModule) (f.get(null)));
             try {
               modules.get(f).assertStaticClean();
             } catch (final ClassHierarchyException e) {
               System.err.println(fS + ": " + e.getMessage());
             }
             for (final Entry<String, String> e : modules.get(f).toStringPairs()) {
               // System.err.println("e: " + e.getKey() + "=" + e.getValue());
               try {
                 final Node n = ch.getNode(e.getKey());
                 if (!setters.contains(e.getKey(), fS)) {
                   setters.put(e.getKey(), fS);
                 }
                 if (n instanceof ClassNode) {
                   final ClassNode<?> cn = (ClassNode<?>) n;
                   if (!knownClasses.contains(cn)) {
                     knownClasses.add(cn);
                   }
                 }
               } catch (final NameResolutionException ex) {
                 //
               }
               try {
                 final String s = e.getValue();
                 final Node n = ch.getNode(s);
                 if (!usages.contains(ReflectionUtilities.getFullName(f), s)) {
                   //  System.err.println("Added usage: " + ReflectionUtilities.getFullName(f) +
                   // "=" + s);
                   usages.put(s, ReflectionUtilities.getFullName(f));
                 }
                 if (n instanceof ClassNode) {
                   final ClassNode<?> cn = (ClassNode<?>) n;
                   if (!knownClasses.contains(cn)) {
                     System.err.println("Added " + cn + " to known classes");
                     knownClasses.add(cn);
                   }
                 }
               } catch (final NameResolutionException ex) {
                 //
               }
             }
           }
         } catch (final ExceptionInInitializerError e) {
           System.err.println(
               "Field " + ReflectionUtilities.getFullName(f) + ": " + e.getCause().getMessage());
         } catch (final IllegalAccessException e) {
           throw new RuntimeException(e);
         }
       }
     }
   }
 }