correctly decompile interface object fields
This commit is contained in:
@@ -124,7 +124,7 @@ public class InitializerProcessor {
|
|||||||
|
|
||||||
RootStatement root = meth.root;
|
RootStatement root = meth.root;
|
||||||
StructClass cl = wrapper.getClassStruct();
|
StructClass cl = wrapper.getClassStruct();
|
||||||
|
boolean isInterface = cl.hasModifier(CodeConstants.ACC_INTERFACE);
|
||||||
Statement firstdata = findFirstData(root);
|
Statement firstdata = findFirstData(root);
|
||||||
if (firstdata != null) {
|
if (firstdata != null) {
|
||||||
while (!firstdata.getExprents().isEmpty()) {
|
while (!firstdata.getExprents().isEmpty()) {
|
||||||
@@ -139,7 +139,8 @@ public class InitializerProcessor {
|
|||||||
if (fexpr.isStatic() && fexpr.getClassname().equals(cl.qualifiedName) &&
|
if (fexpr.isStatic() && fexpr.getClassname().equals(cl.qualifiedName) &&
|
||||||
cl.hasField(fexpr.getName(), fexpr.getDescriptor().descriptorString)) {
|
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);
|
String keyField = InterpreterUtil.makeUniqueKey(fexpr.getName(), fexpr.getDescriptor().descriptorString);
|
||||||
if (!wrapper.getStaticFieldInitializers().containsKey(keyField)) {
|
if (!wrapper.getStaticFieldInitializers().containsKey(keyField)) {
|
||||||
|
|||||||
@@ -83,6 +83,7 @@ public class SingleClassesTest {
|
|||||||
@Test public void testMethodReferenceLetterClass() { doTest("pkg/TestMethodReferenceLetterClass"); }
|
@Test public void testMethodReferenceLetterClass() { doTest("pkg/TestMethodReferenceLetterClass"); }
|
||||||
@Test public void testMemberAnnotations() { doTest("pkg/TestMemberAnnotations"); }
|
@Test public void testMemberAnnotations() { doTest("pkg/TestMemberAnnotations"); }
|
||||||
@Test public void testStaticNameClash() { doTest("pkg/TestStaticNameClash"); }
|
@Test public void testStaticNameClash() { doTest("pkg/TestStaticNameClash"); }
|
||||||
|
@Test public void testInterfaceWithObject() { doTest("pkg/TestInterfaceWithObject"); }
|
||||||
|
|
||||||
protected void doTest(String testFile, String... companionFiles) {
|
protected void doTest(String testFile, String... companionFiles) {
|
||||||
ConsoleDecompiler decompiler = fixture.getDecompiler();
|
ConsoleDecompiler decompiler = fixture.getDecompiler();
|
||||||
@@ -107,7 +108,7 @@ public class SingleClassesTest {
|
|||||||
File decompiledFile = new File(fixture.getTargetDir(), testName + ".java");
|
File decompiledFile = new File(fixture.getTargetDir(), testName + ".java");
|
||||||
assertTrue(decompiledFile.isFile());
|
assertTrue(decompiledFile.isFile());
|
||||||
File referenceFile = new File(fixture.getTestDataDir(), "results/" + testName + ".dec");
|
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);
|
assertFilesEqual(referenceFile, decompiledFile);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
BIN
testData/classes/pkg/TestInterfaceWithObject.class
Normal file
BIN
testData/classes/pkg/TestInterfaceWithObject.class
Normal file
Binary file not shown.
8
testData/results/TestInterfaceWithObject.dec
Normal file
8
testData/results/TestInterfaceWithObject.dec
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
package pkg;
|
||||||
|
|
||||||
|
import java.math.BigDecimal;
|
||||||
|
|
||||||
|
public interface TestInterfaceWithObject {
|
||||||
|
BigDecimal BUGS_IN_THE_DECOMPILER = BigDecimal.ZERO;
|
||||||
|
}
|
||||||
|
|
||||||
13
testData/src/pkg/TestInterfaceWithObject.java
Normal file
13
testData/src/pkg/TestInterfaceWithObject.java
Normal 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;
|
||||||
|
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user