From b98e02e557eb7c30d6425ffd9cfa8b7b71b164dc Mon Sep 17 00:00:00 2001 From: md_5 Date: Fri, 24 Oct 2014 21:16:23 +1100 Subject: Spigot Changes --- .../jetbrains/java/decompiler/util/SortUtil.java | 65 +++++++++++++++ .../jetbrains/java/decompiler/util/VarHelper.java | 92 ++++++++++++++++++++++ 2 files changed, 157 insertions(+) create mode 100644 src/org/jetbrains/java/decompiler/util/SortUtil.java create mode 100644 src/org/jetbrains/java/decompiler/util/VarHelper.java (limited to 'src/org/jetbrains/java/decompiler/util') diff --git a/src/org/jetbrains/java/decompiler/util/SortUtil.java b/src/org/jetbrains/java/decompiler/util/SortUtil.java new file mode 100644 index 0000000..e227e02 --- /dev/null +++ b/src/org/jetbrains/java/decompiler/util/SortUtil.java @@ -0,0 +1,65 @@ +package org.jetbrains.java.decompiler.util; + +import java.util.ArrayList; +import java.util.Collections; +import java.util.Comparator; +import java.util.Iterator; +import java.util.List; + +public class SortUtil +{ + public static interface Indexed + { + public int getSortIndex(); + } + + @SuppressWarnings({ "unchecked", "rawtypes" }) + public static Iterator sortIndexed(Iterator itr) + { + List list = new ArrayList(); + List def_dec = new ArrayList(); + int first = -1; + + while(itr.hasNext()) + { + Object i = itr.next(); + //Split off any default variable declarations and sort them. + if (i instanceof Indexed && ((Indexed)i).getSortIndex() >= 0) + { + if (first == -1) first = list.size(); + def_dec.add((Indexed)i); + } + else + { + list.add(i); + } + } + + if (def_dec.size() > 0) + { + Collections.sort(def_dec, new Comparator() + { + @Override + public int compare(Indexed o1, Indexed o2) + { + return o1.getSortIndex() - o2.getSortIndex(); + } + }); + list.addAll(first, def_dec); + } + + return list.iterator(); + } + + @SuppressWarnings({ "unchecked", "rawtypes" }) + public static Iterator sortComparable(Iterator itr) + { + List list = new ArrayList(); + + while (itr.hasNext()) + list.add(itr.next()); + + Collections.sort(list); + return list.iterator(); + } +} diff --git a/src/org/jetbrains/java/decompiler/util/VarHelper.java b/src/org/jetbrains/java/decompiler/util/VarHelper.java new file mode 100644 index 0000000..5001cb0 --- /dev/null +++ b/src/org/jetbrains/java/decompiler/util/VarHelper.java @@ -0,0 +1,92 @@ +package org.jetbrains.java.decompiler.util; + +import java.util.HashMap; +import java.util.HashSet; +import java.util.Map; +import java.util.Set; + +public class VarHelper { + + private static final Map switches = new HashMap(); + + static { + switches.put("byte", new String[]{ + "b" + }); + switches.put("char", new String[]{ + "c" + }); + switches.put("short", new String[]{ + "short" + }); + switches.put("int", new String[]{ + "i", "j", "k", "l" + }); + switches.put("long", new String[]{ + "i", "j", "k", "l" + }); + switches.put("boolean", new String[]{ + "flag" + }); + switches.put("double", new String[]{ + "d" + }); + switches.put("float", new String[]{ + "f", "f" // Add twice because the original script is inconsistent + }); + switches.put("String", new String[]{ + "s", "s" // Add twice because the original script is inconsistent + }); + switches.put("Class", new String[]{ + "oclass" + }); + switches.put("Long", new String[]{ + "olong" + }); + switches.put("Byte", new String[]{ + "obyte" + }); + switches.put("Short", new String[]{ + "oshort" + }); + switches.put("Boolean", new String[]{ + "obool" + }); + switches.put("Long", new String[]{ + "olong" + }); + switches.put("Enum", new String[]{ + "oenum" + }); + } + private final Set used = new HashSet(); + + public String help(String name, String type, boolean varArgs) { + if (type == null || !name.startsWith("var")) { + return name; + } + + if (type.endsWith("]")) { + type = "a" + type.substring(0, type.indexOf('[')); + } else if (varArgs) { + type = "a" + type; + } + + String[] remap = switches.get(type); + if (remap == null) { + remap = new String[]{ + type.toLowerCase() + }; + } + + for (int counter = 0;; counter++) { + for (String subMap : remap) { + String attempt = subMap + ((counter == 0 && !subMap.equals("short") && (remap.length > 1 || subMap.length() > 1)) ? "" : counter); + if (!used.contains(attempt)) { + used.add(attempt); + return attempt; + } + } + } + } +} -- cgit v1.2.3