Fix pmd-java

This commit is contained in:
Clément Fournier
2022-11-16 14:41:06 +01:00
parent be691c71bf
commit 9a5c2523f6
3 changed files with 83 additions and 6 deletions

View File

@ -1774,7 +1774,7 @@ void InstanceOfExpression() #void:
{
AbstractJavaNode id = jjtree.popNode();
ASTRecordPattern pat = (ASTRecordPattern) jjtree.peekNode();
pat.addChild(id);
pat.addChild(id, pat.getNumChildren());
}
]
]

View File

@ -143,7 +143,7 @@ public class CommentDefaultAccessModifierRule extends AbstractJavaRulechainRule
boolean isConcreteClass = !enclosing.isInterface() && !enclosing.isEnum();
// ignore if it's inside an interface / Annotation
return isConcreteClass && isMissingComment(decl) && !hasIgnoredAnnotation(parentClassOrInterface);
return isConcreteClass && isMissingComment(decl) && isNotIgnored(decl) && isNotIgnored(enclosing);
}
private boolean isMissingComment(AccessNode decl) {
@ -152,9 +152,7 @@ public class CommentDefaultAccessModifierRule extends AbstractJavaRulechainRule
return decl.getVisibility() == Visibility.V_PACKAGE
// if is a default access modifier check if there is a comment
// in this line
&& !interestingLineNumberComments.contains(decl.getBeginLine())
// that it is not annotated with e.g. @VisibleForTesting
&& isNotIgnored(decl);
&& !interestingLineNumberComments.contains(decl.getBeginLine());
}
private boolean isNotIgnored(AccessNode decl) {

View File

@ -11,7 +11,7 @@
+- ImportDeclaration[@ImportOnDemand = false, @ImportedName = "java.util.stream.Stream", @ImportedSimpleName = "Stream", @PackageName = "java.util.stream", @Static = false]
+- ClassOrInterfaceDeclaration[@Abstract = false, @Annotation = false, @Anonymous = false, @BinaryName = "ParserCornerCases18", @CanonicalName = "ParserCornerCases18", @EffectiveVisibility = Visibility.V_PUBLIC, @Enum = false, @Final = false, @Interface = false, @Local = false, @Nested = false, @PackageName = "", @PackagePrivate = false, @Record = false, @RegularClass = true, @RegularInterface = false, @SimpleName = "ParserCornerCases18", @TopLevel = true, @Visibility = Visibility.V_PUBLIC]
| +- ModifierList[@EffectiveModifiers = "{public}", @ExplicitModifiers = "{public}"]
| +- ClassOrInterfaceBody[@Empty = false, @Size = 26]
| +- ClassOrInterfaceBody[@Empty = false, @Size = 30]
| +- MethodDeclaration[@Abstract = false, @Arity = 0, @EffectiveVisibility = Visibility.V_PUBLIC, @Image = "lambdas", @Name = "lambdas", @Overridden = false, @Varargs = false, @Visibility = Visibility.V_PUBLIC, @Void = true]
| | +- ModifierList[@EffectiveModifiers = "{public}", @ExplicitModifiers = "{public}"]
| | +- VoidType[]
@ -966,6 +966,85 @@
| | +- Annotation[@SimpleName = "NonNull"]
| | | +- ClassOrInterfaceType[@FullyQualified = false, @SimpleName = "NonNull"]
| | +- NumericLiteral[@Base = 10, @CompileTimeConstant = true, @DoubleLiteral = false, @FloatLiteral = false, @Image = "0", @IntLiteral = true, @Integral = true, @LongLiteral = false, @ParenthesisDepth = 0, @Parenthesized = false, @ValueAsDouble = 0.0, @ValueAsFloat = 0.0, @ValueAsInt = 0, @ValueAsLong = 0]
| +- MethodDeclaration[@Abstract = false, @Arity = 1, @EffectiveVisibility = Visibility.V_PUBLIC, @Image = "check", @Name = "check", @Overridden = false, @Varargs = false, @Visibility = Visibility.V_PUBLIC, @Void = false]
| | +- ModifierList[@EffectiveModifiers = "{public, static}", @ExplicitModifiers = "{public, static}"]
| | +- TypeParameters[@Empty = false, @Size = 1]
| | | +- TypeParameter[@Image = "T", @Name = "T", @TypeBound = false]
| | +- ArrayType[@ArrayDepth = 2]
| | | +- ClassOrInterfaceType[@FullyQualified = false, @SimpleName = "T"]
| | | +- ArrayDimensions[@Empty = false, @Size = 2]
| | | +- ArrayTypeDim[@Varargs = false]
| | | +- ArrayTypeDim[@Varargs = false]
| | +- FormalParameters[@Empty = false, @Size = 1]
| | | +- FormalParameter[@EffectiveVisibility = Visibility.V_LOCAL, @Final = false, @Varargs = false, @Visibility = Visibility.V_LOCAL]
| | | +- ModifierList[@EffectiveModifiers = "{}", @ExplicitModifiers = "{}"]
| | | +- ArrayType[@ArrayDepth = 2]
| | | | +- ClassOrInterfaceType[@FullyQualified = false, @SimpleName = "T"]
| | | | +- ArrayDimensions[@Empty = false, @Size = 2]
| | | | +- ArrayTypeDim[@Varargs = false]
| | | | | +- Annotation[@SimpleName = "Anno"]
| | | | | +- ClassOrInterfaceType[@FullyQualified = false, @SimpleName = "Anno"]
| | | | +- ArrayTypeDim[@Varargs = false]
| | | | +- Annotation[@SimpleName = "Anno"]
| | | | +- ClassOrInterfaceType[@FullyQualified = false, @SimpleName = "Anno"]
| | | +- VariableDeclaratorId[@ArrayType = true, @EffectiveVisibility = Visibility.V_LOCAL, @EnumConstant = false, @ExceptionBlockParameter = false, @Field = false, @Final = false, @ForLoopVariable = false, @ForeachVariable = false, @FormalParameter = true, @LambdaParameter = false, @LocalVariable = false, @Name = "arr", @PatternBinding = false, @RecordComponent = false, @ResourceDeclaration = false, @TypeInferred = false, @Visibility = Visibility.V_LOCAL]
| | +- Block[@Empty = false, @Size = 2, @containsComment = false]
| | +- IfStatement[@Else = false]
| | | +- InfixExpression[@CompileTimeConstant = false, @Operator = BinaryOp.EQ, @ParenthesisDepth = 0, @Parenthesized = false]
| | | | +- VariableAccess[@AccessType = AccessType.READ, @CompileTimeConstant = false, @Image = "arr", @Name = "arr", @ParenthesisDepth = 0, @Parenthesized = false]
| | | | +- NullLiteral[@CompileTimeConstant = false, @ParenthesisDepth = 0, @Parenthesized = false]
| | | +- Block[@Empty = false, @Size = 1, @containsComment = false]
| | | +- ThrowStatement[]
| | | +- ConstructorCall[@AnonymousClass = false, @CompileTimeConstant = false, @DiamondTypeArgs = false, @MethodName = "new", @ParenthesisDepth = 0, @Parenthesized = false, @QualifiedInstanceCreation = false]
| | | +- ClassOrInterfaceType[@FullyQualified = false, @SimpleName = "NullPointerException"]
| | | +- ArgumentList[@Empty = true, @Size = 0]
| | +- ReturnStatement[]
| | +- VariableAccess[@AccessType = AccessType.READ, @CompileTimeConstant = false, @Image = "arr", @Name = "arr", @ParenthesisDepth = 0, @Parenthesized = false]
| +- MethodDeclaration[@Abstract = false, @Arity = 0, @EffectiveVisibility = Visibility.V_PUBLIC, @Image = "func", @Name = "func", @Overridden = false, @Varargs = false, @Visibility = Visibility.V_PUBLIC, @Void = false]
| | +- ModifierList[@EffectiveModifiers = "{public}", @ExplicitModifiers = "{public}"]
| | +- ClassOrInterfaceType[@FullyQualified = false, @SimpleName = "Function"]
| | +- FormalParameters[@Empty = true, @Size = 0]
| | | +- ReceiverParameter[]
| | | +- ClassOrInterfaceType[@FullyQualified = false, @SimpleName = "Main"]
| | +- Block[@Empty = false, @Size = 1, @containsComment = true]
| | +- ReturnStatement[]
| | +- MethodReference[@CompileTimeConstant = false, @ConstructorReference = true, @MethodName = "new", @ParenthesisDepth = 0, @Parenthesized = false]
| | +- TypeExpression[@CompileTimeConstant = false, @ParenthesisDepth = 0, @Parenthesized = false]
| | +- ClassOrInterfaceType[@FullyQualified = false, @SimpleName = "Inner"]
| | +- ClassOrInterfaceType[@FullyQualified = false, @SimpleName = "Main"]
| | +- Annotation[@SimpleName = "A"]
| | +- ClassOrInterfaceType[@FullyQualified = false, @SimpleName = "A"]
| +- MethodDeclaration[@Abstract = false, @Arity = 1, @EffectiveVisibility = Visibility.V_PUBLIC, @Image = "max", @Name = "max", @Overridden = false, @Varargs = true, @Visibility = Visibility.V_PUBLIC, @Void = false]
| | +- ModifierList[@EffectiveModifiers = "{public, static}", @ExplicitModifiers = "{public, static}"]
| | +- PrimitiveType[@Kind = PrimitiveTypeKind.BYTE]
| | +- FormalParameters[@Empty = false, @Size = 1]
| | | +- FormalParameter[@EffectiveVisibility = Visibility.V_LOCAL, @Final = true, @Varargs = true, @Visibility = Visibility.V_LOCAL]
| | | +- ModifierList[@EffectiveModifiers = "{final}", @ExplicitModifiers = "{final}"]
| | | +- ArrayType[@ArrayDepth = 1]
| | | | +- PrimitiveType[@Kind = PrimitiveTypeKind.BYTE]
| | | | +- ArrayDimensions[@Empty = false, @Size = 1]
| | | | +- ArrayTypeDim[@Varargs = true]
| | | | +- Annotation[@SimpleName = "NotNull"]
| | | | +- ClassOrInterfaceType[@FullyQualified = false, @SimpleName = "NotNull"]
| | | +- VariableDeclaratorId[@ArrayType = true, @EffectiveVisibility = Visibility.V_LOCAL, @EnumConstant = false, @ExceptionBlockParameter = false, @Field = false, @Final = true, @ForLoopVariable = false, @ForeachVariable = false, @FormalParameter = true, @LambdaParameter = false, @LocalVariable = false, @Name = "array", @PatternBinding = false, @RecordComponent = false, @ResourceDeclaration = false, @TypeInferred = false, @Visibility = Visibility.V_LOCAL]
| | +- Block[@Empty = false, @Size = 1, @containsComment = false]
| | +- ReturnStatement[]
| | +- NumericLiteral[@Base = 10, @CompileTimeConstant = true, @DoubleLiteral = false, @FloatLiteral = false, @Image = "0", @IntLiteral = true, @Integral = true, @LongLiteral = false, @ParenthesisDepth = 0, @Parenthesized = false, @ValueAsDouble = 0.0, @ValueAsFloat = 0.0, @ValueAsInt = 0, @ValueAsLong = 0]
| +- AnnotationTypeDeclaration[@Abstract = true, @Annotation = true, @Anonymous = false, @BinaryName = "ParserCornerCases18$Anno", @CanonicalName = "ParserCornerCases18.Anno", @EffectiveVisibility = Visibility.V_PACKAGE, @Enum = false, @Final = false, @Interface = true, @Local = false, @Nested = true, @PackageName = "", @Record = false, @RegularClass = false, @RegularInterface = false, @SimpleName = "Anno", @TopLevel = false, @Visibility = Visibility.V_PACKAGE]
| | +- ModifierList[@EffectiveModifiers = "{abstract, static}", @ExplicitModifiers = "{}"]
| | | +- Annotation[@SimpleName = "Retention"]
| | | | +- ClassOrInterfaceType[@FullyQualified = false, @SimpleName = "Retention"]
| | | | +- AnnotationMemberList[@Empty = false, @Size = 1]
| | | | +- MemberValuePair[@Image = "value", @Name = "value", @Shorthand = true]
| | | | +- FieldAccess[@AccessType = AccessType.READ, @CompileTimeConstant = false, @Image = "CLASS", @Name = "CLASS", @ParenthesisDepth = 0, @Parenthesized = false]
| | | | +- AmbiguousName[@CompileTimeConstant = false, @Image = "RetentionPolicy", @Name = "RetentionPolicy", @ParenthesisDepth = 0, @Parenthesized = false]
| | | +- Annotation[@SimpleName = "Target"]
| | | +- ClassOrInterfaceType[@FullyQualified = false, @SimpleName = "Target"]
| | | +- AnnotationMemberList[@Empty = false, @Size = 1]
| | | +- MemberValuePair[@Image = "value", @Name = "value", @Shorthand = true]
| | | +- MemberValueArrayInitializer[]
| | | +- VariableAccess[@AccessType = AccessType.READ, @CompileTimeConstant = false, @Image = "TYPE_USE", @Name = "TYPE_USE", @ParenthesisDepth = 0, @Parenthesized = false]
| | +- AnnotationTypeBody[@Empty = true, @Size = 0]
| +- MethodDeclaration[@Abstract = false, @Arity = 0, @EffectiveVisibility = Visibility.V_PRIVATE, @Image = "testMultiDimArrayWithAnnotations", @Name = "testMultiDimArrayWithAnnotations", @Overridden = false, @Varargs = false, @Visibility = Visibility.V_PRIVATE, @Void = true]
| | +- ModifierList[@EffectiveModifiers = "{private, static}", @ExplicitModifiers = "{private, static}"]
| | +- VoidType[]