From 0f12304abe4ec425c6934286ba26d895e449093b Mon Sep 17 00:00:00 2001 From: Mumfrey Date: Wed, 16 Dec 2015 17:52:03 +0000 Subject: [PATCH] Fix AP stripping generics with nested generic signatures --- .../tools/obfuscation/TypeHandle.java | 20 +++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/src/ap/java/org/spongepowered/tools/obfuscation/TypeHandle.java b/src/ap/java/org/spongepowered/tools/obfuscation/TypeHandle.java index 74cfcb0f..5307713a 100644 --- a/src/ap/java/org/spongepowered/tools/obfuscation/TypeHandle.java +++ b/src/ap/java/org/spongepowered/tools/obfuscation/TypeHandle.java @@ -222,7 +222,7 @@ public class TypeHandle { * @return handle to the discovered field if matched or null if no match */ public FieldHandle findField(String name, String type) { - String rawType = type.replaceAll("<[^>]+>", ""); + String rawType = TypeHandle.stripGenerics(type); for (Element element : this.getEnclosedElements()) { if (element.getKind() != ElementKind.FIELD) { @@ -260,7 +260,7 @@ public class TypeHandle { * @return handle to the discovered method if matched or null if no match */ public MethodHandle findMethod(String name, String signature) { - String rawSignature = signature.replaceAll("<[^>]+>", ""); + String rawSignature = TypeHandle.stripGenerics(signature); for (Element element : this.getEnclosedElements()) { switch (element.getKind()) { @@ -312,4 +312,20 @@ public class TypeHandle { return element.asType().toString(); } + static String stripGenerics(String type) { + StringBuilder sb = new StringBuilder(); + for (int pos = 0, depth = 0; pos < type.length(); pos++) { + char c = type.charAt(pos); + if (c == '<') { + depth++; + } + if (depth == 0) { + sb.append(c); + } else if (c == '>') { + depth--; + } + } + return sb.toString(); + } + }