MCPcopy Create free account
hub / github.com/FabricMC/Matcher / Cfr

Class Cfr

src/main/java/matcher/srcprocess/Cfr.java:21–123  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

19import matcher.type.ClassInstance;
20
21public class Cfr implements Decompiler {
22 @Override
23 public synchronized String decompile(ClassInstance cls, ClassFeatureExtractor env, NameType nameType) {
24 Map<String, String> options = new HashMap<>();
25
26 Sink sink = new Sink();
27
28 CfrDriver driver = new CfrDriver.Builder()
29 .withOptions(options)
30 .withClassFileSource(new Source(env, nameType))
31 .withOutputSink(sink)
32 .build();
33
34 driver.analyse(Collections.singletonList(cls.getName(nameType).concat(fileSuffix)));
35
36 return sink.toString();
37 }
38
39 private static class Source implements ClassFileSource {
40 Source(ClassFeatureExtractor env, NameType nameType) {
41 this.env = env;
42 this.nameType = nameType;
43 }
44
45 @Override
46 public void informAnalysisRelativePathDetail(String usePath, String classFilePath) {
47 //Matcher.LOGGER.debug("informAnalysisRelativePathDetail {} {}", usePath, classFilePath);
48 }
49
50 @Override
51 public Collection<String> addJar(String jarPath) {
52 Matcher.LOGGER.debug("addJar {}", jarPath);
53
54 throw new UnsupportedOperationException();
55 }
56
57 @Override
58 public String getPossiblyRenamedPath(String path) {
59 return path;
60 }
61
62 @Override
63 public Pair<byte[], String> getClassFileContent(String path) throws IOException {
64 if (!path.endsWith(fileSuffix)) {
65 Matcher.LOGGER.debug("getClassFileContent invalid path: {}", path);
66 throw new NoSuchFileException(path);
67 }
68
69 String clsName = path.substring(0, path.length() - fileSuffix.length());
70 ClassInstance cls = env.getClsByName(clsName, nameType);
71
72 if (cls == null) {
73 Matcher.LOGGER.debug("getClassFileContent missing cls: {}", clsName);
74 throw new NoSuchFileException(path);
75 }
76
77 if (cls.getAsmNodes() == null) {
78 Matcher.LOGGER.debug("getClassFileContent unknown cls: {}", clsName);

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected