From 478e6896e952183eeb5510759e2847e1b162f0f6 Mon Sep 17 00:00:00 2001 From: "Egor.Ushakov" Date: Wed, 26 Apr 2017 20:14:23 +0300 Subject: [PATCH] fixed static interface methods --- .../java/decompiler/main/ClassWriter.java | 2 +- .../java/decompiler/SingleClassesTest.java | 1 + .../classes/pkg/TestInterfaceMethods.class | Bin 0 -> 340 bytes testData/results/TestInterfaceMethods.dec | 23 ++++++++++++++++++ testData/src/pkg/TestInterfaceMethods.java | 6 +++++ 5 files changed, 31 insertions(+), 1 deletion(-) create mode 100644 testData/classes/pkg/TestInterfaceMethods.class create mode 100644 testData/results/TestInterfaceMethods.dec create mode 100644 testData/src/pkg/TestInterfaceMethods.java diff --git a/src/org/jetbrains/java/decompiler/main/ClassWriter.java b/src/org/jetbrains/java/decompiler/main/ClassWriter.java index b7b8fb4..5646407 100644 --- a/src/org/jetbrains/java/decompiler/main/ClassWriter.java +++ b/src/org/jetbrains/java/decompiler/main/ClassWriter.java @@ -624,7 +624,7 @@ public class ClassWriter { appendModifiers(buffer, flags, METHOD_ALLOWED, isInterface, METHOD_EXCLUDED); - if (isInterface && mt.containsCode()) { + if (isInterface && !mt.hasModifier(CodeConstants.ACC_STATIC) && mt.containsCode()) { // 'default' modifier (Java 8) buffer.append("default "); } diff --git a/test/org/jetbrains/java/decompiler/SingleClassesTest.java b/test/org/jetbrains/java/decompiler/SingleClassesTest.java index 8c770d5..fe54ecb 100644 --- a/test/org/jetbrains/java/decompiler/SingleClassesTest.java +++ b/test/org/jetbrains/java/decompiler/SingleClassesTest.java @@ -111,6 +111,7 @@ public class SingleClassesTest { //@Test public void TestSwitchOnStrings() { doTest("pkg/TestSwitchOnStrings");} @Test public void testVarArgCalls() { doTest("pkg/TestVarArgCalls"); } @Test public void testLambdaParams() { doTest("pkg/TestLambdaParams"); } + @Test public void testInterfaceMethods() { doTest("pkg/TestInterfaceMethods"); } private void doTest(String testFile, String... companionFiles) { ConsoleDecompiler decompiler = fixture.getDecompiler(); diff --git a/testData/classes/pkg/TestInterfaceMethods.class b/testData/classes/pkg/TestInterfaceMethods.class new file mode 100644 index 0000000000000000000000000000000000000000..1cc7d69cb9bc5adb0f5ee97e8556e13f6b04cf3b GIT binary patch literal 340 zcmZ{fJx;?w5QX13jt#*fh>CCm5E5?aD3Oqm3=~A^$LmS5!Pv-Nb1zy74#1&M#!EmH z(7gG1-#lqPKHuH}TwoGo9Alr5w2qxMx8hcHK^UBz&I#dFT?k>4*-GxZr(BvD=cR7O zg)F!$-8X)i)rQMCH@5e;Q0P{+B^+nZkIQr>t-Gn5Gz&KJb=F=IMh|t@7`e86>hv$@ ze9bRRIQlPyaL^NJ$<;Ew&(~sHL?8tEA5?cSK&bOjr>Wlo^r{UZQjN621Mv@b=G`q8 U{KAIVQ7iE$q{$->?x_YyHs#Mqwg3PC literal 0 HcmV?d00001 diff --git a/testData/results/TestInterfaceMethods.dec b/testData/results/TestInterfaceMethods.dec new file mode 100644 index 0000000..d27a839 --- /dev/null +++ b/testData/results/TestInterfaceMethods.dec @@ -0,0 +1,23 @@ +package pkg; + +public interface TestInterfaceMethods { + static void staticMethod() { + }// 4 + + default void defaultMethod() { + }// 5 +} + +class 'pkg/TestInterfaceMethods' { + method 'staticMethod ()V' { + 0 4 + } + + method 'defaultMethod ()V' { + 0 7 + } +} + +Lines mapping: +4 <-> 5 +5 <-> 8 diff --git a/testData/src/pkg/TestInterfaceMethods.java b/testData/src/pkg/TestInterfaceMethods.java new file mode 100644 index 0000000..26f7d76 --- /dev/null +++ b/testData/src/pkg/TestInterfaceMethods.java @@ -0,0 +1,6 @@ +package pkg; + +public interface TestInterfaceMethods { + static void staticMethod() {} + default void defaultMethod() {} +} \ No newline at end of file