correctly decompile interface object fields

This commit is contained in:
Alexandru-Constantin Bledea
2016-03-07 18:52:37 +02:00
parent d50e8a860e
commit 06c993b508
5 changed files with 27 additions and 4 deletions

View File

@@ -124,7 +124,7 @@ public class InitializerProcessor {
RootStatement root = meth.root;
StructClass cl = wrapper.getClassStruct();
boolean isInterface = cl.hasModifier(CodeConstants.ACC_INTERFACE);
Statement firstdata = findFirstData(root);
if (firstdata != null) {
while (!firstdata.getExprents().isEmpty()) {
@@ -139,7 +139,8 @@ public class InitializerProcessor {
if (fexpr.isStatic() && fexpr.getClassname().equals(cl.qualifiedName) &&
cl.hasField(fexpr.getName(), fexpr.getDescriptor().descriptorString)) {
if (isExprentIndependent(asexpr.getRight(), meth)) {
// interfaces fields should always be initialized inline
if (isInterface || isExprentIndependent(asexpr.getRight(), meth)) {
String keyField = InterpreterUtil.makeUniqueKey(fexpr.getName(), fexpr.getDescriptor().descriptorString);
if (!wrapper.getStaticFieldInitializers().containsKey(keyField)) {

View File

@@ -83,6 +83,7 @@ public class SingleClassesTest {
@Test public void testMethodReferenceLetterClass() { doTest("pkg/TestMethodReferenceLetterClass"); }
@Test public void testMemberAnnotations() { doTest("pkg/TestMemberAnnotations"); }
@Test public void testStaticNameClash() { doTest("pkg/TestStaticNameClash"); }
@Test public void testInterfaceWithObject() { doTest("pkg/TestInterfaceWithObject"); }
protected void doTest(String testFile, String... companionFiles) {
ConsoleDecompiler decompiler = fixture.getDecompiler();
@@ -107,7 +108,7 @@ public class SingleClassesTest {
File decompiledFile = new File(fixture.getTargetDir(), testName + ".java");
assertTrue(decompiledFile.isFile());
File referenceFile = new File(fixture.getTestDataDir(), "results/" + testName + ".dec");
assertTrue(referenceFile.isFile());
assertTrue("Expecting " + referenceFile.getAbsolutePath() + " to be a file", referenceFile.isFile());
assertFilesEqual(referenceFile, decompiledFile);
}

Binary file not shown.

View File

@@ -0,0 +1,8 @@
package pkg;
import java.math.BigDecimal;
public interface TestInterfaceWithObject {
BigDecimal BUGS_IN_THE_DECOMPILER = BigDecimal.ZERO;
}

View File

@@ -0,0 +1,13 @@
package pkg;
import java.math.BigDecimal;
/**
* @author Alexandru-Constantin Bledea
* @since March 06, 2016
*/
public interface TestInterfaceWithObject {
BigDecimal BUGS_IN_THE_DECOMPILER = BigDecimal.ZERO;
}