Esempio n. 1
0
 public Map<String, LinkedInterfaceNode> buildTree(ClassProvider provider) {
   boolean complete;
   do {
     complete = true;
     classes:
     for (InterfaceNode node : classes.values()) {
       String name = node.name;
       for (String parent : node.parents) {
         InterfaceNode p = classes.get(parent);
         if (p == null) {
           p = provider.getClass(parent);
           if (p != null) {
             classes.put(parent, p);
             complete = false;
             break classes;
           } else {
             /*System.out.println("Class " + parent
             + " could not be provided for class "
             + node.name + ".");*/
           }
         }
         if (p != null) {
           List<String> children = p.children;
           if (!children.contains(name)) {
             children.add(name);
           }
         }
       }
     }
   } while (!complete);
   Map<String, LinkedInterfaceNode> tree = new HashMap<String, LinkedInterfaceNode>();
   for (InterfaceNode cn : classes.values()) {
     tree.put(
         cn.name,
         new LinkedInterfaceNode(
             cn.name, cn.access, cn.superName, cn.external, cn.fields, cn.methods));
   }
   for (LinkedInterfaceNode in : tree.values()) {
     InterfaceNode cn = classes.get(in.name);
     if (cn != null) {
       for (String parent : cn.parents) {
         LinkedInterfaceNode p = tree.get(parent);
         if (p == null) {
           System.err.println("Parent " + parent + " not found!");
         } else {
           in.addParent(p);
         }
       }
       for (String child : cn.children) {
         in.addChild(tree.get(child));
       }
     }
   }
   return tree;
 }
Esempio n. 2
0
 // TODO: Pass renaming rules to this method.
 public Remapper rename(Map<String, LinkedInterfaceNode> tree) {
   for (LinkedInterfaceNode node : tree.values()) {
     boolean cont;
     do {
       cont = false;
       if (node.rename("Class" + classPostfix) && !node.external) {
         ++classPostfix;
         cont = true;
       }
     } while (cont);
   }
   NameRemapper remapper = new NameRemapper(tree);
   for (LinkedInterfaceNode node : tree.values()) {
     if (node.name.startsWith("jag") && node.name.startsWith("jac")) {
       continue;
     }
     if (!node.external) {
       for (MemberNode field : node.getFields()) {
         if (node.renameField(field, getFieldName(remapper, field.desc, fieldPostfix))) {
           ++fieldPostfix;
         }
       }
       for (MemberNode method : node.getMethods()) {
         if (method.name.length() < 3) {
           if (node.renameMethod(method, "method" + methodPostfix)) {
             ++methodPostfix;
           }
         }
       }
     }
   }
   return remapper;
 }
Esempio n. 3
0
 public static void dumpMappings(Map<String, LinkedInterfaceNode> tree, File out)
     throws IOException {
   BufferedWriter writer = new BufferedWriter(new FileWriter(out));
   for (LinkedInterfaceNode node : tree.values()) {
     if (!node.external) {
       String newName = node.getNewName();
       if (newName != null) {
         writer.newLine();
         writer.write("	Old Class:" + node.name + " New Class:" + node.getNewName());
         writer.newLine();
         writer.write("Fields Renamed \n");
         writer.newLine();
         for (MemberNode field : node.getFields()) {
           String desc = field.desc;
           String name_old = field.name;
           String name_new = node.getFieldName(name_old, desc);
           if (!name_old.equals(name_new)) {
             writer.write(
                 "		Old Field: " + name_old + " New: " + name_new + " Field Signature: " + desc);
             writer.newLine();
           }
         }
         writer.newLine();
         writer.write("Methods Renamed \n");
         writer.newLine();
         for (MemberNode method : node.getMethods()) {
           String desc = method.desc;
           String name_old = method.name;
           String name_new = node.getMethodName(name_old, method.desc);
           if (!name_old.equals(name_new)) {
             writer.write(
                 "		Old Method Name: "
                     + name_old
                     + " New Name: "
                     + name_new
                     + " Method Signature: "
                     + desc);
             writer.newLine();
           }
         }
       } else {
         writer.newLine();
         writer.write("	Class:" + node.name);
         writer.newLine();
         writer.write("Fields Renamed \n");
         writer.newLine();
         for (MemberNode field : node.getFields()) {
           String desc = field.desc;
           String name_old = field.name;
           String name_new = node.getFieldName(name_old, desc);
           if (!name_old.equals(name_new)) {
             writer.write(
                 "		Old Field: " + name_old + " New: " + name_new + " Field Signature: " + desc);
             writer.newLine();
           }
         }
         writer.newLine();
         writer.write("Methods Renamed \n");
         writer.newLine();
         for (MemberNode method : node.getMethods()) {
           String desc = method.desc;
           String name_old = method.name;
           String name_new = node.getMethodName(name_old, method.desc);
           if (!name_old.equals(name_new)) {
             writer.write(
                 "		Old Method Name: "
                     + name_old
                     + " New Name: "
                     + name_new
                     + " Method Signature: "
                     + desc);
             writer.newLine();
           }
         }
       }
     }
   }
   writer.flush();
 }