correctly decompile interface object fields

master
Alexandru-Constantin Bledea 9 years ago
parent d50e8a860e
commit 06c993b508
  1. 5
      src/org/jetbrains/java/decompiler/main/InitializerProcessor.java
  2. 3
      test/org/jetbrains/java/decompiler/SingleClassesTest.java
  3. BIN
      testData/classes/pkg/TestInterfaceWithObject.class
  4. 8
      testData/results/TestInterfaceWithObject.dec
  5. 13
      testData/src/pkg/TestInterfaceWithObject.java

@ -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)) {

@ -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);
}

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

@ -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;
}
Loading…
Cancel
Save