Skip to content

Commit f20eb97

Browse files
authored
Remove public + static from class definitions in interfaces (#491)
* Remove public + static from class definitions in interfaces * Fix tests
1 parent 37737b0 commit f20eb97

File tree

6 files changed

+20
-11
lines changed

6 files changed

+20
-11
lines changed

src/org/jetbrains/java/decompiler/main/ClassWriter.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -641,6 +641,15 @@ private void writeClassDefinition(ClassNode node, TextBuffer buffer, int indent)
641641
}
642642
}
643643

644+
// Classes defined inside of interfaces are implicitly public/static (JLS 9.5 Member Type Declarations)
645+
if (
646+
node.type == ClassNode.Type.MEMBER &&
647+
(node.parent.getWrapper().getClassStruct().getAccessFlags() & CodeConstants.ACC_INTERFACE) != 0
648+
) {
649+
flags &= ~CodeConstants.ACC_PUBLIC;
650+
flags &= ~CodeConstants.ACC_STATIC;
651+
}
652+
644653
if (interceptor != null) {
645654
String oldName = interceptor.getOldName(cl.qualifiedName);
646655
appendRenameComment(buffer, oldName, MType.CLASS, indent);

testData/results/pkg/MoreAnnotations.dec

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -95,11 +95,11 @@ public @interface MoreAnnotations {
9595

9696
Class<? extends CharSequence>[] classArray() default {CharSequence.class, String.class, StringBuilder.class};
9797

98-
public @interface NestedAnnotation {
98+
@interface NestedAnnotation {
9999
String value() default "MyString";
100100
}
101101

102-
public static enum TestEnum {
102+
enum TestEnum {
103103
FirstValue,
104104
SecondValue;
105105
}

testData/results/pkg/TestGenericSubclassTypes.dec

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,14 @@ public interface TestGenericSubclassTypes<T> {
1515
return i -> i;// 27
1616
}
1717

18-
public static class Constant<T> implements TestGenericSubclassTypes.Numerical<T> {
18+
class Constant<T> implements TestGenericSubclassTypes.Numerical<T> {
1919
@Override
2020
public int get(T in) {
2121
return 1;// 16
2222
}
2323
}
2424

25-
public interface Numerical<T> {
25+
interface Numerical<T> {
2626
int get(T var1);
2727
}
2828
}

testData/results/pkg/TestInterfaceSubclass.dec

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,11 @@ public interface TestInterfaceSubclass {
55

66
int doOtherThing();
77

8-
public abstract static class AbstractClass implements TestInterfaceSubclass {
8+
abstract class AbstractClass implements TestInterfaceSubclass {
99
public abstract double doDoubleThing();
1010
}
1111

12-
public static class Multiple extends TestInterfaceSubclass.AbstractClass implements TestInterfaceSubclass {
12+
class Multiple extends TestInterfaceSubclass.AbstractClass implements TestInterfaceSubclass {
1313
@Override
1414
public void doThing() {
1515
System.out.println("Hello");// 29
@@ -26,7 +26,7 @@ public interface TestInterfaceSubclass {
2626
}
2727
}
2828

29-
public static class Subclass implements TestInterfaceSubclass {
29+
class Subclass implements TestInterfaceSubclass {
3030
@Override
3131
public void doThing() {
3232
System.out.println("Hi");// 12

testData/results/pkg/TestInterfaceSuper.dec

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ public interface TestInterfaceSuper {
44
default void defaultMethod() {
55
}// 4
66

7-
public static class Impl implements TestInterfaceSuper {
7+
class Impl implements TestInterfaceSuper {
88
@Override
99
public void defaultMethod() {
1010
TestInterfaceSuper.super.defaultMethod();// 8

testData/results/pkg/TestRecordPatterns6.dec

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,13 +25,13 @@ public class TestRecordPatterns6 {
2525
}
2626

2727
sealed interface I permits TestRecordPatterns6.I.R1, TestRecordPatterns6.I.R2, TestRecordPatterns6.I.R3 {
28-
public record R1(Object o) implements TestRecordPatterns6.I {
28+
record R1(Object o) implements TestRecordPatterns6.I {
2929
}
3030

31-
public record R2(int i) implements TestRecordPatterns6.I {
31+
record R2(int i) implements TestRecordPatterns6.I {
3232
}
3333

34-
public record R3(String s) implements TestRecordPatterns6.I {
34+
record R3(String s) implements TestRecordPatterns6.I {
3535
}
3636
}
3737
}

0 commit comments

Comments
 (0)