From 0c0d6f33ad55630f79bffc75762b21ee6a93e9c4 Mon Sep 17 00:00:00 2001 From: Andreas Dangel Date: Thu, 9 Feb 2023 18:37:35 +0100 Subject: [PATCH] [kotlin] Update grammar to version 1.8 --- .../pmd/it/BinaryDistributionIT.java | 3 +- .../sourceforge/pmd/lang/kotlin/ast/Kotlin.g4 | 9 +- .../pmd/lang/kotlin/ast/KotlinLexer.g4 | 2 + .../pmd/lang/kotlin/ast/KotlinLexer.tokens | 382 +++++++++--------- .../sourceforge/pmd/lang/kotlin/ast/README.md | 4 +- .../pmd/lang/kotlin/ast/UnicodeClasses.g4 | 2 +- .../pmd/lang/kotlin/KotlinLanguageModule.java | 3 +- .../pmd/lang/kotlin/LanguageVersionTest.java | 2 +- 8 files changed, 207 insertions(+), 200 deletions(-) diff --git a/pmd-dist/src/test/java/net/sourceforge/pmd/it/BinaryDistributionIT.java b/pmd-dist/src/test/java/net/sourceforge/pmd/it/BinaryDistributionIT.java index 431d5f1bcf..2d0f21feca 100644 --- a/pmd-dist/src/test/java/net/sourceforge/pmd/it/BinaryDistributionIT.java +++ b/pmd-dist/src/test/java/net/sourceforge/pmd/it/BinaryDistributionIT.java @@ -49,7 +49,7 @@ class BinaryDistributionIT extends AbstractBinaryDistributionTest { "java-19-preview", "java-20", "java-20-preview", "java-5", "java-6", "java-7", "java-8", "java-9", "jsp-2", "jsp-3", "kotlin-1.6", - "kotlin-1.7", "modelica-3.4", "modelica-3.5", + "kotlin-1.7", "kotlin-1.8", "modelica-3.4", "modelica-3.5", "plsql-11g", "plsql-12.1", "plsql-12.2", "plsql-12c_Release_1", "plsql-12c_Release_2", "plsql-18c", "plsql-19c", "plsql-21c", "pom-4.0.0", @@ -62,7 +62,6 @@ class BinaryDistributionIT extends AbstractBinaryDistributionTest { "xsl-3.0" ); - private final String srcDir = new File(".", "src/test/resources/sample-source/java/").getAbsolutePath(); private static Pattern toListPattern(List items) { diff --git a/pmd-kotlin/src/main/antlr4/net/sourceforge/pmd/lang/kotlin/ast/Kotlin.g4 b/pmd-kotlin/src/main/antlr4/net/sourceforge/pmd/lang/kotlin/ast/Kotlin.g4 index c905ec427d..282b737351 100644 --- a/pmd-kotlin/src/main/antlr4/net/sourceforge/pmd/lang/kotlin/ast/Kotlin.g4 +++ b/pmd-kotlin/src/main/antlr4/net/sourceforge/pmd/lang/kotlin/ast/Kotlin.g4 @@ -116,6 +116,7 @@ delegationSpecifier | explicitDelegation | userType | functionType + | SUSPEND NL* functionType ; constructorInvocation @@ -272,7 +273,7 @@ enumEntry // SECTION: types type - : typeModifiers? (parenthesizedType | nullableType | typeReference | functionType) + : typeModifiers? (functionType | parenthesizedType | nullableType | typeReference | definitelyNonNullableType) ; typeReference @@ -331,6 +332,10 @@ parenthesizedUserType : LPAREN NL* (userType | parenthesizedUserType) NL* RPAREN ; +definitelyNonNullableType + : typeModifiers? (userType | parenthesizedUserType) NL* AMP NL* typeModifiers? (userType | parenthesizedUserType) + ; + // SECTION: statements statements @@ -379,12 +384,10 @@ assignment semi : (SEMICOLON | NL) NL* - | EOF ; semis : (SEMICOLON | NL)+ - | EOF ; // SECTION: expressions diff --git a/pmd-kotlin/src/main/antlr4/net/sourceforge/pmd/lang/kotlin/ast/KotlinLexer.g4 b/pmd-kotlin/src/main/antlr4/net/sourceforge/pmd/lang/kotlin/ast/KotlinLexer.g4 index 2a33305a1d..9b7f6ac8af 100644 --- a/pmd-kotlin/src/main/antlr4/net/sourceforge/pmd/lang/kotlin/ast/KotlinLexer.g4 +++ b/pmd-kotlin/src/main/antlr4/net/sourceforge/pmd/lang/kotlin/ast/KotlinLexer.g4 @@ -88,6 +88,7 @@ AS_SAFE: 'as?'; EQEQ: '=='; EQEQEQ: '==='; SINGLE_QUOTE: '\''; +AMP: '&'; // SECTION: keywords @@ -441,6 +442,7 @@ Inside_AS_SAFE: AS_SAFE -> type(AS_SAFE); Inside_EQEQ: EQEQ -> type(EQEQ); Inside_EQEQEQ: EQEQEQ -> type(EQEQEQ); Inside_SINGLE_QUOTE: SINGLE_QUOTE -> type(SINGLE_QUOTE); +Inside_AMP: AMP -> type(AMP); Inside_QUOTE_OPEN: QUOTE_OPEN -> pushMode(LineString), type(QUOTE_OPEN); Inside_TRIPLE_QUOTE_OPEN: TRIPLE_QUOTE_OPEN -> pushMode(MultiLineString), type(TRIPLE_QUOTE_OPEN); diff --git a/pmd-kotlin/src/main/antlr4/net/sourceforge/pmd/lang/kotlin/ast/KotlinLexer.tokens b/pmd-kotlin/src/main/antlr4/net/sourceforge/pmd/lang/kotlin/ast/KotlinLexer.tokens index a207d69c19..8692c66d62 100644 --- a/pmd-kotlin/src/main/antlr4/net/sourceforge/pmd/lang/kotlin/ast/KotlinLexer.tokens +++ b/pmd-kotlin/src/main/antlr4/net/sourceforge/pmd/lang/kotlin/ast/KotlinLexer.tokens @@ -53,122 +53,123 @@ AS_SAFE=52 EQEQ=53 EQEQEQ=54 SINGLE_QUOTE=55 -RETURN_AT=56 -CONTINUE_AT=57 -BREAK_AT=58 -THIS_AT=59 -SUPER_AT=60 -FILE=61 -FIELD=62 -PROPERTY=63 -GET=64 -SET=65 -RECEIVER=66 -PARAM=67 -SETPARAM=68 -DELEGATE=69 -PACKAGE=70 -IMPORT=71 -CLASS=72 -INTERFACE=73 -FUN=74 -OBJECT=75 -VAL=76 -VAR=77 -TYPE_ALIAS=78 -CONSTRUCTOR=79 -BY=80 -COMPANION=81 -INIT=82 -THIS=83 -SUPER=84 -TYPEOF=85 -WHERE=86 -IF=87 -ELSE=88 -WHEN=89 -TRY=90 -CATCH=91 -FINALLY=92 -FOR=93 -DO=94 -WHILE=95 -THROW=96 -RETURN=97 -CONTINUE=98 -BREAK=99 -AS=100 -IS=101 -IN=102 -NOT_IS=103 -NOT_IN=104 -OUT=105 -DYNAMIC=106 -PUBLIC=107 -PRIVATE=108 -PROTECTED=109 -INTERNAL=110 -ENUM=111 -SEALED=112 -ANNOTATION=113 -DATA=114 -INNER=115 -VALUE=116 -TAILREC=117 -OPERATOR=118 -INLINE=119 -INFIX=120 -EXTERNAL=121 -SUSPEND=122 -OVERRIDE=123 -ABSTRACT=124 -FINAL=125 -OPEN=126 -CONST=127 -LATEINIT=128 -VARARG=129 -NOINLINE=130 -CROSSINLINE=131 -REIFIED=132 -EXPECT=133 -ACTUAL=134 -RealLiteral=135 -FloatLiteral=136 -DoubleLiteral=137 -IntegerLiteral=138 -HexLiteral=139 -BinLiteral=140 -UnsignedLiteral=141 -LongLiteral=142 -BooleanLiteral=143 -NullLiteral=144 -CharacterLiteral=145 -Identifier=146 -IdentifierOrSoftKey=147 -FieldIdentifier=148 -QUOTE_OPEN=149 -TRIPLE_QUOTE_OPEN=150 -UNICODE_CLASS_LL=151 -UNICODE_CLASS_LM=152 -UNICODE_CLASS_LO=153 -UNICODE_CLASS_LT=154 -UNICODE_CLASS_LU=155 -UNICODE_CLASS_ND=156 -UNICODE_CLASS_NL=157 -QUOTE_CLOSE=158 -LineStrRef=159 -LineStrText=160 -LineStrEscapedChar=161 -LineStrExprStart=162 -TRIPLE_QUOTE_CLOSE=163 -MultiLineStringQuote=164 -MultiLineStrRef=165 -MultiLineStrText=166 -MultiLineStrExprStart=167 -Inside_Comment=168 -Inside_WS=169 -Inside_NL=170 -ErrorCharacter=171 +AMP=56 +RETURN_AT=57 +CONTINUE_AT=58 +BREAK_AT=59 +THIS_AT=60 +SUPER_AT=61 +FILE=62 +FIELD=63 +PROPERTY=64 +GET=65 +SET=66 +RECEIVER=67 +PARAM=68 +SETPARAM=69 +DELEGATE=70 +PACKAGE=71 +IMPORT=72 +CLASS=73 +INTERFACE=74 +FUN=75 +OBJECT=76 +VAL=77 +VAR=78 +TYPE_ALIAS=79 +CONSTRUCTOR=80 +BY=81 +COMPANION=82 +INIT=83 +THIS=84 +SUPER=85 +TYPEOF=86 +WHERE=87 +IF=88 +ELSE=89 +WHEN=90 +TRY=91 +CATCH=92 +FINALLY=93 +FOR=94 +DO=95 +WHILE=96 +THROW=97 +RETURN=98 +CONTINUE=99 +BREAK=100 +AS=101 +IS=102 +IN=103 +NOT_IS=104 +NOT_IN=105 +OUT=106 +DYNAMIC=107 +PUBLIC=108 +PRIVATE=109 +PROTECTED=110 +INTERNAL=111 +ENUM=112 +SEALED=113 +ANNOTATION=114 +DATA=115 +INNER=116 +VALUE=117 +TAILREC=118 +OPERATOR=119 +INLINE=120 +INFIX=121 +EXTERNAL=122 +SUSPEND=123 +OVERRIDE=124 +ABSTRACT=125 +FINAL=126 +OPEN=127 +CONST=128 +LATEINIT=129 +VARARG=130 +NOINLINE=131 +CROSSINLINE=132 +REIFIED=133 +EXPECT=134 +ACTUAL=135 +RealLiteral=136 +FloatLiteral=137 +DoubleLiteral=138 +IntegerLiteral=139 +HexLiteral=140 +BinLiteral=141 +UnsignedLiteral=142 +LongLiteral=143 +BooleanLiteral=144 +NullLiteral=145 +CharacterLiteral=146 +Identifier=147 +IdentifierOrSoftKey=148 +FieldIdentifier=149 +QUOTE_OPEN=150 +TRIPLE_QUOTE_OPEN=151 +UNICODE_CLASS_LL=152 +UNICODE_CLASS_LM=153 +UNICODE_CLASS_LO=154 +UNICODE_CLASS_LT=155 +UNICODE_CLASS_LU=156 +UNICODE_CLASS_ND=157 +UNICODE_CLASS_NL=158 +QUOTE_CLOSE=159 +LineStrRef=160 +LineStrText=161 +LineStrEscapedChar=162 +LineStrExprStart=163 +TRIPLE_QUOTE_CLOSE=164 +MultiLineStringQuote=165 +MultiLineStrRef=166 +MultiLineStrText=167 +MultiLineStrExprStart=168 +Inside_Comment=169 +Inside_WS=170 +Inside_NL=171 +ErrorCharacter=172 '...'=6 '.'=7 ','=8 @@ -214,77 +215,78 @@ ErrorCharacter=171 '=='=53 '==='=54 '\''=55 -'file'=61 -'field'=62 -'property'=63 -'get'=64 -'set'=65 -'receiver'=66 -'param'=67 -'setparam'=68 -'delegate'=69 -'package'=70 -'import'=71 -'class'=72 -'interface'=73 -'fun'=74 -'object'=75 -'val'=76 -'var'=77 -'typealias'=78 -'constructor'=79 -'by'=80 -'companion'=81 -'init'=82 -'this'=83 -'super'=84 -'typeof'=85 -'where'=86 -'if'=87 -'else'=88 -'when'=89 -'try'=90 -'catch'=91 -'finally'=92 -'for'=93 -'do'=94 -'while'=95 -'throw'=96 -'return'=97 -'continue'=98 -'break'=99 -'as'=100 -'is'=101 -'in'=102 -'out'=105 -'dynamic'=106 -'public'=107 -'private'=108 -'protected'=109 -'internal'=110 -'enum'=111 -'sealed'=112 -'annotation'=113 -'data'=114 -'inner'=115 -'value'=116 -'tailrec'=117 -'operator'=118 -'inline'=119 -'infix'=120 -'external'=121 -'suspend'=122 -'override'=123 -'abstract'=124 -'final'=125 -'open'=126 -'const'=127 -'lateinit'=128 -'vararg'=129 -'noinline'=130 -'crossinline'=131 -'reified'=132 -'expect'=133 -'actual'=134 -'null'=144 -'"""'=150 +'&'=56 +'file'=62 +'field'=63 +'property'=64 +'get'=65 +'set'=66 +'receiver'=67 +'param'=68 +'setparam'=69 +'delegate'=70 +'package'=71 +'import'=72 +'class'=73 +'interface'=74 +'fun'=75 +'object'=76 +'val'=77 +'var'=78 +'typealias'=79 +'constructor'=80 +'by'=81 +'companion'=82 +'init'=83 +'this'=84 +'super'=85 +'typeof'=86 +'where'=87 +'if'=88 +'else'=89 +'when'=90 +'try'=91 +'catch'=92 +'finally'=93 +'for'=94 +'do'=95 +'while'=96 +'throw'=97 +'return'=98 +'continue'=99 +'break'=100 +'as'=101 +'is'=102 +'in'=103 +'out'=106 +'dynamic'=107 +'public'=108 +'private'=109 +'protected'=110 +'internal'=111 +'enum'=112 +'sealed'=113 +'annotation'=114 +'data'=115 +'inner'=116 +'value'=117 +'tailrec'=118 +'operator'=119 +'inline'=120 +'infix'=121 +'external'=122 +'suspend'=123 +'override'=124 +'abstract'=125 +'final'=126 +'open'=127 +'const'=128 +'lateinit'=129 +'vararg'=130 +'noinline'=131 +'crossinline'=132 +'reified'=133 +'expect'=134 +'actual'=135 +'null'=145 +'"""'=151 diff --git a/pmd-kotlin/src/main/antlr4/net/sourceforge/pmd/lang/kotlin/ast/README.md b/pmd-kotlin/src/main/antlr4/net/sourceforge/pmd/lang/kotlin/ast/README.md index 84ef104798..20361f9a64 100644 --- a/pmd-kotlin/src/main/antlr4/net/sourceforge/pmd/lang/kotlin/ast/README.md +++ b/pmd-kotlin/src/main/antlr4/net/sourceforge/pmd/lang/kotlin/ast/README.md @@ -24,8 +24,8 @@ All other files in this PMD module are licensed under BSD. ## Currently used version -* Release: -* Source: +* Release: +* Source: ### Modifications diff --git a/pmd-kotlin/src/main/antlr4/net/sourceforge/pmd/lang/kotlin/ast/UnicodeClasses.g4 b/pmd-kotlin/src/main/antlr4/net/sourceforge/pmd/lang/kotlin/ast/UnicodeClasses.g4 index 71a0b720ae..5a882ef8c1 100644 --- a/pmd-kotlin/src/main/antlr4/net/sourceforge/pmd/lang/kotlin/ast/UnicodeClasses.g4 +++ b/pmd-kotlin/src/main/antlr4/net/sourceforge/pmd/lang/kotlin/ast/UnicodeClasses.g4 @@ -1647,4 +1647,4 @@ UNICODE_CLASS_NL: '\u3007' | '\u3021'..'\u3029' | '\u3038'..'\u303A' | - '\uA6E6'..'\uA6EF'; \ No newline at end of file + '\uA6E6'..'\uA6EF'; diff --git a/pmd-kotlin/src/main/java/net/sourceforge/pmd/lang/kotlin/KotlinLanguageModule.java b/pmd-kotlin/src/main/java/net/sourceforge/pmd/lang/kotlin/KotlinLanguageModule.java index 6faf72c06b..0d66084d18 100644 --- a/pmd-kotlin/src/main/java/net/sourceforge/pmd/lang/kotlin/KotlinLanguageModule.java +++ b/pmd-kotlin/src/main/java/net/sourceforge/pmd/lang/kotlin/KotlinLanguageModule.java @@ -35,7 +35,8 @@ public class KotlinLanguageModule extends SimpleLanguageModuleBase { super(LanguageMetadata.withId(TERSE_NAME).name(NAME) .extensions(EXTENSIONS) .addVersion("1.6") - .addDefaultVersion("1.7"), + .addVersion("1.7") + .addDefaultVersion("1.8"), new KotlinHandler()); } } diff --git a/pmd-kotlin/src/test/java/net/sourceforge/pmd/lang/kotlin/LanguageVersionTest.java b/pmd-kotlin/src/test/java/net/sourceforge/pmd/lang/kotlin/LanguageVersionTest.java index 5a6956aa8e..ca5c9920f1 100644 --- a/pmd-kotlin/src/test/java/net/sourceforge/pmd/lang/kotlin/LanguageVersionTest.java +++ b/pmd-kotlin/src/test/java/net/sourceforge/pmd/lang/kotlin/LanguageVersionTest.java @@ -13,7 +13,7 @@ class LanguageVersionTest extends AbstractLanguageVersionTest { static Collection data() { return Arrays.asList( - new TestDescriptor(KotlinLanguageModule.NAME, KotlinLanguageModule.TERSE_NAME, "1.7", + new TestDescriptor(KotlinLanguageModule.NAME, KotlinLanguageModule.TERSE_NAME, "1.8", getLanguage(KotlinLanguageModule.NAME).getDefaultVersion())); } }