Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue #10978: Record inside interface is parsed as method #10979

Merged
merged 2 commits into from
Nov 27, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion .ci/validation.sh
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ no-error-xwiki)
cd ..
checkout_from https://github.com/xwiki/xwiki-platform.git
cd .ci-temp/xwiki-platform
git checkout "dc""f""b67ad6b5b78d7d506760c""e78d9a3d44b125af"
git checkout "1180900c""ea69d4235e20ff1ff0f156e9876d4b10"
# Validate xwiki-platform
mvn -e --no-transfer-progress checkstyle:check@default -Dcheckstyle.version=${CS_POM_VERSION}
cd ..
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -259,11 +259,11 @@ interfaceBodyDeclaration

interfaceMemberDeclaration[List<ModifierContext> mods]
: fieldDeclaration[mods]
| recordDeclaration[mods]
| interfaceMethodDeclaration[mods]
| interfaceDeclaration[mods]
| annotationTypeDeclaration[mods]
| classDeclaration[mods]
| recordDeclaration[mods]
| enumDeclaration[mods]
;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -191,4 +191,17 @@ public void testGetAcceptableTokens() {
assertArrayEquals(expected, actual, "Default acceptable tokens are invalid");
}

@Test
public void testRecordInInterfaceBody() throws Exception {

final String pattern = "^[a-z][a-zA-Z0-9]*$";

final String[] expected = {
"24:14: " + getCheckMessage(MSG_INVALID_PATTERN, "VIOLATION", pattern),
};

verifyWithInlineConfigParser(
getNonCompilablePath("InputMethodNameRecordInInterfaceBody.java"), expected);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -304,4 +304,10 @@ public void testUnusualAnnotation() throws Exception {
verifyAst(getPath("InputAntlr4AstRegressionUnusualAnnotation.txt"),
getPath("InputAntlr4AstRegressionUnusualAnnotation.java"));
}

@Test
public void testInterfaceMemberAlternativePrecedence() throws Exception {
verifyAst(getPath("InputAntlr4AstRegressionInterfaceRecordDef.txt"),
getNonCompilablePath("InputAntlr4AstRegressionInterfaceRecordDef.java"));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
/*
MethodName
format = (default)^[a-z][a-zA-Z0-9]*$
allowClassName = (default)false
applyToPublic = (default)true
applyToProtected = (default)true
applyToPackage = (default)true
applyToPrivate = (default)true

*/

//non-compiled with javac: Compilable with Java14
package com.puppycrawl.tools.checkstyle.checks.naming.methodname;

public interface InputMethodNameRecordInInterfaceBody {
int record = 1;
static record MyRedundantStaticRecord() {}
record MyRecord1(){}
record MyRecord2(int x, int y, int z){}
record MyRecord3(int[][] x, String... z){
String record() { // ok
return null;
}
void VIOLATION() { // violation

}
}
default void record(int x, int y, int z) {}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
//non-compiled with javac: Compilable with Java14
package com.puppycrawl.tools.checkstyle.grammar.antlr4;

public interface InputAntlr4AstRegressionInterfaceRecordDef {
int record = 1;
static record MyRedundantStaticRecord() {}
record MyRecord1(){}
record MyRecord2(int x, int y, int z){}
record MyRecord3(int[][] x, String... z){
String record(){
return null;
}
}
default void record(int x, int y, int z) {}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,148 @@
COMPILATION_UNIT -> COMPILATION_UNIT [2:0]
|--PACKAGE_DEF -> package [2:0]
| |--ANNOTATIONS -> ANNOTATIONS [2:47]
| |--DOT -> . [2:47]
| | |--DOT -> . [2:39]
| | | |--DOT -> . [2:28]
| | | | |--DOT -> . [2:22]
| | | | | |--DOT -> . [2:11]
| | | | | | |--IDENT -> com [2:8]
| | | | | | `--IDENT -> puppycrawl [2:12]
| | | | | `--IDENT -> tools [2:23]
| | | | `--IDENT -> checkstyle [2:29]
| | | `--IDENT -> grammar [2:40]
| | `--IDENT -> antlr4 [2:48]
| `--SEMI -> ; [2:54]
`--INTERFACE_DEF -> INTERFACE_DEF [4:0]
|--MODIFIERS -> MODIFIERS [4:0]
| `--LITERAL_PUBLIC -> public [4:0]
|--LITERAL_INTERFACE -> interface [4:7]
|--IDENT -> InputAntlr4AstRegressionInterfaceRecordDef [4:17]
`--OBJBLOCK -> OBJBLOCK [4:60]
|--LCURLY -> { [4:60]
|--VARIABLE_DEF -> VARIABLE_DEF [5:4]
| |--MODIFIERS -> MODIFIERS [5:4]
| |--TYPE -> TYPE [5:4]
| | `--LITERAL_INT -> int [5:4]
| |--IDENT -> record [5:8]
| |--ASSIGN -> = [5:15]
| | `--EXPR -> EXPR [5:17]
| | `--NUM_INT -> 1 [5:17]
| `--SEMI -> ; [5:18]
|--RECORD_DEF -> RECORD_DEF [6:4]
| |--MODIFIERS -> MODIFIERS [6:4]
| | `--LITERAL_STATIC -> static [6:4]
| |--LITERAL_RECORD -> record [6:11]
| |--IDENT -> MyRedundantStaticRecord [6:18]
| |--LPAREN -> ( [6:41]
| |--RECORD_COMPONENTS -> RECORD_COMPONENTS [6:42]
| |--RPAREN -> ) [6:42]
| `--OBJBLOCK -> OBJBLOCK [6:44]
| |--LCURLY -> { [6:44]
| `--RCURLY -> } [6:45]
|--RECORD_DEF -> RECORD_DEF [7:4]
| |--MODIFIERS -> MODIFIERS [7:4]
| |--LITERAL_RECORD -> record [7:4]
| |--IDENT -> MyRecord1 [7:11]
| |--LPAREN -> ( [7:20]
| |--RECORD_COMPONENTS -> RECORD_COMPONENTS [7:21]
| |--RPAREN -> ) [7:21]
| `--OBJBLOCK -> OBJBLOCK [7:22]
| |--LCURLY -> { [7:22]
| `--RCURLY -> } [7:23]
|--RECORD_DEF -> RECORD_DEF [8:4]
| |--MODIFIERS -> MODIFIERS [8:4]
| |--LITERAL_RECORD -> record [8:4]
| |--IDENT -> MyRecord2 [8:11]
| |--LPAREN -> ( [8:20]
| |--RECORD_COMPONENTS -> RECORD_COMPONENTS [8:21]
| | |--RECORD_COMPONENT_DEF -> RECORD_COMPONENT_DEF [8:21]
| | | |--ANNOTATIONS -> ANNOTATIONS [8:21]
| | | |--TYPE -> TYPE [8:21]
| | | | `--LITERAL_INT -> int [8:21]
| | | `--IDENT -> x [8:25]
| | |--COMMA -> , [8:26]
| | |--RECORD_COMPONENT_DEF -> RECORD_COMPONENT_DEF [8:28]
| | | |--ANNOTATIONS -> ANNOTATIONS [8:28]
| | | |--TYPE -> TYPE [8:28]
| | | | `--LITERAL_INT -> int [8:28]
| | | `--IDENT -> y [8:32]
| | |--COMMA -> , [8:33]
| | `--RECORD_COMPONENT_DEF -> RECORD_COMPONENT_DEF [8:35]
| | |--ANNOTATIONS -> ANNOTATIONS [8:35]
| | |--TYPE -> TYPE [8:35]
| | | `--LITERAL_INT -> int [8:35]
| | `--IDENT -> z [8:39]
| |--RPAREN -> ) [8:40]
| `--OBJBLOCK -> OBJBLOCK [8:41]
| |--LCURLY -> { [8:41]
| `--RCURLY -> } [8:42]
|--RECORD_DEF -> RECORD_DEF [9:4]
| |--MODIFIERS -> MODIFIERS [9:4]
| |--LITERAL_RECORD -> record [9:4]
| |--IDENT -> MyRecord3 [9:11]
| |--LPAREN -> ( [9:20]
| |--RECORD_COMPONENTS -> RECORD_COMPONENTS [9:21]
| | |--RECORD_COMPONENT_DEF -> RECORD_COMPONENT_DEF [9:21]
| | | |--ANNOTATIONS -> ANNOTATIONS [9:21]
| | | |--TYPE -> TYPE [9:21]
| | | | |--LITERAL_INT -> int [9:21]
| | | | |--ARRAY_DECLARATOR -> [ [9:24]
| | | | | `--RBRACK -> ] [9:25]
| | | | `--ARRAY_DECLARATOR -> [ [9:26]
| | | | `--RBRACK -> ] [9:27]
| | | `--IDENT -> x [9:29]
| | |--COMMA -> , [9:30]
| | `--RECORD_COMPONENT_DEF -> RECORD_COMPONENT_DEF [9:32]
| | |--ANNOTATIONS -> ANNOTATIONS [9:32]
| | |--TYPE -> TYPE [9:32]
| | | `--IDENT -> String [9:32]
| | |--ELLIPSIS -> ... [9:38]
| | `--IDENT -> z [9:42]
| |--RPAREN -> ) [9:43]
| `--OBJBLOCK -> OBJBLOCK [9:44]
| |--LCURLY -> { [9:44]
| |--METHOD_DEF -> METHOD_DEF [10:8]
| | |--MODIFIERS -> MODIFIERS [10:8]
| | |--TYPE -> TYPE [10:8]
| | | `--IDENT -> String [10:8]
| | |--IDENT -> record [10:15]
| | |--LPAREN -> ( [10:21]
| | |--PARAMETERS -> PARAMETERS [10:22]
| | |--RPAREN -> ) [10:22]
| | `--SLIST -> { [10:23]
| | |--LITERAL_RETURN -> return [11:12]
| | | |--EXPR -> EXPR [11:19]
| | | | `--LITERAL_NULL -> null [11:19]
| | | `--SEMI -> ; [11:23]
| | `--RCURLY -> } [12:8]
| `--RCURLY -> } [13:4]
|--METHOD_DEF -> METHOD_DEF [14:4]
| |--MODIFIERS -> MODIFIERS [14:4]
| | `--LITERAL_DEFAULT -> default [14:4]
| |--TYPE -> TYPE [14:12]
| | `--LITERAL_VOID -> void [14:12]
| |--IDENT -> record [14:17]
| |--LPAREN -> ( [14:23]
| |--PARAMETERS -> PARAMETERS [14:24]
| | |--PARAMETER_DEF -> PARAMETER_DEF [14:24]
| | | |--MODIFIERS -> MODIFIERS [14:24]
| | | |--TYPE -> TYPE [14:24]
| | | | `--LITERAL_INT -> int [14:24]
| | | `--IDENT -> x [14:28]
| | |--COMMA -> , [14:29]
| | |--PARAMETER_DEF -> PARAMETER_DEF [14:31]
| | | |--MODIFIERS -> MODIFIERS [14:31]
| | | |--TYPE -> TYPE [14:31]
| | | | `--LITERAL_INT -> int [14:31]
| | | `--IDENT -> y [14:35]
| | |--COMMA -> , [14:36]
| | `--PARAMETER_DEF -> PARAMETER_DEF [14:38]
| | |--MODIFIERS -> MODIFIERS [14:38]
| | |--TYPE -> TYPE [14:38]
| | | `--LITERAL_INT -> int [14:38]
| | `--IDENT -> z [14:42]
| |--RPAREN -> ) [14:43]
| `--SLIST -> { [14:45]
| `--RCURLY -> } [14:46]
`--RCURLY -> } [15:0]