blob: 85c72f810d54ab521966b6cf75a3272aa31aee70 (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
|
/*******************************************************************************
* Copyright (c) 2015 Jeff Martin.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the GNU Lesser General Public
* License v3.0 which accompanies this distribution, and is available at
* http://www.gnu.org/licenses/lgpl.html
*
* Contributors:
* Jeff Martin - initial API and implementation
******************************************************************************/
package cuchaz.enigma;
import cuchaz.enigma.analysis.ClassCache;
import cuchaz.enigma.analysis.index.JarIndex;
import cuchaz.enigma.source.Decompiler;
import cuchaz.enigma.source.Decompilers;
import cuchaz.enigma.source.SourceSettings;
import cuchaz.enigma.translation.representation.entry.ClassEntry;
import org.junit.Test;
import java.nio.file.Paths;
import static cuchaz.enigma.TestEntryFactory.newClass;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.is;
public class TestInnerClasses {
private static final ClassEntry SimpleOuter = newClass("d");
private static final ClassEntry SimpleInner = newClass("d$a");
private static final ClassEntry ConstructorArgsOuter = newClass("c");
private static final ClassEntry ConstructorArgsInner = newClass("c$a");
private static final ClassEntry ClassTreeRoot = newClass("f");
private static final ClassEntry ClassTreeLevel1 = newClass("f$a");
private static final ClassEntry ClassTreeLevel2 = newClass("f$a$a");
private static final ClassEntry ClassTreeLevel3 = newClass("f$a$a$a");
private final JarIndex index;
private final Decompiler decompiler;
public TestInnerClasses() throws Exception {
ClassCache classCache = ClassCache.of(Paths.get("build/test-obf/innerClasses.jar"));
index = classCache.index(ProgressListener.none());
decompiler = Decompilers.PROCYON.create(classCache, new SourceSettings(false, false));
}
@Test
public void simple() {
decompile(SimpleOuter);
}
@Test
public void constructorArgs() {
decompile(ConstructorArgsOuter);
}
@Test
public void classTree() {
// root level
assertThat(index.getEntryIndex().hasClass(ClassTreeRoot), is(true));
// level 1
ClassEntry fullClassEntry = new ClassEntry(ClassTreeRoot.getName()
+ "$" + ClassTreeLevel1.getSimpleName());
assertThat(index.getEntryIndex().hasClass(fullClassEntry), is(true));
// level 2
fullClassEntry = new ClassEntry(ClassTreeRoot.getName()
+ "$" + ClassTreeLevel1.getSimpleName()
+ "$" + ClassTreeLevel2.getSimpleName());
assertThat(index.getEntryIndex().hasClass(fullClassEntry), is(true));
// level 3
fullClassEntry = new ClassEntry(ClassTreeRoot.getName()
+ "$" + ClassTreeLevel1.getSimpleName()
+ "$" + ClassTreeLevel2.getSimpleName()
+ "$" + ClassTreeLevel3.getSimpleName());
assertThat(index.getEntryIndex().hasClass(fullClassEntry), is(true));
}
private void decompile(ClassEntry classEntry) {
decompiler.getSource(classEntry.getName());
}
}
|