Ability to compare two class files after fields, methods, etc. have been sorted.
The idea is that two classes are compared such that the occurrence of fields,
methods, etc. do not "confuse" the diff view.
The use-case is this:
Source-code and its corresponding .class are available. Then, .class is
modified structurally (fields, methods added, removed, changed) such that when
new .class is compared with the original .class, the new structural changes do
not longer confuse the diff view.
The changes are the following:
(patch form)
### Eclipse Workspace Patch 1.0
#P de.loskutov.ByteCodeOutline
Index: src/de/loskutov/bco/asm/SortedClassNode.java
===================================================================
--- src/de/loskutov/bco/asm/SortedClassNode.java (revision 0)
+++ src/de/loskutov/bco/asm/SortedClassNode.java (working copy)
@@ -0,0 +1,54 @@
+package de.loskutov.bco.asm;
+
+import java.util.Collections;
+import java.util.Comparator;
+
+import org.objectweb.asm.ClassVisitor;
+import org.objectweb.asm.tree.ClassNode;
+import org.objectweb.asm.tree.FieldNode;
+import org.objectweb.asm.tree.InnerClassNode;
+import org.objectweb.asm.tree.MethodNode;
+
+
+public class SortedClassNode extends ClassNode {
+
+ public SortedClassNode(final int api) {
+ super(api);
+ }
+
+ @Override
+ public void accept(final ClassVisitor acv) {
+ sortAll();
+ super.accept(acv);
+ }
+
+ public void sortAll() {
+
+ Collections.sort(interfaces);
+
+ Collections.sort(innerClasses, new Comparator() {
+ @Override
+ public int compare(Object arg0, Object arg1) {
+ InnerClassNode ic0 = (InnerClassNode) arg0;
+ InnerClassNode ic1 = (InnerClassNode) arg1;
+ return ic0.name.compareTo(ic1.name);
+ }});
+
+ Collections.sort(fields, new Comparator() {
+ @Override
+ public int compare(Object arg0, Object arg1) {
+ FieldNode fn0 = (FieldNode) arg0;
+ FieldNode fn1 = (FieldNode) arg1;
+ return fn0.name.compareTo(fn1.name);
+ }});
+
+ Collections.sort(methods, new Comparator() {
+ @Override
+ public int compare(Object arg0, Object arg1) {
+ MethodNode mn0 = (MethodNode) arg0;
+ MethodNode mn1 = (MethodNode) arg1;
+ return mn0.name.compareTo(mn1.name);
+ }});
+
+ }
+}
Index: src/de/loskutov/bco/asm/DecompilerHelper.java
===================================================================
--- src/de/loskutov/bco/asm/DecompilerHelper.java (revision 1635)
+++ src/de/loskutov/bco/asm/DecompilerHelper.java (working copy)
@@ -31,7 +31,7 @@
DecompilerOptions options)
throws IOException, UnsupportedClassVersionError {
ClassReader cr = new ClassReader(is);
- ClassNode cn = new ClassNode(Opcodes.ASM4);
+ ClassNode cn = new SortedClassNode(Opcodes.ASM4);
int crFlags = 0;
if(options.modes.get(BCOConstants.F_EXPAND_STACKMAP)) {
crFlags |= ClassReader.EXPAND_FRAMES;