Skip to content

Commit

Permalink
Fix issues solven-eu#842 and solven-eu#843
Browse files Browse the repository at this point in the history
  • Loading branch information
mches committed Oct 8, 2024
1 parent 6f7fa54 commit c7a76c1
Show file tree
Hide file tree
Showing 2 changed files with 73 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import com.github.javaparser.ast.body.AnnotationDeclaration;
import com.github.javaparser.ast.body.AnnotationMemberDeclaration;
import com.github.javaparser.ast.body.ClassOrInterfaceDeclaration;
import com.github.javaparser.ast.body.EnumDeclaration;
import com.github.javaparser.ast.body.FieldDeclaration;
import com.github.javaparser.ast.body.MethodDeclaration;
import com.github.javaparser.ast.nodeTypes.NodeWithModifiers;
Expand Down Expand Up @@ -109,6 +110,8 @@ protected boolean processNotRecursively(NodeAndSymbolSolver<?> nodeAndSymbolSolv
var parentNode = modifier.getParentNode().get();
if (!(parentNode instanceof MethodDeclaration) && !(parentNode instanceof FieldDeclaration)
&& !(parentNode instanceof ClassOrInterfaceDeclaration)
&& !(parentNode instanceof AnnotationDeclaration)
&& !(parentNode instanceof EnumDeclaration)
&& !(parentNode instanceof AnnotationMemberDeclaration)) {
return false;
}
Expand All @@ -124,9 +127,11 @@ protected boolean processNotRecursively(NodeAndSymbolSolver<?> nodeAndSymbolSolv
return false;
}

// We are considering a modifier from an interface method|field|classOrInterface
if (modifier.getKeyword() == Keyword.PUBLIC || modifier.getKeyword() == Keyword.ABSTRACT
|| modifier.getKeyword() == Keyword.FINAL
// We are considering a modifier from an interface method|field|classOrInterface|annotation|enum
if (modifier.getKeyword() == Keyword.PUBLIC
|| (modifier.getKeyword() == Keyword.ABSTRACT || modifier.getKeyword() == Keyword.FINAL)
&& !(parentNode instanceof ClassOrInterfaceDeclaration
&& !((ClassOrInterfaceDeclaration) parentNode).isInterface())
|| modifier.getKeyword() == Keyword.STATIC && !(parentNode instanceof MethodDeclaration)) {

// https://github.com/javaparser/javaparser/issues/3935
Expand All @@ -150,9 +155,11 @@ protected boolean processNotRecursively(NodeAndSymbolSolver<?> nodeAndSymbolSolv

return false;
} else if (grandParentNode instanceof AnnotationDeclaration) {
// We are considering a modifier from an annotation method|field|classOrInterface
if (modifier.getKeyword() == Keyword.PUBLIC || modifier.getKeyword() == Keyword.ABSTRACT
|| modifier.getKeyword() == Keyword.FINAL
// We are considering a modifier from an annotation classOrInterface|annotation|enum|annotationMember
if (modifier.getKeyword() == Keyword.PUBLIC
|| (modifier.getKeyword() == Keyword.ABSTRACT || modifier.getKeyword() == Keyword.FINAL)
&& !(parentNode instanceof ClassOrInterfaceDeclaration
&& !((ClassOrInterfaceDeclaration) parentNode).isInterface())
|| modifier.getKeyword() == Keyword.STATIC) {
return modifier.remove();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,21 @@ public static interface Baz {
static String parse() {
return "parsed";
}

// public, static, abstract are redundant
public static abstract interface MyInterface {}

// public and static are redundant, but not abstract
public static abstract class MyAbstractClass implements MyInterface {}

// public and static are redundant, but not final
public static final class MyFinalClass extends MyAbstractClass {}

// public, static, and abstract are redundant
public static abstract @interface MyAnnotation {}

// public and static are redundant
public static enum MyEnum {}
}

public interface Post {
Expand All @@ -57,6 +72,21 @@ interface Baz {
static String parse() {
return "parsed";
}

// public, static, abstract are redundant
interface MyInterface {}

// public and static are redundant, but not abstract
abstract class MyAbstractClass implements MyInterface {}

// public and static are redundant, but not final
final class MyFinalClass extends MyAbstractClass {}

// public, static, and abstract are redundant
@interface MyAnnotation {}

// public and static are redundant
enum MyEnum {}
}
}

Expand All @@ -77,6 +107,21 @@ public static class Bar {
// ditto
public static interface Baz {
}

// public, static, abstract are redundant
public static abstract interface MyInterface {}

// public and static are redundant, but not abstract
public static abstract class MyAbstractClass implements MyInterface {}

// public and static are redundant, but not final
public static final class MyFinalClass extends MyAbstractClass {}

// public, static, and abstract are redundant
public static abstract @interface MyAnnotation {}

// public and static are redundant
public static enum MyEnum {}
}

public @interface Post {
Expand All @@ -93,6 +138,21 @@ class Bar {
// ditto
interface Baz {
}

// public, static, abstract are redundant
interface MyInterface {}

// public and static are redundant, but not abstract
abstract class MyAbstractClass implements MyInterface {}

// public and static are redundant, but not final
final class MyFinalClass extends MyAbstractClass {}

// public, static, and abstract are redundant
@interface MyAnnotation {}

// public and static are redundant
enum MyEnum {}
}
}

Expand Down

0 comments on commit c7a76c1

Please sign in to comment.