private void RenameInterfaces() { List <ClassWrapperNode> lstInterfaces = GetReversePostOrderListIterative(rootInterfaces ); Dictionary <string, Dictionary <string, string> > interfaceNameMaps = new Dictionary <string, Dictionary <string, string> >(); // rename methods and fields foreach (ClassWrapperNode node in lstInterfaces) { StructClass cl = node.GetClassStruct(); Dictionary <string, string> names = new Dictionary <string, string>(); // merge information on super interfaces foreach (string ifName in cl.GetInterfaceNames()) { Dictionary <string, string> mapInt = interfaceNameMaps.GetOrNull(ifName); if (mapInt != null) { Sharpen.Collections.PutAll(names, mapInt); } } RenameClassIdentifiers(cl, names); Sharpen.Collections.Put(interfaceNameMaps, cl.qualifiedName, names); } this.interfaceNameMaps = interfaceNameMaps; }
public ImportCollector(ClassesProcessor.ClassNode root) { // set of field names in this class and all its predecessors. string clName = root.classStruct.qualifiedName; int index = clName.LastIndexOf('/'); if (index >= 0) { string packageName = Sharpen.Runtime.Substring(clName, 0, index); currentPackageSlash = packageName + '/'; currentPackagePoint = packageName.Replace('/', '.'); } else { currentPackageSlash = string.Empty; currentPackagePoint = string.Empty; } Dictionary <string, StructClass> classes = DecompilerContext.GetStructContext().GetClasses (); LinkedList <string> queue = new LinkedList <string>(); StructClass currentClass = root.classStruct; while (currentClass != null) { if (currentClass.superClass != null) { queue.AddLast(currentClass.superClass.GetString()); } Sharpen.Collections.AddAll(queue, currentClass.GetInterfaceNames()); // all field names for the current class .. foreach (StructField f in currentClass.GetFields()) { setFieldNames.Add(f.GetName()); } // .. all inner classes for the current class .. StructInnerClassesAttribute attribute = currentClass.GetAttribute(StructGeneralAttribute .Attribute_Inner_Classes); if (attribute != null) { foreach (StructInnerClassesAttribute.Entry entry in attribute.GetEntries()) { if (entry.enclosingName != null && entry.enclosingName.Equals(currentClass.qualifiedName )) { setInnerClassNames.Add(entry.simpleName); } } } // .. and traverse through parent. currentClass = !(queue.Count == 0) ? classes.GetOrNull(Sharpen.Collections.RemoveFirst (queue)) : null; while (currentClass == null && !(queue.Count == 0)) { currentClass = classes.GetOrNull(Sharpen.Collections.RemoveFirst(queue)); } } }
private void RenameClasses() { List <ClassWrapperNode> lstClasses = GetReversePostOrderListIterative(rootClasses ); Dictionary <string, Dictionary <string, string> > classNameMaps = new Dictionary <string , Dictionary <string, string> >(); foreach (ClassWrapperNode node in lstClasses) { StructClass cl = node.GetClassStruct(); Dictionary <string, string> names = new Dictionary <string, string>(); // merge information on super class if (cl.superClass != null) { Dictionary <string, string> mapClass = classNameMaps.GetOrNull(cl.superClass.GetString ()); if (mapClass != null) { Sharpen.Collections.PutAll(names, mapClass); } } // merge information on interfaces foreach (string ifName in cl.GetInterfaceNames()) { Dictionary <string, string> mapInt = interfaceNameMaps.GetOrNull(ifName); if (mapInt != null) { Sharpen.Collections.PutAll(names, mapInt); } else { StructClass clintr = context.GetClass(ifName); if (clintr != null) { Sharpen.Collections.PutAll(names, ProcessExternalInterface(clintr)); } } } RenameClassIdentifiers(cl, names); if (!(node.GetSubclasses().Count == 0)) { Sharpen.Collections.Put(classNameMaps, cl.qualifiedName, names); } } }
private Dictionary <string, string> ProcessExternalInterface(StructClass cl) { Dictionary <string, string> names = new Dictionary <string, string>(); foreach (string ifName in cl.GetInterfaceNames()) { Dictionary <string, string> mapInt = interfaceNameMaps.GetOrNull(ifName); if (mapInt != null) { Sharpen.Collections.PutAll(names, mapInt); } else { StructClass clintr = context.GetClass(ifName); if (clintr != null) { Sharpen.Collections.PutAll(names, ProcessExternalInterface(clintr)); } } } RenameClassIdentifiers(cl, names); return(names); }
private void BuildInheritanceTree() { Dictionary <string, ClassWrapperNode> nodes = new Dictionary <string, ClassWrapperNode >(); Dictionary <string, StructClass> classes = context.GetClasses(); List <ClassWrapperNode> rootClasses = new List <ClassWrapperNode>(); List <ClassWrapperNode> rootInterfaces = new List <ClassWrapperNode>(); foreach (StructClass cl in classes.Values) { if (!cl.IsOwn()) { continue; } LinkedList <StructClass> stack = new LinkedList <StructClass>(); LinkedList <ClassWrapperNode> stackSubNodes = new LinkedList <ClassWrapperNode>(); stack.AddLast(cl); stackSubNodes.AddLast((ClassWrapperNode)null); while (!(stack.Count == 0)) { StructClass clStr = Sharpen.Collections.RemoveFirst(stack); ClassWrapperNode child = Sharpen.Collections.RemoveFirst(stackSubNodes); ClassWrapperNode node = nodes.GetOrNull(clStr.qualifiedName); bool isNewNode = (node == null); if (isNewNode) { Sharpen.Collections.Put(nodes, clStr.qualifiedName, node = new ClassWrapperNode(clStr )); } if (child != null) { node.AddSubclass(child); } if (!isNewNode) { break; } else { bool isInterface = clStr.HasModifier(ICodeConstants.Acc_Interface); bool found_parent = false; if (isInterface) { foreach (string ifName in clStr.GetInterfaceNames()) { StructClass clParent = classes.GetOrNull(ifName); if (clParent != null) { stack.AddLast(clParent); stackSubNodes.AddLast(node); found_parent = true; } } } else if (clStr.superClass != null) { // null iff java/lang/Object StructClass clParent = classes.GetOrNull(clStr.superClass.GetString()); if (clParent != null) { stack.AddLast(clParent); stackSubNodes.AddLast(node); found_parent = true; } } if (!found_parent) { // no super class or interface (isInterface ? rootInterfaces : rootClasses).Add(node); } } } } this.rootClasses = rootClasses; this.rootInterfaces = rootInterfaces; }