diff options
| author | 2019-12-02 15:43:23 +0200 | |
|---|---|---|
| committer | 2019-12-02 13:43:23 +0000 | |
| commit | a9e03fa0e75b5b338021de982acbbb8277e08706 (patch) | |
| tree | 94233d173c5937584a3376895bf864fb24697a8c /src/main/java/cuchaz/enigma/SourceProvider.java | |
| parent | Correctly decompile bridges, and add command to add bridges to mappings (#180) (diff) | |
| download | enigma-fork-a9e03fa0e75b5b338021de982acbbb8277e08706.tar.gz enigma-fork-a9e03fa0e75b5b338021de982acbbb8277e08706.tar.xz enigma-fork-a9e03fa0e75b5b338021de982acbbb8277e08706.zip | |
Allow attaching class, method, field, and parameter javadocs (#185)
* bring liach pr to modern enigma
* bump version
* fuck off vscode
* switch to COMMENT and write comments before
* it was already after, what do you want
* oops
* put inner classes at the end
* remove indents and use all caps
* add refreshmappings command
* Update src/main/java/cuchaz/enigma/translation/mapping/serde/EnigmaMappingsWriter.java
* Delete RefreshEnigmaMappingsCommand.java
* Update CommandMain.java
* ok
Diffstat (limited to 'src/main/java/cuchaz/enigma/SourceProvider.java')
| -rw-r--r-- | src/main/java/cuchaz/enigma/SourceProvider.java | 17 |
1 files changed, 16 insertions, 1 deletions
diff --git a/src/main/java/cuchaz/enigma/SourceProvider.java b/src/main/java/cuchaz/enigma/SourceProvider.java index 704424a..d3d3003 100644 --- a/src/main/java/cuchaz/enigma/SourceProvider.java +++ b/src/main/java/cuchaz/enigma/SourceProvider.java | |||
| @@ -19,8 +19,10 @@ import oml.ast.transformers.*; | |||
| 19 | 19 | ||
| 20 | import java.io.StringWriter; | 20 | import java.io.StringWriter; |
| 21 | import java.io.Writer; | 21 | import java.io.Writer; |
| 22 | import java.lang.ref.WeakReference; | ||
| 22 | import java.util.Arrays; | 23 | import java.util.Arrays; |
| 23 | import java.util.List; | 24 | import java.util.List; |
| 25 | import java.util.Objects; | ||
| 24 | 26 | ||
| 25 | public class SourceProvider { | 27 | public class SourceProvider { |
| 26 | private final DecompilerSettings settings; | 28 | private final DecompilerSettings settings; |
| @@ -28,6 +30,9 @@ public class SourceProvider { | |||
| 28 | private final ITypeLoader typeLoader; | 30 | private final ITypeLoader typeLoader; |
| 29 | private final MetadataSystem metadataSystem; | 31 | private final MetadataSystem metadataSystem; |
| 30 | 32 | ||
| 33 | private String lastLookUpName; | ||
| 34 | private WeakReference<CompilationUnit> lastDecompiled; | ||
| 35 | |||
| 31 | public SourceProvider(DecompilerSettings settings, ITypeLoader typeLoader, MetadataSystem metadataSystem) { | 36 | public SourceProvider(DecompilerSettings settings, ITypeLoader typeLoader, MetadataSystem metadataSystem) { |
| 32 | this.settings = settings; | 37 | this.settings = settings; |
| 33 | this.typeLoader = typeLoader; | 38 | this.typeLoader = typeLoader; |
| @@ -55,6 +60,13 @@ public class SourceProvider { | |||
| 55 | } | 60 | } |
| 56 | 61 | ||
| 57 | public CompilationUnit getSources(String name) { | 62 | public CompilationUnit getSources(String name) { |
| 63 | // Optimization for javadoc-caused decompilations | ||
| 64 | if (Objects.equals(lastLookUpName, name)) { | ||
| 65 | CompilationUnit last = lastDecompiled.get(); | ||
| 66 | if (last != null) | ||
| 67 | return last; | ||
| 68 | } | ||
| 69 | |||
| 58 | TypeReference type = metadataSystem.lookupType(name); | 70 | TypeReference type = metadataSystem.lookupType(name); |
| 59 | if (type == null) { | 71 | if (type == null) { |
| 60 | throw new Error(String.format("Unable to find desc: %s", name)); | 72 | throw new Error(String.format("Unable to find desc: %s", name)); |
| @@ -74,7 +86,10 @@ public class SourceProvider { | |||
| 74 | builder.runTransformations(null); | 86 | builder.runTransformations(null); |
| 75 | runCustomTransforms(builder, context); | 87 | runCustomTransforms(builder, context); |
| 76 | 88 | ||
| 77 | return builder.getCompilationUnit(); | 89 | CompilationUnit ret = builder.getCompilationUnit(); |
| 90 | lastLookUpName = name; | ||
| 91 | lastDecompiled = new WeakReference<>(ret); | ||
| 92 | return ret; | ||
| 78 | } | 93 | } |
| 79 | 94 | ||
| 80 | public void writeSource(Writer writer, CompilationUnit sourceTree) { | 95 | public void writeSource(Writer writer, CompilationUnit sourceTree) { |