decompiler: check method names for invalid symbols (mostly for groovy)

master
Egor.Ushakov 10 years ago
parent 531a1d5477
commit 5702e5dfdd
  1. 22
      src/org/jetbrains/java/decompiler/main/ClassWriter.java

@ -566,6 +566,26 @@ public class ClassWriter {
} }
} }
public static String toValidJavaIdentifier(String name) {
if (name == null || name.isEmpty()) return name;
boolean changed = false;
StringBuilder res = new StringBuilder(name.length());
for (int i = 0; i < name.length(); i++) {
char c = name.charAt(i);
if ((i == 0 && !Character.isJavaIdentifierStart(c))
|| (i > 0 && !Character.isJavaIdentifierPart(c))) {
changed = true;
res.append("_");
}
else res.append(c);
}
if (!changed) {
return name;
}
return res.append("/* $FF was: ").append(name).append("*/").toString();
}
private boolean methodToJava(ClassNode node, StructMethod mt, TextBuffer buffer, int indent, BytecodeMappingTracer tracer) { private boolean methodToJava(ClassNode node, StructMethod mt, TextBuffer buffer, int indent, BytecodeMappingTracer tracer) {
ClassWrapper wrapper = node.getWrapper(); ClassWrapper wrapper = node.getWrapper();
StructClass cl = wrapper.getClassStruct(); StructClass cl = wrapper.getClassStruct();
@ -686,7 +706,7 @@ public class ClassWriter {
buffer.append(' '); buffer.append(' ');
} }
buffer.append(name); buffer.append(toValidJavaIdentifier(name));
buffer.append('('); buffer.append('(');
// parameters // parameters

Loading…
Cancel
Save