diff options
author | md_5 <git@md-5.net> | 2018-12-06 10:00:00 +1100 |
---|---|---|
committer | md_5 <git@md-5.net> | 2018-12-06 10:00:00 +1100 |
commit | 88d3d7481fb0d3f908ef19a220453ffbceeffc62 (patch) | |
tree | 9a2ce100f987925e853ab65c2fb8b57eb581def6 /src/org/jetbrains/java/decompiler/util | |
parent | e0f22e66296eeaf1e2a9af73af0c7f9ba28521b1 (diff) | |
download | fernflower-code-cleanup.tar fernflower-code-cleanup.tar.gz fernflower-code-cleanup.tar.lz fernflower-code-cleanup.tar.xz fernflower-code-cleanup.zip |
Clean up old decompiler changes + add new sugaringcode-cleanup
Contains code from:
Alexandru-Constantin Bledea - Boxing
Dmitry Cherniachenko - Vararg parameters, Boxing
Egor Ushakov - Lambda, String Quoting
Lex Manos - Switch decompilation
Thinkofdeath - Formatting
Diffstat (limited to 'src/org/jetbrains/java/decompiler/util')
-rw-r--r-- | src/org/jetbrains/java/decompiler/util/Util.java | 12 | ||||
-rw-r--r-- | src/org/jetbrains/java/decompiler/util/VarHelper.java | 104 |
2 files changed, 116 insertions, 0 deletions
diff --git a/src/org/jetbrains/java/decompiler/util/Util.java b/src/org/jetbrains/java/decompiler/util/Util.java new file mode 100644 index 0000000..5ade232 --- /dev/null +++ b/src/org/jetbrains/java/decompiler/util/Util.java @@ -0,0 +1,12 @@ +package org.jetbrains.java.decompiler.util; + +import java.util.regex.Pattern; + +public class Util { + + private final static Pattern RTRIM = Pattern.compile("\\s+$"); + + public static String rtrim(String s) { + return RTRIM.matcher(s).replaceAll(""); + } +} 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..34b52a9 --- /dev/null +++ b/src/org/jetbrains/java/decompiler/util/VarHelper.java @@ -0,0 +1,104 @@ +package org.jetbrains.java.decompiler.util; + +import java.util.HashMap; +import java.util.HashSet; +import java.util.Locale; +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("Double", new String[]{ + "odouble" + }); + switches.put("Float", new String[]{ + "ofloat" + }); + 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; + } + + while (type.contains( "<" )) { + type = type.substring(0, type.indexOf('<')) + type.substring(type.lastIndexOf('>') + 1); + } + type = type.replace( '.', '_' ); + + 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(Locale.ENGLISH) + }; + } + + 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; + } + } + } + } +} |