summaryrefslogtreecommitdiffstats
path: root/src/org/jetbrains/java/decompiler/util
diff options
context:
space:
mode:
authormd_5 <git@md-5.net>2014-10-24 21:16:23 +1100
committermd_5 <git@md-5.net>2014-10-25 09:30:59 +1100
commitb98e02e557eb7c30d6425ffd9cfa8b7b71b164dc (patch)
tree4c1ac9026ebda849390d4000fe744cea917c4a17 /src/org/jetbrains/java/decompiler/util
parente0f22e66296eeaf1e2a9af73af0c7f9ba28521b1 (diff)
downloadfernflower-b98e02e557eb7c30d6425ffd9cfa8b7b71b164dc.tar
fernflower-b98e02e557eb7c30d6425ffd9cfa8b7b71b164dc.tar.gz
fernflower-b98e02e557eb7c30d6425ffd9cfa8b7b71b164dc.tar.lz
fernflower-b98e02e557eb7c30d6425ffd9cfa8b7b71b164dc.tar.xz
fernflower-b98e02e557eb7c30d6425ffd9cfa8b7b71b164dc.zip
Spigot Changes
Diffstat (limited to 'src/org/jetbrains/java/decompiler/util')
-rw-r--r--src/org/jetbrains/java/decompiler/util/SortUtil.java65
-rw-r--r--src/org/jetbrains/java/decompiler/util/VarHelper.java92
2 files changed, 157 insertions, 0 deletions
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<Indexed> def_dec = new ArrayList<Indexed>();
+ 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<Indexed>()
+ {
+ @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 <T extends Comparable> Iterator<T> sortComparable(Iterator<T> itr)
+ {
+ List<T> list = new ArrayList<T>();
+
+ 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<String, String[]> switches = new HashMap<String, String[]>();
+
+ 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<String> used = new HashSet<String>();
+
+ 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;
+ }
+ }
+ }
+ }
+}