Skip to content
This repository has been archived by the owner on Sep 12, 2019. It is now read-only.

Attempt at merging changes from upstream #3

Open
wants to merge 2 commits into
base: LVTProcessing
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions java-decompiler-engine.iml
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,6 @@
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
<orderEntry type="library" scope="TEST" name="JUnit4" level="project" />
<orderEntry type="library" scope="TEST" name="hamcrest" level="project" />
</component>
</module>
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,8 @@ public String getShortName(String fullname, boolean imported) {

if (existsDefaultClass ||
(mapSimpleNames.containsKey(nshort) && !npackage.equals(mapSimpleNames.get(nshort)))) {
return fullname;
// don't return full name because if the class is a inner class, full name refers to the parent full name, not the child full name
return retname == null ? fullname : (npackage + "." + retname);
}
else if (!mapSimpleNames.containsKey(nshort)) {
mapSimpleNames.put(nshort, npackage);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,44 +37,73 @@
*/

public class StructInnerClassesAttribute extends StructGeneralAttribute {
private List<InnerClassInfo> entries;
private List<InnerClassInfo> entries;
private List<int[]> classEntries;
private List<String[]> stringEntries;

@Override
public void initContent(ConstantPool pool) throws IOException {
DataInputStream data = stream();
@Override
public void initContent(ConstantPool pool) throws IOException {
DataInputStream data = stream();

int len = data.readUnsignedShort();
if (len > 0) {
entries = new ArrayList<InnerClassInfo>();
int len = data.readUnsignedShort();
if (len > 0) {
entries = new ArrayList<InnerClassInfo>();
classEntries = new ArrayList<int[]>(len);
stringEntries = new ArrayList<String[]>(len);

for (int i = 0; i < len; i++) {
entries.add(new InnerClassInfo(data, pool));
}
}
else {
entries = Collections.emptyList();
}
}
for (int i = 0; i < len; i++) {
entries.add(new InnerClassInfo(data, pool));
int[] classEntry = new int[4];
for (int j = 0; j < 4; j++) {
classEntry[j] = data.readUnsignedShort();
}
classEntries.add(classEntry);

public List<InnerClassInfo> getEntries() {
return entries;
}
// inner name, enclosing class, original simple name
String[] stringEntry = new String[3];
stringEntry[0] = pool.getPrimitiveConstant(classEntry[0]).getString();
if (classEntry[1] != 0) {
stringEntry[1] = pool.getPrimitiveConstant(classEntry[1]).getString();
}
if (classEntry[2] != 0) {
stringEntry[2] = pool.getPrimitiveConstant(classEntry[2]).getString();
}
stringEntries.add(stringEntry);
}
} else {
entries = Collections.emptyList();
classEntries = Collections.emptyList();
stringEntries = Collections.emptyList();
}
}

public static class InnerClassInfo {
public String inner_class;
public String outer_class;
public String inner_name;
public int access;
public List<InnerClassInfo> getEntries() {
return entries;
}

private InnerClassInfo(DataInputStream data, ConstantPool pool) throws IOException {
this.inner_class = readString(pool, data.readUnsignedShort());
this.outer_class = readString(pool, data.readUnsignedShort());
this.inner_name = readString(pool, data.readUnsignedShort());
this.access = data.readUnsignedShort();
}
public List<int[]> getClassEntries() {
return classEntries;
}

private String readString(ConstantPool pool, int index) {
return index == 0 ? null : pool.getPrimitiveConstant(index).getString();
}
}
public List<String[]> getStringEntries() {
return stringEntries;
}

public static class InnerClassInfo {
public String inner_class;
public String outer_class;
public String inner_name;
public int access;

private InnerClassInfo(DataInputStream data, ConstantPool pool) throws IOException {
this.inner_class = readString(pool, data.readUnsignedShort());
this.outer_class = readString(pool, data.readUnsignedShort());
this.inner_name = readString(pool, data.readUnsignedShort());
this.access = data.readUnsignedShort();
}

private String readString(ConstantPool pool, int index) {
return index == 0 ? null : pool.getPrimitiveConstant(index).getString();
}
}
}
21 changes: 4 additions & 17 deletions test/org/jetbrains/java/decompiler/BulkDecompilationTest.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2000-2014 JetBrains s.r.o.
* Copyright 2000-2015 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -15,7 +15,6 @@
*/
package org.jetbrains.java.decompiler;

import org.hamcrest.Matchers;
import org.jetbrains.java.decompiler.main.decompiler.ConsoleDecompiler;
import org.jetbrains.java.decompiler.util.InterpreterUtil;
import org.junit.After;
Expand All @@ -27,7 +26,7 @@
import java.util.zip.ZipEntry;
import java.util.zip.ZipFile;

import static org.junit.Assert.assertThat;
import static org.jetbrains.java.decompiler.DecompilerTestFixture.assertFilesEqual;
import static org.junit.Assert.assertTrue;

public class BulkDecompilationTest {
Expand All @@ -54,7 +53,7 @@ public void testDirectory() {
decompiler.addSpace(classes, true);
decompiler.decompileContext();

compareDirectories(new File(fixture.getTestDataDir(), "bulk"), fixture.getTargetDir());
assertFilesEqual(new File(fixture.getTestDataDir(), "bulk"), fixture.getTargetDir());
}

@Test
Expand All @@ -66,7 +65,7 @@ public void testJar() {
File unpacked = new File(fixture.getTempDir(), "unpacked");
unpack(new File(fixture.getTargetDir(), "bulk.jar"), unpacked);

compareDirectories(new File(fixture.getTestDataDir(), "bulk"), unpacked);
assertFilesEqual(new File(fixture.getTestDataDir(), "bulk"), unpacked);
}

private static void unpack(File archive, File targetDir) {
Expand Down Expand Up @@ -95,16 +94,4 @@ private static void unpack(File archive, File targetDir) {
throw new RuntimeException(e);
}
}

private static void compareDirectories(File expected, File actual) {
String[] expectedList = expected.list();
String[] actualList = actual.list();
assertThat(actualList, Matchers.arrayContainingInAnyOrder(expectedList));
for (String name : expectedList) {
File child = new File(expected, name);
if (child.isDirectory()) {
compareDirectories(child, new File(actual, name));
}
}
}
}
27 changes: 26 additions & 1 deletion test/org/jetbrains/java/decompiler/DecompilerTestFixture.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2000-2014 JetBrains s.r.o.
* Copyright 2000-2015 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -15,15 +15,18 @@
*/
package org.jetbrains.java.decompiler;

import org.hamcrest.Matchers;
import org.jetbrains.java.decompiler.main.decompiler.ConsoleDecompiler;
import org.jetbrains.java.decompiler.main.extern.IFernflowerPreferences;
import org.jetbrains.java.decompiler.util.InterpreterUtil;

import java.io.File;
import java.io.IOException;
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;

import static org.junit.Assert.assertThat;
import static org.junit.Assert.assertTrue;

public class DecompilerTestFixture {
Expand All @@ -44,6 +47,7 @@ public void setUp(final Map<String, Object> options) throws IOException {
if (!isTestDataDir(testDataDir)) testDataDir = new File("../community/plugins/java-decompiler/engine/testData");
if (!isTestDataDir(testDataDir)) testDataDir = new File("../plugins/java-decompiler/engine/testData");
assertTrue("current dir: " + new File("").getAbsolutePath(), isTestDataDir(testDataDir));
testDataDir = testDataDir.getAbsoluteFile();

//noinspection SSBasedInspection
tempDir = File.createTempFile("decompiler_test_", "_dir");
Expand Down Expand Up @@ -97,4 +101,25 @@ private static void delete(File file) {
}
assertTrue(file.delete());
}

public static void assertFilesEqual(File expected, File actual) {
if (expected.isDirectory()) {
assertThat(actual.list(), Matchers.arrayContainingInAnyOrder(expected.list()));
for (String name : expected.list()) {
assertFilesEqual(new File(expected, name), new File(actual, name));
}
}
else {
assertThat(getContent(actual), Matchers.equalTo(getContent(expected)));
}
}

private static String getContent(File expected) {
try {
return new String(InterpreterUtil.getBytes(expected), "UTF-8").replace("\r\n", "\n");
}
catch (IOException e) {
throw new RuntimeException(e);
}
}
}
1 change: 1 addition & 0 deletions test/org/jetbrains/java/decompiler/SingleClassesTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -61,4 +61,5 @@ protected Map<String, Object> getDecompilerOptions() {
@Test public void testInnerLocalPkg() { doTest("pkg/TestInnerLocalPkg"); }
@Test public void testInnerSignature() { doTest("pkg/TestInnerSignature"); }
@Test public void testParameterizedTypes() { doTest("pkg/TestParameterizedTypes"); }
@Test public void testShadowing() { doTest("pkg/TestShadowing", "pkg/Shadow", "ext/Shadow"); }
}
Loading