more careful replacement of '$' chars in class names

This commit is contained in:
Eugene Zhuravlev
2010-05-27 10:18:36 +04:00
parent 95c8a57778
commit 70b251deb0
@@ -49,9 +49,12 @@ import java.text.StringCharacterIterator;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.regex.Pattern;
@SuppressWarnings({"HardCodedStringLiteral"})
public class ClsStubBuilder {
private static final Pattern REGEX_PATTERN = Pattern.compile("(?<=[^\\$])\\${1}(?=[^\\$])");
private ClsStubBuilder() {
}
@@ -677,6 +680,12 @@ public class ClsStubBuilder {
private static String getTypeText(final Type type) {
final String raw = type.getClassName();
return raw.replace('$', '.');
// As the '$' char is a valid java identifier and is actively used by bytecode genarators, the problem is
// which occurrences of this char should be replaced and which should not.
// Heuristic: replace only those $ occurrences that are surrounded non-"$" chars
// (most likely generated by javac to separate inner or anonymoys class name)
// Leading and trailing $ chars should be left unchanged.
return raw.contains("$")? REGEX_PATTERN.matcher(raw).replaceAll("\\.") : raw;
}
}