diff options
5 files changed, 50 insertions, 30 deletions
diff --git a/src/main/java/cuchaz/enigma/TranslatingTypeLoader.java b/src/main/java/cuchaz/enigma/TranslatingTypeLoader.java index 6ddfa634..d9dc67b2 100644 --- a/src/main/java/cuchaz/enigma/TranslatingTypeLoader.java +++ b/src/main/java/cuchaz/enigma/TranslatingTypeLoader.java | |||
| @@ -51,7 +51,8 @@ public class TranslatingTypeLoader implements ITypeLoader { | |||
| 51 | this.cache = Maps.newHashMap(); | 51 | this.cache = Maps.newHashMap(); |
| 52 | this.defaultTypeLoader = new ClasspathTypeLoader(); | 52 | this.defaultTypeLoader = new ClasspathTypeLoader(); |
| 53 | this.docMapping = docMapping; | 53 | this.docMapping = docMapping; |
| 54 | this.docMapping.cleanBehaviors(); | 54 | if (docMapping != null) |
| 55 | this.docMapping.cleanBehaviors(); | ||
| 55 | } | 56 | } |
| 56 | 57 | ||
| 57 | public void clearCache() { | 58 | public void clearCache() { |
diff --git a/src/main/java/cuchaz/enigma/gui/MemberMatchingGui.java b/src/main/java/cuchaz/enigma/gui/MemberMatchingGui.java index 50550910..91067b50 100644 --- a/src/main/java/cuchaz/enigma/gui/MemberMatchingGui.java +++ b/src/main/java/cuchaz/enigma/gui/MemberMatchingGui.java | |||
| @@ -382,13 +382,11 @@ public class MemberMatchingGui<T extends Entry> { | |||
| 382 | } | 382 | } |
| 383 | 383 | ||
| 384 | private void setDest(T obfEntry) { | 384 | private void setDest(T obfEntry) { |
| 385 | if (obfEntry == null) { | 385 | m_obfDestEntry = obfEntry; |
| 386 | m_obfDestEntry = null; | 386 | if (obfEntry == null) |
| 387 | m_destLabel.setText(""); | 387 | m_destLabel.setText(""); |
| 388 | } else { | 388 | else |
| 389 | m_obfDestEntry = obfEntry; | ||
| 390 | m_destLabel.setText(getEntryLabel(obfEntry, m_destDeobfuscator)); | 389 | m_destLabel.setText(getEntryLabel(obfEntry, m_destDeobfuscator)); |
| 391 | } | ||
| 392 | } | 390 | } |
| 393 | 391 | ||
| 394 | private String getEntryLabel(T obfEntry, Deobfuscator deobfuscator) { | 392 | private String getEntryLabel(T obfEntry, Deobfuscator deobfuscator) { |
diff --git a/src/main/java/cuchaz/enigma/mapping/NameValidator.java b/src/main/java/cuchaz/enigma/mapping/NameValidator.java index 6925b72a..15b0314c 100644 --- a/src/main/java/cuchaz/enigma/mapping/NameValidator.java +++ b/src/main/java/cuchaz/enigma/mapping/NameValidator.java | |||
| @@ -30,6 +30,8 @@ public class NameValidator { | |||
| 30 | ); | 30 | ); |
| 31 | 31 | ||
| 32 | static { | 32 | static { |
| 33 | |||
| 34 | // java allows all kinds of weird characters... | ||
| 33 | String identifierRegex = "[A-Za-z_<][A-Za-z0-9_>]*"; | 35 | String identifierRegex = "[A-Za-z_<][A-Za-z0-9_>]*"; |
| 34 | IdentifierPattern = Pattern.compile(identifierRegex); | 36 | IdentifierPattern = Pattern.compile(identifierRegex); |
| 35 | ClassPattern = Pattern.compile(String.format("^(%s(\\.|/))*(%s)$", identifierRegex, identifierRegex)); | 37 | ClassPattern = Pattern.compile(String.format("^(%s(\\.|/))*(%s)$", identifierRegex, identifierRegex)); |
diff --git a/src/main/java/cuchaz/enigma/mapping/javadoc/JavaDocMapping.java b/src/main/java/cuchaz/enigma/mapping/javadoc/JavaDocMapping.java index 98996fdb..8b68a12d 100644 --- a/src/main/java/cuchaz/enigma/mapping/javadoc/JavaDocMapping.java +++ b/src/main/java/cuchaz/enigma/mapping/javadoc/JavaDocMapping.java | |||
| @@ -35,7 +35,7 @@ public class JavaDocMapping | |||
| 35 | 35 | ||
| 36 | // TODO: File format | 36 | // TODO: File format |
| 37 | addField("a", "none/akw", "Lnone/kp;", "Hello from Enigma"); | 37 | addField("a", "none/akw", "Lnone/kp;", "Hello from Enigma"); |
| 38 | addMethod("<init>", "none/akw", "(Lnone/ayo;)V", "You know what? I love constructors!", "The material of the block!"); | 38 | addMethod("<init>", "none/akw", "(Lnone/ayo;)V", "You know what? I love constructors!", null, new String[]{ "The material of the block!" }); |
| 39 | addClass("none/akw", "HEY I'M A BLOCK YOU KNOW THAT?!"); | 39 | addClass("none/akw", "HEY I'M A BLOCK YOU KNOW THAT?!"); |
| 40 | } | 40 | } |
| 41 | 41 | ||
| @@ -49,7 +49,7 @@ public class JavaDocMapping | |||
| 49 | this.javaDocFieldByID.put(new FieldEntry(new ClassEntry(className), fieldName, new Type(type)), new JavaDocField(new JavaDocClass(className, "LOL"), fieldName, type, comment)); | 49 | this.javaDocFieldByID.put(new FieldEntry(new ClassEntry(className), fieldName, new Type(type)), new JavaDocField(new JavaDocClass(className, "LOL"), fieldName, type, comment)); |
| 50 | } | 50 | } |
| 51 | 51 | ||
| 52 | public void addMethod(String methodName, String className, String signature, String comment, String... argComment) | 52 | public void addMethod(String methodName, String className, String signature, String comment, String returnComment, String[] argComment) |
| 53 | { | 53 | { |
| 54 | BehaviorEntry behaviorEntry; | 54 | BehaviorEntry behaviorEntry; |
| 55 | if (methodName.equals("<init>")) | 55 | if (methodName.equals("<init>")) |
| @@ -58,7 +58,7 @@ public class JavaDocMapping | |||
| 58 | behaviorEntry = new MethodEntry(new ClassEntry(className), methodName, new Signature(signature)); | 58 | behaviorEntry = new MethodEntry(new ClassEntry(className), methodName, new Signature(signature)); |
| 59 | 59 | ||
| 60 | this.javaDocMethodByID.put(behaviorEntry, new JavaDocMethod(new JavaDocClass(className, "LOL"), methodName, signature, comment, | 60 | this.javaDocMethodByID.put(behaviorEntry, new JavaDocMethod(new JavaDocClass(className, "LOL"), methodName, signature, comment, |
| 61 | Arrays.asList(argComment))); | 61 | returnComment, argComment)); |
| 62 | } | 62 | } |
| 63 | 63 | ||
| 64 | public void cleanBehaviors() | 64 | public void cleanBehaviors() |
| @@ -121,10 +121,17 @@ public class JavaDocMapping | |||
| 121 | // Prepare the annotation | 121 | // Prepare the annotation |
| 122 | AnnotationsAttribute attr = new AnnotationsAttribute(constpool, AnnotationsAttribute.visibleTag); | 122 | AnnotationsAttribute attr = new AnnotationsAttribute(constpool, AnnotationsAttribute.visibleTag); |
| 123 | Annotation annot = new Annotation("enigma.remapper.MethodDoc", constpool); | 123 | Annotation annot = new Annotation("enigma.remapper.MethodDoc", constpool); |
| 124 | annot.addMemberValue("comment", new StringMemberValue(javaDocMethod.getComment(), constpool)); | 124 | String comment = javaDocMethod.getComment(); |
| 125 | if (comment != null) | ||
| 126 | annot.addMemberValue("comment", new StringMemberValue(comment, constpool)); | ||
| 127 | |||
| 125 | behaviorByID.add(entry); | 128 | behaviorByID.add(entry); |
| 126 | annot.addMemberValue("behavior", new IntegerMemberValue(constpool, behaviorByID.size() - 1)); | 129 | annot.addMemberValue("behavior", new IntegerMemberValue(constpool, behaviorByID.size() - 1)); |
| 127 | annot.addMemberValue("args", translateStringArray(constpool, javaDocMethod.getArgsComments())); | 130 | annot.addMemberValue("args", translateStringArray(constpool, javaDocMethod.getArgsComments())); |
| 131 | |||
| 132 | String returnComment = javaDocMethod.getReturnComment(); | ||
| 133 | if (returnComment != null) | ||
| 134 | annot.addMemberValue("return", new StringMemberValue(returnComment, constpool)); | ||
| 128 | attr.addAnnotation(annot); | 135 | attr.addAnnotation(annot); |
| 129 | ctBehavior.getMethodInfo().addAttribute(attr); | 136 | ctBehavior.getMethodInfo().addAttribute(attr); |
| 130 | } | 137 | } |
| @@ -154,7 +161,7 @@ public class JavaDocMapping | |||
| 154 | { | 161 | { |
| 155 | MemberValue[] result = new MemberValue[args.length]; | 162 | MemberValue[] result = new MemberValue[args.length]; |
| 156 | for (int i = 0; i < result.length; i++) | 163 | for (int i = 0; i < result.length; i++) |
| 157 | result[i] = new StringMemberValue(args[i], pool); | 164 | result[i] = new StringMemberValue(args[i] == null ? "null" : args[i], pool); |
| 158 | 165 | ||
| 159 | return result; | 166 | return result; |
| 160 | } | 167 | } |
| @@ -202,15 +209,18 @@ public class JavaDocMapping | |||
| 202 | if (child instanceof PrimitiveExpression) | 209 | if (child instanceof PrimitiveExpression) |
| 203 | { | 210 | { |
| 204 | PrimitiveExpression data = (PrimitiveExpression) child; | 211 | PrimitiveExpression data = (PrimitiveExpression) child; |
| 205 | if (id.equals("comment")) | 212 | switch (id) |
| 206 | { | 213 | { |
| 207 | builder.append(spaces); | 214 | case "comment": |
| 208 | builder.append(" * "); | 215 | addCommentLine(builder, (String) data.getValue(), spaces); |
| 209 | builder.append(data.getValue()); | 216 | break; |
| 210 | builder.append("\n"); | 217 | case "behavior": |
| 218 | behaviorID = (Integer) data.getValue(); | ||
| 219 | break; | ||
| 220 | case "return": | ||
| 221 | addCommentLine(builder, "@return " + data.getValue(), spaces); | ||
| 222 | break; | ||
| 211 | } | 223 | } |
| 212 | else if (id.equals("behavior")) | ||
| 213 | behaviorID = (Integer) data.getValue(); | ||
| 214 | } | 224 | } |
| 215 | else if (child instanceof ArrayInitializerExpression) | 225 | else if (child instanceof ArrayInitializerExpression) |
| 216 | { | 226 | { |
| @@ -226,16 +236,14 @@ public class JavaDocMapping | |||
| 226 | { | 236 | { |
| 227 | if (expArg instanceof PrimitiveExpression) | 237 | if (expArg instanceof PrimitiveExpression) |
| 228 | { | 238 | { |
| 229 | PrimitiveExpression primitiveExpression = (PrimitiveExpression) expArg; | 239 | PrimitiveExpression argComment = (PrimitiveExpression) expArg; |
| 240 | String commentStr = (String) argComment.getValue(); | ||
| 241 | if (commentStr.equals("null")) | ||
| 242 | continue; | ||
| 230 | String argName = entry == null ? null : this.translator.translate(new ArgumentEntry(entry, i, "")); | 243 | String argName = entry == null ? null : this.translator.translate(new ArgumentEntry(entry, i, "")); |
| 231 | if (argName == null) | 244 | if (argName == null) |
| 232 | argName = "a" + (i + 1); | 245 | argName = "a" + (i + 1); |
| 233 | builder.append(spaces); | 246 | addCommentLine(builder, "@param " + argName + " " + argComment.getValue(), spaces); |
| 234 | builder.append(" * @param "); | ||
| 235 | builder.append(argName); | ||
| 236 | builder.append(" "); | ||
| 237 | builder.append(primitiveExpression.getValue()); | ||
| 238 | builder.append("\n"); | ||
| 239 | } | 247 | } |
| 240 | i++; | 248 | i++; |
| 241 | } | 249 | } |
| @@ -248,6 +256,14 @@ public class JavaDocMapping | |||
| 248 | return builder.toString(); | 256 | return builder.toString(); |
| 249 | } | 257 | } |
| 250 | 258 | ||
| 259 | public void addCommentLine(StringBuilder builder, String value, String spaces) | ||
| 260 | { | ||
| 261 | builder.append(spaces); | ||
| 262 | builder.append(" * "); | ||
| 263 | builder.append(value); | ||
| 264 | builder.append("\n"); | ||
| 265 | } | ||
| 266 | |||
| 251 | private String buildLineSpace(int spacesCount) | 267 | private String buildLineSpace(int spacesCount) |
| 252 | { | 268 | { |
| 253 | StringBuilder builder = new StringBuilder(); | 269 | StringBuilder builder = new StringBuilder(); |
diff --git a/src/main/java/cuchaz/enigma/mapping/javadoc/JavaDocMethod.java b/src/main/java/cuchaz/enigma/mapping/javadoc/JavaDocMethod.java index 1508aede..6ed7ff8c 100644 --- a/src/main/java/cuchaz/enigma/mapping/javadoc/JavaDocMethod.java +++ b/src/main/java/cuchaz/enigma/mapping/javadoc/JavaDocMethod.java | |||
| @@ -17,13 +17,16 @@ public class JavaDocMethod extends BaseJavaDocEntry | |||
| 17 | { | 17 | { |
| 18 | private final JavaDocClass classDocEntry; | 18 | private final JavaDocClass classDocEntry; |
| 19 | private final String name; | 19 | private final String name; |
| 20 | private final List<String> argsComments; | 20 | private final String returnComment; |
| 21 | private final String[] argsComments; | ||
| 21 | 22 | ||
| 22 | public JavaDocMethod(JavaDocClass classDocEntry, String name, String identifier, String comment, List<String> argsComments) | 23 | public JavaDocMethod(JavaDocClass classDocEntry, String name, String identifier, String comment, |
| 24 | String returnComment, String[] argsComments) | ||
| 23 | { | 25 | { |
| 24 | super(identifier, comment); | 26 | super(identifier, comment); |
| 25 | this.name = name; | 27 | this.name = name; |
| 26 | this.classDocEntry = classDocEntry; | 28 | this.classDocEntry = classDocEntry; |
| 29 | this.returnComment = returnComment; | ||
| 27 | this.argsComments = argsComments; | 30 | this.argsComments = argsComments; |
| 28 | } | 31 | } |
| 29 | 32 | ||
| @@ -39,11 +42,11 @@ public class JavaDocMethod extends BaseJavaDocEntry | |||
| 39 | 42 | ||
| 40 | public String[] getArgsComments() | 43 | public String[] getArgsComments() |
| 41 | { | 44 | { |
| 42 | return argsComments.toArray(new String[argsComments.size()]); | 45 | return argsComments; |
| 43 | } | 46 | } |
| 44 | 47 | ||
| 45 | public String getArgsComment(int id) | 48 | public String getReturnComment() |
| 46 | { | 49 | { |
| 47 | return argsComments.size() > id ? argsComments.get(id) : null; | 50 | return returnComment; |
| 48 | } | 51 | } |
| 49 | } | 52 | } |