示例#1
0
  private static void writeVariables(String _package, String _class, String _object)
      throws Exception {
    // out.printf( "\t//varaibles defined in %s%s (and its super classes/interfaces)\n\n", _package,
    // _class );

    Class gl_class = Class.forName(_package + _class);

    // Field[] fields = gl_class.getDeclaredFields(); // returns private fields

    Field[] fields = gl_class.getFields(); // only public fields

    for (Field f : fields) {
      String s = f.toString();

      int i1 = s.lastIndexOf(".");

      String s1 = s.substring(0, i1);

      int i2 = s1.lastIndexOf(' ');

      String s2 = s1.substring(0, i2);

      s1 = s1.substring(i2 + 1);

      out.printf("\t%s %s = %s.%s;\n", s2, f.getName(), s1, f.getName());
    }
  }
示例#2
0
  private MutableTreeNode populateAttributes(CavityDBObject obj) {
    DefaultMutableTreeNode tree = new DefaultMutableTreeNode("attrs");
    Class cls = obj.getClass();
    for (Field f : cls.getFields()) {
      int mod = f.getModifiers();
      if (Modifier.isPublic(mod) && !Modifier.isStatic(mod)) {
        String fieldName = f.getName();
        try {
          Object value = f.get(obj);
          tree.add(
              new DefaultMutableTreeNode(String.format("%s=%s", fieldName, String.valueOf(value))));

        } catch (IllegalAccessException e) {
          // do nothing.
        }
      }
    }
    return tree;
  }
示例#3
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);
         }
       }
     }
   }
 }