From 1fda7a07820b0a7efb80d374ee9a5904b580391e Mon Sep 17 00:00:00 2001 From: jborgers Date: Tue, 7 Sep 2021 16:17:58 +0200 Subject: [PATCH 001/198] Adding PMD support for a new ANTLR grammar based language - step 1-4 --- pmd-kotlin/pom.xml | 6 +++ .../pmd/lang/kotlin/ast/KotlinErrorNode.java | 16 ++++++++ .../pmd/lang/kotlin/ast/KotlinInnerNode.java | 41 +++++++++++++++++++ .../pmd/lang/kotlin/ast/KotlinNode.java | 8 ++++ .../pmd/lang/kotlin/ast/KotlinRootNode.java | 33 +++++++++++++++ .../lang/kotlin/ast/KotlinTerminalNode.java | 29 +++++++++++++ 6 files changed, 133 insertions(+) create mode 100644 pmd-kotlin/src/main/java/net/sourceforge/pmd/lang/kotlin/ast/KotlinErrorNode.java create mode 100644 pmd-kotlin/src/main/java/net/sourceforge/pmd/lang/kotlin/ast/KotlinInnerNode.java create mode 100644 pmd-kotlin/src/main/java/net/sourceforge/pmd/lang/kotlin/ast/KotlinNode.java create mode 100644 pmd-kotlin/src/main/java/net/sourceforge/pmd/lang/kotlin/ast/KotlinRootNode.java create mode 100644 pmd-kotlin/src/main/java/net/sourceforge/pmd/lang/kotlin/ast/KotlinTerminalNode.java diff --git a/pmd-kotlin/pom.xml b/pmd-kotlin/pom.xml index cc2edc2f2b..7a61b85e2b 100644 --- a/pmd-kotlin/pom.xml +++ b/pmd-kotlin/pom.xml @@ -11,6 +11,10 @@ ../ + + true + + @@ -32,6 +36,8 @@ + + diff --git a/pmd-kotlin/src/main/java/net/sourceforge/pmd/lang/kotlin/ast/KotlinErrorNode.java b/pmd-kotlin/src/main/java/net/sourceforge/pmd/lang/kotlin/ast/KotlinErrorNode.java new file mode 100644 index 0000000000..82ddedf524 --- /dev/null +++ b/pmd-kotlin/src/main/java/net/sourceforge/pmd/lang/kotlin/ast/KotlinErrorNode.java @@ -0,0 +1,16 @@ +/* + * BSD-style license; for more info see http://pmd.sourceforge.net/license.html + */ + +package net.sourceforge.pmd.lang.kotlin.ast; + +import net.sourceforge.pmd.lang.ast.impl.antlr4.BaseAntlrErrorNode; +import org.antlr.v4.runtime.Token; + +public final class KotlinErrorNode extends BaseAntlrErrorNode implements KotlinNode { + + KotlinErrorNode(Token token) { + super(token); + } + +} diff --git a/pmd-kotlin/src/main/java/net/sourceforge/pmd/lang/kotlin/ast/KotlinInnerNode.java b/pmd-kotlin/src/main/java/net/sourceforge/pmd/lang/kotlin/ast/KotlinInnerNode.java new file mode 100644 index 0000000000..578cf4e9ab --- /dev/null +++ b/pmd-kotlin/src/main/java/net/sourceforge/pmd/lang/kotlin/ast/KotlinInnerNode.java @@ -0,0 +1,41 @@ +/* + * BSD-style license; for more info see http://pmd.sourceforge.net/license.html + */ + +package net.sourceforge.pmd.lang.kotlin.ast; + +import net.sourceforge.pmd.lang.ast.AstVisitor; +import net.sourceforge.pmd.lang.ast.impl.antlr4.BaseAntlrInnerNode; +import org.antlr.v4.runtime.ParserRuleContext; + +public abstract class KotlinInnerNode + extends BaseAntlrInnerNode implements KotlinNode { + + KotlinInnerNode() { + super(); + } + + KotlinInnerNode(ParserRuleContext parent, int invokingStateNumber) { + super(parent, invokingStateNumber); + } + + @Override + public R acceptVisitor(AstVisitor visitor, P data) { + if (visitor instanceof KotlinVisitor) { + // some of the generated antlr nodes have no accept method... + return ((KotlinVisitor) visitor).visitKotlinNode(this, data); + } + return visitor.visitNode(this, data); + } + + + @Override // override to make visible in package + protected PmdAsAntlrInnerNode asAntlrNode() { + return super.asAntlrNode(); + } + + @Override + public String getXPathNodeName() { + return KotlinParser.DICO.getXPathNameOfRule(getRuleIndex()); + } +} diff --git a/pmd-kotlin/src/main/java/net/sourceforge/pmd/lang/kotlin/ast/KotlinNode.java b/pmd-kotlin/src/main/java/net/sourceforge/pmd/lang/kotlin/ast/KotlinNode.java new file mode 100644 index 0000000000..1d933a829a --- /dev/null +++ b/pmd-kotlin/src/main/java/net/sourceforge/pmd/lang/kotlin/ast/KotlinNode.java @@ -0,0 +1,8 @@ +package net.sourceforge.pmd.lang.kotlin.ast; +import net.sourceforge.pmd.lang.ast.impl.antlr4.AntlrNode; + +/** + * Supertype of all kotlin nodes. + */ +public interface KotlinNode extends AntlrNode { +} diff --git a/pmd-kotlin/src/main/java/net/sourceforge/pmd/lang/kotlin/ast/KotlinRootNode.java b/pmd-kotlin/src/main/java/net/sourceforge/pmd/lang/kotlin/ast/KotlinRootNode.java new file mode 100644 index 0000000000..3e2fd8f04e --- /dev/null +++ b/pmd-kotlin/src/main/java/net/sourceforge/pmd/lang/kotlin/ast/KotlinRootNode.java @@ -0,0 +1,33 @@ +/* + * BSD-style license; for more info see http://pmd.sourceforge.net/license.html + */ + +package net.sourceforge.pmd.lang.kotlin.ast; + +import net.sourceforge.pmd.lang.ast.AstInfo; +import net.sourceforge.pmd.lang.ast.Parser.ParserTask; +import net.sourceforge.pmd.lang.ast.RootNode; +import net.sourceforge.pmd.lang.kotlin.ast.KotlinParser.KtTopLevel; +import org.antlr.v4.runtime.ParserRuleContext; + +// package private base class +abstract class KotlinRootNode extends KotlinInnerNode implements RootNode { + + private AstInfo astInfo; + + KotlinRootNode(ParserRuleContext parent, int invokingStateNumber) { + super(parent, invokingStateNumber); + } + + @Override + public AstInfo getAstInfo() { + return astInfo; + } + + KtTopLevel makeAstInfo(ParserTask task) { + KtTopLevel me = (KtTopLevel) this; + this.astInfo = new AstInfo<>(task, me); + return me; + } + +} diff --git a/pmd-kotlin/src/main/java/net/sourceforge/pmd/lang/kotlin/ast/KotlinTerminalNode.java b/pmd-kotlin/src/main/java/net/sourceforge/pmd/lang/kotlin/ast/KotlinTerminalNode.java new file mode 100644 index 0000000000..6da6718116 --- /dev/null +++ b/pmd-kotlin/src/main/java/net/sourceforge/pmd/lang/kotlin/ast/KotlinTerminalNode.java @@ -0,0 +1,29 @@ +/* + * BSD-style license; for more info see http://pmd.sourceforge.net/license.html + */ + +package net.sourceforge.pmd.lang.kotlin.ast; + +import net.sourceforge.pmd.lang.ast.impl.antlr4.BaseAntlrTerminalNode; +import org.antlr.v4.runtime.Token; +import org.checkerframework.checker.nullness.qual.NonNull; + +public final class KotlinTerminalNode extends BaseAntlrTerminalNode implements KotlinNode { + + KotlinTerminalNode(Token token) { + super(token); + } + + @Override + public @NonNull String getText() { + String constImage = KotlinParser.DICO.getConstantImageOfToken(getFirstAntlrToken()); + return constImage == null ? getFirstAntlrToken().getText() + : constImage; + } + + @Override + public String getXPathNodeName() { + return KotlinParser.DICO.getXPathNameOfToken(getFirstAntlrToken().getType()); + } + +} From 01eacda5a6caeb778782c32357c38c3c3d57b1bd Mon Sep 17 00:00:00 2001 From: Andreas Dangel Date: Tue, 7 Sep 2021 19:14:43 +0200 Subject: [PATCH 002/198] [doc] Fix typo with mvn generate-sources --- .../major_contributions/adding_a_new_antlr_based_language.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/pages/pmd/devdocs/major_contributions/adding_a_new_antlr_based_language.md b/docs/pages/pmd/devdocs/major_contributions/adding_a_new_antlr_based_language.md index 7f156054d7..babf8b5812 100644 --- a/docs/pages/pmd/devdocs/major_contributions/adding_a_new_antlr_based_language.md +++ b/docs/pages/pmd/devdocs/major_contributions/adding_a_new_antlr_based_language.md @@ -52,7 +52,7 @@ folder: pmd/devdocs ## 4. Generate your parser * Make sure, you have the property `true` in your `pom.xml` file. * This is just a matter of building the language module. ANTLR is called via ant, and this step is added - to the phase `generate-sources`. So you can just call e.g. `./mvnw generate-source -pl pmd-swift` to + to the phase `generate-sources`. So you can just call e.g. `./mvnw generate-sources -pl pmd-swift` to have the parser generated. * The generated code will be placed under `target/generated-sources/antlr4` and will not be committed to source control. From 2780560b365b56ee9426be39df587e22ea5ee9aa Mon Sep 17 00:00:00 2001 From: jborgers Date: Wed, 8 Sep 2021 18:37:00 +0200 Subject: [PATCH 003/198] Add official Kotlin ANTLR grammar files, copy and rename some more from Swift --- pmd-kotlin/pom.xml | 2 +- .../pmd/lang/kotlin/ast/KotlinLexer.g4 | 850 ++++----- .../pmd/lang/kotlin/ast/KotlinLexer.tokens | 290 +++ .../pmd/lang/kotlin/ast/KotlinParser.g4 | 923 +++++++++ .../pmd/lang/kotlin/ast/UnicodeClasses.g4 | 1649 +++++++++++++++++ .../pmd/lang/kotlin/ast/UnicodeClasses.tokens | 7 + .../net.sourceforge.pmd.lang.Language | 1 + .../category/kotlin/categories.properties | 19 + 8 files changed, 3283 insertions(+), 458 deletions(-) mode change 100644 => 100755 pmd-kotlin/src/main/antlr4/net/sourceforge/pmd/lang/kotlin/ast/KotlinLexer.g4 create mode 100644 pmd-kotlin/src/main/antlr4/net/sourceforge/pmd/lang/kotlin/ast/KotlinLexer.tokens create mode 100644 pmd-kotlin/src/main/antlr4/net/sourceforge/pmd/lang/kotlin/ast/KotlinParser.g4 create mode 100644 pmd-kotlin/src/main/antlr4/net/sourceforge/pmd/lang/kotlin/ast/UnicodeClasses.g4 create mode 100644 pmd-kotlin/src/main/antlr4/net/sourceforge/pmd/lang/kotlin/ast/UnicodeClasses.tokens create mode 100644 pmd-kotlin/src/main/resources/META-INF/services/net.sourceforge.pmd.lang.Language create mode 100644 pmd-kotlin/src/main/resources/category/kotlin/categories.properties diff --git a/pmd-kotlin/pom.xml b/pmd-kotlin/pom.xml index 7a61b85e2b..c1b3e36220 100644 --- a/pmd-kotlin/pom.xml +++ b/pmd-kotlin/pom.xml @@ -33,7 +33,7 @@ - + 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 old mode 100644 new mode 100755 index c790e314f1..9b401e934a --- 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 @@ -1,22 +1,11 @@ /** - * Kotlin Grammar for ANTLR v4 - * - * Based on: - * http://jetbrains.github.io/kotlin-spec/#_grammars_and_parsing - * and - * http://kotlinlang.org/docs/reference/grammar.html - * - * Tested on - * https://github.com/JetBrains/kotlin/tree/master/compiler/testData/psi + * Kotlin lexical grammar in ANTLR4 notation */ lexer grammar KotlinLexer; -/** - * Taken from http://www.antlr3.org/grammar/1345144569663/AntlrUnicode.txt - */ - -//lexer grammar UnicodeClasses; +//import UnicodeClasses; +// Taken from http://www.antlr3.org/grammar/1345144569663/AntlrUnicode.txt UNICODE_CLASS_LL: '\u0061'..'\u007A' | @@ -1660,9 +1649,10 @@ UNICODE_CLASS_NL: '\u3038'..'\u303A' | '\uA6E6'..'\uA6EF'; +// SECTION: lexicalGeneral + ShebangLine - : '#!' ~[\u000A\u000D]* - -> channel(HIDDEN) + : '#!' ~[\r\n]* ; DelimitedComment @@ -1671,154 +1661,176 @@ DelimitedComment ; LineComment - : '//' ~[\u000A\u000D]* + : '//' ~[\r\n]* -> channel(HIDDEN) ; WS : [\u0020\u0009\u000C] - -> skip + -> channel(HIDDEN) ; -NL: '\u000A' | '\u000D' '\u000A' ; +NL: '\n' | '\r' '\n'?; -//SEPARATORS & OPERATIONS +fragment Hidden: DelimitedComment | LineComment | WS; -RESERVED: '...' ; -DOT: '.' ; -COMMA: ',' ; -LPAREN: '(' -> pushMode(Inside) ; -RPAREN: ')' ; -LSQUARE: '[' -> pushMode(Inside) ; -RSQUARE: ']' ; -LCURL: '{' ; -RCURL: '}' ; -MULT: '*' ; -MOD: '%' ; -DIV: '/' ; -ADD: '+' ; -SUB: '-' ; -INCR: '++' ; -DECR: '--' ; -CONJ: '&&' ; -DISJ: '||' ; -EXCL: '!' ; -COLON: ':' ; -SEMICOLON: ';' ; -ASSIGNMENT: '=' ; -ADD_ASSIGNMENT: '+=' ; -SUB_ASSIGNMENT: '-=' ; -MULT_ASSIGNMENT: '*=' ; -DIV_ASSIGNMENT: '/=' ; -MOD_ASSIGNMENT: '%=' ; -ARROW: '->' ; -DOUBLE_ARROW: '=>' ; -RANGE: '..' ; -COLONCOLON: '::' ; -Q_COLONCOLON: '?::' ; -DOUBLE_SEMICOLON: ';;' ; -HASH: '#' ; -AT: '@' ; -QUEST: '?' ; -ELVIS: '?:' ; -LANGLE: '<' ; -RANGLE: '>' ; -LE: '<=' ; -GE: '>=' ; -EXCL_EQ: '!=' ; -EXCL_EQEQ: '!==' ; -AS_SAFE: 'as?' ; -EQEQ: '==' ; -EQEQEQ: '===' ; -SINGLE_QUOTE: '\'' ; +// SECTION: separatorsAndOperations -//KEYWORDS +RESERVED: '...'; +DOT: '.'; +COMMA: ','; +LPAREN: '(' -> pushMode(Inside); +RPAREN: ')'; +LSQUARE: '[' -> pushMode(Inside); +RSQUARE: ']'; +LCURL: '{' -> pushMode(DEFAULT_MODE); +/* + * When using another programming language (not Java) to generate a parser, + * please replace this code with the corresponding code of a programming language you are using. + */ +RCURL: '}' { if (!_modeStack.isEmpty()) { popMode(); } }; +MULT: '*'; +MOD: '%'; +DIV: '/'; +ADD: '+'; +SUB: '-'; +INCR: '++'; +DECR: '--'; +CONJ: '&&'; +DISJ: '||'; +EXCL_WS: '!' Hidden; +EXCL_NO_WS: '!'; +COLON: ':'; +SEMICOLON: ';'; +ASSIGNMENT: '='; +ADD_ASSIGNMENT: '+='; +SUB_ASSIGNMENT: '-='; +MULT_ASSIGNMENT: '*='; +DIV_ASSIGNMENT: '/='; +MOD_ASSIGNMENT: '%='; +ARROW: '->'; +DOUBLE_ARROW: '=>'; +RANGE: '..'; +COLONCOLON: '::'; +DOUBLE_SEMICOLON: ';;'; +HASH: '#'; +AT_NO_WS: '@'; +AT_POST_WS: '@' (Hidden | NL); +AT_PRE_WS: (Hidden | NL) '@' ; +AT_BOTH_WS: (Hidden | NL) '@' (Hidden | NL); +QUEST_WS: '?' Hidden; +QUEST_NO_WS: '?'; +LANGLE: '<'; +RANGLE: '>'; +LE: '<='; +GE: '>='; +EXCL_EQ: '!='; +EXCL_EQEQ: '!=='; +AS_SAFE: 'as?'; +EQEQ: '=='; +EQEQEQ: '==='; +SINGLE_QUOTE: '\''; -RETURN_AT: 'return@' Identifier ; -CONTINUE_AT: 'continue@' Identifier ; -BREAK_AT: 'break@' Identifier ; +// SECTION: keywords -FILE: '@file' ; -PACKAGE: 'package' ; -IMPORT: 'import' ; -CLASS: 'class' ; -INTERFACE: 'interface' ; -FUN: 'fun' ; -OBJECT: 'object' ; -VAL: 'val' ; -VAR: 'var' ; -TYPE_ALIAS: 'typealias' ; -CONSTRUCTOR: 'constructor' ; -BY: 'by' ; -COMPANION: 'companion' ; -INIT: 'init' ; -THIS: 'this' ; -SUPER: 'super' ; -TYPEOF: 'typeof' ; -WHERE: 'where' ; -IF: 'if' ; -ELSE: 'else' ; -WHEN: 'when' ; -TRY: 'try' ; -CATCH: 'catch' ; -FINALLY: 'finally' ; -FOR: 'for' ; -DO: 'do' ; -WHILE: 'while' ; -THROW: 'throw' ; -RETURN: 'return' ; -CONTINUE: 'continue' ; -BREAK: 'break' ; -AS: 'as' ; -IS: 'is' ; -IN: 'in' ; -NOT_IS: '!is' (WS | NL)+ ; -NOT_IN: '!in' (WS | NL)+ ; -OUT: 'out' ; -FIELD: '@field' ; -PROPERTY: '@property' ; -GET: '@get' ; -SET: '@set' ; -GETTER: 'get' ; -SETTER: 'set' ; -RECEIVER: '@receiver' ; -PARAM: '@param' ; -SETPARAM: '@setparam' ; -DELEGATE: '@delegate' ; -DYNAMIC: 'dynamic' ; +RETURN_AT: 'return@' Identifier; +CONTINUE_AT: 'continue@' Identifier; +BREAK_AT: 'break@' Identifier; -//MODIFIERS +THIS_AT: 'this@' Identifier; +SUPER_AT: 'super@' Identifier; -PUBLIC: 'public' ; -PRIVATE: 'private' ; -PROTECTED: 'protected' ; -INTERNAL: 'internal' ; -ENUM: 'enum' ; -SEALED: 'sealed' ; -ANNOTATION: 'annotation' ; -DATA: 'data' ; -INNER: 'inner' ; -TAILREC: 'tailrec' ; -OPERATOR: 'operator' ; -INLINE: 'inline' ; -INFIX: 'infix' ; -EXTERNAL: 'external' ; -SUSPEND: 'suspend' ; -OVERRIDE: 'override' ; -ABSTRACT: 'abstract' ; -FINAL: 'final' ; -OPEN: 'open' ; -CONST: 'const' ; -LATEINIT: 'lateinit' ; -VARARG: 'vararg' ; -NOINLINE: 'noinline' ; -CROSSINLINE: 'crossinline' ; -REIFIED: 'reified' ; +FILE: 'file'; +FIELD: 'field'; +PROPERTY: 'property'; +GET: 'get'; +SET: 'set'; +RECEIVER: 'receiver'; +PARAM: 'param'; +SETPARAM: 'setparam'; +DELEGATE: 'delegate'; -// +PACKAGE: 'package'; +IMPORT: 'import'; +CLASS: 'class'; +INTERFACE: 'interface'; +FUN: 'fun'; +OBJECT: 'object'; +VAL: 'val'; +VAR: 'var'; +TYPE_ALIAS: 'typealias'; +CONSTRUCTOR: 'constructor'; +BY: 'by'; +COMPANION: 'companion'; +INIT: 'init'; +THIS: 'this'; +SUPER: 'super'; +TYPEOF: 'typeof'; +WHERE: 'where'; +IF: 'if'; +ELSE: 'else'; +WHEN: 'when'; +TRY: 'try'; +CATCH: 'catch'; +FINALLY: 'finally'; +FOR: 'for'; +DO: 'do'; +WHILE: 'while'; +THROW: 'throw'; +RETURN: 'return'; +CONTINUE: 'continue'; +BREAK: 'break'; +AS: 'as'; +IS: 'is'; +IN: 'in'; +NOT_IS: '!is' (Hidden | NL); +NOT_IN: '!in' (Hidden | NL); +OUT: 'out'; +DYNAMIC: 'dynamic'; -QUOTE_OPEN: '"' -> pushMode(LineString) ; -TRIPLE_QUOTE_OPEN: '"""' -> pushMode(MultiLineString) ; +// SECTION: lexicalModifiers + +PUBLIC: 'public'; +PRIVATE: 'private'; +PROTECTED: 'protected'; +INTERNAL: 'internal'; +ENUM: 'enum'; +SEALED: 'sealed'; +ANNOTATION: 'annotation'; +DATA: 'data'; +INNER: 'inner'; +VALUE: 'value'; +TAILREC: 'tailrec'; +OPERATOR: 'operator'; +INLINE: 'inline'; +INFIX: 'infix'; +EXTERNAL: 'external'; +SUSPEND: 'suspend'; +OVERRIDE: 'override'; +ABSTRACT: 'abstract'; +FINAL: 'final'; +OPEN: 'open'; +CONST: 'const'; +LATEINIT: 'lateinit'; +VARARG: 'vararg'; +NOINLINE: 'noinline'; +CROSSINLINE: 'crossinline'; +REIFIED: 'reified'; +EXPECT: 'expect'; +ACTUAL: 'actual'; + +// SECTION: literals + +fragment DecDigit: '0'..'9'; +fragment DecDigitNoZero: '1'..'9'; +fragment DecDigitOrSeparator: DecDigit | '_'; + +fragment DecDigits + : DecDigit DecDigitOrSeparator* DecDigit + | DecDigit + ; + +fragment DoubleExponent: [eE] [+-]? DecDigits; RealLiteral : FloatLiteral @@ -1826,133 +1838,116 @@ RealLiteral ; FloatLiteral - : (DoubleLiteral | IntegerLiteral) [fF] + : DoubleLiteral [fF] + | DecDigits [fF] ; DoubleLiteral - : ( (DecDigitNoZero DecDigit*)? '.' - | (DecDigitNoZero (DecDigit | '_')* DecDigit)? '.') - ( DecDigit+ - | DecDigit (DecDigit | '_')+ DecDigit - | DecDigit+ [eE] ('+' | '-')? DecDigit+ - | DecDigit+ [eE] ('+' | '-')? DecDigit (DecDigit | '_')+ DecDigit - | DecDigit (DecDigit | '_')+ DecDigit [eE] ('+' | '-')? DecDigit+ - | DecDigit (DecDigit | '_')+ DecDigit [eE] ('+' | '-')? DecDigit (DecDigit | '_')+ DecDigit - ) - ; - -LongLiteral - : (IntegerLiteral | HexLiteral | BinLiteral) 'L' + : DecDigits? '.' DecDigits DoubleExponent? + | DecDigits DoubleExponent ; IntegerLiteral - : ('0' - | DecDigitNoZero DecDigit* - | DecDigitNoZero (DecDigit | '_')+ DecDigit - | DecDigitNoZero DecDigit* [eE] ('+' | '-')? DecDigit+ - | DecDigitNoZero DecDigit* [eE] ('+' | '-')? DecDigit (DecDigit | '_')+ DecDigit - | DecDigitNoZero (DecDigit | '_')+ DecDigit [eE] ('+' | '-')? DecDigit+ - | DecDigitNoZero (DecDigit | '_')+ DecDigit [eE] ('+' | '-')? DecDigit (DecDigit | '_')+ DecDigit - ) + : DecDigitNoZero DecDigitOrSeparator* DecDigit + | DecDigit ; -fragment DecDigit - : UNICODE_CLASS_ND - ; - -fragment DecDigitNoZero - : UNICODE_CLASS_ND_NoZeros - ; - -fragment UNICODE_CLASS_ND_NoZeros - : '\u0031'..'\u0039' - | '\u0661'..'\u0669' - | '\u06f1'..'\u06f9' - | '\u07c1'..'\u07c9' - | '\u0967'..'\u096f' - | '\u09e7'..'\u09ef' - | '\u0a67'..'\u0a6f' - | '\u0ae7'..'\u0aef' - | '\u0b67'..'\u0b6f' - | '\u0be7'..'\u0bef' - | '\u0c67'..'\u0c6f' - | '\u0ce7'..'\u0cef' - | '\u0d67'..'\u0d6f' - | '\u0de7'..'\u0def' - | '\u0e51'..'\u0e59' - | '\u0ed1'..'\u0ed9' - | '\u0f21'..'\u0f29' - | '\u1041'..'\u1049' - | '\u1091'..'\u1099' - | '\u17e1'..'\u17e9' - | '\u1811'..'\u1819' - | '\u1947'..'\u194f' - | '\u19d1'..'\u19d9' - | '\u1a81'..'\u1a89' - | '\u1a91'..'\u1a99' - | '\u1b51'..'\u1b59' - | '\u1bb1'..'\u1bb9' - | '\u1c41'..'\u1c49' - | '\u1c51'..'\u1c59' - | '\ua621'..'\ua629' - | '\ua8d1'..'\ua8d9' - | '\ua901'..'\ua909' - | '\ua9d1'..'\ua9d9' - | '\ua9f1'..'\ua9f9' - | '\uaa51'..'\uaa59' - | '\uabf1'..'\uabf9' - | '\uff11'..'\uff19' - ; +fragment HexDigit: [0-9a-fA-F]; +fragment HexDigitOrSeparator: HexDigit | '_'; HexLiteral - : '0' [xX] HexDigit (HexDigit | '_')* + : '0' [xX] HexDigit HexDigitOrSeparator* HexDigit + | '0' [xX] HexDigit ; -fragment HexDigit - : [0-9a-fA-F] - ; +fragment BinDigit: [01]; +fragment BinDigitOrSeparator: BinDigit | '_'; BinLiteral - : '0' [bB] BinDigit (BinDigit | '_')* + : '0' [bB] BinDigit BinDigitOrSeparator* BinDigit + | '0' [bB] BinDigit ; -fragment BinDigit - : [01] +UnsignedLiteral + : (IntegerLiteral | HexLiteral | BinLiteral) [uU] [lL]? ; -BooleanLiteral - : 'true' - | 'false' +LongLiteral + : (IntegerLiteral | HexLiteral | BinLiteral) [lL] ; -NullLiteral - : 'null' +BooleanLiteral: 'true'| 'false'; + +NullLiteral: 'null'; + +CharacterLiteral + : '\'' (EscapeSeq | ~[\n\r'\\]) '\'' ; +// SECTION: lexicalIdentifiers + +fragment UnicodeDigit: UNICODE_CLASS_ND; + Identifier - : (Letter | '_') (Letter | '_' | DecDigit)* - | '`' ~('`')+ '`' + : (Letter | '_') (Letter | '_' | UnicodeDigit)* + | '`' ~([\r\n] | '`')+ '`' ; -LabelReference - : '@' Identifier - ; - -LabelDefinition - : Identifier '@' +IdentifierOrSoftKey + : Identifier + /* Soft keywords */ + | ABSTRACT + | ANNOTATION + | BY + | CATCH + | COMPANION + | CONSTRUCTOR + | CROSSINLINE + | DATA + | DYNAMIC + | ENUM + | EXTERNAL + | FINAL + | FINALLY + | IMPORT + | INFIX + | INIT + | INLINE + | INNER + | INTERNAL + | LATEINIT + | NOINLINE + | OPEN + | OPERATOR + | OUT + | OVERRIDE + | PRIVATE + | PROTECTED + | PUBLIC + | REIFIED + | SEALED + | TAILREC + | VARARG + | WHERE + | GET + | SET + | FIELD + | PROPERTY + | RECEIVER + | PARAM + | SETPARAM + | DELEGATE + | FILE + | EXPECT + | ACTUAL + | VALUE + /* Strong keywords */ + | CONST + | SUSPEND ; FieldIdentifier - : '$' Identifier - ; - -CharacterLiteral - : '\'' (EscapeSeq | .) '\'' - ; - -fragment EscapeSeq - : UniCharacterLiteral - | EscapedIdentifier + : '$' IdentifierOrSoftKey ; fragment UniCharacterLiteral @@ -1963,6 +1958,13 @@ fragment EscapedIdentifier : '\\' ('t' | 'b' | 'r' | 'n' | '\'' | '"' | '\\' | '$') ; +fragment EscapeSeq + : UniCharacterLiteral + | EscapedIdentifier + ; + +// SECTION: characters + fragment Letter : UNICODE_CLASS_LL | UNICODE_CLASS_LM @@ -1972,140 +1974,13 @@ fragment Letter | UNICODE_CLASS_NL ; +// SECTION: strings -mode Inside ; +QUOTE_OPEN: '"' -> pushMode(LineString); -Inside_RPAREN: ')' -> popMode, type(RPAREN) ; -Inside_RSQUARE: ']' -> popMode, type(RSQUARE); +TRIPLE_QUOTE_OPEN: '"""' -> pushMode(MultiLineString); -Inside_LPAREN: LPAREN -> pushMode(Inside), type(LPAREN) ; -Inside_LSQUARE: LSQUARE -> pushMode(Inside), type(LSQUARE) ; - -Inside_LCURL: LCURL -> type(LCURL) ; -Inside_RCURL: RCURL -> type(RCURL) ; -Inside_DOT: DOT -> type(DOT) ; -Inside_COMMA: COMMA -> type(COMMA) ; -Inside_MULT: MULT -> type(MULT) ; -Inside_MOD: MOD -> type(MOD) ; -Inside_DIV: DIV -> type(DIV) ; -Inside_ADD: ADD -> type(ADD) ; -Inside_SUB: SUB -> type(SUB) ; -Inside_INCR: INCR -> type(INCR) ; -Inside_DECR: DECR -> type(DECR) ; -Inside_CONJ: CONJ -> type(CONJ) ; -Inside_DISJ: DISJ -> type(DISJ) ; -Inside_EXCL: EXCL -> type(EXCL) ; -Inside_COLON: COLON -> type(COLON) ; -Inside_SEMICOLON: SEMICOLON -> type(SEMICOLON) ; -Inside_ASSIGNMENT: ASSIGNMENT -> type(ASSIGNMENT) ; -Inside_ADD_ASSIGNMENT: ADD_ASSIGNMENT -> type(ADD_ASSIGNMENT) ; -Inside_SUB_ASSIGNMENT: SUB_ASSIGNMENT -> type(SUB_ASSIGNMENT) ; -Inside_MULT_ASSIGNMENT: MULT_ASSIGNMENT -> type(MULT_ASSIGNMENT) ; -Inside_DIV_ASSIGNMENT: DIV_ASSIGNMENT -> type(DIV_ASSIGNMENT) ; -Inside_MOD_ASSIGNMENT: MOD_ASSIGNMENT -> type(MOD_ASSIGNMENT) ; -Inside_ARROW: ARROW -> type(ARROW) ; -Inside_DOUBLE_ARROW: DOUBLE_ARROW -> type(DOUBLE_ARROW) ; -Inside_RANGE: RANGE -> type(RANGE) ; -Inside_RESERVED: RESERVED -> type(RESERVED) ; -Inside_COLONCOLON: COLONCOLON -> type(COLONCOLON) ; -Inside_Q_COLONCOLON: Q_COLONCOLON -> type(Q_COLONCOLON) ; -Inside_DOUBLE_SEMICOLON: DOUBLE_SEMICOLON -> type(DOUBLE_SEMICOLON) ; -Inside_HASH: HASH -> type(HASH) ; -Inside_AT: AT -> type(AT) ; -Inside_QUEST: QUEST -> type(QUEST) ; -Inside_ELVIS: ELVIS -> type(ELVIS) ; -Inside_LANGLE: LANGLE -> type(LANGLE) ; -Inside_RANGLE: RANGLE -> type(RANGLE) ; -Inside_LE: LE -> type(LE) ; -Inside_GE: GE -> type(GE) ; -Inside_EXCL_EQ: EXCL_EQ -> type(EXCL_EQ) ; -Inside_EXCL_EQEQ: EXCL_EQEQ -> type(EXCL_EQEQ) ; -Inside_NOT_IS: NOT_IS -> type(NOT_IS) ; -Inside_NOT_IN: NOT_IN -> type(NOT_IN) ; -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_QUOTE_OPEN: QUOTE_OPEN -> pushMode(LineString), type(QUOTE_OPEN) ; -Inside_TRIPLE_QUOTE_OPEN: TRIPLE_QUOTE_OPEN -> pushMode(MultiLineString), type(TRIPLE_QUOTE_OPEN) ; - -Inside_VAL: VAL -> type(VAL) ; -Inside_VAR: VAR -> type(VAR) ; -Inside_OBJECT: OBJECT -> type(OBJECT) ; -Inside_SUPER: SUPER -> type(SUPER) ; -Inside_IN: IN -> type(IN) ; -Inside_OUT: OUT -> type(OUT) ; -Inside_FIELD: FIELD -> type(FIELD) ; -Inside_FILE: FILE -> type(FILE) ; -Inside_PROPERTY: PROPERTY -> type(PROPERTY) ; -Inside_GET: GET -> type(GET) ; -Inside_SET: SET -> type(SET) ; -Inside_RECEIVER: RECEIVER -> type(RECEIVER) ; -Inside_PARAM: PARAM -> type(PARAM) ; -Inside_SETPARAM: SETPARAM -> type(SETPARAM) ; -Inside_DELEGATE: DELEGATE -> type(DELEGATE) ; -Inside_THROW: THROW -> type(THROW) ; -Inside_RETURN: RETURN -> type(RETURN) ; -Inside_CONTINUE: CONTINUE -> type(CONTINUE) ; -Inside_BREAK: BREAK -> type(BREAK) ; -Inside_RETURN_AT: RETURN_AT -> type(RETURN_AT) ; -Inside_CONTINUE_AT: CONTINUE_AT -> type(CONTINUE_AT) ; -Inside_BREAK_AT: BREAK_AT -> type(BREAK_AT) ; -Inside_IF: IF -> type(IF) ; -Inside_ELSE: ELSE -> type(ELSE) ; -Inside_WHEN: WHEN -> type(WHEN) ; -Inside_TRY: TRY -> type(TRY) ; -Inside_CATCH: CATCH -> type(CATCH) ; -Inside_FINALLY: FINALLY -> type(FINALLY) ; -Inside_FOR: FOR -> type(FOR) ; -Inside_DO: DO -> type(DO) ; -Inside_WHILE: WHILE -> type(WHILE) ; - -Inside_PUBLIC: PUBLIC -> type(PUBLIC) ; -Inside_PRIVATE: PRIVATE -> type(PRIVATE) ; -Inside_PROTECTED: PROTECTED -> type(PROTECTED) ; -Inside_INTERNAL: INTERNAL -> type(INTERNAL) ; -Inside_ENUM: ENUM -> type(ENUM) ; -Inside_SEALED: SEALED -> type(SEALED) ; -Inside_ANNOTATION: ANNOTATION -> type(ANNOTATION) ; -Inside_DATA: DATA -> type(DATA) ; -Inside_INNER: INNER -> type(INNER) ; -Inside_TAILREC: TAILREC -> type(TAILREC) ; -Inside_OPERATOR: OPERATOR -> type(OPERATOR) ; -Inside_INLINE: INLINE -> type(INLINE) ; -Inside_INFIX: INFIX -> type(INFIX) ; -Inside_EXTERNAL: EXTERNAL -> type(EXTERNAL) ; -Inside_SUSPEND: SUSPEND -> type(SUSPEND) ; -Inside_OVERRIDE: OVERRIDE -> type(OVERRIDE) ; -Inside_ABSTRACT: ABSTRACT -> type(ABSTRACT) ; -Inside_FINAL: FINAL -> type(FINAL) ; -Inside_OPEN: OPEN -> type(OPEN) ; -Inside_CONST: CONST -> type(CONST) ; -Inside_LATEINIT: LATEINIT -> type(LATEINIT) ; -Inside_VARARG: VARARG -> type(VARARG) ; -Inside_NOINLINE: NOINLINE -> type(NOINLINE) ; -Inside_CROSSINLINE: CROSSINLINE -> type(CROSSINLINE) ; -Inside_REIFIED: REIFIED -> type(REIFIED) ; - -Inside_BooleanLiteral: BooleanLiteral -> type(BooleanLiteral) ; -Inside_IntegerLiteral: IntegerLiteral -> type(IntegerLiteral) ; -Inside_HexLiteral: HexLiteral -> type(HexLiteral) ; -Inside_BinLiteral: BinLiteral -> type(BinLiteral) ; -Inside_CharacterLiteral: CharacterLiteral -> type(CharacterLiteral) ; -Inside_RealLiteral: RealLiteral -> type(RealLiteral) ; -Inside_NullLiteral: NullLiteral -> type(NullLiteral) ; - -Inside_LongLiteral: LongLiteral -> type(LongLiteral) ; - -Inside_Identifier: Identifier -> type(Identifier) ; -Inside_LabelReference: LabelReference -> type(LabelReference) ; -Inside_LabelDefinition: LabelDefinition -> type(LabelDefinition) ; -Inside_Comment: (LineComment | DelimitedComment) -> channel(HIDDEN) ; -Inside_WS: WS -> skip ; -Inside_NL: NL -> skip ; - - -mode LineString ; +mode LineString; QUOTE_CLOSE : '"' -> popMode @@ -2120,16 +1995,15 @@ LineStrText ; LineStrEscapedChar - : '\\' . + : EscapedIdentifier | UniCharacterLiteral ; LineStrExprStart - : '${' -> pushMode(StringExpression) + : '${' -> pushMode(DEFAULT_MODE) ; - -mode MultiLineString ; +mode MultiLineString; TRIPLE_QUOTE_CLOSE : MultiLineStringQuote? '"""' -> popMode @@ -2144,90 +2018,152 @@ MultiLineStrRef ; MultiLineStrText - : ~('\\' | '"' | '$')+ | '$' - ; - -MultiLineStrEscapedChar - : '\\' . + : ~('"' | '$')+ | '$' ; MultiLineStrExprStart - : '${' -> pushMode(StringExpression) + : '${' -> pushMode(DEFAULT_MODE) ; -MultiLineNL: NL -> skip ; +// SECTION: inside +mode Inside; -mode StringExpression ; +Inside_RPAREN: RPAREN -> popMode, type(RPAREN); +Inside_RSQUARE: RSQUARE -> popMode, type(RSQUARE); +Inside_LPAREN: LPAREN -> pushMode(Inside), type(LPAREN); +Inside_LSQUARE: LSQUARE -> pushMode(Inside), type(LSQUARE); +Inside_LCURL: LCURL -> pushMode(DEFAULT_MODE), type(LCURL); +Inside_RCURL: RCURL -> popMode, type(RCURL); -StrExpr_RCURL: RCURL -> popMode, type(RCURL) ; +Inside_DOT: DOT -> type(DOT); +Inside_COMMA: COMMA -> type(COMMA); +Inside_MULT: MULT -> type(MULT); +Inside_MOD: MOD -> type(MOD); +Inside_DIV: DIV -> type(DIV); +Inside_ADD: ADD -> type(ADD); +Inside_SUB: SUB -> type(SUB); +Inside_INCR: INCR -> type(INCR); +Inside_DECR: DECR -> type(DECR); +Inside_CONJ: CONJ -> type(CONJ); +Inside_DISJ: DISJ -> type(DISJ); +Inside_EXCL_WS: '!' (Hidden|NL) -> type(EXCL_WS); +Inside_EXCL_NO_WS: EXCL_NO_WS -> type(EXCL_NO_WS); +Inside_COLON: COLON -> type(COLON); +Inside_SEMICOLON: SEMICOLON -> type(SEMICOLON); +Inside_ASSIGNMENT: ASSIGNMENT -> type(ASSIGNMENT); +Inside_ADD_ASSIGNMENT: ADD_ASSIGNMENT -> type(ADD_ASSIGNMENT); +Inside_SUB_ASSIGNMENT: SUB_ASSIGNMENT -> type(SUB_ASSIGNMENT); +Inside_MULT_ASSIGNMENT: MULT_ASSIGNMENT -> type(MULT_ASSIGNMENT); +Inside_DIV_ASSIGNMENT: DIV_ASSIGNMENT -> type(DIV_ASSIGNMENT); +Inside_MOD_ASSIGNMENT: MOD_ASSIGNMENT -> type(MOD_ASSIGNMENT); +Inside_ARROW: ARROW -> type(ARROW); +Inside_DOUBLE_ARROW: DOUBLE_ARROW -> type(DOUBLE_ARROW); +Inside_RANGE: RANGE -> type(RANGE); +Inside_RESERVED: RESERVED -> type(RESERVED); +Inside_COLONCOLON: COLONCOLON -> type(COLONCOLON); +Inside_DOUBLE_SEMICOLON: DOUBLE_SEMICOLON -> type(DOUBLE_SEMICOLON); +Inside_HASH: HASH -> type(HASH); +Inside_AT_NO_WS: AT_NO_WS -> type(AT_NO_WS); +Inside_AT_POST_WS: AT_POST_WS -> type(AT_POST_WS); +Inside_AT_PRE_WS: AT_PRE_WS -> type(AT_PRE_WS); +Inside_AT_BOTH_WS: AT_BOTH_WS -> type(AT_BOTH_WS); +Inside_QUEST_WS: '?' (Hidden | NL) -> type(QUEST_WS); +Inside_QUEST_NO_WS: QUEST_NO_WS -> type(QUEST_NO_WS); +Inside_LANGLE: LANGLE -> type(LANGLE); +Inside_RANGLE: RANGLE -> type(RANGLE); +Inside_LE: LE -> type(LE); +Inside_GE: GE -> type(GE); +Inside_EXCL_EQ: EXCL_EQ -> type(EXCL_EQ); +Inside_EXCL_EQEQ: EXCL_EQEQ -> type(EXCL_EQEQ); +Inside_IS: IS -> type(IS); +Inside_NOT_IS: NOT_IS -> type(NOT_IS); +Inside_NOT_IN: NOT_IN -> type(NOT_IN); +Inside_AS: AS -> type(AS); +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_QUOTE_OPEN: QUOTE_OPEN -> pushMode(LineString), type(QUOTE_OPEN); +Inside_TRIPLE_QUOTE_OPEN: TRIPLE_QUOTE_OPEN -> pushMode(MultiLineString), type(TRIPLE_QUOTE_OPEN); -StrExpr_LPAREN: LPAREN -> pushMode(Inside), type(LPAREN) ; -StrExpr_LSQUARE: LSQUARE -> pushMode(Inside), type(LSQUARE) ; +Inside_VAL: VAL -> type(VAL); +Inside_VAR: VAR -> type(VAR); +Inside_FUN: FUN -> type(FUN); +Inside_OBJECT: OBJECT -> type(OBJECT); +Inside_SUPER: SUPER -> type(SUPER); +Inside_IN: IN -> type(IN); +Inside_OUT: OUT -> type(OUT); +Inside_FIELD: FIELD -> type(FIELD); +Inside_FILE: FILE -> type(FILE); +Inside_PROPERTY: PROPERTY -> type(PROPERTY); +Inside_GET: GET -> type(GET); +Inside_SET: SET -> type(SET); +Inside_RECEIVER: RECEIVER -> type(RECEIVER); +Inside_PARAM: PARAM -> type(PARAM); +Inside_SETPARAM: SETPARAM -> type(SETPARAM); +Inside_DELEGATE: DELEGATE -> type(DELEGATE); +Inside_THROW: THROW -> type(THROW); +Inside_RETURN: RETURN -> type(RETURN); +Inside_CONTINUE: CONTINUE -> type(CONTINUE); +Inside_BREAK: BREAK -> type(BREAK); +Inside_RETURN_AT: RETURN_AT -> type(RETURN_AT); +Inside_CONTINUE_AT: CONTINUE_AT -> type(CONTINUE_AT); +Inside_BREAK_AT: BREAK_AT -> type(BREAK_AT); +Inside_IF: IF -> type(IF); +Inside_ELSE: ELSE -> type(ELSE); +Inside_WHEN: WHEN -> type(WHEN); +Inside_TRY: TRY -> type(TRY); +Inside_CATCH: CATCH -> type(CATCH); +Inside_FINALLY: FINALLY -> type(FINALLY); +Inside_FOR: FOR -> type(FOR); +Inside_DO: DO -> type(DO); +Inside_WHILE: WHILE -> type(WHILE); -StrExpr_RPAREN: ')' -> type(RPAREN) ; -StrExpr_RSQUARE: ']' -> type(RSQUARE); -StrExpr_LCURL: LCURL -> pushMode(StringExpression), type(LCURL) ; -StrExpr_DOT: DOT -> type(DOT) ; -StrExpr_COMMA: COMMA -> type(COMMA) ; -StrExpr_MULT: MULT -> type(MULT) ; -StrExpr_MOD: MOD -> type(MOD) ; -StrExpr_DIV: DIV -> type(DIV) ; -StrExpr_ADD: ADD -> type(ADD) ; -StrExpr_SUB: SUB -> type(SUB) ; -StrExpr_INCR: INCR -> type(INCR) ; -StrExpr_DECR: DECR -> type(DECR) ; -StrExpr_CONJ: CONJ -> type(CONJ) ; -StrExpr_DISJ: DISJ -> type(DISJ) ; -StrExpr_EXCL: EXCL -> type(EXCL) ; -StrExpr_COLON: COLON -> type(COLON) ; -StrExpr_SEMICOLON: SEMICOLON -> type(SEMICOLON) ; -StrExpr_ASSIGNMENT: ASSIGNMENT -> type(ASSIGNMENT) ; -StrExpr_ADD_ASSIGNMENT: ADD_ASSIGNMENT -> type(ADD_ASSIGNMENT) ; -StrExpr_SUB_ASSIGNMENT: SUB_ASSIGNMENT -> type(SUB_ASSIGNMENT) ; -StrExpr_MULT_ASSIGNMENT: MULT_ASSIGNMENT -> type(MULT_ASSIGNMENT) ; -StrExpr_DIV_ASSIGNMENT: DIV_ASSIGNMENT -> type(DIV_ASSIGNMENT) ; -StrExpr_MOD_ASSIGNMENT: MOD_ASSIGNMENT -> type(MOD_ASSIGNMENT) ; -StrExpr_ARROW: ARROW -> type(ARROW) ; -StrExpr_DOUBLE_ARROW: DOUBLE_ARROW -> type(DOUBLE_ARROW) ; -StrExpr_RANGE: RANGE -> type(RANGE) ; -StrExpr_COLONCOLON: COLONCOLON -> type(COLONCOLON) ; -StrExpr_Q_COLONCOLON: Q_COLONCOLON -> type(Q_COLONCOLON) ; -StrExpr_DOUBLE_SEMICOLON: DOUBLE_SEMICOLON -> type(DOUBLE_SEMICOLON) ; -StrExpr_HASH: HASH -> type(HASH) ; -StrExpr_AT: AT -> type(AT) ; -StrExpr_QUEST: QUEST -> type(QUEST) ; -StrExpr_ELVIS: ELVIS -> type(ELVIS) ; -StrExpr_LANGLE: LANGLE -> type(LANGLE) ; -StrExpr_RANGLE: RANGLE -> type(RANGLE) ; -StrExpr_LE: LE -> type(LE) ; -StrExpr_GE: GE -> type(GE) ; -StrExpr_EXCL_EQ: EXCL_EQ -> type(EXCL_EQ) ; -StrExpr_EXCL_EQEQ: EXCL_EQEQ -> type(EXCL_EQEQ) ; -StrExpr_AS: AS -> type(IS) ; -StrExpr_IS: IS -> type(IN) ; -StrExpr_IN: IN ; -StrExpr_NOT_IS: NOT_IS -> type(NOT_IS) ; -StrExpr_NOT_IN: NOT_IN -> type(NOT_IN) ; -StrExpr_AS_SAFE: AS_SAFE -> type(AS_SAFE) ; -StrExpr_EQEQ: EQEQ -> type(EQEQ) ; -StrExpr_EQEQEQ: EQEQEQ -> type(EQEQEQ) ; -StrExpr_SINGLE_QUOTE: SINGLE_QUOTE -> type(SINGLE_QUOTE) ; -StrExpr_QUOTE_OPEN: QUOTE_OPEN -> pushMode(LineString), type(QUOTE_OPEN) ; -StrExpr_TRIPLE_QUOTE_OPEN: TRIPLE_QUOTE_OPEN -> pushMode(MultiLineString), type(TRIPLE_QUOTE_OPEN) ; +Inside_PUBLIC: PUBLIC -> type(PUBLIC); +Inside_PRIVATE: PRIVATE -> type(PRIVATE); +Inside_PROTECTED: PROTECTED -> type(PROTECTED); +Inside_INTERNAL: INTERNAL -> type(INTERNAL); +Inside_ENUM: ENUM -> type(ENUM); +Inside_SEALED: SEALED -> type(SEALED); +Inside_ANNOTATION: ANNOTATION -> type(ANNOTATION); +Inside_DATA: DATA -> type(DATA); +Inside_INNER: INNER -> type(INNER); +Inside_VALUE: VALUE -> type(VALUE); +Inside_TAILREC: TAILREC -> type(TAILREC); +Inside_OPERATOR: OPERATOR -> type(OPERATOR); +Inside_INLINE: INLINE -> type(INLINE); +Inside_INFIX: INFIX -> type(INFIX); +Inside_EXTERNAL: EXTERNAL -> type(EXTERNAL); +Inside_SUSPEND: SUSPEND -> type(SUSPEND); +Inside_OVERRIDE: OVERRIDE -> type(OVERRIDE); +Inside_ABSTRACT: ABSTRACT -> type(ABSTRACT); +Inside_FINAL: FINAL -> type(FINAL); +Inside_OPEN: OPEN -> type(OPEN); +Inside_CONST: CONST -> type(CONST); +Inside_LATEINIT: LATEINIT -> type(LATEINIT); +Inside_VARARG: VARARG -> type(VARARG); +Inside_NOINLINE: NOINLINE -> type(NOINLINE); +Inside_CROSSINLINE: CROSSINLINE -> type(CROSSINLINE); +Inside_REIFIED: REIFIED -> type(REIFIED); +Inside_EXPECT: EXPECT -> type(EXPECT); +Inside_ACTUAL: ACTUAL -> type(ACTUAL); -StrExpr_BooleanLiteral: BooleanLiteral -> type(BooleanLiteral) ; -StrExpr_IntegerLiteral: IntegerLiteral -> type(IntegerLiteral) ; -StrExpr_HexLiteral: HexLiteral -> type(HexLiteral) ; -StrExpr_BinLiteral: BinLiteral -> type(BinLiteral) ; -StrExpr_CharacterLiteral: CharacterLiteral -> type(CharacterLiteral) ; -StrExpr_RealLiteral: RealLiteral -> type(RealLiteral) ; -StrExpr_NullLiteral: NullLiteral -> type(NullLiteral) ; -StrExpr_LongLiteral: LongLiteral -> type(LongLiteral) ; +Inside_BooleanLiteral: BooleanLiteral -> type(BooleanLiteral); +Inside_IntegerLiteral: IntegerLiteral -> type(IntegerLiteral); +Inside_HexLiteral: HexLiteral -> type(HexLiteral); +Inside_BinLiteral: BinLiteral -> type(BinLiteral); +Inside_CharacterLiteral: CharacterLiteral -> type(CharacterLiteral); +Inside_RealLiteral: RealLiteral -> type(RealLiteral); +Inside_NullLiteral: NullLiteral -> type(NullLiteral); +Inside_LongLiteral: LongLiteral -> type(LongLiteral); +Inside_UnsignedLiteral: UnsignedLiteral -> type(UnsignedLiteral); -StrExpr_Identifier: Identifier -> type(Identifier) ; -StrExpr_LabelReference: LabelReference -> type(LabelReference) ; -StrExpr_LabelDefinition: LabelDefinition -> type(LabelDefinition) ; -StrExpr_Comment: (LineComment | DelimitedComment) -> channel(HIDDEN) ; -StrExpr_WS: WS -> skip ; -StrExpr_NL: NL -> skip ; +Inside_Identifier: Identifier -> type(Identifier); +Inside_Comment: (LineComment | DelimitedComment) -> channel(HIDDEN); +Inside_WS: WS -> channel(HIDDEN); +Inside_NL: NL -> channel(HIDDEN); + +mode DEFAULT_MODE; + +ErrorCharacter: .; 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 new file mode 100644 index 0000000000..df481370e5 --- /dev/null +++ b/pmd-kotlin/src/main/antlr4/net/sourceforge/pmd/lang/kotlin/ast/KotlinLexer.tokens @@ -0,0 +1,290 @@ +UNICODE_CLASS_LL=1 +UNICODE_CLASS_LM=2 +UNICODE_CLASS_LO=3 +UNICODE_CLASS_LT=4 +UNICODE_CLASS_LU=5 +UNICODE_CLASS_ND=6 +UNICODE_CLASS_NL=7 +ShebangLine=8 +DelimitedComment=9 +LineComment=10 +WS=11 +NL=12 +RESERVED=13 +DOT=14 +COMMA=15 +LPAREN=16 +RPAREN=17 +LSQUARE=18 +RSQUARE=19 +LCURL=20 +RCURL=21 +MULT=22 +MOD=23 +DIV=24 +ADD=25 +SUB=26 +INCR=27 +DECR=28 +CONJ=29 +DISJ=30 +EXCL_WS=31 +EXCL_NO_WS=32 +COLON=33 +SEMICOLON=34 +ASSIGNMENT=35 +ADD_ASSIGNMENT=36 +SUB_ASSIGNMENT=37 +MULT_ASSIGNMENT=38 +DIV_ASSIGNMENT=39 +MOD_ASSIGNMENT=40 +ARROW=41 +DOUBLE_ARROW=42 +RANGE=43 +COLONCOLON=44 +DOUBLE_SEMICOLON=45 +HASH=46 +AT_NO_WS=47 +AT_POST_WS=48 +AT_PRE_WS=49 +AT_BOTH_WS=50 +QUEST_WS=51 +QUEST_NO_WS=52 +LANGLE=53 +RANGLE=54 +LE=55 +GE=56 +EXCL_EQ=57 +EXCL_EQEQ=58 +AS_SAFE=59 +EQEQ=60 +EQEQEQ=61 +SINGLE_QUOTE=62 +RETURN_AT=63 +CONTINUE_AT=64 +BREAK_AT=65 +THIS_AT=66 +SUPER_AT=67 +FILE=68 +FIELD=69 +PROPERTY=70 +GET=71 +SET=72 +RECEIVER=73 +PARAM=74 +SETPARAM=75 +DELEGATE=76 +PACKAGE=77 +IMPORT=78 +CLASS=79 +INTERFACE=80 +FUN=81 +OBJECT=82 +VAL=83 +VAR=84 +TYPE_ALIAS=85 +CONSTRUCTOR=86 +BY=87 +COMPANION=88 +INIT=89 +THIS=90 +SUPER=91 +TYPEOF=92 +WHERE=93 +IF=94 +ELSE=95 +WHEN=96 +TRY=97 +CATCH=98 +FINALLY=99 +FOR=100 +DO=101 +WHILE=102 +THROW=103 +RETURN=104 +CONTINUE=105 +BREAK=106 +AS=107 +IS=108 +IN=109 +NOT_IS=110 +NOT_IN=111 +OUT=112 +DYNAMIC=113 +PUBLIC=114 +PRIVATE=115 +PROTECTED=116 +INTERNAL=117 +ENUM=118 +SEALED=119 +ANNOTATION=120 +DATA=121 +INNER=122 +VALUE=123 +TAILREC=124 +OPERATOR=125 +INLINE=126 +INFIX=127 +EXTERNAL=128 +SUSPEND=129 +OVERRIDE=130 +ABSTRACT=131 +FINAL=132 +OPEN=133 +CONST=134 +LATEINIT=135 +VARARG=136 +NOINLINE=137 +CROSSINLINE=138 +REIFIED=139 +EXPECT=140 +ACTUAL=141 +RealLiteral=142 +FloatLiteral=143 +DoubleLiteral=144 +IntegerLiteral=145 +HexLiteral=146 +BinLiteral=147 +UnsignedLiteral=148 +LongLiteral=149 +BooleanLiteral=150 +NullLiteral=151 +CharacterLiteral=152 +Identifier=153 +IdentifierOrSoftKey=154 +FieldIdentifier=155 +QUOTE_OPEN=156 +TRIPLE_QUOTE_OPEN=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 +'...'=13 +'.'=14 +','=15 +'('=16 +')'=17 +'['=18 +']'=19 +'{'=20 +'}'=21 +'*'=22 +'%'=23 +'/'=24 +'+'=25 +'-'=26 +'++'=27 +'--'=28 +'&&'=29 +'||'=30 +'!'=32 +':'=33 +';'=34 +'='=35 +'+='=36 +'-='=37 +'*='=38 +'/='=39 +'%='=40 +'->'=41 +'=>'=42 +'..'=43 +'::'=44 +';;'=45 +'#'=46 +'@'=47 +'?'=52 +'<'=53 +'>'=54 +'<='=55 +'>='=56 +'!='=57 +'!=='=58 +'as?'=59 +'=='=60 +'==='=61 +'\''=62 +'file'=68 +'field'=69 +'property'=70 +'get'=71 +'set'=72 +'receiver'=73 +'param'=74 +'setparam'=75 +'delegate'=76 +'package'=77 +'import'=78 +'class'=79 +'interface'=80 +'fun'=81 +'object'=82 +'val'=83 +'var'=84 +'typealias'=85 +'constructor'=86 +'by'=87 +'companion'=88 +'init'=89 +'this'=90 +'super'=91 +'typeof'=92 +'where'=93 +'if'=94 +'else'=95 +'when'=96 +'try'=97 +'catch'=98 +'finally'=99 +'for'=100 +'do'=101 +'while'=102 +'throw'=103 +'return'=104 +'continue'=105 +'break'=106 +'as'=107 +'is'=108 +'in'=109 +'out'=112 +'dynamic'=113 +'public'=114 +'private'=115 +'protected'=116 +'internal'=117 +'enum'=118 +'sealed'=119 +'annotation'=120 +'data'=121 +'inner'=122 +'value'=123 +'tailrec'=124 +'operator'=125 +'inline'=126 +'infix'=127 +'external'=128 +'suspend'=129 +'override'=130 +'abstract'=131 +'final'=132 +'open'=133 +'const'=134 +'lateinit'=135 +'vararg'=136 +'noinline'=137 +'crossinline'=138 +'reified'=139 +'expect'=140 +'actual'=141 +'null'=151 +'"""'=157 diff --git a/pmd-kotlin/src/main/antlr4/net/sourceforge/pmd/lang/kotlin/ast/KotlinParser.g4 b/pmd-kotlin/src/main/antlr4/net/sourceforge/pmd/lang/kotlin/ast/KotlinParser.g4 new file mode 100644 index 0000000000..628dbed387 --- /dev/null +++ b/pmd-kotlin/src/main/antlr4/net/sourceforge/pmd/lang/kotlin/ast/KotlinParser.g4 @@ -0,0 +1,923 @@ +/** + * Kotlin syntax grammar in ANTLR4 notation + */ + +parser grammar KotlinParser; + +options { tokenVocab = KotlinLexer; } + +// SECTION: general + +kotlinFile + : shebangLine? NL* fileAnnotation* packageHeader importList topLevelObject* EOF + ; + +script + : shebangLine? NL* fileAnnotation* packageHeader importList (statement semi)* EOF + ; + +shebangLine + : ShebangLine NL+ + ; + +fileAnnotation + : (AT_NO_WS | AT_PRE_WS) FILE NL* COLON NL* (LSQUARE unescapedAnnotation+ RSQUARE | unescapedAnnotation) NL* + ; + +packageHeader + : (PACKAGE identifier semi?)? + ; + +importList + : importHeader* + ; + +importHeader + : IMPORT identifier (DOT MULT | importAlias)? semi? + ; + +importAlias + : AS simpleIdentifier + ; + +topLevelObject + : declaration semis? + ; + +typeAlias + : modifiers? TYPE_ALIAS NL* simpleIdentifier (NL* typeParameters)? NL* ASSIGNMENT NL* type + ; + +declaration + : classDeclaration + | objectDeclaration + | functionDeclaration + | propertyDeclaration + | typeAlias + ; + +// SECTION: classes + +classDeclaration + : modifiers? (CLASS | (FUN NL*)? INTERFACE) NL* simpleIdentifier + (NL* typeParameters)? (NL* primaryConstructor)? + (NL* COLON NL* delegationSpecifiers)? + (NL* typeConstraints)? + (NL* classBody | NL* enumClassBody)? + ; + +primaryConstructor + : (modifiers? CONSTRUCTOR NL*)? classParameters + ; + +classBody + : LCURL NL* classMemberDeclarations NL* RCURL + ; + +classParameters + : LPAREN NL* (classParameter (NL* COMMA NL* classParameter)* (NL* COMMA)?)? NL* RPAREN + ; + +classParameter + : modifiers? (VAL | VAR)? NL* simpleIdentifier COLON NL* type (NL* ASSIGNMENT NL* expression)? + ; + +delegationSpecifiers + : annotatedDelegationSpecifier (NL* COMMA NL* annotatedDelegationSpecifier)* + ; + +delegationSpecifier + : constructorInvocation + | explicitDelegation + | userType + | functionType + ; + +constructorInvocation + : userType valueArguments + ; + +annotatedDelegationSpecifier + : annotation* NL* delegationSpecifier + ; + +explicitDelegation + : (userType | functionType) NL* BY NL* expression + ; + +typeParameters + : LANGLE NL* typeParameter (NL* COMMA NL* typeParameter)* (NL* COMMA)? NL* RANGLE + ; + +typeParameter + : typeParameterModifiers? NL* simpleIdentifier (NL* COLON NL* type)? + ; + +typeConstraints + : WHERE NL* typeConstraint (NL* COMMA NL* typeConstraint)* + ; + +typeConstraint + : annotation* simpleIdentifier NL* COLON NL* type + ; + +// SECTION: classMembers + +classMemberDeclarations + : (classMemberDeclaration semis?)* + ; + +classMemberDeclaration + : declaration + | companionObject + | anonymousInitializer + | secondaryConstructor + ; + +anonymousInitializer + : INIT NL* block + ; + +companionObject + : modifiers? COMPANION NL* OBJECT + (NL* simpleIdentifier)? + (NL* COLON NL* delegationSpecifiers)? + (NL* classBody)? + ; + +functionValueParameters + : LPAREN NL* (functionValueParameter (NL* COMMA NL* functionValueParameter)* (NL* COMMA)?)? NL* RPAREN + ; + +functionValueParameter + : parameterModifiers? parameter (NL* ASSIGNMENT NL* expression)? + ; + +functionDeclaration + : modifiers? + FUN (NL* typeParameters)? (NL* receiverType NL* DOT)? NL* simpleIdentifier + NL* functionValueParameters + (NL* COLON NL* type)? + (NL* typeConstraints)? + (NL* functionBody)? + ; + +functionBody + : block + | ASSIGNMENT NL* expression + ; + +variableDeclaration + : annotation* NL* simpleIdentifier (NL* COLON NL* type)? + ; + +multiVariableDeclaration + : LPAREN NL* variableDeclaration (NL* COMMA NL* variableDeclaration)* (NL* COMMA)? NL* RPAREN + ; + +propertyDeclaration + : modifiers? (VAL | VAR) + (NL* typeParameters)? + (NL* receiverType NL* DOT)? + (NL* (multiVariableDeclaration | variableDeclaration)) + (NL* typeConstraints)? + (NL* (ASSIGNMENT NL* expression | propertyDelegate))? + (NL+ SEMICOLON)? NL* (getter? (NL* semi? setter)? | setter? (NL* semi? getter)?) + ; + +propertyDelegate + : BY NL* expression + ; + +getter + : modifiers? GET + (NL* LPAREN NL* RPAREN (NL* COLON NL* type)? NL* functionBody)? + ; + +setter + : modifiers? SET + (NL* LPAREN NL* functionValueParameterWithOptionalType (NL* COMMA)? NL* RPAREN (NL* COLON NL* type)? NL* functionBody)? + ; + +parametersWithOptionalType + : LPAREN NL* (functionValueParameterWithOptionalType (NL* COMMA NL* functionValueParameterWithOptionalType)* (NL* COMMA)?)? NL* RPAREN + ; + +functionValueParameterWithOptionalType + : parameterModifiers? parameterWithOptionalType (NL* ASSIGNMENT NL* expression)? + ; + +parameterWithOptionalType + : simpleIdentifier NL* (COLON NL* type)? + ; + +parameter + : simpleIdentifier NL* COLON NL* type + ; + +objectDeclaration + : modifiers? OBJECT + NL* simpleIdentifier + (NL* COLON NL* delegationSpecifiers)? + (NL* classBody)? + ; + +secondaryConstructor + : modifiers? CONSTRUCTOR NL* functionValueParameters (NL* COLON NL* constructorDelegationCall)? NL* block? + ; + +constructorDelegationCall + : (THIS | SUPER) NL* valueArguments + ; + +// SECTION: enumClasses + +enumClassBody + : LCURL NL* enumEntries? (NL* SEMICOLON NL* classMemberDeclarations)? NL* RCURL + ; + +enumEntries + : enumEntry (NL* COMMA NL* enumEntry)* NL* COMMA? + ; + +enumEntry + : (modifiers NL*)? simpleIdentifier (NL* valueArguments)? (NL* classBody)? + ; + +// SECTION: types + +type + : typeModifiers? (parenthesizedType | nullableType | typeReference | functionType) + ; + +typeReference + : userType + | DYNAMIC + ; + +nullableType + : (typeReference | parenthesizedType) NL* quest+ + ; + +quest + : QUEST_NO_WS + | QUEST_WS + ; + +userType + : simpleUserType (NL* DOT NL* simpleUserType)* + ; + +simpleUserType + : simpleIdentifier (NL* typeArguments)? + ; + +typeProjection + : typeProjectionModifiers? type + | MULT + ; + +typeProjectionModifiers + : typeProjectionModifier+ + ; + +typeProjectionModifier + : varianceModifier NL* + | annotation + ; + +functionType + : (receiverType NL* DOT NL*)? functionTypeParameters NL* ARROW NL* type + ; + +functionTypeParameters + : LPAREN NL* (parameter | type)? (NL* COMMA NL* (parameter | type))* (NL* COMMA)? NL* RPAREN + ; + +parenthesizedType + : LPAREN NL* type NL* RPAREN + ; + +receiverType + : typeModifiers? (parenthesizedType | nullableType | typeReference) + ; + +parenthesizedUserType + : LPAREN NL* (userType | parenthesizedUserType) NL* RPAREN + ; + +// SECTION: statements + +statements + : (statement (semis statement)*)? semis? + ; + +statement + : (label | annotation)* ( declaration | assignment | loopStatement | expression) + ; + +label + : simpleIdentifier (AT_NO_WS | AT_POST_WS) NL* + ; + +controlStructureBody + : block + | statement + ; + +block + : LCURL NL* statements NL* RCURL + ; + +loopStatement + : forStatement + | whileStatement + | doWhileStatement + ; + +forStatement + : FOR NL* LPAREN annotation* (variableDeclaration | multiVariableDeclaration) + IN expression RPAREN NL* controlStructureBody? + ; + +whileStatement + : WHILE NL* LPAREN expression RPAREN NL* (controlStructureBody | SEMICOLON) + ; + +doWhileStatement + : DO NL* controlStructureBody? NL* WHILE NL* LPAREN expression RPAREN + ; + +assignment + : (directlyAssignableExpression ASSIGNMENT | assignableExpression assignmentAndOperator) NL* expression + ; + +semi + : (SEMICOLON | NL) NL* + | EOF + ; + +semis + : (SEMICOLON | NL)+ + | EOF + ; + +// SECTION: expressions + +expression + : disjunction + ; + +disjunction + : conjunction (NL* DISJ NL* conjunction)* + ; + +conjunction + : equality (NL* CONJ NL* equality)* + ; + +equality + : comparison (equalityOperator NL* comparison)* + ; + +comparison + : genericCallLikeComparison (comparisonOperator NL* genericCallLikeComparison)* + ; + +genericCallLikeComparison + : infixOperation callSuffix* + ; + +infixOperation + : elvisExpression (inOperator NL* elvisExpression | isOperator NL* type)* + ; + +elvisExpression + : infixFunctionCall (NL* elvis NL* infixFunctionCall)* + ; + +elvis + : QUEST_NO_WS COLON + ; + +infixFunctionCall + : rangeExpression (simpleIdentifier NL* rangeExpression)* + ; + +rangeExpression + : additiveExpression (RANGE NL* additiveExpression)* + ; + +additiveExpression + : multiplicativeExpression (additiveOperator NL* multiplicativeExpression)* + ; + +multiplicativeExpression + : asExpression (multiplicativeOperator NL* asExpression)* + ; + +asExpression + : prefixUnaryExpression (NL* asOperator NL* type)* + ; + +prefixUnaryExpression + : unaryPrefix* postfixUnaryExpression + ; + +unaryPrefix + : annotation + | label + | prefixUnaryOperator NL* + ; + +postfixUnaryExpression + : primaryExpression postfixUnarySuffix* + ; + +postfixUnarySuffix + : postfixUnaryOperator + | typeArguments + | callSuffix + | indexingSuffix + | navigationSuffix + ; + +directlyAssignableExpression + : postfixUnaryExpression assignableSuffix + | simpleIdentifier + | parenthesizedDirectlyAssignableExpression + ; + +parenthesizedDirectlyAssignableExpression + : LPAREN NL* directlyAssignableExpression NL* RPAREN + ; + +assignableExpression + : prefixUnaryExpression + | parenthesizedAssignableExpression + ; + +parenthesizedAssignableExpression + : LPAREN NL* assignableExpression NL* RPAREN + ; + +assignableSuffix + : typeArguments + | indexingSuffix + | navigationSuffix + ; + +indexingSuffix + : LSQUARE NL* expression (NL* COMMA NL* expression)* (NL* COMMA)? NL* RSQUARE + ; + +navigationSuffix + : memberAccessOperator NL* (simpleIdentifier | parenthesizedExpression | CLASS) + ; + +callSuffix + : typeArguments? (valueArguments? annotatedLambda | valueArguments) + ; + +annotatedLambda + : annotation* label? NL* lambdaLiteral + ; + +typeArguments + : LANGLE NL* typeProjection (NL* COMMA NL* typeProjection)* (NL* COMMA)? NL* RANGLE + ; + +valueArguments + : LPAREN NL* (valueArgument (NL* COMMA NL* valueArgument)* (NL* COMMA)? NL*)? RPAREN + ; + +valueArgument + : annotation? NL* (simpleIdentifier NL* ASSIGNMENT NL*)? MULT? NL* expression + ; + +primaryExpression + : parenthesizedExpression + | simpleIdentifier + | literalConstant + | stringLiteral + | callableReference + | functionLiteral + | objectLiteral + | collectionLiteral + | thisExpression + | superExpression + | ifExpression + | whenExpression + | tryExpression + | jumpExpression + ; + +parenthesizedExpression + : LPAREN NL* expression NL* RPAREN + ; + +collectionLiteral + : LSQUARE NL* (expression (NL* COMMA NL* expression)* (NL* COMMA)? NL*)? RSQUARE + ; + +literalConstant + : BooleanLiteral + | IntegerLiteral + | HexLiteral + | BinLiteral + | CharacterLiteral + | RealLiteral + | NullLiteral + | LongLiteral + | UnsignedLiteral + ; + +stringLiteral + : lineStringLiteral + | multiLineStringLiteral + ; + +lineStringLiteral + : QUOTE_OPEN (lineStringContent | lineStringExpression)* QUOTE_CLOSE + ; + +multiLineStringLiteral + : TRIPLE_QUOTE_OPEN (multiLineStringContent | multiLineStringExpression | MultiLineStringQuote)* TRIPLE_QUOTE_CLOSE + ; + +lineStringContent + : LineStrText + | LineStrEscapedChar + | LineStrRef + ; + +lineStringExpression + : LineStrExprStart NL* expression NL* RCURL + ; + +multiLineStringContent + : MultiLineStrText + | MultiLineStringQuote + | MultiLineStrRef + ; + +multiLineStringExpression + : MultiLineStrExprStart NL* expression NL* RCURL + ; + +lambdaLiteral + : LCURL NL* (lambdaParameters? NL* ARROW NL*)? statements NL* RCURL + ; + +lambdaParameters + : lambdaParameter (NL* COMMA NL* lambdaParameter)* (NL* COMMA)? + ; + +lambdaParameter + : variableDeclaration + | multiVariableDeclaration (NL* COLON NL* type)? + ; + +anonymousFunction + : FUN + (NL* type NL* DOT)? + NL* parametersWithOptionalType + (NL* COLON NL* type)? + (NL* typeConstraints)? + (NL* functionBody)? + ; + +functionLiteral + : lambdaLiteral + | anonymousFunction + ; + +objectLiteral + : OBJECT (NL* COLON NL* delegationSpecifiers NL*)? (NL* classBody)? + ; + +thisExpression + : THIS + | THIS_AT + ; + +superExpression + : SUPER (LANGLE NL* type NL* RANGLE)? (AT_NO_WS simpleIdentifier)? + | SUPER_AT + ; + +ifExpression + : IF NL* LPAREN NL* expression NL* RPAREN NL* + ( controlStructureBody + | controlStructureBody? NL* SEMICOLON? NL* ELSE NL* (controlStructureBody | SEMICOLON) + | SEMICOLON) + ; + +whenSubject + : LPAREN (annotation* NL* VAL NL* variableDeclaration NL* ASSIGNMENT NL*)? expression RPAREN + ; + +whenExpression + : WHEN NL* whenSubject? NL* LCURL NL* (whenEntry NL*)* NL* RCURL + ; + +whenEntry + : whenCondition (NL* COMMA NL* whenCondition)* (NL* COMMA)? NL* ARROW NL* controlStructureBody semi? + | ELSE NL* ARROW NL* controlStructureBody semi? + ; + +whenCondition + : expression + | rangeTest + | typeTest + ; + +rangeTest + : inOperator NL* expression + ; + +typeTest + : isOperator NL* type + ; + +tryExpression + : TRY NL* block ((NL* catchBlock)+ (NL* finallyBlock)? | NL* finallyBlock) + ; + +catchBlock + : CATCH NL* LPAREN annotation* simpleIdentifier COLON type (NL* COMMA)? RPAREN NL* block + ; + +finallyBlock + : FINALLY NL* block + ; + +jumpExpression + : THROW NL* expression + | (RETURN | RETURN_AT) expression? + | CONTINUE + | CONTINUE_AT + | BREAK + | BREAK_AT + ; + +callableReference + : receiverType? COLONCOLON NL* (simpleIdentifier | CLASS) + ; + +assignmentAndOperator + : ADD_ASSIGNMENT + | SUB_ASSIGNMENT + | MULT_ASSIGNMENT + | DIV_ASSIGNMENT + | MOD_ASSIGNMENT + ; + +equalityOperator + : EXCL_EQ + | EXCL_EQEQ + | EQEQ + | EQEQEQ + ; + +comparisonOperator + : LANGLE + | RANGLE + | LE + | GE + ; + +inOperator + : IN + | NOT_IN + ; + +isOperator + : IS + | NOT_IS + ; + +additiveOperator + : ADD + | SUB + ; + +multiplicativeOperator + : MULT + | DIV + | MOD + ; + +asOperator + : AS + | AS_SAFE + ; + +prefixUnaryOperator + : INCR + | DECR + | SUB + | ADD + | excl + ; + +postfixUnaryOperator + : INCR + | DECR + | EXCL_NO_WS excl + ; + +excl + : EXCL_NO_WS + | EXCL_WS + ; + +memberAccessOperator + : NL* DOT + | NL* safeNav + | COLONCOLON + ; + +safeNav + : QUEST_NO_WS DOT + ; + +// SECTION: modifiers + +modifiers + : (annotation | modifier)+ + ; + +parameterModifiers + : (annotation | parameterModifier)+ + ; + +modifier + : (classModifier + | memberModifier + | visibilityModifier + | functionModifier + | propertyModifier + | inheritanceModifier + | parameterModifier + | platformModifier) NL* + ; + +typeModifiers + : typeModifier+ + ; + +typeModifier + : annotation + | SUSPEND NL* + ; + +classModifier + : ENUM + | SEALED + | ANNOTATION + | DATA + | INNER + | VALUE + ; + +memberModifier + : OVERRIDE + | LATEINIT + ; + +visibilityModifier + : PUBLIC + | PRIVATE + | INTERNAL + | PROTECTED + ; + +varianceModifier + : IN + | OUT + ; + +typeParameterModifiers + : typeParameterModifier+ + ; + +typeParameterModifier + : reificationModifier NL* + | varianceModifier NL* + | annotation + ; + +functionModifier + : TAILREC + | OPERATOR + | INFIX + | INLINE + | EXTERNAL + | SUSPEND + ; + +propertyModifier + : CONST + ; + +inheritanceModifier + : ABSTRACT + | FINAL + | OPEN + ; + +parameterModifier + : VARARG + | NOINLINE + | CROSSINLINE + ; + +reificationModifier + : REIFIED + ; + +platformModifier + : EXPECT + | ACTUAL + ; + +// SECTION: annotations + +annotation + : (singleAnnotation | multiAnnotation) NL* + ; + +singleAnnotation + : (annotationUseSiteTarget NL* | AT_NO_WS | AT_PRE_WS) unescapedAnnotation + ; + +multiAnnotation + : (annotationUseSiteTarget NL* | AT_NO_WS | AT_PRE_WS) LSQUARE unescapedAnnotation+ RSQUARE + ; + +annotationUseSiteTarget + : (AT_NO_WS | AT_PRE_WS) (FIELD | PROPERTY | GET | SET | RECEIVER | PARAM | SETPARAM | DELEGATE) NL* COLON + ; + +unescapedAnnotation + : constructorInvocation + | userType + ; + +// SECTION: identifiers + +simpleIdentifier + : Identifier + | ABSTRACT + | ANNOTATION + | BY + | CATCH + | COMPANION + | CONSTRUCTOR + | CROSSINLINE + | DATA + | DYNAMIC + | ENUM + | EXTERNAL + | FINAL + | FINALLY + | GET + | IMPORT + | INFIX + | INIT + | INLINE + | INNER + | INTERNAL + | LATEINIT + | NOINLINE + | OPEN + | OPERATOR + | OUT + | OVERRIDE + | PRIVATE + | PROTECTED + | PUBLIC + | REIFIED + | SEALED + | TAILREC + | SET + | VARARG + | WHERE + | FIELD + | PROPERTY + | RECEIVER + | PARAM + | SETPARAM + | DELEGATE + | FILE + | EXPECT + | ACTUAL + | CONST + | SUSPEND + | VALUE + ; + +identifier + : simpleIdentifier (NL* DOT simpleIdentifier)* + ; 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 new file mode 100644 index 0000000000..537284804c --- /dev/null +++ b/pmd-kotlin/src/main/antlr4/net/sourceforge/pmd/lang/kotlin/ast/UnicodeClasses.g4 @@ -0,0 +1,1649 @@ +/** + * Kotlin lexical grammar in ANTLR4 notation (Unicode classes) + * + * Taken from http://www.antlr3.org/grammar/1345144569663/AntlrUnicode.txt + */ + +lexer grammar UnicodeClasses; + +UNICODE_CLASS_LL: + '\u0061'..'\u007A' | + '\u00B5' | + '\u00DF'..'\u00F6' | + '\u00F8'..'\u00FF' | + '\u0101' | + '\u0103' | + '\u0105' | + '\u0107' | + '\u0109' | + '\u010B' | + '\u010D' | + '\u010F' | + '\u0111' | + '\u0113' | + '\u0115' | + '\u0117' | + '\u0119' | + '\u011B' | + '\u011D' | + '\u011F' | + '\u0121' | + '\u0123' | + '\u0125' | + '\u0127' | + '\u0129' | + '\u012B' | + '\u012D' | + '\u012F' | + '\u0131' | + '\u0133' | + '\u0135' | + '\u0137' | + '\u0138' | + '\u013A' | + '\u013C' | + '\u013E' | + '\u0140' | + '\u0142' | + '\u0144' | + '\u0146' | + '\u0148' | + '\u0149' | + '\u014B' | + '\u014D' | + '\u014F' | + '\u0151' | + '\u0153' | + '\u0155' | + '\u0157' | + '\u0159' | + '\u015B' | + '\u015D' | + '\u015F' | + '\u0161' | + '\u0163' | + '\u0165' | + '\u0167' | + '\u0169' | + '\u016B' | + '\u016D' | + '\u016F' | + '\u0171' | + '\u0173' | + '\u0175' | + '\u0177' | + '\u017A' | + '\u017C' | + '\u017E'..'\u0180' | + '\u0183' | + '\u0185' | + '\u0188' | + '\u018C' | + '\u018D' | + '\u0192' | + '\u0195' | + '\u0199'..'\u019B' | + '\u019E' | + '\u01A1' | + '\u01A3' | + '\u01A5' | + '\u01A8' | + '\u01AA' | + '\u01AB' | + '\u01AD' | + '\u01B0' | + '\u01B4' | + '\u01B6' | + '\u01B9' | + '\u01BA' | + '\u01BD'..'\u01BF' | + '\u01C6' | + '\u01C9' | + '\u01CC' | + '\u01CE' | + '\u01D0' | + '\u01D2' | + '\u01D4' | + '\u01D6' | + '\u01D8' | + '\u01DA' | + '\u01DC' | + '\u01DD' | + '\u01DF' | + '\u01E1' | + '\u01E3' | + '\u01E5' | + '\u01E7' | + '\u01E9' | + '\u01EB' | + '\u01ED' | + '\u01EF' | + '\u01F0' | + '\u01F3' | + '\u01F5' | + '\u01F9' | + '\u01FB' | + '\u01FD' | + '\u01FF' | + '\u0201' | + '\u0203' | + '\u0205' | + '\u0207' | + '\u0209' | + '\u020B' | + '\u020D' | + '\u020F' | + '\u0211' | + '\u0213' | + '\u0215' | + '\u0217' | + '\u0219' | + '\u021B' | + '\u021D' | + '\u021F' | + '\u0221' | + '\u0223' | + '\u0225' | + '\u0227' | + '\u0229' | + '\u022B' | + '\u022D' | + '\u022F' | + '\u0231' | + '\u0233'..'\u0239' | + '\u023C' | + '\u023F' | + '\u0240' | + '\u0242' | + '\u0247' | + '\u0249' | + '\u024B' | + '\u024D' | + '\u024F'..'\u0293' | + '\u0295'..'\u02AF' | + '\u0371' | + '\u0373' | + '\u0377' | + '\u037B'..'\u037D' | + '\u0390' | + '\u03AC'..'\u03CE' | + '\u03D0' | + '\u03D1' | + '\u03D5'..'\u03D7' | + '\u03D9' | + '\u03DB' | + '\u03DD' | + '\u03DF' | + '\u03E1' | + '\u03E3' | + '\u03E5' | + '\u03E7' | + '\u03E9' | + '\u03EB' | + '\u03ED' | + '\u03EF'..'\u03F3' | + '\u03F5' | + '\u03F8' | + '\u03FB' | + '\u03FC' | + '\u0430'..'\u045F' | + '\u0461' | + '\u0463' | + '\u0465' | + '\u0467' | + '\u0469' | + '\u046B' | + '\u046D' | + '\u046F' | + '\u0471' | + '\u0473' | + '\u0475' | + '\u0477' | + '\u0479' | + '\u047B' | + '\u047D' | + '\u047F' | + '\u0481' | + '\u048B' | + '\u048D' | + '\u048F' | + '\u0491' | + '\u0493' | + '\u0495' | + '\u0497' | + '\u0499' | + '\u049B' | + '\u049D' | + '\u049F' | + '\u04A1' | + '\u04A3' | + '\u04A5' | + '\u04A7' | + '\u04A9' | + '\u04AB' | + '\u04AD' | + '\u04AF' | + '\u04B1' | + '\u04B3' | + '\u04B5' | + '\u04B7' | + '\u04B9' | + '\u04BB' | + '\u04BD' | + '\u04BF' | + '\u04C2' | + '\u04C4' | + '\u04C6' | + '\u04C8' | + '\u04CA' | + '\u04CC' | + '\u04CE' | + '\u04CF' | + '\u04D1' | + '\u04D3' | + '\u04D5' | + '\u04D7' | + '\u04D9' | + '\u04DB' | + '\u04DD' | + '\u04DF' | + '\u04E1' | + '\u04E3' | + '\u04E5' | + '\u04E7' | + '\u04E9' | + '\u04EB' | + '\u04ED' | + '\u04EF' | + '\u04F1' | + '\u04F3' | + '\u04F5' | + '\u04F7' | + '\u04F9' | + '\u04FB' | + '\u04FD' | + '\u04FF' | + '\u0501' | + '\u0503' | + '\u0505' | + '\u0507' | + '\u0509' | + '\u050B' | + '\u050D' | + '\u050F' | + '\u0511' | + '\u0513' | + '\u0515' | + '\u0517' | + '\u0519' | + '\u051B' | + '\u051D' | + '\u051F' | + '\u0521' | + '\u0523' | + '\u0525' | + '\u0527' | + '\u0561'..'\u0587' | + '\u1D00'..'\u1D2B' | + '\u1D6B'..'\u1D77' | + '\u1D79'..'\u1D9A' | + '\u1E01' | + '\u1E03' | + '\u1E05' | + '\u1E07' | + '\u1E09' | + '\u1E0B' | + '\u1E0D' | + '\u1E0F' | + '\u1E11' | + '\u1E13' | + '\u1E15' | + '\u1E17' | + '\u1E19' | + '\u1E1B' | + '\u1E1D' | + '\u1E1F' | + '\u1E21' | + '\u1E23' | + '\u1E25' | + '\u1E27' | + '\u1E29' | + '\u1E2B' | + '\u1E2D' | + '\u1E2F' | + '\u1E31' | + '\u1E33' | + '\u1E35' | + '\u1E37' | + '\u1E39' | + '\u1E3B' | + '\u1E3D' | + '\u1E3F' | + '\u1E41' | + '\u1E43' | + '\u1E45' | + '\u1E47' | + '\u1E49' | + '\u1E4B' | + '\u1E4D' | + '\u1E4F' | + '\u1E51' | + '\u1E53' | + '\u1E55' | + '\u1E57' | + '\u1E59' | + '\u1E5B' | + '\u1E5D' | + '\u1E5F' | + '\u1E61' | + '\u1E63' | + '\u1E65' | + '\u1E67' | + '\u1E69' | + '\u1E6B' | + '\u1E6D' | + '\u1E6F' | + '\u1E71' | + '\u1E73' | + '\u1E75' | + '\u1E77' | + '\u1E79' | + '\u1E7B' | + '\u1E7D' | + '\u1E7F' | + '\u1E81' | + '\u1E83' | + '\u1E85' | + '\u1E87' | + '\u1E89' | + '\u1E8B' | + '\u1E8D' | + '\u1E8F' | + '\u1E91' | + '\u1E93' | + '\u1E95'..'\u1E9D' | + '\u1E9F' | + '\u1EA1' | + '\u1EA3' | + '\u1EA5' | + '\u1EA7' | + '\u1EA9' | + '\u1EAB' | + '\u1EAD' | + '\u1EAF' | + '\u1EB1' | + '\u1EB3' | + '\u1EB5' | + '\u1EB7' | + '\u1EB9' | + '\u1EBB' | + '\u1EBD' | + '\u1EBF' | + '\u1EC1' | + '\u1EC3' | + '\u1EC5' | + '\u1EC7' | + '\u1EC9' | + '\u1ECB' | + '\u1ECD' | + '\u1ECF' | + '\u1ED1' | + '\u1ED3' | + '\u1ED5' | + '\u1ED7' | + '\u1ED9' | + '\u1EDB' | + '\u1EDD' | + '\u1EDF' | + '\u1EE1' | + '\u1EE3' | + '\u1EE5' | + '\u1EE7' | + '\u1EE9' | + '\u1EEB' | + '\u1EED' | + '\u1EEF' | + '\u1EF1' | + '\u1EF3' | + '\u1EF5' | + '\u1EF7' | + '\u1EF9' | + '\u1EFB' | + '\u1EFD' | + '\u1EFF'..'\u1F07' | + '\u1F10'..'\u1F15' | + '\u1F20'..'\u1F27' | + '\u1F30'..'\u1F37' | + '\u1F40'..'\u1F45' | + '\u1F50'..'\u1F57' | + '\u1F60'..'\u1F67' | + '\u1F70'..'\u1F7D' | + '\u1F80'..'\u1F87' | + '\u1F90'..'\u1F97' | + '\u1FA0'..'\u1FA7' | + '\u1FB0'..'\u1FB4' | + '\u1FB6' | + '\u1FB7' | + '\u1FBE' | + '\u1FC2'..'\u1FC4' | + '\u1FC6' | + '\u1FC7' | + '\u1FD0'..'\u1FD3' | + '\u1FD6' | + '\u1FD7' | + '\u1FE0'..'\u1FE7' | + '\u1FF2'..'\u1FF4' | + '\u1FF6' | + '\u1FF7' | + '\u210A' | + '\u210E' | + '\u210F' | + '\u2113' | + '\u212F' | + '\u2134' | + '\u2139' | + '\u213C' | + '\u213D' | + '\u2146'..'\u2149' | + '\u214E' | + '\u2184' | + '\u2C30'..'\u2C5E' | + '\u2C61' | + '\u2C65' | + '\u2C66' | + '\u2C68' | + '\u2C6A' | + '\u2C6C' | + '\u2C71' | + '\u2C73' | + '\u2C74' | + '\u2C76'..'\u2C7B' | + '\u2C81' | + '\u2C83' | + '\u2C85' | + '\u2C87' | + '\u2C89' | + '\u2C8B' | + '\u2C8D' | + '\u2C8F' | + '\u2C91' | + '\u2C93' | + '\u2C95' | + '\u2C97' | + '\u2C99' | + '\u2C9B' | + '\u2C9D' | + '\u2C9F' | + '\u2CA1' | + '\u2CA3' | + '\u2CA5' | + '\u2CA7' | + '\u2CA9' | + '\u2CAB' | + '\u2CAD' | + '\u2CAF' | + '\u2CB1' | + '\u2CB3' | + '\u2CB5' | + '\u2CB7' | + '\u2CB9' | + '\u2CBB' | + '\u2CBD' | + '\u2CBF' | + '\u2CC1' | + '\u2CC3' | + '\u2CC5' | + '\u2CC7' | + '\u2CC9' | + '\u2CCB' | + '\u2CCD' | + '\u2CCF' | + '\u2CD1' | + '\u2CD3' | + '\u2CD5' | + '\u2CD7' | + '\u2CD9' | + '\u2CDB' | + '\u2CDD' | + '\u2CDF' | + '\u2CE1' | + '\u2CE3' | + '\u2CE4' | + '\u2CEC' | + '\u2CEE' | + '\u2CF3' | + '\u2D00'..'\u2D25' | + '\u2D27' | + '\u2D2D' | + '\uA641' | + '\uA643' | + '\uA645' | + '\uA647' | + '\uA649' | + '\uA64B' | + '\uA64D' | + '\uA64F' | + '\uA651' | + '\uA653' | + '\uA655' | + '\uA657' | + '\uA659' | + '\uA65B' | + '\uA65D' | + '\uA65F' | + '\uA661' | + '\uA663' | + '\uA665' | + '\uA667' | + '\uA669' | + '\uA66B' | + '\uA66D' | + '\uA681' | + '\uA683' | + '\uA685' | + '\uA687' | + '\uA689' | + '\uA68B' | + '\uA68D' | + '\uA68F' | + '\uA691' | + '\uA693' | + '\uA695' | + '\uA697' | + '\uA723' | + '\uA725' | + '\uA727' | + '\uA729' | + '\uA72B' | + '\uA72D' | + '\uA72F'..'\uA731' | + '\uA733' | + '\uA735' | + '\uA737' | + '\uA739' | + '\uA73B' | + '\uA73D' | + '\uA73F' | + '\uA741' | + '\uA743' | + '\uA745' | + '\uA747' | + '\uA749' | + '\uA74B' | + '\uA74D' | + '\uA74F' | + '\uA751' | + '\uA753' | + '\uA755' | + '\uA757' | + '\uA759' | + '\uA75B' | + '\uA75D' | + '\uA75F' | + '\uA761' | + '\uA763' | + '\uA765' | + '\uA767' | + '\uA769' | + '\uA76B' | + '\uA76D' | + '\uA76F' | + '\uA771'..'\uA778' | + '\uA77A' | + '\uA77C' | + '\uA77F' | + '\uA781' | + '\uA783' | + '\uA785' | + '\uA787' | + '\uA78C' | + '\uA78E' | + '\uA791' | + '\uA793' | + '\uA7A1' | + '\uA7A3' | + '\uA7A5' | + '\uA7A7' | + '\uA7A9' | + '\uA7FA' | + '\uFB00'..'\uFB06' | + '\uFB13'..'\uFB17' | + '\uFF41'..'\uFF5A'; + +UNICODE_CLASS_LM: + '\u02B0'..'\u02C1' | + '\u02C6'..'\u02D1' | + '\u02E0'..'\u02E4' | + '\u02EC' | + '\u02EE' | + '\u0374' | + '\u037A' | + '\u0559' | + '\u0640' | + '\u06E5' | + '\u06E6' | + '\u07F4' | + '\u07F5' | + '\u07FA' | + '\u081A' | + '\u0824' | + '\u0828' | + '\u0971' | + '\u0E46' | + '\u0EC6' | + '\u10FC' | + '\u17D7' | + '\u1843' | + '\u1AA7' | + '\u1C78'..'\u1C7D' | + '\u1D2C'..'\u1D6A' | + '\u1D78' | + '\u1D9B'..'\u1DBF' | + '\u2071' | + '\u207F' | + '\u2090'..'\u209C' | + '\u2C7C' | + '\u2C7D' | + '\u2D6F' | + '\u2E2F' | + '\u3005' | + '\u3031'..'\u3035' | + '\u303B' | + '\u309D' | + '\u309E' | + '\u30FC'..'\u30FE' | + '\uA015' | + '\uA4F8'..'\uA4FD' | + '\uA60C' | + '\uA67F' | + '\uA717'..'\uA71F' | + '\uA770' | + '\uA788' | + '\uA7F8' | + '\uA7F9' | + '\uA9CF' | + '\uAA70' | + '\uAADD' | + '\uAAF3' | + '\uAAF4' | + '\uFF70' | + '\uFF9E' | + '\uFF9F'; + +UNICODE_CLASS_LO: + '\u00AA' | + '\u00BA' | + '\u01BB' | + '\u01C0'..'\u01C3' | + '\u0294' | + '\u05D0'..'\u05EA' | + '\u05F0'..'\u05F2' | + '\u0620'..'\u063F' | + '\u0641'..'\u064A' | + '\u066E' | + '\u066F' | + '\u0671'..'\u06D3' | + '\u06D5' | + '\u06EE' | + '\u06EF' | + '\u06FA'..'\u06FC' | + '\u06FF' | + '\u0710' | + '\u0712'..'\u072F' | + '\u074D'..'\u07A5' | + '\u07B1' | + '\u07CA'..'\u07EA' | + '\u0800'..'\u0815' | + '\u0840'..'\u0858' | + '\u08A0' | + '\u08A2'..'\u08AC' | + '\u0904'..'\u0939' | + '\u093D' | + '\u0950' | + '\u0958'..'\u0961' | + '\u0972'..'\u0977' | + '\u0979'..'\u097F' | + '\u0985'..'\u098C' | + '\u098F' | + '\u0990' | + '\u0993'..'\u09A8' | + '\u09AA'..'\u09B0' | + '\u09B2' | + '\u09B6'..'\u09B9' | + '\u09BD' | + '\u09CE' | + '\u09DC' | + '\u09DD' | + '\u09DF'..'\u09E1' | + '\u09F0' | + '\u09F1' | + '\u0A05'..'\u0A0A' | + '\u0A0F' | + '\u0A10' | + '\u0A13'..'\u0A28' | + '\u0A2A'..'\u0A30' | + '\u0A32' | + '\u0A33' | + '\u0A35' | + '\u0A36' | + '\u0A38' | + '\u0A39' | + '\u0A59'..'\u0A5C' | + '\u0A5E' | + '\u0A72'..'\u0A74' | + '\u0A85'..'\u0A8D' | + '\u0A8F'..'\u0A91' | + '\u0A93'..'\u0AA8' | + '\u0AAA'..'\u0AB0' | + '\u0AB2' | + '\u0AB3' | + '\u0AB5'..'\u0AB9' | + '\u0ABD' | + '\u0AD0' | + '\u0AE0' | + '\u0AE1' | + '\u0B05'..'\u0B0C' | + '\u0B0F' | + '\u0B10' | + '\u0B13'..'\u0B28' | + '\u0B2A'..'\u0B30' | + '\u0B32' | + '\u0B33' | + '\u0B35'..'\u0B39' | + '\u0B3D' | + '\u0B5C' | + '\u0B5D' | + '\u0B5F'..'\u0B61' | + '\u0B71' | + '\u0B83' | + '\u0B85'..'\u0B8A' | + '\u0B8E'..'\u0B90' | + '\u0B92'..'\u0B95' | + '\u0B99' | + '\u0B9A' | + '\u0B9C' | + '\u0B9E' | + '\u0B9F' | + '\u0BA3' | + '\u0BA4' | + '\u0BA8'..'\u0BAA' | + '\u0BAE'..'\u0BB9' | + '\u0BD0' | + '\u0C05'..'\u0C0C' | + '\u0C0E'..'\u0C10' | + '\u0C12'..'\u0C28' | + '\u0C2A'..'\u0C33' | + '\u0C35'..'\u0C39' | + '\u0C3D' | + '\u0C58' | + '\u0C59' | + '\u0C60' | + '\u0C61' | + '\u0C85'..'\u0C8C' | + '\u0C8E'..'\u0C90' | + '\u0C92'..'\u0CA8' | + '\u0CAA'..'\u0CB3' | + '\u0CB5'..'\u0CB9' | + '\u0CBD' | + '\u0CDE' | + '\u0CE0' | + '\u0CE1' | + '\u0CF1' | + '\u0CF2' | + '\u0D05'..'\u0D0C' | + '\u0D0E'..'\u0D10' | + '\u0D12'..'\u0D3A' | + '\u0D3D' | + '\u0D4E' | + '\u0D60' | + '\u0D61' | + '\u0D7A'..'\u0D7F' | + '\u0D85'..'\u0D96' | + '\u0D9A'..'\u0DB1' | + '\u0DB3'..'\u0DBB' | + '\u0DBD' | + '\u0DC0'..'\u0DC6' | + '\u0E01'..'\u0E30' | + '\u0E32' | + '\u0E33' | + '\u0E40'..'\u0E45' | + '\u0E81' | + '\u0E82' | + '\u0E84' | + '\u0E87' | + '\u0E88' | + '\u0E8A' | + '\u0E8D' | + '\u0E94'..'\u0E97' | + '\u0E99'..'\u0E9F' | + '\u0EA1'..'\u0EA3' | + '\u0EA5' | + '\u0EA7' | + '\u0EAA' | + '\u0EAB' | + '\u0EAD'..'\u0EB0' | + '\u0EB2' | + '\u0EB3' | + '\u0EBD' | + '\u0EC0'..'\u0EC4' | + '\u0EDC'..'\u0EDF' | + '\u0F00' | + '\u0F40'..'\u0F47' | + '\u0F49'..'\u0F6C' | + '\u0F88'..'\u0F8C' | + '\u1000'..'\u102A' | + '\u103F' | + '\u1050'..'\u1055' | + '\u105A'..'\u105D' | + '\u1061' | + '\u1065' | + '\u1066' | + '\u106E'..'\u1070' | + '\u1075'..'\u1081' | + '\u108E' | + '\u10D0'..'\u10FA' | + '\u10FD'..'\u1248' | + '\u124A'..'\u124D' | + '\u1250'..'\u1256' | + '\u1258' | + '\u125A'..'\u125D' | + '\u1260'..'\u1288' | + '\u128A'..'\u128D' | + '\u1290'..'\u12B0' | + '\u12B2'..'\u12B5' | + '\u12B8'..'\u12BE' | + '\u12C0' | + '\u12C2'..'\u12C5' | + '\u12C8'..'\u12D6' | + '\u12D8'..'\u1310' | + '\u1312'..'\u1315' | + '\u1318'..'\u135A' | + '\u1380'..'\u138F' | + '\u13A0'..'\u13F4' | + '\u1401'..'\u166C' | + '\u166F'..'\u167F' | + '\u1681'..'\u169A' | + '\u16A0'..'\u16EA' | + '\u1700'..'\u170C' | + '\u170E'..'\u1711' | + '\u1720'..'\u1731' | + '\u1740'..'\u1751' | + '\u1760'..'\u176C' | + '\u176E'..'\u1770' | + '\u1780'..'\u17B3' | + '\u17DC' | + '\u1820'..'\u1842' | + '\u1844'..'\u1877' | + '\u1880'..'\u18A8' | + '\u18AA' | + '\u18B0'..'\u18F5' | + '\u1900'..'\u191C' | + '\u1950'..'\u196D' | + '\u1970'..'\u1974' | + '\u1980'..'\u19AB' | + '\u19C1'..'\u19C7' | + '\u1A00'..'\u1A16' | + '\u1A20'..'\u1A54' | + '\u1B05'..'\u1B33' | + '\u1B45'..'\u1B4B' | + '\u1B83'..'\u1BA0' | + '\u1BAE' | + '\u1BAF' | + '\u1BBA'..'\u1BE5' | + '\u1C00'..'\u1C23' | + '\u1C4D'..'\u1C4F' | + '\u1C5A'..'\u1C77' | + '\u1CE9'..'\u1CEC' | + '\u1CEE'..'\u1CF1' | + '\u1CF5' | + '\u1CF6' | + '\u2135'..'\u2138' | + '\u2D30'..'\u2D67' | + '\u2D80'..'\u2D96' | + '\u2DA0'..'\u2DA6' | + '\u2DA8'..'\u2DAE' | + '\u2DB0'..'\u2DB6' | + '\u2DB8'..'\u2DBE' | + '\u2DC0'..'\u2DC6' | + '\u2DC8'..'\u2DCE' | + '\u2DD0'..'\u2DD6' | + '\u2DD8'..'\u2DDE' | + '\u3006' | + '\u303C' | + '\u3041'..'\u3096' | + '\u309F' | + '\u30A1'..'\u30FA' | + '\u30FF' | + '\u3105'..'\u312D' | + '\u3131'..'\u318E' | + '\u31A0'..'\u31BA' | + '\u31F0'..'\u31FF' | + '\u3400' | + '\u4DB5' | + '\u4E00' | + '\u9FCC' | + '\uA000'..'\uA014' | + '\uA016'..'\uA48C' | + '\uA4D0'..'\uA4F7' | + '\uA500'..'\uA60B' | + '\uA610'..'\uA61F' | + '\uA62A' | + '\uA62B' | + '\uA66E' | + '\uA6A0'..'\uA6E5' | + '\uA7FB'..'\uA801' | + '\uA803'..'\uA805' | + '\uA807'..'\uA80A' | + '\uA80C'..'\uA822' | + '\uA840'..'\uA873' | + '\uA882'..'\uA8B3' | + '\uA8F2'..'\uA8F7' | + '\uA8FB' | + '\uA90A'..'\uA925' | + '\uA930'..'\uA946' | + '\uA960'..'\uA97C' | + '\uA984'..'\uA9B2' | + '\uAA00'..'\uAA28' | + '\uAA40'..'\uAA42' | + '\uAA44'..'\uAA4B' | + '\uAA60'..'\uAA6F' | + '\uAA71'..'\uAA76' | + '\uAA7A' | + '\uAA80'..'\uAAAF' | + '\uAAB1' | + '\uAAB5' | + '\uAAB6' | + '\uAAB9'..'\uAABD' | + '\uAAC0' | + '\uAAC2' | + '\uAADB' | + '\uAADC' | + '\uAAE0'..'\uAAEA' | + '\uAAF2' | + '\uAB01'..'\uAB06' | + '\uAB09'..'\uAB0E' | + '\uAB11'..'\uAB16' | + '\uAB20'..'\uAB26' | + '\uAB28'..'\uAB2E' | + '\uABC0'..'\uABE2' | + '\uAC00' | + '\uD7A3' | + '\uD7B0'..'\uD7C6' | + '\uD7CB'..'\uD7FB' | + '\uF900'..'\uFA6D' | + '\uFA70'..'\uFAD9' | + '\uFB1D' | + '\uFB1F'..'\uFB28' | + '\uFB2A'..'\uFB36' | + '\uFB38'..'\uFB3C' | + '\uFB3E' | + '\uFB40' | + '\uFB41' | + '\uFB43' | + '\uFB44' | + '\uFB46'..'\uFBB1' | + '\uFBD3'..'\uFD3D' | + '\uFD50'..'\uFD8F' | + '\uFD92'..'\uFDC7' | + '\uFDF0'..'\uFDFB' | + '\uFE70'..'\uFE74' | + '\uFE76'..'\uFEFC' | + '\uFF66'..'\uFF6F' | + '\uFF71'..'\uFF9D' | + '\uFFA0'..'\uFFBE' | + '\uFFC2'..'\uFFC7' | + '\uFFCA'..'\uFFCF' | + '\uFFD2'..'\uFFD7' | + '\uFFDA'..'\uFFDC'; + +UNICODE_CLASS_LT: + '\u01C5' | + '\u01C8' | + '\u01CB' | + '\u01F2' | + '\u1F88'..'\u1F8F' | + '\u1F98'..'\u1F9F' | + '\u1FA8'..'\u1FAF' | + '\u1FBC' | + '\u1FCC' | + '\u1FFC'; + +UNICODE_CLASS_LU: + '\u0041'..'\u005A' | + '\u00C0'..'\u00D6' | + '\u00D8'..'\u00DE' | + '\u0100' | + '\u0102' | + '\u0104' | + '\u0106' | + '\u0108' | + '\u010A' | + '\u010C' | + '\u010E' | + '\u0110' | + '\u0112' | + '\u0114' | + '\u0116' | + '\u0118' | + '\u011A' | + '\u011C' | + '\u011E' | + '\u0120' | + '\u0122' | + '\u0124' | + '\u0126' | + '\u0128' | + '\u012A' | + '\u012C' | + '\u012E' | + '\u0130' | + '\u0132' | + '\u0134' | + '\u0136' | + '\u0139' | + '\u013B' | + '\u013D' | + '\u013F' | + '\u0141' | + '\u0143' | + '\u0145' | + '\u0147' | + '\u014A' | + '\u014C' | + '\u014E' | + '\u0150' | + '\u0152' | + '\u0154' | + '\u0156' | + '\u0158' | + '\u015A' | + '\u015C' | + '\u015E' | + '\u0160' | + '\u0162' | + '\u0164' | + '\u0166' | + '\u0168' | + '\u016A' | + '\u016C' | + '\u016E' | + '\u0170' | + '\u0172' | + '\u0174' | + '\u0176' | + '\u0178' | + '\u0179' | + '\u017B' | + '\u017D' | + '\u0181' | + '\u0182' | + '\u0184' | + '\u0186' | + '\u0187' | + '\u0189'..'\u018B' | + '\u018E'..'\u0191' | + '\u0193' | + '\u0194' | + '\u0196'..'\u0198' | + '\u019C' | + '\u019D' | + '\u019F' | + '\u01A0' | + '\u01A2' | + '\u01A4' | + '\u01A6' | + '\u01A7' | + '\u01A9' | + '\u01AC' | + '\u01AE' | + '\u01AF' | + '\u01B1'..'\u01B3' | + '\u01B5' | + '\u01B7' | + '\u01B8' | + '\u01BC' | + '\u01C4' | + '\u01C7' | + '\u01CA' | + '\u01CD' | + '\u01CF' | + '\u01D1' | + '\u01D3' | + '\u01D5' | + '\u01D7' | + '\u01D9' | + '\u01DB' | + '\u01DE' | + '\u01E0' | + '\u01E2' | + '\u01E4' | + '\u01E6' | + '\u01E8' | + '\u01EA' | + '\u01EC' | + '\u01EE' | + '\u01F1' | + '\u01F4' | + '\u01F6'..'\u01F8' | + '\u01FA' | + '\u01FC' | + '\u01FE' | + '\u0200' | + '\u0202' | + '\u0204' | + '\u0206' | + '\u0208' | + '\u020A' | + '\u020C' | + '\u020E' | + '\u0210' | + '\u0212' | + '\u0214' | + '\u0216' | + '\u0218' | + '\u021A' | + '\u021C' | + '\u021E' | + '\u0220' | + '\u0222' | + '\u0224' | + '\u0226' | + '\u0228' | + '\u022A' | + '\u022C' | + '\u022E' | + '\u0230' | + '\u0232' | + '\u023A' | + '\u023B' | + '\u023D' | + '\u023E' | + '\u0241' | + '\u0243'..'\u0246' | + '\u0248' | + '\u024A' | + '\u024C' | + '\u024E' | + '\u0370' | + '\u0372' | + '\u0376' | + '\u0386' | + '\u0388'..'\u038A' | + '\u038C' | + '\u038E' | + '\u038F' | + '\u0391'..'\u03A1' | + '\u03A3'..'\u03AB' | + '\u03CF' | + '\u03D2'..'\u03D4' | + '\u03D8' | + '\u03DA' | + '\u03DC' | + '\u03DE' | + '\u03E0' | + '\u03E2' | + '\u03E4' | + '\u03E6' | + '\u03E8' | + '\u03EA' | + '\u03EC' | + '\u03EE' | + '\u03F4' | + '\u03F7' | + '\u03F9' | + '\u03FA' | + '\u03FD'..'\u042F' | + '\u0460' | + '\u0462' | + '\u0464' | + '\u0466' | + '\u0468' | + '\u046A' | + '\u046C' | + '\u046E' | + '\u0470' | + '\u0472' | + '\u0474' | + '\u0476' | + '\u0478' | + '\u047A' | + '\u047C' | + '\u047E' | + '\u0480' | + '\u048A' | + '\u048C' | + '\u048E' | + '\u0490' | + '\u0492' | + '\u0494' | + '\u0496' | + '\u0498' | + '\u049A' | + '\u049C' | + '\u049E' | + '\u04A0' | + '\u04A2' | + '\u04A4' | + '\u04A6' | + '\u04A8' | + '\u04AA' | + '\u04AC' | + '\u04AE' | + '\u04B0' | + '\u04B2' | + '\u04B4' | + '\u04B6' | + '\u04B8' | + '\u04BA' | + '\u04BC' | + '\u04BE' | + '\u04C0' | + '\u04C1' | + '\u04C3' | + '\u04C5' | + '\u04C7' | + '\u04C9' | + '\u04CB' | + '\u04CD' | + '\u04D0' | + '\u04D2' | + '\u04D4' | + '\u04D6' | + '\u04D8' | + '\u04DA' | + '\u04DC' | + '\u04DE' | + '\u04E0' | + '\u04E2' | + '\u04E4' | + '\u04E6' | + '\u04E8' | + '\u04EA' | + '\u04EC' | + '\u04EE' | + '\u04F0' | + '\u04F2' | + '\u04F4' | + '\u04F6' | + '\u04F8' | + '\u04FA' | + '\u04FC' | + '\u04FE' | + '\u0500' | + '\u0502' | + '\u0504' | + '\u0506' | + '\u0508' | + '\u050A' | + '\u050C' | + '\u050E' | + '\u0510' | + '\u0512' | + '\u0514' | + '\u0516' | + '\u0518' | + '\u051A' | + '\u051C' | + '\u051E' | + '\u0520' | + '\u0522' | + '\u0524' | + '\u0526' | + '\u0531'..'\u0556' | + '\u10A0'..'\u10C5' | + '\u10C7' | + '\u10CD' | + '\u1E00' | + '\u1E02' | + '\u1E04' | + '\u1E06' | + '\u1E08' | + '\u1E0A' | + '\u1E0C' | + '\u1E0E' | + '\u1E10' | + '\u1E12' | + '\u1E14' | + '\u1E16' | + '\u1E18' | + '\u1E1A' | + '\u1E1C' | + '\u1E1E' | + '\u1E20' | + '\u1E22' | + '\u1E24' | + '\u1E26' | + '\u1E28' | + '\u1E2A' | + '\u1E2C' | + '\u1E2E' | + '\u1E30' | + '\u1E32' | + '\u1E34' | + '\u1E36' | + '\u1E38' | + '\u1E3A' | + '\u1E3C' | + '\u1E3E' | + '\u1E40' | + '\u1E42' | + '\u1E44' | + '\u1E46' | + '\u1E48' | + '\u1E4A' | + '\u1E4C' | + '\u1E4E' | + '\u1E50' | + '\u1E52' | + '\u1E54' | + '\u1E56' | + '\u1E58' | + '\u1E5A' | + '\u1E5C' | + '\u1E5E' | + '\u1E60' | + '\u1E62' | + '\u1E64' | + '\u1E66' | + '\u1E68' | + '\u1E6A' | + '\u1E6C' | + '\u1E6E' | + '\u1E70' | + '\u1E72' | + '\u1E74' | + '\u1E76' | + '\u1E78' | + '\u1E7A' | + '\u1E7C' | + '\u1E7E' | + '\u1E80' | + '\u1E82' | + '\u1E84' | + '\u1E86' | + '\u1E88' | + '\u1E8A' | + '\u1E8C' | + '\u1E8E' | + '\u1E90' | + '\u1E92' | + '\u1E94' | + '\u1E9E' | + '\u1EA0' | + '\u1EA2' | + '\u1EA4' | + '\u1EA6' | + '\u1EA8' | + '\u1EAA' | + '\u1EAC' | + '\u1EAE' | + '\u1EB0' | + '\u1EB2' | + '\u1EB4' | + '\u1EB6' | + '\u1EB8' | + '\u1EBA' | + '\u1EBC' | + '\u1EBE' | + '\u1EC0' | + '\u1EC2' | + '\u1EC4' | + '\u1EC6' | + '\u1EC8' | + '\u1ECA' | + '\u1ECC' | + '\u1ECE' | + '\u1ED0' | + '\u1ED2' | + '\u1ED4' | + '\u1ED6' | + '\u1ED8' | + '\u1EDA' | + '\u1EDC' | + '\u1EDE' | + '\u1EE0' | + '\u1EE2' | + '\u1EE4' | + '\u1EE6' | + '\u1EE8' | + '\u1EEA' | + '\u1EEC' | + '\u1EEE' | + '\u1EF0' | + '\u1EF2' | + '\u1EF4' | + '\u1EF6' | + '\u1EF8' | + '\u1EFA' | + '\u1EFC' | + '\u1EFE' | + '\u1F08'..'\u1F0F' | + '\u1F18'..'\u1F1D' | + '\u1F28'..'\u1F2F' | + '\u1F38'..'\u1F3F' | + '\u1F48'..'\u1F4D' | + '\u1F59' | + '\u1F5B' | + '\u1F5D' | + '\u1F5F' | + '\u1F68'..'\u1F6F' | + '\u1FB8'..'\u1FBB' | + '\u1FC8'..'\u1FCB' | + '\u1FD8'..'\u1FDB' | + '\u1FE8'..'\u1FEC' | + '\u1FF8'..'\u1FFB' | + '\u2102' | + '\u2107' | + '\u210B'..'\u210D' | + '\u2110'..'\u2112' | + '\u2115' | + '\u2119'..'\u211D' | + '\u2124' | + '\u2126' | + '\u2128' | + '\u212A'..'\u212D' | + '\u2130'..'\u2133' | + '\u213E' | + '\u213F' | + '\u2145' | + '\u2183' | + '\u2C00'..'\u2C2E' | + '\u2C60' | + '\u2C62'..'\u2C64' | + '\u2C67' | + '\u2C69' | + '\u2C6B' | + '\u2C6D'..'\u2C70' | + '\u2C72' | + '\u2C75' | + '\u2C7E'..'\u2C80' | + '\u2C82' | + '\u2C84' | + '\u2C86' | + '\u2C88' | + '\u2C8A' | + '\u2C8C' | + '\u2C8E' | + '\u2C90' | + '\u2C92' | + '\u2C94' | + '\u2C96' | + '\u2C98' | + '\u2C9A' | + '\u2C9C' | + '\u2C9E' | + '\u2CA0' | + '\u2CA2' | + '\u2CA4' | + '\u2CA6' | + '\u2CA8' | + '\u2CAA' | + '\u2CAC' | + '\u2CAE' | + '\u2CB0' | + '\u2CB2' | + '\u2CB4' | + '\u2CB6' | + '\u2CB8' | + '\u2CBA' | + '\u2CBC' | + '\u2CBE' | + '\u2CC0' | + '\u2CC2' | + '\u2CC4' | + '\u2CC6' | + '\u2CC8' | + '\u2CCA' | + '\u2CCC' | + '\u2CCE' | + '\u2CD0' | + '\u2CD2' | + '\u2CD4' | + '\u2CD6' | + '\u2CD8' | + '\u2CDA' | + '\u2CDC' | + '\u2CDE' | + '\u2CE0' | + '\u2CE2' | + '\u2CEB' | + '\u2CED' | + '\u2CF2' | + '\uA640' | + '\uA642' | + '\uA644' | + '\uA646' | + '\uA648' | + '\uA64A' | + '\uA64C' | + '\uA64E' | + '\uA650' | + '\uA652' | + '\uA654' | + '\uA656' | + '\uA658' | + '\uA65A' | + '\uA65C' | + '\uA65E' | + '\uA660' | + '\uA662' | + '\uA664' | + '\uA666' | + '\uA668' | + '\uA66A' | + '\uA66C' | + '\uA680' | + '\uA682' | + '\uA684' | + '\uA686' | + '\uA688' | + '\uA68A' | + '\uA68C' | + '\uA68E' | + '\uA690' | + '\uA692' | + '\uA694' | + '\uA696' | + '\uA722' | + '\uA724' | + '\uA726' | + '\uA728' | + '\uA72A' | + '\uA72C' | + '\uA72E' | + '\uA732' | + '\uA734' | + '\uA736' | + '\uA738' | + '\uA73A' | + '\uA73C' | + '\uA73E' | + '\uA740' | + '\uA742' | + '\uA744' | + '\uA746' | + '\uA748' | + '\uA74A' | + '\uA74C' | + '\uA74E' | + '\uA750' | + '\uA752' | + '\uA754' | + '\uA756' | + '\uA758' | + '\uA75A' | + '\uA75C' | + '\uA75E' | + '\uA760' | + '\uA762' | + '\uA764' | + '\uA766' | + '\uA768' | + '\uA76A' | + '\uA76C' | + '\uA76E' | + '\uA779' | + '\uA77B' | + '\uA77D' | + '\uA77E' | + '\uA780' | + '\uA782' | + '\uA784' | + '\uA786' | + '\uA78B' | + '\uA78D' | + '\uA790' | + '\uA792' | + '\uA7A0' | + '\uA7A2' | + '\uA7A4' | + '\uA7A6' | + '\uA7A8' | + '\uA7AA' | + '\uFF21'..'\uFF3A'; + +UNICODE_CLASS_ND: + '\u0030'..'\u0039' | + '\u0660'..'\u0669' | + '\u06F0'..'\u06F9' | + '\u07C0'..'\u07C9' | + '\u0966'..'\u096F' | + '\u09E6'..'\u09EF' | + '\u0A66'..'\u0A6F' | + '\u0AE6'..'\u0AEF' | + '\u0B66'..'\u0B6F' | + '\u0BE6'..'\u0BEF' | + '\u0C66'..'\u0C6F' | + '\u0CE6'..'\u0CEF' | + '\u0D66'..'\u0D6F' | + '\u0E50'..'\u0E59' | + '\u0ED0'..'\u0ED9' | + '\u0F20'..'\u0F29' | + '\u1040'..'\u1049' | + '\u1090'..'\u1099' | + '\u17E0'..'\u17E9' | + '\u1810'..'\u1819' | + '\u1946'..'\u194F' | + '\u19D0'..'\u19D9' | + '\u1A80'..'\u1A89' | + '\u1A90'..'\u1A99' | + '\u1B50'..'\u1B59' | + '\u1BB0'..'\u1BB9' | + '\u1C40'..'\u1C49' | + '\u1C50'..'\u1C59' | + '\uA620'..'\uA629' | + '\uA8D0'..'\uA8D9' | + '\uA900'..'\uA909' | + '\uA9D0'..'\uA9D9' | + '\uAA50'..'\uAA59' | + '\uABF0'..'\uABF9' | + '\uFF10'..'\uFF19'; + +UNICODE_CLASS_NL: + '\u16EE'..'\u16F0' | + '\u2160'..'\u2182' | + '\u2185'..'\u2188' | + '\u3007' | + '\u3021'..'\u3029' | + '\u3038'..'\u303A' | + '\uA6E6'..'\uA6EF'; \ No newline at end of file diff --git a/pmd-kotlin/src/main/antlr4/net/sourceforge/pmd/lang/kotlin/ast/UnicodeClasses.tokens b/pmd-kotlin/src/main/antlr4/net/sourceforge/pmd/lang/kotlin/ast/UnicodeClasses.tokens new file mode 100644 index 0000000000..bd91da7e6b --- /dev/null +++ b/pmd-kotlin/src/main/antlr4/net/sourceforge/pmd/lang/kotlin/ast/UnicodeClasses.tokens @@ -0,0 +1,7 @@ +UNICODE_CLASS_LL=1 +UNICODE_CLASS_LM=2 +UNICODE_CLASS_LO=3 +UNICODE_CLASS_LT=4 +UNICODE_CLASS_LU=5 +UNICODE_CLASS_ND=6 +UNICODE_CLASS_NL=7 diff --git a/pmd-kotlin/src/main/resources/META-INF/services/net.sourceforge.pmd.lang.Language b/pmd-kotlin/src/main/resources/META-INF/services/net.sourceforge.pmd.lang.Language new file mode 100644 index 0000000000..78c4e9b40d --- /dev/null +++ b/pmd-kotlin/src/main/resources/META-INF/services/net.sourceforge.pmd.lang.Language @@ -0,0 +1 @@ +net.sourceforge.pmd.lang.kotlin.KotlinLanguageModule diff --git a/pmd-kotlin/src/main/resources/category/kotlin/categories.properties b/pmd-kotlin/src/main/resources/category/kotlin/categories.properties new file mode 100644 index 0000000000..f8ffec58d8 --- /dev/null +++ b/pmd-kotlin/src/main/resources/category/kotlin/categories.properties @@ -0,0 +1,19 @@ +# +# BSD-style license; for more info see http://pmd.sourceforge.net/license.html +# + +rulesets.filenames= + +# +# categories without rules +# + +# category/kotlin/bestpractices.xml,\ +# category/kotlin/errorprone.xml + +# category/kotlin/codestyle.xml +# category/kotlin/design.xml +# category/kotlin/documentation.xml +# category/kotlin/multithreading.xml +# category/kotlin/performance.xml +# category/kotlin/security.xml From d82b245e53371361966e24d7043bbee8bba6b607 Mon Sep 17 00:00:00 2001 From: Andreas Dangel Date: Wed, 8 Sep 2021 20:26:11 +0200 Subject: [PATCH 004/198] Fix typo --- .../major_contributions/adding_a_new_antlr_based_language.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/pages/pmd/devdocs/major_contributions/adding_a_new_antlr_based_language.md b/docs/pages/pmd/devdocs/major_contributions/adding_a_new_antlr_based_language.md index babf8b5812..90cd18a417 100644 --- a/docs/pages/pmd/devdocs/major_contributions/adding_a_new_antlr_based_language.md +++ b/docs/pages/pmd/devdocs/major_contributions/adding_a_new_antlr_based_language.md @@ -24,7 +24,7 @@ folder: pmd/devdocs ## 3. Create AST node classes * The individual AST nodes are generated, but you need to define the common interface for them. -* You need a need to define the supertype interface for all nodes of the language. For that, we provide +* You need to define the supertype interface for all nodes of the language. For that, we provide [`AntlrNode`](https://github.com/pmd/pmd/blob/pmd/7.0.x/pmd-core/src/main/java/net/sourceforge/pmd/lang/ast/impl/antlr4/AntlrNode.java). * See [`SwiftNode`](https://github.com/pmd/pmd/blob/pmd/7.0.x/pmd-swift/src/main/java/net/sourceforge/pmd/lang/swift/ast/SwiftNode.java) as an example. From cde4efb27edc3f4291b0832599e2576ae1521d9a Mon Sep 17 00:00:00 2001 From: jborgers Date: Fri, 10 Sep 2021 17:10:24 +0200 Subject: [PATCH 005/198] Combine KotlinParser, KotlinLexer and UnicodeClasses and use Swift.g4 as example --- .../sourceforge/pmd/lang/kotlin/ast/Kotlin.g4 | 3129 +++++++++++++++++ 1 file changed, 3129 insertions(+) create mode 100755 pmd-kotlin/src/main/antlr4/net/sourceforge/pmd/lang/kotlin/ast/Kotlin.g4 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 new file mode 100755 index 0000000000..3f42bab00a --- /dev/null +++ b/pmd-kotlin/src/main/antlr4/net/sourceforge/pmd/lang/kotlin/ast/Kotlin.g4 @@ -0,0 +1,3129 @@ +/** + * Kotlin parser/syntax grammar + Kotlin lexical grammar + unicode classes lexical grammar in ANTLR4 notation + */ + +grammar Kotlin; + +@header { +import net.sourceforge.pmd.lang.ast.impl.antlr4.*; +import net.sourceforge.pmd.lang.ast.AstVisitor; +} + +@parser::members { + + static final AntlrNameDictionary DICO = new KotlinNameDictionary(VOCABULARY, ruleNames); + + @Override + public KotlinTerminalNode createPmdTerminal(ParserRuleContext parent, Token t) { + return new KotlinTerminalNode(t); + } + + @Override + public KotlinErrorNode createPmdError(ParserRuleContext parent, Token t) { + return new KotlinErrorNode(t); + } +} + +options { + contextSuperClass = 'KotlinInnerNode'; + superClass = 'AntlrGeneratedParserBase'; +} + +/** + * Kotlin syntax grammar in ANTLR4 notation + * from KotlinParser.g4 + */ + +kotlinFile + : shebangLine? NL* fileAnnotation* packageHeader importList topLevelObject* EOF + ; + +script + : shebangLine? NL* fileAnnotation* packageHeader importList (statement semi)* EOF + ; + +shebangLine + : ShebangLine NL+ + ; + +fileAnnotation + : (AT_NO_WS | AT_PRE_WS) FILE NL* COLON NL* (LSQUARE unescapedAnnotation+ RSQUARE | unescapedAnnotation) NL* + ; + +packageHeader + : (PACKAGE identifier semi?)? + ; + +importList + : importHeader* + ; + +importHeader + : IMPORT identifier (DOT MULT | importAlias)? semi? + ; + +importAlias + : AS simpleIdentifier + ; + +topLevelObject + : declaration semis? + ; + +typeAlias + : modifiers? TYPE_ALIAS NL* simpleIdentifier (NL* typeParameters)? NL* ASSIGNMENT NL* type + ; + +declaration + : classDeclaration + | objectDeclaration + | functionDeclaration + | propertyDeclaration + | typeAlias + ; + +// SECTION: classes + +classDeclaration + : modifiers? (CLASS | (FUN NL*)? INTERFACE) NL* simpleIdentifier + (NL* typeParameters)? (NL* primaryConstructor)? + (NL* COLON NL* delegationSpecifiers)? + (NL* typeConstraints)? + (NL* classBody | NL* enumClassBody)? + ; + +primaryConstructor + : (modifiers? CONSTRUCTOR NL*)? classParameters + ; + +classBody + : LCURL NL* classMemberDeclarations NL* RCURL + ; + +classParameters + : LPAREN NL* (classParameter (NL* COMMA NL* classParameter)* (NL* COMMA)?)? NL* RPAREN + ; + +classParameter + : modifiers? (VAL | VAR)? NL* simpleIdentifier COLON NL* type (NL* ASSIGNMENT NL* expression)? + ; + +delegationSpecifiers + : annotatedDelegationSpecifier (NL* COMMA NL* annotatedDelegationSpecifier)* + ; + +delegationSpecifier + : constructorInvocation + | explicitDelegation + | userType + | functionType + ; + +constructorInvocation + : userType valueArguments + ; + +annotatedDelegationSpecifier + : annotation* NL* delegationSpecifier + ; + +explicitDelegation + : (userType | functionType) NL* BY NL* expression + ; + +typeParameters + : LANGLE NL* typeParameter (NL* COMMA NL* typeParameter)* (NL* COMMA)? NL* RANGLE + ; + +typeParameter + : typeParameterModifiers? NL* simpleIdentifier (NL* COLON NL* type)? + ; + +typeConstraints + : WHERE NL* typeConstraint (NL* COMMA NL* typeConstraint)* + ; + +typeConstraint + : annotation* simpleIdentifier NL* COLON NL* type + ; + +// SECTION: classMembers + +classMemberDeclarations + : (classMemberDeclaration semis?)* + ; + +classMemberDeclaration + : declaration + | companionObject + | anonymousInitializer + | secondaryConstructor + ; + +anonymousInitializer + : INIT NL* block + ; + +companionObject + : modifiers? COMPANION NL* OBJECT + (NL* simpleIdentifier)? + (NL* COLON NL* delegationSpecifiers)? + (NL* classBody)? + ; + +functionValueParameters + : LPAREN NL* (functionValueParameter (NL* COMMA NL* functionValueParameter)* (NL* COMMA)?)? NL* RPAREN + ; + +functionValueParameter + : parameterModifiers? parameter (NL* ASSIGNMENT NL* expression)? + ; + +functionDeclaration + : modifiers? + FUN (NL* typeParameters)? (NL* receiverType NL* DOT)? NL* simpleIdentifier + NL* functionValueParameters + (NL* COLON NL* type)? + (NL* typeConstraints)? + (NL* functionBody)? + ; + +functionBody + : block + | ASSIGNMENT NL* expression + ; + +variableDeclaration + : annotation* NL* simpleIdentifier (NL* COLON NL* type)? + ; + +multiVariableDeclaration + : LPAREN NL* variableDeclaration (NL* COMMA NL* variableDeclaration)* (NL* COMMA)? NL* RPAREN + ; + +propertyDeclaration + : modifiers? (VAL | VAR) + (NL* typeParameters)? + (NL* receiverType NL* DOT)? + (NL* (multiVariableDeclaration | variableDeclaration)) + (NL* typeConstraints)? + (NL* (ASSIGNMENT NL* expression | propertyDelegate))? + (NL+ SEMICOLON)? NL* (getter? (NL* semi? setter)? | setter? (NL* semi? getter)?) + ; + +propertyDelegate + : BY NL* expression + ; + +getter + : modifiers? GET + (NL* LPAREN NL* RPAREN (NL* COLON NL* type)? NL* functionBody)? + ; + +setter + : modifiers? SET + (NL* LPAREN NL* functionValueParameterWithOptionalType (NL* COMMA)? NL* RPAREN (NL* COLON NL* type)? NL* functionBody)? + ; + +parametersWithOptionalType + : LPAREN NL* (functionValueParameterWithOptionalType (NL* COMMA NL* functionValueParameterWithOptionalType)* (NL* COMMA)?)? NL* RPAREN + ; + +functionValueParameterWithOptionalType + : parameterModifiers? parameterWithOptionalType (NL* ASSIGNMENT NL* expression)? + ; + +parameterWithOptionalType + : simpleIdentifier NL* (COLON NL* type)? + ; + +parameter + : simpleIdentifier NL* COLON NL* type + ; + +objectDeclaration + : modifiers? OBJECT + NL* simpleIdentifier + (NL* COLON NL* delegationSpecifiers)? + (NL* classBody)? + ; + +secondaryConstructor + : modifiers? CONSTRUCTOR NL* functionValueParameters (NL* COLON NL* constructorDelegationCall)? NL* block? + ; + +constructorDelegationCall + : (THIS | SUPER) NL* valueArguments + ; + +// SECTION: enumClasses + +enumClassBody + : LCURL NL* enumEntries? (NL* SEMICOLON NL* classMemberDeclarations)? NL* RCURL + ; + +enumEntries + : enumEntry (NL* COMMA NL* enumEntry)* NL* COMMA? + ; + +enumEntry + : (modifiers NL*)? simpleIdentifier (NL* valueArguments)? (NL* classBody)? + ; + +// SECTION: types + +type + : typeModifiers? (parenthesizedType | nullableType | typeReference | functionType) + ; + +typeReference + : userType + | DYNAMIC + ; + +nullableType + : (typeReference | parenthesizedType) NL* quest+ + ; + +quest + : QUEST_NO_WS + | QUEST_WS + ; + +userType + : simpleUserType (NL* DOT NL* simpleUserType)* + ; + +simpleUserType + : simpleIdentifier (NL* typeArguments)? + ; + +typeProjection + : typeProjectionModifiers? type + | MULT + ; + +typeProjectionModifiers + : typeProjectionModifier+ + ; + +typeProjectionModifier + : varianceModifier NL* + | annotation + ; + +functionType + : (receiverType NL* DOT NL*)? functionTypeParameters NL* ARROW NL* type + ; + +functionTypeParameters + : LPAREN NL* (parameter | type)? (NL* COMMA NL* (parameter | type))* (NL* COMMA)? NL* RPAREN + ; + +parenthesizedType + : LPAREN NL* type NL* RPAREN + ; + +receiverType + : typeModifiers? (parenthesizedType | nullableType | typeReference) + ; + +parenthesizedUserType + : LPAREN NL* (userType | parenthesizedUserType) NL* RPAREN + ; + +// SECTION: statements + +statements + : (statement (semis statement)*)? semis? + ; + +statement + : (label | annotation)* ( declaration | assignment | loopStatement | expression) + ; + +label + : simpleIdentifier (AT_NO_WS | AT_POST_WS) NL* + ; + +controlStructureBody + : block + | statement + ; + +block + : LCURL NL* statements NL* RCURL + ; + +loopStatement + : forStatement + | whileStatement + | doWhileStatement + ; + +forStatement + : FOR NL* LPAREN annotation* (variableDeclaration | multiVariableDeclaration) + IN expression RPAREN NL* controlStructureBody? + ; + +whileStatement + : WHILE NL* LPAREN expression RPAREN NL* (controlStructureBody | SEMICOLON) + ; + +doWhileStatement + : DO NL* controlStructureBody? NL* WHILE NL* LPAREN expression RPAREN + ; + +assignment + : (directlyAssignableExpression ASSIGNMENT | assignableExpression assignmentAndOperator) NL* expression + ; + +semi + : (SEMICOLON | NL) NL* + | EOF + ; + +semis + : (SEMICOLON | NL)+ + | EOF + ; + +// SECTION: expressions + +expression + : disjunction + ; + +disjunction + : conjunction (NL* DISJ NL* conjunction)* + ; + +conjunction + : equality (NL* CONJ NL* equality)* + ; + +equality + : comparison (equalityOperator NL* comparison)* + ; + +comparison + : genericCallLikeComparison (comparisonOperator NL* genericCallLikeComparison)* + ; + +genericCallLikeComparison + : infixOperation callSuffix* + ; + +infixOperation + : elvisExpression (inOperator NL* elvisExpression | isOperator NL* type)* + ; + +elvisExpression + : infixFunctionCall (NL* elvis NL* infixFunctionCall)* + ; + +elvis + : QUEST_NO_WS COLON + ; + +infixFunctionCall + : rangeExpression (simpleIdentifier NL* rangeExpression)* + ; + +rangeExpression + : additiveExpression (RANGE NL* additiveExpression)* + ; + +additiveExpression + : multiplicativeExpression (additiveOperator NL* multiplicativeExpression)* + ; + +multiplicativeExpression + : asExpression (multiplicativeOperator NL* asExpression)* + ; + +asExpression + : prefixUnaryExpression (NL* asOperator NL* type)* + ; + +prefixUnaryExpression + : unaryPrefix* postfixUnaryExpression + ; + +unaryPrefix + : annotation + | label + | prefixUnaryOperator NL* + ; + +postfixUnaryExpression + : primaryExpression postfixUnarySuffix* + ; + +postfixUnarySuffix + : postfixUnaryOperator + | typeArguments + | callSuffix + | indexingSuffix + | navigationSuffix + ; + +directlyAssignableExpression + : postfixUnaryExpression assignableSuffix + | simpleIdentifier + | parenthesizedDirectlyAssignableExpression + ; + +parenthesizedDirectlyAssignableExpression + : LPAREN NL* directlyAssignableExpression NL* RPAREN + ; + +assignableExpression + : prefixUnaryExpression + | parenthesizedAssignableExpression + ; + +parenthesizedAssignableExpression + : LPAREN NL* assignableExpression NL* RPAREN + ; + +assignableSuffix + : typeArguments + | indexingSuffix + | navigationSuffix + ; + +indexingSuffix + : LSQUARE NL* expression (NL* COMMA NL* expression)* (NL* COMMA)? NL* RSQUARE + ; + +navigationSuffix + : memberAccessOperator NL* (simpleIdentifier | parenthesizedExpression | CLASS) + ; + +callSuffix + : typeArguments? (valueArguments? annotatedLambda | valueArguments) + ; + +annotatedLambda + : annotation* label? NL* lambdaLiteral + ; + +typeArguments + : LANGLE NL* typeProjection (NL* COMMA NL* typeProjection)* (NL* COMMA)? NL* RANGLE + ; + +valueArguments + : LPAREN NL* (valueArgument (NL* COMMA NL* valueArgument)* (NL* COMMA)? NL*)? RPAREN + ; + +valueArgument + : annotation? NL* (simpleIdentifier NL* ASSIGNMENT NL*)? MULT? NL* expression + ; + +primaryExpression + : parenthesizedExpression + | simpleIdentifier + | literalConstant + | stringLiteral + | callableReference + | functionLiteral + | objectLiteral + | collectionLiteral + | thisExpression + | superExpression + | ifExpression + | whenExpression + | tryExpression + | jumpExpression + ; + +parenthesizedExpression + : LPAREN NL* expression NL* RPAREN + ; + +collectionLiteral + : LSQUARE NL* (expression (NL* COMMA NL* expression)* (NL* COMMA)? NL*)? RSQUARE + ; + +literalConstant + : BooleanLiteral + | IntegerLiteral + | HexLiteral + | BinLiteral + | CharacterLiteral + | RealLiteral + | NullLiteral + | LongLiteral + | UnsignedLiteral + ; + +stringLiteral + : lineStringLiteral + | multiLineStringLiteral + ; + +lineStringLiteral + : QUOTE_OPEN (lineStringContent | lineStringExpression)* QUOTE_CLOSE + ; + +multiLineStringLiteral + : TRIPLE_QUOTE_OPEN (multiLineStringContent | multiLineStringExpression | MultiLineStringQuote)* TRIPLE_QUOTE_CLOSE + ; + +lineStringContent + : LineStrText + | LineStrEscapedChar + | LineStrRef + ; + +lineStringExpression + : LineStrExprStart NL* expression NL* RCURL + ; + +multiLineStringContent + : MultiLineStrText + | MultiLineStringQuote + | MultiLineStrRef + ; + +multiLineStringExpression + : MultiLineStrExprStart NL* expression NL* RCURL + ; + +lambdaLiteral + : LCURL NL* (lambdaParameters? NL* ARROW NL*)? statements NL* RCURL + ; + +lambdaParameters + : lambdaParameter (NL* COMMA NL* lambdaParameter)* (NL* COMMA)? + ; + +lambdaParameter + : variableDeclaration + | multiVariableDeclaration (NL* COLON NL* type)? + ; + +anonymousFunction + : FUN + (NL* type NL* DOT)? + NL* parametersWithOptionalType + (NL* COLON NL* type)? + (NL* typeConstraints)? + (NL* functionBody)? + ; + +functionLiteral + : lambdaLiteral + | anonymousFunction + ; + +objectLiteral + : OBJECT (NL* COLON NL* delegationSpecifiers NL*)? (NL* classBody)? + ; + +thisExpression + : THIS + | THIS_AT + ; + +superExpression + : SUPER (LANGLE NL* type NL* RANGLE)? (AT_NO_WS simpleIdentifier)? + | SUPER_AT + ; + +ifExpression + : IF NL* LPAREN NL* expression NL* RPAREN NL* + ( controlStructureBody + | controlStructureBody? NL* SEMICOLON? NL* ELSE NL* (controlStructureBody | SEMICOLON) + | SEMICOLON) + ; + +whenSubject + : LPAREN (annotation* NL* VAL NL* variableDeclaration NL* ASSIGNMENT NL*)? expression RPAREN + ; + +whenExpression + : WHEN NL* whenSubject? NL* LCURL NL* (whenEntry NL*)* NL* RCURL + ; + +whenEntry + : whenCondition (NL* COMMA NL* whenCondition)* (NL* COMMA)? NL* ARROW NL* controlStructureBody semi? + | ELSE NL* ARROW NL* controlStructureBody semi? + ; + +whenCondition + : expression + | rangeTest + | typeTest + ; + +rangeTest + : inOperator NL* expression + ; + +typeTest + : isOperator NL* type + ; + +tryExpression + : TRY NL* block ((NL* catchBlock)+ (NL* finallyBlock)? | NL* finallyBlock) + ; + +catchBlock + : CATCH NL* LPAREN annotation* simpleIdentifier COLON type (NL* COMMA)? RPAREN NL* block + ; + +finallyBlock + : FINALLY NL* block + ; + +jumpExpression + : THROW NL* expression + | (RETURN | RETURN_AT) expression? + | CONTINUE + | CONTINUE_AT + | BREAK + | BREAK_AT + ; + +callableReference + : receiverType? COLONCOLON NL* (simpleIdentifier | CLASS) + ; + +assignmentAndOperator + : ADD_ASSIGNMENT + | SUB_ASSIGNMENT + | MULT_ASSIGNMENT + | DIV_ASSIGNMENT + | MOD_ASSIGNMENT + ; + +equalityOperator + : EXCL_EQ + | EXCL_EQEQ + | EQEQ + | EQEQEQ + ; + +comparisonOperator + : LANGLE + | RANGLE + | LE + | GE + ; + +inOperator + : IN + | NOT_IN + ; + +isOperator + : IS + | NOT_IS + ; + +additiveOperator + : ADD + | SUB + ; + +multiplicativeOperator + : MULT + | DIV + | MOD + ; + +asOperator + : AS + | AS_SAFE + ; + +prefixUnaryOperator + : INCR + | DECR + | SUB + | ADD + | excl + ; + +postfixUnaryOperator + : INCR + | DECR + | EXCL_NO_WS excl + ; + +excl + : EXCL_NO_WS + | EXCL_WS + ; + +memberAccessOperator + : NL* DOT + | NL* safeNav + | COLONCOLON + ; + +safeNav + : QUEST_NO_WS DOT + ; + +// SECTION: modifiers + +modifiers + : (annotation | modifier)+ + ; + +parameterModifiers + : (annotation | parameterModifier)+ + ; + +modifier + : (classModifier + | memberModifier + | visibilityModifier + | functionModifier + | propertyModifier + | inheritanceModifier + | parameterModifier + | platformModifier) NL* + ; + +typeModifiers + : typeModifier+ + ; + +typeModifier + : annotation + | SUSPEND NL* + ; + +classModifier + : ENUM + | SEALED + | ANNOTATION + | DATA + | INNER + | VALUE + ; + +memberModifier + : OVERRIDE + | LATEINIT + ; + +visibilityModifier + : PUBLIC + | PRIVATE + | INTERNAL + | PROTECTED + ; + +varianceModifier + : IN + | OUT + ; + +typeParameterModifiers + : typeParameterModifier+ + ; + +typeParameterModifier + : reificationModifier NL* + | varianceModifier NL* + | annotation + ; + +functionModifier + : TAILREC + | OPERATOR + | INFIX + | INLINE + | EXTERNAL + | SUSPEND + ; + +propertyModifier + : CONST + ; + +inheritanceModifier + : ABSTRACT + | FINAL + | OPEN + ; + +parameterModifier + : VARARG + | NOINLINE + | CROSSINLINE + ; + +reificationModifier + : REIFIED + ; + +platformModifier + : EXPECT + | ACTUAL + ; + +// SECTION: annotations + +annotation + : (singleAnnotation | multiAnnotation) NL* + ; + +singleAnnotation + : (annotationUseSiteTarget NL* | AT_NO_WS | AT_PRE_WS) unescapedAnnotation + ; + +multiAnnotation + : (annotationUseSiteTarget NL* | AT_NO_WS | AT_PRE_WS) LSQUARE unescapedAnnotation+ RSQUARE + ; + +annotationUseSiteTarget + : (AT_NO_WS | AT_PRE_WS) (FIELD | PROPERTY | GET | SET | RECEIVER | PARAM | SETPARAM | DELEGATE) NL* COLON + ; + +unescapedAnnotation + : constructorInvocation + | userType + ; + +// SECTION: identifiers + +simpleIdentifier + : Identifier + | ABSTRACT + | ANNOTATION + | BY + | CATCH + | COMPANION + | CONSTRUCTOR + | CROSSINLINE + | DATA + | DYNAMIC + | ENUM + | EXTERNAL + | FINAL + | FINALLY + | GET + | IMPORT + | INFIX + | INIT + | INLINE + | INNER + | INTERNAL + | LATEINIT + | NOINLINE + | OPEN + | OPERATOR + | OUT + | OVERRIDE + | PRIVATE + | PROTECTED + | PUBLIC + | REIFIED + | SEALED + | TAILREC + | SET + | VARARG + | WHERE + | FIELD + | PROPERTY + | RECEIVER + | PARAM + | SETPARAM + | DELEGATE + | FILE + | EXPECT + | ACTUAL + | CONST + | SUSPEND + | VALUE + ; + +identifier + : simpleIdentifier (NL* DOT simpleIdentifier)* + ; + + + +/** + * Kotlin lexical grammar in ANTLR4 notation (Unicode classes) + * + * Taken from http://www.antlr3.org/grammar/1345144569663/AntlrUnicode.txt + * + * from UnicodeClasses.g4 + */ + + +UNICODE_CLASS_LL: + '\u0061'..'\u007A' | + '\u00B5' | + '\u00DF'..'\u00F6' | + '\u00F8'..'\u00FF' | + '\u0101' | + '\u0103' | + '\u0105' | + '\u0107' | + '\u0109' | + '\u010B' | + '\u010D' | + '\u010F' | + '\u0111' | + '\u0113' | + '\u0115' | + '\u0117' | + '\u0119' | + '\u011B' | + '\u011D' | + '\u011F' | + '\u0121' | + '\u0123' | + '\u0125' | + '\u0127' | + '\u0129' | + '\u012B' | + '\u012D' | + '\u012F' | + '\u0131' | + '\u0133' | + '\u0135' | + '\u0137' | + '\u0138' | + '\u013A' | + '\u013C' | + '\u013E' | + '\u0140' | + '\u0142' | + '\u0144' | + '\u0146' | + '\u0148' | + '\u0149' | + '\u014B' | + '\u014D' | + '\u014F' | + '\u0151' | + '\u0153' | + '\u0155' | + '\u0157' | + '\u0159' | + '\u015B' | + '\u015D' | + '\u015F' | + '\u0161' | + '\u0163' | + '\u0165' | + '\u0167' | + '\u0169' | + '\u016B' | + '\u016D' | + '\u016F' | + '\u0171' | + '\u0173' | + '\u0175' | + '\u0177' | + '\u017A' | + '\u017C' | + '\u017E'..'\u0180' | + '\u0183' | + '\u0185' | + '\u0188' | + '\u018C' | + '\u018D' | + '\u0192' | + '\u0195' | + '\u0199'..'\u019B' | + '\u019E' | + '\u01A1' | + '\u01A3' | + '\u01A5' | + '\u01A8' | + '\u01AA' | + '\u01AB' | + '\u01AD' | + '\u01B0' | + '\u01B4' | + '\u01B6' | + '\u01B9' | + '\u01BA' | + '\u01BD'..'\u01BF' | + '\u01C6' | + '\u01C9' | + '\u01CC' | + '\u01CE' | + '\u01D0' | + '\u01D2' | + '\u01D4' | + '\u01D6' | + '\u01D8' | + '\u01DA' | + '\u01DC' | + '\u01DD' | + '\u01DF' | + '\u01E1' | + '\u01E3' | + '\u01E5' | + '\u01E7' | + '\u01E9' | + '\u01EB' | + '\u01ED' | + '\u01EF' | + '\u01F0' | + '\u01F3' | + '\u01F5' | + '\u01F9' | + '\u01FB' | + '\u01FD' | + '\u01FF' | + '\u0201' | + '\u0203' | + '\u0205' | + '\u0207' | + '\u0209' | + '\u020B' | + '\u020D' | + '\u020F' | + '\u0211' | + '\u0213' | + '\u0215' | + '\u0217' | + '\u0219' | + '\u021B' | + '\u021D' | + '\u021F' | + '\u0221' | + '\u0223' | + '\u0225' | + '\u0227' | + '\u0229' | + '\u022B' | + '\u022D' | + '\u022F' | + '\u0231' | + '\u0233'..'\u0239' | + '\u023C' | + '\u023F' | + '\u0240' | + '\u0242' | + '\u0247' | + '\u0249' | + '\u024B' | + '\u024D' | + '\u024F'..'\u0293' | + '\u0295'..'\u02AF' | + '\u0371' | + '\u0373' | + '\u0377' | + '\u037B'..'\u037D' | + '\u0390' | + '\u03AC'..'\u03CE' | + '\u03D0' | + '\u03D1' | + '\u03D5'..'\u03D7' | + '\u03D9' | + '\u03DB' | + '\u03DD' | + '\u03DF' | + '\u03E1' | + '\u03E3' | + '\u03E5' | + '\u03E7' | + '\u03E9' | + '\u03EB' | + '\u03ED' | + '\u03EF'..'\u03F3' | + '\u03F5' | + '\u03F8' | + '\u03FB' | + '\u03FC' | + '\u0430'..'\u045F' | + '\u0461' | + '\u0463' | + '\u0465' | + '\u0467' | + '\u0469' | + '\u046B' | + '\u046D' | + '\u046F' | + '\u0471' | + '\u0473' | + '\u0475' | + '\u0477' | + '\u0479' | + '\u047B' | + '\u047D' | + '\u047F' | + '\u0481' | + '\u048B' | + '\u048D' | + '\u048F' | + '\u0491' | + '\u0493' | + '\u0495' | + '\u0497' | + '\u0499' | + '\u049B' | + '\u049D' | + '\u049F' | + '\u04A1' | + '\u04A3' | + '\u04A5' | + '\u04A7' | + '\u04A9' | + '\u04AB' | + '\u04AD' | + '\u04AF' | + '\u04B1' | + '\u04B3' | + '\u04B5' | + '\u04B7' | + '\u04B9' | + '\u04BB' | + '\u04BD' | + '\u04BF' | + '\u04C2' | + '\u04C4' | + '\u04C6' | + '\u04C8' | + '\u04CA' | + '\u04CC' | + '\u04CE' | + '\u04CF' | + '\u04D1' | + '\u04D3' | + '\u04D5' | + '\u04D7' | + '\u04D9' | + '\u04DB' | + '\u04DD' | + '\u04DF' | + '\u04E1' | + '\u04E3' | + '\u04E5' | + '\u04E7' | + '\u04E9' | + '\u04EB' | + '\u04ED' | + '\u04EF' | + '\u04F1' | + '\u04F3' | + '\u04F5' | + '\u04F7' | + '\u04F9' | + '\u04FB' | + '\u04FD' | + '\u04FF' | + '\u0501' | + '\u0503' | + '\u0505' | + '\u0507' | + '\u0509' | + '\u050B' | + '\u050D' | + '\u050F' | + '\u0511' | + '\u0513' | + '\u0515' | + '\u0517' | + '\u0519' | + '\u051B' | + '\u051D' | + '\u051F' | + '\u0521' | + '\u0523' | + '\u0525' | + '\u0527' | + '\u0561'..'\u0587' | + '\u1D00'..'\u1D2B' | + '\u1D6B'..'\u1D77' | + '\u1D79'..'\u1D9A' | + '\u1E01' | + '\u1E03' | + '\u1E05' | + '\u1E07' | + '\u1E09' | + '\u1E0B' | + '\u1E0D' | + '\u1E0F' | + '\u1E11' | + '\u1E13' | + '\u1E15' | + '\u1E17' | + '\u1E19' | + '\u1E1B' | + '\u1E1D' | + '\u1E1F' | + '\u1E21' | + '\u1E23' | + '\u1E25' | + '\u1E27' | + '\u1E29' | + '\u1E2B' | + '\u1E2D' | + '\u1E2F' | + '\u1E31' | + '\u1E33' | + '\u1E35' | + '\u1E37' | + '\u1E39' | + '\u1E3B' | + '\u1E3D' | + '\u1E3F' | + '\u1E41' | + '\u1E43' | + '\u1E45' | + '\u1E47' | + '\u1E49' | + '\u1E4B' | + '\u1E4D' | + '\u1E4F' | + '\u1E51' | + '\u1E53' | + '\u1E55' | + '\u1E57' | + '\u1E59' | + '\u1E5B' | + '\u1E5D' | + '\u1E5F' | + '\u1E61' | + '\u1E63' | + '\u1E65' | + '\u1E67' | + '\u1E69' | + '\u1E6B' | + '\u1E6D' | + '\u1E6F' | + '\u1E71' | + '\u1E73' | + '\u1E75' | + '\u1E77' | + '\u1E79' | + '\u1E7B' | + '\u1E7D' | + '\u1E7F' | + '\u1E81' | + '\u1E83' | + '\u1E85' | + '\u1E87' | + '\u1E89' | + '\u1E8B' | + '\u1E8D' | + '\u1E8F' | + '\u1E91' | + '\u1E93' | + '\u1E95'..'\u1E9D' | + '\u1E9F' | + '\u1EA1' | + '\u1EA3' | + '\u1EA5' | + '\u1EA7' | + '\u1EA9' | + '\u1EAB' | + '\u1EAD' | + '\u1EAF' | + '\u1EB1' | + '\u1EB3' | + '\u1EB5' | + '\u1EB7' | + '\u1EB9' | + '\u1EBB' | + '\u1EBD' | + '\u1EBF' | + '\u1EC1' | + '\u1EC3' | + '\u1EC5' | + '\u1EC7' | + '\u1EC9' | + '\u1ECB' | + '\u1ECD' | + '\u1ECF' | + '\u1ED1' | + '\u1ED3' | + '\u1ED5' | + '\u1ED7' | + '\u1ED9' | + '\u1EDB' | + '\u1EDD' | + '\u1EDF' | + '\u1EE1' | + '\u1EE3' | + '\u1EE5' | + '\u1EE7' | + '\u1EE9' | + '\u1EEB' | + '\u1EED' | + '\u1EEF' | + '\u1EF1' | + '\u1EF3' | + '\u1EF5' | + '\u1EF7' | + '\u1EF9' | + '\u1EFB' | + '\u1EFD' | + '\u1EFF'..'\u1F07' | + '\u1F10'..'\u1F15' | + '\u1F20'..'\u1F27' | + '\u1F30'..'\u1F37' | + '\u1F40'..'\u1F45' | + '\u1F50'..'\u1F57' | + '\u1F60'..'\u1F67' | + '\u1F70'..'\u1F7D' | + '\u1F80'..'\u1F87' | + '\u1F90'..'\u1F97' | + '\u1FA0'..'\u1FA7' | + '\u1FB0'..'\u1FB4' | + '\u1FB6' | + '\u1FB7' | + '\u1FBE' | + '\u1FC2'..'\u1FC4' | + '\u1FC6' | + '\u1FC7' | + '\u1FD0'..'\u1FD3' | + '\u1FD6' | + '\u1FD7' | + '\u1FE0'..'\u1FE7' | + '\u1FF2'..'\u1FF4' | + '\u1FF6' | + '\u1FF7' | + '\u210A' | + '\u210E' | + '\u210F' | + '\u2113' | + '\u212F' | + '\u2134' | + '\u2139' | + '\u213C' | + '\u213D' | + '\u2146'..'\u2149' | + '\u214E' | + '\u2184' | + '\u2C30'..'\u2C5E' | + '\u2C61' | + '\u2C65' | + '\u2C66' | + '\u2C68' | + '\u2C6A' | + '\u2C6C' | + '\u2C71' | + '\u2C73' | + '\u2C74' | + '\u2C76'..'\u2C7B' | + '\u2C81' | + '\u2C83' | + '\u2C85' | + '\u2C87' | + '\u2C89' | + '\u2C8B' | + '\u2C8D' | + '\u2C8F' | + '\u2C91' | + '\u2C93' | + '\u2C95' | + '\u2C97' | + '\u2C99' | + '\u2C9B' | + '\u2C9D' | + '\u2C9F' | + '\u2CA1' | + '\u2CA3' | + '\u2CA5' | + '\u2CA7' | + '\u2CA9' | + '\u2CAB' | + '\u2CAD' | + '\u2CAF' | + '\u2CB1' | + '\u2CB3' | + '\u2CB5' | + '\u2CB7' | + '\u2CB9' | + '\u2CBB' | + '\u2CBD' | + '\u2CBF' | + '\u2CC1' | + '\u2CC3' | + '\u2CC5' | + '\u2CC7' | + '\u2CC9' | + '\u2CCB' | + '\u2CCD' | + '\u2CCF' | + '\u2CD1' | + '\u2CD3' | + '\u2CD5' | + '\u2CD7' | + '\u2CD9' | + '\u2CDB' | + '\u2CDD' | + '\u2CDF' | + '\u2CE1' | + '\u2CE3' | + '\u2CE4' | + '\u2CEC' | + '\u2CEE' | + '\u2CF3' | + '\u2D00'..'\u2D25' | + '\u2D27' | + '\u2D2D' | + '\uA641' | + '\uA643' | + '\uA645' | + '\uA647' | + '\uA649' | + '\uA64B' | + '\uA64D' | + '\uA64F' | + '\uA651' | + '\uA653' | + '\uA655' | + '\uA657' | + '\uA659' | + '\uA65B' | + '\uA65D' | + '\uA65F' | + '\uA661' | + '\uA663' | + '\uA665' | + '\uA667' | + '\uA669' | + '\uA66B' | + '\uA66D' | + '\uA681' | + '\uA683' | + '\uA685' | + '\uA687' | + '\uA689' | + '\uA68B' | + '\uA68D' | + '\uA68F' | + '\uA691' | + '\uA693' | + '\uA695' | + '\uA697' | + '\uA723' | + '\uA725' | + '\uA727' | + '\uA729' | + '\uA72B' | + '\uA72D' | + '\uA72F'..'\uA731' | + '\uA733' | + '\uA735' | + '\uA737' | + '\uA739' | + '\uA73B' | + '\uA73D' | + '\uA73F' | + '\uA741' | + '\uA743' | + '\uA745' | + '\uA747' | + '\uA749' | + '\uA74B' | + '\uA74D' | + '\uA74F' | + '\uA751' | + '\uA753' | + '\uA755' | + '\uA757' | + '\uA759' | + '\uA75B' | + '\uA75D' | + '\uA75F' | + '\uA761' | + '\uA763' | + '\uA765' | + '\uA767' | + '\uA769' | + '\uA76B' | + '\uA76D' | + '\uA76F' | + '\uA771'..'\uA778' | + '\uA77A' | + '\uA77C' | + '\uA77F' | + '\uA781' | + '\uA783' | + '\uA785' | + '\uA787' | + '\uA78C' | + '\uA78E' | + '\uA791' | + '\uA793' | + '\uA7A1' | + '\uA7A3' | + '\uA7A5' | + '\uA7A7' | + '\uA7A9' | + '\uA7FA' | + '\uFB00'..'\uFB06' | + '\uFB13'..'\uFB17' | + '\uFF41'..'\uFF5A'; + +UNICODE_CLASS_LM: + '\u02B0'..'\u02C1' | + '\u02C6'..'\u02D1' | + '\u02E0'..'\u02E4' | + '\u02EC' | + '\u02EE' | + '\u0374' | + '\u037A' | + '\u0559' | + '\u0640' | + '\u06E5' | + '\u06E6' | + '\u07F4' | + '\u07F5' | + '\u07FA' | + '\u081A' | + '\u0824' | + '\u0828' | + '\u0971' | + '\u0E46' | + '\u0EC6' | + '\u10FC' | + '\u17D7' | + '\u1843' | + '\u1AA7' | + '\u1C78'..'\u1C7D' | + '\u1D2C'..'\u1D6A' | + '\u1D78' | + '\u1D9B'..'\u1DBF' | + '\u2071' | + '\u207F' | + '\u2090'..'\u209C' | + '\u2C7C' | + '\u2C7D' | + '\u2D6F' | + '\u2E2F' | + '\u3005' | + '\u3031'..'\u3035' | + '\u303B' | + '\u309D' | + '\u309E' | + '\u30FC'..'\u30FE' | + '\uA015' | + '\uA4F8'..'\uA4FD' | + '\uA60C' | + '\uA67F' | + '\uA717'..'\uA71F' | + '\uA770' | + '\uA788' | + '\uA7F8' | + '\uA7F9' | + '\uA9CF' | + '\uAA70' | + '\uAADD' | + '\uAAF3' | + '\uAAF4' | + '\uFF70' | + '\uFF9E' | + '\uFF9F'; + +UNICODE_CLASS_LO: + '\u00AA' | + '\u00BA' | + '\u01BB' | + '\u01C0'..'\u01C3' | + '\u0294' | + '\u05D0'..'\u05EA' | + '\u05F0'..'\u05F2' | + '\u0620'..'\u063F' | + '\u0641'..'\u064A' | + '\u066E' | + '\u066F' | + '\u0671'..'\u06D3' | + '\u06D5' | + '\u06EE' | + '\u06EF' | + '\u06FA'..'\u06FC' | + '\u06FF' | + '\u0710' | + '\u0712'..'\u072F' | + '\u074D'..'\u07A5' | + '\u07B1' | + '\u07CA'..'\u07EA' | + '\u0800'..'\u0815' | + '\u0840'..'\u0858' | + '\u08A0' | + '\u08A2'..'\u08AC' | + '\u0904'..'\u0939' | + '\u093D' | + '\u0950' | + '\u0958'..'\u0961' | + '\u0972'..'\u0977' | + '\u0979'..'\u097F' | + '\u0985'..'\u098C' | + '\u098F' | + '\u0990' | + '\u0993'..'\u09A8' | + '\u09AA'..'\u09B0' | + '\u09B2' | + '\u09B6'..'\u09B9' | + '\u09BD' | + '\u09CE' | + '\u09DC' | + '\u09DD' | + '\u09DF'..'\u09E1' | + '\u09F0' | + '\u09F1' | + '\u0A05'..'\u0A0A' | + '\u0A0F' | + '\u0A10' | + '\u0A13'..'\u0A28' | + '\u0A2A'..'\u0A30' | + '\u0A32' | + '\u0A33' | + '\u0A35' | + '\u0A36' | + '\u0A38' | + '\u0A39' | + '\u0A59'..'\u0A5C' | + '\u0A5E' | + '\u0A72'..'\u0A74' | + '\u0A85'..'\u0A8D' | + '\u0A8F'..'\u0A91' | + '\u0A93'..'\u0AA8' | + '\u0AAA'..'\u0AB0' | + '\u0AB2' | + '\u0AB3' | + '\u0AB5'..'\u0AB9' | + '\u0ABD' | + '\u0AD0' | + '\u0AE0' | + '\u0AE1' | + '\u0B05'..'\u0B0C' | + '\u0B0F' | + '\u0B10' | + '\u0B13'..'\u0B28' | + '\u0B2A'..'\u0B30' | + '\u0B32' | + '\u0B33' | + '\u0B35'..'\u0B39' | + '\u0B3D' | + '\u0B5C' | + '\u0B5D' | + '\u0B5F'..'\u0B61' | + '\u0B71' | + '\u0B83' | + '\u0B85'..'\u0B8A' | + '\u0B8E'..'\u0B90' | + '\u0B92'..'\u0B95' | + '\u0B99' | + '\u0B9A' | + '\u0B9C' | + '\u0B9E' | + '\u0B9F' | + '\u0BA3' | + '\u0BA4' | + '\u0BA8'..'\u0BAA' | + '\u0BAE'..'\u0BB9' | + '\u0BD0' | + '\u0C05'..'\u0C0C' | + '\u0C0E'..'\u0C10' | + '\u0C12'..'\u0C28' | + '\u0C2A'..'\u0C33' | + '\u0C35'..'\u0C39' | + '\u0C3D' | + '\u0C58' | + '\u0C59' | + '\u0C60' | + '\u0C61' | + '\u0C85'..'\u0C8C' | + '\u0C8E'..'\u0C90' | + '\u0C92'..'\u0CA8' | + '\u0CAA'..'\u0CB3' | + '\u0CB5'..'\u0CB9' | + '\u0CBD' | + '\u0CDE' | + '\u0CE0' | + '\u0CE1' | + '\u0CF1' | + '\u0CF2' | + '\u0D05'..'\u0D0C' | + '\u0D0E'..'\u0D10' | + '\u0D12'..'\u0D3A' | + '\u0D3D' | + '\u0D4E' | + '\u0D60' | + '\u0D61' | + '\u0D7A'..'\u0D7F' | + '\u0D85'..'\u0D96' | + '\u0D9A'..'\u0DB1' | + '\u0DB3'..'\u0DBB' | + '\u0DBD' | + '\u0DC0'..'\u0DC6' | + '\u0E01'..'\u0E30' | + '\u0E32' | + '\u0E33' | + '\u0E40'..'\u0E45' | + '\u0E81' | + '\u0E82' | + '\u0E84' | + '\u0E87' | + '\u0E88' | + '\u0E8A' | + '\u0E8D' | + '\u0E94'..'\u0E97' | + '\u0E99'..'\u0E9F' | + '\u0EA1'..'\u0EA3' | + '\u0EA5' | + '\u0EA7' | + '\u0EAA' | + '\u0EAB' | + '\u0EAD'..'\u0EB0' | + '\u0EB2' | + '\u0EB3' | + '\u0EBD' | + '\u0EC0'..'\u0EC4' | + '\u0EDC'..'\u0EDF' | + '\u0F00' | + '\u0F40'..'\u0F47' | + '\u0F49'..'\u0F6C' | + '\u0F88'..'\u0F8C' | + '\u1000'..'\u102A' | + '\u103F' | + '\u1050'..'\u1055' | + '\u105A'..'\u105D' | + '\u1061' | + '\u1065' | + '\u1066' | + '\u106E'..'\u1070' | + '\u1075'..'\u1081' | + '\u108E' | + '\u10D0'..'\u10FA' | + '\u10FD'..'\u1248' | + '\u124A'..'\u124D' | + '\u1250'..'\u1256' | + '\u1258' | + '\u125A'..'\u125D' | + '\u1260'..'\u1288' | + '\u128A'..'\u128D' | + '\u1290'..'\u12B0' | + '\u12B2'..'\u12B5' | + '\u12B8'..'\u12BE' | + '\u12C0' | + '\u12C2'..'\u12C5' | + '\u12C8'..'\u12D6' | + '\u12D8'..'\u1310' | + '\u1312'..'\u1315' | + '\u1318'..'\u135A' | + '\u1380'..'\u138F' | + '\u13A0'..'\u13F4' | + '\u1401'..'\u166C' | + '\u166F'..'\u167F' | + '\u1681'..'\u169A' | + '\u16A0'..'\u16EA' | + '\u1700'..'\u170C' | + '\u170E'..'\u1711' | + '\u1720'..'\u1731' | + '\u1740'..'\u1751' | + '\u1760'..'\u176C' | + '\u176E'..'\u1770' | + '\u1780'..'\u17B3' | + '\u17DC' | + '\u1820'..'\u1842' | + '\u1844'..'\u1877' | + '\u1880'..'\u18A8' | + '\u18AA' | + '\u18B0'..'\u18F5' | + '\u1900'..'\u191C' | + '\u1950'..'\u196D' | + '\u1970'..'\u1974' | + '\u1980'..'\u19AB' | + '\u19C1'..'\u19C7' | + '\u1A00'..'\u1A16' | + '\u1A20'..'\u1A54' | + '\u1B05'..'\u1B33' | + '\u1B45'..'\u1B4B' | + '\u1B83'..'\u1BA0' | + '\u1BAE' | + '\u1BAF' | + '\u1BBA'..'\u1BE5' | + '\u1C00'..'\u1C23' | + '\u1C4D'..'\u1C4F' | + '\u1C5A'..'\u1C77' | + '\u1CE9'..'\u1CEC' | + '\u1CEE'..'\u1CF1' | + '\u1CF5' | + '\u1CF6' | + '\u2135'..'\u2138' | + '\u2D30'..'\u2D67' | + '\u2D80'..'\u2D96' | + '\u2DA0'..'\u2DA6' | + '\u2DA8'..'\u2DAE' | + '\u2DB0'..'\u2DB6' | + '\u2DB8'..'\u2DBE' | + '\u2DC0'..'\u2DC6' | + '\u2DC8'..'\u2DCE' | + '\u2DD0'..'\u2DD6' | + '\u2DD8'..'\u2DDE' | + '\u3006' | + '\u303C' | + '\u3041'..'\u3096' | + '\u309F' | + '\u30A1'..'\u30FA' | + '\u30FF' | + '\u3105'..'\u312D' | + '\u3131'..'\u318E' | + '\u31A0'..'\u31BA' | + '\u31F0'..'\u31FF' | + '\u3400' | + '\u4DB5' | + '\u4E00' | + '\u9FCC' | + '\uA000'..'\uA014' | + '\uA016'..'\uA48C' | + '\uA4D0'..'\uA4F7' | + '\uA500'..'\uA60B' | + '\uA610'..'\uA61F' | + '\uA62A' | + '\uA62B' | + '\uA66E' | + '\uA6A0'..'\uA6E5' | + '\uA7FB'..'\uA801' | + '\uA803'..'\uA805' | + '\uA807'..'\uA80A' | + '\uA80C'..'\uA822' | + '\uA840'..'\uA873' | + '\uA882'..'\uA8B3' | + '\uA8F2'..'\uA8F7' | + '\uA8FB' | + '\uA90A'..'\uA925' | + '\uA930'..'\uA946' | + '\uA960'..'\uA97C' | + '\uA984'..'\uA9B2' | + '\uAA00'..'\uAA28' | + '\uAA40'..'\uAA42' | + '\uAA44'..'\uAA4B' | + '\uAA60'..'\uAA6F' | + '\uAA71'..'\uAA76' | + '\uAA7A' | + '\uAA80'..'\uAAAF' | + '\uAAB1' | + '\uAAB5' | + '\uAAB6' | + '\uAAB9'..'\uAABD' | + '\uAAC0' | + '\uAAC2' | + '\uAADB' | + '\uAADC' | + '\uAAE0'..'\uAAEA' | + '\uAAF2' | + '\uAB01'..'\uAB06' | + '\uAB09'..'\uAB0E' | + '\uAB11'..'\uAB16' | + '\uAB20'..'\uAB26' | + '\uAB28'..'\uAB2E' | + '\uABC0'..'\uABE2' | + '\uAC00' | + '\uD7A3' | + '\uD7B0'..'\uD7C6' | + '\uD7CB'..'\uD7FB' | + '\uF900'..'\uFA6D' | + '\uFA70'..'\uFAD9' | + '\uFB1D' | + '\uFB1F'..'\uFB28' | + '\uFB2A'..'\uFB36' | + '\uFB38'..'\uFB3C' | + '\uFB3E' | + '\uFB40' | + '\uFB41' | + '\uFB43' | + '\uFB44' | + '\uFB46'..'\uFBB1' | + '\uFBD3'..'\uFD3D' | + '\uFD50'..'\uFD8F' | + '\uFD92'..'\uFDC7' | + '\uFDF0'..'\uFDFB' | + '\uFE70'..'\uFE74' | + '\uFE76'..'\uFEFC' | + '\uFF66'..'\uFF6F' | + '\uFF71'..'\uFF9D' | + '\uFFA0'..'\uFFBE' | + '\uFFC2'..'\uFFC7' | + '\uFFCA'..'\uFFCF' | + '\uFFD2'..'\uFFD7' | + '\uFFDA'..'\uFFDC'; + +UNICODE_CLASS_LT: + '\u01C5' | + '\u01C8' | + '\u01CB' | + '\u01F2' | + '\u1F88'..'\u1F8F' | + '\u1F98'..'\u1F9F' | + '\u1FA8'..'\u1FAF' | + '\u1FBC' | + '\u1FCC' | + '\u1FFC'; + +UNICODE_CLASS_LU: + '\u0041'..'\u005A' | + '\u00C0'..'\u00D6' | + '\u00D8'..'\u00DE' | + '\u0100' | + '\u0102' | + '\u0104' | + '\u0106' | + '\u0108' | + '\u010A' | + '\u010C' | + '\u010E' | + '\u0110' | + '\u0112' | + '\u0114' | + '\u0116' | + '\u0118' | + '\u011A' | + '\u011C' | + '\u011E' | + '\u0120' | + '\u0122' | + '\u0124' | + '\u0126' | + '\u0128' | + '\u012A' | + '\u012C' | + '\u012E' | + '\u0130' | + '\u0132' | + '\u0134' | + '\u0136' | + '\u0139' | + '\u013B' | + '\u013D' | + '\u013F' | + '\u0141' | + '\u0143' | + '\u0145' | + '\u0147' | + '\u014A' | + '\u014C' | + '\u014E' | + '\u0150' | + '\u0152' | + '\u0154' | + '\u0156' | + '\u0158' | + '\u015A' | + '\u015C' | + '\u015E' | + '\u0160' | + '\u0162' | + '\u0164' | + '\u0166' | + '\u0168' | + '\u016A' | + '\u016C' | + '\u016E' | + '\u0170' | + '\u0172' | + '\u0174' | + '\u0176' | + '\u0178' | + '\u0179' | + '\u017B' | + '\u017D' | + '\u0181' | + '\u0182' | + '\u0184' | + '\u0186' | + '\u0187' | + '\u0189'..'\u018B' | + '\u018E'..'\u0191' | + '\u0193' | + '\u0194' | + '\u0196'..'\u0198' | + '\u019C' | + '\u019D' | + '\u019F' | + '\u01A0' | + '\u01A2' | + '\u01A4' | + '\u01A6' | + '\u01A7' | + '\u01A9' | + '\u01AC' | + '\u01AE' | + '\u01AF' | + '\u01B1'..'\u01B3' | + '\u01B5' | + '\u01B7' | + '\u01B8' | + '\u01BC' | + '\u01C4' | + '\u01C7' | + '\u01CA' | + '\u01CD' | + '\u01CF' | + '\u01D1' | + '\u01D3' | + '\u01D5' | + '\u01D7' | + '\u01D9' | + '\u01DB' | + '\u01DE' | + '\u01E0' | + '\u01E2' | + '\u01E4' | + '\u01E6' | + '\u01E8' | + '\u01EA' | + '\u01EC' | + '\u01EE' | + '\u01F1' | + '\u01F4' | + '\u01F6'..'\u01F8' | + '\u01FA' | + '\u01FC' | + '\u01FE' | + '\u0200' | + '\u0202' | + '\u0204' | + '\u0206' | + '\u0208' | + '\u020A' | + '\u020C' | + '\u020E' | + '\u0210' | + '\u0212' | + '\u0214' | + '\u0216' | + '\u0218' | + '\u021A' | + '\u021C' | + '\u021E' | + '\u0220' | + '\u0222' | + '\u0224' | + '\u0226' | + '\u0228' | + '\u022A' | + '\u022C' | + '\u022E' | + '\u0230' | + '\u0232' | + '\u023A' | + '\u023B' | + '\u023D' | + '\u023E' | + '\u0241' | + '\u0243'..'\u0246' | + '\u0248' | + '\u024A' | + '\u024C' | + '\u024E' | + '\u0370' | + '\u0372' | + '\u0376' | + '\u0386' | + '\u0388'..'\u038A' | + '\u038C' | + '\u038E' | + '\u038F' | + '\u0391'..'\u03A1' | + '\u03A3'..'\u03AB' | + '\u03CF' | + '\u03D2'..'\u03D4' | + '\u03D8' | + '\u03DA' | + '\u03DC' | + '\u03DE' | + '\u03E0' | + '\u03E2' | + '\u03E4' | + '\u03E6' | + '\u03E8' | + '\u03EA' | + '\u03EC' | + '\u03EE' | + '\u03F4' | + '\u03F7' | + '\u03F9' | + '\u03FA' | + '\u03FD'..'\u042F' | + '\u0460' | + '\u0462' | + '\u0464' | + '\u0466' | + '\u0468' | + '\u046A' | + '\u046C' | + '\u046E' | + '\u0470' | + '\u0472' | + '\u0474' | + '\u0476' | + '\u0478' | + '\u047A' | + '\u047C' | + '\u047E' | + '\u0480' | + '\u048A' | + '\u048C' | + '\u048E' | + '\u0490' | + '\u0492' | + '\u0494' | + '\u0496' | + '\u0498' | + '\u049A' | + '\u049C' | + '\u049E' | + '\u04A0' | + '\u04A2' | + '\u04A4' | + '\u04A6' | + '\u04A8' | + '\u04AA' | + '\u04AC' | + '\u04AE' | + '\u04B0' | + '\u04B2' | + '\u04B4' | + '\u04B6' | + '\u04B8' | + '\u04BA' | + '\u04BC' | + '\u04BE' | + '\u04C0' | + '\u04C1' | + '\u04C3' | + '\u04C5' | + '\u04C7' | + '\u04C9' | + '\u04CB' | + '\u04CD' | + '\u04D0' | + '\u04D2' | + '\u04D4' | + '\u04D6' | + '\u04D8' | + '\u04DA' | + '\u04DC' | + '\u04DE' | + '\u04E0' | + '\u04E2' | + '\u04E4' | + '\u04E6' | + '\u04E8' | + '\u04EA' | + '\u04EC' | + '\u04EE' | + '\u04F0' | + '\u04F2' | + '\u04F4' | + '\u04F6' | + '\u04F8' | + '\u04FA' | + '\u04FC' | + '\u04FE' | + '\u0500' | + '\u0502' | + '\u0504' | + '\u0506' | + '\u0508' | + '\u050A' | + '\u050C' | + '\u050E' | + '\u0510' | + '\u0512' | + '\u0514' | + '\u0516' | + '\u0518' | + '\u051A' | + '\u051C' | + '\u051E' | + '\u0520' | + '\u0522' | + '\u0524' | + '\u0526' | + '\u0531'..'\u0556' | + '\u10A0'..'\u10C5' | + '\u10C7' | + '\u10CD' | + '\u1E00' | + '\u1E02' | + '\u1E04' | + '\u1E06' | + '\u1E08' | + '\u1E0A' | + '\u1E0C' | + '\u1E0E' | + '\u1E10' | + '\u1E12' | + '\u1E14' | + '\u1E16' | + '\u1E18' | + '\u1E1A' | + '\u1E1C' | + '\u1E1E' | + '\u1E20' | + '\u1E22' | + '\u1E24' | + '\u1E26' | + '\u1E28' | + '\u1E2A' | + '\u1E2C' | + '\u1E2E' | + '\u1E30' | + '\u1E32' | + '\u1E34' | + '\u1E36' | + '\u1E38' | + '\u1E3A' | + '\u1E3C' | + '\u1E3E' | + '\u1E40' | + '\u1E42' | + '\u1E44' | + '\u1E46' | + '\u1E48' | + '\u1E4A' | + '\u1E4C' | + '\u1E4E' | + '\u1E50' | + '\u1E52' | + '\u1E54' | + '\u1E56' | + '\u1E58' | + '\u1E5A' | + '\u1E5C' | + '\u1E5E' | + '\u1E60' | + '\u1E62' | + '\u1E64' | + '\u1E66' | + '\u1E68' | + '\u1E6A' | + '\u1E6C' | + '\u1E6E' | + '\u1E70' | + '\u1E72' | + '\u1E74' | + '\u1E76' | + '\u1E78' | + '\u1E7A' | + '\u1E7C' | + '\u1E7E' | + '\u1E80' | + '\u1E82' | + '\u1E84' | + '\u1E86' | + '\u1E88' | + '\u1E8A' | + '\u1E8C' | + '\u1E8E' | + '\u1E90' | + '\u1E92' | + '\u1E94' | + '\u1E9E' | + '\u1EA0' | + '\u1EA2' | + '\u1EA4' | + '\u1EA6' | + '\u1EA8' | + '\u1EAA' | + '\u1EAC' | + '\u1EAE' | + '\u1EB0' | + '\u1EB2' | + '\u1EB4' | + '\u1EB6' | + '\u1EB8' | + '\u1EBA' | + '\u1EBC' | + '\u1EBE' | + '\u1EC0' | + '\u1EC2' | + '\u1EC4' | + '\u1EC6' | + '\u1EC8' | + '\u1ECA' | + '\u1ECC' | + '\u1ECE' | + '\u1ED0' | + '\u1ED2' | + '\u1ED4' | + '\u1ED6' | + '\u1ED8' | + '\u1EDA' | + '\u1EDC' | + '\u1EDE' | + '\u1EE0' | + '\u1EE2' | + '\u1EE4' | + '\u1EE6' | + '\u1EE8' | + '\u1EEA' | + '\u1EEC' | + '\u1EEE' | + '\u1EF0' | + '\u1EF2' | + '\u1EF4' | + '\u1EF6' | + '\u1EF8' | + '\u1EFA' | + '\u1EFC' | + '\u1EFE' | + '\u1F08'..'\u1F0F' | + '\u1F18'..'\u1F1D' | + '\u1F28'..'\u1F2F' | + '\u1F38'..'\u1F3F' | + '\u1F48'..'\u1F4D' | + '\u1F59' | + '\u1F5B' | + '\u1F5D' | + '\u1F5F' | + '\u1F68'..'\u1F6F' | + '\u1FB8'..'\u1FBB' | + '\u1FC8'..'\u1FCB' | + '\u1FD8'..'\u1FDB' | + '\u1FE8'..'\u1FEC' | + '\u1FF8'..'\u1FFB' | + '\u2102' | + '\u2107' | + '\u210B'..'\u210D' | + '\u2110'..'\u2112' | + '\u2115' | + '\u2119'..'\u211D' | + '\u2124' | + '\u2126' | + '\u2128' | + '\u212A'..'\u212D' | + '\u2130'..'\u2133' | + '\u213E' | + '\u213F' | + '\u2145' | + '\u2183' | + '\u2C00'..'\u2C2E' | + '\u2C60' | + '\u2C62'..'\u2C64' | + '\u2C67' | + '\u2C69' | + '\u2C6B' | + '\u2C6D'..'\u2C70' | + '\u2C72' | + '\u2C75' | + '\u2C7E'..'\u2C80' | + '\u2C82' | + '\u2C84' | + '\u2C86' | + '\u2C88' | + '\u2C8A' | + '\u2C8C' | + '\u2C8E' | + '\u2C90' | + '\u2C92' | + '\u2C94' | + '\u2C96' | + '\u2C98' | + '\u2C9A' | + '\u2C9C' | + '\u2C9E' | + '\u2CA0' | + '\u2CA2' | + '\u2CA4' | + '\u2CA6' | + '\u2CA8' | + '\u2CAA' | + '\u2CAC' | + '\u2CAE' | + '\u2CB0' | + '\u2CB2' | + '\u2CB4' | + '\u2CB6' | + '\u2CB8' | + '\u2CBA' | + '\u2CBC' | + '\u2CBE' | + '\u2CC0' | + '\u2CC2' | + '\u2CC4' | + '\u2CC6' | + '\u2CC8' | + '\u2CCA' | + '\u2CCC' | + '\u2CCE' | + '\u2CD0' | + '\u2CD2' | + '\u2CD4' | + '\u2CD6' | + '\u2CD8' | + '\u2CDA' | + '\u2CDC' | + '\u2CDE' | + '\u2CE0' | + '\u2CE2' | + '\u2CEB' | + '\u2CED' | + '\u2CF2' | + '\uA640' | + '\uA642' | + '\uA644' | + '\uA646' | + '\uA648' | + '\uA64A' | + '\uA64C' | + '\uA64E' | + '\uA650' | + '\uA652' | + '\uA654' | + '\uA656' | + '\uA658' | + '\uA65A' | + '\uA65C' | + '\uA65E' | + '\uA660' | + '\uA662' | + '\uA664' | + '\uA666' | + '\uA668' | + '\uA66A' | + '\uA66C' | + '\uA680' | + '\uA682' | + '\uA684' | + '\uA686' | + '\uA688' | + '\uA68A' | + '\uA68C' | + '\uA68E' | + '\uA690' | + '\uA692' | + '\uA694' | + '\uA696' | + '\uA722' | + '\uA724' | + '\uA726' | + '\uA728' | + '\uA72A' | + '\uA72C' | + '\uA72E' | + '\uA732' | + '\uA734' | + '\uA736' | + '\uA738' | + '\uA73A' | + '\uA73C' | + '\uA73E' | + '\uA740' | + '\uA742' | + '\uA744' | + '\uA746' | + '\uA748' | + '\uA74A' | + '\uA74C' | + '\uA74E' | + '\uA750' | + '\uA752' | + '\uA754' | + '\uA756' | + '\uA758' | + '\uA75A' | + '\uA75C' | + '\uA75E' | + '\uA760' | + '\uA762' | + '\uA764' | + '\uA766' | + '\uA768' | + '\uA76A' | + '\uA76C' | + '\uA76E' | + '\uA779' | + '\uA77B' | + '\uA77D' | + '\uA77E' | + '\uA780' | + '\uA782' | + '\uA784' | + '\uA786' | + '\uA78B' | + '\uA78D' | + '\uA790' | + '\uA792' | + '\uA7A0' | + '\uA7A2' | + '\uA7A4' | + '\uA7A6' | + '\uA7A8' | + '\uA7AA' | + '\uFF21'..'\uFF3A'; + +UNICODE_CLASS_ND: + '\u0030'..'\u0039' | + '\u0660'..'\u0669' | + '\u06F0'..'\u06F9' | + '\u07C0'..'\u07C9' | + '\u0966'..'\u096F' | + '\u09E6'..'\u09EF' | + '\u0A66'..'\u0A6F' | + '\u0AE6'..'\u0AEF' | + '\u0B66'..'\u0B6F' | + '\u0BE6'..'\u0BEF' | + '\u0C66'..'\u0C6F' | + '\u0CE6'..'\u0CEF' | + '\u0D66'..'\u0D6F' | + '\u0E50'..'\u0E59' | + '\u0ED0'..'\u0ED9' | + '\u0F20'..'\u0F29' | + '\u1040'..'\u1049' | + '\u1090'..'\u1099' | + '\u17E0'..'\u17E9' | + '\u1810'..'\u1819' | + '\u1946'..'\u194F' | + '\u19D0'..'\u19D9' | + '\u1A80'..'\u1A89' | + '\u1A90'..'\u1A99' | + '\u1B50'..'\u1B59' | + '\u1BB0'..'\u1BB9' | + '\u1C40'..'\u1C49' | + '\u1C50'..'\u1C59' | + '\uA620'..'\uA629' | + '\uA8D0'..'\uA8D9' | + '\uA900'..'\uA909' | + '\uA9D0'..'\uA9D9' | + '\uAA50'..'\uAA59' | + '\uABF0'..'\uABF9' | + '\uFF10'..'\uFF19'; + +UNICODE_CLASS_NL: + '\u16EE'..'\u16F0' | + '\u2160'..'\u2182' | + '\u2185'..'\u2188' | + '\u3007' | + '\u3021'..'\u3029' | + '\u3038'..'\u303A' | + '\uA6E6'..'\uA6EF'; + +/** + * Kotlin lexical grammar in ANTLR4 notation + * from KotlinLexer.g4 + */ + +// SECTION: lexicalGeneral + +ShebangLine + : '#!' ~[\r\n]* + ; + +DelimitedComment + : '/*' ( DelimitedComment | . )*? '*/' + -> channel(HIDDEN) + ; + +LineComment + : '//' ~[\r\n]* + -> channel(HIDDEN) + ; + +WS + : [\u0020\u0009\u000C] + -> channel(HIDDEN) + ; + +NL: '\n' | '\r' '\n'?; + +fragment Hidden: DelimitedComment | LineComment | WS; + +// SECTION: separatorsAndOperations + +RESERVED: '...'; +DOT: '.'; +COMMA: ','; +LPAREN: '(' -> pushMode(Inside); +RPAREN: ')'; +LSQUARE: '[' -> pushMode(Inside); +RSQUARE: ']'; +LCURL: '{' -> pushMode(DEFAULT_MODE); +/* + * When using another programming language (not Java) to generate a parser, + * please replace this code with the corresponding code of a programming language you are using. + */ +RCURL: '}' { if (!_modeStack.isEmpty()) { popMode(); } }; +MULT: '*'; +MOD: '%'; +DIV: '/'; +ADD: '+'; +SUB: '-'; +INCR: '++'; +DECR: '--'; +CONJ: '&&'; +DISJ: '||'; +EXCL_WS: '!' Hidden; +EXCL_NO_WS: '!'; +COLON: ':'; +SEMICOLON: ';'; +ASSIGNMENT: '='; +ADD_ASSIGNMENT: '+='; +SUB_ASSIGNMENT: '-='; +MULT_ASSIGNMENT: '*='; +DIV_ASSIGNMENT: '/='; +MOD_ASSIGNMENT: '%='; +ARROW: '->'; +DOUBLE_ARROW: '=>'; +RANGE: '..'; +COLONCOLON: '::'; +DOUBLE_SEMICOLON: ';;'; +HASH: '#'; +AT_NO_WS: '@'; +AT_POST_WS: '@' (Hidden | NL); +AT_PRE_WS: (Hidden | NL) '@' ; +AT_BOTH_WS: (Hidden | NL) '@' (Hidden | NL); +QUEST_WS: '?' Hidden; +QUEST_NO_WS: '?'; +LANGLE: '<'; +RANGLE: '>'; +LE: '<='; +GE: '>='; +EXCL_EQ: '!='; +EXCL_EQEQ: '!=='; +AS_SAFE: 'as?'; +EQEQ: '=='; +EQEQEQ: '==='; +SINGLE_QUOTE: '\''; + +// SECTION: keywords + +RETURN_AT: 'return@' Identifier; +CONTINUE_AT: 'continue@' Identifier; +BREAK_AT: 'break@' Identifier; + +THIS_AT: 'this@' Identifier; +SUPER_AT: 'super@' Identifier; + +FILE: 'file'; +FIELD: 'field'; +PROPERTY: 'property'; +GET: 'get'; +SET: 'set'; +RECEIVER: 'receiver'; +PARAM: 'param'; +SETPARAM: 'setparam'; +DELEGATE: 'delegate'; + +PACKAGE: 'package'; +IMPORT: 'import'; +CLASS: 'class'; +INTERFACE: 'interface'; +FUN: 'fun'; +OBJECT: 'object'; +VAL: 'val'; +VAR: 'var'; +TYPE_ALIAS: 'typealias'; +CONSTRUCTOR: 'constructor'; +BY: 'by'; +COMPANION: 'companion'; +INIT: 'init'; +THIS: 'this'; +SUPER: 'super'; +TYPEOF: 'typeof'; +WHERE: 'where'; +IF: 'if'; +ELSE: 'else'; +WHEN: 'when'; +TRY: 'try'; +CATCH: 'catch'; +FINALLY: 'finally'; +FOR: 'for'; +DO: 'do'; +WHILE: 'while'; +THROW: 'throw'; +RETURN: 'return'; +CONTINUE: 'continue'; +BREAK: 'break'; +AS: 'as'; +IS: 'is'; +IN: 'in'; +NOT_IS: '!is' (Hidden | NL); +NOT_IN: '!in' (Hidden | NL); +OUT: 'out'; +DYNAMIC: 'dynamic'; + +// SECTION: lexicalModifiers + +PUBLIC: 'public'; +PRIVATE: 'private'; +PROTECTED: 'protected'; +INTERNAL: 'internal'; +ENUM: 'enum'; +SEALED: 'sealed'; +ANNOTATION: 'annotation'; +DATA: 'data'; +INNER: 'inner'; +VALUE: 'value'; +TAILREC: 'tailrec'; +OPERATOR: 'operator'; +INLINE: 'inline'; +INFIX: 'infix'; +EXTERNAL: 'external'; +SUSPEND: 'suspend'; +OVERRIDE: 'override'; +ABSTRACT: 'abstract'; +FINAL: 'final'; +OPEN: 'open'; +CONST: 'const'; +LATEINIT: 'lateinit'; +VARARG: 'vararg'; +NOINLINE: 'noinline'; +CROSSINLINE: 'crossinline'; +REIFIED: 'reified'; +EXPECT: 'expect'; +ACTUAL: 'actual'; + +// SECTION: literals + +fragment DecDigit: '0'..'9'; +fragment DecDigitNoZero: '1'..'9'; +fragment DecDigitOrSeparator: DecDigit | '_'; + +fragment DecDigits + : DecDigit DecDigitOrSeparator* DecDigit + | DecDigit + ; + +fragment DoubleExponent: [eE] [+-]? DecDigits; + +RealLiteral + : FloatLiteral + | DoubleLiteral + ; + +FloatLiteral + : DoubleLiteral [fF] + | DecDigits [fF] + ; + +DoubleLiteral + : DecDigits? '.' DecDigits DoubleExponent? + | DecDigits DoubleExponent + ; + +IntegerLiteral + : DecDigitNoZero DecDigitOrSeparator* DecDigit + | DecDigit + ; + +fragment HexDigit: [0-9a-fA-F]; +fragment HexDigitOrSeparator: HexDigit | '_'; + +HexLiteral + : '0' [xX] HexDigit HexDigitOrSeparator* HexDigit + | '0' [xX] HexDigit + ; + +fragment BinDigit: [01]; +fragment BinDigitOrSeparator: BinDigit | '_'; + +BinLiteral + : '0' [bB] BinDigit BinDigitOrSeparator* BinDigit + | '0' [bB] BinDigit + ; + +UnsignedLiteral + : (IntegerLiteral | HexLiteral | BinLiteral) [uU] [lL]? + ; + +LongLiteral + : (IntegerLiteral | HexLiteral | BinLiteral) [lL] + ; + +BooleanLiteral: 'true'| 'false'; + +NullLiteral: 'null'; + +CharacterLiteral + : '\'' (EscapeSeq | ~[\n\r'\\]) '\'' + ; + +// SECTION: lexicalIdentifiers + +fragment UnicodeDigit: UNICODE_CLASS_ND; + +Identifier + : (Letter | '_') (Letter | '_' | UnicodeDigit)* + | '`' ~([\r\n] | '`')+ '`' + ; + +IdentifierOrSoftKey + : Identifier + /* Soft keywords */ + | ABSTRACT + | ANNOTATION + | BY + | CATCH + | COMPANION + | CONSTRUCTOR + | CROSSINLINE + | DATA + | DYNAMIC + | ENUM + | EXTERNAL + | FINAL + | FINALLY + | IMPORT + | INFIX + | INIT + | INLINE + | INNER + | INTERNAL + | LATEINIT + | NOINLINE + | OPEN + | OPERATOR + | OUT + | OVERRIDE + | PRIVATE + | PROTECTED + | PUBLIC + | REIFIED + | SEALED + | TAILREC + | VARARG + | WHERE + | GET + | SET + | FIELD + | PROPERTY + | RECEIVER + | PARAM + | SETPARAM + | DELEGATE + | FILE + | EXPECT + | ACTUAL + | VALUE + /* Strong keywords */ + | CONST + | SUSPEND + ; + +FieldIdentifier + : '$' IdentifierOrSoftKey + ; + +fragment UniCharacterLiteral + : '\\' 'u' HexDigit HexDigit HexDigit HexDigit + ; + +fragment EscapedIdentifier + : '\\' ('t' | 'b' | 'r' | 'n' | '\'' | '"' | '\\' | '$') + ; + +fragment EscapeSeq + : UniCharacterLiteral + | EscapedIdentifier + ; + +// SECTION: characters + +fragment Letter + : UNICODE_CLASS_LL + | UNICODE_CLASS_LM + | UNICODE_CLASS_LO + | UNICODE_CLASS_LT + | UNICODE_CLASS_LU + | UNICODE_CLASS_NL + ; + +// SECTION: strings + +QUOTE_OPEN: '"' -> pushMode(LineString); + +TRIPLE_QUOTE_OPEN: '"""' -> pushMode(MultiLineString); + +mode LineString; + +QUOTE_CLOSE + : '"' -> popMode + ; + +LineStrRef + : FieldIdentifier + ; + +LineStrText + : ~('\\' | '"' | '$')+ | '$' + ; + +LineStrEscapedChar + : EscapedIdentifier + | UniCharacterLiteral + ; + +LineStrExprStart + : '${' -> pushMode(DEFAULT_MODE) + ; + +mode MultiLineString; + +TRIPLE_QUOTE_CLOSE + : MultiLineStringQuote? '"""' -> popMode + ; + +MultiLineStringQuote + : '"'+ + ; + +MultiLineStrRef + : FieldIdentifier + ; + +MultiLineStrText + : ~('"' | '$')+ | '$' + ; + +MultiLineStrExprStart + : '${' -> pushMode(DEFAULT_MODE) + ; + +// SECTION: inside + +mode Inside; + +Inside_RPAREN: RPAREN -> popMode, type(RPAREN); +Inside_RSQUARE: RSQUARE -> popMode, type(RSQUARE); +Inside_LPAREN: LPAREN -> pushMode(Inside), type(LPAREN); +Inside_LSQUARE: LSQUARE -> pushMode(Inside), type(LSQUARE); +Inside_LCURL: LCURL -> pushMode(DEFAULT_MODE), type(LCURL); +Inside_RCURL: RCURL -> popMode, type(RCURL); + +Inside_DOT: DOT -> type(DOT); +Inside_COMMA: COMMA -> type(COMMA); +Inside_MULT: MULT -> type(MULT); +Inside_MOD: MOD -> type(MOD); +Inside_DIV: DIV -> type(DIV); +Inside_ADD: ADD -> type(ADD); +Inside_SUB: SUB -> type(SUB); +Inside_INCR: INCR -> type(INCR); +Inside_DECR: DECR -> type(DECR); +Inside_CONJ: CONJ -> type(CONJ); +Inside_DISJ: DISJ -> type(DISJ); +Inside_EXCL_WS: '!' (Hidden|NL) -> type(EXCL_WS); +Inside_EXCL_NO_WS: EXCL_NO_WS -> type(EXCL_NO_WS); +Inside_COLON: COLON -> type(COLON); +Inside_SEMICOLON: SEMICOLON -> type(SEMICOLON); +Inside_ASSIGNMENT: ASSIGNMENT -> type(ASSIGNMENT); +Inside_ADD_ASSIGNMENT: ADD_ASSIGNMENT -> type(ADD_ASSIGNMENT); +Inside_SUB_ASSIGNMENT: SUB_ASSIGNMENT -> type(SUB_ASSIGNMENT); +Inside_MULT_ASSIGNMENT: MULT_ASSIGNMENT -> type(MULT_ASSIGNMENT); +Inside_DIV_ASSIGNMENT: DIV_ASSIGNMENT -> type(DIV_ASSIGNMENT); +Inside_MOD_ASSIGNMENT: MOD_ASSIGNMENT -> type(MOD_ASSIGNMENT); +Inside_ARROW: ARROW -> type(ARROW); +Inside_DOUBLE_ARROW: DOUBLE_ARROW -> type(DOUBLE_ARROW); +Inside_RANGE: RANGE -> type(RANGE); +Inside_RESERVED: RESERVED -> type(RESERVED); +Inside_COLONCOLON: COLONCOLON -> type(COLONCOLON); +Inside_DOUBLE_SEMICOLON: DOUBLE_SEMICOLON -> type(DOUBLE_SEMICOLON); +Inside_HASH: HASH -> type(HASH); +Inside_AT_NO_WS: AT_NO_WS -> type(AT_NO_WS); +Inside_AT_POST_WS: AT_POST_WS -> type(AT_POST_WS); +Inside_AT_PRE_WS: AT_PRE_WS -> type(AT_PRE_WS); +Inside_AT_BOTH_WS: AT_BOTH_WS -> type(AT_BOTH_WS); +Inside_QUEST_WS: '?' (Hidden | NL) -> type(QUEST_WS); +Inside_QUEST_NO_WS: QUEST_NO_WS -> type(QUEST_NO_WS); +Inside_LANGLE: LANGLE -> type(LANGLE); +Inside_RANGLE: RANGLE -> type(RANGLE); +Inside_LE: LE -> type(LE); +Inside_GE: GE -> type(GE); +Inside_EXCL_EQ: EXCL_EQ -> type(EXCL_EQ); +Inside_EXCL_EQEQ: EXCL_EQEQ -> type(EXCL_EQEQ); +Inside_IS: IS -> type(IS); +Inside_NOT_IS: NOT_IS -> type(NOT_IS); +Inside_NOT_IN: NOT_IN -> type(NOT_IN); +Inside_AS: AS -> type(AS); +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_QUOTE_OPEN: QUOTE_OPEN -> pushMode(LineString), type(QUOTE_OPEN); +Inside_TRIPLE_QUOTE_OPEN: TRIPLE_QUOTE_OPEN -> pushMode(MultiLineString), type(TRIPLE_QUOTE_OPEN); + +Inside_VAL: VAL -> type(VAL); +Inside_VAR: VAR -> type(VAR); +Inside_FUN: FUN -> type(FUN); +Inside_OBJECT: OBJECT -> type(OBJECT); +Inside_SUPER: SUPER -> type(SUPER); +Inside_IN: IN -> type(IN); +Inside_OUT: OUT -> type(OUT); +Inside_FIELD: FIELD -> type(FIELD); +Inside_FILE: FILE -> type(FILE); +Inside_PROPERTY: PROPERTY -> type(PROPERTY); +Inside_GET: GET -> type(GET); +Inside_SET: SET -> type(SET); +Inside_RECEIVER: RECEIVER -> type(RECEIVER); +Inside_PARAM: PARAM -> type(PARAM); +Inside_SETPARAM: SETPARAM -> type(SETPARAM); +Inside_DELEGATE: DELEGATE -> type(DELEGATE); +Inside_THROW: THROW -> type(THROW); +Inside_RETURN: RETURN -> type(RETURN); +Inside_CONTINUE: CONTINUE -> type(CONTINUE); +Inside_BREAK: BREAK -> type(BREAK); +Inside_RETURN_AT: RETURN_AT -> type(RETURN_AT); +Inside_CONTINUE_AT: CONTINUE_AT -> type(CONTINUE_AT); +Inside_BREAK_AT: BREAK_AT -> type(BREAK_AT); +Inside_IF: IF -> type(IF); +Inside_ELSE: ELSE -> type(ELSE); +Inside_WHEN: WHEN -> type(WHEN); +Inside_TRY: TRY -> type(TRY); +Inside_CATCH: CATCH -> type(CATCH); +Inside_FINALLY: FINALLY -> type(FINALLY); +Inside_FOR: FOR -> type(FOR); +Inside_DO: DO -> type(DO); +Inside_WHILE: WHILE -> type(WHILE); + +Inside_PUBLIC: PUBLIC -> type(PUBLIC); +Inside_PRIVATE: PRIVATE -> type(PRIVATE); +Inside_PROTECTED: PROTECTED -> type(PROTECTED); +Inside_INTERNAL: INTERNAL -> type(INTERNAL); +Inside_ENUM: ENUM -> type(ENUM); +Inside_SEALED: SEALED -> type(SEALED); +Inside_ANNOTATION: ANNOTATION -> type(ANNOTATION); +Inside_DATA: DATA -> type(DATA); +Inside_INNER: INNER -> type(INNER); +Inside_VALUE: VALUE -> type(VALUE); +Inside_TAILREC: TAILREC -> type(TAILREC); +Inside_OPERATOR: OPERATOR -> type(OPERATOR); +Inside_INLINE: INLINE -> type(INLINE); +Inside_INFIX: INFIX -> type(INFIX); +Inside_EXTERNAL: EXTERNAL -> type(EXTERNAL); +Inside_SUSPEND: SUSPEND -> type(SUSPEND); +Inside_OVERRIDE: OVERRIDE -> type(OVERRIDE); +Inside_ABSTRACT: ABSTRACT -> type(ABSTRACT); +Inside_FINAL: FINAL -> type(FINAL); +Inside_OPEN: OPEN -> type(OPEN); +Inside_CONST: CONST -> type(CONST); +Inside_LATEINIT: LATEINIT -> type(LATEINIT); +Inside_VARARG: VARARG -> type(VARARG); +Inside_NOINLINE: NOINLINE -> type(NOINLINE); +Inside_CROSSINLINE: CROSSINLINE -> type(CROSSINLINE); +Inside_REIFIED: REIFIED -> type(REIFIED); +Inside_EXPECT: EXPECT -> type(EXPECT); +Inside_ACTUAL: ACTUAL -> type(ACTUAL); + +Inside_BooleanLiteral: BooleanLiteral -> type(BooleanLiteral); +Inside_IntegerLiteral: IntegerLiteral -> type(IntegerLiteral); +Inside_HexLiteral: HexLiteral -> type(HexLiteral); +Inside_BinLiteral: BinLiteral -> type(BinLiteral); +Inside_CharacterLiteral: CharacterLiteral -> type(CharacterLiteral); +Inside_RealLiteral: RealLiteral -> type(RealLiteral); +Inside_NullLiteral: NullLiteral -> type(NullLiteral); +Inside_LongLiteral: LongLiteral -> type(LongLiteral); +Inside_UnsignedLiteral: UnsignedLiteral -> type(UnsignedLiteral); + +Inside_Identifier: Identifier -> type(Identifier); +Inside_Comment: (LineComment | DelimitedComment) -> channel(HIDDEN); +Inside_WS: WS -> channel(HIDDEN); +Inside_NL: NL -> channel(HIDDEN); + +mode DEFAULT_MODE; + +ErrorCharacter: .; + + + From a82e7eff2450460dbf61b4c04387e4cbe483858f Mon Sep 17 00:00:00 2001 From: jborgers Date: Mon, 13 Sep 2021 14:15:25 +0200 Subject: [PATCH 006/198] Handled all steps of "Adding PMD support for a new ANTLR grammar based language" except $. Generate your Parser did not succeed because combining lexer and parser grammars has issues. --- .../pmd/lang/kotlin/ast/KotlinLexer.g4 | 2169 ----------------- .../pmd/lang/kotlin/ast/KotlinParser.g4 | 923 ------- .../pmd/lang/kotlin/ast/PmdKotlinParser.java | 28 + .../pmd/lang/kotlin/AbstractKotlinRule.java | 19 + .../pmd/lang/kotlin/KotlinHandler.java | 25 + .../pmd/lang/kotlin/KotlinLanguageModule.java | 28 + .../lang/kotlin/ast/KotlinVisitorBase.java | 14 + 7 files changed, 114 insertions(+), 3092 deletions(-) delete mode 100755 pmd-kotlin/src/main/antlr4/net/sourceforge/pmd/lang/kotlin/ast/KotlinLexer.g4 delete mode 100644 pmd-kotlin/src/main/antlr4/net/sourceforge/pmd/lang/kotlin/ast/KotlinParser.g4 create mode 100644 pmd-kotlin/src/main/antlr4/net/sourceforge/pmd/lang/kotlin/ast/PmdKotlinParser.java create mode 100644 pmd-kotlin/src/main/java/net/sourceforge/pmd/lang/kotlin/AbstractKotlinRule.java create mode 100644 pmd-kotlin/src/main/java/net/sourceforge/pmd/lang/kotlin/KotlinHandler.java create mode 100644 pmd-kotlin/src/main/java/net/sourceforge/pmd/lang/kotlin/KotlinLanguageModule.java create mode 100644 pmd-kotlin/src/main/java/net/sourceforge/pmd/lang/kotlin/ast/KotlinVisitorBase.java 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 deleted file mode 100755 index 9b401e934a..0000000000 --- a/pmd-kotlin/src/main/antlr4/net/sourceforge/pmd/lang/kotlin/ast/KotlinLexer.g4 +++ /dev/null @@ -1,2169 +0,0 @@ -/** - * Kotlin lexical grammar in ANTLR4 notation - */ - -lexer grammar KotlinLexer; - -//import UnicodeClasses; -// Taken from http://www.antlr3.org/grammar/1345144569663/AntlrUnicode.txt - -UNICODE_CLASS_LL: - '\u0061'..'\u007A' | - '\u00B5' | - '\u00DF'..'\u00F6' | - '\u00F8'..'\u00FF' | - '\u0101' | - '\u0103' | - '\u0105' | - '\u0107' | - '\u0109' | - '\u010B' | - '\u010D' | - '\u010F' | - '\u0111' | - '\u0113' | - '\u0115' | - '\u0117' | - '\u0119' | - '\u011B' | - '\u011D' | - '\u011F' | - '\u0121' | - '\u0123' | - '\u0125' | - '\u0127' | - '\u0129' | - '\u012B' | - '\u012D' | - '\u012F' | - '\u0131' | - '\u0133' | - '\u0135' | - '\u0137' | - '\u0138' | - '\u013A' | - '\u013C' | - '\u013E' | - '\u0140' | - '\u0142' | - '\u0144' | - '\u0146' | - '\u0148' | - '\u0149' | - '\u014B' | - '\u014D' | - '\u014F' | - '\u0151' | - '\u0153' | - '\u0155' | - '\u0157' | - '\u0159' | - '\u015B' | - '\u015D' | - '\u015F' | - '\u0161' | - '\u0163' | - '\u0165' | - '\u0167' | - '\u0169' | - '\u016B' | - '\u016D' | - '\u016F' | - '\u0171' | - '\u0173' | - '\u0175' | - '\u0177' | - '\u017A' | - '\u017C' | - '\u017E'..'\u0180' | - '\u0183' | - '\u0185' | - '\u0188' | - '\u018C' | - '\u018D' | - '\u0192' | - '\u0195' | - '\u0199'..'\u019B' | - '\u019E' | - '\u01A1' | - '\u01A3' | - '\u01A5' | - '\u01A8' | - '\u01AA' | - '\u01AB' | - '\u01AD' | - '\u01B0' | - '\u01B4' | - '\u01B6' | - '\u01B9' | - '\u01BA' | - '\u01BD'..'\u01BF' | - '\u01C6' | - '\u01C9' | - '\u01CC' | - '\u01CE' | - '\u01D0' | - '\u01D2' | - '\u01D4' | - '\u01D6' | - '\u01D8' | - '\u01DA' | - '\u01DC' | - '\u01DD' | - '\u01DF' | - '\u01E1' | - '\u01E3' | - '\u01E5' | - '\u01E7' | - '\u01E9' | - '\u01EB' | - '\u01ED' | - '\u01EF' | - '\u01F0' | - '\u01F3' | - '\u01F5' | - '\u01F9' | - '\u01FB' | - '\u01FD' | - '\u01FF' | - '\u0201' | - '\u0203' | - '\u0205' | - '\u0207' | - '\u0209' | - '\u020B' | - '\u020D' | - '\u020F' | - '\u0211' | - '\u0213' | - '\u0215' | - '\u0217' | - '\u0219' | - '\u021B' | - '\u021D' | - '\u021F' | - '\u0221' | - '\u0223' | - '\u0225' | - '\u0227' | - '\u0229' | - '\u022B' | - '\u022D' | - '\u022F' | - '\u0231' | - '\u0233'..'\u0239' | - '\u023C' | - '\u023F' | - '\u0240' | - '\u0242' | - '\u0247' | - '\u0249' | - '\u024B' | - '\u024D' | - '\u024F'..'\u0293' | - '\u0295'..'\u02AF' | - '\u0371' | - '\u0373' | - '\u0377' | - '\u037B'..'\u037D' | - '\u0390' | - '\u03AC'..'\u03CE' | - '\u03D0' | - '\u03D1' | - '\u03D5'..'\u03D7' | - '\u03D9' | - '\u03DB' | - '\u03DD' | - '\u03DF' | - '\u03E1' | - '\u03E3' | - '\u03E5' | - '\u03E7' | - '\u03E9' | - '\u03EB' | - '\u03ED' | - '\u03EF'..'\u03F3' | - '\u03F5' | - '\u03F8' | - '\u03FB' | - '\u03FC' | - '\u0430'..'\u045F' | - '\u0461' | - '\u0463' | - '\u0465' | - '\u0467' | - '\u0469' | - '\u046B' | - '\u046D' | - '\u046F' | - '\u0471' | - '\u0473' | - '\u0475' | - '\u0477' | - '\u0479' | - '\u047B' | - '\u047D' | - '\u047F' | - '\u0481' | - '\u048B' | - '\u048D' | - '\u048F' | - '\u0491' | - '\u0493' | - '\u0495' | - '\u0497' | - '\u0499' | - '\u049B' | - '\u049D' | - '\u049F' | - '\u04A1' | - '\u04A3' | - '\u04A5' | - '\u04A7' | - '\u04A9' | - '\u04AB' | - '\u04AD' | - '\u04AF' | - '\u04B1' | - '\u04B3' | - '\u04B5' | - '\u04B7' | - '\u04B9' | - '\u04BB' | - '\u04BD' | - '\u04BF' | - '\u04C2' | - '\u04C4' | - '\u04C6' | - '\u04C8' | - '\u04CA' | - '\u04CC' | - '\u04CE' | - '\u04CF' | - '\u04D1' | - '\u04D3' | - '\u04D5' | - '\u04D7' | - '\u04D9' | - '\u04DB' | - '\u04DD' | - '\u04DF' | - '\u04E1' | - '\u04E3' | - '\u04E5' | - '\u04E7' | - '\u04E9' | - '\u04EB' | - '\u04ED' | - '\u04EF' | - '\u04F1' | - '\u04F3' | - '\u04F5' | - '\u04F7' | - '\u04F9' | - '\u04FB' | - '\u04FD' | - '\u04FF' | - '\u0501' | - '\u0503' | - '\u0505' | - '\u0507' | - '\u0509' | - '\u050B' | - '\u050D' | - '\u050F' | - '\u0511' | - '\u0513' | - '\u0515' | - '\u0517' | - '\u0519' | - '\u051B' | - '\u051D' | - '\u051F' | - '\u0521' | - '\u0523' | - '\u0525' | - '\u0527' | - '\u0561'..'\u0587' | - '\u1D00'..'\u1D2B' | - '\u1D6B'..'\u1D77' | - '\u1D79'..'\u1D9A' | - '\u1E01' | - '\u1E03' | - '\u1E05' | - '\u1E07' | - '\u1E09' | - '\u1E0B' | - '\u1E0D' | - '\u1E0F' | - '\u1E11' | - '\u1E13' | - '\u1E15' | - '\u1E17' | - '\u1E19' | - '\u1E1B' | - '\u1E1D' | - '\u1E1F' | - '\u1E21' | - '\u1E23' | - '\u1E25' | - '\u1E27' | - '\u1E29' | - '\u1E2B' | - '\u1E2D' | - '\u1E2F' | - '\u1E31' | - '\u1E33' | - '\u1E35' | - '\u1E37' | - '\u1E39' | - '\u1E3B' | - '\u1E3D' | - '\u1E3F' | - '\u1E41' | - '\u1E43' | - '\u1E45' | - '\u1E47' | - '\u1E49' | - '\u1E4B' | - '\u1E4D' | - '\u1E4F' | - '\u1E51' | - '\u1E53' | - '\u1E55' | - '\u1E57' | - '\u1E59' | - '\u1E5B' | - '\u1E5D' | - '\u1E5F' | - '\u1E61' | - '\u1E63' | - '\u1E65' | - '\u1E67' | - '\u1E69' | - '\u1E6B' | - '\u1E6D' | - '\u1E6F' | - '\u1E71' | - '\u1E73' | - '\u1E75' | - '\u1E77' | - '\u1E79' | - '\u1E7B' | - '\u1E7D' | - '\u1E7F' | - '\u1E81' | - '\u1E83' | - '\u1E85' | - '\u1E87' | - '\u1E89' | - '\u1E8B' | - '\u1E8D' | - '\u1E8F' | - '\u1E91' | - '\u1E93' | - '\u1E95'..'\u1E9D' | - '\u1E9F' | - '\u1EA1' | - '\u1EA3' | - '\u1EA5' | - '\u1EA7' | - '\u1EA9' | - '\u1EAB' | - '\u1EAD' | - '\u1EAF' | - '\u1EB1' | - '\u1EB3' | - '\u1EB5' | - '\u1EB7' | - '\u1EB9' | - '\u1EBB' | - '\u1EBD' | - '\u1EBF' | - '\u1EC1' | - '\u1EC3' | - '\u1EC5' | - '\u1EC7' | - '\u1EC9' | - '\u1ECB' | - '\u1ECD' | - '\u1ECF' | - '\u1ED1' | - '\u1ED3' | - '\u1ED5' | - '\u1ED7' | - '\u1ED9' | - '\u1EDB' | - '\u1EDD' | - '\u1EDF' | - '\u1EE1' | - '\u1EE3' | - '\u1EE5' | - '\u1EE7' | - '\u1EE9' | - '\u1EEB' | - '\u1EED' | - '\u1EEF' | - '\u1EF1' | - '\u1EF3' | - '\u1EF5' | - '\u1EF7' | - '\u1EF9' | - '\u1EFB' | - '\u1EFD' | - '\u1EFF'..'\u1F07' | - '\u1F10'..'\u1F15' | - '\u1F20'..'\u1F27' | - '\u1F30'..'\u1F37' | - '\u1F40'..'\u1F45' | - '\u1F50'..'\u1F57' | - '\u1F60'..'\u1F67' | - '\u1F70'..'\u1F7D' | - '\u1F80'..'\u1F87' | - '\u1F90'..'\u1F97' | - '\u1FA0'..'\u1FA7' | - '\u1FB0'..'\u1FB4' | - '\u1FB6' | - '\u1FB7' | - '\u1FBE' | - '\u1FC2'..'\u1FC4' | - '\u1FC6' | - '\u1FC7' | - '\u1FD0'..'\u1FD3' | - '\u1FD6' | - '\u1FD7' | - '\u1FE0'..'\u1FE7' | - '\u1FF2'..'\u1FF4' | - '\u1FF6' | - '\u1FF7' | - '\u210A' | - '\u210E' | - '\u210F' | - '\u2113' | - '\u212F' | - '\u2134' | - '\u2139' | - '\u213C' | - '\u213D' | - '\u2146'..'\u2149' | - '\u214E' | - '\u2184' | - '\u2C30'..'\u2C5E' | - '\u2C61' | - '\u2C65' | - '\u2C66' | - '\u2C68' | - '\u2C6A' | - '\u2C6C' | - '\u2C71' | - '\u2C73' | - '\u2C74' | - '\u2C76'..'\u2C7B' | - '\u2C81' | - '\u2C83' | - '\u2C85' | - '\u2C87' | - '\u2C89' | - '\u2C8B' | - '\u2C8D' | - '\u2C8F' | - '\u2C91' | - '\u2C93' | - '\u2C95' | - '\u2C97' | - '\u2C99' | - '\u2C9B' | - '\u2C9D' | - '\u2C9F' | - '\u2CA1' | - '\u2CA3' | - '\u2CA5' | - '\u2CA7' | - '\u2CA9' | - '\u2CAB' | - '\u2CAD' | - '\u2CAF' | - '\u2CB1' | - '\u2CB3' | - '\u2CB5' | - '\u2CB7' | - '\u2CB9' | - '\u2CBB' | - '\u2CBD' | - '\u2CBF' | - '\u2CC1' | - '\u2CC3' | - '\u2CC5' | - '\u2CC7' | - '\u2CC9' | - '\u2CCB' | - '\u2CCD' | - '\u2CCF' | - '\u2CD1' | - '\u2CD3' | - '\u2CD5' | - '\u2CD7' | - '\u2CD9' | - '\u2CDB' | - '\u2CDD' | - '\u2CDF' | - '\u2CE1' | - '\u2CE3' | - '\u2CE4' | - '\u2CEC' | - '\u2CEE' | - '\u2CF3' | - '\u2D00'..'\u2D25' | - '\u2D27' | - '\u2D2D' | - '\uA641' | - '\uA643' | - '\uA645' | - '\uA647' | - '\uA649' | - '\uA64B' | - '\uA64D' | - '\uA64F' | - '\uA651' | - '\uA653' | - '\uA655' | - '\uA657' | - '\uA659' | - '\uA65B' | - '\uA65D' | - '\uA65F' | - '\uA661' | - '\uA663' | - '\uA665' | - '\uA667' | - '\uA669' | - '\uA66B' | - '\uA66D' | - '\uA681' | - '\uA683' | - '\uA685' | - '\uA687' | - '\uA689' | - '\uA68B' | - '\uA68D' | - '\uA68F' | - '\uA691' | - '\uA693' | - '\uA695' | - '\uA697' | - '\uA723' | - '\uA725' | - '\uA727' | - '\uA729' | - '\uA72B' | - '\uA72D' | - '\uA72F'..'\uA731' | - '\uA733' | - '\uA735' | - '\uA737' | - '\uA739' | - '\uA73B' | - '\uA73D' | - '\uA73F' | - '\uA741' | - '\uA743' | - '\uA745' | - '\uA747' | - '\uA749' | - '\uA74B' | - '\uA74D' | - '\uA74F' | - '\uA751' | - '\uA753' | - '\uA755' | - '\uA757' | - '\uA759' | - '\uA75B' | - '\uA75D' | - '\uA75F' | - '\uA761' | - '\uA763' | - '\uA765' | - '\uA767' | - '\uA769' | - '\uA76B' | - '\uA76D' | - '\uA76F' | - '\uA771'..'\uA778' | - '\uA77A' | - '\uA77C' | - '\uA77F' | - '\uA781' | - '\uA783' | - '\uA785' | - '\uA787' | - '\uA78C' | - '\uA78E' | - '\uA791' | - '\uA793' | - '\uA7A1' | - '\uA7A3' | - '\uA7A5' | - '\uA7A7' | - '\uA7A9' | - '\uA7FA' | - '\uFB00'..'\uFB06' | - '\uFB13'..'\uFB17' | - '\uFF41'..'\uFF5A'; - -UNICODE_CLASS_LM: - '\u02B0'..'\u02C1' | - '\u02C6'..'\u02D1' | - '\u02E0'..'\u02E4' | - '\u02EC' | - '\u02EE' | - '\u0374' | - '\u037A' | - '\u0559' | - '\u0640' | - '\u06E5' | - '\u06E6' | - '\u07F4' | - '\u07F5' | - '\u07FA' | - '\u081A' | - '\u0824' | - '\u0828' | - '\u0971' | - '\u0E46' | - '\u0EC6' | - '\u10FC' | - '\u17D7' | - '\u1843' | - '\u1AA7' | - '\u1C78'..'\u1C7D' | - '\u1D2C'..'\u1D6A' | - '\u1D78' | - '\u1D9B'..'\u1DBF' | - '\u2071' | - '\u207F' | - '\u2090'..'\u209C' | - '\u2C7C' | - '\u2C7D' | - '\u2D6F' | - '\u2E2F' | - '\u3005' | - '\u3031'..'\u3035' | - '\u303B' | - '\u309D' | - '\u309E' | - '\u30FC'..'\u30FE' | - '\uA015' | - '\uA4F8'..'\uA4FD' | - '\uA60C' | - '\uA67F' | - '\uA717'..'\uA71F' | - '\uA770' | - '\uA788' | - '\uA7F8' | - '\uA7F9' | - '\uA9CF' | - '\uAA70' | - '\uAADD' | - '\uAAF3' | - '\uAAF4' | - '\uFF70' | - '\uFF9E' | - '\uFF9F'; - -UNICODE_CLASS_LO: - '\u00AA' | - '\u00BA' | - '\u01BB' | - '\u01C0'..'\u01C3' | - '\u0294' | - '\u05D0'..'\u05EA' | - '\u05F0'..'\u05F2' | - '\u0620'..'\u063F' | - '\u0641'..'\u064A' | - '\u066E' | - '\u066F' | - '\u0671'..'\u06D3' | - '\u06D5' | - '\u06EE' | - '\u06EF' | - '\u06FA'..'\u06FC' | - '\u06FF' | - '\u0710' | - '\u0712'..'\u072F' | - '\u074D'..'\u07A5' | - '\u07B1' | - '\u07CA'..'\u07EA' | - '\u0800'..'\u0815' | - '\u0840'..'\u0858' | - '\u08A0' | - '\u08A2'..'\u08AC' | - '\u0904'..'\u0939' | - '\u093D' | - '\u0950' | - '\u0958'..'\u0961' | - '\u0972'..'\u0977' | - '\u0979'..'\u097F' | - '\u0985'..'\u098C' | - '\u098F' | - '\u0990' | - '\u0993'..'\u09A8' | - '\u09AA'..'\u09B0' | - '\u09B2' | - '\u09B6'..'\u09B9' | - '\u09BD' | - '\u09CE' | - '\u09DC' | - '\u09DD' | - '\u09DF'..'\u09E1' | - '\u09F0' | - '\u09F1' | - '\u0A05'..'\u0A0A' | - '\u0A0F' | - '\u0A10' | - '\u0A13'..'\u0A28' | - '\u0A2A'..'\u0A30' | - '\u0A32' | - '\u0A33' | - '\u0A35' | - '\u0A36' | - '\u0A38' | - '\u0A39' | - '\u0A59'..'\u0A5C' | - '\u0A5E' | - '\u0A72'..'\u0A74' | - '\u0A85'..'\u0A8D' | - '\u0A8F'..'\u0A91' | - '\u0A93'..'\u0AA8' | - '\u0AAA'..'\u0AB0' | - '\u0AB2' | - '\u0AB3' | - '\u0AB5'..'\u0AB9' | - '\u0ABD' | - '\u0AD0' | - '\u0AE0' | - '\u0AE1' | - '\u0B05'..'\u0B0C' | - '\u0B0F' | - '\u0B10' | - '\u0B13'..'\u0B28' | - '\u0B2A'..'\u0B30' | - '\u0B32' | - '\u0B33' | - '\u0B35'..'\u0B39' | - '\u0B3D' | - '\u0B5C' | - '\u0B5D' | - '\u0B5F'..'\u0B61' | - '\u0B71' | - '\u0B83' | - '\u0B85'..'\u0B8A' | - '\u0B8E'..'\u0B90' | - '\u0B92'..'\u0B95' | - '\u0B99' | - '\u0B9A' | - '\u0B9C' | - '\u0B9E' | - '\u0B9F' | - '\u0BA3' | - '\u0BA4' | - '\u0BA8'..'\u0BAA' | - '\u0BAE'..'\u0BB9' | - '\u0BD0' | - '\u0C05'..'\u0C0C' | - '\u0C0E'..'\u0C10' | - '\u0C12'..'\u0C28' | - '\u0C2A'..'\u0C33' | - '\u0C35'..'\u0C39' | - '\u0C3D' | - '\u0C58' | - '\u0C59' | - '\u0C60' | - '\u0C61' | - '\u0C85'..'\u0C8C' | - '\u0C8E'..'\u0C90' | - '\u0C92'..'\u0CA8' | - '\u0CAA'..'\u0CB3' | - '\u0CB5'..'\u0CB9' | - '\u0CBD' | - '\u0CDE' | - '\u0CE0' | - '\u0CE1' | - '\u0CF1' | - '\u0CF2' | - '\u0D05'..'\u0D0C' | - '\u0D0E'..'\u0D10' | - '\u0D12'..'\u0D3A' | - '\u0D3D' | - '\u0D4E' | - '\u0D60' | - '\u0D61' | - '\u0D7A'..'\u0D7F' | - '\u0D85'..'\u0D96' | - '\u0D9A'..'\u0DB1' | - '\u0DB3'..'\u0DBB' | - '\u0DBD' | - '\u0DC0'..'\u0DC6' | - '\u0E01'..'\u0E30' | - '\u0E32' | - '\u0E33' | - '\u0E40'..'\u0E45' | - '\u0E81' | - '\u0E82' | - '\u0E84' | - '\u0E87' | - '\u0E88' | - '\u0E8A' | - '\u0E8D' | - '\u0E94'..'\u0E97' | - '\u0E99'..'\u0E9F' | - '\u0EA1'..'\u0EA3' | - '\u0EA5' | - '\u0EA7' | - '\u0EAA' | - '\u0EAB' | - '\u0EAD'..'\u0EB0' | - '\u0EB2' | - '\u0EB3' | - '\u0EBD' | - '\u0EC0'..'\u0EC4' | - '\u0EDC'..'\u0EDF' | - '\u0F00' | - '\u0F40'..'\u0F47' | - '\u0F49'..'\u0F6C' | - '\u0F88'..'\u0F8C' | - '\u1000'..'\u102A' | - '\u103F' | - '\u1050'..'\u1055' | - '\u105A'..'\u105D' | - '\u1061' | - '\u1065' | - '\u1066' | - '\u106E'..'\u1070' | - '\u1075'..'\u1081' | - '\u108E' | - '\u10D0'..'\u10FA' | - '\u10FD'..'\u1248' | - '\u124A'..'\u124D' | - '\u1250'..'\u1256' | - '\u1258' | - '\u125A'..'\u125D' | - '\u1260'..'\u1288' | - '\u128A'..'\u128D' | - '\u1290'..'\u12B0' | - '\u12B2'..'\u12B5' | - '\u12B8'..'\u12BE' | - '\u12C0' | - '\u12C2'..'\u12C5' | - '\u12C8'..'\u12D6' | - '\u12D8'..'\u1310' | - '\u1312'..'\u1315' | - '\u1318'..'\u135A' | - '\u1380'..'\u138F' | - '\u13A0'..'\u13F4' | - '\u1401'..'\u166C' | - '\u166F'..'\u167F' | - '\u1681'..'\u169A' | - '\u16A0'..'\u16EA' | - '\u1700'..'\u170C' | - '\u170E'..'\u1711' | - '\u1720'..'\u1731' | - '\u1740'..'\u1751' | - '\u1760'..'\u176C' | - '\u176E'..'\u1770' | - '\u1780'..'\u17B3' | - '\u17DC' | - '\u1820'..'\u1842' | - '\u1844'..'\u1877' | - '\u1880'..'\u18A8' | - '\u18AA' | - '\u18B0'..'\u18F5' | - '\u1900'..'\u191C' | - '\u1950'..'\u196D' | - '\u1970'..'\u1974' | - '\u1980'..'\u19AB' | - '\u19C1'..'\u19C7' | - '\u1A00'..'\u1A16' | - '\u1A20'..'\u1A54' | - '\u1B05'..'\u1B33' | - '\u1B45'..'\u1B4B' | - '\u1B83'..'\u1BA0' | - '\u1BAE' | - '\u1BAF' | - '\u1BBA'..'\u1BE5' | - '\u1C00'..'\u1C23' | - '\u1C4D'..'\u1C4F' | - '\u1C5A'..'\u1C77' | - '\u1CE9'..'\u1CEC' | - '\u1CEE'..'\u1CF1' | - '\u1CF5' | - '\u1CF6' | - '\u2135'..'\u2138' | - '\u2D30'..'\u2D67' | - '\u2D80'..'\u2D96' | - '\u2DA0'..'\u2DA6' | - '\u2DA8'..'\u2DAE' | - '\u2DB0'..'\u2DB6' | - '\u2DB8'..'\u2DBE' | - '\u2DC0'..'\u2DC6' | - '\u2DC8'..'\u2DCE' | - '\u2DD0'..'\u2DD6' | - '\u2DD8'..'\u2DDE' | - '\u3006' | - '\u303C' | - '\u3041'..'\u3096' | - '\u309F' | - '\u30A1'..'\u30FA' | - '\u30FF' | - '\u3105'..'\u312D' | - '\u3131'..'\u318E' | - '\u31A0'..'\u31BA' | - '\u31F0'..'\u31FF' | - '\u3400' | - '\u4DB5' | - '\u4E00' | - '\u9FCC' | - '\uA000'..'\uA014' | - '\uA016'..'\uA48C' | - '\uA4D0'..'\uA4F7' | - '\uA500'..'\uA60B' | - '\uA610'..'\uA61F' | - '\uA62A' | - '\uA62B' | - '\uA66E' | - '\uA6A0'..'\uA6E5' | - '\uA7FB'..'\uA801' | - '\uA803'..'\uA805' | - '\uA807'..'\uA80A' | - '\uA80C'..'\uA822' | - '\uA840'..'\uA873' | - '\uA882'..'\uA8B3' | - '\uA8F2'..'\uA8F7' | - '\uA8FB' | - '\uA90A'..'\uA925' | - '\uA930'..'\uA946' | - '\uA960'..'\uA97C' | - '\uA984'..'\uA9B2' | - '\uAA00'..'\uAA28' | - '\uAA40'..'\uAA42' | - '\uAA44'..'\uAA4B' | - '\uAA60'..'\uAA6F' | - '\uAA71'..'\uAA76' | - '\uAA7A' | - '\uAA80'..'\uAAAF' | - '\uAAB1' | - '\uAAB5' | - '\uAAB6' | - '\uAAB9'..'\uAABD' | - '\uAAC0' | - '\uAAC2' | - '\uAADB' | - '\uAADC' | - '\uAAE0'..'\uAAEA' | - '\uAAF2' | - '\uAB01'..'\uAB06' | - '\uAB09'..'\uAB0E' | - '\uAB11'..'\uAB16' | - '\uAB20'..'\uAB26' | - '\uAB28'..'\uAB2E' | - '\uABC0'..'\uABE2' | - '\uAC00' | - '\uD7A3' | - '\uD7B0'..'\uD7C6' | - '\uD7CB'..'\uD7FB' | - '\uF900'..'\uFA6D' | - '\uFA70'..'\uFAD9' | - '\uFB1D' | - '\uFB1F'..'\uFB28' | - '\uFB2A'..'\uFB36' | - '\uFB38'..'\uFB3C' | - '\uFB3E' | - '\uFB40' | - '\uFB41' | - '\uFB43' | - '\uFB44' | - '\uFB46'..'\uFBB1' | - '\uFBD3'..'\uFD3D' | - '\uFD50'..'\uFD8F' | - '\uFD92'..'\uFDC7' | - '\uFDF0'..'\uFDFB' | - '\uFE70'..'\uFE74' | - '\uFE76'..'\uFEFC' | - '\uFF66'..'\uFF6F' | - '\uFF71'..'\uFF9D' | - '\uFFA0'..'\uFFBE' | - '\uFFC2'..'\uFFC7' | - '\uFFCA'..'\uFFCF' | - '\uFFD2'..'\uFFD7' | - '\uFFDA'..'\uFFDC'; - -UNICODE_CLASS_LT: - '\u01C5' | - '\u01C8' | - '\u01CB' | - '\u01F2' | - '\u1F88'..'\u1F8F' | - '\u1F98'..'\u1F9F' | - '\u1FA8'..'\u1FAF' | - '\u1FBC' | - '\u1FCC' | - '\u1FFC'; - -UNICODE_CLASS_LU: - '\u0041'..'\u005A' | - '\u00C0'..'\u00D6' | - '\u00D8'..'\u00DE' | - '\u0100' | - '\u0102' | - '\u0104' | - '\u0106' | - '\u0108' | - '\u010A' | - '\u010C' | - '\u010E' | - '\u0110' | - '\u0112' | - '\u0114' | - '\u0116' | - '\u0118' | - '\u011A' | - '\u011C' | - '\u011E' | - '\u0120' | - '\u0122' | - '\u0124' | - '\u0126' | - '\u0128' | - '\u012A' | - '\u012C' | - '\u012E' | - '\u0130' | - '\u0132' | - '\u0134' | - '\u0136' | - '\u0139' | - '\u013B' | - '\u013D' | - '\u013F' | - '\u0141' | - '\u0143' | - '\u0145' | - '\u0147' | - '\u014A' | - '\u014C' | - '\u014E' | - '\u0150' | - '\u0152' | - '\u0154' | - '\u0156' | - '\u0158' | - '\u015A' | - '\u015C' | - '\u015E' | - '\u0160' | - '\u0162' | - '\u0164' | - '\u0166' | - '\u0168' | - '\u016A' | - '\u016C' | - '\u016E' | - '\u0170' | - '\u0172' | - '\u0174' | - '\u0176' | - '\u0178' | - '\u0179' | - '\u017B' | - '\u017D' | - '\u0181' | - '\u0182' | - '\u0184' | - '\u0186' | - '\u0187' | - '\u0189'..'\u018B' | - '\u018E'..'\u0191' | - '\u0193' | - '\u0194' | - '\u0196'..'\u0198' | - '\u019C' | - '\u019D' | - '\u019F' | - '\u01A0' | - '\u01A2' | - '\u01A4' | - '\u01A6' | - '\u01A7' | - '\u01A9' | - '\u01AC' | - '\u01AE' | - '\u01AF' | - '\u01B1'..'\u01B3' | - '\u01B5' | - '\u01B7' | - '\u01B8' | - '\u01BC' | - '\u01C4' | - '\u01C7' | - '\u01CA' | - '\u01CD' | - '\u01CF' | - '\u01D1' | - '\u01D3' | - '\u01D5' | - '\u01D7' | - '\u01D9' | - '\u01DB' | - '\u01DE' | - '\u01E0' | - '\u01E2' | - '\u01E4' | - '\u01E6' | - '\u01E8' | - '\u01EA' | - '\u01EC' | - '\u01EE' | - '\u01F1' | - '\u01F4' | - '\u01F6'..'\u01F8' | - '\u01FA' | - '\u01FC' | - '\u01FE' | - '\u0200' | - '\u0202' | - '\u0204' | - '\u0206' | - '\u0208' | - '\u020A' | - '\u020C' | - '\u020E' | - '\u0210' | - '\u0212' | - '\u0214' | - '\u0216' | - '\u0218' | - '\u021A' | - '\u021C' | - '\u021E' | - '\u0220' | - '\u0222' | - '\u0224' | - '\u0226' | - '\u0228' | - '\u022A' | - '\u022C' | - '\u022E' | - '\u0230' | - '\u0232' | - '\u023A' | - '\u023B' | - '\u023D' | - '\u023E' | - '\u0241' | - '\u0243'..'\u0246' | - '\u0248' | - '\u024A' | - '\u024C' | - '\u024E' | - '\u0370' | - '\u0372' | - '\u0376' | - '\u0386' | - '\u0388'..'\u038A' | - '\u038C' | - '\u038E' | - '\u038F' | - '\u0391'..'\u03A1' | - '\u03A3'..'\u03AB' | - '\u03CF' | - '\u03D2'..'\u03D4' | - '\u03D8' | - '\u03DA' | - '\u03DC' | - '\u03DE' | - '\u03E0' | - '\u03E2' | - '\u03E4' | - '\u03E6' | - '\u03E8' | - '\u03EA' | - '\u03EC' | - '\u03EE' | - '\u03F4' | - '\u03F7' | - '\u03F9' | - '\u03FA' | - '\u03FD'..'\u042F' | - '\u0460' | - '\u0462' | - '\u0464' | - '\u0466' | - '\u0468' | - '\u046A' | - '\u046C' | - '\u046E' | - '\u0470' | - '\u0472' | - '\u0474' | - '\u0476' | - '\u0478' | - '\u047A' | - '\u047C' | - '\u047E' | - '\u0480' | - '\u048A' | - '\u048C' | - '\u048E' | - '\u0490' | - '\u0492' | - '\u0494' | - '\u0496' | - '\u0498' | - '\u049A' | - '\u049C' | - '\u049E' | - '\u04A0' | - '\u04A2' | - '\u04A4' | - '\u04A6' | - '\u04A8' | - '\u04AA' | - '\u04AC' | - '\u04AE' | - '\u04B0' | - '\u04B2' | - '\u04B4' | - '\u04B6' | - '\u04B8' | - '\u04BA' | - '\u04BC' | - '\u04BE' | - '\u04C0' | - '\u04C1' | - '\u04C3' | - '\u04C5' | - '\u04C7' | - '\u04C9' | - '\u04CB' | - '\u04CD' | - '\u04D0' | - '\u04D2' | - '\u04D4' | - '\u04D6' | - '\u04D8' | - '\u04DA' | - '\u04DC' | - '\u04DE' | - '\u04E0' | - '\u04E2' | - '\u04E4' | - '\u04E6' | - '\u04E8' | - '\u04EA' | - '\u04EC' | - '\u04EE' | - '\u04F0' | - '\u04F2' | - '\u04F4' | - '\u04F6' | - '\u04F8' | - '\u04FA' | - '\u04FC' | - '\u04FE' | - '\u0500' | - '\u0502' | - '\u0504' | - '\u0506' | - '\u0508' | - '\u050A' | - '\u050C' | - '\u050E' | - '\u0510' | - '\u0512' | - '\u0514' | - '\u0516' | - '\u0518' | - '\u051A' | - '\u051C' | - '\u051E' | - '\u0520' | - '\u0522' | - '\u0524' | - '\u0526' | - '\u0531'..'\u0556' | - '\u10A0'..'\u10C5' | - '\u10C7' | - '\u10CD' | - '\u1E00' | - '\u1E02' | - '\u1E04' | - '\u1E06' | - '\u1E08' | - '\u1E0A' | - '\u1E0C' | - '\u1E0E' | - '\u1E10' | - '\u1E12' | - '\u1E14' | - '\u1E16' | - '\u1E18' | - '\u1E1A' | - '\u1E1C' | - '\u1E1E' | - '\u1E20' | - '\u1E22' | - '\u1E24' | - '\u1E26' | - '\u1E28' | - '\u1E2A' | - '\u1E2C' | - '\u1E2E' | - '\u1E30' | - '\u1E32' | - '\u1E34' | - '\u1E36' | - '\u1E38' | - '\u1E3A' | - '\u1E3C' | - '\u1E3E' | - '\u1E40' | - '\u1E42' | - '\u1E44' | - '\u1E46' | - '\u1E48' | - '\u1E4A' | - '\u1E4C' | - '\u1E4E' | - '\u1E50' | - '\u1E52' | - '\u1E54' | - '\u1E56' | - '\u1E58' | - '\u1E5A' | - '\u1E5C' | - '\u1E5E' | - '\u1E60' | - '\u1E62' | - '\u1E64' | - '\u1E66' | - '\u1E68' | - '\u1E6A' | - '\u1E6C' | - '\u1E6E' | - '\u1E70' | - '\u1E72' | - '\u1E74' | - '\u1E76' | - '\u1E78' | - '\u1E7A' | - '\u1E7C' | - '\u1E7E' | - '\u1E80' | - '\u1E82' | - '\u1E84' | - '\u1E86' | - '\u1E88' | - '\u1E8A' | - '\u1E8C' | - '\u1E8E' | - '\u1E90' | - '\u1E92' | - '\u1E94' | - '\u1E9E' | - '\u1EA0' | - '\u1EA2' | - '\u1EA4' | - '\u1EA6' | - '\u1EA8' | - '\u1EAA' | - '\u1EAC' | - '\u1EAE' | - '\u1EB0' | - '\u1EB2' | - '\u1EB4' | - '\u1EB6' | - '\u1EB8' | - '\u1EBA' | - '\u1EBC' | - '\u1EBE' | - '\u1EC0' | - '\u1EC2' | - '\u1EC4' | - '\u1EC6' | - '\u1EC8' | - '\u1ECA' | - '\u1ECC' | - '\u1ECE' | - '\u1ED0' | - '\u1ED2' | - '\u1ED4' | - '\u1ED6' | - '\u1ED8' | - '\u1EDA' | - '\u1EDC' | - '\u1EDE' | - '\u1EE0' | - '\u1EE2' | - '\u1EE4' | - '\u1EE6' | - '\u1EE8' | - '\u1EEA' | - '\u1EEC' | - '\u1EEE' | - '\u1EF0' | - '\u1EF2' | - '\u1EF4' | - '\u1EF6' | - '\u1EF8' | - '\u1EFA' | - '\u1EFC' | - '\u1EFE' | - '\u1F08'..'\u1F0F' | - '\u1F18'..'\u1F1D' | - '\u1F28'..'\u1F2F' | - '\u1F38'..'\u1F3F' | - '\u1F48'..'\u1F4D' | - '\u1F59' | - '\u1F5B' | - '\u1F5D' | - '\u1F5F' | - '\u1F68'..'\u1F6F' | - '\u1FB8'..'\u1FBB' | - '\u1FC8'..'\u1FCB' | - '\u1FD8'..'\u1FDB' | - '\u1FE8'..'\u1FEC' | - '\u1FF8'..'\u1FFB' | - '\u2102' | - '\u2107' | - '\u210B'..'\u210D' | - '\u2110'..'\u2112' | - '\u2115' | - '\u2119'..'\u211D' | - '\u2124' | - '\u2126' | - '\u2128' | - '\u212A'..'\u212D' | - '\u2130'..'\u2133' | - '\u213E' | - '\u213F' | - '\u2145' | - '\u2183' | - '\u2C00'..'\u2C2E' | - '\u2C60' | - '\u2C62'..'\u2C64' | - '\u2C67' | - '\u2C69' | - '\u2C6B' | - '\u2C6D'..'\u2C70' | - '\u2C72' | - '\u2C75' | - '\u2C7E'..'\u2C80' | - '\u2C82' | - '\u2C84' | - '\u2C86' | - '\u2C88' | - '\u2C8A' | - '\u2C8C' | - '\u2C8E' | - '\u2C90' | - '\u2C92' | - '\u2C94' | - '\u2C96' | - '\u2C98' | - '\u2C9A' | - '\u2C9C' | - '\u2C9E' | - '\u2CA0' | - '\u2CA2' | - '\u2CA4' | - '\u2CA6' | - '\u2CA8' | - '\u2CAA' | - '\u2CAC' | - '\u2CAE' | - '\u2CB0' | - '\u2CB2' | - '\u2CB4' | - '\u2CB6' | - '\u2CB8' | - '\u2CBA' | - '\u2CBC' | - '\u2CBE' | - '\u2CC0' | - '\u2CC2' | - '\u2CC4' | - '\u2CC6' | - '\u2CC8' | - '\u2CCA' | - '\u2CCC' | - '\u2CCE' | - '\u2CD0' | - '\u2CD2' | - '\u2CD4' | - '\u2CD6' | - '\u2CD8' | - '\u2CDA' | - '\u2CDC' | - '\u2CDE' | - '\u2CE0' | - '\u2CE2' | - '\u2CEB' | - '\u2CED' | - '\u2CF2' | - '\uA640' | - '\uA642' | - '\uA644' | - '\uA646' | - '\uA648' | - '\uA64A' | - '\uA64C' | - '\uA64E' | - '\uA650' | - '\uA652' | - '\uA654' | - '\uA656' | - '\uA658' | - '\uA65A' | - '\uA65C' | - '\uA65E' | - '\uA660' | - '\uA662' | - '\uA664' | - '\uA666' | - '\uA668' | - '\uA66A' | - '\uA66C' | - '\uA680' | - '\uA682' | - '\uA684' | - '\uA686' | - '\uA688' | - '\uA68A' | - '\uA68C' | - '\uA68E' | - '\uA690' | - '\uA692' | - '\uA694' | - '\uA696' | - '\uA722' | - '\uA724' | - '\uA726' | - '\uA728' | - '\uA72A' | - '\uA72C' | - '\uA72E' | - '\uA732' | - '\uA734' | - '\uA736' | - '\uA738' | - '\uA73A' | - '\uA73C' | - '\uA73E' | - '\uA740' | - '\uA742' | - '\uA744' | - '\uA746' | - '\uA748' | - '\uA74A' | - '\uA74C' | - '\uA74E' | - '\uA750' | - '\uA752' | - '\uA754' | - '\uA756' | - '\uA758' | - '\uA75A' | - '\uA75C' | - '\uA75E' | - '\uA760' | - '\uA762' | - '\uA764' | - '\uA766' | - '\uA768' | - '\uA76A' | - '\uA76C' | - '\uA76E' | - '\uA779' | - '\uA77B' | - '\uA77D' | - '\uA77E' | - '\uA780' | - '\uA782' | - '\uA784' | - '\uA786' | - '\uA78B' | - '\uA78D' | - '\uA790' | - '\uA792' | - '\uA7A0' | - '\uA7A2' | - '\uA7A4' | - '\uA7A6' | - '\uA7A8' | - '\uA7AA' | - '\uFF21'..'\uFF3A'; - -UNICODE_CLASS_ND: - '\u0030'..'\u0039' | - '\u0660'..'\u0669' | - '\u06F0'..'\u06F9' | - '\u07C0'..'\u07C9' | - '\u0966'..'\u096F' | - '\u09E6'..'\u09EF' | - '\u0A66'..'\u0A6F' | - '\u0AE6'..'\u0AEF' | - '\u0B66'..'\u0B6F' | - '\u0BE6'..'\u0BEF' | - '\u0C66'..'\u0C6F' | - '\u0CE6'..'\u0CEF' | - '\u0D66'..'\u0D6F' | - '\u0E50'..'\u0E59' | - '\u0ED0'..'\u0ED9' | - '\u0F20'..'\u0F29' | - '\u1040'..'\u1049' | - '\u1090'..'\u1099' | - '\u17E0'..'\u17E9' | - '\u1810'..'\u1819' | - '\u1946'..'\u194F' | - '\u19D0'..'\u19D9' | - '\u1A80'..'\u1A89' | - '\u1A90'..'\u1A99' | - '\u1B50'..'\u1B59' | - '\u1BB0'..'\u1BB9' | - '\u1C40'..'\u1C49' | - '\u1C50'..'\u1C59' | - '\uA620'..'\uA629' | - '\uA8D0'..'\uA8D9' | - '\uA900'..'\uA909' | - '\uA9D0'..'\uA9D9' | - '\uAA50'..'\uAA59' | - '\uABF0'..'\uABF9' | - '\uFF10'..'\uFF19'; - -UNICODE_CLASS_NL: - '\u16EE'..'\u16F0' | - '\u2160'..'\u2182' | - '\u2185'..'\u2188' | - '\u3007' | - '\u3021'..'\u3029' | - '\u3038'..'\u303A' | - '\uA6E6'..'\uA6EF'; - -// SECTION: lexicalGeneral - -ShebangLine - : '#!' ~[\r\n]* - ; - -DelimitedComment - : '/*' ( DelimitedComment | . )*? '*/' - -> channel(HIDDEN) - ; - -LineComment - : '//' ~[\r\n]* - -> channel(HIDDEN) - ; - -WS - : [\u0020\u0009\u000C] - -> channel(HIDDEN) - ; - -NL: '\n' | '\r' '\n'?; - -fragment Hidden: DelimitedComment | LineComment | WS; - -// SECTION: separatorsAndOperations - -RESERVED: '...'; -DOT: '.'; -COMMA: ','; -LPAREN: '(' -> pushMode(Inside); -RPAREN: ')'; -LSQUARE: '[' -> pushMode(Inside); -RSQUARE: ']'; -LCURL: '{' -> pushMode(DEFAULT_MODE); -/* - * When using another programming language (not Java) to generate a parser, - * please replace this code with the corresponding code of a programming language you are using. - */ -RCURL: '}' { if (!_modeStack.isEmpty()) { popMode(); } }; -MULT: '*'; -MOD: '%'; -DIV: '/'; -ADD: '+'; -SUB: '-'; -INCR: '++'; -DECR: '--'; -CONJ: '&&'; -DISJ: '||'; -EXCL_WS: '!' Hidden; -EXCL_NO_WS: '!'; -COLON: ':'; -SEMICOLON: ';'; -ASSIGNMENT: '='; -ADD_ASSIGNMENT: '+='; -SUB_ASSIGNMENT: '-='; -MULT_ASSIGNMENT: '*='; -DIV_ASSIGNMENT: '/='; -MOD_ASSIGNMENT: '%='; -ARROW: '->'; -DOUBLE_ARROW: '=>'; -RANGE: '..'; -COLONCOLON: '::'; -DOUBLE_SEMICOLON: ';;'; -HASH: '#'; -AT_NO_WS: '@'; -AT_POST_WS: '@' (Hidden | NL); -AT_PRE_WS: (Hidden | NL) '@' ; -AT_BOTH_WS: (Hidden | NL) '@' (Hidden | NL); -QUEST_WS: '?' Hidden; -QUEST_NO_WS: '?'; -LANGLE: '<'; -RANGLE: '>'; -LE: '<='; -GE: '>='; -EXCL_EQ: '!='; -EXCL_EQEQ: '!=='; -AS_SAFE: 'as?'; -EQEQ: '=='; -EQEQEQ: '==='; -SINGLE_QUOTE: '\''; - -// SECTION: keywords - -RETURN_AT: 'return@' Identifier; -CONTINUE_AT: 'continue@' Identifier; -BREAK_AT: 'break@' Identifier; - -THIS_AT: 'this@' Identifier; -SUPER_AT: 'super@' Identifier; - -FILE: 'file'; -FIELD: 'field'; -PROPERTY: 'property'; -GET: 'get'; -SET: 'set'; -RECEIVER: 'receiver'; -PARAM: 'param'; -SETPARAM: 'setparam'; -DELEGATE: 'delegate'; - -PACKAGE: 'package'; -IMPORT: 'import'; -CLASS: 'class'; -INTERFACE: 'interface'; -FUN: 'fun'; -OBJECT: 'object'; -VAL: 'val'; -VAR: 'var'; -TYPE_ALIAS: 'typealias'; -CONSTRUCTOR: 'constructor'; -BY: 'by'; -COMPANION: 'companion'; -INIT: 'init'; -THIS: 'this'; -SUPER: 'super'; -TYPEOF: 'typeof'; -WHERE: 'where'; -IF: 'if'; -ELSE: 'else'; -WHEN: 'when'; -TRY: 'try'; -CATCH: 'catch'; -FINALLY: 'finally'; -FOR: 'for'; -DO: 'do'; -WHILE: 'while'; -THROW: 'throw'; -RETURN: 'return'; -CONTINUE: 'continue'; -BREAK: 'break'; -AS: 'as'; -IS: 'is'; -IN: 'in'; -NOT_IS: '!is' (Hidden | NL); -NOT_IN: '!in' (Hidden | NL); -OUT: 'out'; -DYNAMIC: 'dynamic'; - -// SECTION: lexicalModifiers - -PUBLIC: 'public'; -PRIVATE: 'private'; -PROTECTED: 'protected'; -INTERNAL: 'internal'; -ENUM: 'enum'; -SEALED: 'sealed'; -ANNOTATION: 'annotation'; -DATA: 'data'; -INNER: 'inner'; -VALUE: 'value'; -TAILREC: 'tailrec'; -OPERATOR: 'operator'; -INLINE: 'inline'; -INFIX: 'infix'; -EXTERNAL: 'external'; -SUSPEND: 'suspend'; -OVERRIDE: 'override'; -ABSTRACT: 'abstract'; -FINAL: 'final'; -OPEN: 'open'; -CONST: 'const'; -LATEINIT: 'lateinit'; -VARARG: 'vararg'; -NOINLINE: 'noinline'; -CROSSINLINE: 'crossinline'; -REIFIED: 'reified'; -EXPECT: 'expect'; -ACTUAL: 'actual'; - -// SECTION: literals - -fragment DecDigit: '0'..'9'; -fragment DecDigitNoZero: '1'..'9'; -fragment DecDigitOrSeparator: DecDigit | '_'; - -fragment DecDigits - : DecDigit DecDigitOrSeparator* DecDigit - | DecDigit - ; - -fragment DoubleExponent: [eE] [+-]? DecDigits; - -RealLiteral - : FloatLiteral - | DoubleLiteral - ; - -FloatLiteral - : DoubleLiteral [fF] - | DecDigits [fF] - ; - -DoubleLiteral - : DecDigits? '.' DecDigits DoubleExponent? - | DecDigits DoubleExponent - ; - -IntegerLiteral - : DecDigitNoZero DecDigitOrSeparator* DecDigit - | DecDigit - ; - -fragment HexDigit: [0-9a-fA-F]; -fragment HexDigitOrSeparator: HexDigit | '_'; - -HexLiteral - : '0' [xX] HexDigit HexDigitOrSeparator* HexDigit - | '0' [xX] HexDigit - ; - -fragment BinDigit: [01]; -fragment BinDigitOrSeparator: BinDigit | '_'; - -BinLiteral - : '0' [bB] BinDigit BinDigitOrSeparator* BinDigit - | '0' [bB] BinDigit - ; - -UnsignedLiteral - : (IntegerLiteral | HexLiteral | BinLiteral) [uU] [lL]? - ; - -LongLiteral - : (IntegerLiteral | HexLiteral | BinLiteral) [lL] - ; - -BooleanLiteral: 'true'| 'false'; - -NullLiteral: 'null'; - -CharacterLiteral - : '\'' (EscapeSeq | ~[\n\r'\\]) '\'' - ; - -// SECTION: lexicalIdentifiers - -fragment UnicodeDigit: UNICODE_CLASS_ND; - -Identifier - : (Letter | '_') (Letter | '_' | UnicodeDigit)* - | '`' ~([\r\n] | '`')+ '`' - ; - -IdentifierOrSoftKey - : Identifier - /* Soft keywords */ - | ABSTRACT - | ANNOTATION - | BY - | CATCH - | COMPANION - | CONSTRUCTOR - | CROSSINLINE - | DATA - | DYNAMIC - | ENUM - | EXTERNAL - | FINAL - | FINALLY - | IMPORT - | INFIX - | INIT - | INLINE - | INNER - | INTERNAL - | LATEINIT - | NOINLINE - | OPEN - | OPERATOR - | OUT - | OVERRIDE - | PRIVATE - | PROTECTED - | PUBLIC - | REIFIED - | SEALED - | TAILREC - | VARARG - | WHERE - | GET - | SET - | FIELD - | PROPERTY - | RECEIVER - | PARAM - | SETPARAM - | DELEGATE - | FILE - | EXPECT - | ACTUAL - | VALUE - /* Strong keywords */ - | CONST - | SUSPEND - ; - -FieldIdentifier - : '$' IdentifierOrSoftKey - ; - -fragment UniCharacterLiteral - : '\\' 'u' HexDigit HexDigit HexDigit HexDigit - ; - -fragment EscapedIdentifier - : '\\' ('t' | 'b' | 'r' | 'n' | '\'' | '"' | '\\' | '$') - ; - -fragment EscapeSeq - : UniCharacterLiteral - | EscapedIdentifier - ; - -// SECTION: characters - -fragment Letter - : UNICODE_CLASS_LL - | UNICODE_CLASS_LM - | UNICODE_CLASS_LO - | UNICODE_CLASS_LT - | UNICODE_CLASS_LU - | UNICODE_CLASS_NL - ; - -// SECTION: strings - -QUOTE_OPEN: '"' -> pushMode(LineString); - -TRIPLE_QUOTE_OPEN: '"""' -> pushMode(MultiLineString); - -mode LineString; - -QUOTE_CLOSE - : '"' -> popMode - ; - -LineStrRef - : FieldIdentifier - ; - -LineStrText - : ~('\\' | '"' | '$')+ | '$' - ; - -LineStrEscapedChar - : EscapedIdentifier - | UniCharacterLiteral - ; - -LineStrExprStart - : '${' -> pushMode(DEFAULT_MODE) - ; - -mode MultiLineString; - -TRIPLE_QUOTE_CLOSE - : MultiLineStringQuote? '"""' -> popMode - ; - -MultiLineStringQuote - : '"'+ - ; - -MultiLineStrRef - : FieldIdentifier - ; - -MultiLineStrText - : ~('"' | '$')+ | '$' - ; - -MultiLineStrExprStart - : '${' -> pushMode(DEFAULT_MODE) - ; - -// SECTION: inside - -mode Inside; - -Inside_RPAREN: RPAREN -> popMode, type(RPAREN); -Inside_RSQUARE: RSQUARE -> popMode, type(RSQUARE); -Inside_LPAREN: LPAREN -> pushMode(Inside), type(LPAREN); -Inside_LSQUARE: LSQUARE -> pushMode(Inside), type(LSQUARE); -Inside_LCURL: LCURL -> pushMode(DEFAULT_MODE), type(LCURL); -Inside_RCURL: RCURL -> popMode, type(RCURL); - -Inside_DOT: DOT -> type(DOT); -Inside_COMMA: COMMA -> type(COMMA); -Inside_MULT: MULT -> type(MULT); -Inside_MOD: MOD -> type(MOD); -Inside_DIV: DIV -> type(DIV); -Inside_ADD: ADD -> type(ADD); -Inside_SUB: SUB -> type(SUB); -Inside_INCR: INCR -> type(INCR); -Inside_DECR: DECR -> type(DECR); -Inside_CONJ: CONJ -> type(CONJ); -Inside_DISJ: DISJ -> type(DISJ); -Inside_EXCL_WS: '!' (Hidden|NL) -> type(EXCL_WS); -Inside_EXCL_NO_WS: EXCL_NO_WS -> type(EXCL_NO_WS); -Inside_COLON: COLON -> type(COLON); -Inside_SEMICOLON: SEMICOLON -> type(SEMICOLON); -Inside_ASSIGNMENT: ASSIGNMENT -> type(ASSIGNMENT); -Inside_ADD_ASSIGNMENT: ADD_ASSIGNMENT -> type(ADD_ASSIGNMENT); -Inside_SUB_ASSIGNMENT: SUB_ASSIGNMENT -> type(SUB_ASSIGNMENT); -Inside_MULT_ASSIGNMENT: MULT_ASSIGNMENT -> type(MULT_ASSIGNMENT); -Inside_DIV_ASSIGNMENT: DIV_ASSIGNMENT -> type(DIV_ASSIGNMENT); -Inside_MOD_ASSIGNMENT: MOD_ASSIGNMENT -> type(MOD_ASSIGNMENT); -Inside_ARROW: ARROW -> type(ARROW); -Inside_DOUBLE_ARROW: DOUBLE_ARROW -> type(DOUBLE_ARROW); -Inside_RANGE: RANGE -> type(RANGE); -Inside_RESERVED: RESERVED -> type(RESERVED); -Inside_COLONCOLON: COLONCOLON -> type(COLONCOLON); -Inside_DOUBLE_SEMICOLON: DOUBLE_SEMICOLON -> type(DOUBLE_SEMICOLON); -Inside_HASH: HASH -> type(HASH); -Inside_AT_NO_WS: AT_NO_WS -> type(AT_NO_WS); -Inside_AT_POST_WS: AT_POST_WS -> type(AT_POST_WS); -Inside_AT_PRE_WS: AT_PRE_WS -> type(AT_PRE_WS); -Inside_AT_BOTH_WS: AT_BOTH_WS -> type(AT_BOTH_WS); -Inside_QUEST_WS: '?' (Hidden | NL) -> type(QUEST_WS); -Inside_QUEST_NO_WS: QUEST_NO_WS -> type(QUEST_NO_WS); -Inside_LANGLE: LANGLE -> type(LANGLE); -Inside_RANGLE: RANGLE -> type(RANGLE); -Inside_LE: LE -> type(LE); -Inside_GE: GE -> type(GE); -Inside_EXCL_EQ: EXCL_EQ -> type(EXCL_EQ); -Inside_EXCL_EQEQ: EXCL_EQEQ -> type(EXCL_EQEQ); -Inside_IS: IS -> type(IS); -Inside_NOT_IS: NOT_IS -> type(NOT_IS); -Inside_NOT_IN: NOT_IN -> type(NOT_IN); -Inside_AS: AS -> type(AS); -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_QUOTE_OPEN: QUOTE_OPEN -> pushMode(LineString), type(QUOTE_OPEN); -Inside_TRIPLE_QUOTE_OPEN: TRIPLE_QUOTE_OPEN -> pushMode(MultiLineString), type(TRIPLE_QUOTE_OPEN); - -Inside_VAL: VAL -> type(VAL); -Inside_VAR: VAR -> type(VAR); -Inside_FUN: FUN -> type(FUN); -Inside_OBJECT: OBJECT -> type(OBJECT); -Inside_SUPER: SUPER -> type(SUPER); -Inside_IN: IN -> type(IN); -Inside_OUT: OUT -> type(OUT); -Inside_FIELD: FIELD -> type(FIELD); -Inside_FILE: FILE -> type(FILE); -Inside_PROPERTY: PROPERTY -> type(PROPERTY); -Inside_GET: GET -> type(GET); -Inside_SET: SET -> type(SET); -Inside_RECEIVER: RECEIVER -> type(RECEIVER); -Inside_PARAM: PARAM -> type(PARAM); -Inside_SETPARAM: SETPARAM -> type(SETPARAM); -Inside_DELEGATE: DELEGATE -> type(DELEGATE); -Inside_THROW: THROW -> type(THROW); -Inside_RETURN: RETURN -> type(RETURN); -Inside_CONTINUE: CONTINUE -> type(CONTINUE); -Inside_BREAK: BREAK -> type(BREAK); -Inside_RETURN_AT: RETURN_AT -> type(RETURN_AT); -Inside_CONTINUE_AT: CONTINUE_AT -> type(CONTINUE_AT); -Inside_BREAK_AT: BREAK_AT -> type(BREAK_AT); -Inside_IF: IF -> type(IF); -Inside_ELSE: ELSE -> type(ELSE); -Inside_WHEN: WHEN -> type(WHEN); -Inside_TRY: TRY -> type(TRY); -Inside_CATCH: CATCH -> type(CATCH); -Inside_FINALLY: FINALLY -> type(FINALLY); -Inside_FOR: FOR -> type(FOR); -Inside_DO: DO -> type(DO); -Inside_WHILE: WHILE -> type(WHILE); - -Inside_PUBLIC: PUBLIC -> type(PUBLIC); -Inside_PRIVATE: PRIVATE -> type(PRIVATE); -Inside_PROTECTED: PROTECTED -> type(PROTECTED); -Inside_INTERNAL: INTERNAL -> type(INTERNAL); -Inside_ENUM: ENUM -> type(ENUM); -Inside_SEALED: SEALED -> type(SEALED); -Inside_ANNOTATION: ANNOTATION -> type(ANNOTATION); -Inside_DATA: DATA -> type(DATA); -Inside_INNER: INNER -> type(INNER); -Inside_VALUE: VALUE -> type(VALUE); -Inside_TAILREC: TAILREC -> type(TAILREC); -Inside_OPERATOR: OPERATOR -> type(OPERATOR); -Inside_INLINE: INLINE -> type(INLINE); -Inside_INFIX: INFIX -> type(INFIX); -Inside_EXTERNAL: EXTERNAL -> type(EXTERNAL); -Inside_SUSPEND: SUSPEND -> type(SUSPEND); -Inside_OVERRIDE: OVERRIDE -> type(OVERRIDE); -Inside_ABSTRACT: ABSTRACT -> type(ABSTRACT); -Inside_FINAL: FINAL -> type(FINAL); -Inside_OPEN: OPEN -> type(OPEN); -Inside_CONST: CONST -> type(CONST); -Inside_LATEINIT: LATEINIT -> type(LATEINIT); -Inside_VARARG: VARARG -> type(VARARG); -Inside_NOINLINE: NOINLINE -> type(NOINLINE); -Inside_CROSSINLINE: CROSSINLINE -> type(CROSSINLINE); -Inside_REIFIED: REIFIED -> type(REIFIED); -Inside_EXPECT: EXPECT -> type(EXPECT); -Inside_ACTUAL: ACTUAL -> type(ACTUAL); - -Inside_BooleanLiteral: BooleanLiteral -> type(BooleanLiteral); -Inside_IntegerLiteral: IntegerLiteral -> type(IntegerLiteral); -Inside_HexLiteral: HexLiteral -> type(HexLiteral); -Inside_BinLiteral: BinLiteral -> type(BinLiteral); -Inside_CharacterLiteral: CharacterLiteral -> type(CharacterLiteral); -Inside_RealLiteral: RealLiteral -> type(RealLiteral); -Inside_NullLiteral: NullLiteral -> type(NullLiteral); -Inside_LongLiteral: LongLiteral -> type(LongLiteral); -Inside_UnsignedLiteral: UnsignedLiteral -> type(UnsignedLiteral); - -Inside_Identifier: Identifier -> type(Identifier); -Inside_Comment: (LineComment | DelimitedComment) -> channel(HIDDEN); -Inside_WS: WS -> channel(HIDDEN); -Inside_NL: NL -> channel(HIDDEN); - -mode DEFAULT_MODE; - -ErrorCharacter: .; diff --git a/pmd-kotlin/src/main/antlr4/net/sourceforge/pmd/lang/kotlin/ast/KotlinParser.g4 b/pmd-kotlin/src/main/antlr4/net/sourceforge/pmd/lang/kotlin/ast/KotlinParser.g4 deleted file mode 100644 index 628dbed387..0000000000 --- a/pmd-kotlin/src/main/antlr4/net/sourceforge/pmd/lang/kotlin/ast/KotlinParser.g4 +++ /dev/null @@ -1,923 +0,0 @@ -/** - * Kotlin syntax grammar in ANTLR4 notation - */ - -parser grammar KotlinParser; - -options { tokenVocab = KotlinLexer; } - -// SECTION: general - -kotlinFile - : shebangLine? NL* fileAnnotation* packageHeader importList topLevelObject* EOF - ; - -script - : shebangLine? NL* fileAnnotation* packageHeader importList (statement semi)* EOF - ; - -shebangLine - : ShebangLine NL+ - ; - -fileAnnotation - : (AT_NO_WS | AT_PRE_WS) FILE NL* COLON NL* (LSQUARE unescapedAnnotation+ RSQUARE | unescapedAnnotation) NL* - ; - -packageHeader - : (PACKAGE identifier semi?)? - ; - -importList - : importHeader* - ; - -importHeader - : IMPORT identifier (DOT MULT | importAlias)? semi? - ; - -importAlias - : AS simpleIdentifier - ; - -topLevelObject - : declaration semis? - ; - -typeAlias - : modifiers? TYPE_ALIAS NL* simpleIdentifier (NL* typeParameters)? NL* ASSIGNMENT NL* type - ; - -declaration - : classDeclaration - | objectDeclaration - | functionDeclaration - | propertyDeclaration - | typeAlias - ; - -// SECTION: classes - -classDeclaration - : modifiers? (CLASS | (FUN NL*)? INTERFACE) NL* simpleIdentifier - (NL* typeParameters)? (NL* primaryConstructor)? - (NL* COLON NL* delegationSpecifiers)? - (NL* typeConstraints)? - (NL* classBody | NL* enumClassBody)? - ; - -primaryConstructor - : (modifiers? CONSTRUCTOR NL*)? classParameters - ; - -classBody - : LCURL NL* classMemberDeclarations NL* RCURL - ; - -classParameters - : LPAREN NL* (classParameter (NL* COMMA NL* classParameter)* (NL* COMMA)?)? NL* RPAREN - ; - -classParameter - : modifiers? (VAL | VAR)? NL* simpleIdentifier COLON NL* type (NL* ASSIGNMENT NL* expression)? - ; - -delegationSpecifiers - : annotatedDelegationSpecifier (NL* COMMA NL* annotatedDelegationSpecifier)* - ; - -delegationSpecifier - : constructorInvocation - | explicitDelegation - | userType - | functionType - ; - -constructorInvocation - : userType valueArguments - ; - -annotatedDelegationSpecifier - : annotation* NL* delegationSpecifier - ; - -explicitDelegation - : (userType | functionType) NL* BY NL* expression - ; - -typeParameters - : LANGLE NL* typeParameter (NL* COMMA NL* typeParameter)* (NL* COMMA)? NL* RANGLE - ; - -typeParameter - : typeParameterModifiers? NL* simpleIdentifier (NL* COLON NL* type)? - ; - -typeConstraints - : WHERE NL* typeConstraint (NL* COMMA NL* typeConstraint)* - ; - -typeConstraint - : annotation* simpleIdentifier NL* COLON NL* type - ; - -// SECTION: classMembers - -classMemberDeclarations - : (classMemberDeclaration semis?)* - ; - -classMemberDeclaration - : declaration - | companionObject - | anonymousInitializer - | secondaryConstructor - ; - -anonymousInitializer - : INIT NL* block - ; - -companionObject - : modifiers? COMPANION NL* OBJECT - (NL* simpleIdentifier)? - (NL* COLON NL* delegationSpecifiers)? - (NL* classBody)? - ; - -functionValueParameters - : LPAREN NL* (functionValueParameter (NL* COMMA NL* functionValueParameter)* (NL* COMMA)?)? NL* RPAREN - ; - -functionValueParameter - : parameterModifiers? parameter (NL* ASSIGNMENT NL* expression)? - ; - -functionDeclaration - : modifiers? - FUN (NL* typeParameters)? (NL* receiverType NL* DOT)? NL* simpleIdentifier - NL* functionValueParameters - (NL* COLON NL* type)? - (NL* typeConstraints)? - (NL* functionBody)? - ; - -functionBody - : block - | ASSIGNMENT NL* expression - ; - -variableDeclaration - : annotation* NL* simpleIdentifier (NL* COLON NL* type)? - ; - -multiVariableDeclaration - : LPAREN NL* variableDeclaration (NL* COMMA NL* variableDeclaration)* (NL* COMMA)? NL* RPAREN - ; - -propertyDeclaration - : modifiers? (VAL | VAR) - (NL* typeParameters)? - (NL* receiverType NL* DOT)? - (NL* (multiVariableDeclaration | variableDeclaration)) - (NL* typeConstraints)? - (NL* (ASSIGNMENT NL* expression | propertyDelegate))? - (NL+ SEMICOLON)? NL* (getter? (NL* semi? setter)? | setter? (NL* semi? getter)?) - ; - -propertyDelegate - : BY NL* expression - ; - -getter - : modifiers? GET - (NL* LPAREN NL* RPAREN (NL* COLON NL* type)? NL* functionBody)? - ; - -setter - : modifiers? SET - (NL* LPAREN NL* functionValueParameterWithOptionalType (NL* COMMA)? NL* RPAREN (NL* COLON NL* type)? NL* functionBody)? - ; - -parametersWithOptionalType - : LPAREN NL* (functionValueParameterWithOptionalType (NL* COMMA NL* functionValueParameterWithOptionalType)* (NL* COMMA)?)? NL* RPAREN - ; - -functionValueParameterWithOptionalType - : parameterModifiers? parameterWithOptionalType (NL* ASSIGNMENT NL* expression)? - ; - -parameterWithOptionalType - : simpleIdentifier NL* (COLON NL* type)? - ; - -parameter - : simpleIdentifier NL* COLON NL* type - ; - -objectDeclaration - : modifiers? OBJECT - NL* simpleIdentifier - (NL* COLON NL* delegationSpecifiers)? - (NL* classBody)? - ; - -secondaryConstructor - : modifiers? CONSTRUCTOR NL* functionValueParameters (NL* COLON NL* constructorDelegationCall)? NL* block? - ; - -constructorDelegationCall - : (THIS | SUPER) NL* valueArguments - ; - -// SECTION: enumClasses - -enumClassBody - : LCURL NL* enumEntries? (NL* SEMICOLON NL* classMemberDeclarations)? NL* RCURL - ; - -enumEntries - : enumEntry (NL* COMMA NL* enumEntry)* NL* COMMA? - ; - -enumEntry - : (modifiers NL*)? simpleIdentifier (NL* valueArguments)? (NL* classBody)? - ; - -// SECTION: types - -type - : typeModifiers? (parenthesizedType | nullableType | typeReference | functionType) - ; - -typeReference - : userType - | DYNAMIC - ; - -nullableType - : (typeReference | parenthesizedType) NL* quest+ - ; - -quest - : QUEST_NO_WS - | QUEST_WS - ; - -userType - : simpleUserType (NL* DOT NL* simpleUserType)* - ; - -simpleUserType - : simpleIdentifier (NL* typeArguments)? - ; - -typeProjection - : typeProjectionModifiers? type - | MULT - ; - -typeProjectionModifiers - : typeProjectionModifier+ - ; - -typeProjectionModifier - : varianceModifier NL* - | annotation - ; - -functionType - : (receiverType NL* DOT NL*)? functionTypeParameters NL* ARROW NL* type - ; - -functionTypeParameters - : LPAREN NL* (parameter | type)? (NL* COMMA NL* (parameter | type))* (NL* COMMA)? NL* RPAREN - ; - -parenthesizedType - : LPAREN NL* type NL* RPAREN - ; - -receiverType - : typeModifiers? (parenthesizedType | nullableType | typeReference) - ; - -parenthesizedUserType - : LPAREN NL* (userType | parenthesizedUserType) NL* RPAREN - ; - -// SECTION: statements - -statements - : (statement (semis statement)*)? semis? - ; - -statement - : (label | annotation)* ( declaration | assignment | loopStatement | expression) - ; - -label - : simpleIdentifier (AT_NO_WS | AT_POST_WS) NL* - ; - -controlStructureBody - : block - | statement - ; - -block - : LCURL NL* statements NL* RCURL - ; - -loopStatement - : forStatement - | whileStatement - | doWhileStatement - ; - -forStatement - : FOR NL* LPAREN annotation* (variableDeclaration | multiVariableDeclaration) - IN expression RPAREN NL* controlStructureBody? - ; - -whileStatement - : WHILE NL* LPAREN expression RPAREN NL* (controlStructureBody | SEMICOLON) - ; - -doWhileStatement - : DO NL* controlStructureBody? NL* WHILE NL* LPAREN expression RPAREN - ; - -assignment - : (directlyAssignableExpression ASSIGNMENT | assignableExpression assignmentAndOperator) NL* expression - ; - -semi - : (SEMICOLON | NL) NL* - | EOF - ; - -semis - : (SEMICOLON | NL)+ - | EOF - ; - -// SECTION: expressions - -expression - : disjunction - ; - -disjunction - : conjunction (NL* DISJ NL* conjunction)* - ; - -conjunction - : equality (NL* CONJ NL* equality)* - ; - -equality - : comparison (equalityOperator NL* comparison)* - ; - -comparison - : genericCallLikeComparison (comparisonOperator NL* genericCallLikeComparison)* - ; - -genericCallLikeComparison - : infixOperation callSuffix* - ; - -infixOperation - : elvisExpression (inOperator NL* elvisExpression | isOperator NL* type)* - ; - -elvisExpression - : infixFunctionCall (NL* elvis NL* infixFunctionCall)* - ; - -elvis - : QUEST_NO_WS COLON - ; - -infixFunctionCall - : rangeExpression (simpleIdentifier NL* rangeExpression)* - ; - -rangeExpression - : additiveExpression (RANGE NL* additiveExpression)* - ; - -additiveExpression - : multiplicativeExpression (additiveOperator NL* multiplicativeExpression)* - ; - -multiplicativeExpression - : asExpression (multiplicativeOperator NL* asExpression)* - ; - -asExpression - : prefixUnaryExpression (NL* asOperator NL* type)* - ; - -prefixUnaryExpression - : unaryPrefix* postfixUnaryExpression - ; - -unaryPrefix - : annotation - | label - | prefixUnaryOperator NL* - ; - -postfixUnaryExpression - : primaryExpression postfixUnarySuffix* - ; - -postfixUnarySuffix - : postfixUnaryOperator - | typeArguments - | callSuffix - | indexingSuffix - | navigationSuffix - ; - -directlyAssignableExpression - : postfixUnaryExpression assignableSuffix - | simpleIdentifier - | parenthesizedDirectlyAssignableExpression - ; - -parenthesizedDirectlyAssignableExpression - : LPAREN NL* directlyAssignableExpression NL* RPAREN - ; - -assignableExpression - : prefixUnaryExpression - | parenthesizedAssignableExpression - ; - -parenthesizedAssignableExpression - : LPAREN NL* assignableExpression NL* RPAREN - ; - -assignableSuffix - : typeArguments - | indexingSuffix - | navigationSuffix - ; - -indexingSuffix - : LSQUARE NL* expression (NL* COMMA NL* expression)* (NL* COMMA)? NL* RSQUARE - ; - -navigationSuffix - : memberAccessOperator NL* (simpleIdentifier | parenthesizedExpression | CLASS) - ; - -callSuffix - : typeArguments? (valueArguments? annotatedLambda | valueArguments) - ; - -annotatedLambda - : annotation* label? NL* lambdaLiteral - ; - -typeArguments - : LANGLE NL* typeProjection (NL* COMMA NL* typeProjection)* (NL* COMMA)? NL* RANGLE - ; - -valueArguments - : LPAREN NL* (valueArgument (NL* COMMA NL* valueArgument)* (NL* COMMA)? NL*)? RPAREN - ; - -valueArgument - : annotation? NL* (simpleIdentifier NL* ASSIGNMENT NL*)? MULT? NL* expression - ; - -primaryExpression - : parenthesizedExpression - | simpleIdentifier - | literalConstant - | stringLiteral - | callableReference - | functionLiteral - | objectLiteral - | collectionLiteral - | thisExpression - | superExpression - | ifExpression - | whenExpression - | tryExpression - | jumpExpression - ; - -parenthesizedExpression - : LPAREN NL* expression NL* RPAREN - ; - -collectionLiteral - : LSQUARE NL* (expression (NL* COMMA NL* expression)* (NL* COMMA)? NL*)? RSQUARE - ; - -literalConstant - : BooleanLiteral - | IntegerLiteral - | HexLiteral - | BinLiteral - | CharacterLiteral - | RealLiteral - | NullLiteral - | LongLiteral - | UnsignedLiteral - ; - -stringLiteral - : lineStringLiteral - | multiLineStringLiteral - ; - -lineStringLiteral - : QUOTE_OPEN (lineStringContent | lineStringExpression)* QUOTE_CLOSE - ; - -multiLineStringLiteral - : TRIPLE_QUOTE_OPEN (multiLineStringContent | multiLineStringExpression | MultiLineStringQuote)* TRIPLE_QUOTE_CLOSE - ; - -lineStringContent - : LineStrText - | LineStrEscapedChar - | LineStrRef - ; - -lineStringExpression - : LineStrExprStart NL* expression NL* RCURL - ; - -multiLineStringContent - : MultiLineStrText - | MultiLineStringQuote - | MultiLineStrRef - ; - -multiLineStringExpression - : MultiLineStrExprStart NL* expression NL* RCURL - ; - -lambdaLiteral - : LCURL NL* (lambdaParameters? NL* ARROW NL*)? statements NL* RCURL - ; - -lambdaParameters - : lambdaParameter (NL* COMMA NL* lambdaParameter)* (NL* COMMA)? - ; - -lambdaParameter - : variableDeclaration - | multiVariableDeclaration (NL* COLON NL* type)? - ; - -anonymousFunction - : FUN - (NL* type NL* DOT)? - NL* parametersWithOptionalType - (NL* COLON NL* type)? - (NL* typeConstraints)? - (NL* functionBody)? - ; - -functionLiteral - : lambdaLiteral - | anonymousFunction - ; - -objectLiteral - : OBJECT (NL* COLON NL* delegationSpecifiers NL*)? (NL* classBody)? - ; - -thisExpression - : THIS - | THIS_AT - ; - -superExpression - : SUPER (LANGLE NL* type NL* RANGLE)? (AT_NO_WS simpleIdentifier)? - | SUPER_AT - ; - -ifExpression - : IF NL* LPAREN NL* expression NL* RPAREN NL* - ( controlStructureBody - | controlStructureBody? NL* SEMICOLON? NL* ELSE NL* (controlStructureBody | SEMICOLON) - | SEMICOLON) - ; - -whenSubject - : LPAREN (annotation* NL* VAL NL* variableDeclaration NL* ASSIGNMENT NL*)? expression RPAREN - ; - -whenExpression - : WHEN NL* whenSubject? NL* LCURL NL* (whenEntry NL*)* NL* RCURL - ; - -whenEntry - : whenCondition (NL* COMMA NL* whenCondition)* (NL* COMMA)? NL* ARROW NL* controlStructureBody semi? - | ELSE NL* ARROW NL* controlStructureBody semi? - ; - -whenCondition - : expression - | rangeTest - | typeTest - ; - -rangeTest - : inOperator NL* expression - ; - -typeTest - : isOperator NL* type - ; - -tryExpression - : TRY NL* block ((NL* catchBlock)+ (NL* finallyBlock)? | NL* finallyBlock) - ; - -catchBlock - : CATCH NL* LPAREN annotation* simpleIdentifier COLON type (NL* COMMA)? RPAREN NL* block - ; - -finallyBlock - : FINALLY NL* block - ; - -jumpExpression - : THROW NL* expression - | (RETURN | RETURN_AT) expression? - | CONTINUE - | CONTINUE_AT - | BREAK - | BREAK_AT - ; - -callableReference - : receiverType? COLONCOLON NL* (simpleIdentifier | CLASS) - ; - -assignmentAndOperator - : ADD_ASSIGNMENT - | SUB_ASSIGNMENT - | MULT_ASSIGNMENT - | DIV_ASSIGNMENT - | MOD_ASSIGNMENT - ; - -equalityOperator - : EXCL_EQ - | EXCL_EQEQ - | EQEQ - | EQEQEQ - ; - -comparisonOperator - : LANGLE - | RANGLE - | LE - | GE - ; - -inOperator - : IN - | NOT_IN - ; - -isOperator - : IS - | NOT_IS - ; - -additiveOperator - : ADD - | SUB - ; - -multiplicativeOperator - : MULT - | DIV - | MOD - ; - -asOperator - : AS - | AS_SAFE - ; - -prefixUnaryOperator - : INCR - | DECR - | SUB - | ADD - | excl - ; - -postfixUnaryOperator - : INCR - | DECR - | EXCL_NO_WS excl - ; - -excl - : EXCL_NO_WS - | EXCL_WS - ; - -memberAccessOperator - : NL* DOT - | NL* safeNav - | COLONCOLON - ; - -safeNav - : QUEST_NO_WS DOT - ; - -// SECTION: modifiers - -modifiers - : (annotation | modifier)+ - ; - -parameterModifiers - : (annotation | parameterModifier)+ - ; - -modifier - : (classModifier - | memberModifier - | visibilityModifier - | functionModifier - | propertyModifier - | inheritanceModifier - | parameterModifier - | platformModifier) NL* - ; - -typeModifiers - : typeModifier+ - ; - -typeModifier - : annotation - | SUSPEND NL* - ; - -classModifier - : ENUM - | SEALED - | ANNOTATION - | DATA - | INNER - | VALUE - ; - -memberModifier - : OVERRIDE - | LATEINIT - ; - -visibilityModifier - : PUBLIC - | PRIVATE - | INTERNAL - | PROTECTED - ; - -varianceModifier - : IN - | OUT - ; - -typeParameterModifiers - : typeParameterModifier+ - ; - -typeParameterModifier - : reificationModifier NL* - | varianceModifier NL* - | annotation - ; - -functionModifier - : TAILREC - | OPERATOR - | INFIX - | INLINE - | EXTERNAL - | SUSPEND - ; - -propertyModifier - : CONST - ; - -inheritanceModifier - : ABSTRACT - | FINAL - | OPEN - ; - -parameterModifier - : VARARG - | NOINLINE - | CROSSINLINE - ; - -reificationModifier - : REIFIED - ; - -platformModifier - : EXPECT - | ACTUAL - ; - -// SECTION: annotations - -annotation - : (singleAnnotation | multiAnnotation) NL* - ; - -singleAnnotation - : (annotationUseSiteTarget NL* | AT_NO_WS | AT_PRE_WS) unescapedAnnotation - ; - -multiAnnotation - : (annotationUseSiteTarget NL* | AT_NO_WS | AT_PRE_WS) LSQUARE unescapedAnnotation+ RSQUARE - ; - -annotationUseSiteTarget - : (AT_NO_WS | AT_PRE_WS) (FIELD | PROPERTY | GET | SET | RECEIVER | PARAM | SETPARAM | DELEGATE) NL* COLON - ; - -unescapedAnnotation - : constructorInvocation - | userType - ; - -// SECTION: identifiers - -simpleIdentifier - : Identifier - | ABSTRACT - | ANNOTATION - | BY - | CATCH - | COMPANION - | CONSTRUCTOR - | CROSSINLINE - | DATA - | DYNAMIC - | ENUM - | EXTERNAL - | FINAL - | FINALLY - | GET - | IMPORT - | INFIX - | INIT - | INLINE - | INNER - | INTERNAL - | LATEINIT - | NOINLINE - | OPEN - | OPERATOR - | OUT - | OVERRIDE - | PRIVATE - | PROTECTED - | PUBLIC - | REIFIED - | SEALED - | TAILREC - | SET - | VARARG - | WHERE - | FIELD - | PROPERTY - | RECEIVER - | PARAM - | SETPARAM - | DELEGATE - | FILE - | EXPECT - | ACTUAL - | CONST - | SUSPEND - | VALUE - ; - -identifier - : simpleIdentifier (NL* DOT simpleIdentifier)* - ; diff --git a/pmd-kotlin/src/main/antlr4/net/sourceforge/pmd/lang/kotlin/ast/PmdKotlinParser.java b/pmd-kotlin/src/main/antlr4/net/sourceforge/pmd/lang/kotlin/ast/PmdKotlinParser.java new file mode 100644 index 0000000000..c789950765 --- /dev/null +++ b/pmd-kotlin/src/main/antlr4/net/sourceforge/pmd/lang/kotlin/ast/PmdKotlinParser.java @@ -0,0 +1,28 @@ +/* + * BSD-style license; for more info see http://pmd.sourceforge.net/license.html + */ + +package net.sourceforge.pmd.lang.kotlin.ast; + +import net.sourceforge.pmd.lang.ast.impl.antlr4.AntlrBaseParser; +import net.sourceforge.pmd.lang.kotlin.ast.KotlinParser.KtTopLevel; +import org.antlr.v4.runtime.CharStream; +import org.antlr.v4.runtime.CommonTokenStream; +import org.antlr.v4.runtime.Lexer; + +/** + * Adapter for the KotlinParser. + */ +public final class PmdKotlinParser extends AntlrBaseParser { + + @Override + protected KtTopLevel parse(final Lexer lexer, ParserTask task) { + KotlinParser parser = new KotlinParser(new CommonTokenStream(lexer)); + return parser.topLevel().makeAstInfo(task); + } + + @Override + protected Lexer getLexer(final CharStream source) { + return new KotlinLexer(source); + } +} diff --git a/pmd-kotlin/src/main/java/net/sourceforge/pmd/lang/kotlin/AbstractKotlinRule.java b/pmd-kotlin/src/main/java/net/sourceforge/pmd/lang/kotlin/AbstractKotlinRule.java new file mode 100644 index 0000000000..ac65ac86d6 --- /dev/null +++ b/pmd-kotlin/src/main/java/net/sourceforge/pmd/lang/kotlin/AbstractKotlinRule.java @@ -0,0 +1,19 @@ +/** + * BSD-style license; for more info see http://pmd.sourceforge.net/license.html + */ + +package net.sourceforge.pmd.lang.kotlin; + +import net.sourceforge.pmd.RuleContext; +import net.sourceforge.pmd.lang.ast.AstVisitor; +import net.sourceforge.pmd.lang.ast.impl.antlr4.AntlrBaseRule; + +public abstract class AbstractKotlinRule extends AntlrBaseRule { + + protected AbstractKotlinRule() { + // inheritance constructor + } + + @Override + public abstract AstVisitor buildVisitor(); +} diff --git a/pmd-kotlin/src/main/java/net/sourceforge/pmd/lang/kotlin/KotlinHandler.java b/pmd-kotlin/src/main/java/net/sourceforge/pmd/lang/kotlin/KotlinHandler.java new file mode 100644 index 0000000000..6eaa0c5752 --- /dev/null +++ b/pmd-kotlin/src/main/java/net/sourceforge/pmd/lang/kotlin/KotlinHandler.java @@ -0,0 +1,25 @@ +/** + * BSD-style license; for more info see http://pmd.sourceforge.net/license.html + */ + +package net.sourceforge.pmd.lang.kotlin; + +import net.sourceforge.pmd.lang.AbstractPmdLanguageVersionHandler; +import net.sourceforge.pmd.lang.ast.Parser; +import net.sourceforge.pmd.lang.kotlin.ast.PmdKotlinParser; + + +public class KotlinHandler extends AbstractPmdLanguageVersionHandler { + + private final String kotlinRelease; + + public KotlinHandler(String release) { + kotlinRelease = release; + // check language version? + } + + @Override + public Parser getParser() { + return new PmdKotlinParser(); + } +} 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 new file mode 100644 index 0000000000..e61608b108 --- /dev/null +++ b/pmd-kotlin/src/main/java/net/sourceforge/pmd/lang/kotlin/KotlinLanguageModule.java @@ -0,0 +1,28 @@ +/** + * BSD-style license; for more info see http://pmd.sourceforge.net/license.html + */ + +package net.sourceforge.pmd.lang.kotlin; + +import net.sourceforge.pmd.lang.BaseLanguageModule; + +/** + * Language Module for Kotlin + */ +public class KotlinLanguageModule extends BaseLanguageModule { + + /** The name. */ + public static final String NAME = "Kotlin"; + /** The terse name. */ + public static final String TERSE_NAME = "kotlin"; + + /** + * Create a new instance of Kotlin Language Module. + */ + public KotlinLanguageModule() { + super(NAME, null, TERSE_NAME, "kt", "ktm"); + addVersion("", new KotlinHandler("1.3")); + addVersion("", new KotlinHandler("1.4")); + addDefaultVersion("", new KotlinHandler("1.5")); + } +} diff --git a/pmd-kotlin/src/main/java/net/sourceforge/pmd/lang/kotlin/ast/KotlinVisitorBase.java b/pmd-kotlin/src/main/java/net/sourceforge/pmd/lang/kotlin/ast/KotlinVisitorBase.java new file mode 100644 index 0000000000..b6b0054400 --- /dev/null +++ b/pmd-kotlin/src/main/java/net/sourceforge/pmd/lang/kotlin/ast/KotlinVisitorBase.java @@ -0,0 +1,14 @@ +/* + * BSD-style license; for more info see http://pmd.sourceforge.net/license.html + */ + +package net.sourceforge.pmd.lang.kotlin.ast; + +import net.sourceforge.pmd.lang.ast.AstVisitorBase; + +/** + * Base class for kotlin visitors. + */ +public abstract class KotlinVisitorBase extends AstVisitorBase implements KotlinVisitor { + +} From de6ddbd624e1cef7ad71948ad6ca3bf978cb4209 Mon Sep 17 00:00:00 2001 From: jborgers Date: Wed, 15 Sep 2021 15:41:36 +0200 Subject: [PATCH 007/198] Separate Kotlin.g4 for parser grammar and KotlinLexer.g4 for lexer grammar; and move PmdKotlinParser.java to the right place --- .../sourceforge/pmd/lang/kotlin/ast/Kotlin.g4 | 2209 +---------------- .../ast/{UnicodeClasses.g4 => KotlinLexer.g4} | 530 +++- .../pmd/lang/kotlin/ast/PmdKotlinParser.java | 0 3 files changed, 529 insertions(+), 2210 deletions(-) mode change 100755 => 100644 pmd-kotlin/src/main/antlr4/net/sourceforge/pmd/lang/kotlin/ast/Kotlin.g4 rename pmd-kotlin/src/main/antlr4/net/sourceforge/pmd/lang/kotlin/ast/{UnicodeClasses.g4 => KotlinLexer.g4} (65%) mode change 100644 => 100755 rename pmd-kotlin/src/main/{antlr4 => java}/net/sourceforge/pmd/lang/kotlin/ast/PmdKotlinParser.java (100%) 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 old mode 100755 new mode 100644 index 3f42bab00a..5712a7f82d --- 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 @@ -1,38 +1,17 @@ /** - * Kotlin parser/syntax grammar + Kotlin lexical grammar + unicode classes lexical grammar in ANTLR4 notation + * Kotlin syntax grammar in ANTLR4 notation */ -grammar Kotlin; +parser grammar Kotlin; @header { import net.sourceforge.pmd.lang.ast.impl.antlr4.*; import net.sourceforge.pmd.lang.ast.AstVisitor; } -@parser::members { +options { tokenVocab = KotlinLexer; } - static final AntlrNameDictionary DICO = new KotlinNameDictionary(VOCABULARY, ruleNames); - - @Override - public KotlinTerminalNode createPmdTerminal(ParserRuleContext parent, Token t) { - return new KotlinTerminalNode(t); - } - - @Override - public KotlinErrorNode createPmdError(ParserRuleContext parent, Token t) { - return new KotlinErrorNode(t); - } -} - -options { - contextSuperClass = 'KotlinInnerNode'; - superClass = 'AntlrGeneratedParserBase'; -} - -/** - * Kotlin syntax grammar in ANTLR4 notation - * from KotlinParser.g4 - */ +// SECTION: general kotlinFile : shebangLine? NL* fileAnnotation* packageHeader importList topLevelObject* EOF @@ -947,2183 +926,3 @@ simpleIdentifier identifier : simpleIdentifier (NL* DOT simpleIdentifier)* ; - - - -/** - * Kotlin lexical grammar in ANTLR4 notation (Unicode classes) - * - * Taken from http://www.antlr3.org/grammar/1345144569663/AntlrUnicode.txt - * - * from UnicodeClasses.g4 - */ - - -UNICODE_CLASS_LL: - '\u0061'..'\u007A' | - '\u00B5' | - '\u00DF'..'\u00F6' | - '\u00F8'..'\u00FF' | - '\u0101' | - '\u0103' | - '\u0105' | - '\u0107' | - '\u0109' | - '\u010B' | - '\u010D' | - '\u010F' | - '\u0111' | - '\u0113' | - '\u0115' | - '\u0117' | - '\u0119' | - '\u011B' | - '\u011D' | - '\u011F' | - '\u0121' | - '\u0123' | - '\u0125' | - '\u0127' | - '\u0129' | - '\u012B' | - '\u012D' | - '\u012F' | - '\u0131' | - '\u0133' | - '\u0135' | - '\u0137' | - '\u0138' | - '\u013A' | - '\u013C' | - '\u013E' | - '\u0140' | - '\u0142' | - '\u0144' | - '\u0146' | - '\u0148' | - '\u0149' | - '\u014B' | - '\u014D' | - '\u014F' | - '\u0151' | - '\u0153' | - '\u0155' | - '\u0157' | - '\u0159' | - '\u015B' | - '\u015D' | - '\u015F' | - '\u0161' | - '\u0163' | - '\u0165' | - '\u0167' | - '\u0169' | - '\u016B' | - '\u016D' | - '\u016F' | - '\u0171' | - '\u0173' | - '\u0175' | - '\u0177' | - '\u017A' | - '\u017C' | - '\u017E'..'\u0180' | - '\u0183' | - '\u0185' | - '\u0188' | - '\u018C' | - '\u018D' | - '\u0192' | - '\u0195' | - '\u0199'..'\u019B' | - '\u019E' | - '\u01A1' | - '\u01A3' | - '\u01A5' | - '\u01A8' | - '\u01AA' | - '\u01AB' | - '\u01AD' | - '\u01B0' | - '\u01B4' | - '\u01B6' | - '\u01B9' | - '\u01BA' | - '\u01BD'..'\u01BF' | - '\u01C6' | - '\u01C9' | - '\u01CC' | - '\u01CE' | - '\u01D0' | - '\u01D2' | - '\u01D4' | - '\u01D6' | - '\u01D8' | - '\u01DA' | - '\u01DC' | - '\u01DD' | - '\u01DF' | - '\u01E1' | - '\u01E3' | - '\u01E5' | - '\u01E7' | - '\u01E9' | - '\u01EB' | - '\u01ED' | - '\u01EF' | - '\u01F0' | - '\u01F3' | - '\u01F5' | - '\u01F9' | - '\u01FB' | - '\u01FD' | - '\u01FF' | - '\u0201' | - '\u0203' | - '\u0205' | - '\u0207' | - '\u0209' | - '\u020B' | - '\u020D' | - '\u020F' | - '\u0211' | - '\u0213' | - '\u0215' | - '\u0217' | - '\u0219' | - '\u021B' | - '\u021D' | - '\u021F' | - '\u0221' | - '\u0223' | - '\u0225' | - '\u0227' | - '\u0229' | - '\u022B' | - '\u022D' | - '\u022F' | - '\u0231' | - '\u0233'..'\u0239' | - '\u023C' | - '\u023F' | - '\u0240' | - '\u0242' | - '\u0247' | - '\u0249' | - '\u024B' | - '\u024D' | - '\u024F'..'\u0293' | - '\u0295'..'\u02AF' | - '\u0371' | - '\u0373' | - '\u0377' | - '\u037B'..'\u037D' | - '\u0390' | - '\u03AC'..'\u03CE' | - '\u03D0' | - '\u03D1' | - '\u03D5'..'\u03D7' | - '\u03D9' | - '\u03DB' | - '\u03DD' | - '\u03DF' | - '\u03E1' | - '\u03E3' | - '\u03E5' | - '\u03E7' | - '\u03E9' | - '\u03EB' | - '\u03ED' | - '\u03EF'..'\u03F3' | - '\u03F5' | - '\u03F8' | - '\u03FB' | - '\u03FC' | - '\u0430'..'\u045F' | - '\u0461' | - '\u0463' | - '\u0465' | - '\u0467' | - '\u0469' | - '\u046B' | - '\u046D' | - '\u046F' | - '\u0471' | - '\u0473' | - '\u0475' | - '\u0477' | - '\u0479' | - '\u047B' | - '\u047D' | - '\u047F' | - '\u0481' | - '\u048B' | - '\u048D' | - '\u048F' | - '\u0491' | - '\u0493' | - '\u0495' | - '\u0497' | - '\u0499' | - '\u049B' | - '\u049D' | - '\u049F' | - '\u04A1' | - '\u04A3' | - '\u04A5' | - '\u04A7' | - '\u04A9' | - '\u04AB' | - '\u04AD' | - '\u04AF' | - '\u04B1' | - '\u04B3' | - '\u04B5' | - '\u04B7' | - '\u04B9' | - '\u04BB' | - '\u04BD' | - '\u04BF' | - '\u04C2' | - '\u04C4' | - '\u04C6' | - '\u04C8' | - '\u04CA' | - '\u04CC' | - '\u04CE' | - '\u04CF' | - '\u04D1' | - '\u04D3' | - '\u04D5' | - '\u04D7' | - '\u04D9' | - '\u04DB' | - '\u04DD' | - '\u04DF' | - '\u04E1' | - '\u04E3' | - '\u04E5' | - '\u04E7' | - '\u04E9' | - '\u04EB' | - '\u04ED' | - '\u04EF' | - '\u04F1' | - '\u04F3' | - '\u04F5' | - '\u04F7' | - '\u04F9' | - '\u04FB' | - '\u04FD' | - '\u04FF' | - '\u0501' | - '\u0503' | - '\u0505' | - '\u0507' | - '\u0509' | - '\u050B' | - '\u050D' | - '\u050F' | - '\u0511' | - '\u0513' | - '\u0515' | - '\u0517' | - '\u0519' | - '\u051B' | - '\u051D' | - '\u051F' | - '\u0521' | - '\u0523' | - '\u0525' | - '\u0527' | - '\u0561'..'\u0587' | - '\u1D00'..'\u1D2B' | - '\u1D6B'..'\u1D77' | - '\u1D79'..'\u1D9A' | - '\u1E01' | - '\u1E03' | - '\u1E05' | - '\u1E07' | - '\u1E09' | - '\u1E0B' | - '\u1E0D' | - '\u1E0F' | - '\u1E11' | - '\u1E13' | - '\u1E15' | - '\u1E17' | - '\u1E19' | - '\u1E1B' | - '\u1E1D' | - '\u1E1F' | - '\u1E21' | - '\u1E23' | - '\u1E25' | - '\u1E27' | - '\u1E29' | - '\u1E2B' | - '\u1E2D' | - '\u1E2F' | - '\u1E31' | - '\u1E33' | - '\u1E35' | - '\u1E37' | - '\u1E39' | - '\u1E3B' | - '\u1E3D' | - '\u1E3F' | - '\u1E41' | - '\u1E43' | - '\u1E45' | - '\u1E47' | - '\u1E49' | - '\u1E4B' | - '\u1E4D' | - '\u1E4F' | - '\u1E51' | - '\u1E53' | - '\u1E55' | - '\u1E57' | - '\u1E59' | - '\u1E5B' | - '\u1E5D' | - '\u1E5F' | - '\u1E61' | - '\u1E63' | - '\u1E65' | - '\u1E67' | - '\u1E69' | - '\u1E6B' | - '\u1E6D' | - '\u1E6F' | - '\u1E71' | - '\u1E73' | - '\u1E75' | - '\u1E77' | - '\u1E79' | - '\u1E7B' | - '\u1E7D' | - '\u1E7F' | - '\u1E81' | - '\u1E83' | - '\u1E85' | - '\u1E87' | - '\u1E89' | - '\u1E8B' | - '\u1E8D' | - '\u1E8F' | - '\u1E91' | - '\u1E93' | - '\u1E95'..'\u1E9D' | - '\u1E9F' | - '\u1EA1' | - '\u1EA3' | - '\u1EA5' | - '\u1EA7' | - '\u1EA9' | - '\u1EAB' | - '\u1EAD' | - '\u1EAF' | - '\u1EB1' | - '\u1EB3' | - '\u1EB5' | - '\u1EB7' | - '\u1EB9' | - '\u1EBB' | - '\u1EBD' | - '\u1EBF' | - '\u1EC1' | - '\u1EC3' | - '\u1EC5' | - '\u1EC7' | - '\u1EC9' | - '\u1ECB' | - '\u1ECD' | - '\u1ECF' | - '\u1ED1' | - '\u1ED3' | - '\u1ED5' | - '\u1ED7' | - '\u1ED9' | - '\u1EDB' | - '\u1EDD' | - '\u1EDF' | - '\u1EE1' | - '\u1EE3' | - '\u1EE5' | - '\u1EE7' | - '\u1EE9' | - '\u1EEB' | - '\u1EED' | - '\u1EEF' | - '\u1EF1' | - '\u1EF3' | - '\u1EF5' | - '\u1EF7' | - '\u1EF9' | - '\u1EFB' | - '\u1EFD' | - '\u1EFF'..'\u1F07' | - '\u1F10'..'\u1F15' | - '\u1F20'..'\u1F27' | - '\u1F30'..'\u1F37' | - '\u1F40'..'\u1F45' | - '\u1F50'..'\u1F57' | - '\u1F60'..'\u1F67' | - '\u1F70'..'\u1F7D' | - '\u1F80'..'\u1F87' | - '\u1F90'..'\u1F97' | - '\u1FA0'..'\u1FA7' | - '\u1FB0'..'\u1FB4' | - '\u1FB6' | - '\u1FB7' | - '\u1FBE' | - '\u1FC2'..'\u1FC4' | - '\u1FC6' | - '\u1FC7' | - '\u1FD0'..'\u1FD3' | - '\u1FD6' | - '\u1FD7' | - '\u1FE0'..'\u1FE7' | - '\u1FF2'..'\u1FF4' | - '\u1FF6' | - '\u1FF7' | - '\u210A' | - '\u210E' | - '\u210F' | - '\u2113' | - '\u212F' | - '\u2134' | - '\u2139' | - '\u213C' | - '\u213D' | - '\u2146'..'\u2149' | - '\u214E' | - '\u2184' | - '\u2C30'..'\u2C5E' | - '\u2C61' | - '\u2C65' | - '\u2C66' | - '\u2C68' | - '\u2C6A' | - '\u2C6C' | - '\u2C71' | - '\u2C73' | - '\u2C74' | - '\u2C76'..'\u2C7B' | - '\u2C81' | - '\u2C83' | - '\u2C85' | - '\u2C87' | - '\u2C89' | - '\u2C8B' | - '\u2C8D' | - '\u2C8F' | - '\u2C91' | - '\u2C93' | - '\u2C95' | - '\u2C97' | - '\u2C99' | - '\u2C9B' | - '\u2C9D' | - '\u2C9F' | - '\u2CA1' | - '\u2CA3' | - '\u2CA5' | - '\u2CA7' | - '\u2CA9' | - '\u2CAB' | - '\u2CAD' | - '\u2CAF' | - '\u2CB1' | - '\u2CB3' | - '\u2CB5' | - '\u2CB7' | - '\u2CB9' | - '\u2CBB' | - '\u2CBD' | - '\u2CBF' | - '\u2CC1' | - '\u2CC3' | - '\u2CC5' | - '\u2CC7' | - '\u2CC9' | - '\u2CCB' | - '\u2CCD' | - '\u2CCF' | - '\u2CD1' | - '\u2CD3' | - '\u2CD5' | - '\u2CD7' | - '\u2CD9' | - '\u2CDB' | - '\u2CDD' | - '\u2CDF' | - '\u2CE1' | - '\u2CE3' | - '\u2CE4' | - '\u2CEC' | - '\u2CEE' | - '\u2CF3' | - '\u2D00'..'\u2D25' | - '\u2D27' | - '\u2D2D' | - '\uA641' | - '\uA643' | - '\uA645' | - '\uA647' | - '\uA649' | - '\uA64B' | - '\uA64D' | - '\uA64F' | - '\uA651' | - '\uA653' | - '\uA655' | - '\uA657' | - '\uA659' | - '\uA65B' | - '\uA65D' | - '\uA65F' | - '\uA661' | - '\uA663' | - '\uA665' | - '\uA667' | - '\uA669' | - '\uA66B' | - '\uA66D' | - '\uA681' | - '\uA683' | - '\uA685' | - '\uA687' | - '\uA689' | - '\uA68B' | - '\uA68D' | - '\uA68F' | - '\uA691' | - '\uA693' | - '\uA695' | - '\uA697' | - '\uA723' | - '\uA725' | - '\uA727' | - '\uA729' | - '\uA72B' | - '\uA72D' | - '\uA72F'..'\uA731' | - '\uA733' | - '\uA735' | - '\uA737' | - '\uA739' | - '\uA73B' | - '\uA73D' | - '\uA73F' | - '\uA741' | - '\uA743' | - '\uA745' | - '\uA747' | - '\uA749' | - '\uA74B' | - '\uA74D' | - '\uA74F' | - '\uA751' | - '\uA753' | - '\uA755' | - '\uA757' | - '\uA759' | - '\uA75B' | - '\uA75D' | - '\uA75F' | - '\uA761' | - '\uA763' | - '\uA765' | - '\uA767' | - '\uA769' | - '\uA76B' | - '\uA76D' | - '\uA76F' | - '\uA771'..'\uA778' | - '\uA77A' | - '\uA77C' | - '\uA77F' | - '\uA781' | - '\uA783' | - '\uA785' | - '\uA787' | - '\uA78C' | - '\uA78E' | - '\uA791' | - '\uA793' | - '\uA7A1' | - '\uA7A3' | - '\uA7A5' | - '\uA7A7' | - '\uA7A9' | - '\uA7FA' | - '\uFB00'..'\uFB06' | - '\uFB13'..'\uFB17' | - '\uFF41'..'\uFF5A'; - -UNICODE_CLASS_LM: - '\u02B0'..'\u02C1' | - '\u02C6'..'\u02D1' | - '\u02E0'..'\u02E4' | - '\u02EC' | - '\u02EE' | - '\u0374' | - '\u037A' | - '\u0559' | - '\u0640' | - '\u06E5' | - '\u06E6' | - '\u07F4' | - '\u07F5' | - '\u07FA' | - '\u081A' | - '\u0824' | - '\u0828' | - '\u0971' | - '\u0E46' | - '\u0EC6' | - '\u10FC' | - '\u17D7' | - '\u1843' | - '\u1AA7' | - '\u1C78'..'\u1C7D' | - '\u1D2C'..'\u1D6A' | - '\u1D78' | - '\u1D9B'..'\u1DBF' | - '\u2071' | - '\u207F' | - '\u2090'..'\u209C' | - '\u2C7C' | - '\u2C7D' | - '\u2D6F' | - '\u2E2F' | - '\u3005' | - '\u3031'..'\u3035' | - '\u303B' | - '\u309D' | - '\u309E' | - '\u30FC'..'\u30FE' | - '\uA015' | - '\uA4F8'..'\uA4FD' | - '\uA60C' | - '\uA67F' | - '\uA717'..'\uA71F' | - '\uA770' | - '\uA788' | - '\uA7F8' | - '\uA7F9' | - '\uA9CF' | - '\uAA70' | - '\uAADD' | - '\uAAF3' | - '\uAAF4' | - '\uFF70' | - '\uFF9E' | - '\uFF9F'; - -UNICODE_CLASS_LO: - '\u00AA' | - '\u00BA' | - '\u01BB' | - '\u01C0'..'\u01C3' | - '\u0294' | - '\u05D0'..'\u05EA' | - '\u05F0'..'\u05F2' | - '\u0620'..'\u063F' | - '\u0641'..'\u064A' | - '\u066E' | - '\u066F' | - '\u0671'..'\u06D3' | - '\u06D5' | - '\u06EE' | - '\u06EF' | - '\u06FA'..'\u06FC' | - '\u06FF' | - '\u0710' | - '\u0712'..'\u072F' | - '\u074D'..'\u07A5' | - '\u07B1' | - '\u07CA'..'\u07EA' | - '\u0800'..'\u0815' | - '\u0840'..'\u0858' | - '\u08A0' | - '\u08A2'..'\u08AC' | - '\u0904'..'\u0939' | - '\u093D' | - '\u0950' | - '\u0958'..'\u0961' | - '\u0972'..'\u0977' | - '\u0979'..'\u097F' | - '\u0985'..'\u098C' | - '\u098F' | - '\u0990' | - '\u0993'..'\u09A8' | - '\u09AA'..'\u09B0' | - '\u09B2' | - '\u09B6'..'\u09B9' | - '\u09BD' | - '\u09CE' | - '\u09DC' | - '\u09DD' | - '\u09DF'..'\u09E1' | - '\u09F0' | - '\u09F1' | - '\u0A05'..'\u0A0A' | - '\u0A0F' | - '\u0A10' | - '\u0A13'..'\u0A28' | - '\u0A2A'..'\u0A30' | - '\u0A32' | - '\u0A33' | - '\u0A35' | - '\u0A36' | - '\u0A38' | - '\u0A39' | - '\u0A59'..'\u0A5C' | - '\u0A5E' | - '\u0A72'..'\u0A74' | - '\u0A85'..'\u0A8D' | - '\u0A8F'..'\u0A91' | - '\u0A93'..'\u0AA8' | - '\u0AAA'..'\u0AB0' | - '\u0AB2' | - '\u0AB3' | - '\u0AB5'..'\u0AB9' | - '\u0ABD' | - '\u0AD0' | - '\u0AE0' | - '\u0AE1' | - '\u0B05'..'\u0B0C' | - '\u0B0F' | - '\u0B10' | - '\u0B13'..'\u0B28' | - '\u0B2A'..'\u0B30' | - '\u0B32' | - '\u0B33' | - '\u0B35'..'\u0B39' | - '\u0B3D' | - '\u0B5C' | - '\u0B5D' | - '\u0B5F'..'\u0B61' | - '\u0B71' | - '\u0B83' | - '\u0B85'..'\u0B8A' | - '\u0B8E'..'\u0B90' | - '\u0B92'..'\u0B95' | - '\u0B99' | - '\u0B9A' | - '\u0B9C' | - '\u0B9E' | - '\u0B9F' | - '\u0BA3' | - '\u0BA4' | - '\u0BA8'..'\u0BAA' | - '\u0BAE'..'\u0BB9' | - '\u0BD0' | - '\u0C05'..'\u0C0C' | - '\u0C0E'..'\u0C10' | - '\u0C12'..'\u0C28' | - '\u0C2A'..'\u0C33' | - '\u0C35'..'\u0C39' | - '\u0C3D' | - '\u0C58' | - '\u0C59' | - '\u0C60' | - '\u0C61' | - '\u0C85'..'\u0C8C' | - '\u0C8E'..'\u0C90' | - '\u0C92'..'\u0CA8' | - '\u0CAA'..'\u0CB3' | - '\u0CB5'..'\u0CB9' | - '\u0CBD' | - '\u0CDE' | - '\u0CE0' | - '\u0CE1' | - '\u0CF1' | - '\u0CF2' | - '\u0D05'..'\u0D0C' | - '\u0D0E'..'\u0D10' | - '\u0D12'..'\u0D3A' | - '\u0D3D' | - '\u0D4E' | - '\u0D60' | - '\u0D61' | - '\u0D7A'..'\u0D7F' | - '\u0D85'..'\u0D96' | - '\u0D9A'..'\u0DB1' | - '\u0DB3'..'\u0DBB' | - '\u0DBD' | - '\u0DC0'..'\u0DC6' | - '\u0E01'..'\u0E30' | - '\u0E32' | - '\u0E33' | - '\u0E40'..'\u0E45' | - '\u0E81' | - '\u0E82' | - '\u0E84' | - '\u0E87' | - '\u0E88' | - '\u0E8A' | - '\u0E8D' | - '\u0E94'..'\u0E97' | - '\u0E99'..'\u0E9F' | - '\u0EA1'..'\u0EA3' | - '\u0EA5' | - '\u0EA7' | - '\u0EAA' | - '\u0EAB' | - '\u0EAD'..'\u0EB0' | - '\u0EB2' | - '\u0EB3' | - '\u0EBD' | - '\u0EC0'..'\u0EC4' | - '\u0EDC'..'\u0EDF' | - '\u0F00' | - '\u0F40'..'\u0F47' | - '\u0F49'..'\u0F6C' | - '\u0F88'..'\u0F8C' | - '\u1000'..'\u102A' | - '\u103F' | - '\u1050'..'\u1055' | - '\u105A'..'\u105D' | - '\u1061' | - '\u1065' | - '\u1066' | - '\u106E'..'\u1070' | - '\u1075'..'\u1081' | - '\u108E' | - '\u10D0'..'\u10FA' | - '\u10FD'..'\u1248' | - '\u124A'..'\u124D' | - '\u1250'..'\u1256' | - '\u1258' | - '\u125A'..'\u125D' | - '\u1260'..'\u1288' | - '\u128A'..'\u128D' | - '\u1290'..'\u12B0' | - '\u12B2'..'\u12B5' | - '\u12B8'..'\u12BE' | - '\u12C0' | - '\u12C2'..'\u12C5' | - '\u12C8'..'\u12D6' | - '\u12D8'..'\u1310' | - '\u1312'..'\u1315' | - '\u1318'..'\u135A' | - '\u1380'..'\u138F' | - '\u13A0'..'\u13F4' | - '\u1401'..'\u166C' | - '\u166F'..'\u167F' | - '\u1681'..'\u169A' | - '\u16A0'..'\u16EA' | - '\u1700'..'\u170C' | - '\u170E'..'\u1711' | - '\u1720'..'\u1731' | - '\u1740'..'\u1751' | - '\u1760'..'\u176C' | - '\u176E'..'\u1770' | - '\u1780'..'\u17B3' | - '\u17DC' | - '\u1820'..'\u1842' | - '\u1844'..'\u1877' | - '\u1880'..'\u18A8' | - '\u18AA' | - '\u18B0'..'\u18F5' | - '\u1900'..'\u191C' | - '\u1950'..'\u196D' | - '\u1970'..'\u1974' | - '\u1980'..'\u19AB' | - '\u19C1'..'\u19C7' | - '\u1A00'..'\u1A16' | - '\u1A20'..'\u1A54' | - '\u1B05'..'\u1B33' | - '\u1B45'..'\u1B4B' | - '\u1B83'..'\u1BA0' | - '\u1BAE' | - '\u1BAF' | - '\u1BBA'..'\u1BE5' | - '\u1C00'..'\u1C23' | - '\u1C4D'..'\u1C4F' | - '\u1C5A'..'\u1C77' | - '\u1CE9'..'\u1CEC' | - '\u1CEE'..'\u1CF1' | - '\u1CF5' | - '\u1CF6' | - '\u2135'..'\u2138' | - '\u2D30'..'\u2D67' | - '\u2D80'..'\u2D96' | - '\u2DA0'..'\u2DA6' | - '\u2DA8'..'\u2DAE' | - '\u2DB0'..'\u2DB6' | - '\u2DB8'..'\u2DBE' | - '\u2DC0'..'\u2DC6' | - '\u2DC8'..'\u2DCE' | - '\u2DD0'..'\u2DD6' | - '\u2DD8'..'\u2DDE' | - '\u3006' | - '\u303C' | - '\u3041'..'\u3096' | - '\u309F' | - '\u30A1'..'\u30FA' | - '\u30FF' | - '\u3105'..'\u312D' | - '\u3131'..'\u318E' | - '\u31A0'..'\u31BA' | - '\u31F0'..'\u31FF' | - '\u3400' | - '\u4DB5' | - '\u4E00' | - '\u9FCC' | - '\uA000'..'\uA014' | - '\uA016'..'\uA48C' | - '\uA4D0'..'\uA4F7' | - '\uA500'..'\uA60B' | - '\uA610'..'\uA61F' | - '\uA62A' | - '\uA62B' | - '\uA66E' | - '\uA6A0'..'\uA6E5' | - '\uA7FB'..'\uA801' | - '\uA803'..'\uA805' | - '\uA807'..'\uA80A' | - '\uA80C'..'\uA822' | - '\uA840'..'\uA873' | - '\uA882'..'\uA8B3' | - '\uA8F2'..'\uA8F7' | - '\uA8FB' | - '\uA90A'..'\uA925' | - '\uA930'..'\uA946' | - '\uA960'..'\uA97C' | - '\uA984'..'\uA9B2' | - '\uAA00'..'\uAA28' | - '\uAA40'..'\uAA42' | - '\uAA44'..'\uAA4B' | - '\uAA60'..'\uAA6F' | - '\uAA71'..'\uAA76' | - '\uAA7A' | - '\uAA80'..'\uAAAF' | - '\uAAB1' | - '\uAAB5' | - '\uAAB6' | - '\uAAB9'..'\uAABD' | - '\uAAC0' | - '\uAAC2' | - '\uAADB' | - '\uAADC' | - '\uAAE0'..'\uAAEA' | - '\uAAF2' | - '\uAB01'..'\uAB06' | - '\uAB09'..'\uAB0E' | - '\uAB11'..'\uAB16' | - '\uAB20'..'\uAB26' | - '\uAB28'..'\uAB2E' | - '\uABC0'..'\uABE2' | - '\uAC00' | - '\uD7A3' | - '\uD7B0'..'\uD7C6' | - '\uD7CB'..'\uD7FB' | - '\uF900'..'\uFA6D' | - '\uFA70'..'\uFAD9' | - '\uFB1D' | - '\uFB1F'..'\uFB28' | - '\uFB2A'..'\uFB36' | - '\uFB38'..'\uFB3C' | - '\uFB3E' | - '\uFB40' | - '\uFB41' | - '\uFB43' | - '\uFB44' | - '\uFB46'..'\uFBB1' | - '\uFBD3'..'\uFD3D' | - '\uFD50'..'\uFD8F' | - '\uFD92'..'\uFDC7' | - '\uFDF0'..'\uFDFB' | - '\uFE70'..'\uFE74' | - '\uFE76'..'\uFEFC' | - '\uFF66'..'\uFF6F' | - '\uFF71'..'\uFF9D' | - '\uFFA0'..'\uFFBE' | - '\uFFC2'..'\uFFC7' | - '\uFFCA'..'\uFFCF' | - '\uFFD2'..'\uFFD7' | - '\uFFDA'..'\uFFDC'; - -UNICODE_CLASS_LT: - '\u01C5' | - '\u01C8' | - '\u01CB' | - '\u01F2' | - '\u1F88'..'\u1F8F' | - '\u1F98'..'\u1F9F' | - '\u1FA8'..'\u1FAF' | - '\u1FBC' | - '\u1FCC' | - '\u1FFC'; - -UNICODE_CLASS_LU: - '\u0041'..'\u005A' | - '\u00C0'..'\u00D6' | - '\u00D8'..'\u00DE' | - '\u0100' | - '\u0102' | - '\u0104' | - '\u0106' | - '\u0108' | - '\u010A' | - '\u010C' | - '\u010E' | - '\u0110' | - '\u0112' | - '\u0114' | - '\u0116' | - '\u0118' | - '\u011A' | - '\u011C' | - '\u011E' | - '\u0120' | - '\u0122' | - '\u0124' | - '\u0126' | - '\u0128' | - '\u012A' | - '\u012C' | - '\u012E' | - '\u0130' | - '\u0132' | - '\u0134' | - '\u0136' | - '\u0139' | - '\u013B' | - '\u013D' | - '\u013F' | - '\u0141' | - '\u0143' | - '\u0145' | - '\u0147' | - '\u014A' | - '\u014C' | - '\u014E' | - '\u0150' | - '\u0152' | - '\u0154' | - '\u0156' | - '\u0158' | - '\u015A' | - '\u015C' | - '\u015E' | - '\u0160' | - '\u0162' | - '\u0164' | - '\u0166' | - '\u0168' | - '\u016A' | - '\u016C' | - '\u016E' | - '\u0170' | - '\u0172' | - '\u0174' | - '\u0176' | - '\u0178' | - '\u0179' | - '\u017B' | - '\u017D' | - '\u0181' | - '\u0182' | - '\u0184' | - '\u0186' | - '\u0187' | - '\u0189'..'\u018B' | - '\u018E'..'\u0191' | - '\u0193' | - '\u0194' | - '\u0196'..'\u0198' | - '\u019C' | - '\u019D' | - '\u019F' | - '\u01A0' | - '\u01A2' | - '\u01A4' | - '\u01A6' | - '\u01A7' | - '\u01A9' | - '\u01AC' | - '\u01AE' | - '\u01AF' | - '\u01B1'..'\u01B3' | - '\u01B5' | - '\u01B7' | - '\u01B8' | - '\u01BC' | - '\u01C4' | - '\u01C7' | - '\u01CA' | - '\u01CD' | - '\u01CF' | - '\u01D1' | - '\u01D3' | - '\u01D5' | - '\u01D7' | - '\u01D9' | - '\u01DB' | - '\u01DE' | - '\u01E0' | - '\u01E2' | - '\u01E4' | - '\u01E6' | - '\u01E8' | - '\u01EA' | - '\u01EC' | - '\u01EE' | - '\u01F1' | - '\u01F4' | - '\u01F6'..'\u01F8' | - '\u01FA' | - '\u01FC' | - '\u01FE' | - '\u0200' | - '\u0202' | - '\u0204' | - '\u0206' | - '\u0208' | - '\u020A' | - '\u020C' | - '\u020E' | - '\u0210' | - '\u0212' | - '\u0214' | - '\u0216' | - '\u0218' | - '\u021A' | - '\u021C' | - '\u021E' | - '\u0220' | - '\u0222' | - '\u0224' | - '\u0226' | - '\u0228' | - '\u022A' | - '\u022C' | - '\u022E' | - '\u0230' | - '\u0232' | - '\u023A' | - '\u023B' | - '\u023D' | - '\u023E' | - '\u0241' | - '\u0243'..'\u0246' | - '\u0248' | - '\u024A' | - '\u024C' | - '\u024E' | - '\u0370' | - '\u0372' | - '\u0376' | - '\u0386' | - '\u0388'..'\u038A' | - '\u038C' | - '\u038E' | - '\u038F' | - '\u0391'..'\u03A1' | - '\u03A3'..'\u03AB' | - '\u03CF' | - '\u03D2'..'\u03D4' | - '\u03D8' | - '\u03DA' | - '\u03DC' | - '\u03DE' | - '\u03E0' | - '\u03E2' | - '\u03E4' | - '\u03E6' | - '\u03E8' | - '\u03EA' | - '\u03EC' | - '\u03EE' | - '\u03F4' | - '\u03F7' | - '\u03F9' | - '\u03FA' | - '\u03FD'..'\u042F' | - '\u0460' | - '\u0462' | - '\u0464' | - '\u0466' | - '\u0468' | - '\u046A' | - '\u046C' | - '\u046E' | - '\u0470' | - '\u0472' | - '\u0474' | - '\u0476' | - '\u0478' | - '\u047A' | - '\u047C' | - '\u047E' | - '\u0480' | - '\u048A' | - '\u048C' | - '\u048E' | - '\u0490' | - '\u0492' | - '\u0494' | - '\u0496' | - '\u0498' | - '\u049A' | - '\u049C' | - '\u049E' | - '\u04A0' | - '\u04A2' | - '\u04A4' | - '\u04A6' | - '\u04A8' | - '\u04AA' | - '\u04AC' | - '\u04AE' | - '\u04B0' | - '\u04B2' | - '\u04B4' | - '\u04B6' | - '\u04B8' | - '\u04BA' | - '\u04BC' | - '\u04BE' | - '\u04C0' | - '\u04C1' | - '\u04C3' | - '\u04C5' | - '\u04C7' | - '\u04C9' | - '\u04CB' | - '\u04CD' | - '\u04D0' | - '\u04D2' | - '\u04D4' | - '\u04D6' | - '\u04D8' | - '\u04DA' | - '\u04DC' | - '\u04DE' | - '\u04E0' | - '\u04E2' | - '\u04E4' | - '\u04E6' | - '\u04E8' | - '\u04EA' | - '\u04EC' | - '\u04EE' | - '\u04F0' | - '\u04F2' | - '\u04F4' | - '\u04F6' | - '\u04F8' | - '\u04FA' | - '\u04FC' | - '\u04FE' | - '\u0500' | - '\u0502' | - '\u0504' | - '\u0506' | - '\u0508' | - '\u050A' | - '\u050C' | - '\u050E' | - '\u0510' | - '\u0512' | - '\u0514' | - '\u0516' | - '\u0518' | - '\u051A' | - '\u051C' | - '\u051E' | - '\u0520' | - '\u0522' | - '\u0524' | - '\u0526' | - '\u0531'..'\u0556' | - '\u10A0'..'\u10C5' | - '\u10C7' | - '\u10CD' | - '\u1E00' | - '\u1E02' | - '\u1E04' | - '\u1E06' | - '\u1E08' | - '\u1E0A' | - '\u1E0C' | - '\u1E0E' | - '\u1E10' | - '\u1E12' | - '\u1E14' | - '\u1E16' | - '\u1E18' | - '\u1E1A' | - '\u1E1C' | - '\u1E1E' | - '\u1E20' | - '\u1E22' | - '\u1E24' | - '\u1E26' | - '\u1E28' | - '\u1E2A' | - '\u1E2C' | - '\u1E2E' | - '\u1E30' | - '\u1E32' | - '\u1E34' | - '\u1E36' | - '\u1E38' | - '\u1E3A' | - '\u1E3C' | - '\u1E3E' | - '\u1E40' | - '\u1E42' | - '\u1E44' | - '\u1E46' | - '\u1E48' | - '\u1E4A' | - '\u1E4C' | - '\u1E4E' | - '\u1E50' | - '\u1E52' | - '\u1E54' | - '\u1E56' | - '\u1E58' | - '\u1E5A' | - '\u1E5C' | - '\u1E5E' | - '\u1E60' | - '\u1E62' | - '\u1E64' | - '\u1E66' | - '\u1E68' | - '\u1E6A' | - '\u1E6C' | - '\u1E6E' | - '\u1E70' | - '\u1E72' | - '\u1E74' | - '\u1E76' | - '\u1E78' | - '\u1E7A' | - '\u1E7C' | - '\u1E7E' | - '\u1E80' | - '\u1E82' | - '\u1E84' | - '\u1E86' | - '\u1E88' | - '\u1E8A' | - '\u1E8C' | - '\u1E8E' | - '\u1E90' | - '\u1E92' | - '\u1E94' | - '\u1E9E' | - '\u1EA0' | - '\u1EA2' | - '\u1EA4' | - '\u1EA6' | - '\u1EA8' | - '\u1EAA' | - '\u1EAC' | - '\u1EAE' | - '\u1EB0' | - '\u1EB2' | - '\u1EB4' | - '\u1EB6' | - '\u1EB8' | - '\u1EBA' | - '\u1EBC' | - '\u1EBE' | - '\u1EC0' | - '\u1EC2' | - '\u1EC4' | - '\u1EC6' | - '\u1EC8' | - '\u1ECA' | - '\u1ECC' | - '\u1ECE' | - '\u1ED0' | - '\u1ED2' | - '\u1ED4' | - '\u1ED6' | - '\u1ED8' | - '\u1EDA' | - '\u1EDC' | - '\u1EDE' | - '\u1EE0' | - '\u1EE2' | - '\u1EE4' | - '\u1EE6' | - '\u1EE8' | - '\u1EEA' | - '\u1EEC' | - '\u1EEE' | - '\u1EF0' | - '\u1EF2' | - '\u1EF4' | - '\u1EF6' | - '\u1EF8' | - '\u1EFA' | - '\u1EFC' | - '\u1EFE' | - '\u1F08'..'\u1F0F' | - '\u1F18'..'\u1F1D' | - '\u1F28'..'\u1F2F' | - '\u1F38'..'\u1F3F' | - '\u1F48'..'\u1F4D' | - '\u1F59' | - '\u1F5B' | - '\u1F5D' | - '\u1F5F' | - '\u1F68'..'\u1F6F' | - '\u1FB8'..'\u1FBB' | - '\u1FC8'..'\u1FCB' | - '\u1FD8'..'\u1FDB' | - '\u1FE8'..'\u1FEC' | - '\u1FF8'..'\u1FFB' | - '\u2102' | - '\u2107' | - '\u210B'..'\u210D' | - '\u2110'..'\u2112' | - '\u2115' | - '\u2119'..'\u211D' | - '\u2124' | - '\u2126' | - '\u2128' | - '\u212A'..'\u212D' | - '\u2130'..'\u2133' | - '\u213E' | - '\u213F' | - '\u2145' | - '\u2183' | - '\u2C00'..'\u2C2E' | - '\u2C60' | - '\u2C62'..'\u2C64' | - '\u2C67' | - '\u2C69' | - '\u2C6B' | - '\u2C6D'..'\u2C70' | - '\u2C72' | - '\u2C75' | - '\u2C7E'..'\u2C80' | - '\u2C82' | - '\u2C84' | - '\u2C86' | - '\u2C88' | - '\u2C8A' | - '\u2C8C' | - '\u2C8E' | - '\u2C90' | - '\u2C92' | - '\u2C94' | - '\u2C96' | - '\u2C98' | - '\u2C9A' | - '\u2C9C' | - '\u2C9E' | - '\u2CA0' | - '\u2CA2' | - '\u2CA4' | - '\u2CA6' | - '\u2CA8' | - '\u2CAA' | - '\u2CAC' | - '\u2CAE' | - '\u2CB0' | - '\u2CB2' | - '\u2CB4' | - '\u2CB6' | - '\u2CB8' | - '\u2CBA' | - '\u2CBC' | - '\u2CBE' | - '\u2CC0' | - '\u2CC2' | - '\u2CC4' | - '\u2CC6' | - '\u2CC8' | - '\u2CCA' | - '\u2CCC' | - '\u2CCE' | - '\u2CD0' | - '\u2CD2' | - '\u2CD4' | - '\u2CD6' | - '\u2CD8' | - '\u2CDA' | - '\u2CDC' | - '\u2CDE' | - '\u2CE0' | - '\u2CE2' | - '\u2CEB' | - '\u2CED' | - '\u2CF2' | - '\uA640' | - '\uA642' | - '\uA644' | - '\uA646' | - '\uA648' | - '\uA64A' | - '\uA64C' | - '\uA64E' | - '\uA650' | - '\uA652' | - '\uA654' | - '\uA656' | - '\uA658' | - '\uA65A' | - '\uA65C' | - '\uA65E' | - '\uA660' | - '\uA662' | - '\uA664' | - '\uA666' | - '\uA668' | - '\uA66A' | - '\uA66C' | - '\uA680' | - '\uA682' | - '\uA684' | - '\uA686' | - '\uA688' | - '\uA68A' | - '\uA68C' | - '\uA68E' | - '\uA690' | - '\uA692' | - '\uA694' | - '\uA696' | - '\uA722' | - '\uA724' | - '\uA726' | - '\uA728' | - '\uA72A' | - '\uA72C' | - '\uA72E' | - '\uA732' | - '\uA734' | - '\uA736' | - '\uA738' | - '\uA73A' | - '\uA73C' | - '\uA73E' | - '\uA740' | - '\uA742' | - '\uA744' | - '\uA746' | - '\uA748' | - '\uA74A' | - '\uA74C' | - '\uA74E' | - '\uA750' | - '\uA752' | - '\uA754' | - '\uA756' | - '\uA758' | - '\uA75A' | - '\uA75C' | - '\uA75E' | - '\uA760' | - '\uA762' | - '\uA764' | - '\uA766' | - '\uA768' | - '\uA76A' | - '\uA76C' | - '\uA76E' | - '\uA779' | - '\uA77B' | - '\uA77D' | - '\uA77E' | - '\uA780' | - '\uA782' | - '\uA784' | - '\uA786' | - '\uA78B' | - '\uA78D' | - '\uA790' | - '\uA792' | - '\uA7A0' | - '\uA7A2' | - '\uA7A4' | - '\uA7A6' | - '\uA7A8' | - '\uA7AA' | - '\uFF21'..'\uFF3A'; - -UNICODE_CLASS_ND: - '\u0030'..'\u0039' | - '\u0660'..'\u0669' | - '\u06F0'..'\u06F9' | - '\u07C0'..'\u07C9' | - '\u0966'..'\u096F' | - '\u09E6'..'\u09EF' | - '\u0A66'..'\u0A6F' | - '\u0AE6'..'\u0AEF' | - '\u0B66'..'\u0B6F' | - '\u0BE6'..'\u0BEF' | - '\u0C66'..'\u0C6F' | - '\u0CE6'..'\u0CEF' | - '\u0D66'..'\u0D6F' | - '\u0E50'..'\u0E59' | - '\u0ED0'..'\u0ED9' | - '\u0F20'..'\u0F29' | - '\u1040'..'\u1049' | - '\u1090'..'\u1099' | - '\u17E0'..'\u17E9' | - '\u1810'..'\u1819' | - '\u1946'..'\u194F' | - '\u19D0'..'\u19D9' | - '\u1A80'..'\u1A89' | - '\u1A90'..'\u1A99' | - '\u1B50'..'\u1B59' | - '\u1BB0'..'\u1BB9' | - '\u1C40'..'\u1C49' | - '\u1C50'..'\u1C59' | - '\uA620'..'\uA629' | - '\uA8D0'..'\uA8D9' | - '\uA900'..'\uA909' | - '\uA9D0'..'\uA9D9' | - '\uAA50'..'\uAA59' | - '\uABF0'..'\uABF9' | - '\uFF10'..'\uFF19'; - -UNICODE_CLASS_NL: - '\u16EE'..'\u16F0' | - '\u2160'..'\u2182' | - '\u2185'..'\u2188' | - '\u3007' | - '\u3021'..'\u3029' | - '\u3038'..'\u303A' | - '\uA6E6'..'\uA6EF'; - -/** - * Kotlin lexical grammar in ANTLR4 notation - * from KotlinLexer.g4 - */ - -// SECTION: lexicalGeneral - -ShebangLine - : '#!' ~[\r\n]* - ; - -DelimitedComment - : '/*' ( DelimitedComment | . )*? '*/' - -> channel(HIDDEN) - ; - -LineComment - : '//' ~[\r\n]* - -> channel(HIDDEN) - ; - -WS - : [\u0020\u0009\u000C] - -> channel(HIDDEN) - ; - -NL: '\n' | '\r' '\n'?; - -fragment Hidden: DelimitedComment | LineComment | WS; - -// SECTION: separatorsAndOperations - -RESERVED: '...'; -DOT: '.'; -COMMA: ','; -LPAREN: '(' -> pushMode(Inside); -RPAREN: ')'; -LSQUARE: '[' -> pushMode(Inside); -RSQUARE: ']'; -LCURL: '{' -> pushMode(DEFAULT_MODE); -/* - * When using another programming language (not Java) to generate a parser, - * please replace this code with the corresponding code of a programming language you are using. - */ -RCURL: '}' { if (!_modeStack.isEmpty()) { popMode(); } }; -MULT: '*'; -MOD: '%'; -DIV: '/'; -ADD: '+'; -SUB: '-'; -INCR: '++'; -DECR: '--'; -CONJ: '&&'; -DISJ: '||'; -EXCL_WS: '!' Hidden; -EXCL_NO_WS: '!'; -COLON: ':'; -SEMICOLON: ';'; -ASSIGNMENT: '='; -ADD_ASSIGNMENT: '+='; -SUB_ASSIGNMENT: '-='; -MULT_ASSIGNMENT: '*='; -DIV_ASSIGNMENT: '/='; -MOD_ASSIGNMENT: '%='; -ARROW: '->'; -DOUBLE_ARROW: '=>'; -RANGE: '..'; -COLONCOLON: '::'; -DOUBLE_SEMICOLON: ';;'; -HASH: '#'; -AT_NO_WS: '@'; -AT_POST_WS: '@' (Hidden | NL); -AT_PRE_WS: (Hidden | NL) '@' ; -AT_BOTH_WS: (Hidden | NL) '@' (Hidden | NL); -QUEST_WS: '?' Hidden; -QUEST_NO_WS: '?'; -LANGLE: '<'; -RANGLE: '>'; -LE: '<='; -GE: '>='; -EXCL_EQ: '!='; -EXCL_EQEQ: '!=='; -AS_SAFE: 'as?'; -EQEQ: '=='; -EQEQEQ: '==='; -SINGLE_QUOTE: '\''; - -// SECTION: keywords - -RETURN_AT: 'return@' Identifier; -CONTINUE_AT: 'continue@' Identifier; -BREAK_AT: 'break@' Identifier; - -THIS_AT: 'this@' Identifier; -SUPER_AT: 'super@' Identifier; - -FILE: 'file'; -FIELD: 'field'; -PROPERTY: 'property'; -GET: 'get'; -SET: 'set'; -RECEIVER: 'receiver'; -PARAM: 'param'; -SETPARAM: 'setparam'; -DELEGATE: 'delegate'; - -PACKAGE: 'package'; -IMPORT: 'import'; -CLASS: 'class'; -INTERFACE: 'interface'; -FUN: 'fun'; -OBJECT: 'object'; -VAL: 'val'; -VAR: 'var'; -TYPE_ALIAS: 'typealias'; -CONSTRUCTOR: 'constructor'; -BY: 'by'; -COMPANION: 'companion'; -INIT: 'init'; -THIS: 'this'; -SUPER: 'super'; -TYPEOF: 'typeof'; -WHERE: 'where'; -IF: 'if'; -ELSE: 'else'; -WHEN: 'when'; -TRY: 'try'; -CATCH: 'catch'; -FINALLY: 'finally'; -FOR: 'for'; -DO: 'do'; -WHILE: 'while'; -THROW: 'throw'; -RETURN: 'return'; -CONTINUE: 'continue'; -BREAK: 'break'; -AS: 'as'; -IS: 'is'; -IN: 'in'; -NOT_IS: '!is' (Hidden | NL); -NOT_IN: '!in' (Hidden | NL); -OUT: 'out'; -DYNAMIC: 'dynamic'; - -// SECTION: lexicalModifiers - -PUBLIC: 'public'; -PRIVATE: 'private'; -PROTECTED: 'protected'; -INTERNAL: 'internal'; -ENUM: 'enum'; -SEALED: 'sealed'; -ANNOTATION: 'annotation'; -DATA: 'data'; -INNER: 'inner'; -VALUE: 'value'; -TAILREC: 'tailrec'; -OPERATOR: 'operator'; -INLINE: 'inline'; -INFIX: 'infix'; -EXTERNAL: 'external'; -SUSPEND: 'suspend'; -OVERRIDE: 'override'; -ABSTRACT: 'abstract'; -FINAL: 'final'; -OPEN: 'open'; -CONST: 'const'; -LATEINIT: 'lateinit'; -VARARG: 'vararg'; -NOINLINE: 'noinline'; -CROSSINLINE: 'crossinline'; -REIFIED: 'reified'; -EXPECT: 'expect'; -ACTUAL: 'actual'; - -// SECTION: literals - -fragment DecDigit: '0'..'9'; -fragment DecDigitNoZero: '1'..'9'; -fragment DecDigitOrSeparator: DecDigit | '_'; - -fragment DecDigits - : DecDigit DecDigitOrSeparator* DecDigit - | DecDigit - ; - -fragment DoubleExponent: [eE] [+-]? DecDigits; - -RealLiteral - : FloatLiteral - | DoubleLiteral - ; - -FloatLiteral - : DoubleLiteral [fF] - | DecDigits [fF] - ; - -DoubleLiteral - : DecDigits? '.' DecDigits DoubleExponent? - | DecDigits DoubleExponent - ; - -IntegerLiteral - : DecDigitNoZero DecDigitOrSeparator* DecDigit - | DecDigit - ; - -fragment HexDigit: [0-9a-fA-F]; -fragment HexDigitOrSeparator: HexDigit | '_'; - -HexLiteral - : '0' [xX] HexDigit HexDigitOrSeparator* HexDigit - | '0' [xX] HexDigit - ; - -fragment BinDigit: [01]; -fragment BinDigitOrSeparator: BinDigit | '_'; - -BinLiteral - : '0' [bB] BinDigit BinDigitOrSeparator* BinDigit - | '0' [bB] BinDigit - ; - -UnsignedLiteral - : (IntegerLiteral | HexLiteral | BinLiteral) [uU] [lL]? - ; - -LongLiteral - : (IntegerLiteral | HexLiteral | BinLiteral) [lL] - ; - -BooleanLiteral: 'true'| 'false'; - -NullLiteral: 'null'; - -CharacterLiteral - : '\'' (EscapeSeq | ~[\n\r'\\]) '\'' - ; - -// SECTION: lexicalIdentifiers - -fragment UnicodeDigit: UNICODE_CLASS_ND; - -Identifier - : (Letter | '_') (Letter | '_' | UnicodeDigit)* - | '`' ~([\r\n] | '`')+ '`' - ; - -IdentifierOrSoftKey - : Identifier - /* Soft keywords */ - | ABSTRACT - | ANNOTATION - | BY - | CATCH - | COMPANION - | CONSTRUCTOR - | CROSSINLINE - | DATA - | DYNAMIC - | ENUM - | EXTERNAL - | FINAL - | FINALLY - | IMPORT - | INFIX - | INIT - | INLINE - | INNER - | INTERNAL - | LATEINIT - | NOINLINE - | OPEN - | OPERATOR - | OUT - | OVERRIDE - | PRIVATE - | PROTECTED - | PUBLIC - | REIFIED - | SEALED - | TAILREC - | VARARG - | WHERE - | GET - | SET - | FIELD - | PROPERTY - | RECEIVER - | PARAM - | SETPARAM - | DELEGATE - | FILE - | EXPECT - | ACTUAL - | VALUE - /* Strong keywords */ - | CONST - | SUSPEND - ; - -FieldIdentifier - : '$' IdentifierOrSoftKey - ; - -fragment UniCharacterLiteral - : '\\' 'u' HexDigit HexDigit HexDigit HexDigit - ; - -fragment EscapedIdentifier - : '\\' ('t' | 'b' | 'r' | 'n' | '\'' | '"' | '\\' | '$') - ; - -fragment EscapeSeq - : UniCharacterLiteral - | EscapedIdentifier - ; - -// SECTION: characters - -fragment Letter - : UNICODE_CLASS_LL - | UNICODE_CLASS_LM - | UNICODE_CLASS_LO - | UNICODE_CLASS_LT - | UNICODE_CLASS_LU - | UNICODE_CLASS_NL - ; - -// SECTION: strings - -QUOTE_OPEN: '"' -> pushMode(LineString); - -TRIPLE_QUOTE_OPEN: '"""' -> pushMode(MultiLineString); - -mode LineString; - -QUOTE_CLOSE - : '"' -> popMode - ; - -LineStrRef - : FieldIdentifier - ; - -LineStrText - : ~('\\' | '"' | '$')+ | '$' - ; - -LineStrEscapedChar - : EscapedIdentifier - | UniCharacterLiteral - ; - -LineStrExprStart - : '${' -> pushMode(DEFAULT_MODE) - ; - -mode MultiLineString; - -TRIPLE_QUOTE_CLOSE - : MultiLineStringQuote? '"""' -> popMode - ; - -MultiLineStringQuote - : '"'+ - ; - -MultiLineStrRef - : FieldIdentifier - ; - -MultiLineStrText - : ~('"' | '$')+ | '$' - ; - -MultiLineStrExprStart - : '${' -> pushMode(DEFAULT_MODE) - ; - -// SECTION: inside - -mode Inside; - -Inside_RPAREN: RPAREN -> popMode, type(RPAREN); -Inside_RSQUARE: RSQUARE -> popMode, type(RSQUARE); -Inside_LPAREN: LPAREN -> pushMode(Inside), type(LPAREN); -Inside_LSQUARE: LSQUARE -> pushMode(Inside), type(LSQUARE); -Inside_LCURL: LCURL -> pushMode(DEFAULT_MODE), type(LCURL); -Inside_RCURL: RCURL -> popMode, type(RCURL); - -Inside_DOT: DOT -> type(DOT); -Inside_COMMA: COMMA -> type(COMMA); -Inside_MULT: MULT -> type(MULT); -Inside_MOD: MOD -> type(MOD); -Inside_DIV: DIV -> type(DIV); -Inside_ADD: ADD -> type(ADD); -Inside_SUB: SUB -> type(SUB); -Inside_INCR: INCR -> type(INCR); -Inside_DECR: DECR -> type(DECR); -Inside_CONJ: CONJ -> type(CONJ); -Inside_DISJ: DISJ -> type(DISJ); -Inside_EXCL_WS: '!' (Hidden|NL) -> type(EXCL_WS); -Inside_EXCL_NO_WS: EXCL_NO_WS -> type(EXCL_NO_WS); -Inside_COLON: COLON -> type(COLON); -Inside_SEMICOLON: SEMICOLON -> type(SEMICOLON); -Inside_ASSIGNMENT: ASSIGNMENT -> type(ASSIGNMENT); -Inside_ADD_ASSIGNMENT: ADD_ASSIGNMENT -> type(ADD_ASSIGNMENT); -Inside_SUB_ASSIGNMENT: SUB_ASSIGNMENT -> type(SUB_ASSIGNMENT); -Inside_MULT_ASSIGNMENT: MULT_ASSIGNMENT -> type(MULT_ASSIGNMENT); -Inside_DIV_ASSIGNMENT: DIV_ASSIGNMENT -> type(DIV_ASSIGNMENT); -Inside_MOD_ASSIGNMENT: MOD_ASSIGNMENT -> type(MOD_ASSIGNMENT); -Inside_ARROW: ARROW -> type(ARROW); -Inside_DOUBLE_ARROW: DOUBLE_ARROW -> type(DOUBLE_ARROW); -Inside_RANGE: RANGE -> type(RANGE); -Inside_RESERVED: RESERVED -> type(RESERVED); -Inside_COLONCOLON: COLONCOLON -> type(COLONCOLON); -Inside_DOUBLE_SEMICOLON: DOUBLE_SEMICOLON -> type(DOUBLE_SEMICOLON); -Inside_HASH: HASH -> type(HASH); -Inside_AT_NO_WS: AT_NO_WS -> type(AT_NO_WS); -Inside_AT_POST_WS: AT_POST_WS -> type(AT_POST_WS); -Inside_AT_PRE_WS: AT_PRE_WS -> type(AT_PRE_WS); -Inside_AT_BOTH_WS: AT_BOTH_WS -> type(AT_BOTH_WS); -Inside_QUEST_WS: '?' (Hidden | NL) -> type(QUEST_WS); -Inside_QUEST_NO_WS: QUEST_NO_WS -> type(QUEST_NO_WS); -Inside_LANGLE: LANGLE -> type(LANGLE); -Inside_RANGLE: RANGLE -> type(RANGLE); -Inside_LE: LE -> type(LE); -Inside_GE: GE -> type(GE); -Inside_EXCL_EQ: EXCL_EQ -> type(EXCL_EQ); -Inside_EXCL_EQEQ: EXCL_EQEQ -> type(EXCL_EQEQ); -Inside_IS: IS -> type(IS); -Inside_NOT_IS: NOT_IS -> type(NOT_IS); -Inside_NOT_IN: NOT_IN -> type(NOT_IN); -Inside_AS: AS -> type(AS); -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_QUOTE_OPEN: QUOTE_OPEN -> pushMode(LineString), type(QUOTE_OPEN); -Inside_TRIPLE_QUOTE_OPEN: TRIPLE_QUOTE_OPEN -> pushMode(MultiLineString), type(TRIPLE_QUOTE_OPEN); - -Inside_VAL: VAL -> type(VAL); -Inside_VAR: VAR -> type(VAR); -Inside_FUN: FUN -> type(FUN); -Inside_OBJECT: OBJECT -> type(OBJECT); -Inside_SUPER: SUPER -> type(SUPER); -Inside_IN: IN -> type(IN); -Inside_OUT: OUT -> type(OUT); -Inside_FIELD: FIELD -> type(FIELD); -Inside_FILE: FILE -> type(FILE); -Inside_PROPERTY: PROPERTY -> type(PROPERTY); -Inside_GET: GET -> type(GET); -Inside_SET: SET -> type(SET); -Inside_RECEIVER: RECEIVER -> type(RECEIVER); -Inside_PARAM: PARAM -> type(PARAM); -Inside_SETPARAM: SETPARAM -> type(SETPARAM); -Inside_DELEGATE: DELEGATE -> type(DELEGATE); -Inside_THROW: THROW -> type(THROW); -Inside_RETURN: RETURN -> type(RETURN); -Inside_CONTINUE: CONTINUE -> type(CONTINUE); -Inside_BREAK: BREAK -> type(BREAK); -Inside_RETURN_AT: RETURN_AT -> type(RETURN_AT); -Inside_CONTINUE_AT: CONTINUE_AT -> type(CONTINUE_AT); -Inside_BREAK_AT: BREAK_AT -> type(BREAK_AT); -Inside_IF: IF -> type(IF); -Inside_ELSE: ELSE -> type(ELSE); -Inside_WHEN: WHEN -> type(WHEN); -Inside_TRY: TRY -> type(TRY); -Inside_CATCH: CATCH -> type(CATCH); -Inside_FINALLY: FINALLY -> type(FINALLY); -Inside_FOR: FOR -> type(FOR); -Inside_DO: DO -> type(DO); -Inside_WHILE: WHILE -> type(WHILE); - -Inside_PUBLIC: PUBLIC -> type(PUBLIC); -Inside_PRIVATE: PRIVATE -> type(PRIVATE); -Inside_PROTECTED: PROTECTED -> type(PROTECTED); -Inside_INTERNAL: INTERNAL -> type(INTERNAL); -Inside_ENUM: ENUM -> type(ENUM); -Inside_SEALED: SEALED -> type(SEALED); -Inside_ANNOTATION: ANNOTATION -> type(ANNOTATION); -Inside_DATA: DATA -> type(DATA); -Inside_INNER: INNER -> type(INNER); -Inside_VALUE: VALUE -> type(VALUE); -Inside_TAILREC: TAILREC -> type(TAILREC); -Inside_OPERATOR: OPERATOR -> type(OPERATOR); -Inside_INLINE: INLINE -> type(INLINE); -Inside_INFIX: INFIX -> type(INFIX); -Inside_EXTERNAL: EXTERNAL -> type(EXTERNAL); -Inside_SUSPEND: SUSPEND -> type(SUSPEND); -Inside_OVERRIDE: OVERRIDE -> type(OVERRIDE); -Inside_ABSTRACT: ABSTRACT -> type(ABSTRACT); -Inside_FINAL: FINAL -> type(FINAL); -Inside_OPEN: OPEN -> type(OPEN); -Inside_CONST: CONST -> type(CONST); -Inside_LATEINIT: LATEINIT -> type(LATEINIT); -Inside_VARARG: VARARG -> type(VARARG); -Inside_NOINLINE: NOINLINE -> type(NOINLINE); -Inside_CROSSINLINE: CROSSINLINE -> type(CROSSINLINE); -Inside_REIFIED: REIFIED -> type(REIFIED); -Inside_EXPECT: EXPECT -> type(EXPECT); -Inside_ACTUAL: ACTUAL -> type(ACTUAL); - -Inside_BooleanLiteral: BooleanLiteral -> type(BooleanLiteral); -Inside_IntegerLiteral: IntegerLiteral -> type(IntegerLiteral); -Inside_HexLiteral: HexLiteral -> type(HexLiteral); -Inside_BinLiteral: BinLiteral -> type(BinLiteral); -Inside_CharacterLiteral: CharacterLiteral -> type(CharacterLiteral); -Inside_RealLiteral: RealLiteral -> type(RealLiteral); -Inside_NullLiteral: NullLiteral -> type(NullLiteral); -Inside_LongLiteral: LongLiteral -> type(LongLiteral); -Inside_UnsignedLiteral: UnsignedLiteral -> type(UnsignedLiteral); - -Inside_Identifier: Identifier -> type(Identifier); -Inside_Comment: (LineComment | DelimitedComment) -> channel(HIDDEN); -Inside_WS: WS -> channel(HIDDEN); -Inside_NL: NL -> channel(HIDDEN); - -mode DEFAULT_MODE; - -ErrorCharacter: .; - - - 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/KotlinLexer.g4 old mode 100644 new mode 100755 similarity index 65% rename from pmd-kotlin/src/main/antlr4/net/sourceforge/pmd/lang/kotlin/ast/UnicodeClasses.g4 rename to pmd-kotlin/src/main/antlr4/net/sourceforge/pmd/lang/kotlin/ast/KotlinLexer.g4 index 537284804c..9b401e934a --- 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/KotlinLexer.g4 @@ -1,10 +1,11 @@ /** - * Kotlin lexical grammar in ANTLR4 notation (Unicode classes) - * - * Taken from http://www.antlr3.org/grammar/1345144569663/AntlrUnicode.txt + * Kotlin lexical grammar in ANTLR4 notation */ -lexer grammar UnicodeClasses; +lexer grammar KotlinLexer; + +//import UnicodeClasses; +// Taken from http://www.antlr3.org/grammar/1345144569663/AntlrUnicode.txt UNICODE_CLASS_LL: '\u0061'..'\u007A' | @@ -1646,4 +1647,523 @@ UNICODE_CLASS_NL: '\u3007' | '\u3021'..'\u3029' | '\u3038'..'\u303A' | - '\uA6E6'..'\uA6EF'; \ No newline at end of file + '\uA6E6'..'\uA6EF'; + +// SECTION: lexicalGeneral + +ShebangLine + : '#!' ~[\r\n]* + ; + +DelimitedComment + : '/*' ( DelimitedComment | . )*? '*/' + -> channel(HIDDEN) + ; + +LineComment + : '//' ~[\r\n]* + -> channel(HIDDEN) + ; + +WS + : [\u0020\u0009\u000C] + -> channel(HIDDEN) + ; + +NL: '\n' | '\r' '\n'?; + +fragment Hidden: DelimitedComment | LineComment | WS; + +// SECTION: separatorsAndOperations + +RESERVED: '...'; +DOT: '.'; +COMMA: ','; +LPAREN: '(' -> pushMode(Inside); +RPAREN: ')'; +LSQUARE: '[' -> pushMode(Inside); +RSQUARE: ']'; +LCURL: '{' -> pushMode(DEFAULT_MODE); +/* + * When using another programming language (not Java) to generate a parser, + * please replace this code with the corresponding code of a programming language you are using. + */ +RCURL: '}' { if (!_modeStack.isEmpty()) { popMode(); } }; +MULT: '*'; +MOD: '%'; +DIV: '/'; +ADD: '+'; +SUB: '-'; +INCR: '++'; +DECR: '--'; +CONJ: '&&'; +DISJ: '||'; +EXCL_WS: '!' Hidden; +EXCL_NO_WS: '!'; +COLON: ':'; +SEMICOLON: ';'; +ASSIGNMENT: '='; +ADD_ASSIGNMENT: '+='; +SUB_ASSIGNMENT: '-='; +MULT_ASSIGNMENT: '*='; +DIV_ASSIGNMENT: '/='; +MOD_ASSIGNMENT: '%='; +ARROW: '->'; +DOUBLE_ARROW: '=>'; +RANGE: '..'; +COLONCOLON: '::'; +DOUBLE_SEMICOLON: ';;'; +HASH: '#'; +AT_NO_WS: '@'; +AT_POST_WS: '@' (Hidden | NL); +AT_PRE_WS: (Hidden | NL) '@' ; +AT_BOTH_WS: (Hidden | NL) '@' (Hidden | NL); +QUEST_WS: '?' Hidden; +QUEST_NO_WS: '?'; +LANGLE: '<'; +RANGLE: '>'; +LE: '<='; +GE: '>='; +EXCL_EQ: '!='; +EXCL_EQEQ: '!=='; +AS_SAFE: 'as?'; +EQEQ: '=='; +EQEQEQ: '==='; +SINGLE_QUOTE: '\''; + +// SECTION: keywords + +RETURN_AT: 'return@' Identifier; +CONTINUE_AT: 'continue@' Identifier; +BREAK_AT: 'break@' Identifier; + +THIS_AT: 'this@' Identifier; +SUPER_AT: 'super@' Identifier; + +FILE: 'file'; +FIELD: 'field'; +PROPERTY: 'property'; +GET: 'get'; +SET: 'set'; +RECEIVER: 'receiver'; +PARAM: 'param'; +SETPARAM: 'setparam'; +DELEGATE: 'delegate'; + +PACKAGE: 'package'; +IMPORT: 'import'; +CLASS: 'class'; +INTERFACE: 'interface'; +FUN: 'fun'; +OBJECT: 'object'; +VAL: 'val'; +VAR: 'var'; +TYPE_ALIAS: 'typealias'; +CONSTRUCTOR: 'constructor'; +BY: 'by'; +COMPANION: 'companion'; +INIT: 'init'; +THIS: 'this'; +SUPER: 'super'; +TYPEOF: 'typeof'; +WHERE: 'where'; +IF: 'if'; +ELSE: 'else'; +WHEN: 'when'; +TRY: 'try'; +CATCH: 'catch'; +FINALLY: 'finally'; +FOR: 'for'; +DO: 'do'; +WHILE: 'while'; +THROW: 'throw'; +RETURN: 'return'; +CONTINUE: 'continue'; +BREAK: 'break'; +AS: 'as'; +IS: 'is'; +IN: 'in'; +NOT_IS: '!is' (Hidden | NL); +NOT_IN: '!in' (Hidden | NL); +OUT: 'out'; +DYNAMIC: 'dynamic'; + +// SECTION: lexicalModifiers + +PUBLIC: 'public'; +PRIVATE: 'private'; +PROTECTED: 'protected'; +INTERNAL: 'internal'; +ENUM: 'enum'; +SEALED: 'sealed'; +ANNOTATION: 'annotation'; +DATA: 'data'; +INNER: 'inner'; +VALUE: 'value'; +TAILREC: 'tailrec'; +OPERATOR: 'operator'; +INLINE: 'inline'; +INFIX: 'infix'; +EXTERNAL: 'external'; +SUSPEND: 'suspend'; +OVERRIDE: 'override'; +ABSTRACT: 'abstract'; +FINAL: 'final'; +OPEN: 'open'; +CONST: 'const'; +LATEINIT: 'lateinit'; +VARARG: 'vararg'; +NOINLINE: 'noinline'; +CROSSINLINE: 'crossinline'; +REIFIED: 'reified'; +EXPECT: 'expect'; +ACTUAL: 'actual'; + +// SECTION: literals + +fragment DecDigit: '0'..'9'; +fragment DecDigitNoZero: '1'..'9'; +fragment DecDigitOrSeparator: DecDigit | '_'; + +fragment DecDigits + : DecDigit DecDigitOrSeparator* DecDigit + | DecDigit + ; + +fragment DoubleExponent: [eE] [+-]? DecDigits; + +RealLiteral + : FloatLiteral + | DoubleLiteral + ; + +FloatLiteral + : DoubleLiteral [fF] + | DecDigits [fF] + ; + +DoubleLiteral + : DecDigits? '.' DecDigits DoubleExponent? + | DecDigits DoubleExponent + ; + +IntegerLiteral + : DecDigitNoZero DecDigitOrSeparator* DecDigit + | DecDigit + ; + +fragment HexDigit: [0-9a-fA-F]; +fragment HexDigitOrSeparator: HexDigit | '_'; + +HexLiteral + : '0' [xX] HexDigit HexDigitOrSeparator* HexDigit + | '0' [xX] HexDigit + ; + +fragment BinDigit: [01]; +fragment BinDigitOrSeparator: BinDigit | '_'; + +BinLiteral + : '0' [bB] BinDigit BinDigitOrSeparator* BinDigit + | '0' [bB] BinDigit + ; + +UnsignedLiteral + : (IntegerLiteral | HexLiteral | BinLiteral) [uU] [lL]? + ; + +LongLiteral + : (IntegerLiteral | HexLiteral | BinLiteral) [lL] + ; + +BooleanLiteral: 'true'| 'false'; + +NullLiteral: 'null'; + +CharacterLiteral + : '\'' (EscapeSeq | ~[\n\r'\\]) '\'' + ; + +// SECTION: lexicalIdentifiers + +fragment UnicodeDigit: UNICODE_CLASS_ND; + +Identifier + : (Letter | '_') (Letter | '_' | UnicodeDigit)* + | '`' ~([\r\n] | '`')+ '`' + ; + +IdentifierOrSoftKey + : Identifier + /* Soft keywords */ + | ABSTRACT + | ANNOTATION + | BY + | CATCH + | COMPANION + | CONSTRUCTOR + | CROSSINLINE + | DATA + | DYNAMIC + | ENUM + | EXTERNAL + | FINAL + | FINALLY + | IMPORT + | INFIX + | INIT + | INLINE + | INNER + | INTERNAL + | LATEINIT + | NOINLINE + | OPEN + | OPERATOR + | OUT + | OVERRIDE + | PRIVATE + | PROTECTED + | PUBLIC + | REIFIED + | SEALED + | TAILREC + | VARARG + | WHERE + | GET + | SET + | FIELD + | PROPERTY + | RECEIVER + | PARAM + | SETPARAM + | DELEGATE + | FILE + | EXPECT + | ACTUAL + | VALUE + /* Strong keywords */ + | CONST + | SUSPEND + ; + +FieldIdentifier + : '$' IdentifierOrSoftKey + ; + +fragment UniCharacterLiteral + : '\\' 'u' HexDigit HexDigit HexDigit HexDigit + ; + +fragment EscapedIdentifier + : '\\' ('t' | 'b' | 'r' | 'n' | '\'' | '"' | '\\' | '$') + ; + +fragment EscapeSeq + : UniCharacterLiteral + | EscapedIdentifier + ; + +// SECTION: characters + +fragment Letter + : UNICODE_CLASS_LL + | UNICODE_CLASS_LM + | UNICODE_CLASS_LO + | UNICODE_CLASS_LT + | UNICODE_CLASS_LU + | UNICODE_CLASS_NL + ; + +// SECTION: strings + +QUOTE_OPEN: '"' -> pushMode(LineString); + +TRIPLE_QUOTE_OPEN: '"""' -> pushMode(MultiLineString); + +mode LineString; + +QUOTE_CLOSE + : '"' -> popMode + ; + +LineStrRef + : FieldIdentifier + ; + +LineStrText + : ~('\\' | '"' | '$')+ | '$' + ; + +LineStrEscapedChar + : EscapedIdentifier + | UniCharacterLiteral + ; + +LineStrExprStart + : '${' -> pushMode(DEFAULT_MODE) + ; + +mode MultiLineString; + +TRIPLE_QUOTE_CLOSE + : MultiLineStringQuote? '"""' -> popMode + ; + +MultiLineStringQuote + : '"'+ + ; + +MultiLineStrRef + : FieldIdentifier + ; + +MultiLineStrText + : ~('"' | '$')+ | '$' + ; + +MultiLineStrExprStart + : '${' -> pushMode(DEFAULT_MODE) + ; + +// SECTION: inside + +mode Inside; + +Inside_RPAREN: RPAREN -> popMode, type(RPAREN); +Inside_RSQUARE: RSQUARE -> popMode, type(RSQUARE); +Inside_LPAREN: LPAREN -> pushMode(Inside), type(LPAREN); +Inside_LSQUARE: LSQUARE -> pushMode(Inside), type(LSQUARE); +Inside_LCURL: LCURL -> pushMode(DEFAULT_MODE), type(LCURL); +Inside_RCURL: RCURL -> popMode, type(RCURL); + +Inside_DOT: DOT -> type(DOT); +Inside_COMMA: COMMA -> type(COMMA); +Inside_MULT: MULT -> type(MULT); +Inside_MOD: MOD -> type(MOD); +Inside_DIV: DIV -> type(DIV); +Inside_ADD: ADD -> type(ADD); +Inside_SUB: SUB -> type(SUB); +Inside_INCR: INCR -> type(INCR); +Inside_DECR: DECR -> type(DECR); +Inside_CONJ: CONJ -> type(CONJ); +Inside_DISJ: DISJ -> type(DISJ); +Inside_EXCL_WS: '!' (Hidden|NL) -> type(EXCL_WS); +Inside_EXCL_NO_WS: EXCL_NO_WS -> type(EXCL_NO_WS); +Inside_COLON: COLON -> type(COLON); +Inside_SEMICOLON: SEMICOLON -> type(SEMICOLON); +Inside_ASSIGNMENT: ASSIGNMENT -> type(ASSIGNMENT); +Inside_ADD_ASSIGNMENT: ADD_ASSIGNMENT -> type(ADD_ASSIGNMENT); +Inside_SUB_ASSIGNMENT: SUB_ASSIGNMENT -> type(SUB_ASSIGNMENT); +Inside_MULT_ASSIGNMENT: MULT_ASSIGNMENT -> type(MULT_ASSIGNMENT); +Inside_DIV_ASSIGNMENT: DIV_ASSIGNMENT -> type(DIV_ASSIGNMENT); +Inside_MOD_ASSIGNMENT: MOD_ASSIGNMENT -> type(MOD_ASSIGNMENT); +Inside_ARROW: ARROW -> type(ARROW); +Inside_DOUBLE_ARROW: DOUBLE_ARROW -> type(DOUBLE_ARROW); +Inside_RANGE: RANGE -> type(RANGE); +Inside_RESERVED: RESERVED -> type(RESERVED); +Inside_COLONCOLON: COLONCOLON -> type(COLONCOLON); +Inside_DOUBLE_SEMICOLON: DOUBLE_SEMICOLON -> type(DOUBLE_SEMICOLON); +Inside_HASH: HASH -> type(HASH); +Inside_AT_NO_WS: AT_NO_WS -> type(AT_NO_WS); +Inside_AT_POST_WS: AT_POST_WS -> type(AT_POST_WS); +Inside_AT_PRE_WS: AT_PRE_WS -> type(AT_PRE_WS); +Inside_AT_BOTH_WS: AT_BOTH_WS -> type(AT_BOTH_WS); +Inside_QUEST_WS: '?' (Hidden | NL) -> type(QUEST_WS); +Inside_QUEST_NO_WS: QUEST_NO_WS -> type(QUEST_NO_WS); +Inside_LANGLE: LANGLE -> type(LANGLE); +Inside_RANGLE: RANGLE -> type(RANGLE); +Inside_LE: LE -> type(LE); +Inside_GE: GE -> type(GE); +Inside_EXCL_EQ: EXCL_EQ -> type(EXCL_EQ); +Inside_EXCL_EQEQ: EXCL_EQEQ -> type(EXCL_EQEQ); +Inside_IS: IS -> type(IS); +Inside_NOT_IS: NOT_IS -> type(NOT_IS); +Inside_NOT_IN: NOT_IN -> type(NOT_IN); +Inside_AS: AS -> type(AS); +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_QUOTE_OPEN: QUOTE_OPEN -> pushMode(LineString), type(QUOTE_OPEN); +Inside_TRIPLE_QUOTE_OPEN: TRIPLE_QUOTE_OPEN -> pushMode(MultiLineString), type(TRIPLE_QUOTE_OPEN); + +Inside_VAL: VAL -> type(VAL); +Inside_VAR: VAR -> type(VAR); +Inside_FUN: FUN -> type(FUN); +Inside_OBJECT: OBJECT -> type(OBJECT); +Inside_SUPER: SUPER -> type(SUPER); +Inside_IN: IN -> type(IN); +Inside_OUT: OUT -> type(OUT); +Inside_FIELD: FIELD -> type(FIELD); +Inside_FILE: FILE -> type(FILE); +Inside_PROPERTY: PROPERTY -> type(PROPERTY); +Inside_GET: GET -> type(GET); +Inside_SET: SET -> type(SET); +Inside_RECEIVER: RECEIVER -> type(RECEIVER); +Inside_PARAM: PARAM -> type(PARAM); +Inside_SETPARAM: SETPARAM -> type(SETPARAM); +Inside_DELEGATE: DELEGATE -> type(DELEGATE); +Inside_THROW: THROW -> type(THROW); +Inside_RETURN: RETURN -> type(RETURN); +Inside_CONTINUE: CONTINUE -> type(CONTINUE); +Inside_BREAK: BREAK -> type(BREAK); +Inside_RETURN_AT: RETURN_AT -> type(RETURN_AT); +Inside_CONTINUE_AT: CONTINUE_AT -> type(CONTINUE_AT); +Inside_BREAK_AT: BREAK_AT -> type(BREAK_AT); +Inside_IF: IF -> type(IF); +Inside_ELSE: ELSE -> type(ELSE); +Inside_WHEN: WHEN -> type(WHEN); +Inside_TRY: TRY -> type(TRY); +Inside_CATCH: CATCH -> type(CATCH); +Inside_FINALLY: FINALLY -> type(FINALLY); +Inside_FOR: FOR -> type(FOR); +Inside_DO: DO -> type(DO); +Inside_WHILE: WHILE -> type(WHILE); + +Inside_PUBLIC: PUBLIC -> type(PUBLIC); +Inside_PRIVATE: PRIVATE -> type(PRIVATE); +Inside_PROTECTED: PROTECTED -> type(PROTECTED); +Inside_INTERNAL: INTERNAL -> type(INTERNAL); +Inside_ENUM: ENUM -> type(ENUM); +Inside_SEALED: SEALED -> type(SEALED); +Inside_ANNOTATION: ANNOTATION -> type(ANNOTATION); +Inside_DATA: DATA -> type(DATA); +Inside_INNER: INNER -> type(INNER); +Inside_VALUE: VALUE -> type(VALUE); +Inside_TAILREC: TAILREC -> type(TAILREC); +Inside_OPERATOR: OPERATOR -> type(OPERATOR); +Inside_INLINE: INLINE -> type(INLINE); +Inside_INFIX: INFIX -> type(INFIX); +Inside_EXTERNAL: EXTERNAL -> type(EXTERNAL); +Inside_SUSPEND: SUSPEND -> type(SUSPEND); +Inside_OVERRIDE: OVERRIDE -> type(OVERRIDE); +Inside_ABSTRACT: ABSTRACT -> type(ABSTRACT); +Inside_FINAL: FINAL -> type(FINAL); +Inside_OPEN: OPEN -> type(OPEN); +Inside_CONST: CONST -> type(CONST); +Inside_LATEINIT: LATEINIT -> type(LATEINIT); +Inside_VARARG: VARARG -> type(VARARG); +Inside_NOINLINE: NOINLINE -> type(NOINLINE); +Inside_CROSSINLINE: CROSSINLINE -> type(CROSSINLINE); +Inside_REIFIED: REIFIED -> type(REIFIED); +Inside_EXPECT: EXPECT -> type(EXPECT); +Inside_ACTUAL: ACTUAL -> type(ACTUAL); + +Inside_BooleanLiteral: BooleanLiteral -> type(BooleanLiteral); +Inside_IntegerLiteral: IntegerLiteral -> type(IntegerLiteral); +Inside_HexLiteral: HexLiteral -> type(HexLiteral); +Inside_BinLiteral: BinLiteral -> type(BinLiteral); +Inside_CharacterLiteral: CharacterLiteral -> type(CharacterLiteral); +Inside_RealLiteral: RealLiteral -> type(RealLiteral); +Inside_NullLiteral: NullLiteral -> type(NullLiteral); +Inside_LongLiteral: LongLiteral -> type(LongLiteral); +Inside_UnsignedLiteral: UnsignedLiteral -> type(UnsignedLiteral); + +Inside_Identifier: Identifier -> type(Identifier); +Inside_Comment: (LineComment | DelimitedComment) -> channel(HIDDEN); +Inside_WS: WS -> channel(HIDDEN); +Inside_NL: NL -> channel(HIDDEN); + +mode DEFAULT_MODE; + +ErrorCharacter: .; diff --git a/pmd-kotlin/src/main/antlr4/net/sourceforge/pmd/lang/kotlin/ast/PmdKotlinParser.java b/pmd-kotlin/src/main/java/net/sourceforge/pmd/lang/kotlin/ast/PmdKotlinParser.java similarity index 100% rename from pmd-kotlin/src/main/antlr4/net/sourceforge/pmd/lang/kotlin/ast/PmdKotlinParser.java rename to pmd-kotlin/src/main/java/net/sourceforge/pmd/lang/kotlin/ast/PmdKotlinParser.java From 5d278c049bb658502c107bf85029b322a72d045e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9ment=20Fournier?= Date: Wed, 15 Sep 2021 16:55:37 +0200 Subject: [PATCH 008/198] Fix compilation issues --- antlr4-wrapper.xml | 38 ++++++++++++++++++- .../ast/impl/antlr4/BaseAntlrInnerNode.java | 6 +++ pmd-kotlin/pom.xml | 2 +- .../sourceforge/pmd/lang/kotlin/ast/Kotlin.g4 | 23 ++++++++++- .../lang/kotlin/ast/KotlinNameDictionary.java | 24 ++++++++++++ .../pmd/lang/kotlin/ast/KotlinRootNode.java | 13 ++++--- .../pmd/lang/kotlin/ast/PmdKotlinParser.java | 11 +++--- 7 files changed, 102 insertions(+), 15 deletions(-) create mode 100644 pmd-kotlin/src/main/java/net/sourceforge/pmd/lang/kotlin/ast/KotlinNameDictionary.java diff --git a/antlr4-wrapper.xml b/antlr4-wrapper.xml index 2e4b617e27..7219dcf44d 100644 --- a/antlr4-wrapper.xml +++ b/antlr4-wrapper.xml @@ -31,9 +31,45 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + @@ -45,7 +81,7 @@ - + diff --git a/pmd-core/src/main/java/net/sourceforge/pmd/lang/ast/impl/antlr4/BaseAntlrInnerNode.java b/pmd-core/src/main/java/net/sourceforge/pmd/lang/ast/impl/antlr4/BaseAntlrInnerNode.java index 5833547776..03c37ca247 100644 --- a/pmd-core/src/main/java/net/sourceforge/pmd/lang/ast/impl/antlr4/BaseAntlrInnerNode.java +++ b/pmd-core/src/main/java/net/sourceforge/pmd/lang/ast/impl/antlr4/BaseAntlrInnerNode.java @@ -88,6 +88,12 @@ public abstract class BaseAntlrInnerNode> extends BaseAnt return pmdWrapper != null ? pmdWrapper.asAntlrNode() : null; } + protected List getTokens(int kind) { + return children(BaseAntlrTerminalNode.class) + .filter(it -> it.getTokenKind() == kind) + .toList(BaseAntlrTerminalNode::asAntlrNode); + } + protected void copyFrom(BaseAntlrInnerNode other) { asAntlrNode().copyFrom(other.asAntlrNode()); } diff --git a/pmd-kotlin/pom.xml b/pmd-kotlin/pom.xml index c1b3e36220..d00109b502 100644 --- a/pmd-kotlin/pom.xml +++ b/pmd-kotlin/pom.xml @@ -36,7 +36,7 @@ - + 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 5712a7f82d..885fb61b91 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 @@ -9,11 +9,30 @@ import net.sourceforge.pmd.lang.ast.impl.antlr4.*; import net.sourceforge.pmd.lang.ast.AstVisitor; } -options { tokenVocab = KotlinLexer; } +@parser::members { + + static final AntlrNameDictionary DICO = new KotlinNameDictionary(VOCABULARY, ruleNames); + + @Override + public KotlinTerminalNode createPmdTerminal(ParserRuleContext parent, Token t) { + return new KotlinTerminalNode(t); + } + + @Override + public KotlinErrorNode createPmdError(ParserRuleContext parent, Token t) { + return new KotlinErrorNode(t); + } +} + +options { + tokenVocab = KotlinLexer; + contextSuperClass = 'KotlinInnerNode'; + superClass = 'AntlrGeneratedParserBase'; +} // SECTION: general -kotlinFile +file : shebangLine? NL* fileAnnotation* packageHeader importList topLevelObject* EOF ; diff --git a/pmd-kotlin/src/main/java/net/sourceforge/pmd/lang/kotlin/ast/KotlinNameDictionary.java b/pmd-kotlin/src/main/java/net/sourceforge/pmd/lang/kotlin/ast/KotlinNameDictionary.java new file mode 100644 index 0000000000..387717bb53 --- /dev/null +++ b/pmd-kotlin/src/main/java/net/sourceforge/pmd/lang/kotlin/ast/KotlinNameDictionary.java @@ -0,0 +1,24 @@ +/* + * BSD-style license; for more info see http://pmd.sourceforge.net/license.html + */ + +package net.sourceforge.pmd.lang.kotlin.ast; + +import org.antlr.v4.runtime.Vocabulary; +import org.checkerframework.checker.nullness.qual.Nullable; + +import net.sourceforge.pmd.lang.ast.impl.antlr4.AntlrNameDictionary; + + +final class KotlinNameDictionary extends AntlrNameDictionary { + + KotlinNameDictionary(Vocabulary vocab, String[] ruleNames) { + super(vocab, ruleNames); + } + + @Override + protected @Nullable String nonAlphaNumName(String name) { + // todo + return super.nonAlphaNumName(name); + } +} diff --git a/pmd-kotlin/src/main/java/net/sourceforge/pmd/lang/kotlin/ast/KotlinRootNode.java b/pmd-kotlin/src/main/java/net/sourceforge/pmd/lang/kotlin/ast/KotlinRootNode.java index 3e2fd8f04e..bb62e02a20 100644 --- a/pmd-kotlin/src/main/java/net/sourceforge/pmd/lang/kotlin/ast/KotlinRootNode.java +++ b/pmd-kotlin/src/main/java/net/sourceforge/pmd/lang/kotlin/ast/KotlinRootNode.java @@ -4,28 +4,29 @@ package net.sourceforge.pmd.lang.kotlin.ast; +import org.antlr.v4.runtime.ParserRuleContext; + import net.sourceforge.pmd.lang.ast.AstInfo; import net.sourceforge.pmd.lang.ast.Parser.ParserTask; import net.sourceforge.pmd.lang.ast.RootNode; -import net.sourceforge.pmd.lang.kotlin.ast.KotlinParser.KtTopLevel; -import org.antlr.v4.runtime.ParserRuleContext; +import net.sourceforge.pmd.lang.kotlin.ast.KotlinParser.KtFile; // package private base class abstract class KotlinRootNode extends KotlinInnerNode implements RootNode { - private AstInfo astInfo; + private AstInfo astInfo; KotlinRootNode(ParserRuleContext parent, int invokingStateNumber) { super(parent, invokingStateNumber); } @Override - public AstInfo getAstInfo() { + public AstInfo getAstInfo() { return astInfo; } - KtTopLevel makeAstInfo(ParserTask task) { - KtTopLevel me = (KtTopLevel) this; + KtFile makeAstInfo(ParserTask task) { + KtFile me = (KtFile) this; this.astInfo = new AstInfo<>(task, me); return me; } diff --git a/pmd-kotlin/src/main/java/net/sourceforge/pmd/lang/kotlin/ast/PmdKotlinParser.java b/pmd-kotlin/src/main/java/net/sourceforge/pmd/lang/kotlin/ast/PmdKotlinParser.java index c789950765..234a95491f 100644 --- a/pmd-kotlin/src/main/java/net/sourceforge/pmd/lang/kotlin/ast/PmdKotlinParser.java +++ b/pmd-kotlin/src/main/java/net/sourceforge/pmd/lang/kotlin/ast/PmdKotlinParser.java @@ -4,21 +4,22 @@ package net.sourceforge.pmd.lang.kotlin.ast; -import net.sourceforge.pmd.lang.ast.impl.antlr4.AntlrBaseParser; -import net.sourceforge.pmd.lang.kotlin.ast.KotlinParser.KtTopLevel; import org.antlr.v4.runtime.CharStream; import org.antlr.v4.runtime.CommonTokenStream; import org.antlr.v4.runtime.Lexer; +import net.sourceforge.pmd.lang.ast.impl.antlr4.AntlrBaseParser; +import net.sourceforge.pmd.lang.kotlin.ast.KotlinParser.KtFile; + /** * Adapter for the KotlinParser. */ -public final class PmdKotlinParser extends AntlrBaseParser { +public final class PmdKotlinParser extends AntlrBaseParser { @Override - protected KtTopLevel parse(final Lexer lexer, ParserTask task) { + protected KtFile parse(final Lexer lexer, ParserTask task) { KotlinParser parser = new KotlinParser(new CommonTokenStream(lexer)); - return parser.topLevel().makeAstInfo(task); + return parser.file().makeAstInfo(task); } @Override From e945897278f51887caad80f1a0d3e2d1e901054d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9ment=20Fournier?= Date: Wed, 15 Sep 2021 17:36:47 +0200 Subject: [PATCH 009/198] Fix pmd warning --- .../java/net/sourceforge/pmd/lang/kotlin/KotlinHandler.java | 4 ++++ .../sourceforge/pmd/lang/kotlin/KotlinLanguageModule.java | 6 +++--- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/pmd-kotlin/src/main/java/net/sourceforge/pmd/lang/kotlin/KotlinHandler.java b/pmd-kotlin/src/main/java/net/sourceforge/pmd/lang/kotlin/KotlinHandler.java index 6eaa0c5752..e7df396ec2 100644 --- a/pmd-kotlin/src/main/java/net/sourceforge/pmd/lang/kotlin/KotlinHandler.java +++ b/pmd-kotlin/src/main/java/net/sourceforge/pmd/lang/kotlin/KotlinHandler.java @@ -22,4 +22,8 @@ public class KotlinHandler extends AbstractPmdLanguageVersionHandler { public Parser getParser() { return new PmdKotlinParser(); } + + public String getKotlinRelease() { + return kotlinRelease; + } } 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 e61608b108..9a26caf4e0 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 @@ -21,8 +21,8 @@ public class KotlinLanguageModule extends BaseLanguageModule { */ public KotlinLanguageModule() { super(NAME, null, TERSE_NAME, "kt", "ktm"); - addVersion("", new KotlinHandler("1.3")); - addVersion("", new KotlinHandler("1.4")); - addDefaultVersion("", new KotlinHandler("1.5")); + addVersion("1.3", new KotlinHandler("1.3")); + addVersion("1.4", new KotlinHandler("1.4")); + addDefaultVersion("1.5", new KotlinHandler("1.5")); } } From c2eb1e6bab6293050253c45f769f9cf1eb1665b0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9ment=20Fournier?= Date: Wed, 15 Sep 2021 18:25:04 +0200 Subject: [PATCH 010/198] checkstyle issues --- .../sourceforge/pmd/lang/kotlin/ast/KotlinErrorNode.java | 3 ++- .../sourceforge/pmd/lang/kotlin/ast/KotlinInnerNode.java | 7 ++----- .../net/sourceforge/pmd/lang/kotlin/ast/KotlinNode.java | 5 +++++ .../pmd/lang/kotlin/ast/KotlinTerminalNode.java | 3 ++- 4 files changed, 11 insertions(+), 7 deletions(-) diff --git a/pmd-kotlin/src/main/java/net/sourceforge/pmd/lang/kotlin/ast/KotlinErrorNode.java b/pmd-kotlin/src/main/java/net/sourceforge/pmd/lang/kotlin/ast/KotlinErrorNode.java index 82ddedf524..f1b2f686d0 100644 --- a/pmd-kotlin/src/main/java/net/sourceforge/pmd/lang/kotlin/ast/KotlinErrorNode.java +++ b/pmd-kotlin/src/main/java/net/sourceforge/pmd/lang/kotlin/ast/KotlinErrorNode.java @@ -4,9 +4,10 @@ package net.sourceforge.pmd.lang.kotlin.ast; -import net.sourceforge.pmd.lang.ast.impl.antlr4.BaseAntlrErrorNode; import org.antlr.v4.runtime.Token; +import net.sourceforge.pmd.lang.ast.impl.antlr4.BaseAntlrErrorNode; + public final class KotlinErrorNode extends BaseAntlrErrorNode implements KotlinNode { KotlinErrorNode(Token token) { diff --git a/pmd-kotlin/src/main/java/net/sourceforge/pmd/lang/kotlin/ast/KotlinInnerNode.java b/pmd-kotlin/src/main/java/net/sourceforge/pmd/lang/kotlin/ast/KotlinInnerNode.java index 578cf4e9ab..a6d58699ae 100644 --- a/pmd-kotlin/src/main/java/net/sourceforge/pmd/lang/kotlin/ast/KotlinInnerNode.java +++ b/pmd-kotlin/src/main/java/net/sourceforge/pmd/lang/kotlin/ast/KotlinInnerNode.java @@ -4,17 +4,14 @@ package net.sourceforge.pmd.lang.kotlin.ast; +import org.antlr.v4.runtime.ParserRuleContext; + import net.sourceforge.pmd.lang.ast.AstVisitor; import net.sourceforge.pmd.lang.ast.impl.antlr4.BaseAntlrInnerNode; -import org.antlr.v4.runtime.ParserRuleContext; public abstract class KotlinInnerNode extends BaseAntlrInnerNode implements KotlinNode { - KotlinInnerNode() { - super(); - } - KotlinInnerNode(ParserRuleContext parent, int invokingStateNumber) { super(parent, invokingStateNumber); } diff --git a/pmd-kotlin/src/main/java/net/sourceforge/pmd/lang/kotlin/ast/KotlinNode.java b/pmd-kotlin/src/main/java/net/sourceforge/pmd/lang/kotlin/ast/KotlinNode.java index 1d933a829a..6bb32f677b 100644 --- a/pmd-kotlin/src/main/java/net/sourceforge/pmd/lang/kotlin/ast/KotlinNode.java +++ b/pmd-kotlin/src/main/java/net/sourceforge/pmd/lang/kotlin/ast/KotlinNode.java @@ -1,4 +1,9 @@ +/* + * BSD-style license; for more info see http://pmd.sourceforge.net/license.html + */ + package net.sourceforge.pmd.lang.kotlin.ast; + import net.sourceforge.pmd.lang.ast.impl.antlr4.AntlrNode; /** diff --git a/pmd-kotlin/src/main/java/net/sourceforge/pmd/lang/kotlin/ast/KotlinTerminalNode.java b/pmd-kotlin/src/main/java/net/sourceforge/pmd/lang/kotlin/ast/KotlinTerminalNode.java index 6da6718116..bcf9e867b2 100644 --- a/pmd-kotlin/src/main/java/net/sourceforge/pmd/lang/kotlin/ast/KotlinTerminalNode.java +++ b/pmd-kotlin/src/main/java/net/sourceforge/pmd/lang/kotlin/ast/KotlinTerminalNode.java @@ -4,10 +4,11 @@ package net.sourceforge.pmd.lang.kotlin.ast; -import net.sourceforge.pmd.lang.ast.impl.antlr4.BaseAntlrTerminalNode; import org.antlr.v4.runtime.Token; import org.checkerframework.checker.nullness.qual.NonNull; +import net.sourceforge.pmd.lang.ast.impl.antlr4.BaseAntlrTerminalNode; + public final class KotlinTerminalNode extends BaseAntlrTerminalNode implements KotlinNode { KotlinTerminalNode(Token token) { From 1a36a7cc555390ad6ef771d391b5d016255740dd Mon Sep 17 00:00:00 2001 From: Peter Paul Bakker Date: Wed, 13 Oct 2021 10:32:19 +0200 Subject: [PATCH 011/198] upped antlr plugin version, fix AST errors by using separate UnicodeClasses.g4 file, added to maven antlr plugin to make it work --- .../pmd/lang/kotlin/ast/KotlinLexer.g4 | 1645 +--------------- .../pmd/lang/kotlin/ast/UnicodeClasses.g4 | 1649 +++++++++++++++++ pom.xml | 3 +- 3 files changed, 1653 insertions(+), 1644 deletions(-) create mode 100644 pmd-kotlin/src/main/antlr4/net/sourceforge/pmd/lang/kotlin/ast/UnicodeClasses.g4 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 9b401e934a..02d9d5736a 100755 --- 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 @@ -4,1650 +4,9 @@ lexer grammar KotlinLexer; -//import UnicodeClasses; -// Taken from http://www.antlr3.org/grammar/1345144569663/AntlrUnicode.txt +import UnicodeClasses; -UNICODE_CLASS_LL: - '\u0061'..'\u007A' | - '\u00B5' | - '\u00DF'..'\u00F6' | - '\u00F8'..'\u00FF' | - '\u0101' | - '\u0103' | - '\u0105' | - '\u0107' | - '\u0109' | - '\u010B' | - '\u010D' | - '\u010F' | - '\u0111' | - '\u0113' | - '\u0115' | - '\u0117' | - '\u0119' | - '\u011B' | - '\u011D' | - '\u011F' | - '\u0121' | - '\u0123' | - '\u0125' | - '\u0127' | - '\u0129' | - '\u012B' | - '\u012D' | - '\u012F' | - '\u0131' | - '\u0133' | - '\u0135' | - '\u0137' | - '\u0138' | - '\u013A' | - '\u013C' | - '\u013E' | - '\u0140' | - '\u0142' | - '\u0144' | - '\u0146' | - '\u0148' | - '\u0149' | - '\u014B' | - '\u014D' | - '\u014F' | - '\u0151' | - '\u0153' | - '\u0155' | - '\u0157' | - '\u0159' | - '\u015B' | - '\u015D' | - '\u015F' | - '\u0161' | - '\u0163' | - '\u0165' | - '\u0167' | - '\u0169' | - '\u016B' | - '\u016D' | - '\u016F' | - '\u0171' | - '\u0173' | - '\u0175' | - '\u0177' | - '\u017A' | - '\u017C' | - '\u017E'..'\u0180' | - '\u0183' | - '\u0185' | - '\u0188' | - '\u018C' | - '\u018D' | - '\u0192' | - '\u0195' | - '\u0199'..'\u019B' | - '\u019E' | - '\u01A1' | - '\u01A3' | - '\u01A5' | - '\u01A8' | - '\u01AA' | - '\u01AB' | - '\u01AD' | - '\u01B0' | - '\u01B4' | - '\u01B6' | - '\u01B9' | - '\u01BA' | - '\u01BD'..'\u01BF' | - '\u01C6' | - '\u01C9' | - '\u01CC' | - '\u01CE' | - '\u01D0' | - '\u01D2' | - '\u01D4' | - '\u01D6' | - '\u01D8' | - '\u01DA' | - '\u01DC' | - '\u01DD' | - '\u01DF' | - '\u01E1' | - '\u01E3' | - '\u01E5' | - '\u01E7' | - '\u01E9' | - '\u01EB' | - '\u01ED' | - '\u01EF' | - '\u01F0' | - '\u01F3' | - '\u01F5' | - '\u01F9' | - '\u01FB' | - '\u01FD' | - '\u01FF' | - '\u0201' | - '\u0203' | - '\u0205' | - '\u0207' | - '\u0209' | - '\u020B' | - '\u020D' | - '\u020F' | - '\u0211' | - '\u0213' | - '\u0215' | - '\u0217' | - '\u0219' | - '\u021B' | - '\u021D' | - '\u021F' | - '\u0221' | - '\u0223' | - '\u0225' | - '\u0227' | - '\u0229' | - '\u022B' | - '\u022D' | - '\u022F' | - '\u0231' | - '\u0233'..'\u0239' | - '\u023C' | - '\u023F' | - '\u0240' | - '\u0242' | - '\u0247' | - '\u0249' | - '\u024B' | - '\u024D' | - '\u024F'..'\u0293' | - '\u0295'..'\u02AF' | - '\u0371' | - '\u0373' | - '\u0377' | - '\u037B'..'\u037D' | - '\u0390' | - '\u03AC'..'\u03CE' | - '\u03D0' | - '\u03D1' | - '\u03D5'..'\u03D7' | - '\u03D9' | - '\u03DB' | - '\u03DD' | - '\u03DF' | - '\u03E1' | - '\u03E3' | - '\u03E5' | - '\u03E7' | - '\u03E9' | - '\u03EB' | - '\u03ED' | - '\u03EF'..'\u03F3' | - '\u03F5' | - '\u03F8' | - '\u03FB' | - '\u03FC' | - '\u0430'..'\u045F' | - '\u0461' | - '\u0463' | - '\u0465' | - '\u0467' | - '\u0469' | - '\u046B' | - '\u046D' | - '\u046F' | - '\u0471' | - '\u0473' | - '\u0475' | - '\u0477' | - '\u0479' | - '\u047B' | - '\u047D' | - '\u047F' | - '\u0481' | - '\u048B' | - '\u048D' | - '\u048F' | - '\u0491' | - '\u0493' | - '\u0495' | - '\u0497' | - '\u0499' | - '\u049B' | - '\u049D' | - '\u049F' | - '\u04A1' | - '\u04A3' | - '\u04A5' | - '\u04A7' | - '\u04A9' | - '\u04AB' | - '\u04AD' | - '\u04AF' | - '\u04B1' | - '\u04B3' | - '\u04B5' | - '\u04B7' | - '\u04B9' | - '\u04BB' | - '\u04BD' | - '\u04BF' | - '\u04C2' | - '\u04C4' | - '\u04C6' | - '\u04C8' | - '\u04CA' | - '\u04CC' | - '\u04CE' | - '\u04CF' | - '\u04D1' | - '\u04D3' | - '\u04D5' | - '\u04D7' | - '\u04D9' | - '\u04DB' | - '\u04DD' | - '\u04DF' | - '\u04E1' | - '\u04E3' | - '\u04E5' | - '\u04E7' | - '\u04E9' | - '\u04EB' | - '\u04ED' | - '\u04EF' | - '\u04F1' | - '\u04F3' | - '\u04F5' | - '\u04F7' | - '\u04F9' | - '\u04FB' | - '\u04FD' | - '\u04FF' | - '\u0501' | - '\u0503' | - '\u0505' | - '\u0507' | - '\u0509' | - '\u050B' | - '\u050D' | - '\u050F' | - '\u0511' | - '\u0513' | - '\u0515' | - '\u0517' | - '\u0519' | - '\u051B' | - '\u051D' | - '\u051F' | - '\u0521' | - '\u0523' | - '\u0525' | - '\u0527' | - '\u0561'..'\u0587' | - '\u1D00'..'\u1D2B' | - '\u1D6B'..'\u1D77' | - '\u1D79'..'\u1D9A' | - '\u1E01' | - '\u1E03' | - '\u1E05' | - '\u1E07' | - '\u1E09' | - '\u1E0B' | - '\u1E0D' | - '\u1E0F' | - '\u1E11' | - '\u1E13' | - '\u1E15' | - '\u1E17' | - '\u1E19' | - '\u1E1B' | - '\u1E1D' | - '\u1E1F' | - '\u1E21' | - '\u1E23' | - '\u1E25' | - '\u1E27' | - '\u1E29' | - '\u1E2B' | - '\u1E2D' | - '\u1E2F' | - '\u1E31' | - '\u1E33' | - '\u1E35' | - '\u1E37' | - '\u1E39' | - '\u1E3B' | - '\u1E3D' | - '\u1E3F' | - '\u1E41' | - '\u1E43' | - '\u1E45' | - '\u1E47' | - '\u1E49' | - '\u1E4B' | - '\u1E4D' | - '\u1E4F' | - '\u1E51' | - '\u1E53' | - '\u1E55' | - '\u1E57' | - '\u1E59' | - '\u1E5B' | - '\u1E5D' | - '\u1E5F' | - '\u1E61' | - '\u1E63' | - '\u1E65' | - '\u1E67' | - '\u1E69' | - '\u1E6B' | - '\u1E6D' | - '\u1E6F' | - '\u1E71' | - '\u1E73' | - '\u1E75' | - '\u1E77' | - '\u1E79' | - '\u1E7B' | - '\u1E7D' | - '\u1E7F' | - '\u1E81' | - '\u1E83' | - '\u1E85' | - '\u1E87' | - '\u1E89' | - '\u1E8B' | - '\u1E8D' | - '\u1E8F' | - '\u1E91' | - '\u1E93' | - '\u1E95'..'\u1E9D' | - '\u1E9F' | - '\u1EA1' | - '\u1EA3' | - '\u1EA5' | - '\u1EA7' | - '\u1EA9' | - '\u1EAB' | - '\u1EAD' | - '\u1EAF' | - '\u1EB1' | - '\u1EB3' | - '\u1EB5' | - '\u1EB7' | - '\u1EB9' | - '\u1EBB' | - '\u1EBD' | - '\u1EBF' | - '\u1EC1' | - '\u1EC3' | - '\u1EC5' | - '\u1EC7' | - '\u1EC9' | - '\u1ECB' | - '\u1ECD' | - '\u1ECF' | - '\u1ED1' | - '\u1ED3' | - '\u1ED5' | - '\u1ED7' | - '\u1ED9' | - '\u1EDB' | - '\u1EDD' | - '\u1EDF' | - '\u1EE1' | - '\u1EE3' | - '\u1EE5' | - '\u1EE7' | - '\u1EE9' | - '\u1EEB' | - '\u1EED' | - '\u1EEF' | - '\u1EF1' | - '\u1EF3' | - '\u1EF5' | - '\u1EF7' | - '\u1EF9' | - '\u1EFB' | - '\u1EFD' | - '\u1EFF'..'\u1F07' | - '\u1F10'..'\u1F15' | - '\u1F20'..'\u1F27' | - '\u1F30'..'\u1F37' | - '\u1F40'..'\u1F45' | - '\u1F50'..'\u1F57' | - '\u1F60'..'\u1F67' | - '\u1F70'..'\u1F7D' | - '\u1F80'..'\u1F87' | - '\u1F90'..'\u1F97' | - '\u1FA0'..'\u1FA7' | - '\u1FB0'..'\u1FB4' | - '\u1FB6' | - '\u1FB7' | - '\u1FBE' | - '\u1FC2'..'\u1FC4' | - '\u1FC6' | - '\u1FC7' | - '\u1FD0'..'\u1FD3' | - '\u1FD6' | - '\u1FD7' | - '\u1FE0'..'\u1FE7' | - '\u1FF2'..'\u1FF4' | - '\u1FF6' | - '\u1FF7' | - '\u210A' | - '\u210E' | - '\u210F' | - '\u2113' | - '\u212F' | - '\u2134' | - '\u2139' | - '\u213C' | - '\u213D' | - '\u2146'..'\u2149' | - '\u214E' | - '\u2184' | - '\u2C30'..'\u2C5E' | - '\u2C61' | - '\u2C65' | - '\u2C66' | - '\u2C68' | - '\u2C6A' | - '\u2C6C' | - '\u2C71' | - '\u2C73' | - '\u2C74' | - '\u2C76'..'\u2C7B' | - '\u2C81' | - '\u2C83' | - '\u2C85' | - '\u2C87' | - '\u2C89' | - '\u2C8B' | - '\u2C8D' | - '\u2C8F' | - '\u2C91' | - '\u2C93' | - '\u2C95' | - '\u2C97' | - '\u2C99' | - '\u2C9B' | - '\u2C9D' | - '\u2C9F' | - '\u2CA1' | - '\u2CA3' | - '\u2CA5' | - '\u2CA7' | - '\u2CA9' | - '\u2CAB' | - '\u2CAD' | - '\u2CAF' | - '\u2CB1' | - '\u2CB3' | - '\u2CB5' | - '\u2CB7' | - '\u2CB9' | - '\u2CBB' | - '\u2CBD' | - '\u2CBF' | - '\u2CC1' | - '\u2CC3' | - '\u2CC5' | - '\u2CC7' | - '\u2CC9' | - '\u2CCB' | - '\u2CCD' | - '\u2CCF' | - '\u2CD1' | - '\u2CD3' | - '\u2CD5' | - '\u2CD7' | - '\u2CD9' | - '\u2CDB' | - '\u2CDD' | - '\u2CDF' | - '\u2CE1' | - '\u2CE3' | - '\u2CE4' | - '\u2CEC' | - '\u2CEE' | - '\u2CF3' | - '\u2D00'..'\u2D25' | - '\u2D27' | - '\u2D2D' | - '\uA641' | - '\uA643' | - '\uA645' | - '\uA647' | - '\uA649' | - '\uA64B' | - '\uA64D' | - '\uA64F' | - '\uA651' | - '\uA653' | - '\uA655' | - '\uA657' | - '\uA659' | - '\uA65B' | - '\uA65D' | - '\uA65F' | - '\uA661' | - '\uA663' | - '\uA665' | - '\uA667' | - '\uA669' | - '\uA66B' | - '\uA66D' | - '\uA681' | - '\uA683' | - '\uA685' | - '\uA687' | - '\uA689' | - '\uA68B' | - '\uA68D' | - '\uA68F' | - '\uA691' | - '\uA693' | - '\uA695' | - '\uA697' | - '\uA723' | - '\uA725' | - '\uA727' | - '\uA729' | - '\uA72B' | - '\uA72D' | - '\uA72F'..'\uA731' | - '\uA733' | - '\uA735' | - '\uA737' | - '\uA739' | - '\uA73B' | - '\uA73D' | - '\uA73F' | - '\uA741' | - '\uA743' | - '\uA745' | - '\uA747' | - '\uA749' | - '\uA74B' | - '\uA74D' | - '\uA74F' | - '\uA751' | - '\uA753' | - '\uA755' | - '\uA757' | - '\uA759' | - '\uA75B' | - '\uA75D' | - '\uA75F' | - '\uA761' | - '\uA763' | - '\uA765' | - '\uA767' | - '\uA769' | - '\uA76B' | - '\uA76D' | - '\uA76F' | - '\uA771'..'\uA778' | - '\uA77A' | - '\uA77C' | - '\uA77F' | - '\uA781' | - '\uA783' | - '\uA785' | - '\uA787' | - '\uA78C' | - '\uA78E' | - '\uA791' | - '\uA793' | - '\uA7A1' | - '\uA7A3' | - '\uA7A5' | - '\uA7A7' | - '\uA7A9' | - '\uA7FA' | - '\uFB00'..'\uFB06' | - '\uFB13'..'\uFB17' | - '\uFF41'..'\uFF5A'; - -UNICODE_CLASS_LM: - '\u02B0'..'\u02C1' | - '\u02C6'..'\u02D1' | - '\u02E0'..'\u02E4' | - '\u02EC' | - '\u02EE' | - '\u0374' | - '\u037A' | - '\u0559' | - '\u0640' | - '\u06E5' | - '\u06E6' | - '\u07F4' | - '\u07F5' | - '\u07FA' | - '\u081A' | - '\u0824' | - '\u0828' | - '\u0971' | - '\u0E46' | - '\u0EC6' | - '\u10FC' | - '\u17D7' | - '\u1843' | - '\u1AA7' | - '\u1C78'..'\u1C7D' | - '\u1D2C'..'\u1D6A' | - '\u1D78' | - '\u1D9B'..'\u1DBF' | - '\u2071' | - '\u207F' | - '\u2090'..'\u209C' | - '\u2C7C' | - '\u2C7D' | - '\u2D6F' | - '\u2E2F' | - '\u3005' | - '\u3031'..'\u3035' | - '\u303B' | - '\u309D' | - '\u309E' | - '\u30FC'..'\u30FE' | - '\uA015' | - '\uA4F8'..'\uA4FD' | - '\uA60C' | - '\uA67F' | - '\uA717'..'\uA71F' | - '\uA770' | - '\uA788' | - '\uA7F8' | - '\uA7F9' | - '\uA9CF' | - '\uAA70' | - '\uAADD' | - '\uAAF3' | - '\uAAF4' | - '\uFF70' | - '\uFF9E' | - '\uFF9F'; - -UNICODE_CLASS_LO: - '\u00AA' | - '\u00BA' | - '\u01BB' | - '\u01C0'..'\u01C3' | - '\u0294' | - '\u05D0'..'\u05EA' | - '\u05F0'..'\u05F2' | - '\u0620'..'\u063F' | - '\u0641'..'\u064A' | - '\u066E' | - '\u066F' | - '\u0671'..'\u06D3' | - '\u06D5' | - '\u06EE' | - '\u06EF' | - '\u06FA'..'\u06FC' | - '\u06FF' | - '\u0710' | - '\u0712'..'\u072F' | - '\u074D'..'\u07A5' | - '\u07B1' | - '\u07CA'..'\u07EA' | - '\u0800'..'\u0815' | - '\u0840'..'\u0858' | - '\u08A0' | - '\u08A2'..'\u08AC' | - '\u0904'..'\u0939' | - '\u093D' | - '\u0950' | - '\u0958'..'\u0961' | - '\u0972'..'\u0977' | - '\u0979'..'\u097F' | - '\u0985'..'\u098C' | - '\u098F' | - '\u0990' | - '\u0993'..'\u09A8' | - '\u09AA'..'\u09B0' | - '\u09B2' | - '\u09B6'..'\u09B9' | - '\u09BD' | - '\u09CE' | - '\u09DC' | - '\u09DD' | - '\u09DF'..'\u09E1' | - '\u09F0' | - '\u09F1' | - '\u0A05'..'\u0A0A' | - '\u0A0F' | - '\u0A10' | - '\u0A13'..'\u0A28' | - '\u0A2A'..'\u0A30' | - '\u0A32' | - '\u0A33' | - '\u0A35' | - '\u0A36' | - '\u0A38' | - '\u0A39' | - '\u0A59'..'\u0A5C' | - '\u0A5E' | - '\u0A72'..'\u0A74' | - '\u0A85'..'\u0A8D' | - '\u0A8F'..'\u0A91' | - '\u0A93'..'\u0AA8' | - '\u0AAA'..'\u0AB0' | - '\u0AB2' | - '\u0AB3' | - '\u0AB5'..'\u0AB9' | - '\u0ABD' | - '\u0AD0' | - '\u0AE0' | - '\u0AE1' | - '\u0B05'..'\u0B0C' | - '\u0B0F' | - '\u0B10' | - '\u0B13'..'\u0B28' | - '\u0B2A'..'\u0B30' | - '\u0B32' | - '\u0B33' | - '\u0B35'..'\u0B39' | - '\u0B3D' | - '\u0B5C' | - '\u0B5D' | - '\u0B5F'..'\u0B61' | - '\u0B71' | - '\u0B83' | - '\u0B85'..'\u0B8A' | - '\u0B8E'..'\u0B90' | - '\u0B92'..'\u0B95' | - '\u0B99' | - '\u0B9A' | - '\u0B9C' | - '\u0B9E' | - '\u0B9F' | - '\u0BA3' | - '\u0BA4' | - '\u0BA8'..'\u0BAA' | - '\u0BAE'..'\u0BB9' | - '\u0BD0' | - '\u0C05'..'\u0C0C' | - '\u0C0E'..'\u0C10' | - '\u0C12'..'\u0C28' | - '\u0C2A'..'\u0C33' | - '\u0C35'..'\u0C39' | - '\u0C3D' | - '\u0C58' | - '\u0C59' | - '\u0C60' | - '\u0C61' | - '\u0C85'..'\u0C8C' | - '\u0C8E'..'\u0C90' | - '\u0C92'..'\u0CA8' | - '\u0CAA'..'\u0CB3' | - '\u0CB5'..'\u0CB9' | - '\u0CBD' | - '\u0CDE' | - '\u0CE0' | - '\u0CE1' | - '\u0CF1' | - '\u0CF2' | - '\u0D05'..'\u0D0C' | - '\u0D0E'..'\u0D10' | - '\u0D12'..'\u0D3A' | - '\u0D3D' | - '\u0D4E' | - '\u0D60' | - '\u0D61' | - '\u0D7A'..'\u0D7F' | - '\u0D85'..'\u0D96' | - '\u0D9A'..'\u0DB1' | - '\u0DB3'..'\u0DBB' | - '\u0DBD' | - '\u0DC0'..'\u0DC6' | - '\u0E01'..'\u0E30' | - '\u0E32' | - '\u0E33' | - '\u0E40'..'\u0E45' | - '\u0E81' | - '\u0E82' | - '\u0E84' | - '\u0E87' | - '\u0E88' | - '\u0E8A' | - '\u0E8D' | - '\u0E94'..'\u0E97' | - '\u0E99'..'\u0E9F' | - '\u0EA1'..'\u0EA3' | - '\u0EA5' | - '\u0EA7' | - '\u0EAA' | - '\u0EAB' | - '\u0EAD'..'\u0EB0' | - '\u0EB2' | - '\u0EB3' | - '\u0EBD' | - '\u0EC0'..'\u0EC4' | - '\u0EDC'..'\u0EDF' | - '\u0F00' | - '\u0F40'..'\u0F47' | - '\u0F49'..'\u0F6C' | - '\u0F88'..'\u0F8C' | - '\u1000'..'\u102A' | - '\u103F' | - '\u1050'..'\u1055' | - '\u105A'..'\u105D' | - '\u1061' | - '\u1065' | - '\u1066' | - '\u106E'..'\u1070' | - '\u1075'..'\u1081' | - '\u108E' | - '\u10D0'..'\u10FA' | - '\u10FD'..'\u1248' | - '\u124A'..'\u124D' | - '\u1250'..'\u1256' | - '\u1258' | - '\u125A'..'\u125D' | - '\u1260'..'\u1288' | - '\u128A'..'\u128D' | - '\u1290'..'\u12B0' | - '\u12B2'..'\u12B5' | - '\u12B8'..'\u12BE' | - '\u12C0' | - '\u12C2'..'\u12C5' | - '\u12C8'..'\u12D6' | - '\u12D8'..'\u1310' | - '\u1312'..'\u1315' | - '\u1318'..'\u135A' | - '\u1380'..'\u138F' | - '\u13A0'..'\u13F4' | - '\u1401'..'\u166C' | - '\u166F'..'\u167F' | - '\u1681'..'\u169A' | - '\u16A0'..'\u16EA' | - '\u1700'..'\u170C' | - '\u170E'..'\u1711' | - '\u1720'..'\u1731' | - '\u1740'..'\u1751' | - '\u1760'..'\u176C' | - '\u176E'..'\u1770' | - '\u1780'..'\u17B3' | - '\u17DC' | - '\u1820'..'\u1842' | - '\u1844'..'\u1877' | - '\u1880'..'\u18A8' | - '\u18AA' | - '\u18B0'..'\u18F5' | - '\u1900'..'\u191C' | - '\u1950'..'\u196D' | - '\u1970'..'\u1974' | - '\u1980'..'\u19AB' | - '\u19C1'..'\u19C7' | - '\u1A00'..'\u1A16' | - '\u1A20'..'\u1A54' | - '\u1B05'..'\u1B33' | - '\u1B45'..'\u1B4B' | - '\u1B83'..'\u1BA0' | - '\u1BAE' | - '\u1BAF' | - '\u1BBA'..'\u1BE5' | - '\u1C00'..'\u1C23' | - '\u1C4D'..'\u1C4F' | - '\u1C5A'..'\u1C77' | - '\u1CE9'..'\u1CEC' | - '\u1CEE'..'\u1CF1' | - '\u1CF5' | - '\u1CF6' | - '\u2135'..'\u2138' | - '\u2D30'..'\u2D67' | - '\u2D80'..'\u2D96' | - '\u2DA0'..'\u2DA6' | - '\u2DA8'..'\u2DAE' | - '\u2DB0'..'\u2DB6' | - '\u2DB8'..'\u2DBE' | - '\u2DC0'..'\u2DC6' | - '\u2DC8'..'\u2DCE' | - '\u2DD0'..'\u2DD6' | - '\u2DD8'..'\u2DDE' | - '\u3006' | - '\u303C' | - '\u3041'..'\u3096' | - '\u309F' | - '\u30A1'..'\u30FA' | - '\u30FF' | - '\u3105'..'\u312D' | - '\u3131'..'\u318E' | - '\u31A0'..'\u31BA' | - '\u31F0'..'\u31FF' | - '\u3400' | - '\u4DB5' | - '\u4E00' | - '\u9FCC' | - '\uA000'..'\uA014' | - '\uA016'..'\uA48C' | - '\uA4D0'..'\uA4F7' | - '\uA500'..'\uA60B' | - '\uA610'..'\uA61F' | - '\uA62A' | - '\uA62B' | - '\uA66E' | - '\uA6A0'..'\uA6E5' | - '\uA7FB'..'\uA801' | - '\uA803'..'\uA805' | - '\uA807'..'\uA80A' | - '\uA80C'..'\uA822' | - '\uA840'..'\uA873' | - '\uA882'..'\uA8B3' | - '\uA8F2'..'\uA8F7' | - '\uA8FB' | - '\uA90A'..'\uA925' | - '\uA930'..'\uA946' | - '\uA960'..'\uA97C' | - '\uA984'..'\uA9B2' | - '\uAA00'..'\uAA28' | - '\uAA40'..'\uAA42' | - '\uAA44'..'\uAA4B' | - '\uAA60'..'\uAA6F' | - '\uAA71'..'\uAA76' | - '\uAA7A' | - '\uAA80'..'\uAAAF' | - '\uAAB1' | - '\uAAB5' | - '\uAAB6' | - '\uAAB9'..'\uAABD' | - '\uAAC0' | - '\uAAC2' | - '\uAADB' | - '\uAADC' | - '\uAAE0'..'\uAAEA' | - '\uAAF2' | - '\uAB01'..'\uAB06' | - '\uAB09'..'\uAB0E' | - '\uAB11'..'\uAB16' | - '\uAB20'..'\uAB26' | - '\uAB28'..'\uAB2E' | - '\uABC0'..'\uABE2' | - '\uAC00' | - '\uD7A3' | - '\uD7B0'..'\uD7C6' | - '\uD7CB'..'\uD7FB' | - '\uF900'..'\uFA6D' | - '\uFA70'..'\uFAD9' | - '\uFB1D' | - '\uFB1F'..'\uFB28' | - '\uFB2A'..'\uFB36' | - '\uFB38'..'\uFB3C' | - '\uFB3E' | - '\uFB40' | - '\uFB41' | - '\uFB43' | - '\uFB44' | - '\uFB46'..'\uFBB1' | - '\uFBD3'..'\uFD3D' | - '\uFD50'..'\uFD8F' | - '\uFD92'..'\uFDC7' | - '\uFDF0'..'\uFDFB' | - '\uFE70'..'\uFE74' | - '\uFE76'..'\uFEFC' | - '\uFF66'..'\uFF6F' | - '\uFF71'..'\uFF9D' | - '\uFFA0'..'\uFFBE' | - '\uFFC2'..'\uFFC7' | - '\uFFCA'..'\uFFCF' | - '\uFFD2'..'\uFFD7' | - '\uFFDA'..'\uFFDC'; - -UNICODE_CLASS_LT: - '\u01C5' | - '\u01C8' | - '\u01CB' | - '\u01F2' | - '\u1F88'..'\u1F8F' | - '\u1F98'..'\u1F9F' | - '\u1FA8'..'\u1FAF' | - '\u1FBC' | - '\u1FCC' | - '\u1FFC'; - -UNICODE_CLASS_LU: - '\u0041'..'\u005A' | - '\u00C0'..'\u00D6' | - '\u00D8'..'\u00DE' | - '\u0100' | - '\u0102' | - '\u0104' | - '\u0106' | - '\u0108' | - '\u010A' | - '\u010C' | - '\u010E' | - '\u0110' | - '\u0112' | - '\u0114' | - '\u0116' | - '\u0118' | - '\u011A' | - '\u011C' | - '\u011E' | - '\u0120' | - '\u0122' | - '\u0124' | - '\u0126' | - '\u0128' | - '\u012A' | - '\u012C' | - '\u012E' | - '\u0130' | - '\u0132' | - '\u0134' | - '\u0136' | - '\u0139' | - '\u013B' | - '\u013D' | - '\u013F' | - '\u0141' | - '\u0143' | - '\u0145' | - '\u0147' | - '\u014A' | - '\u014C' | - '\u014E' | - '\u0150' | - '\u0152' | - '\u0154' | - '\u0156' | - '\u0158' | - '\u015A' | - '\u015C' | - '\u015E' | - '\u0160' | - '\u0162' | - '\u0164' | - '\u0166' | - '\u0168' | - '\u016A' | - '\u016C' | - '\u016E' | - '\u0170' | - '\u0172' | - '\u0174' | - '\u0176' | - '\u0178' | - '\u0179' | - '\u017B' | - '\u017D' | - '\u0181' | - '\u0182' | - '\u0184' | - '\u0186' | - '\u0187' | - '\u0189'..'\u018B' | - '\u018E'..'\u0191' | - '\u0193' | - '\u0194' | - '\u0196'..'\u0198' | - '\u019C' | - '\u019D' | - '\u019F' | - '\u01A0' | - '\u01A2' | - '\u01A4' | - '\u01A6' | - '\u01A7' | - '\u01A9' | - '\u01AC' | - '\u01AE' | - '\u01AF' | - '\u01B1'..'\u01B3' | - '\u01B5' | - '\u01B7' | - '\u01B8' | - '\u01BC' | - '\u01C4' | - '\u01C7' | - '\u01CA' | - '\u01CD' | - '\u01CF' | - '\u01D1' | - '\u01D3' | - '\u01D5' | - '\u01D7' | - '\u01D9' | - '\u01DB' | - '\u01DE' | - '\u01E0' | - '\u01E2' | - '\u01E4' | - '\u01E6' | - '\u01E8' | - '\u01EA' | - '\u01EC' | - '\u01EE' | - '\u01F1' | - '\u01F4' | - '\u01F6'..'\u01F8' | - '\u01FA' | - '\u01FC' | - '\u01FE' | - '\u0200' | - '\u0202' | - '\u0204' | - '\u0206' | - '\u0208' | - '\u020A' | - '\u020C' | - '\u020E' | - '\u0210' | - '\u0212' | - '\u0214' | - '\u0216' | - '\u0218' | - '\u021A' | - '\u021C' | - '\u021E' | - '\u0220' | - '\u0222' | - '\u0224' | - '\u0226' | - '\u0228' | - '\u022A' | - '\u022C' | - '\u022E' | - '\u0230' | - '\u0232' | - '\u023A' | - '\u023B' | - '\u023D' | - '\u023E' | - '\u0241' | - '\u0243'..'\u0246' | - '\u0248' | - '\u024A' | - '\u024C' | - '\u024E' | - '\u0370' | - '\u0372' | - '\u0376' | - '\u0386' | - '\u0388'..'\u038A' | - '\u038C' | - '\u038E' | - '\u038F' | - '\u0391'..'\u03A1' | - '\u03A3'..'\u03AB' | - '\u03CF' | - '\u03D2'..'\u03D4' | - '\u03D8' | - '\u03DA' | - '\u03DC' | - '\u03DE' | - '\u03E0' | - '\u03E2' | - '\u03E4' | - '\u03E6' | - '\u03E8' | - '\u03EA' | - '\u03EC' | - '\u03EE' | - '\u03F4' | - '\u03F7' | - '\u03F9' | - '\u03FA' | - '\u03FD'..'\u042F' | - '\u0460' | - '\u0462' | - '\u0464' | - '\u0466' | - '\u0468' | - '\u046A' | - '\u046C' | - '\u046E' | - '\u0470' | - '\u0472' | - '\u0474' | - '\u0476' | - '\u0478' | - '\u047A' | - '\u047C' | - '\u047E' | - '\u0480' | - '\u048A' | - '\u048C' | - '\u048E' | - '\u0490' | - '\u0492' | - '\u0494' | - '\u0496' | - '\u0498' | - '\u049A' | - '\u049C' | - '\u049E' | - '\u04A0' | - '\u04A2' | - '\u04A4' | - '\u04A6' | - '\u04A8' | - '\u04AA' | - '\u04AC' | - '\u04AE' | - '\u04B0' | - '\u04B2' | - '\u04B4' | - '\u04B6' | - '\u04B8' | - '\u04BA' | - '\u04BC' | - '\u04BE' | - '\u04C0' | - '\u04C1' | - '\u04C3' | - '\u04C5' | - '\u04C7' | - '\u04C9' | - '\u04CB' | - '\u04CD' | - '\u04D0' | - '\u04D2' | - '\u04D4' | - '\u04D6' | - '\u04D8' | - '\u04DA' | - '\u04DC' | - '\u04DE' | - '\u04E0' | - '\u04E2' | - '\u04E4' | - '\u04E6' | - '\u04E8' | - '\u04EA' | - '\u04EC' | - '\u04EE' | - '\u04F0' | - '\u04F2' | - '\u04F4' | - '\u04F6' | - '\u04F8' | - '\u04FA' | - '\u04FC' | - '\u04FE' | - '\u0500' | - '\u0502' | - '\u0504' | - '\u0506' | - '\u0508' | - '\u050A' | - '\u050C' | - '\u050E' | - '\u0510' | - '\u0512' | - '\u0514' | - '\u0516' | - '\u0518' | - '\u051A' | - '\u051C' | - '\u051E' | - '\u0520' | - '\u0522' | - '\u0524' | - '\u0526' | - '\u0531'..'\u0556' | - '\u10A0'..'\u10C5' | - '\u10C7' | - '\u10CD' | - '\u1E00' | - '\u1E02' | - '\u1E04' | - '\u1E06' | - '\u1E08' | - '\u1E0A' | - '\u1E0C' | - '\u1E0E' | - '\u1E10' | - '\u1E12' | - '\u1E14' | - '\u1E16' | - '\u1E18' | - '\u1E1A' | - '\u1E1C' | - '\u1E1E' | - '\u1E20' | - '\u1E22' | - '\u1E24' | - '\u1E26' | - '\u1E28' | - '\u1E2A' | - '\u1E2C' | - '\u1E2E' | - '\u1E30' | - '\u1E32' | - '\u1E34' | - '\u1E36' | - '\u1E38' | - '\u1E3A' | - '\u1E3C' | - '\u1E3E' | - '\u1E40' | - '\u1E42' | - '\u1E44' | - '\u1E46' | - '\u1E48' | - '\u1E4A' | - '\u1E4C' | - '\u1E4E' | - '\u1E50' | - '\u1E52' | - '\u1E54' | - '\u1E56' | - '\u1E58' | - '\u1E5A' | - '\u1E5C' | - '\u1E5E' | - '\u1E60' | - '\u1E62' | - '\u1E64' | - '\u1E66' | - '\u1E68' | - '\u1E6A' | - '\u1E6C' | - '\u1E6E' | - '\u1E70' | - '\u1E72' | - '\u1E74' | - '\u1E76' | - '\u1E78' | - '\u1E7A' | - '\u1E7C' | - '\u1E7E' | - '\u1E80' | - '\u1E82' | - '\u1E84' | - '\u1E86' | - '\u1E88' | - '\u1E8A' | - '\u1E8C' | - '\u1E8E' | - '\u1E90' | - '\u1E92' | - '\u1E94' | - '\u1E9E' | - '\u1EA0' | - '\u1EA2' | - '\u1EA4' | - '\u1EA6' | - '\u1EA8' | - '\u1EAA' | - '\u1EAC' | - '\u1EAE' | - '\u1EB0' | - '\u1EB2' | - '\u1EB4' | - '\u1EB6' | - '\u1EB8' | - '\u1EBA' | - '\u1EBC' | - '\u1EBE' | - '\u1EC0' | - '\u1EC2' | - '\u1EC4' | - '\u1EC6' | - '\u1EC8' | - '\u1ECA' | - '\u1ECC' | - '\u1ECE' | - '\u1ED0' | - '\u1ED2' | - '\u1ED4' | - '\u1ED6' | - '\u1ED8' | - '\u1EDA' | - '\u1EDC' | - '\u1EDE' | - '\u1EE0' | - '\u1EE2' | - '\u1EE4' | - '\u1EE6' | - '\u1EE8' | - '\u1EEA' | - '\u1EEC' | - '\u1EEE' | - '\u1EF0' | - '\u1EF2' | - '\u1EF4' | - '\u1EF6' | - '\u1EF8' | - '\u1EFA' | - '\u1EFC' | - '\u1EFE' | - '\u1F08'..'\u1F0F' | - '\u1F18'..'\u1F1D' | - '\u1F28'..'\u1F2F' | - '\u1F38'..'\u1F3F' | - '\u1F48'..'\u1F4D' | - '\u1F59' | - '\u1F5B' | - '\u1F5D' | - '\u1F5F' | - '\u1F68'..'\u1F6F' | - '\u1FB8'..'\u1FBB' | - '\u1FC8'..'\u1FCB' | - '\u1FD8'..'\u1FDB' | - '\u1FE8'..'\u1FEC' | - '\u1FF8'..'\u1FFB' | - '\u2102' | - '\u2107' | - '\u210B'..'\u210D' | - '\u2110'..'\u2112' | - '\u2115' | - '\u2119'..'\u211D' | - '\u2124' | - '\u2126' | - '\u2128' | - '\u212A'..'\u212D' | - '\u2130'..'\u2133' | - '\u213E' | - '\u213F' | - '\u2145' | - '\u2183' | - '\u2C00'..'\u2C2E' | - '\u2C60' | - '\u2C62'..'\u2C64' | - '\u2C67' | - '\u2C69' | - '\u2C6B' | - '\u2C6D'..'\u2C70' | - '\u2C72' | - '\u2C75' | - '\u2C7E'..'\u2C80' | - '\u2C82' | - '\u2C84' | - '\u2C86' | - '\u2C88' | - '\u2C8A' | - '\u2C8C' | - '\u2C8E' | - '\u2C90' | - '\u2C92' | - '\u2C94' | - '\u2C96' | - '\u2C98' | - '\u2C9A' | - '\u2C9C' | - '\u2C9E' | - '\u2CA0' | - '\u2CA2' | - '\u2CA4' | - '\u2CA6' | - '\u2CA8' | - '\u2CAA' | - '\u2CAC' | - '\u2CAE' | - '\u2CB0' | - '\u2CB2' | - '\u2CB4' | - '\u2CB6' | - '\u2CB8' | - '\u2CBA' | - '\u2CBC' | - '\u2CBE' | - '\u2CC0' | - '\u2CC2' | - '\u2CC4' | - '\u2CC6' | - '\u2CC8' | - '\u2CCA' | - '\u2CCC' | - '\u2CCE' | - '\u2CD0' | - '\u2CD2' | - '\u2CD4' | - '\u2CD6' | - '\u2CD8' | - '\u2CDA' | - '\u2CDC' | - '\u2CDE' | - '\u2CE0' | - '\u2CE2' | - '\u2CEB' | - '\u2CED' | - '\u2CF2' | - '\uA640' | - '\uA642' | - '\uA644' | - '\uA646' | - '\uA648' | - '\uA64A' | - '\uA64C' | - '\uA64E' | - '\uA650' | - '\uA652' | - '\uA654' | - '\uA656' | - '\uA658' | - '\uA65A' | - '\uA65C' | - '\uA65E' | - '\uA660' | - '\uA662' | - '\uA664' | - '\uA666' | - '\uA668' | - '\uA66A' | - '\uA66C' | - '\uA680' | - '\uA682' | - '\uA684' | - '\uA686' | - '\uA688' | - '\uA68A' | - '\uA68C' | - '\uA68E' | - '\uA690' | - '\uA692' | - '\uA694' | - '\uA696' | - '\uA722' | - '\uA724' | - '\uA726' | - '\uA728' | - '\uA72A' | - '\uA72C' | - '\uA72E' | - '\uA732' | - '\uA734' | - '\uA736' | - '\uA738' | - '\uA73A' | - '\uA73C' | - '\uA73E' | - '\uA740' | - '\uA742' | - '\uA744' | - '\uA746' | - '\uA748' | - '\uA74A' | - '\uA74C' | - '\uA74E' | - '\uA750' | - '\uA752' | - '\uA754' | - '\uA756' | - '\uA758' | - '\uA75A' | - '\uA75C' | - '\uA75E' | - '\uA760' | - '\uA762' | - '\uA764' | - '\uA766' | - '\uA768' | - '\uA76A' | - '\uA76C' | - '\uA76E' | - '\uA779' | - '\uA77B' | - '\uA77D' | - '\uA77E' | - '\uA780' | - '\uA782' | - '\uA784' | - '\uA786' | - '\uA78B' | - '\uA78D' | - '\uA790' | - '\uA792' | - '\uA7A0' | - '\uA7A2' | - '\uA7A4' | - '\uA7A6' | - '\uA7A8' | - '\uA7AA' | - '\uFF21'..'\uFF3A'; - -UNICODE_CLASS_ND: - '\u0030'..'\u0039' | - '\u0660'..'\u0669' | - '\u06F0'..'\u06F9' | - '\u07C0'..'\u07C9' | - '\u0966'..'\u096F' | - '\u09E6'..'\u09EF' | - '\u0A66'..'\u0A6F' | - '\u0AE6'..'\u0AEF' | - '\u0B66'..'\u0B6F' | - '\u0BE6'..'\u0BEF' | - '\u0C66'..'\u0C6F' | - '\u0CE6'..'\u0CEF' | - '\u0D66'..'\u0D6F' | - '\u0E50'..'\u0E59' | - '\u0ED0'..'\u0ED9' | - '\u0F20'..'\u0F29' | - '\u1040'..'\u1049' | - '\u1090'..'\u1099' | - '\u17E0'..'\u17E9' | - '\u1810'..'\u1819' | - '\u1946'..'\u194F' | - '\u19D0'..'\u19D9' | - '\u1A80'..'\u1A89' | - '\u1A90'..'\u1A99' | - '\u1B50'..'\u1B59' | - '\u1BB0'..'\u1BB9' | - '\u1C40'..'\u1C49' | - '\u1C50'..'\u1C59' | - '\uA620'..'\uA629' | - '\uA8D0'..'\uA8D9' | - '\uA900'..'\uA909' | - '\uA9D0'..'\uA9D9' | - '\uAA50'..'\uAA59' | - '\uABF0'..'\uABF9' | - '\uFF10'..'\uFF19'; - -UNICODE_CLASS_NL: - '\u16EE'..'\u16F0' | - '\u2160'..'\u2182' | - '\u2185'..'\u2188' | - '\u3007' | - '\u3021'..'\u3029' | - '\u3038'..'\u303A' | - '\uA6E6'..'\uA6EF'; +options { tokenVocab = UnicodeClasses; } // SECTION: lexicalGeneral 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 new file mode 100644 index 0000000000..537284804c --- /dev/null +++ b/pmd-kotlin/src/main/antlr4/net/sourceforge/pmd/lang/kotlin/ast/UnicodeClasses.g4 @@ -0,0 +1,1649 @@ +/** + * Kotlin lexical grammar in ANTLR4 notation (Unicode classes) + * + * Taken from http://www.antlr3.org/grammar/1345144569663/AntlrUnicode.txt + */ + +lexer grammar UnicodeClasses; + +UNICODE_CLASS_LL: + '\u0061'..'\u007A' | + '\u00B5' | + '\u00DF'..'\u00F6' | + '\u00F8'..'\u00FF' | + '\u0101' | + '\u0103' | + '\u0105' | + '\u0107' | + '\u0109' | + '\u010B' | + '\u010D' | + '\u010F' | + '\u0111' | + '\u0113' | + '\u0115' | + '\u0117' | + '\u0119' | + '\u011B' | + '\u011D' | + '\u011F' | + '\u0121' | + '\u0123' | + '\u0125' | + '\u0127' | + '\u0129' | + '\u012B' | + '\u012D' | + '\u012F' | + '\u0131' | + '\u0133' | + '\u0135' | + '\u0137' | + '\u0138' | + '\u013A' | + '\u013C' | + '\u013E' | + '\u0140' | + '\u0142' | + '\u0144' | + '\u0146' | + '\u0148' | + '\u0149' | + '\u014B' | + '\u014D' | + '\u014F' | + '\u0151' | + '\u0153' | + '\u0155' | + '\u0157' | + '\u0159' | + '\u015B' | + '\u015D' | + '\u015F' | + '\u0161' | + '\u0163' | + '\u0165' | + '\u0167' | + '\u0169' | + '\u016B' | + '\u016D' | + '\u016F' | + '\u0171' | + '\u0173' | + '\u0175' | + '\u0177' | + '\u017A' | + '\u017C' | + '\u017E'..'\u0180' | + '\u0183' | + '\u0185' | + '\u0188' | + '\u018C' | + '\u018D' | + '\u0192' | + '\u0195' | + '\u0199'..'\u019B' | + '\u019E' | + '\u01A1' | + '\u01A3' | + '\u01A5' | + '\u01A8' | + '\u01AA' | + '\u01AB' | + '\u01AD' | + '\u01B0' | + '\u01B4' | + '\u01B6' | + '\u01B9' | + '\u01BA' | + '\u01BD'..'\u01BF' | + '\u01C6' | + '\u01C9' | + '\u01CC' | + '\u01CE' | + '\u01D0' | + '\u01D2' | + '\u01D4' | + '\u01D6' | + '\u01D8' | + '\u01DA' | + '\u01DC' | + '\u01DD' | + '\u01DF' | + '\u01E1' | + '\u01E3' | + '\u01E5' | + '\u01E7' | + '\u01E9' | + '\u01EB' | + '\u01ED' | + '\u01EF' | + '\u01F0' | + '\u01F3' | + '\u01F5' | + '\u01F9' | + '\u01FB' | + '\u01FD' | + '\u01FF' | + '\u0201' | + '\u0203' | + '\u0205' | + '\u0207' | + '\u0209' | + '\u020B' | + '\u020D' | + '\u020F' | + '\u0211' | + '\u0213' | + '\u0215' | + '\u0217' | + '\u0219' | + '\u021B' | + '\u021D' | + '\u021F' | + '\u0221' | + '\u0223' | + '\u0225' | + '\u0227' | + '\u0229' | + '\u022B' | + '\u022D' | + '\u022F' | + '\u0231' | + '\u0233'..'\u0239' | + '\u023C' | + '\u023F' | + '\u0240' | + '\u0242' | + '\u0247' | + '\u0249' | + '\u024B' | + '\u024D' | + '\u024F'..'\u0293' | + '\u0295'..'\u02AF' | + '\u0371' | + '\u0373' | + '\u0377' | + '\u037B'..'\u037D' | + '\u0390' | + '\u03AC'..'\u03CE' | + '\u03D0' | + '\u03D1' | + '\u03D5'..'\u03D7' | + '\u03D9' | + '\u03DB' | + '\u03DD' | + '\u03DF' | + '\u03E1' | + '\u03E3' | + '\u03E5' | + '\u03E7' | + '\u03E9' | + '\u03EB' | + '\u03ED' | + '\u03EF'..'\u03F3' | + '\u03F5' | + '\u03F8' | + '\u03FB' | + '\u03FC' | + '\u0430'..'\u045F' | + '\u0461' | + '\u0463' | + '\u0465' | + '\u0467' | + '\u0469' | + '\u046B' | + '\u046D' | + '\u046F' | + '\u0471' | + '\u0473' | + '\u0475' | + '\u0477' | + '\u0479' | + '\u047B' | + '\u047D' | + '\u047F' | + '\u0481' | + '\u048B' | + '\u048D' | + '\u048F' | + '\u0491' | + '\u0493' | + '\u0495' | + '\u0497' | + '\u0499' | + '\u049B' | + '\u049D' | + '\u049F' | + '\u04A1' | + '\u04A3' | + '\u04A5' | + '\u04A7' | + '\u04A9' | + '\u04AB' | + '\u04AD' | + '\u04AF' | + '\u04B1' | + '\u04B3' | + '\u04B5' | + '\u04B7' | + '\u04B9' | + '\u04BB' | + '\u04BD' | + '\u04BF' | + '\u04C2' | + '\u04C4' | + '\u04C6' | + '\u04C8' | + '\u04CA' | + '\u04CC' | + '\u04CE' | + '\u04CF' | + '\u04D1' | + '\u04D3' | + '\u04D5' | + '\u04D7' | + '\u04D9' | + '\u04DB' | + '\u04DD' | + '\u04DF' | + '\u04E1' | + '\u04E3' | + '\u04E5' | + '\u04E7' | + '\u04E9' | + '\u04EB' | + '\u04ED' | + '\u04EF' | + '\u04F1' | + '\u04F3' | + '\u04F5' | + '\u04F7' | + '\u04F9' | + '\u04FB' | + '\u04FD' | + '\u04FF' | + '\u0501' | + '\u0503' | + '\u0505' | + '\u0507' | + '\u0509' | + '\u050B' | + '\u050D' | + '\u050F' | + '\u0511' | + '\u0513' | + '\u0515' | + '\u0517' | + '\u0519' | + '\u051B' | + '\u051D' | + '\u051F' | + '\u0521' | + '\u0523' | + '\u0525' | + '\u0527' | + '\u0561'..'\u0587' | + '\u1D00'..'\u1D2B' | + '\u1D6B'..'\u1D77' | + '\u1D79'..'\u1D9A' | + '\u1E01' | + '\u1E03' | + '\u1E05' | + '\u1E07' | + '\u1E09' | + '\u1E0B' | + '\u1E0D' | + '\u1E0F' | + '\u1E11' | + '\u1E13' | + '\u1E15' | + '\u1E17' | + '\u1E19' | + '\u1E1B' | + '\u1E1D' | + '\u1E1F' | + '\u1E21' | + '\u1E23' | + '\u1E25' | + '\u1E27' | + '\u1E29' | + '\u1E2B' | + '\u1E2D' | + '\u1E2F' | + '\u1E31' | + '\u1E33' | + '\u1E35' | + '\u1E37' | + '\u1E39' | + '\u1E3B' | + '\u1E3D' | + '\u1E3F' | + '\u1E41' | + '\u1E43' | + '\u1E45' | + '\u1E47' | + '\u1E49' | + '\u1E4B' | + '\u1E4D' | + '\u1E4F' | + '\u1E51' | + '\u1E53' | + '\u1E55' | + '\u1E57' | + '\u1E59' | + '\u1E5B' | + '\u1E5D' | + '\u1E5F' | + '\u1E61' | + '\u1E63' | + '\u1E65' | + '\u1E67' | + '\u1E69' | + '\u1E6B' | + '\u1E6D' | + '\u1E6F' | + '\u1E71' | + '\u1E73' | + '\u1E75' | + '\u1E77' | + '\u1E79' | + '\u1E7B' | + '\u1E7D' | + '\u1E7F' | + '\u1E81' | + '\u1E83' | + '\u1E85' | + '\u1E87' | + '\u1E89' | + '\u1E8B' | + '\u1E8D' | + '\u1E8F' | + '\u1E91' | + '\u1E93' | + '\u1E95'..'\u1E9D' | + '\u1E9F' | + '\u1EA1' | + '\u1EA3' | + '\u1EA5' | + '\u1EA7' | + '\u1EA9' | + '\u1EAB' | + '\u1EAD' | + '\u1EAF' | + '\u1EB1' | + '\u1EB3' | + '\u1EB5' | + '\u1EB7' | + '\u1EB9' | + '\u1EBB' | + '\u1EBD' | + '\u1EBF' | + '\u1EC1' | + '\u1EC3' | + '\u1EC5' | + '\u1EC7' | + '\u1EC9' | + '\u1ECB' | + '\u1ECD' | + '\u1ECF' | + '\u1ED1' | + '\u1ED3' | + '\u1ED5' | + '\u1ED7' | + '\u1ED9' | + '\u1EDB' | + '\u1EDD' | + '\u1EDF' | + '\u1EE1' | + '\u1EE3' | + '\u1EE5' | + '\u1EE7' | + '\u1EE9' | + '\u1EEB' | + '\u1EED' | + '\u1EEF' | + '\u1EF1' | + '\u1EF3' | + '\u1EF5' | + '\u1EF7' | + '\u1EF9' | + '\u1EFB' | + '\u1EFD' | + '\u1EFF'..'\u1F07' | + '\u1F10'..'\u1F15' | + '\u1F20'..'\u1F27' | + '\u1F30'..'\u1F37' | + '\u1F40'..'\u1F45' | + '\u1F50'..'\u1F57' | + '\u1F60'..'\u1F67' | + '\u1F70'..'\u1F7D' | + '\u1F80'..'\u1F87' | + '\u1F90'..'\u1F97' | + '\u1FA0'..'\u1FA7' | + '\u1FB0'..'\u1FB4' | + '\u1FB6' | + '\u1FB7' | + '\u1FBE' | + '\u1FC2'..'\u1FC4' | + '\u1FC6' | + '\u1FC7' | + '\u1FD0'..'\u1FD3' | + '\u1FD6' | + '\u1FD7' | + '\u1FE0'..'\u1FE7' | + '\u1FF2'..'\u1FF4' | + '\u1FF6' | + '\u1FF7' | + '\u210A' | + '\u210E' | + '\u210F' | + '\u2113' | + '\u212F' | + '\u2134' | + '\u2139' | + '\u213C' | + '\u213D' | + '\u2146'..'\u2149' | + '\u214E' | + '\u2184' | + '\u2C30'..'\u2C5E' | + '\u2C61' | + '\u2C65' | + '\u2C66' | + '\u2C68' | + '\u2C6A' | + '\u2C6C' | + '\u2C71' | + '\u2C73' | + '\u2C74' | + '\u2C76'..'\u2C7B' | + '\u2C81' | + '\u2C83' | + '\u2C85' | + '\u2C87' | + '\u2C89' | + '\u2C8B' | + '\u2C8D' | + '\u2C8F' | + '\u2C91' | + '\u2C93' | + '\u2C95' | + '\u2C97' | + '\u2C99' | + '\u2C9B' | + '\u2C9D' | + '\u2C9F' | + '\u2CA1' | + '\u2CA3' | + '\u2CA5' | + '\u2CA7' | + '\u2CA9' | + '\u2CAB' | + '\u2CAD' | + '\u2CAF' | + '\u2CB1' | + '\u2CB3' | + '\u2CB5' | + '\u2CB7' | + '\u2CB9' | + '\u2CBB' | + '\u2CBD' | + '\u2CBF' | + '\u2CC1' | + '\u2CC3' | + '\u2CC5' | + '\u2CC7' | + '\u2CC9' | + '\u2CCB' | + '\u2CCD' | + '\u2CCF' | + '\u2CD1' | + '\u2CD3' | + '\u2CD5' | + '\u2CD7' | + '\u2CD9' | + '\u2CDB' | + '\u2CDD' | + '\u2CDF' | + '\u2CE1' | + '\u2CE3' | + '\u2CE4' | + '\u2CEC' | + '\u2CEE' | + '\u2CF3' | + '\u2D00'..'\u2D25' | + '\u2D27' | + '\u2D2D' | + '\uA641' | + '\uA643' | + '\uA645' | + '\uA647' | + '\uA649' | + '\uA64B' | + '\uA64D' | + '\uA64F' | + '\uA651' | + '\uA653' | + '\uA655' | + '\uA657' | + '\uA659' | + '\uA65B' | + '\uA65D' | + '\uA65F' | + '\uA661' | + '\uA663' | + '\uA665' | + '\uA667' | + '\uA669' | + '\uA66B' | + '\uA66D' | + '\uA681' | + '\uA683' | + '\uA685' | + '\uA687' | + '\uA689' | + '\uA68B' | + '\uA68D' | + '\uA68F' | + '\uA691' | + '\uA693' | + '\uA695' | + '\uA697' | + '\uA723' | + '\uA725' | + '\uA727' | + '\uA729' | + '\uA72B' | + '\uA72D' | + '\uA72F'..'\uA731' | + '\uA733' | + '\uA735' | + '\uA737' | + '\uA739' | + '\uA73B' | + '\uA73D' | + '\uA73F' | + '\uA741' | + '\uA743' | + '\uA745' | + '\uA747' | + '\uA749' | + '\uA74B' | + '\uA74D' | + '\uA74F' | + '\uA751' | + '\uA753' | + '\uA755' | + '\uA757' | + '\uA759' | + '\uA75B' | + '\uA75D' | + '\uA75F' | + '\uA761' | + '\uA763' | + '\uA765' | + '\uA767' | + '\uA769' | + '\uA76B' | + '\uA76D' | + '\uA76F' | + '\uA771'..'\uA778' | + '\uA77A' | + '\uA77C' | + '\uA77F' | + '\uA781' | + '\uA783' | + '\uA785' | + '\uA787' | + '\uA78C' | + '\uA78E' | + '\uA791' | + '\uA793' | + '\uA7A1' | + '\uA7A3' | + '\uA7A5' | + '\uA7A7' | + '\uA7A9' | + '\uA7FA' | + '\uFB00'..'\uFB06' | + '\uFB13'..'\uFB17' | + '\uFF41'..'\uFF5A'; + +UNICODE_CLASS_LM: + '\u02B0'..'\u02C1' | + '\u02C6'..'\u02D1' | + '\u02E0'..'\u02E4' | + '\u02EC' | + '\u02EE' | + '\u0374' | + '\u037A' | + '\u0559' | + '\u0640' | + '\u06E5' | + '\u06E6' | + '\u07F4' | + '\u07F5' | + '\u07FA' | + '\u081A' | + '\u0824' | + '\u0828' | + '\u0971' | + '\u0E46' | + '\u0EC6' | + '\u10FC' | + '\u17D7' | + '\u1843' | + '\u1AA7' | + '\u1C78'..'\u1C7D' | + '\u1D2C'..'\u1D6A' | + '\u1D78' | + '\u1D9B'..'\u1DBF' | + '\u2071' | + '\u207F' | + '\u2090'..'\u209C' | + '\u2C7C' | + '\u2C7D' | + '\u2D6F' | + '\u2E2F' | + '\u3005' | + '\u3031'..'\u3035' | + '\u303B' | + '\u309D' | + '\u309E' | + '\u30FC'..'\u30FE' | + '\uA015' | + '\uA4F8'..'\uA4FD' | + '\uA60C' | + '\uA67F' | + '\uA717'..'\uA71F' | + '\uA770' | + '\uA788' | + '\uA7F8' | + '\uA7F9' | + '\uA9CF' | + '\uAA70' | + '\uAADD' | + '\uAAF3' | + '\uAAF4' | + '\uFF70' | + '\uFF9E' | + '\uFF9F'; + +UNICODE_CLASS_LO: + '\u00AA' | + '\u00BA' | + '\u01BB' | + '\u01C0'..'\u01C3' | + '\u0294' | + '\u05D0'..'\u05EA' | + '\u05F0'..'\u05F2' | + '\u0620'..'\u063F' | + '\u0641'..'\u064A' | + '\u066E' | + '\u066F' | + '\u0671'..'\u06D3' | + '\u06D5' | + '\u06EE' | + '\u06EF' | + '\u06FA'..'\u06FC' | + '\u06FF' | + '\u0710' | + '\u0712'..'\u072F' | + '\u074D'..'\u07A5' | + '\u07B1' | + '\u07CA'..'\u07EA' | + '\u0800'..'\u0815' | + '\u0840'..'\u0858' | + '\u08A0' | + '\u08A2'..'\u08AC' | + '\u0904'..'\u0939' | + '\u093D' | + '\u0950' | + '\u0958'..'\u0961' | + '\u0972'..'\u0977' | + '\u0979'..'\u097F' | + '\u0985'..'\u098C' | + '\u098F' | + '\u0990' | + '\u0993'..'\u09A8' | + '\u09AA'..'\u09B0' | + '\u09B2' | + '\u09B6'..'\u09B9' | + '\u09BD' | + '\u09CE' | + '\u09DC' | + '\u09DD' | + '\u09DF'..'\u09E1' | + '\u09F0' | + '\u09F1' | + '\u0A05'..'\u0A0A' | + '\u0A0F' | + '\u0A10' | + '\u0A13'..'\u0A28' | + '\u0A2A'..'\u0A30' | + '\u0A32' | + '\u0A33' | + '\u0A35' | + '\u0A36' | + '\u0A38' | + '\u0A39' | + '\u0A59'..'\u0A5C' | + '\u0A5E' | + '\u0A72'..'\u0A74' | + '\u0A85'..'\u0A8D' | + '\u0A8F'..'\u0A91' | + '\u0A93'..'\u0AA8' | + '\u0AAA'..'\u0AB0' | + '\u0AB2' | + '\u0AB3' | + '\u0AB5'..'\u0AB9' | + '\u0ABD' | + '\u0AD0' | + '\u0AE0' | + '\u0AE1' | + '\u0B05'..'\u0B0C' | + '\u0B0F' | + '\u0B10' | + '\u0B13'..'\u0B28' | + '\u0B2A'..'\u0B30' | + '\u0B32' | + '\u0B33' | + '\u0B35'..'\u0B39' | + '\u0B3D' | + '\u0B5C' | + '\u0B5D' | + '\u0B5F'..'\u0B61' | + '\u0B71' | + '\u0B83' | + '\u0B85'..'\u0B8A' | + '\u0B8E'..'\u0B90' | + '\u0B92'..'\u0B95' | + '\u0B99' | + '\u0B9A' | + '\u0B9C' | + '\u0B9E' | + '\u0B9F' | + '\u0BA3' | + '\u0BA4' | + '\u0BA8'..'\u0BAA' | + '\u0BAE'..'\u0BB9' | + '\u0BD0' | + '\u0C05'..'\u0C0C' | + '\u0C0E'..'\u0C10' | + '\u0C12'..'\u0C28' | + '\u0C2A'..'\u0C33' | + '\u0C35'..'\u0C39' | + '\u0C3D' | + '\u0C58' | + '\u0C59' | + '\u0C60' | + '\u0C61' | + '\u0C85'..'\u0C8C' | + '\u0C8E'..'\u0C90' | + '\u0C92'..'\u0CA8' | + '\u0CAA'..'\u0CB3' | + '\u0CB5'..'\u0CB9' | + '\u0CBD' | + '\u0CDE' | + '\u0CE0' | + '\u0CE1' | + '\u0CF1' | + '\u0CF2' | + '\u0D05'..'\u0D0C' | + '\u0D0E'..'\u0D10' | + '\u0D12'..'\u0D3A' | + '\u0D3D' | + '\u0D4E' | + '\u0D60' | + '\u0D61' | + '\u0D7A'..'\u0D7F' | + '\u0D85'..'\u0D96' | + '\u0D9A'..'\u0DB1' | + '\u0DB3'..'\u0DBB' | + '\u0DBD' | + '\u0DC0'..'\u0DC6' | + '\u0E01'..'\u0E30' | + '\u0E32' | + '\u0E33' | + '\u0E40'..'\u0E45' | + '\u0E81' | + '\u0E82' | + '\u0E84' | + '\u0E87' | + '\u0E88' | + '\u0E8A' | + '\u0E8D' | + '\u0E94'..'\u0E97' | + '\u0E99'..'\u0E9F' | + '\u0EA1'..'\u0EA3' | + '\u0EA5' | + '\u0EA7' | + '\u0EAA' | + '\u0EAB' | + '\u0EAD'..'\u0EB0' | + '\u0EB2' | + '\u0EB3' | + '\u0EBD' | + '\u0EC0'..'\u0EC4' | + '\u0EDC'..'\u0EDF' | + '\u0F00' | + '\u0F40'..'\u0F47' | + '\u0F49'..'\u0F6C' | + '\u0F88'..'\u0F8C' | + '\u1000'..'\u102A' | + '\u103F' | + '\u1050'..'\u1055' | + '\u105A'..'\u105D' | + '\u1061' | + '\u1065' | + '\u1066' | + '\u106E'..'\u1070' | + '\u1075'..'\u1081' | + '\u108E' | + '\u10D0'..'\u10FA' | + '\u10FD'..'\u1248' | + '\u124A'..'\u124D' | + '\u1250'..'\u1256' | + '\u1258' | + '\u125A'..'\u125D' | + '\u1260'..'\u1288' | + '\u128A'..'\u128D' | + '\u1290'..'\u12B0' | + '\u12B2'..'\u12B5' | + '\u12B8'..'\u12BE' | + '\u12C0' | + '\u12C2'..'\u12C5' | + '\u12C8'..'\u12D6' | + '\u12D8'..'\u1310' | + '\u1312'..'\u1315' | + '\u1318'..'\u135A' | + '\u1380'..'\u138F' | + '\u13A0'..'\u13F4' | + '\u1401'..'\u166C' | + '\u166F'..'\u167F' | + '\u1681'..'\u169A' | + '\u16A0'..'\u16EA' | + '\u1700'..'\u170C' | + '\u170E'..'\u1711' | + '\u1720'..'\u1731' | + '\u1740'..'\u1751' | + '\u1760'..'\u176C' | + '\u176E'..'\u1770' | + '\u1780'..'\u17B3' | + '\u17DC' | + '\u1820'..'\u1842' | + '\u1844'..'\u1877' | + '\u1880'..'\u18A8' | + '\u18AA' | + '\u18B0'..'\u18F5' | + '\u1900'..'\u191C' | + '\u1950'..'\u196D' | + '\u1970'..'\u1974' | + '\u1980'..'\u19AB' | + '\u19C1'..'\u19C7' | + '\u1A00'..'\u1A16' | + '\u1A20'..'\u1A54' | + '\u1B05'..'\u1B33' | + '\u1B45'..'\u1B4B' | + '\u1B83'..'\u1BA0' | + '\u1BAE' | + '\u1BAF' | + '\u1BBA'..'\u1BE5' | + '\u1C00'..'\u1C23' | + '\u1C4D'..'\u1C4F' | + '\u1C5A'..'\u1C77' | + '\u1CE9'..'\u1CEC' | + '\u1CEE'..'\u1CF1' | + '\u1CF5' | + '\u1CF6' | + '\u2135'..'\u2138' | + '\u2D30'..'\u2D67' | + '\u2D80'..'\u2D96' | + '\u2DA0'..'\u2DA6' | + '\u2DA8'..'\u2DAE' | + '\u2DB0'..'\u2DB6' | + '\u2DB8'..'\u2DBE' | + '\u2DC0'..'\u2DC6' | + '\u2DC8'..'\u2DCE' | + '\u2DD0'..'\u2DD6' | + '\u2DD8'..'\u2DDE' | + '\u3006' | + '\u303C' | + '\u3041'..'\u3096' | + '\u309F' | + '\u30A1'..'\u30FA' | + '\u30FF' | + '\u3105'..'\u312D' | + '\u3131'..'\u318E' | + '\u31A0'..'\u31BA' | + '\u31F0'..'\u31FF' | + '\u3400' | + '\u4DB5' | + '\u4E00' | + '\u9FCC' | + '\uA000'..'\uA014' | + '\uA016'..'\uA48C' | + '\uA4D0'..'\uA4F7' | + '\uA500'..'\uA60B' | + '\uA610'..'\uA61F' | + '\uA62A' | + '\uA62B' | + '\uA66E' | + '\uA6A0'..'\uA6E5' | + '\uA7FB'..'\uA801' | + '\uA803'..'\uA805' | + '\uA807'..'\uA80A' | + '\uA80C'..'\uA822' | + '\uA840'..'\uA873' | + '\uA882'..'\uA8B3' | + '\uA8F2'..'\uA8F7' | + '\uA8FB' | + '\uA90A'..'\uA925' | + '\uA930'..'\uA946' | + '\uA960'..'\uA97C' | + '\uA984'..'\uA9B2' | + '\uAA00'..'\uAA28' | + '\uAA40'..'\uAA42' | + '\uAA44'..'\uAA4B' | + '\uAA60'..'\uAA6F' | + '\uAA71'..'\uAA76' | + '\uAA7A' | + '\uAA80'..'\uAAAF' | + '\uAAB1' | + '\uAAB5' | + '\uAAB6' | + '\uAAB9'..'\uAABD' | + '\uAAC0' | + '\uAAC2' | + '\uAADB' | + '\uAADC' | + '\uAAE0'..'\uAAEA' | + '\uAAF2' | + '\uAB01'..'\uAB06' | + '\uAB09'..'\uAB0E' | + '\uAB11'..'\uAB16' | + '\uAB20'..'\uAB26' | + '\uAB28'..'\uAB2E' | + '\uABC0'..'\uABE2' | + '\uAC00' | + '\uD7A3' | + '\uD7B0'..'\uD7C6' | + '\uD7CB'..'\uD7FB' | + '\uF900'..'\uFA6D' | + '\uFA70'..'\uFAD9' | + '\uFB1D' | + '\uFB1F'..'\uFB28' | + '\uFB2A'..'\uFB36' | + '\uFB38'..'\uFB3C' | + '\uFB3E' | + '\uFB40' | + '\uFB41' | + '\uFB43' | + '\uFB44' | + '\uFB46'..'\uFBB1' | + '\uFBD3'..'\uFD3D' | + '\uFD50'..'\uFD8F' | + '\uFD92'..'\uFDC7' | + '\uFDF0'..'\uFDFB' | + '\uFE70'..'\uFE74' | + '\uFE76'..'\uFEFC' | + '\uFF66'..'\uFF6F' | + '\uFF71'..'\uFF9D' | + '\uFFA0'..'\uFFBE' | + '\uFFC2'..'\uFFC7' | + '\uFFCA'..'\uFFCF' | + '\uFFD2'..'\uFFD7' | + '\uFFDA'..'\uFFDC'; + +UNICODE_CLASS_LT: + '\u01C5' | + '\u01C8' | + '\u01CB' | + '\u01F2' | + '\u1F88'..'\u1F8F' | + '\u1F98'..'\u1F9F' | + '\u1FA8'..'\u1FAF' | + '\u1FBC' | + '\u1FCC' | + '\u1FFC'; + +UNICODE_CLASS_LU: + '\u0041'..'\u005A' | + '\u00C0'..'\u00D6' | + '\u00D8'..'\u00DE' | + '\u0100' | + '\u0102' | + '\u0104' | + '\u0106' | + '\u0108' | + '\u010A' | + '\u010C' | + '\u010E' | + '\u0110' | + '\u0112' | + '\u0114' | + '\u0116' | + '\u0118' | + '\u011A' | + '\u011C' | + '\u011E' | + '\u0120' | + '\u0122' | + '\u0124' | + '\u0126' | + '\u0128' | + '\u012A' | + '\u012C' | + '\u012E' | + '\u0130' | + '\u0132' | + '\u0134' | + '\u0136' | + '\u0139' | + '\u013B' | + '\u013D' | + '\u013F' | + '\u0141' | + '\u0143' | + '\u0145' | + '\u0147' | + '\u014A' | + '\u014C' | + '\u014E' | + '\u0150' | + '\u0152' | + '\u0154' | + '\u0156' | + '\u0158' | + '\u015A' | + '\u015C' | + '\u015E' | + '\u0160' | + '\u0162' | + '\u0164' | + '\u0166' | + '\u0168' | + '\u016A' | + '\u016C' | + '\u016E' | + '\u0170' | + '\u0172' | + '\u0174' | + '\u0176' | + '\u0178' | + '\u0179' | + '\u017B' | + '\u017D' | + '\u0181' | + '\u0182' | + '\u0184' | + '\u0186' | + '\u0187' | + '\u0189'..'\u018B' | + '\u018E'..'\u0191' | + '\u0193' | + '\u0194' | + '\u0196'..'\u0198' | + '\u019C' | + '\u019D' | + '\u019F' | + '\u01A0' | + '\u01A2' | + '\u01A4' | + '\u01A6' | + '\u01A7' | + '\u01A9' | + '\u01AC' | + '\u01AE' | + '\u01AF' | + '\u01B1'..'\u01B3' | + '\u01B5' | + '\u01B7' | + '\u01B8' | + '\u01BC' | + '\u01C4' | + '\u01C7' | + '\u01CA' | + '\u01CD' | + '\u01CF' | + '\u01D1' | + '\u01D3' | + '\u01D5' | + '\u01D7' | + '\u01D9' | + '\u01DB' | + '\u01DE' | + '\u01E0' | + '\u01E2' | + '\u01E4' | + '\u01E6' | + '\u01E8' | + '\u01EA' | + '\u01EC' | + '\u01EE' | + '\u01F1' | + '\u01F4' | + '\u01F6'..'\u01F8' | + '\u01FA' | + '\u01FC' | + '\u01FE' | + '\u0200' | + '\u0202' | + '\u0204' | + '\u0206' | + '\u0208' | + '\u020A' | + '\u020C' | + '\u020E' | + '\u0210' | + '\u0212' | + '\u0214' | + '\u0216' | + '\u0218' | + '\u021A' | + '\u021C' | + '\u021E' | + '\u0220' | + '\u0222' | + '\u0224' | + '\u0226' | + '\u0228' | + '\u022A' | + '\u022C' | + '\u022E' | + '\u0230' | + '\u0232' | + '\u023A' | + '\u023B' | + '\u023D' | + '\u023E' | + '\u0241' | + '\u0243'..'\u0246' | + '\u0248' | + '\u024A' | + '\u024C' | + '\u024E' | + '\u0370' | + '\u0372' | + '\u0376' | + '\u0386' | + '\u0388'..'\u038A' | + '\u038C' | + '\u038E' | + '\u038F' | + '\u0391'..'\u03A1' | + '\u03A3'..'\u03AB' | + '\u03CF' | + '\u03D2'..'\u03D4' | + '\u03D8' | + '\u03DA' | + '\u03DC' | + '\u03DE' | + '\u03E0' | + '\u03E2' | + '\u03E4' | + '\u03E6' | + '\u03E8' | + '\u03EA' | + '\u03EC' | + '\u03EE' | + '\u03F4' | + '\u03F7' | + '\u03F9' | + '\u03FA' | + '\u03FD'..'\u042F' | + '\u0460' | + '\u0462' | + '\u0464' | + '\u0466' | + '\u0468' | + '\u046A' | + '\u046C' | + '\u046E' | + '\u0470' | + '\u0472' | + '\u0474' | + '\u0476' | + '\u0478' | + '\u047A' | + '\u047C' | + '\u047E' | + '\u0480' | + '\u048A' | + '\u048C' | + '\u048E' | + '\u0490' | + '\u0492' | + '\u0494' | + '\u0496' | + '\u0498' | + '\u049A' | + '\u049C' | + '\u049E' | + '\u04A0' | + '\u04A2' | + '\u04A4' | + '\u04A6' | + '\u04A8' | + '\u04AA' | + '\u04AC' | + '\u04AE' | + '\u04B0' | + '\u04B2' | + '\u04B4' | + '\u04B6' | + '\u04B8' | + '\u04BA' | + '\u04BC' | + '\u04BE' | + '\u04C0' | + '\u04C1' | + '\u04C3' | + '\u04C5' | + '\u04C7' | + '\u04C9' | + '\u04CB' | + '\u04CD' | + '\u04D0' | + '\u04D2' | + '\u04D4' | + '\u04D6' | + '\u04D8' | + '\u04DA' | + '\u04DC' | + '\u04DE' | + '\u04E0' | + '\u04E2' | + '\u04E4' | + '\u04E6' | + '\u04E8' | + '\u04EA' | + '\u04EC' | + '\u04EE' | + '\u04F0' | + '\u04F2' | + '\u04F4' | + '\u04F6' | + '\u04F8' | + '\u04FA' | + '\u04FC' | + '\u04FE' | + '\u0500' | + '\u0502' | + '\u0504' | + '\u0506' | + '\u0508' | + '\u050A' | + '\u050C' | + '\u050E' | + '\u0510' | + '\u0512' | + '\u0514' | + '\u0516' | + '\u0518' | + '\u051A' | + '\u051C' | + '\u051E' | + '\u0520' | + '\u0522' | + '\u0524' | + '\u0526' | + '\u0531'..'\u0556' | + '\u10A0'..'\u10C5' | + '\u10C7' | + '\u10CD' | + '\u1E00' | + '\u1E02' | + '\u1E04' | + '\u1E06' | + '\u1E08' | + '\u1E0A' | + '\u1E0C' | + '\u1E0E' | + '\u1E10' | + '\u1E12' | + '\u1E14' | + '\u1E16' | + '\u1E18' | + '\u1E1A' | + '\u1E1C' | + '\u1E1E' | + '\u1E20' | + '\u1E22' | + '\u1E24' | + '\u1E26' | + '\u1E28' | + '\u1E2A' | + '\u1E2C' | + '\u1E2E' | + '\u1E30' | + '\u1E32' | + '\u1E34' | + '\u1E36' | + '\u1E38' | + '\u1E3A' | + '\u1E3C' | + '\u1E3E' | + '\u1E40' | + '\u1E42' | + '\u1E44' | + '\u1E46' | + '\u1E48' | + '\u1E4A' | + '\u1E4C' | + '\u1E4E' | + '\u1E50' | + '\u1E52' | + '\u1E54' | + '\u1E56' | + '\u1E58' | + '\u1E5A' | + '\u1E5C' | + '\u1E5E' | + '\u1E60' | + '\u1E62' | + '\u1E64' | + '\u1E66' | + '\u1E68' | + '\u1E6A' | + '\u1E6C' | + '\u1E6E' | + '\u1E70' | + '\u1E72' | + '\u1E74' | + '\u1E76' | + '\u1E78' | + '\u1E7A' | + '\u1E7C' | + '\u1E7E' | + '\u1E80' | + '\u1E82' | + '\u1E84' | + '\u1E86' | + '\u1E88' | + '\u1E8A' | + '\u1E8C' | + '\u1E8E' | + '\u1E90' | + '\u1E92' | + '\u1E94' | + '\u1E9E' | + '\u1EA0' | + '\u1EA2' | + '\u1EA4' | + '\u1EA6' | + '\u1EA8' | + '\u1EAA' | + '\u1EAC' | + '\u1EAE' | + '\u1EB0' | + '\u1EB2' | + '\u1EB4' | + '\u1EB6' | + '\u1EB8' | + '\u1EBA' | + '\u1EBC' | + '\u1EBE' | + '\u1EC0' | + '\u1EC2' | + '\u1EC4' | + '\u1EC6' | + '\u1EC8' | + '\u1ECA' | + '\u1ECC' | + '\u1ECE' | + '\u1ED0' | + '\u1ED2' | + '\u1ED4' | + '\u1ED6' | + '\u1ED8' | + '\u1EDA' | + '\u1EDC' | + '\u1EDE' | + '\u1EE0' | + '\u1EE2' | + '\u1EE4' | + '\u1EE6' | + '\u1EE8' | + '\u1EEA' | + '\u1EEC' | + '\u1EEE' | + '\u1EF0' | + '\u1EF2' | + '\u1EF4' | + '\u1EF6' | + '\u1EF8' | + '\u1EFA' | + '\u1EFC' | + '\u1EFE' | + '\u1F08'..'\u1F0F' | + '\u1F18'..'\u1F1D' | + '\u1F28'..'\u1F2F' | + '\u1F38'..'\u1F3F' | + '\u1F48'..'\u1F4D' | + '\u1F59' | + '\u1F5B' | + '\u1F5D' | + '\u1F5F' | + '\u1F68'..'\u1F6F' | + '\u1FB8'..'\u1FBB' | + '\u1FC8'..'\u1FCB' | + '\u1FD8'..'\u1FDB' | + '\u1FE8'..'\u1FEC' | + '\u1FF8'..'\u1FFB' | + '\u2102' | + '\u2107' | + '\u210B'..'\u210D' | + '\u2110'..'\u2112' | + '\u2115' | + '\u2119'..'\u211D' | + '\u2124' | + '\u2126' | + '\u2128' | + '\u212A'..'\u212D' | + '\u2130'..'\u2133' | + '\u213E' | + '\u213F' | + '\u2145' | + '\u2183' | + '\u2C00'..'\u2C2E' | + '\u2C60' | + '\u2C62'..'\u2C64' | + '\u2C67' | + '\u2C69' | + '\u2C6B' | + '\u2C6D'..'\u2C70' | + '\u2C72' | + '\u2C75' | + '\u2C7E'..'\u2C80' | + '\u2C82' | + '\u2C84' | + '\u2C86' | + '\u2C88' | + '\u2C8A' | + '\u2C8C' | + '\u2C8E' | + '\u2C90' | + '\u2C92' | + '\u2C94' | + '\u2C96' | + '\u2C98' | + '\u2C9A' | + '\u2C9C' | + '\u2C9E' | + '\u2CA0' | + '\u2CA2' | + '\u2CA4' | + '\u2CA6' | + '\u2CA8' | + '\u2CAA' | + '\u2CAC' | + '\u2CAE' | + '\u2CB0' | + '\u2CB2' | + '\u2CB4' | + '\u2CB6' | + '\u2CB8' | + '\u2CBA' | + '\u2CBC' | + '\u2CBE' | + '\u2CC0' | + '\u2CC2' | + '\u2CC4' | + '\u2CC6' | + '\u2CC8' | + '\u2CCA' | + '\u2CCC' | + '\u2CCE' | + '\u2CD0' | + '\u2CD2' | + '\u2CD4' | + '\u2CD6' | + '\u2CD8' | + '\u2CDA' | + '\u2CDC' | + '\u2CDE' | + '\u2CE0' | + '\u2CE2' | + '\u2CEB' | + '\u2CED' | + '\u2CF2' | + '\uA640' | + '\uA642' | + '\uA644' | + '\uA646' | + '\uA648' | + '\uA64A' | + '\uA64C' | + '\uA64E' | + '\uA650' | + '\uA652' | + '\uA654' | + '\uA656' | + '\uA658' | + '\uA65A' | + '\uA65C' | + '\uA65E' | + '\uA660' | + '\uA662' | + '\uA664' | + '\uA666' | + '\uA668' | + '\uA66A' | + '\uA66C' | + '\uA680' | + '\uA682' | + '\uA684' | + '\uA686' | + '\uA688' | + '\uA68A' | + '\uA68C' | + '\uA68E' | + '\uA690' | + '\uA692' | + '\uA694' | + '\uA696' | + '\uA722' | + '\uA724' | + '\uA726' | + '\uA728' | + '\uA72A' | + '\uA72C' | + '\uA72E' | + '\uA732' | + '\uA734' | + '\uA736' | + '\uA738' | + '\uA73A' | + '\uA73C' | + '\uA73E' | + '\uA740' | + '\uA742' | + '\uA744' | + '\uA746' | + '\uA748' | + '\uA74A' | + '\uA74C' | + '\uA74E' | + '\uA750' | + '\uA752' | + '\uA754' | + '\uA756' | + '\uA758' | + '\uA75A' | + '\uA75C' | + '\uA75E' | + '\uA760' | + '\uA762' | + '\uA764' | + '\uA766' | + '\uA768' | + '\uA76A' | + '\uA76C' | + '\uA76E' | + '\uA779' | + '\uA77B' | + '\uA77D' | + '\uA77E' | + '\uA780' | + '\uA782' | + '\uA784' | + '\uA786' | + '\uA78B' | + '\uA78D' | + '\uA790' | + '\uA792' | + '\uA7A0' | + '\uA7A2' | + '\uA7A4' | + '\uA7A6' | + '\uA7A8' | + '\uA7AA' | + '\uFF21'..'\uFF3A'; + +UNICODE_CLASS_ND: + '\u0030'..'\u0039' | + '\u0660'..'\u0669' | + '\u06F0'..'\u06F9' | + '\u07C0'..'\u07C9' | + '\u0966'..'\u096F' | + '\u09E6'..'\u09EF' | + '\u0A66'..'\u0A6F' | + '\u0AE6'..'\u0AEF' | + '\u0B66'..'\u0B6F' | + '\u0BE6'..'\u0BEF' | + '\u0C66'..'\u0C6F' | + '\u0CE6'..'\u0CEF' | + '\u0D66'..'\u0D6F' | + '\u0E50'..'\u0E59' | + '\u0ED0'..'\u0ED9' | + '\u0F20'..'\u0F29' | + '\u1040'..'\u1049' | + '\u1090'..'\u1099' | + '\u17E0'..'\u17E9' | + '\u1810'..'\u1819' | + '\u1946'..'\u194F' | + '\u19D0'..'\u19D9' | + '\u1A80'..'\u1A89' | + '\u1A90'..'\u1A99' | + '\u1B50'..'\u1B59' | + '\u1BB0'..'\u1BB9' | + '\u1C40'..'\u1C49' | + '\u1C50'..'\u1C59' | + '\uA620'..'\uA629' | + '\uA8D0'..'\uA8D9' | + '\uA900'..'\uA909' | + '\uA9D0'..'\uA9D9' | + '\uAA50'..'\uAA59' | + '\uABF0'..'\uABF9' | + '\uFF10'..'\uFF19'; + +UNICODE_CLASS_NL: + '\u16EE'..'\u16F0' | + '\u2160'..'\u2182' | + '\u2185'..'\u2188' | + '\u3007' | + '\u3021'..'\u3029' | + '\u3038'..'\u303A' | + '\uA6E6'..'\uA6EF'; \ No newline at end of file diff --git a/pom.xml b/pom.xml index 1ad831fb5e..c2739dcf74 100644 --- a/pom.xml +++ b/pom.xml @@ -97,7 +97,7 @@ 3.14.0 1.10.11 3.2.0 - 4.8 + 4.9.1 UTF-8 UTF-8 @@ -136,6 +136,7 @@ ${project.build.sourceEncoding} true true + src/main/antlr4/net/sourceforge/pmd/lang/kotlin/ast From 4fbf4fb580dd02299981ca0dd81cae245683da24 Mon Sep 17 00:00:00 2001 From: Peter Paul Bakker Date: Wed, 13 Oct 2021 17:34:20 +0200 Subject: [PATCH 012/198] added FunctionNameTooShort test in bestpractices category for Kotlin, with unit test cases --- .../category/kotlin/bestpractices.xml | 39 +++++++++++++++++++ .../category/kotlin/categories.properties | 8 ++-- .../rulesets/kotlin/rulesets.properties | 7 ++++ .../FunctionNameTooShortTest.java | 11 ++++++ .../xml/FunctionNameTooShort.xml | 28 +++++++++++++ 5 files changed, 88 insertions(+), 5 deletions(-) create mode 100644 pmd-kotlin/src/main/resources/category/kotlin/bestpractices.xml create mode 100644 pmd-kotlin/src/main/resources/rulesets/kotlin/rulesets.properties create mode 100644 pmd-kotlin/src/test/java/net/sourceforge/pmd/lang/kotlin/rule/bestpractices/FunctionNameTooShortTest.java create mode 100644 pmd-kotlin/src/test/resources/net/sourceforge/pmd/lang/kotlin/rule/bestpractices/xml/FunctionNameTooShort.xml diff --git a/pmd-kotlin/src/main/resources/category/kotlin/bestpractices.xml b/pmd-kotlin/src/main/resources/category/kotlin/bestpractices.xml new file mode 100644 index 0000000000..48512462ce --- /dev/null +++ b/pmd-kotlin/src/main/resources/category/kotlin/bestpractices.xml @@ -0,0 +1,39 @@ + + + + + +Rules which enforce generally accepted best practices. + + + + + Function names should be easy to understand and describe the intention. Makes developers happy. + + 3 + + + + + + + + + + + diff --git a/pmd-kotlin/src/main/resources/category/kotlin/categories.properties b/pmd-kotlin/src/main/resources/category/kotlin/categories.properties index f8ffec58d8..3c5f1b3629 100644 --- a/pmd-kotlin/src/main/resources/category/kotlin/categories.properties +++ b/pmd-kotlin/src/main/resources/category/kotlin/categories.properties @@ -2,18 +2,16 @@ # BSD-style license; for more info see http://pmd.sourceforge.net/license.html # -rulesets.filenames= - +rulesets.filenames=\ + category/kotlin/bestpractices.xml # # categories without rules # -# category/kotlin/bestpractices.xml,\ -# category/kotlin/errorprone.xml - # category/kotlin/codestyle.xml # category/kotlin/design.xml # category/kotlin/documentation.xml +# category/kotlin/errorprone.xml # category/kotlin/multithreading.xml # category/kotlin/performance.xml # category/kotlin/security.xml diff --git a/pmd-kotlin/src/main/resources/rulesets/kotlin/rulesets.properties b/pmd-kotlin/src/main/resources/rulesets/kotlin/rulesets.properties new file mode 100644 index 0000000000..eaeaf55d8f --- /dev/null +++ b/pmd-kotlin/src/main/resources/rulesets/kotlin/rulesets.properties @@ -0,0 +1,7 @@ +# +# BSD-style license; for more info see http://pmd.sourceforge.net/license.html +# + +rulesets.filenames=\ + category/kotlin/bestpractices.xml + diff --git a/pmd-kotlin/src/test/java/net/sourceforge/pmd/lang/kotlin/rule/bestpractices/FunctionNameTooShortTest.java b/pmd-kotlin/src/test/java/net/sourceforge/pmd/lang/kotlin/rule/bestpractices/FunctionNameTooShortTest.java new file mode 100644 index 0000000000..4dd4772eb9 --- /dev/null +++ b/pmd-kotlin/src/test/java/net/sourceforge/pmd/lang/kotlin/rule/bestpractices/FunctionNameTooShortTest.java @@ -0,0 +1,11 @@ +/** + * BSD-style license; for more info see http://pmd.sourceforge.net/license.html + */ + +package net.sourceforge.pmd.lang.kotlin.rule.bestpractices; + +import net.sourceforge.pmd.testframework.PmdRuleTst; + +public class FunctionNameTooShortTest extends PmdRuleTst { + // no additional unit tests +} diff --git a/pmd-kotlin/src/test/resources/net/sourceforge/pmd/lang/kotlin/rule/bestpractices/xml/FunctionNameTooShort.xml b/pmd-kotlin/src/test/resources/net/sourceforge/pmd/lang/kotlin/rule/bestpractices/xml/FunctionNameTooShort.xml new file mode 100644 index 0000000000..01067c1111 --- /dev/null +++ b/pmd-kotlin/src/test/resources/net/sourceforge/pmd/lang/kotlin/rule/bestpractices/xml/FunctionNameTooShort.xml @@ -0,0 +1,28 @@ + + + + + Good example #1 + 0 + + + + Bad example #1 + 2 + 2,3 + + + From 39807f325f28184fa55b593949be9d0c66f4c176 Mon Sep 17 00:00:00 2001 From: Andreas Dangel Date: Thu, 14 Oct 2021 14:49:17 +0200 Subject: [PATCH 013/198] [doc] Add a warning box in major language contributions --- .../adding_a_new_antlr_based_language.md | 43 +++++++++++++++++-- .../adding_a_new_javacc_based_language.md | 34 ++++++++++++--- 2 files changed, 69 insertions(+), 8 deletions(-) diff --git a/docs/pages/pmd/devdocs/major_contributions/adding_a_new_antlr_based_language.md b/docs/pages/pmd/devdocs/major_contributions/adding_a_new_antlr_based_language.md index 90cd18a417..567db3d6c2 100644 --- a/docs/pages/pmd/devdocs/major_contributions/adding_a_new_antlr_based_language.md +++ b/docs/pages/pmd/devdocs/major_contributions/adding_a_new_antlr_based_language.md @@ -3,17 +3,54 @@ title: Adding PMD support for a new ANTLR grammar based language short_title: Adding a new language with ANTLR tags: [devdocs, extending] summary: "How to add a new language to PMD using ANTLR grammar." -last_updated: July 21, 2019 +last_updated: October 2021 sidebar: pmd_sidebar permalink: pmd_devdocs_major_adding_new_language_antlr.html folder: pmd/devdocs -# needs to be changed to branch master instead of pmd/7.0.x +# +# needs to be changed to branch master instead of pmd/7.0.x once pmd7 is released # https://github.com/pmd/pmd/blob/pmd/7.0.x -> https://github.com/pmd/pmd/blob/master +# --- +{% include callout.html type="warning" content=" -## 1. Start with a new sub-module. +**Before you start...**

+ +This is really a big contribution and can't be done with a drive by contribution. It requires dedicated passion +and long commitment to implement support for a new language.

+ +This step by step guide is just a small intro to get the basics started and it's also not necessarily up-to-date +or complete and you have to be able to fill in the blanks.

+ +Currently the Antlr integration has some basic limitations compared to JavaCC: The output of the +Antlr parser generator is not an abstract syntax tree (AST) but a parse tree. As such, a parse tree is +much more fine-grained than what a typical JavaCC grammar will produce. This means that the +parse tree is much deeper and contains nodes down to the different token types.

+ +The Antlr nodes themselves don't have any attributes because they are on the wrong abstraction level. +As they don't have attributes, there are no attributes that can be used in XPath based rules.

+ +In order to overcome these limitations, one would need to implement a post-processing step that transforms +a parse tree into an abstract syntax tree and introducing real nodes on a higher abstraction level. This +step is **not** described in this guide.

+ +After the basic support for a language is there, there are lots of missing features left. Typical features +that can greatly improve rule writing are: symbol table, type resolution, call/data flow analysis.

+ +Symbol table keeps track of variables and their usages. Type resolution tries to find the actual class type +of each used type, following along method calls (including overloaded and overwritten methods), allowing +to query sub types and type hierarchy. This requires additional configuration of an auxiliary classpath. +Call and data flow analysis keep track of the data as it is moving through different execution paths +a program has.

+ +These features are out of scope of this guide. Type resolution and data flow are features that +definitely don't come for free. It is much effort and requires perseverance to implement.

+ +" %} + +## 1. Start with a new sub-module * See pmd-swift for examples. ## 2. Implement an AST parser for your language diff --git a/docs/pages/pmd/devdocs/major_contributions/adding_a_new_javacc_based_language.md b/docs/pages/pmd/devdocs/major_contributions/adding_a_new_javacc_based_language.md index c3b470247c..7e14a56a24 100644 --- a/docs/pages/pmd/devdocs/major_contributions/adding_a_new_javacc_based_language.md +++ b/docs/pages/pmd/devdocs/major_contributions/adding_a_new_javacc_based_language.md @@ -1,16 +1,40 @@ --- -title: Adding PMD support for a new JAVACC grammar based language -short_title: Adding a new language with JAVACC +title: Adding PMD support for a new JavaCC grammar based language +short_title: Adding a new language with JavaCC tags: [devdocs, extending] -summary: "How to add a new language to PMD using JAVACC grammar." -last_updated: October 5, 2019 +summary: "How to add a new language to PMD using JavaCC grammar." +last_updated: October 2021 sidebar: pmd_sidebar permalink: pmd_devdocs_major_adding_new_language_javacc.html folder: pmd/devdocs --- +{% include callout.html type="warning" content=" -## 1. Start with a new sub-module. +**Before you start...**

+ +This is really a big contribution and can't be done with a drive by contribution. It requires dedicated passion +and long commitment to implement support for a new language.

+ +This step by step guide is just a small intro to get the basics started and it's also not necessarily up-to-date +or complete and you have to be able to fill in the blanks.

+ +After the basic support for a language is there, there are lots of missing features left. Typical features +that can greatly improve rule writing are: symbol table, type resolution, call/data flow analysis.

+ +Symbol table keeps track of variables and their usages. Type resolution tries to find the actual class type +of each used type, following along method calls (including overloaded and overwritten methods), allowing +to query sub types and type hierarchy. This requires additional configuration of an auxiliary classpath. +Call and data flow analysis keep track of the data as it is moving through different execution paths +a program has.

+ +These features are out of scope of this guide. Type resolution and data flow are features that +definitely don't come for free. It is much effort and requires perseverance to implement.

+ +" %} + + +## 1. Start with a new sub-module * See pmd-java or pmd-vm for examples. ## 2. Implement an AST parser for your language From a2e9d2b65294068063091bed255c83ff8aef199f Mon Sep 17 00:00:00 2001 From: Peter Paul Bakker Date: Fri, 15 Oct 2021 18:51:08 +0200 Subject: [PATCH 014/198] added kotlin xpath function 'pmd-kotlin:hasChildren(3)' as test case for custom kotlin xpath functions --- docs/_data/xpath_funs.yml | 15 +++++ .../pmd/lang/kotlin/KotlinHandler.java | 12 ++++ .../internal/BaseContextNodeTestFun.java | 64 +++++++++++++++++++ .../internal/BaseKotlinXPathFunction.java | 15 +++++ 4 files changed, 106 insertions(+) create mode 100644 pmd-kotlin/src/main/java/net/sourceforge/pmd/lang/kotlin/rule/xpath/internal/BaseContextNodeTestFun.java create mode 100644 pmd-kotlin/src/main/java/net/sourceforge/pmd/lang/kotlin/rule/xpath/internal/BaseKotlinXPathFunction.java diff --git a/docs/_data/xpath_funs.yml b/docs/_data/xpath_funs.yml index 830217ae71..761289506f 100644 --- a/docs/_data/xpath_funs.yml +++ b/docs/_data/xpath_funs.yml @@ -172,3 +172,18 @@ langs: outcome: "Matches calls to any method with 2 `int` parameters (!= argument)" - code: '//ConstructorCall[pmd-java:matchesSig("java.util.ArrayList#new(int)")]' outcome: "Matches constructors calls of ArrayList with a single int parameter" + + - name: "Kotlin" + ns: "pmd-kotlin" + funs: + - name: hasChildren + returnType: "xs:boolean" + shortDescription: "Tests if a node has children" + description: "Returns true if the Node has children. This is for test purposes only." + parameters: + - name: "count" + type: "xs:decimal" + description: "The number of children." + examples: + - code: '//Identifier[pmd-kotlin:hasChildren(3)]' + outcome: "true or false" \ No newline at end of file diff --git a/pmd-kotlin/src/main/java/net/sourceforge/pmd/lang/kotlin/KotlinHandler.java b/pmd-kotlin/src/main/java/net/sourceforge/pmd/lang/kotlin/KotlinHandler.java index e7df396ec2..ecc228b7eb 100644 --- a/pmd-kotlin/src/main/java/net/sourceforge/pmd/lang/kotlin/KotlinHandler.java +++ b/pmd-kotlin/src/main/java/net/sourceforge/pmd/lang/kotlin/KotlinHandler.java @@ -7,17 +7,29 @@ package net.sourceforge.pmd.lang.kotlin; import net.sourceforge.pmd.lang.AbstractPmdLanguageVersionHandler; import net.sourceforge.pmd.lang.ast.Parser; import net.sourceforge.pmd.lang.kotlin.ast.PmdKotlinParser; +import net.sourceforge.pmd.lang.kotlin.rule.xpath.internal.BaseContextNodeTestFun; +import net.sourceforge.pmd.lang.rule.xpath.impl.XPathHandler; public class KotlinHandler extends AbstractPmdLanguageVersionHandler { private final String kotlinRelease; + private static final XPathHandler XPATH_HANDLER = + XPathHandler.getHandlerForFunctionDefs( + BaseContextNodeTestFun.HAS_CHILDREN + ); + public KotlinHandler(String release) { kotlinRelease = release; // check language version? } + @Override + public XPathHandler getXPathHandler() { + return XPATH_HANDLER; + } + @Override public Parser getParser() { return new PmdKotlinParser(); diff --git a/pmd-kotlin/src/main/java/net/sourceforge/pmd/lang/kotlin/rule/xpath/internal/BaseContextNodeTestFun.java b/pmd-kotlin/src/main/java/net/sourceforge/pmd/lang/kotlin/rule/xpath/internal/BaseContextNodeTestFun.java new file mode 100644 index 0000000000..37bfb353c0 --- /dev/null +++ b/pmd-kotlin/src/main/java/net/sourceforge/pmd/lang/kotlin/rule/xpath/internal/BaseContextNodeTestFun.java @@ -0,0 +1,64 @@ +/* + * BSD-style license; for more info see http://pmd.sourceforge.net/license.html + */ + +package net.sourceforge.pmd.lang.kotlin.rule.xpath.internal; + +import net.sourceforge.pmd.lang.ast.Node; +import net.sourceforge.pmd.lang.kotlin.ast.KotlinNode; +import net.sourceforge.pmd.lang.rule.xpath.internal.AstElementNode; + +import net.sf.saxon.expr.XPathContext; +import net.sf.saxon.lib.ExtensionFunctionCall; +import net.sf.saxon.om.Sequence; +import net.sf.saxon.trans.XPathException; +import net.sf.saxon.value.BooleanValue; +import net.sf.saxon.value.SequenceType; + +/** + * XPath function {@code pmd-kotlin:hasChildren(count as xs:decimal) as xs:boolean} + * + *

Example XPath 3.1: {@code //Identifier[pmd-kotlin:hasChildren(3)]} + * + *

Returns true if the node has children, false otherwise. + */ +public class BaseContextNodeTestFun extends BaseKotlinXPathFunction { + + static final SequenceType[] NO_ARGUMENTS = { SequenceType.SINGLE_INTEGER }; + private final Class klass; + + public static final BaseKotlinXPathFunction HAS_CHILDREN = new BaseContextNodeTestFun<>(KotlinNode.class, "hasChildren"); + + protected BaseContextNodeTestFun(Class klass, String localName) { + super(localName); + this.klass = klass; + } + + @Override + public SequenceType[] getArgumentTypes() { + return NO_ARGUMENTS; + } + + @Override + public SequenceType getResultType(SequenceType[] suppliedArgumentTypes) { + return SequenceType.SINGLE_BOOLEAN; + } + + @Override + public boolean dependsOnFocus() { + return true; + } + + @Override + public ExtensionFunctionCall makeCallExpression() { + return new ExtensionFunctionCall() { + @Override + public Sequence call(XPathContext context, Sequence[] arguments) throws XPathException { + Node contextNode = ((AstElementNode) context.getContextItem()).getUnderlyingNode(); + boolean hasChildren = contextNode.getNumChildren() == Integer.parseInt(arguments[0].head().getStringValue()); + return BooleanValue.get(klass.isInstance(contextNode) && hasChildren); + } + }; + } + +} diff --git a/pmd-kotlin/src/main/java/net/sourceforge/pmd/lang/kotlin/rule/xpath/internal/BaseKotlinXPathFunction.java b/pmd-kotlin/src/main/java/net/sourceforge/pmd/lang/kotlin/rule/xpath/internal/BaseKotlinXPathFunction.java new file mode 100644 index 0000000000..8550b4ab6f --- /dev/null +++ b/pmd-kotlin/src/main/java/net/sourceforge/pmd/lang/kotlin/rule/xpath/internal/BaseKotlinXPathFunction.java @@ -0,0 +1,15 @@ +/* + * BSD-style license; for more info see http://pmd.sourceforge.net/license.html + */ + +package net.sourceforge.pmd.lang.kotlin.rule.xpath.internal; + +import net.sourceforge.pmd.lang.kotlin.KotlinLanguageModule; +import net.sourceforge.pmd.lang.rule.xpath.impl.AbstractXPathFunctionDef; + +abstract class BaseKotlinXPathFunction extends AbstractXPathFunctionDef { + + protected BaseKotlinXPathFunction(String localName) { + super(localName, KotlinLanguageModule.TERSE_NAME); + } +} From 97eeac0daa5d25885f2b9c5c199277c3e9da7012 Mon Sep 17 00:00:00 2001 From: Peter Paul Bakker Date: Fri, 15 Oct 2021 19:08:40 +0200 Subject: [PATCH 015/198] added kotlin Simple parser test --- .../kotlin/ast/BaseKotlinTreeDumpTest.java | 26 ++ .../lang/kotlin/ast/KotlinParserTests.java | 24 ++ .../lang/kotlin/ast/KotlinParsingHelper.java | 29 ++ .../pmd/lang/kotlin/ast/testdata/Simple.kt | 12 + .../pmd/lang/kotlin/ast/testdata/Simple.txt | 268 ++++++++++++++++++ 5 files changed, 359 insertions(+) create mode 100644 pmd-kotlin/src/test/java/net/sourceforge/pmd/lang/kotlin/ast/BaseKotlinTreeDumpTest.java create mode 100644 pmd-kotlin/src/test/java/net/sourceforge/pmd/lang/kotlin/ast/KotlinParserTests.java create mode 100644 pmd-kotlin/src/test/java/net/sourceforge/pmd/lang/kotlin/ast/KotlinParsingHelper.java create mode 100644 pmd-kotlin/src/test/resources/net/sourceforge/pmd/lang/kotlin/ast/testdata/Simple.kt create mode 100644 pmd-kotlin/src/test/resources/net/sourceforge/pmd/lang/kotlin/ast/testdata/Simple.txt diff --git a/pmd-kotlin/src/test/java/net/sourceforge/pmd/lang/kotlin/ast/BaseKotlinTreeDumpTest.java b/pmd-kotlin/src/test/java/net/sourceforge/pmd/lang/kotlin/ast/BaseKotlinTreeDumpTest.java new file mode 100644 index 0000000000..82ace21ff6 --- /dev/null +++ b/pmd-kotlin/src/test/java/net/sourceforge/pmd/lang/kotlin/ast/BaseKotlinTreeDumpTest.java @@ -0,0 +1,26 @@ +/* + * BSD-style license; for more info see http://pmd.sourceforge.net/license.html + */ + +package net.sourceforge.pmd.lang.kotlin.ast; + + +import net.sourceforge.pmd.lang.ast.test.BaseTreeDumpTest; +import net.sourceforge.pmd.lang.ast.test.NodePrintersKt; +import org.checkerframework.checker.nullness.qual.NonNull; + +/** + * + */ +public class BaseKotlinTreeDumpTest extends BaseTreeDumpTest { + + public BaseKotlinTreeDumpTest() { + super(NodePrintersKt.getSimpleNodePrinter(), ".kt"); + } + + @NonNull + @Override + public KotlinParsingHelper getParser() { + return KotlinParsingHelper.DEFAULT.withResourceContext(getClass(), "testdata"); + } +} diff --git a/pmd-kotlin/src/test/java/net/sourceforge/pmd/lang/kotlin/ast/KotlinParserTests.java b/pmd-kotlin/src/test/java/net/sourceforge/pmd/lang/kotlin/ast/KotlinParserTests.java new file mode 100644 index 0000000000..6004d75225 --- /dev/null +++ b/pmd-kotlin/src/test/java/net/sourceforge/pmd/lang/kotlin/ast/KotlinParserTests.java @@ -0,0 +1,24 @@ +/* + * BSD-style license; for more info see http://pmd.sourceforge.net/license.html + */ + +package net.sourceforge.pmd.lang.kotlin.ast; + +import org.junit.Test; + +/** + * + */ +public class KotlinParserTests extends BaseKotlinTreeDumpTest { + + @Test + public void testSimpleKotlin() { + doTest("Simple"); + } + +// @Test +// public void testBtree() { +// doTest("BTree"); +// } + +} diff --git a/pmd-kotlin/src/test/java/net/sourceforge/pmd/lang/kotlin/ast/KotlinParsingHelper.java b/pmd-kotlin/src/test/java/net/sourceforge/pmd/lang/kotlin/ast/KotlinParsingHelper.java new file mode 100644 index 0000000000..cc67c12e68 --- /dev/null +++ b/pmd-kotlin/src/test/java/net/sourceforge/pmd/lang/kotlin/ast/KotlinParsingHelper.java @@ -0,0 +1,29 @@ +/* + * BSD-style license; for more info see http://pmd.sourceforge.net/license.html + */ + +package net.sourceforge.pmd.lang.kotlin.ast; + +import net.sourceforge.pmd.lang.ast.test.BaseParsingHelper; +import net.sourceforge.pmd.lang.kotlin.KotlinLanguageModule; + +import org.jetbrains.annotations.NotNull; + +/** + * + */ +public class KotlinParsingHelper extends BaseParsingHelper { + + public static final KotlinParsingHelper DEFAULT = new KotlinParsingHelper(Params.getDefaultNoProcess()); + + + public KotlinParsingHelper(@NotNull Params params) { + super(KotlinLanguageModule.NAME, KotlinParser.KtFile.class, params); + } + + @NotNull + @Override + protected KotlinParsingHelper clone(@NotNull Params params) { + return new KotlinParsingHelper(params); + } +} diff --git a/pmd-kotlin/src/test/resources/net/sourceforge/pmd/lang/kotlin/ast/testdata/Simple.kt b/pmd-kotlin/src/test/resources/net/sourceforge/pmd/lang/kotlin/ast/testdata/Simple.kt new file mode 100644 index 0000000000..e6172fb162 --- /dev/null +++ b/pmd-kotlin/src/test/resources/net/sourceforge/pmd/lang/kotlin/ast/testdata/Simple.kt @@ -0,0 +1,12 @@ +package net.sourceforge.pmd.lang.kotlin.ast.testdata + +class Simple { + private val name = "Simple" + fun info() = "This is $name class" +} + +fun main() { + val s = Simple() + println(s) + println(s.info()) +} \ No newline at end of file diff --git a/pmd-kotlin/src/test/resources/net/sourceforge/pmd/lang/kotlin/ast/testdata/Simple.txt b/pmd-kotlin/src/test/resources/net/sourceforge/pmd/lang/kotlin/ast/testdata/Simple.txt new file mode 100644 index 0000000000..93c01ab1a8 --- /dev/null +++ b/pmd-kotlin/src/test/resources/net/sourceforge/pmd/lang/kotlin/ast/testdata/Simple.txt @@ -0,0 +1,268 @@ ++- File + +- PackageHeader + | +- T-PACKAGE + | +- Identifier + | | +- SimpleIdentifier + | | | +- T-Identifier + | | +- T-DOT + | | +- SimpleIdentifier + | | | +- T-Identifier + | | +- T-DOT + | | +- SimpleIdentifier + | | | +- T-Identifier + | | +- T-DOT + | | +- SimpleIdentifier + | | | +- T-Identifier + | | +- T-DOT + | | +- SimpleIdentifier + | | | +- T-Identifier + | | +- T-DOT + | | +- SimpleIdentifier + | | | +- T-Identifier + | | +- T-DOT + | | +- SimpleIdentifier + | | +- T-Identifier + | +- Semi + | +- T-NL + | +- T-NL + +- ImportList + +- TopLevelObject + | +- Declaration + | | +- ClassDeclaration + | | +- T-CLASS + | | +- SimpleIdentifier + | | | +- T-Identifier + | | +- ClassBody + | | +- T-LCURL + | | +- T-NL + | | +- ClassMemberDeclarations + | | | +- ClassMemberDeclaration + | | | | +- Declaration + | | | | +- PropertyDeclaration + | | | | +- Modifiers + | | | | | +- Modifier + | | | | | +- VisibilityModifier + | | | | | +- T-PRIVATE + | | | | +- T-VAL + | | | | +- VariableDeclaration + | | | | | +- SimpleIdentifier + | | | | | +- T-Identifier + | | | | +- T-ASSIGNMENT + | | | | +- Expression + | | | | | +- Disjunction + | | | | | +- Conjunction + | | | | | +- Equality + | | | | | +- Comparison + | | | | | +- GenericCallLikeComparison + | | | | | +- InfixOperation + | | | | | +- ElvisExpression + | | | | | +- InfixFunctionCall + | | | | | +- RangeExpression + | | | | | +- AdditiveExpression + | | | | | +- MultiplicativeExpression + | | | | | +- AsExpression + | | | | | +- PrefixUnaryExpression + | | | | | +- PostfixUnaryExpression + | | | | | +- PrimaryExpression + | | | | | +- StringLiteral + | | | | | +- LineStringLiteral + | | | | | +- T-QUOTE_OPEN + | | | | | +- LineStringContent + | | | | | | +- T-LineStrText + | | | | | +- T-QUOTE_CLOSE + | | | | +- T-NL + | | | +- ClassMemberDeclaration + | | | | +- Declaration + | | | | +- FunctionDeclaration + | | | | +- T-FUN + | | | | +- SimpleIdentifier + | | | | | +- T-Identifier + | | | | +- FunctionValueParameters + | | | | | +- T-LPAREN + | | | | | +- T-RPAREN + | | | | +- FunctionBody + | | | | +- T-ASSIGNMENT + | | | | +- Expression + | | | | +- Disjunction + | | | | +- Conjunction + | | | | +- Equality + | | | | +- Comparison + | | | | +- GenericCallLikeComparison + | | | | +- InfixOperation + | | | | +- ElvisExpression + | | | | +- InfixFunctionCall + | | | | +- RangeExpression + | | | | +- AdditiveExpression + | | | | +- MultiplicativeExpression + | | | | +- AsExpression + | | | | +- PrefixUnaryExpression + | | | | +- PostfixUnaryExpression + | | | | +- PrimaryExpression + | | | | +- StringLiteral + | | | | +- LineStringLiteral + | | | | +- T-QUOTE_OPEN + | | | | +- LineStringContent + | | | | | +- T-LineStrText + | | | | +- LineStringContent + | | | | | +- T-LineStrRef + | | | | +- LineStringContent + | | | | | +- T-LineStrText + | | | | +- T-QUOTE_CLOSE + | | | +- Semis + | | | +- T-NL + | | +- T-RCURL + | +- Semis + | +- T-NL + | +- T-NL + +- TopLevelObject + | +- Declaration + | | +- FunctionDeclaration + | | +- T-FUN + | | +- SimpleIdentifier + | | | +- T-Identifier + | | +- FunctionValueParameters + | | | +- T-LPAREN + | | | +- T-RPAREN + | | +- FunctionBody + | | +- Block + | | +- T-LCURL + | | +- T-NL + | | +- Statements + | | | +- Statement + | | | | +- Declaration + | | | | +- PropertyDeclaration + | | | | +- T-VAL + | | | | +- VariableDeclaration + | | | | | +- SimpleIdentifier + | | | | | +- T-Identifier + | | | | +- T-ASSIGNMENT + | | | | +- Expression + | | | | +- Disjunction + | | | | +- Conjunction + | | | | +- Equality + | | | | +- Comparison + | | | | +- GenericCallLikeComparison + | | | | +- InfixOperation + | | | | +- ElvisExpression + | | | | +- InfixFunctionCall + | | | | +- RangeExpression + | | | | +- AdditiveExpression + | | | | +- MultiplicativeExpression + | | | | +- AsExpression + | | | | +- PrefixUnaryExpression + | | | | +- PostfixUnaryExpression + | | | | +- PrimaryExpression + | | | | | +- SimpleIdentifier + | | | | | +- T-Identifier + | | | | +- PostfixUnarySuffix + | | | | +- CallSuffix + | | | | +- ValueArguments + | | | | +- T-LPAREN + | | | | +- T-RPAREN + | | | +- Semis + | | | | +- T-NL + | | | +- Statement + | | | | +- Expression + | | | | +- Disjunction + | | | | +- Conjunction + | | | | +- Equality + | | | | +- Comparison + | | | | +- GenericCallLikeComparison + | | | | +- InfixOperation + | | | | +- ElvisExpression + | | | | +- InfixFunctionCall + | | | | +- RangeExpression + | | | | +- AdditiveExpression + | | | | +- MultiplicativeExpression + | | | | +- AsExpression + | | | | +- PrefixUnaryExpression + | | | | +- PostfixUnaryExpression + | | | | +- PrimaryExpression + | | | | | +- SimpleIdentifier + | | | | | +- T-Identifier + | | | | +- PostfixUnarySuffix + | | | | +- CallSuffix + | | | | +- ValueArguments + | | | | +- T-LPAREN + | | | | +- ValueArgument + | | | | | +- Expression + | | | | | +- Disjunction + | | | | | +- Conjunction + | | | | | +- Equality + | | | | | +- Comparison + | | | | | +- GenericCallLikeComparison + | | | | | +- InfixOperation + | | | | | +- ElvisExpression + | | | | | +- InfixFunctionCall + | | | | | +- RangeExpression + | | | | | +- AdditiveExpression + | | | | | +- MultiplicativeExpression + | | | | | +- AsExpression + | | | | | +- PrefixUnaryExpression + | | | | | +- PostfixUnaryExpression + | | | | | +- PrimaryExpression + | | | | | +- SimpleIdentifier + | | | | | +- T-Identifier + | | | | +- T-RPAREN + | | | +- Semis + | | | | +- T-NL + | | | +- Statement + | | | | +- Expression + | | | | +- Disjunction + | | | | +- Conjunction + | | | | +- Equality + | | | | +- Comparison + | | | | +- GenericCallLikeComparison + | | | | +- InfixOperation + | | | | +- ElvisExpression + | | | | +- InfixFunctionCall + | | | | +- RangeExpression + | | | | +- AdditiveExpression + | | | | +- MultiplicativeExpression + | | | | +- AsExpression + | | | | +- PrefixUnaryExpression + | | | | +- PostfixUnaryExpression + | | | | +- PrimaryExpression + | | | | | +- SimpleIdentifier + | | | | | +- T-Identifier + | | | | +- PostfixUnarySuffix + | | | | +- CallSuffix + | | | | +- ValueArguments + | | | | +- T-LPAREN + | | | | +- ValueArgument + | | | | | +- Expression + | | | | | +- Disjunction + | | | | | +- Conjunction + | | | | | +- Equality + | | | | | +- Comparison + | | | | | +- GenericCallLikeComparison + | | | | | +- InfixOperation + | | | | | +- ElvisExpression + | | | | | +- InfixFunctionCall + | | | | | +- RangeExpression + | | | | | +- AdditiveExpression + | | | | | +- MultiplicativeExpression + | | | | | +- AsExpression + | | | | | +- PrefixUnaryExpression + | | | | | +- PostfixUnaryExpression + | | | | | +- PrimaryExpression + | | | | | | +- SimpleIdentifier + | | | | | | +- T-Identifier + | | | | | +- PostfixUnarySuffix + | | | | | | +- NavigationSuffix + | | | | | | +- MemberAccessOperator + | | | | | | | +- T-DOT + | | | | | | +- SimpleIdentifier + | | | | | | +- T-Identifier + | | | | | +- PostfixUnarySuffix + | | | | | +- CallSuffix + | | | | | +- ValueArguments + | | | | | +- T-LPAREN + | | | | | +- T-RPAREN + | | | | +- T-RPAREN + | | | +- Semis + | | | +- T-NL + | | +- T-RCURL + | +- Semis + | +- EOF + +- EOF From faeffd4f17868e45cdd7ae9883c1428bb7159f8a Mon Sep 17 00:00:00 2001 From: Peter Paul Bakker Date: Fri, 15 Oct 2021 19:23:17 +0200 Subject: [PATCH 016/198] fix checkstyle issues --- .../pmd/lang/kotlin/ast/BaseKotlinTreeDumpTest.java | 2 +- .../sourceforge/pmd/lang/kotlin/ast/KotlinParserTests.java | 5 ----- .../pmd/lang/kotlin/ast/KotlinParsingHelper.java | 4 ++-- .../net/sourceforge/pmd/lang/kotlin/ast/testdata/Simple.kt | 6 +++++- .../net/sourceforge/pmd/lang/kotlin/ast/testdata/Simple.txt | 4 +++- 5 files changed, 11 insertions(+), 10 deletions(-) diff --git a/pmd-kotlin/src/test/java/net/sourceforge/pmd/lang/kotlin/ast/BaseKotlinTreeDumpTest.java b/pmd-kotlin/src/test/java/net/sourceforge/pmd/lang/kotlin/ast/BaseKotlinTreeDumpTest.java index 82ace21ff6..3541b69096 100644 --- a/pmd-kotlin/src/test/java/net/sourceforge/pmd/lang/kotlin/ast/BaseKotlinTreeDumpTest.java +++ b/pmd-kotlin/src/test/java/net/sourceforge/pmd/lang/kotlin/ast/BaseKotlinTreeDumpTest.java @@ -4,10 +4,10 @@ package net.sourceforge.pmd.lang.kotlin.ast; +import org.checkerframework.checker.nullness.qual.NonNull; import net.sourceforge.pmd.lang.ast.test.BaseTreeDumpTest; import net.sourceforge.pmd.lang.ast.test.NodePrintersKt; -import org.checkerframework.checker.nullness.qual.NonNull; /** * diff --git a/pmd-kotlin/src/test/java/net/sourceforge/pmd/lang/kotlin/ast/KotlinParserTests.java b/pmd-kotlin/src/test/java/net/sourceforge/pmd/lang/kotlin/ast/KotlinParserTests.java index 6004d75225..bd1944ae31 100644 --- a/pmd-kotlin/src/test/java/net/sourceforge/pmd/lang/kotlin/ast/KotlinParserTests.java +++ b/pmd-kotlin/src/test/java/net/sourceforge/pmd/lang/kotlin/ast/KotlinParserTests.java @@ -16,9 +16,4 @@ public class KotlinParserTests extends BaseKotlinTreeDumpTest { doTest("Simple"); } -// @Test -// public void testBtree() { -// doTest("BTree"); -// } - } diff --git a/pmd-kotlin/src/test/java/net/sourceforge/pmd/lang/kotlin/ast/KotlinParsingHelper.java b/pmd-kotlin/src/test/java/net/sourceforge/pmd/lang/kotlin/ast/KotlinParsingHelper.java index cc67c12e68..9d20cd2b16 100644 --- a/pmd-kotlin/src/test/java/net/sourceforge/pmd/lang/kotlin/ast/KotlinParsingHelper.java +++ b/pmd-kotlin/src/test/java/net/sourceforge/pmd/lang/kotlin/ast/KotlinParsingHelper.java @@ -4,11 +4,11 @@ package net.sourceforge.pmd.lang.kotlin.ast; +import org.jetbrains.annotations.NotNull; + import net.sourceforge.pmd.lang.ast.test.BaseParsingHelper; import net.sourceforge.pmd.lang.kotlin.KotlinLanguageModule; -import org.jetbrains.annotations.NotNull; - /** * */ diff --git a/pmd-kotlin/src/test/resources/net/sourceforge/pmd/lang/kotlin/ast/testdata/Simple.kt b/pmd-kotlin/src/test/resources/net/sourceforge/pmd/lang/kotlin/ast/testdata/Simple.kt index e6172fb162..2cc0f1590e 100644 --- a/pmd-kotlin/src/test/resources/net/sourceforge/pmd/lang/kotlin/ast/testdata/Simple.kt +++ b/pmd-kotlin/src/test/resources/net/sourceforge/pmd/lang/kotlin/ast/testdata/Simple.kt @@ -1,3 +1,7 @@ +/* + * BSD-style license; for more info see http://pmd.sourceforge.net/license.html + */ + package net.sourceforge.pmd.lang.kotlin.ast.testdata class Simple { @@ -9,4 +13,4 @@ fun main() { val s = Simple() println(s) println(s.info()) -} \ No newline at end of file +} diff --git a/pmd-kotlin/src/test/resources/net/sourceforge/pmd/lang/kotlin/ast/testdata/Simple.txt b/pmd-kotlin/src/test/resources/net/sourceforge/pmd/lang/kotlin/ast/testdata/Simple.txt index 93c01ab1a8..dba730ec31 100644 --- a/pmd-kotlin/src/test/resources/net/sourceforge/pmd/lang/kotlin/ast/testdata/Simple.txt +++ b/pmd-kotlin/src/test/resources/net/sourceforge/pmd/lang/kotlin/ast/testdata/Simple.txt @@ -1,4 +1,6 @@ +- File + +- T-NL + +- T-NL +- PackageHeader | +- T-PACKAGE | +- Identifier @@ -264,5 +266,5 @@ | | | +- T-NL | | +- T-RCURL | +- Semis - | +- EOF + | +- T-NL +- EOF From bf10da5444fb4ead8eb6f9fc4f71087485bea6a5 Mon Sep 17 00:00:00 2001 From: Peter Paul Bakker Date: Fri, 15 Oct 2021 19:40:16 +0200 Subject: [PATCH 017/198] moved libDirectory setting for kotlin to pmd-kotlin pom.xml --- pmd-kotlin/pom.xml | 3 +++ pom.xml | 1 - 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/pmd-kotlin/pom.xml b/pmd-kotlin/pom.xml index d00109b502..f1d7cb3ce1 100644 --- a/pmd-kotlin/pom.xml +++ b/pmd-kotlin/pom.xml @@ -20,6 +20,9 @@ org.antlr antlr4-maven-plugin + + src/main/antlr4/net/sourceforge/pmd/lang/kotlin/ast + org.apache.maven.plugins diff --git a/pom.xml b/pom.xml index c2739dcf74..470e267a50 100644 --- a/pom.xml +++ b/pom.xml @@ -136,7 +136,6 @@ ${project.build.sourceEncoding} true true - src/main/antlr4/net/sourceforge/pmd/lang/kotlin/ast From 5ed2b3e100a83551a014cf022af542d2ce6b561e Mon Sep 17 00:00:00 2001 From: Peter Paul Bakker Date: Wed, 3 Nov 2021 11:54:09 +0100 Subject: [PATCH 018/198] fixed NPE which occurred when running sonar-pmd plugin integration tests with pmd/7.0.x branch --- .../sourceforge/pmd/lang/java/rule/AbstractLombokAwareRule.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/rule/AbstractLombokAwareRule.java b/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/rule/AbstractLombokAwareRule.java index f17f057260..4ec3fdd41d 100644 --- a/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/rule/AbstractLombokAwareRule.java +++ b/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/rule/AbstractLombokAwareRule.java @@ -42,7 +42,7 @@ public class AbstractLombokAwareRule extends AbstractIgnoredAnnotationRule { @Override public Object visit(ASTImportDeclaration node, Object data) { - if (!lombokImported && node.getImage() != null & node.getImage().startsWith(LOMBOK_PACKAGE)) { + if (!lombokImported && node.getImage() != null && node.getImage().startsWith(LOMBOK_PACKAGE)) { lombokImported = true; } return super.visit(node, data); From 77ca5eac481a0a4c30319d82b1d61d67f2100552 Mon Sep 17 00:00:00 2001 From: Peter Paul Bakker Date: Thu, 25 Nov 2021 15:19:33 +0100 Subject: [PATCH 019/198] upped pmd-designer.version to 7.0.0-SNAPSHOT --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 470e267a50..d79fde117f 100644 --- a/pom.xml +++ b/pom.xml @@ -107,7 +107,7 @@ 16 - 6.37.0 + 7.0.0-SNAPSHOT ${settings.localRepository}/net/java/dev/javacc/javacc/${javacc.version}/javacc-${javacc.version}.jar ${project.build.directory}/generated-sources/javacc ${project.basedir}/../javacc-wrapper.xml From b4d7867ebade30cda8932d8e3e50d71afcf8afdb Mon Sep 17 00:00:00 2001 From: Peter Paul Bakker Date: Thu, 25 Nov 2021 15:20:29 +0100 Subject: [PATCH 020/198] add resources to the pmd-kotlin jar so rule definitions files can be found by pmd-sonar plugin --- pmd-kotlin/pom.xml | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/pmd-kotlin/pom.xml b/pmd-kotlin/pom.xml index f1d7cb3ce1..c2e2769fb3 100644 --- a/pmd-kotlin/pom.xml +++ b/pmd-kotlin/pom.xml @@ -16,6 +16,13 @@ + + + + ${project.basedir}/src/main/resources + true + + org.antlr From 61201eba125f54aa001c37b6aaaec633573c200c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9ment=20Fournier?= Date: Sun, 2 Jan 2022 17:51:09 +0100 Subject: [PATCH 021/198] Add rule codestyle.xml/UnnecessarySemicolon --- .../resources/category/java/codestyle.xml | 46 ++++++++++++ .../codestyle/UnnecessarySemicolonTest.java | 11 +++ .../codestyle/xml/UnnecessarySemicolon.xml | 72 +++++++++++++++++++ 3 files changed, 129 insertions(+) create mode 100644 pmd-java/src/test/java/net/sourceforge/pmd/lang/java/rule/codestyle/UnnecessarySemicolonTest.java create mode 100644 pmd-java/src/test/resources/net/sourceforge/pmd/lang/java/rule/codestyle/xml/UnnecessarySemicolon.xml diff --git a/pmd-java/src/main/resources/category/java/codestyle.xml b/pmd-java/src/main/resources/category/java/codestyle.xml index 4c506e3b9f..a75f259020 100644 --- a/pmd-java/src/main/resources/category/java/codestyle.xml +++ b/pmd-java/src/main/resources/category/java/codestyle.xml @@ -2088,6 +2088,52 @@ public class Foo { + + + Reports unnecessary semicolons (so called "empty statements" and "empty declarations"). + These can be removed without changing the program. The Java grammar + allows them for historical reasons, but they should be avoided. + + This rule will not report empty statements that are syntactically + required, for instance, because they are the body of a control statement. + + 3 + + + + + + + + + + + + + + + + + + Neg, necessary empty statements + 0 + + + + + Pos, empty stmt in ctor + 1 + 3 + + + + + Pos, empty stmt in method + 1 + 3 + + + + + Pos, empty decl in toplevel + 2 + 1,3 + + + + + Pos, empty decl in inner class + 1 + 3 + + + + From eb6a38d38d27fc18ee6896326011d0b901a86657 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9ment=20Fournier?= Date: Mon, 3 Jan 2022 00:13:10 +0100 Subject: [PATCH 022/198] Add rule EmptyCodeBlock --- .../resources/category/java/codestyle.xml | 59 +++++ .../rule/codestyle/EmptyCodeBlockTest.java | 11 + .../rule/codestyle/xml/EmptyCodeBlock.xml | 247 ++++++++++++++++++ 3 files changed, 317 insertions(+) create mode 100644 pmd-java/src/test/java/net/sourceforge/pmd/lang/java/rule/codestyle/EmptyCodeBlockTest.java create mode 100644 pmd-java/src/test/resources/net/sourceforge/pmd/lang/java/rule/codestyle/xml/EmptyCodeBlock.xml diff --git a/pmd-java/src/main/resources/category/java/codestyle.xml b/pmd-java/src/main/resources/category/java/codestyle.xml index a75f259020..7ef9508fd9 100644 --- a/pmd-java/src/main/resources/category/java/codestyle.xml +++ b/pmd-java/src/main/resources/category/java/codestyle.xml @@ -710,6 +710,65 @@ public abstract class ShouldBeAbstract { + + + 3 + + + + + + + + + + + + + + + pos, empty try block + 1 + 3 + + + + + pos, empty try block + 1 + 3 + + + + pos, empty finally block + 1 + 5 + + + + + pos, empty finally block + 0 + + + + pos, empty try and finally block + 2 + + + + + #432 empty try-with-resource + 0 + target.request(mediaTypes).delete(), DELETE, new ExpectedResponse(status, required))) { + // false positive + } + } + } + ]]> + + + + #432 empty try-with-resource + 0 + target.request(mediaTypes).delete(), DELETE, new ExpectedResponse(status, required))) { + // false positive + } + } + } + ]]> + + + + + pos, empty synchronized stmt + 1 + + + + + neg, nonempty synchronized stmt + 0 + + + + + pos, empty switch stmt + 1 + + + + + neg, nonempty switch stmt + 0 + + + + + failure case (non static) + 1 + + + + + failure case (static) + 1 + + + + + not an initializer + 0 + + + + + initializer not empty + 0 + + + + + static initializer not empty + 0 + + + + + pos, empty while + 1 + 3 + + + + + while(true); + 1 + + + From 6115e543b2e7d919a588b9bc0d4ad1385dc44da7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9ment=20Fournier?= Date: Mon, 3 Jan 2022 00:43:42 +0100 Subject: [PATCH 023/198] Rename to EmptyControlStatement --- .../pmd/lang/java/ast/ASTInitializer.java | 8 + .../java/ast/ASTSynchronizedStatement.java | 7 + .../codestyle/EmptyControlStatementRule.java | 154 ++++++++++++++++++ .../resources/category/java/codestyle.xml | 36 ++-- ...st.java => EmptyControlStatementTest.java} | 2 +- ...odeBlock.xml => EmptyControlStatement.xml} | 36 +++- 6 files changed, 210 insertions(+), 33 deletions(-) create mode 100644 pmd-java/src/main/java/net/sourceforge/pmd/lang/java/rule/codestyle/EmptyControlStatementRule.java rename pmd-java/src/test/java/net/sourceforge/pmd/lang/java/rule/codestyle/{EmptyCodeBlockTest.java => EmptyControlStatementTest.java} (79%) rename pmd-java/src/test/resources/net/sourceforge/pmd/lang/java/rule/codestyle/xml/{EmptyCodeBlock.xml => EmptyControlStatement.xml} (87%) diff --git a/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/ast/ASTInitializer.java b/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/ast/ASTInitializer.java index 98845224d7..870f7c5648 100644 --- a/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/ast/ASTInitializer.java +++ b/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/ast/ASTInitializer.java @@ -36,4 +36,12 @@ public class ASTInitializer extends AbstractJavaNode { public void setStatic() { isStatic = true; } + + /** + * Returns the body of this initializer. + */ + public ASTBlock getBody() { + return (ASTBlock) getChild(0); + } + } diff --git a/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/ast/ASTSynchronizedStatement.java b/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/ast/ASTSynchronizedStatement.java index 6a6695aee6..d0bce08086 100644 --- a/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/ast/ASTSynchronizedStatement.java +++ b/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/ast/ASTSynchronizedStatement.java @@ -24,4 +24,11 @@ public class ASTSynchronizedStatement extends AbstractJavaNode { public Object jjtAccept(JavaParserVisitor visitor, Object data) { return visitor.visit(this, data); } + + /** + * Returns the body of this statement. + */ + public ASTBlock getBody() { + return (ASTBlock) getChild(1); + } } diff --git a/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/rule/codestyle/EmptyControlStatementRule.java b/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/rule/codestyle/EmptyControlStatementRule.java new file mode 100644 index 0000000000..b5bd64e130 --- /dev/null +++ b/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/rule/codestyle/EmptyControlStatementRule.java @@ -0,0 +1,154 @@ +/** + * BSD-style license; for more info see http://pmd.sourceforge.net/license.html + */ + +package net.sourceforge.pmd.lang.java.rule.codestyle; + +import net.sourceforge.pmd.lang.java.ast.ASTBlock; +import net.sourceforge.pmd.lang.java.ast.ASTDoStatement; +import net.sourceforge.pmd.lang.java.ast.ASTEmptyStatement; +import net.sourceforge.pmd.lang.java.ast.ASTFinallyStatement; +import net.sourceforge.pmd.lang.java.ast.ASTForStatement; +import net.sourceforge.pmd.lang.java.ast.ASTIfStatement; +import net.sourceforge.pmd.lang.java.ast.ASTInitializer; +import net.sourceforge.pmd.lang.java.ast.ASTResource; +import net.sourceforge.pmd.lang.java.ast.ASTResourceSpecification; +import net.sourceforge.pmd.lang.java.ast.ASTStatement; +import net.sourceforge.pmd.lang.java.ast.ASTSwitchStatement; +import net.sourceforge.pmd.lang.java.ast.ASTSynchronizedStatement; +import net.sourceforge.pmd.lang.java.ast.ASTTryStatement; +import net.sourceforge.pmd.lang.java.ast.ASTWhileStatement; +import net.sourceforge.pmd.lang.java.ast.JavaNode; +import net.sourceforge.pmd.lang.java.rule.AbstractJavaRule; +import net.sourceforge.pmd.lang.java.rule.internal.JavaRuleUtil; + +public class EmptyControlStatementRule extends AbstractJavaRule { + + public EmptyControlStatementRule() { + addRuleChainVisit(ASTFinallyStatement.class); + addRuleChainVisit(ASTSynchronizedStatement.class); + addRuleChainVisit(ASTTryStatement.class); + addRuleChainVisit(ASTDoStatement.class); + addRuleChainVisit(ASTBlock.class); + addRuleChainVisit(ASTForStatement.class); + addRuleChainVisit(ASTWhileStatement.class); + addRuleChainVisit(ASTIfStatement.class); + addRuleChainVisit(ASTSwitchStatement.class); + addRuleChainVisit(ASTInitializer.class); + } + + @Override + public Object visit(JavaNode node, Object data) { + throw new UnsupportedOperationException("should not be called"); + } + + @Override + public Object visit(ASTFinallyStatement node, Object data) { + if (isEmpty(node.getBody())) { + addViolation(data, node, "Empty finally clause"); + } + return null; + } + + @Override + public Object visit(ASTSynchronizedStatement node, Object data) { + if (isEmpty(node.getBody())) { + addViolation(data, node, "Empty synchronized statement"); + } + return null; + } + + @Override + public Object visit(ASTSwitchStatement node, Object data) { + if (node.getNumChildren() == 1) { + addViolation(data, node, "Empty switch statement"); + } + return null; + } + + @Override + public Object visit(ASTBlock node, Object data) { + if (isEmpty(node) && node.getNthParent(3) instanceof ASTBlock) { + addViolation(data, node, "Empty block"); + } + return null; + } + + @Override + public Object visit(ASTIfStatement node, Object data) { + if (isEmpty(node.getThenBranch().getChild(0))) { + addViolation(data, node, "Empty if statement"); + } + if (isEmpty(node.getElseBranch().getChild(0))) { + addViolation(data, node, "Empty else statement"); + } + return null; + } + + @Override + public Object visit(ASTWhileStatement node, Object data) { + if (isEmpty(node.getBody())) { + addViolation(data, node, "Empty while statement"); + } + return null; + } + + @Override + public Object visit(ASTForStatement node, Object data) { + if (isEmpty(node.getBody())) { + addViolation(data, node, "Empty for statement"); + } + return null; + } + + @Override + public Object visit(ASTDoStatement node, Object data) { + if (isEmpty(node.getBody())) { + addViolation(data, node, "Empty do..while statement"); + } + return null; + } + + @Override + public Object visit(ASTInitializer node, Object data) { + if (isEmpty(node.getBody())) { + addViolation(data, node, "Empty initializer statement"); + } + return null; + } + + @Override + public Object visit(ASTTryStatement node, Object data) { + if (isEmpty(node.getBody())) { + // all resources must be explicitly ignored + boolean allResourcesIgnored = true; + boolean hasResource = false; + ASTResourceSpecification resources = node.getFirstChildOfType(ASTResourceSpecification.class); + if (resources != null) { + for (ASTResource resource : resources.findDescendantsOfType(ASTResource.class)) { + hasResource = true; + String name = resource.getVariableDeclaratorId().getName(); + if (!JavaRuleUtil.isExplicitUnusedVarName(name)) { + allResourcesIgnored = false; + break; + } + } + } + + if (hasResource && !allResourcesIgnored) { + addViolation(data, node, "Empty try body - you could rename the resource to 'ignored'"); + } else if (!hasResource) { + addViolation(data, node, "Empty try body"); + } + } + return null; + } + + private boolean isEmpty(JavaNode node) { + if (node instanceof ASTStatement) { + node = node.getChild(0); + } + return node instanceof ASTBlock && node.getNumChildren() == 0 + || node instanceof ASTEmptyStatement; + } +} diff --git a/pmd-java/src/main/resources/category/java/codestyle.xml b/pmd-java/src/main/resources/category/java/codestyle.xml index 7ef9508fd9..c4c00d7ce0 100644 --- a/pmd-java/src/main/resources/category/java/codestyle.xml +++ b/pmd-java/src/main/resources/category/java/codestyle.xml @@ -710,12 +710,15 @@ public abstract class ShouldBeAbstract { - + + + 3 - - - - - - diff --git a/pmd-java/src/test/java/net/sourceforge/pmd/lang/java/rule/codestyle/EmptyCodeBlockTest.java b/pmd-java/src/test/java/net/sourceforge/pmd/lang/java/rule/codestyle/EmptyControlStatementTest.java similarity index 79% rename from pmd-java/src/test/java/net/sourceforge/pmd/lang/java/rule/codestyle/EmptyCodeBlockTest.java rename to pmd-java/src/test/java/net/sourceforge/pmd/lang/java/rule/codestyle/EmptyControlStatementTest.java index a962f1ea87..ce38ef8144 100644 --- a/pmd-java/src/test/java/net/sourceforge/pmd/lang/java/rule/codestyle/EmptyCodeBlockTest.java +++ b/pmd-java/src/test/java/net/sourceforge/pmd/lang/java/rule/codestyle/EmptyControlStatementTest.java @@ -6,6 +6,6 @@ package net.sourceforge.pmd.lang.java.rule.codestyle; import net.sourceforge.pmd.testframework.PmdRuleTst; -public class EmptyCodeBlockTest extends PmdRuleTst { +public class EmptyControlStatementTest extends PmdRuleTst { // no additional unit tests } diff --git a/pmd-java/src/test/resources/net/sourceforge/pmd/lang/java/rule/codestyle/xml/EmptyCodeBlock.xml b/pmd-java/src/test/resources/net/sourceforge/pmd/lang/java/rule/codestyle/xml/EmptyControlStatement.xml similarity index 87% rename from pmd-java/src/test/resources/net/sourceforge/pmd/lang/java/rule/codestyle/xml/EmptyCodeBlock.xml rename to pmd-java/src/test/resources/net/sourceforge/pmd/lang/java/rule/codestyle/xml/EmptyControlStatement.xml index ee44c856d7..812141f39b 100644 --- a/pmd-java/src/test/resources/net/sourceforge/pmd/lang/java/rule/codestyle/xml/EmptyCodeBlock.xml +++ b/pmd-java/src/test/resources/net/sourceforge/pmd/lang/java/rule/codestyle/xml/EmptyControlStatement.xml @@ -80,8 +80,8 @@ - #432 empty try-with-resource - 0 + #432 empty try-with-resource - not ok + 1 - #432 empty try-with-resource + #432 empty try-with-resource - ok with unused var name 0 target.request(mediaTypes).delete(), DELETE, new ExpectedResponse(status, required))) { - // false positive + try (ClientResponse ignored = execute(() -> target.request(mediaTypes).delete(), DELETE, new ExpectedResponse(status, required))) { } } } @@ -160,6 +159,31 @@ ]]> + + + pos, empty block + 1 + + + + + statement block not empty + 0 + + + failure case (non static) 1 @@ -182,7 +206,7 @@ not an initializer - 0 + 1 Date: Tue, 4 Jan 2022 23:20:05 +0100 Subject: [PATCH 024/198] Cleanups, add tests --- .../codestyle/EmptyControlStatementRule.java | 5 ++ .../resources/category/java/codestyle.xml | 3 +- .../codestyle/xml/EmptyControlStatement.xml | 74 +++++++++++++++++++ 3 files changed, 81 insertions(+), 1 deletion(-) diff --git a/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/rule/codestyle/EmptyControlStatementRule.java b/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/rule/codestyle/EmptyControlStatementRule.java index b5bd64e130..47bb4ced13 100644 --- a/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/rule/codestyle/EmptyControlStatementRule.java +++ b/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/rule/codestyle/EmptyControlStatementRule.java @@ -11,6 +11,7 @@ import net.sourceforge.pmd.lang.java.ast.ASTFinallyStatement; import net.sourceforge.pmd.lang.java.ast.ASTForStatement; import net.sourceforge.pmd.lang.java.ast.ASTIfStatement; import net.sourceforge.pmd.lang.java.ast.ASTInitializer; +import net.sourceforge.pmd.lang.java.ast.ASTLocalVariableDeclaration; import net.sourceforge.pmd.lang.java.ast.ASTResource; import net.sourceforge.pmd.lang.java.ast.ASTResourceSpecification; import net.sourceforge.pmd.lang.java.ast.ASTStatement; @@ -95,6 +96,10 @@ public class EmptyControlStatementRule extends AbstractJavaRule { @Override public Object visit(ASTForStatement node, Object data) { + if (node.isForeach() && JavaRuleUtil.isExplicitUnusedVarName(node.getFirstChildOfType(ASTLocalVariableDeclaration.class).getVariableName())) { + // allow `for (ignored : iterable) {}` + return null; + } if (isEmpty(node.getBody())) { addViolation(data, node, "Empty for statement"); } diff --git a/pmd-java/src/main/resources/category/java/codestyle.xml b/pmd-java/src/main/resources/category/java/codestyle.xml index c4c00d7ce0..7c8e744911 100644 --- a/pmd-java/src/main/resources/category/java/codestyle.xml +++ b/pmd-java/src/main/resources/category/java/codestyle.xml @@ -719,6 +719,7 @@ public abstract class ShouldBeAbstract { + + + pos, empty for + 2 + 3,5 + + + + pos, empty do..while + 2 + 4,6 + + + + pos, empty foreach + 2 + 6,8 + list) { + for (int i : list) { + } + for (int i : list) ; + for (int i : list) { // neg, nonempty + System.out.println(i); + } + } + } + ]]> + + + neg, empty foreach with unused var name + 0 + list) { + for (int ignored : list) { + } + for (int ignored2 : list) ; + for (int i : list) { // neg, nonempty + System.out.println(i); + } + } + } + ]]> + pos, empty while From b23b76d57c704b380d61f71b8e97fbef26c10303 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9ment=20Fournier?= Date: Sun, 16 Jan 2022 14:57:36 +0000 Subject: [PATCH 025/198] fix url --- pmd-java/src/main/resources/category/java/codestyle.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pmd-java/src/main/resources/category/java/codestyle.xml b/pmd-java/src/main/resources/category/java/codestyle.xml index 7c8e744911..a6f04afe3d 100644 --- a/pmd-java/src/main/resources/category/java/codestyle.xml +++ b/pmd-java/src/main/resources/category/java/codestyle.xml @@ -715,7 +715,7 @@ public abstract class ShouldBeAbstract { since="6.42.0" message="This control statement has an empty branch" class="net.sourceforge.pmd.lang.java.rule.codestyle.EmptyControlStatementRule" - externalInfoUrl="${pmd.website.baseurl}/pmd_rules_java_codestyle.html#unnecessarysemicolon"> + externalInfoUrl="${pmd.website.baseurl}/pmd_rules_java_codestyle.html#emptycontrolstatement"> From 051da73ce3f63277195e83c88fbe687d08b157d1 Mon Sep 17 00:00:00 2001 From: Peter Paul Bakker Date: Thu, 20 Jan 2022 15:37:41 +0100 Subject: [PATCH 026/198] set version to 7.0.0-kotlin-SNAPSHOT to avoid mixups in 7.0.0-SNAPSHOT in sonatype snapshots repo --- .ci/build.sh | 2 +- docs/_config.yml | 2 +- pmd-apex-jorje/pom.xml | 2 +- pmd-apex/pom.xml | 2 +- pmd-core/pom.xml | 2 +- pmd-cpp/pom.xml | 2 +- pmd-cs/pom.xml | 2 +- pmd-dart/pom.xml | 2 +- pmd-dist/pom.xml | 2 +- pmd-doc/pom.xml | 2 +- pmd-fortran/pom.xml | 2 +- pmd-go/pom.xml | 2 +- pmd-groovy/pom.xml | 2 +- pmd-java/pom.xml | 2 +- pmd-javascript/pom.xml | 2 +- pmd-jsp/pom.xml | 2 +- pmd-kotlin/pom.xml | 2 +- pmd-lang-test/pom.xml | 2 +- pmd-lua/pom.xml | 2 +- pmd-matlab/pom.xml | 2 +- pmd-modelica/pom.xml | 2 +- pmd-objectivec/pom.xml | 2 +- pmd-perl/pom.xml | 2 +- pmd-php/pom.xml | 2 +- pmd-plsql/pom.xml | 2 +- pmd-python/pom.xml | 2 +- pmd-ruby/pom.xml | 2 +- pmd-scala-modules/pmd-scala-common/pom.xml | 2 +- pmd-scala-modules/pmd-scala_2.12/pom.xml | 2 +- pmd-scala-modules/pmd-scala_2.13/pom.xml | 2 +- pmd-scala/pom.xml | 2 +- pmd-swift/pom.xml | 2 +- pmd-test/pom.xml | 2 +- pmd-visualforce/pom.xml | 2 +- pmd-vm/pom.xml | 2 +- pmd-xml/pom.xml | 2 +- pom.xml | 4 ++-- 37 files changed, 38 insertions(+), 38 deletions(-) diff --git a/.ci/build.sh b/.ci/build.sh index 7bd31fb01c..44cbd93e0e 100755 --- a/.ci/build.sh +++ b/.ci/build.sh @@ -85,7 +85,7 @@ function build() { pmd_ci_log_group_end if pmd_ci_maven_isSnapshotBuild; then - if [ "${PMD_CI_MAVEN_PROJECT_VERSION}" != "7.0.0-SNAPSHOT" ]; then + if [ "${PMD_CI_MAVEN_PROJECT_VERSION}" != "7.0.0-kotlin-SNAPSHOT" ]; then pmd_ci_log_group_start "Executing PMD dogfood test with ${PMD_CI_MAVEN_PROJECT_VERSION}" ./mvnw versions:set -DnewVersion="${PMD_CI_MAVEN_PROJECT_VERSION}-dogfood" -DgenerateBackupPoms=false sed -i 's/[0-9]\{1,\}\.[0-9]\{1,\}\.[0-9]\{1,\}.*<\/version>\( *\)/'"${PMD_CI_MAVEN_PROJECT_VERSION}"'<\/version>\1/' pom.xml diff --git a/docs/_config.yml b/docs/_config.yml index ca829f79b7..fd5f9e78bd 100644 --- a/docs/_config.yml +++ b/docs/_config.yml @@ -1,7 +1,7 @@ repository: pmd/pmd pmd: - version: 7.0.0-SNAPSHOT + version: 7.0.0-kotlin-SNAPSHOT previous_version: 6.38.0 date: ??-?????-2021 release_type: major diff --git a/pmd-apex-jorje/pom.xml b/pmd-apex-jorje/pom.xml index 9c2da9d32c..fe6bb5df4d 100644 --- a/pmd-apex-jorje/pom.xml +++ b/pmd-apex-jorje/pom.xml @@ -8,7 +8,7 @@ net.sourceforge.pmd pmd - 7.0.0-SNAPSHOT + 7.0.0-kotlin-SNAPSHOT ../ diff --git a/pmd-apex/pom.xml b/pmd-apex/pom.xml index 50ede2c0da..b41351783f 100644 --- a/pmd-apex/pom.xml +++ b/pmd-apex/pom.xml @@ -7,7 +7,7 @@ net.sourceforge.pmd pmd - 7.0.0-SNAPSHOT + 7.0.0-kotlin-SNAPSHOT ../ diff --git a/pmd-core/pom.xml b/pmd-core/pom.xml index 1cdde6d0c6..aa52bbae66 100644 --- a/pmd-core/pom.xml +++ b/pmd-core/pom.xml @@ -7,7 +7,7 @@ net.sourceforge.pmd pmd - 7.0.0-SNAPSHOT + 7.0.0-kotlin-SNAPSHOT ../ diff --git a/pmd-cpp/pom.xml b/pmd-cpp/pom.xml index 5318fb16d3..d538abb570 100644 --- a/pmd-cpp/pom.xml +++ b/pmd-cpp/pom.xml @@ -7,7 +7,7 @@ net.sourceforge.pmd pmd - 7.0.0-SNAPSHOT + 7.0.0-kotlin-SNAPSHOT ../ diff --git a/pmd-cs/pom.xml b/pmd-cs/pom.xml index 35e9ba91c2..402ea218e4 100644 --- a/pmd-cs/pom.xml +++ b/pmd-cs/pom.xml @@ -7,7 +7,7 @@ net.sourceforge.pmd pmd - 7.0.0-SNAPSHOT + 7.0.0-kotlin-SNAPSHOT ../ diff --git a/pmd-dart/pom.xml b/pmd-dart/pom.xml index 3a75d27a4a..c49e39580d 100644 --- a/pmd-dart/pom.xml +++ b/pmd-dart/pom.xml @@ -7,7 +7,7 @@ net.sourceforge.pmd pmd - 7.0.0-SNAPSHOT + 7.0.0-kotlin-SNAPSHOT ../ diff --git a/pmd-dist/pom.xml b/pmd-dist/pom.xml index 7ba243789b..9be13a0621 100644 --- a/pmd-dist/pom.xml +++ b/pmd-dist/pom.xml @@ -8,7 +8,7 @@ net.sourceforge.pmd pmd - 7.0.0-SNAPSHOT + 7.0.0-kotlin-SNAPSHOT ../ diff --git a/pmd-doc/pom.xml b/pmd-doc/pom.xml index feadf8bf05..c74542137f 100644 --- a/pmd-doc/pom.xml +++ b/pmd-doc/pom.xml @@ -8,7 +8,7 @@ net.sourceforge.pmd pmd - 7.0.0-SNAPSHOT + 7.0.0-kotlin-SNAPSHOT ../ diff --git a/pmd-fortran/pom.xml b/pmd-fortran/pom.xml index aafc0e252f..5a51e32dc1 100644 --- a/pmd-fortran/pom.xml +++ b/pmd-fortran/pom.xml @@ -7,7 +7,7 @@ net.sourceforge.pmd pmd - 7.0.0-SNAPSHOT + 7.0.0-kotlin-SNAPSHOT ../ diff --git a/pmd-go/pom.xml b/pmd-go/pom.xml index c0ce17de4e..c02ae0522f 100644 --- a/pmd-go/pom.xml +++ b/pmd-go/pom.xml @@ -7,7 +7,7 @@ net.sourceforge.pmd pmd - 7.0.0-SNAPSHOT + 7.0.0-kotlin-SNAPSHOT ../ diff --git a/pmd-groovy/pom.xml b/pmd-groovy/pom.xml index 871d8ffaa9..e8ee26bb58 100644 --- a/pmd-groovy/pom.xml +++ b/pmd-groovy/pom.xml @@ -7,7 +7,7 @@ net.sourceforge.pmd pmd - 7.0.0-SNAPSHOT + 7.0.0-kotlin-SNAPSHOT ../ diff --git a/pmd-java/pom.xml b/pmd-java/pom.xml index bd5a99cdbf..409be95316 100644 --- a/pmd-java/pom.xml +++ b/pmd-java/pom.xml @@ -7,7 +7,7 @@ net.sourceforge.pmd pmd - 7.0.0-SNAPSHOT + 7.0.0-kotlin-SNAPSHOT ../ diff --git a/pmd-javascript/pom.xml b/pmd-javascript/pom.xml index 4c833adc90..d16fd36f45 100644 --- a/pmd-javascript/pom.xml +++ b/pmd-javascript/pom.xml @@ -7,7 +7,7 @@ net.sourceforge.pmd pmd - 7.0.0-SNAPSHOT + 7.0.0-kotlin-SNAPSHOT ../ diff --git a/pmd-jsp/pom.xml b/pmd-jsp/pom.xml index d2956cb7a1..e42cc01ad4 100644 --- a/pmd-jsp/pom.xml +++ b/pmd-jsp/pom.xml @@ -7,7 +7,7 @@ net.sourceforge.pmd pmd - 7.0.0-SNAPSHOT + 7.0.0-kotlin-SNAPSHOT ../ diff --git a/pmd-kotlin/pom.xml b/pmd-kotlin/pom.xml index c2e2769fb3..854d8eebcb 100644 --- a/pmd-kotlin/pom.xml +++ b/pmd-kotlin/pom.xml @@ -7,7 +7,7 @@ net.sourceforge.pmd pmd - 7.0.0-SNAPSHOT + 7.0.0-kotlin-SNAPSHOT ../ diff --git a/pmd-lang-test/pom.xml b/pmd-lang-test/pom.xml index 3f1e9bd3e8..ba4e66a8c1 100644 --- a/pmd-lang-test/pom.xml +++ b/pmd-lang-test/pom.xml @@ -12,7 +12,7 @@ net.sourceforge.pmd pmd - 7.0.0-SNAPSHOT + 7.0.0-kotlin-SNAPSHOT ../ diff --git a/pmd-lua/pom.xml b/pmd-lua/pom.xml index 921cd6335b..7927a79a3b 100644 --- a/pmd-lua/pom.xml +++ b/pmd-lua/pom.xml @@ -7,7 +7,7 @@ net.sourceforge.pmd pmd - 7.0.0-SNAPSHOT + 7.0.0-kotlin-SNAPSHOT ../ diff --git a/pmd-matlab/pom.xml b/pmd-matlab/pom.xml index d420562758..fb33fcb534 100644 --- a/pmd-matlab/pom.xml +++ b/pmd-matlab/pom.xml @@ -7,7 +7,7 @@ net.sourceforge.pmd pmd - 7.0.0-SNAPSHOT + 7.0.0-kotlin-SNAPSHOT ../ diff --git a/pmd-modelica/pom.xml b/pmd-modelica/pom.xml index bd121630ed..7b96a8ae74 100644 --- a/pmd-modelica/pom.xml +++ b/pmd-modelica/pom.xml @@ -7,7 +7,7 @@ net.sourceforge.pmd pmd - 7.0.0-SNAPSHOT + 7.0.0-kotlin-SNAPSHOT ../ diff --git a/pmd-objectivec/pom.xml b/pmd-objectivec/pom.xml index 1933b45325..6db7aea150 100644 --- a/pmd-objectivec/pom.xml +++ b/pmd-objectivec/pom.xml @@ -7,7 +7,7 @@ net.sourceforge.pmd pmd - 7.0.0-SNAPSHOT + 7.0.0-kotlin-SNAPSHOT ../ diff --git a/pmd-perl/pom.xml b/pmd-perl/pom.xml index 513a9e3c01..9c262e79b6 100644 --- a/pmd-perl/pom.xml +++ b/pmd-perl/pom.xml @@ -7,7 +7,7 @@ net.sourceforge.pmd pmd - 7.0.0-SNAPSHOT + 7.0.0-kotlin-SNAPSHOT ../ diff --git a/pmd-php/pom.xml b/pmd-php/pom.xml index 77f74d4119..e701914499 100644 --- a/pmd-php/pom.xml +++ b/pmd-php/pom.xml @@ -7,7 +7,7 @@ net.sourceforge.pmd pmd - 7.0.0-SNAPSHOT + 7.0.0-kotlin-SNAPSHOT ../ diff --git a/pmd-plsql/pom.xml b/pmd-plsql/pom.xml index 2077473533..633467480f 100644 --- a/pmd-plsql/pom.xml +++ b/pmd-plsql/pom.xml @@ -7,7 +7,7 @@ net.sourceforge.pmd pmd - 7.0.0-SNAPSHOT + 7.0.0-kotlin-SNAPSHOT ../ diff --git a/pmd-python/pom.xml b/pmd-python/pom.xml index f0ec5e583b..def5b8a85c 100644 --- a/pmd-python/pom.xml +++ b/pmd-python/pom.xml @@ -7,7 +7,7 @@ net.sourceforge.pmd pmd - 7.0.0-SNAPSHOT + 7.0.0-kotlin-SNAPSHOT ../ diff --git a/pmd-ruby/pom.xml b/pmd-ruby/pom.xml index 0d7c4f9b48..8da41b5554 100644 --- a/pmd-ruby/pom.xml +++ b/pmd-ruby/pom.xml @@ -7,7 +7,7 @@ net.sourceforge.pmd pmd - 7.0.0-SNAPSHOT + 7.0.0-kotlin-SNAPSHOT ../ diff --git a/pmd-scala-modules/pmd-scala-common/pom.xml b/pmd-scala-modules/pmd-scala-common/pom.xml index 60daacafd8..9b9d414b33 100644 --- a/pmd-scala-modules/pmd-scala-common/pom.xml +++ b/pmd-scala-modules/pmd-scala-common/pom.xml @@ -8,7 +8,7 @@ net.sourceforge.pmd pmd - 7.0.0-SNAPSHOT + 7.0.0-kotlin-SNAPSHOT ../.. diff --git a/pmd-scala-modules/pmd-scala_2.12/pom.xml b/pmd-scala-modules/pmd-scala_2.12/pom.xml index cfec80a6fc..393708c3f3 100644 --- a/pmd-scala-modules/pmd-scala_2.12/pom.xml +++ b/pmd-scala-modules/pmd-scala_2.12/pom.xml @@ -7,7 +7,7 @@ net.sourceforge.pmd pmd-scala-common - 7.0.0-SNAPSHOT + 7.0.0-kotlin-SNAPSHOT ../pmd-scala-common diff --git a/pmd-scala-modules/pmd-scala_2.13/pom.xml b/pmd-scala-modules/pmd-scala_2.13/pom.xml index 3ec2f3a427..6c80c3ca88 100644 --- a/pmd-scala-modules/pmd-scala_2.13/pom.xml +++ b/pmd-scala-modules/pmd-scala_2.13/pom.xml @@ -7,7 +7,7 @@ net.sourceforge.pmd pmd-scala-common - 7.0.0-SNAPSHOT + 7.0.0-kotlin-SNAPSHOT ../pmd-scala-common diff --git a/pmd-scala/pom.xml b/pmd-scala/pom.xml index 27919731cd..ef4a7db8ec 100644 --- a/pmd-scala/pom.xml +++ b/pmd-scala/pom.xml @@ -9,7 +9,7 @@ net.sourceforge.pmd pmd - 7.0.0-SNAPSHOT + 7.0.0-kotlin-SNAPSHOT ../ diff --git a/pmd-swift/pom.xml b/pmd-swift/pom.xml index 378ed67bef..9700996b8b 100644 --- a/pmd-swift/pom.xml +++ b/pmd-swift/pom.xml @@ -7,7 +7,7 @@ net.sourceforge.pmd pmd - 7.0.0-SNAPSHOT + 7.0.0-kotlin-SNAPSHOT ../ diff --git a/pmd-test/pom.xml b/pmd-test/pom.xml index 31ffb0a5e5..286a24d77b 100644 --- a/pmd-test/pom.xml +++ b/pmd-test/pom.xml @@ -8,7 +8,7 @@ net.sourceforge.pmd pmd - 7.0.0-SNAPSHOT + 7.0.0-kotlin-SNAPSHOT ../ diff --git a/pmd-visualforce/pom.xml b/pmd-visualforce/pom.xml index bb3ae9a749..979317b7ad 100644 --- a/pmd-visualforce/pom.xml +++ b/pmd-visualforce/pom.xml @@ -7,7 +7,7 @@ net.sourceforge.pmd pmd - 7.0.0-SNAPSHOT + 7.0.0-kotlin-SNAPSHOT ../ diff --git a/pmd-vm/pom.xml b/pmd-vm/pom.xml index db497b272c..7e68a119d0 100644 --- a/pmd-vm/pom.xml +++ b/pmd-vm/pom.xml @@ -7,7 +7,7 @@ net.sourceforge.pmd pmd - 7.0.0-SNAPSHOT + 7.0.0-kotlin-SNAPSHOT ../ diff --git a/pmd-xml/pom.xml b/pmd-xml/pom.xml index e0d09c9a3f..a93e11f442 100644 --- a/pmd-xml/pom.xml +++ b/pmd-xml/pom.xml @@ -7,7 +7,7 @@ net.sourceforge.pmd pmd - 7.0.0-SNAPSHOT + 7.0.0-kotlin-SNAPSHOT ../ diff --git a/pom.xml b/pom.xml index d79fde117f..d607081f5b 100644 --- a/pom.xml +++ b/pom.xml @@ -3,7 +3,7 @@ 4.0.0 net.sourceforge.pmd pmd - 7.0.0-SNAPSHOT + 7.0.0-kotlin-SNAPSHOT pom PMD @@ -107,7 +107,7 @@ 16 - 7.0.0-SNAPSHOT + 7.0.0-kotlin-SNAPSHOT ${settings.localRepository}/net/java/dev/javacc/javacc/${javacc.version}/javacc-${javacc.version}.jar ${project.build.directory}/generated-sources/javacc ${project.basedir}/../javacc-wrapper.xml From d826c3574edbbd880835d46bae133ff9bdfb2798 Mon Sep 17 00:00:00 2001 From: Andreas Dangel Date: Fri, 25 Feb 2022 15:16:35 +0100 Subject: [PATCH 027/198] Revert "set version to 7.0.0-kotlin-SNAPSHOT to avoid mixups in 7.0.0-SNAPSHOT in sonatype snapshots repo" This reverts commit 051da73ce3f63277195e83c88fbe687d08b157d1. --- .ci/build.sh | 2 +- docs/_config.yml | 2 +- pmd-apex-jorje/pom.xml | 2 +- pmd-apex/pom.xml | 2 +- pmd-core/pom.xml | 2 +- pmd-cpp/pom.xml | 2 +- pmd-cs/pom.xml | 2 +- pmd-dart/pom.xml | 2 +- pmd-dist/pom.xml | 2 +- pmd-doc/pom.xml | 2 +- pmd-fortran/pom.xml | 2 +- pmd-go/pom.xml | 2 +- pmd-groovy/pom.xml | 2 +- pmd-java/pom.xml | 2 +- pmd-javascript/pom.xml | 2 +- pmd-jsp/pom.xml | 2 +- pmd-kotlin/pom.xml | 2 +- pmd-lang-test/pom.xml | 2 +- pmd-lua/pom.xml | 2 +- pmd-matlab/pom.xml | 2 +- pmd-modelica/pom.xml | 2 +- pmd-objectivec/pom.xml | 2 +- pmd-perl/pom.xml | 2 +- pmd-php/pom.xml | 2 +- pmd-plsql/pom.xml | 2 +- pmd-python/pom.xml | 2 +- pmd-ruby/pom.xml | 2 +- pmd-scala-modules/pmd-scala-common/pom.xml | 2 +- pmd-scala-modules/pmd-scala_2.12/pom.xml | 2 +- pmd-scala-modules/pmd-scala_2.13/pom.xml | 2 +- pmd-scala/pom.xml | 2 +- pmd-swift/pom.xml | 2 +- pmd-test/pom.xml | 2 +- pmd-visualforce/pom.xml | 2 +- pmd-vm/pom.xml | 2 +- pmd-xml/pom.xml | 2 +- pom.xml | 4 ++-- 37 files changed, 38 insertions(+), 38 deletions(-) diff --git a/.ci/build.sh b/.ci/build.sh index 44cbd93e0e..7bd31fb01c 100755 --- a/.ci/build.sh +++ b/.ci/build.sh @@ -85,7 +85,7 @@ function build() { pmd_ci_log_group_end if pmd_ci_maven_isSnapshotBuild; then - if [ "${PMD_CI_MAVEN_PROJECT_VERSION}" != "7.0.0-kotlin-SNAPSHOT" ]; then + if [ "${PMD_CI_MAVEN_PROJECT_VERSION}" != "7.0.0-SNAPSHOT" ]; then pmd_ci_log_group_start "Executing PMD dogfood test with ${PMD_CI_MAVEN_PROJECT_VERSION}" ./mvnw versions:set -DnewVersion="${PMD_CI_MAVEN_PROJECT_VERSION}-dogfood" -DgenerateBackupPoms=false sed -i 's/[0-9]\{1,\}\.[0-9]\{1,\}\.[0-9]\{1,\}.*<\/version>\( *\)/'"${PMD_CI_MAVEN_PROJECT_VERSION}"'<\/version>\1/' pom.xml diff --git a/docs/_config.yml b/docs/_config.yml index fd5f9e78bd..ca829f79b7 100644 --- a/docs/_config.yml +++ b/docs/_config.yml @@ -1,7 +1,7 @@ repository: pmd/pmd pmd: - version: 7.0.0-kotlin-SNAPSHOT + version: 7.0.0-SNAPSHOT previous_version: 6.38.0 date: ??-?????-2021 release_type: major diff --git a/pmd-apex-jorje/pom.xml b/pmd-apex-jorje/pom.xml index fe6bb5df4d..9c2da9d32c 100644 --- a/pmd-apex-jorje/pom.xml +++ b/pmd-apex-jorje/pom.xml @@ -8,7 +8,7 @@ net.sourceforge.pmd pmd - 7.0.0-kotlin-SNAPSHOT + 7.0.0-SNAPSHOT ../ diff --git a/pmd-apex/pom.xml b/pmd-apex/pom.xml index b41351783f..50ede2c0da 100644 --- a/pmd-apex/pom.xml +++ b/pmd-apex/pom.xml @@ -7,7 +7,7 @@ net.sourceforge.pmd pmd - 7.0.0-kotlin-SNAPSHOT + 7.0.0-SNAPSHOT ../ diff --git a/pmd-core/pom.xml b/pmd-core/pom.xml index aa52bbae66..1cdde6d0c6 100644 --- a/pmd-core/pom.xml +++ b/pmd-core/pom.xml @@ -7,7 +7,7 @@ net.sourceforge.pmd pmd - 7.0.0-kotlin-SNAPSHOT + 7.0.0-SNAPSHOT ../ diff --git a/pmd-cpp/pom.xml b/pmd-cpp/pom.xml index d538abb570..5318fb16d3 100644 --- a/pmd-cpp/pom.xml +++ b/pmd-cpp/pom.xml @@ -7,7 +7,7 @@ net.sourceforge.pmd pmd - 7.0.0-kotlin-SNAPSHOT + 7.0.0-SNAPSHOT ../ diff --git a/pmd-cs/pom.xml b/pmd-cs/pom.xml index 402ea218e4..35e9ba91c2 100644 --- a/pmd-cs/pom.xml +++ b/pmd-cs/pom.xml @@ -7,7 +7,7 @@ net.sourceforge.pmd pmd - 7.0.0-kotlin-SNAPSHOT + 7.0.0-SNAPSHOT ../ diff --git a/pmd-dart/pom.xml b/pmd-dart/pom.xml index c49e39580d..3a75d27a4a 100644 --- a/pmd-dart/pom.xml +++ b/pmd-dart/pom.xml @@ -7,7 +7,7 @@ net.sourceforge.pmd pmd - 7.0.0-kotlin-SNAPSHOT + 7.0.0-SNAPSHOT ../ diff --git a/pmd-dist/pom.xml b/pmd-dist/pom.xml index 9be13a0621..7ba243789b 100644 --- a/pmd-dist/pom.xml +++ b/pmd-dist/pom.xml @@ -8,7 +8,7 @@ net.sourceforge.pmd pmd - 7.0.0-kotlin-SNAPSHOT + 7.0.0-SNAPSHOT ../ diff --git a/pmd-doc/pom.xml b/pmd-doc/pom.xml index c74542137f..feadf8bf05 100644 --- a/pmd-doc/pom.xml +++ b/pmd-doc/pom.xml @@ -8,7 +8,7 @@ net.sourceforge.pmd pmd - 7.0.0-kotlin-SNAPSHOT + 7.0.0-SNAPSHOT ../ diff --git a/pmd-fortran/pom.xml b/pmd-fortran/pom.xml index 5a51e32dc1..aafc0e252f 100644 --- a/pmd-fortran/pom.xml +++ b/pmd-fortran/pom.xml @@ -7,7 +7,7 @@ net.sourceforge.pmd pmd - 7.0.0-kotlin-SNAPSHOT + 7.0.0-SNAPSHOT ../ diff --git a/pmd-go/pom.xml b/pmd-go/pom.xml index c02ae0522f..c0ce17de4e 100644 --- a/pmd-go/pom.xml +++ b/pmd-go/pom.xml @@ -7,7 +7,7 @@ net.sourceforge.pmd pmd - 7.0.0-kotlin-SNAPSHOT + 7.0.0-SNAPSHOT ../ diff --git a/pmd-groovy/pom.xml b/pmd-groovy/pom.xml index e8ee26bb58..871d8ffaa9 100644 --- a/pmd-groovy/pom.xml +++ b/pmd-groovy/pom.xml @@ -7,7 +7,7 @@ net.sourceforge.pmd pmd - 7.0.0-kotlin-SNAPSHOT + 7.0.0-SNAPSHOT ../ diff --git a/pmd-java/pom.xml b/pmd-java/pom.xml index 409be95316..bd5a99cdbf 100644 --- a/pmd-java/pom.xml +++ b/pmd-java/pom.xml @@ -7,7 +7,7 @@ net.sourceforge.pmd pmd - 7.0.0-kotlin-SNAPSHOT + 7.0.0-SNAPSHOT ../ diff --git a/pmd-javascript/pom.xml b/pmd-javascript/pom.xml index d16fd36f45..4c833adc90 100644 --- a/pmd-javascript/pom.xml +++ b/pmd-javascript/pom.xml @@ -7,7 +7,7 @@ net.sourceforge.pmd pmd - 7.0.0-kotlin-SNAPSHOT + 7.0.0-SNAPSHOT ../ diff --git a/pmd-jsp/pom.xml b/pmd-jsp/pom.xml index e42cc01ad4..d2956cb7a1 100644 --- a/pmd-jsp/pom.xml +++ b/pmd-jsp/pom.xml @@ -7,7 +7,7 @@ net.sourceforge.pmd pmd - 7.0.0-kotlin-SNAPSHOT + 7.0.0-SNAPSHOT ../ diff --git a/pmd-kotlin/pom.xml b/pmd-kotlin/pom.xml index 854d8eebcb..c2e2769fb3 100644 --- a/pmd-kotlin/pom.xml +++ b/pmd-kotlin/pom.xml @@ -7,7 +7,7 @@ net.sourceforge.pmd pmd - 7.0.0-kotlin-SNAPSHOT + 7.0.0-SNAPSHOT ../ diff --git a/pmd-lang-test/pom.xml b/pmd-lang-test/pom.xml index ba4e66a8c1..3f1e9bd3e8 100644 --- a/pmd-lang-test/pom.xml +++ b/pmd-lang-test/pom.xml @@ -12,7 +12,7 @@ net.sourceforge.pmd pmd - 7.0.0-kotlin-SNAPSHOT + 7.0.0-SNAPSHOT ../ diff --git a/pmd-lua/pom.xml b/pmd-lua/pom.xml index 7927a79a3b..921cd6335b 100644 --- a/pmd-lua/pom.xml +++ b/pmd-lua/pom.xml @@ -7,7 +7,7 @@ net.sourceforge.pmd pmd - 7.0.0-kotlin-SNAPSHOT + 7.0.0-SNAPSHOT ../ diff --git a/pmd-matlab/pom.xml b/pmd-matlab/pom.xml index fb33fcb534..d420562758 100644 --- a/pmd-matlab/pom.xml +++ b/pmd-matlab/pom.xml @@ -7,7 +7,7 @@ net.sourceforge.pmd pmd - 7.0.0-kotlin-SNAPSHOT + 7.0.0-SNAPSHOT ../ diff --git a/pmd-modelica/pom.xml b/pmd-modelica/pom.xml index 7b96a8ae74..bd121630ed 100644 --- a/pmd-modelica/pom.xml +++ b/pmd-modelica/pom.xml @@ -7,7 +7,7 @@ net.sourceforge.pmd pmd - 7.0.0-kotlin-SNAPSHOT + 7.0.0-SNAPSHOT ../ diff --git a/pmd-objectivec/pom.xml b/pmd-objectivec/pom.xml index 6db7aea150..1933b45325 100644 --- a/pmd-objectivec/pom.xml +++ b/pmd-objectivec/pom.xml @@ -7,7 +7,7 @@ net.sourceforge.pmd pmd - 7.0.0-kotlin-SNAPSHOT + 7.0.0-SNAPSHOT ../ diff --git a/pmd-perl/pom.xml b/pmd-perl/pom.xml index 9c262e79b6..513a9e3c01 100644 --- a/pmd-perl/pom.xml +++ b/pmd-perl/pom.xml @@ -7,7 +7,7 @@ net.sourceforge.pmd pmd - 7.0.0-kotlin-SNAPSHOT + 7.0.0-SNAPSHOT ../ diff --git a/pmd-php/pom.xml b/pmd-php/pom.xml index e701914499..77f74d4119 100644 --- a/pmd-php/pom.xml +++ b/pmd-php/pom.xml @@ -7,7 +7,7 @@ net.sourceforge.pmd pmd - 7.0.0-kotlin-SNAPSHOT + 7.0.0-SNAPSHOT ../ diff --git a/pmd-plsql/pom.xml b/pmd-plsql/pom.xml index 633467480f..2077473533 100644 --- a/pmd-plsql/pom.xml +++ b/pmd-plsql/pom.xml @@ -7,7 +7,7 @@ net.sourceforge.pmd pmd - 7.0.0-kotlin-SNAPSHOT + 7.0.0-SNAPSHOT ../ diff --git a/pmd-python/pom.xml b/pmd-python/pom.xml index def5b8a85c..f0ec5e583b 100644 --- a/pmd-python/pom.xml +++ b/pmd-python/pom.xml @@ -7,7 +7,7 @@ net.sourceforge.pmd pmd - 7.0.0-kotlin-SNAPSHOT + 7.0.0-SNAPSHOT ../ diff --git a/pmd-ruby/pom.xml b/pmd-ruby/pom.xml index 8da41b5554..0d7c4f9b48 100644 --- a/pmd-ruby/pom.xml +++ b/pmd-ruby/pom.xml @@ -7,7 +7,7 @@ net.sourceforge.pmd pmd - 7.0.0-kotlin-SNAPSHOT + 7.0.0-SNAPSHOT ../ diff --git a/pmd-scala-modules/pmd-scala-common/pom.xml b/pmd-scala-modules/pmd-scala-common/pom.xml index 9b9d414b33..60daacafd8 100644 --- a/pmd-scala-modules/pmd-scala-common/pom.xml +++ b/pmd-scala-modules/pmd-scala-common/pom.xml @@ -8,7 +8,7 @@ net.sourceforge.pmd pmd - 7.0.0-kotlin-SNAPSHOT + 7.0.0-SNAPSHOT ../.. diff --git a/pmd-scala-modules/pmd-scala_2.12/pom.xml b/pmd-scala-modules/pmd-scala_2.12/pom.xml index 393708c3f3..cfec80a6fc 100644 --- a/pmd-scala-modules/pmd-scala_2.12/pom.xml +++ b/pmd-scala-modules/pmd-scala_2.12/pom.xml @@ -7,7 +7,7 @@ net.sourceforge.pmd pmd-scala-common - 7.0.0-kotlin-SNAPSHOT + 7.0.0-SNAPSHOT ../pmd-scala-common diff --git a/pmd-scala-modules/pmd-scala_2.13/pom.xml b/pmd-scala-modules/pmd-scala_2.13/pom.xml index 6c80c3ca88..3ec2f3a427 100644 --- a/pmd-scala-modules/pmd-scala_2.13/pom.xml +++ b/pmd-scala-modules/pmd-scala_2.13/pom.xml @@ -7,7 +7,7 @@ net.sourceforge.pmd pmd-scala-common - 7.0.0-kotlin-SNAPSHOT + 7.0.0-SNAPSHOT ../pmd-scala-common diff --git a/pmd-scala/pom.xml b/pmd-scala/pom.xml index ef4a7db8ec..27919731cd 100644 --- a/pmd-scala/pom.xml +++ b/pmd-scala/pom.xml @@ -9,7 +9,7 @@ net.sourceforge.pmd pmd - 7.0.0-kotlin-SNAPSHOT + 7.0.0-SNAPSHOT ../ diff --git a/pmd-swift/pom.xml b/pmd-swift/pom.xml index 9700996b8b..378ed67bef 100644 --- a/pmd-swift/pom.xml +++ b/pmd-swift/pom.xml @@ -7,7 +7,7 @@ net.sourceforge.pmd pmd - 7.0.0-kotlin-SNAPSHOT + 7.0.0-SNAPSHOT ../ diff --git a/pmd-test/pom.xml b/pmd-test/pom.xml index 286a24d77b..31ffb0a5e5 100644 --- a/pmd-test/pom.xml +++ b/pmd-test/pom.xml @@ -8,7 +8,7 @@ net.sourceforge.pmd pmd - 7.0.0-kotlin-SNAPSHOT + 7.0.0-SNAPSHOT ../ diff --git a/pmd-visualforce/pom.xml b/pmd-visualforce/pom.xml index 979317b7ad..bb3ae9a749 100644 --- a/pmd-visualforce/pom.xml +++ b/pmd-visualforce/pom.xml @@ -7,7 +7,7 @@ net.sourceforge.pmd pmd - 7.0.0-kotlin-SNAPSHOT + 7.0.0-SNAPSHOT ../ diff --git a/pmd-vm/pom.xml b/pmd-vm/pom.xml index 7e68a119d0..db497b272c 100644 --- a/pmd-vm/pom.xml +++ b/pmd-vm/pom.xml @@ -7,7 +7,7 @@ net.sourceforge.pmd pmd - 7.0.0-kotlin-SNAPSHOT + 7.0.0-SNAPSHOT ../ diff --git a/pmd-xml/pom.xml b/pmd-xml/pom.xml index a93e11f442..e0d09c9a3f 100644 --- a/pmd-xml/pom.xml +++ b/pmd-xml/pom.xml @@ -7,7 +7,7 @@ net.sourceforge.pmd pmd - 7.0.0-kotlin-SNAPSHOT + 7.0.0-SNAPSHOT ../ diff --git a/pom.xml b/pom.xml index d607081f5b..d79fde117f 100644 --- a/pom.xml +++ b/pom.xml @@ -3,7 +3,7 @@ 4.0.0 net.sourceforge.pmd pmd - 7.0.0-kotlin-SNAPSHOT + 7.0.0-SNAPSHOT pom PMD @@ -107,7 +107,7 @@ 16 - 7.0.0-kotlin-SNAPSHOT + 7.0.0-SNAPSHOT ${settings.localRepository}/net/java/dev/javacc/javacc/${javacc.version}/javacc-${javacc.version}.jar ${project.build.directory}/generated-sources/javacc ${project.basedir}/../javacc-wrapper.xml From b21cb6a9fcbea254053d59ed7ae542cad92efde5 Mon Sep 17 00:00:00 2001 From: Andreas Dangel Date: Fri, 25 Feb 2022 15:33:19 +0100 Subject: [PATCH 028/198] Fix BinaryDistributionIT - kotlin is now one of the PMD languages --- .../test/java/net/sourceforge/pmd/it/BinaryDistributionIT.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 fb3fe71831..34207cfb53 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 @@ -27,7 +27,7 @@ public class BinaryDistributionIT extends AbstractBinaryDistributionTest { static { SUPPORTED_LANGUAGES_CPD = "Supported languages: [apex, cpp, cs, dart, ecmascript, fortran, go, groovy, java, jsp, kotlin, lua, matlab, modelica, objectivec, perl, php, plsql, python, ruby, scala, swift, vf, xml]"; - SUPPORTED_LANGUAGES_PMD = "apex, ecmascript, java, jsp, modelica, plsql, pom, scala, swift, vf, vm, wsdl, xml, xsl"; + SUPPORTED_LANGUAGES_PMD = "apex, ecmascript, java, jsp, kotlin, modelica, plsql, pom, scala, swift, vf, vm, wsdl, xml, xsl"; } @Test From e934efb3bcbadb5448e4c59a009dca3cf14a4090 Mon Sep 17 00:00:00 2001 From: Andreas Dangel Date: Fri, 25 Feb 2022 15:35:11 +0100 Subject: [PATCH 029/198] [doc] Kotlin rules in sidebar --- docs/_data/sidebars/pmd_sidebar.yml | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/docs/_data/sidebars/pmd_sidebar.yml b/docs/_data/sidebars/pmd_sidebar.yml index 0d00f0602c..45c662068f 100644 --- a/docs/_data/sidebars/pmd_sidebar.yml +++ b/docs/_data/sidebars/pmd_sidebar.yml @@ -232,6 +232,18 @@ entries: - title: Security output: web, pdf url: /pmd_rules_jsp_security.html + - title: null + output: web, pdf + subfolders: + - title: Kotlin Rules + output: web, pdf + subfolderitems: + - title: Index + output: web, pdf + url: /pmd_rules_kotlin.html + - title: Best Practices + output: web, pdf + url: /pmd_rules_kotlin_bestpractices.html - title: null output: web, pdf subfolders: From 22bc2f046330514f183e0ee581c2e55c6bf9fd35 Mon Sep 17 00:00:00 2001 From: Andreas Dangel Date: Thu, 3 Mar 2022 20:22:42 +0100 Subject: [PATCH 030/198] KotlinLexer doesn't need to be executable --- .../antlr4/net/sourceforge/pmd/lang/kotlin/ast/KotlinLexer.g4 | 0 1 file changed, 0 insertions(+), 0 deletions(-) mode change 100755 => 100644 pmd-kotlin/src/main/antlr4/net/sourceforge/pmd/lang/kotlin/ast/KotlinLexer.g4 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 old mode 100755 new mode 100644 From 4566ed4f16d2077572d04f2451062c45dc3d141b Mon Sep 17 00:00:00 2001 From: Andreas Dangel Date: Thu, 3 Mar 2022 20:46:06 +0100 Subject: [PATCH 031/198] Update Kotlin Grammar to 1.6-rfc+0.1 Keep the grammar as original as possible --- .../sourceforge/pmd/lang/kotlin/ast/Kotlin.g4 | 2 +- .../pmd/lang/kotlin/ast/KotlinLexer.g4 | 9 +- .../pmd/lang/kotlin/ast/KotlinLexer.tokens | 552 +++++++++--------- .../sourceforge/pmd/lang/kotlin/ast/README.md | 44 ++ .../pmd/lang/kotlin/KotlinHandler.java | 11 - .../pmd/lang/kotlin/KotlinLanguageModule.java | 4 +- .../pmd/lang/kotlin/ast/KotlinRootNode.java | 10 +- .../pmd/lang/kotlin/ast/PmdKotlinParser.java | 8 +- .../lang/kotlin/ast/KotlinParsingHelper.java | 4 +- .../pmd/lang/kotlin/ast/testdata/Simple.txt | 2 +- 10 files changed, 337 insertions(+), 309 deletions(-) create mode 100644 pmd-kotlin/src/main/antlr4/net/sourceforge/pmd/lang/kotlin/ast/README.md 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 885fb61b91..99aecafb6e 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 @@ -32,7 +32,7 @@ options { // SECTION: general -file +kotlinFile : shebangLine? NL* fileAnnotation* packageHeader importList topLevelObject* EOF ; 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 02d9d5736a..418a5e5b01 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 @@ -6,8 +6,6 @@ lexer grammar KotlinLexer; import UnicodeClasses; -options { tokenVocab = UnicodeClasses; } - // SECTION: lexicalGeneral ShebangLine @@ -325,12 +323,11 @@ fragment EscapeSeq // SECTION: characters fragment Letter - : UNICODE_CLASS_LL + : UNICODE_CLASS_LU + | UNICODE_CLASS_LL + | UNICODE_CLASS_LT | UNICODE_CLASS_LM | UNICODE_CLASS_LO - | UNICODE_CLASS_LT - | UNICODE_CLASS_LU - | UNICODE_CLASS_NL ; // SECTION: strings 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 df481370e5..a207d69c19 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 @@ -1,160 +1,160 @@ -UNICODE_CLASS_LL=1 -UNICODE_CLASS_LM=2 -UNICODE_CLASS_LO=3 -UNICODE_CLASS_LT=4 -UNICODE_CLASS_LU=5 -UNICODE_CLASS_ND=6 -UNICODE_CLASS_NL=7 -ShebangLine=8 -DelimitedComment=9 -LineComment=10 -WS=11 -NL=12 -RESERVED=13 -DOT=14 -COMMA=15 -LPAREN=16 -RPAREN=17 -LSQUARE=18 -RSQUARE=19 -LCURL=20 -RCURL=21 -MULT=22 -MOD=23 -DIV=24 -ADD=25 -SUB=26 -INCR=27 -DECR=28 -CONJ=29 -DISJ=30 -EXCL_WS=31 -EXCL_NO_WS=32 -COLON=33 -SEMICOLON=34 -ASSIGNMENT=35 -ADD_ASSIGNMENT=36 -SUB_ASSIGNMENT=37 -MULT_ASSIGNMENT=38 -DIV_ASSIGNMENT=39 -MOD_ASSIGNMENT=40 -ARROW=41 -DOUBLE_ARROW=42 -RANGE=43 -COLONCOLON=44 -DOUBLE_SEMICOLON=45 -HASH=46 -AT_NO_WS=47 -AT_POST_WS=48 -AT_PRE_WS=49 -AT_BOTH_WS=50 -QUEST_WS=51 -QUEST_NO_WS=52 -LANGLE=53 -RANGLE=54 -LE=55 -GE=56 -EXCL_EQ=57 -EXCL_EQEQ=58 -AS_SAFE=59 -EQEQ=60 -EQEQEQ=61 -SINGLE_QUOTE=62 -RETURN_AT=63 -CONTINUE_AT=64 -BREAK_AT=65 -THIS_AT=66 -SUPER_AT=67 -FILE=68 -FIELD=69 -PROPERTY=70 -GET=71 -SET=72 -RECEIVER=73 -PARAM=74 -SETPARAM=75 -DELEGATE=76 -PACKAGE=77 -IMPORT=78 -CLASS=79 -INTERFACE=80 -FUN=81 -OBJECT=82 -VAL=83 -VAR=84 -TYPE_ALIAS=85 -CONSTRUCTOR=86 -BY=87 -COMPANION=88 -INIT=89 -THIS=90 -SUPER=91 -TYPEOF=92 -WHERE=93 -IF=94 -ELSE=95 -WHEN=96 -TRY=97 -CATCH=98 -FINALLY=99 -FOR=100 -DO=101 -WHILE=102 -THROW=103 -RETURN=104 -CONTINUE=105 -BREAK=106 -AS=107 -IS=108 -IN=109 -NOT_IS=110 -NOT_IN=111 -OUT=112 -DYNAMIC=113 -PUBLIC=114 -PRIVATE=115 -PROTECTED=116 -INTERNAL=117 -ENUM=118 -SEALED=119 -ANNOTATION=120 -DATA=121 -INNER=122 -VALUE=123 -TAILREC=124 -OPERATOR=125 -INLINE=126 -INFIX=127 -EXTERNAL=128 -SUSPEND=129 -OVERRIDE=130 -ABSTRACT=131 -FINAL=132 -OPEN=133 -CONST=134 -LATEINIT=135 -VARARG=136 -NOINLINE=137 -CROSSINLINE=138 -REIFIED=139 -EXPECT=140 -ACTUAL=141 -RealLiteral=142 -FloatLiteral=143 -DoubleLiteral=144 -IntegerLiteral=145 -HexLiteral=146 -BinLiteral=147 -UnsignedLiteral=148 -LongLiteral=149 -BooleanLiteral=150 -NullLiteral=151 -CharacterLiteral=152 -Identifier=153 -IdentifierOrSoftKey=154 -FieldIdentifier=155 -QUOTE_OPEN=156 -TRIPLE_QUOTE_OPEN=157 +ShebangLine=1 +DelimitedComment=2 +LineComment=3 +WS=4 +NL=5 +RESERVED=6 +DOT=7 +COMMA=8 +LPAREN=9 +RPAREN=10 +LSQUARE=11 +RSQUARE=12 +LCURL=13 +RCURL=14 +MULT=15 +MOD=16 +DIV=17 +ADD=18 +SUB=19 +INCR=20 +DECR=21 +CONJ=22 +DISJ=23 +EXCL_WS=24 +EXCL_NO_WS=25 +COLON=26 +SEMICOLON=27 +ASSIGNMENT=28 +ADD_ASSIGNMENT=29 +SUB_ASSIGNMENT=30 +MULT_ASSIGNMENT=31 +DIV_ASSIGNMENT=32 +MOD_ASSIGNMENT=33 +ARROW=34 +DOUBLE_ARROW=35 +RANGE=36 +COLONCOLON=37 +DOUBLE_SEMICOLON=38 +HASH=39 +AT_NO_WS=40 +AT_POST_WS=41 +AT_PRE_WS=42 +AT_BOTH_WS=43 +QUEST_WS=44 +QUEST_NO_WS=45 +LANGLE=46 +RANGLE=47 +LE=48 +GE=49 +EXCL_EQ=50 +EXCL_EQEQ=51 +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 @@ -169,122 +169,122 @@ Inside_Comment=168 Inside_WS=169 Inside_NL=170 ErrorCharacter=171 -'...'=13 -'.'=14 -','=15 -'('=16 -')'=17 -'['=18 -']'=19 -'{'=20 -'}'=21 -'*'=22 -'%'=23 -'/'=24 -'+'=25 -'-'=26 -'++'=27 -'--'=28 -'&&'=29 -'||'=30 -'!'=32 -':'=33 -';'=34 -'='=35 -'+='=36 -'-='=37 -'*='=38 -'/='=39 -'%='=40 -'->'=41 -'=>'=42 -'..'=43 -'::'=44 -';;'=45 -'#'=46 -'@'=47 -'?'=52 -'<'=53 -'>'=54 -'<='=55 -'>='=56 -'!='=57 -'!=='=58 -'as?'=59 -'=='=60 -'==='=61 -'\''=62 -'file'=68 -'field'=69 -'property'=70 -'get'=71 -'set'=72 -'receiver'=73 -'param'=74 -'setparam'=75 -'delegate'=76 -'package'=77 -'import'=78 -'class'=79 -'interface'=80 -'fun'=81 -'object'=82 -'val'=83 -'var'=84 -'typealias'=85 -'constructor'=86 -'by'=87 -'companion'=88 -'init'=89 -'this'=90 -'super'=91 -'typeof'=92 -'where'=93 -'if'=94 -'else'=95 -'when'=96 -'try'=97 -'catch'=98 -'finally'=99 -'for'=100 -'do'=101 -'while'=102 -'throw'=103 -'return'=104 -'continue'=105 -'break'=106 -'as'=107 -'is'=108 -'in'=109 -'out'=112 -'dynamic'=113 -'public'=114 -'private'=115 -'protected'=116 -'internal'=117 -'enum'=118 -'sealed'=119 -'annotation'=120 -'data'=121 -'inner'=122 -'value'=123 -'tailrec'=124 -'operator'=125 -'inline'=126 -'infix'=127 -'external'=128 -'suspend'=129 -'override'=130 -'abstract'=131 -'final'=132 -'open'=133 -'const'=134 -'lateinit'=135 -'vararg'=136 -'noinline'=137 -'crossinline'=138 -'reified'=139 -'expect'=140 -'actual'=141 -'null'=151 -'"""'=157 +'...'=6 +'.'=7 +','=8 +'('=9 +')'=10 +'['=11 +']'=12 +'{'=13 +'}'=14 +'*'=15 +'%'=16 +'/'=17 +'+'=18 +'-'=19 +'++'=20 +'--'=21 +'&&'=22 +'||'=23 +'!'=25 +':'=26 +';'=27 +'='=28 +'+='=29 +'-='=30 +'*='=31 +'/='=32 +'%='=33 +'->'=34 +'=>'=35 +'..'=36 +'::'=37 +';;'=38 +'#'=39 +'@'=40 +'?'=45 +'<'=46 +'>'=47 +'<='=48 +'>='=49 +'!='=50 +'!=='=51 +'as?'=52 +'=='=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 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 new file mode 100644 index 0000000000..8965301371 --- /dev/null +++ b/pmd-kotlin/src/main/antlr4/net/sourceforge/pmd/lang/kotlin/ast/README.md @@ -0,0 +1,44 @@ +# Kotlin Grammar + +Release: +Source: + + +Some modifications are made in KotlinParser.g4: + +* The file "KotlinParser.g4" is renamed to "Kotlin.g4" +* `grammar Kotlin` instead of KotlinParser +* Additional headers: + +``` +@header { +import net.sourceforge.pmd.lang.ast.impl.antlr4.*; +import net.sourceforge.pmd.lang.ast.AstVisitor; +} +``` + +* Additional members: + +``` +@parser::members { + + static final AntlrNameDictionary DICO = new KotlinNameDictionary(VOCABULARY, ruleNames); + + @Override + public KotlinTerminalNode createPmdTerminal(ParserRuleContext parent, Token t) { + return new KotlinTerminalNode(t); + } + + @Override + public KotlinErrorNode createPmdError(ParserRuleContext parent, Token t) { + return new KotlinErrorNode(t); + } +} +``` + +* Additional options: + +``` +contextSuperClass = 'KotlinInnerNode'; +superClass = 'AntlrGeneratedParserBase'; +``` diff --git a/pmd-kotlin/src/main/java/net/sourceforge/pmd/lang/kotlin/KotlinHandler.java b/pmd-kotlin/src/main/java/net/sourceforge/pmd/lang/kotlin/KotlinHandler.java index ecc228b7eb..bfb5c9cc48 100644 --- a/pmd-kotlin/src/main/java/net/sourceforge/pmd/lang/kotlin/KotlinHandler.java +++ b/pmd-kotlin/src/main/java/net/sourceforge/pmd/lang/kotlin/KotlinHandler.java @@ -13,18 +13,11 @@ import net.sourceforge.pmd.lang.rule.xpath.impl.XPathHandler; public class KotlinHandler extends AbstractPmdLanguageVersionHandler { - private final String kotlinRelease; - private static final XPathHandler XPATH_HANDLER = XPathHandler.getHandlerForFunctionDefs( BaseContextNodeTestFun.HAS_CHILDREN ); - public KotlinHandler(String release) { - kotlinRelease = release; - // check language version? - } - @Override public XPathHandler getXPathHandler() { return XPATH_HANDLER; @@ -34,8 +27,4 @@ public class KotlinHandler extends AbstractPmdLanguageVersionHandler { public Parser getParser() { return new PmdKotlinParser(); } - - public String getKotlinRelease() { - return kotlinRelease; - } } 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 9a26caf4e0..e8b9c7fe50 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 @@ -21,8 +21,6 @@ public class KotlinLanguageModule extends BaseLanguageModule { */ public KotlinLanguageModule() { super(NAME, null, TERSE_NAME, "kt", "ktm"); - addVersion("1.3", new KotlinHandler("1.3")); - addVersion("1.4", new KotlinHandler("1.4")); - addDefaultVersion("1.5", new KotlinHandler("1.5")); + addDefaultVersion("1.6-rfc+0.1", new KotlinHandler(), "1.6"); } } diff --git a/pmd-kotlin/src/main/java/net/sourceforge/pmd/lang/kotlin/ast/KotlinRootNode.java b/pmd-kotlin/src/main/java/net/sourceforge/pmd/lang/kotlin/ast/KotlinRootNode.java index bb62e02a20..43fa0804f7 100644 --- a/pmd-kotlin/src/main/java/net/sourceforge/pmd/lang/kotlin/ast/KotlinRootNode.java +++ b/pmd-kotlin/src/main/java/net/sourceforge/pmd/lang/kotlin/ast/KotlinRootNode.java @@ -9,24 +9,24 @@ import org.antlr.v4.runtime.ParserRuleContext; import net.sourceforge.pmd.lang.ast.AstInfo; import net.sourceforge.pmd.lang.ast.Parser.ParserTask; import net.sourceforge.pmd.lang.ast.RootNode; -import net.sourceforge.pmd.lang.kotlin.ast.KotlinParser.KtFile; +import net.sourceforge.pmd.lang.kotlin.ast.KotlinParser.KtKotlinFile; // package private base class abstract class KotlinRootNode extends KotlinInnerNode implements RootNode { - private AstInfo astInfo; + private AstInfo astInfo; KotlinRootNode(ParserRuleContext parent, int invokingStateNumber) { super(parent, invokingStateNumber); } @Override - public AstInfo getAstInfo() { + public AstInfo getAstInfo() { return astInfo; } - KtFile makeAstInfo(ParserTask task) { - KtFile me = (KtFile) this; + KtKotlinFile makeAstInfo(ParserTask task) { + KtKotlinFile me = (KtKotlinFile) this; this.astInfo = new AstInfo<>(task, me); return me; } diff --git a/pmd-kotlin/src/main/java/net/sourceforge/pmd/lang/kotlin/ast/PmdKotlinParser.java b/pmd-kotlin/src/main/java/net/sourceforge/pmd/lang/kotlin/ast/PmdKotlinParser.java index 234a95491f..8ad3a430d1 100644 --- a/pmd-kotlin/src/main/java/net/sourceforge/pmd/lang/kotlin/ast/PmdKotlinParser.java +++ b/pmd-kotlin/src/main/java/net/sourceforge/pmd/lang/kotlin/ast/PmdKotlinParser.java @@ -9,17 +9,17 @@ import org.antlr.v4.runtime.CommonTokenStream; import org.antlr.v4.runtime.Lexer; import net.sourceforge.pmd.lang.ast.impl.antlr4.AntlrBaseParser; -import net.sourceforge.pmd.lang.kotlin.ast.KotlinParser.KtFile; +import net.sourceforge.pmd.lang.kotlin.ast.KotlinParser.KtKotlinFile; /** * Adapter for the KotlinParser. */ -public final class PmdKotlinParser extends AntlrBaseParser { +public final class PmdKotlinParser extends AntlrBaseParser { @Override - protected KtFile parse(final Lexer lexer, ParserTask task) { + protected KtKotlinFile parse(final Lexer lexer, ParserTask task) { KotlinParser parser = new KotlinParser(new CommonTokenStream(lexer)); - return parser.file().makeAstInfo(task); + return parser.kotlinFile().makeAstInfo(task); } @Override diff --git a/pmd-kotlin/src/test/java/net/sourceforge/pmd/lang/kotlin/ast/KotlinParsingHelper.java b/pmd-kotlin/src/test/java/net/sourceforge/pmd/lang/kotlin/ast/KotlinParsingHelper.java index 9d20cd2b16..3b2d2331ce 100644 --- a/pmd-kotlin/src/test/java/net/sourceforge/pmd/lang/kotlin/ast/KotlinParsingHelper.java +++ b/pmd-kotlin/src/test/java/net/sourceforge/pmd/lang/kotlin/ast/KotlinParsingHelper.java @@ -12,13 +12,13 @@ import net.sourceforge.pmd.lang.kotlin.KotlinLanguageModule; /** * */ -public class KotlinParsingHelper extends BaseParsingHelper { +public class KotlinParsingHelper extends BaseParsingHelper { public static final KotlinParsingHelper DEFAULT = new KotlinParsingHelper(Params.getDefaultNoProcess()); public KotlinParsingHelper(@NotNull Params params) { - super(KotlinLanguageModule.NAME, KotlinParser.KtFile.class, params); + super(KotlinLanguageModule.NAME, KotlinParser.KtKotlinFile.class, params); } @NotNull diff --git a/pmd-kotlin/src/test/resources/net/sourceforge/pmd/lang/kotlin/ast/testdata/Simple.txt b/pmd-kotlin/src/test/resources/net/sourceforge/pmd/lang/kotlin/ast/testdata/Simple.txt index dba730ec31..00f70e058f 100644 --- a/pmd-kotlin/src/test/resources/net/sourceforge/pmd/lang/kotlin/ast/testdata/Simple.txt +++ b/pmd-kotlin/src/test/resources/net/sourceforge/pmd/lang/kotlin/ast/testdata/Simple.txt @@ -1,4 +1,4 @@ -+- File ++- KotlinFile +- T-NL +- T-NL +- PackageHeader From c0150e46986dc7d7b4ebd8e8ac21d30aab3278df Mon Sep 17 00:00:00 2001 From: Andreas Dangel Date: Thu, 3 Mar 2022 20:46:58 +0100 Subject: [PATCH 032/198] Remove unnecessary rulesets.properties --- .../src/main/resources/rulesets/kotlin/rulesets.properties | 7 ------- 1 file changed, 7 deletions(-) delete mode 100644 pmd-kotlin/src/main/resources/rulesets/kotlin/rulesets.properties diff --git a/pmd-kotlin/src/main/resources/rulesets/kotlin/rulesets.properties b/pmd-kotlin/src/main/resources/rulesets/kotlin/rulesets.properties deleted file mode 100644 index eaeaf55d8f..0000000000 --- a/pmd-kotlin/src/main/resources/rulesets/kotlin/rulesets.properties +++ /dev/null @@ -1,7 +0,0 @@ -# -# BSD-style license; for more info see http://pmd.sourceforge.net/license.html -# - -rulesets.filenames=\ - category/kotlin/bestpractices.xml - From 0a6e4abc750387ade8f93229322473af18ae5454 Mon Sep 17 00:00:00 2001 From: Andreas Dangel Date: Thu, 3 Mar 2022 20:58:46 +0100 Subject: [PATCH 033/198] Fix root-node-name --- antlr4-wrapper.xml | 2 +- pmd-kotlin/pom.xml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/antlr4-wrapper.xml b/antlr4-wrapper.xml index 7219dcf44d..c2d3e224ff 100644 --- a/antlr4-wrapper.xml +++ b/antlr4-wrapper.xml @@ -8,7 +8,7 @@ - lang-name: matches the grammar name (eg "Swift") - lang-terse-name: uncapitalized package name (eg "swift") - node-prefix: prefix for generated AST nodes (eg "Sw") - - root-node-name: name of the root node (eg "TopLevel"), will be made to implement RootNode + - root-node-name: name of the root node without prefix (eg "TopLevel"), will be made to implement RootNode See AntlrGeneratedParserBase diff --git a/pmd-kotlin/pom.xml b/pmd-kotlin/pom.xml index c2e2769fb3..54d10fb5df 100644 --- a/pmd-kotlin/pom.xml +++ b/pmd-kotlin/pom.xml @@ -46,7 +46,7 @@ - + From 396921563547ad0812e82e4fcfe7a3c939e924fb Mon Sep 17 00:00:00 2001 From: Andreas Dangel Date: Thu, 3 Mar 2022 21:09:49 +0100 Subject: [PATCH 034/198] Update ruleset, add ruleset factory test Using pmd.website.baseurl parameter --- pmd-kotlin/pom.xml | 1 - .../main/resources/category/kotlin/bestpractices.xml | 5 ++--- .../pmd/lang/kotlin/RuleSetFactoryTest.java | 10 ++++++++++ 3 files changed, 12 insertions(+), 4 deletions(-) create mode 100644 pmd-kotlin/src/test/java/net/sourceforge/pmd/lang/kotlin/RuleSetFactoryTest.java diff --git a/pmd-kotlin/pom.xml b/pmd-kotlin/pom.xml index 54d10fb5df..5c8ecab013 100644 --- a/pmd-kotlin/pom.xml +++ b/pmd-kotlin/pom.xml @@ -16,7 +16,6 @@ - ${project.basedir}/src/main/resources diff --git a/pmd-kotlin/src/main/resources/category/kotlin/bestpractices.xml b/pmd-kotlin/src/main/resources/category/kotlin/bestpractices.xml index 48512462ce..30a88668f0 100644 --- a/pmd-kotlin/src/main/resources/category/kotlin/bestpractices.xml +++ b/pmd-kotlin/src/main/resources/category/kotlin/bestpractices.xml @@ -10,12 +10,11 @@ Rules which enforce generally accepted best practices. + externalInfoUrl="${pmd.website.baseurl}/pmd_rules_kotlin_bestpractices.html#functionametooshort"> Function names should be easy to understand and describe the intention. Makes developers happy. diff --git a/pmd-kotlin/src/test/java/net/sourceforge/pmd/lang/kotlin/RuleSetFactoryTest.java b/pmd-kotlin/src/test/java/net/sourceforge/pmd/lang/kotlin/RuleSetFactoryTest.java new file mode 100644 index 0000000000..ab10c8550b --- /dev/null +++ b/pmd-kotlin/src/test/java/net/sourceforge/pmd/lang/kotlin/RuleSetFactoryTest.java @@ -0,0 +1,10 @@ +/* + * BSD-style license; for more info see http://pmd.sourceforge.net/license.html + */ + +package net.sourceforge.pmd.lang.kotlin; + +import net.sourceforge.pmd.AbstractRuleSetFactoryTest; + +public class RuleSetFactoryTest extends AbstractRuleSetFactoryTest { +} From a3974bd5600961bfe8a5caee6e5f1b3a3416b82d Mon Sep 17 00:00:00 2001 From: Andreas Dangel Date: Thu, 3 Mar 2022 21:24:33 +0100 Subject: [PATCH 035/198] [doc] Add Kotlin specific language page --- docs/_data/sidebars/pmd_sidebar.yml | 3 +++ docs/pages/pmd/languages/kotlin.md | 14 ++++++++++++++ 2 files changed, 17 insertions(+) create mode 100644 docs/pages/pmd/languages/kotlin.md diff --git a/docs/_data/sidebars/pmd_sidebar.yml b/docs/_data/sidebars/pmd_sidebar.yml index 45c662068f..3e812c5ffe 100644 --- a/docs/_data/sidebars/pmd_sidebar.yml +++ b/docs/_data/sidebars/pmd_sidebar.yml @@ -373,6 +373,9 @@ entries: - title: JSP url: /pmd_languages_jsp.html output: web, pdf + - title: Kotlin + url: /pmd_languages_kotlin.html + output: web, pdf - title: PLSQL url: /pmd_languages_plsql.html output: web, pdf diff --git a/docs/pages/pmd/languages/kotlin.md b/docs/pages/pmd/languages/kotlin.md new file mode 100644 index 0000000000..ad9297a248 --- /dev/null +++ b/docs/pages/pmd/languages/kotlin.md @@ -0,0 +1,14 @@ +--- +title: Kotlin Support +permalink: pmd_languages_kotlin.html +tags: [languages] +summary: "Kotlin-specific features and guidance" +--- + +Kotlin support in PMD is based on the official grammar from . + +Java-based rules and XPath-based rules are supported. + +{% include note.html content="Kotlin support has **experimental** stability level, meaning no compatibility should +be expected between even incremental releases. Any functionality can be added, removed or changed without +warning." %} From 01d24b8ac976bd476882a161e00959e12f5d2a55 Mon Sep 17 00:00:00 2001 From: Andreas Dangel Date: Fri, 4 Mar 2022 19:49:05 +0100 Subject: [PATCH 036/198] Add new rule OverrideBothEqualsAndHashcode --- .../lang/kotlin/ast/KotlinTerminalNode.java | 16 +++- .../OverrideBothEqualsAndHashcodeRule.java | 73 +++++++++++++++++++ .../category/kotlin/categories.properties | 5 +- .../resources/category/kotlin/errorprone.xml | 48 ++++++++++++ .../OverrideBothEqualsAndHashcodeTest.java | 11 +++ .../xml/OverrideBothEqualsAndHashcode.xml | 47 ++++++++++++ 6 files changed, 196 insertions(+), 4 deletions(-) create mode 100644 pmd-kotlin/src/main/java/net/sourceforge/pmd/lang/kotlin/rule/errorprone/OverrideBothEqualsAndHashcodeRule.java create mode 100644 pmd-kotlin/src/main/resources/category/kotlin/errorprone.xml create mode 100644 pmd-kotlin/src/test/java/net/sourceforge/pmd/lang/kotlin/rule/errorprone/OverrideBothEqualsAndHashcodeTest.java create mode 100644 pmd-kotlin/src/test/resources/net/sourceforge/pmd/lang/kotlin/rule/errorprone/xml/OverrideBothEqualsAndHashcode.xml diff --git a/pmd-kotlin/src/main/java/net/sourceforge/pmd/lang/kotlin/ast/KotlinTerminalNode.java b/pmd-kotlin/src/main/java/net/sourceforge/pmd/lang/kotlin/ast/KotlinTerminalNode.java index bcf9e867b2..22f8b49628 100644 --- a/pmd-kotlin/src/main/java/net/sourceforge/pmd/lang/kotlin/ast/KotlinTerminalNode.java +++ b/pmd-kotlin/src/main/java/net/sourceforge/pmd/lang/kotlin/ast/KotlinTerminalNode.java @@ -7,24 +7,36 @@ package net.sourceforge.pmd.lang.kotlin.ast; import org.antlr.v4.runtime.Token; import org.checkerframework.checker.nullness.qual.NonNull; +import net.sourceforge.pmd.lang.ast.AstVisitor; import net.sourceforge.pmd.lang.ast.impl.antlr4.BaseAntlrTerminalNode; public final class KotlinTerminalNode extends BaseAntlrTerminalNode implements KotlinNode { + KotlinTerminalNode(Token token) { super(token); } + @Override public @NonNull String getText() { String constImage = KotlinParser.DICO.getConstantImageOfToken(getFirstAntlrToken()); - return constImage == null ? getFirstAntlrToken().getText() - : constImage; + return constImage == null ? getFirstAntlrToken().getText() : constImage; } + @Override public String getXPathNodeName() { return KotlinParser.DICO.getXPathNameOfToken(getFirstAntlrToken().getType()); } + + @Override + public R acceptVisitor(AstVisitor visitor, P data) { + if (visitor instanceof KotlinVisitor) { + return ((KotlinVisitor) visitor).visitKotlinNode(this, data); + } + return super.acceptVisitor(visitor, data); + } + } diff --git a/pmd-kotlin/src/main/java/net/sourceforge/pmd/lang/kotlin/rule/errorprone/OverrideBothEqualsAndHashcodeRule.java b/pmd-kotlin/src/main/java/net/sourceforge/pmd/lang/kotlin/rule/errorprone/OverrideBothEqualsAndHashcodeRule.java new file mode 100644 index 0000000000..7a087c8ea9 --- /dev/null +++ b/pmd-kotlin/src/main/java/net/sourceforge/pmd/lang/kotlin/rule/errorprone/OverrideBothEqualsAndHashcodeRule.java @@ -0,0 +1,73 @@ +/* + * BSD-style license; for more info see http://pmd.sourceforge.net/license.html + */ + + +package net.sourceforge.pmd.lang.kotlin.rule.errorprone; + +import java.util.List; + +import net.sourceforge.pmd.RuleContext; +import net.sourceforge.pmd.lang.ast.AstVisitor; +import net.sourceforge.pmd.lang.kotlin.AbstractKotlinRule; +import net.sourceforge.pmd.lang.kotlin.ast.KotlinParser.KtClassDeclaration; +import net.sourceforge.pmd.lang.kotlin.ast.KotlinParser.KtClassMemberDeclaration; +import net.sourceforge.pmd.lang.kotlin.ast.KotlinParser.KtClassMemberDeclarations; +import net.sourceforge.pmd.lang.kotlin.ast.KotlinParser.KtDeclaration; +import net.sourceforge.pmd.lang.kotlin.ast.KotlinParser.KtFunctionDeclaration; +import net.sourceforge.pmd.lang.kotlin.ast.KotlinParser.KtFunctionValueParameter; +import net.sourceforge.pmd.lang.kotlin.ast.KotlinParser.KtFunctionValueParameters; +import net.sourceforge.pmd.lang.kotlin.ast.KotlinParser.KtModifiers; +import net.sourceforge.pmd.lang.kotlin.ast.KotlinParser.KtSimpleIdentifier; +import net.sourceforge.pmd.lang.kotlin.ast.KotlinTerminalNode; +import net.sourceforge.pmd.lang.kotlin.ast.KotlinVisitorBase; + +public class OverrideBothEqualsAndHashcodeRule extends AbstractKotlinRule { + + private static final Visitor INSTANCE = new Visitor(); + + @Override + public AstVisitor buildVisitor() { + return INSTANCE; + } + + private static class Visitor extends KotlinVisitorBase { + @Override + public Void visitClassMemberDeclarations(KtClassMemberDeclarations node, RuleContext data) { + List functions = node.children(KtClassMemberDeclaration.class) + .children(KtDeclaration.class) + .children(KtFunctionDeclaration.class) + .toList(); + + boolean hasEqualMethod = functions.stream().filter(this::isEqualsMethod).count() == 1L; + boolean hasHashCodeMethod = functions.stream().filter(this::isHashCodeMethod).count() == 1L; + + if (hasEqualMethod ^ hasHashCodeMethod) { + data.addViolation(node.ancestors(KtClassDeclaration.class).first()); + } + + return super.visitClassMemberDeclarations(node, data); + } + + private boolean isEqualsMethod(KtFunctionDeclaration fun) { + String name = getFunctionName(fun); + int arity = fun.children(KtFunctionValueParameters.class).children(KtFunctionValueParameter.class).count(); + return "equals".equals(name) && hasOverrideModifier(fun) && arity == 1; + } + + private boolean isHashCodeMethod(KtFunctionDeclaration fun) { + String name = getFunctionName(fun); + int arity = fun.children(KtFunctionValueParameters.class).children(KtFunctionValueParameter.class).count(); + return "hashCode".equals(name) && hasOverrideModifier(fun) && arity == 0; + } + + private String getFunctionName(KtFunctionDeclaration fun) { + return fun.children(KtSimpleIdentifier.class).children(KotlinTerminalNode.class).first().getText(); + } + + private boolean hasOverrideModifier(KtFunctionDeclaration fun) { + return fun.children(KtModifiers.class).descendants(KotlinTerminalNode.class) + .any(t -> "override".equals(t.getText())); + } + } +} diff --git a/pmd-kotlin/src/main/resources/category/kotlin/categories.properties b/pmd-kotlin/src/main/resources/category/kotlin/categories.properties index 3c5f1b3629..e0ff81574a 100644 --- a/pmd-kotlin/src/main/resources/category/kotlin/categories.properties +++ b/pmd-kotlin/src/main/resources/category/kotlin/categories.properties @@ -3,7 +3,9 @@ # rulesets.filenames=\ - category/kotlin/bestpractices.xml + category/kotlin/bestpractices.xml,\ + category/kotlin/errorprone.xml + # # categories without rules # @@ -11,7 +13,6 @@ rulesets.filenames=\ # category/kotlin/codestyle.xml # category/kotlin/design.xml # category/kotlin/documentation.xml -# category/kotlin/errorprone.xml # category/kotlin/multithreading.xml # category/kotlin/performance.xml # category/kotlin/security.xml diff --git a/pmd-kotlin/src/main/resources/category/kotlin/errorprone.xml b/pmd-kotlin/src/main/resources/category/kotlin/errorprone.xml new file mode 100644 index 0000000000..d0e5983f49 --- /dev/null +++ b/pmd-kotlin/src/main/resources/category/kotlin/errorprone.xml @@ -0,0 +1,48 @@ + + + + + +Rules to detect constructs that are either broken, extremely confusing or prone to runtime errors. + + + + +Override both public boolean Object.equals(Object other), and public int Object.hashCode(), or override neither. Even if you are inheriting a hashCode() from a parent class, consider implementing hashCode and explicitly delegating to your superclass. + + 3 + + + + + + diff --git a/pmd-kotlin/src/test/java/net/sourceforge/pmd/lang/kotlin/rule/errorprone/OverrideBothEqualsAndHashcodeTest.java b/pmd-kotlin/src/test/java/net/sourceforge/pmd/lang/kotlin/rule/errorprone/OverrideBothEqualsAndHashcodeTest.java new file mode 100644 index 0000000000..7649acfaec --- /dev/null +++ b/pmd-kotlin/src/test/java/net/sourceforge/pmd/lang/kotlin/rule/errorprone/OverrideBothEqualsAndHashcodeTest.java @@ -0,0 +1,11 @@ +/* + * BSD-style license; for more info see http://pmd.sourceforge.net/license.html + */ + +package net.sourceforge.pmd.lang.kotlin.rule.errorprone; + +import net.sourceforge.pmd.testframework.PmdRuleTst; + +public class OverrideBothEqualsAndHashcodeTest extends PmdRuleTst { + // no additional unit tests +} diff --git a/pmd-kotlin/src/test/resources/net/sourceforge/pmd/lang/kotlin/rule/errorprone/xml/OverrideBothEqualsAndHashcode.xml b/pmd-kotlin/src/test/resources/net/sourceforge/pmd/lang/kotlin/rule/errorprone/xml/OverrideBothEqualsAndHashcode.xml new file mode 100644 index 0000000000..e95842b726 --- /dev/null +++ b/pmd-kotlin/src/test/resources/net/sourceforge/pmd/lang/kotlin/rule/errorprone/xml/OverrideBothEqualsAndHashcode.xml @@ -0,0 +1,47 @@ + + + + + Good example #1 + 0 + + + + + Bad example #1 - missing hashCode + 1 + 1 + + + + + Bad example #2 - missing equals + 1 + 1 + + + From db627b4535d3a846f1c78aaefee16a3e9856a701 Mon Sep 17 00:00:00 2001 From: Andreas Dangel Date: Fri, 4 Mar 2022 19:50:21 +0100 Subject: [PATCH 037/198] AbstractKotlinRule should use KotlinVisitor --- .../net/sourceforge/pmd/lang/kotlin/AbstractKotlinRule.java | 4 ++-- .../rule/errorprone/OverrideBothEqualsAndHashcodeRule.java | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/pmd-kotlin/src/main/java/net/sourceforge/pmd/lang/kotlin/AbstractKotlinRule.java b/pmd-kotlin/src/main/java/net/sourceforge/pmd/lang/kotlin/AbstractKotlinRule.java index ac65ac86d6..31262b1473 100644 --- a/pmd-kotlin/src/main/java/net/sourceforge/pmd/lang/kotlin/AbstractKotlinRule.java +++ b/pmd-kotlin/src/main/java/net/sourceforge/pmd/lang/kotlin/AbstractKotlinRule.java @@ -5,8 +5,8 @@ package net.sourceforge.pmd.lang.kotlin; import net.sourceforge.pmd.RuleContext; -import net.sourceforge.pmd.lang.ast.AstVisitor; import net.sourceforge.pmd.lang.ast.impl.antlr4.AntlrBaseRule; +import net.sourceforge.pmd.lang.kotlin.ast.KotlinVisitor; public abstract class AbstractKotlinRule extends AntlrBaseRule { @@ -15,5 +15,5 @@ public abstract class AbstractKotlinRule extends AntlrBaseRule { } @Override - public abstract AstVisitor buildVisitor(); + public abstract KotlinVisitor buildVisitor(); } diff --git a/pmd-kotlin/src/main/java/net/sourceforge/pmd/lang/kotlin/rule/errorprone/OverrideBothEqualsAndHashcodeRule.java b/pmd-kotlin/src/main/java/net/sourceforge/pmd/lang/kotlin/rule/errorprone/OverrideBothEqualsAndHashcodeRule.java index 7a087c8ea9..de5f8a21be 100644 --- a/pmd-kotlin/src/main/java/net/sourceforge/pmd/lang/kotlin/rule/errorprone/OverrideBothEqualsAndHashcodeRule.java +++ b/pmd-kotlin/src/main/java/net/sourceforge/pmd/lang/kotlin/rule/errorprone/OverrideBothEqualsAndHashcodeRule.java @@ -8,7 +8,6 @@ package net.sourceforge.pmd.lang.kotlin.rule.errorprone; import java.util.List; import net.sourceforge.pmd.RuleContext; -import net.sourceforge.pmd.lang.ast.AstVisitor; import net.sourceforge.pmd.lang.kotlin.AbstractKotlinRule; import net.sourceforge.pmd.lang.kotlin.ast.KotlinParser.KtClassDeclaration; import net.sourceforge.pmd.lang.kotlin.ast.KotlinParser.KtClassMemberDeclaration; @@ -20,6 +19,7 @@ import net.sourceforge.pmd.lang.kotlin.ast.KotlinParser.KtFunctionValueParameter import net.sourceforge.pmd.lang.kotlin.ast.KotlinParser.KtModifiers; import net.sourceforge.pmd.lang.kotlin.ast.KotlinParser.KtSimpleIdentifier; import net.sourceforge.pmd.lang.kotlin.ast.KotlinTerminalNode; +import net.sourceforge.pmd.lang.kotlin.ast.KotlinVisitor; import net.sourceforge.pmd.lang.kotlin.ast.KotlinVisitorBase; public class OverrideBothEqualsAndHashcodeRule extends AbstractKotlinRule { @@ -27,7 +27,7 @@ public class OverrideBothEqualsAndHashcodeRule extends AbstractKotlinRule { private static final Visitor INSTANCE = new Visitor(); @Override - public AstVisitor buildVisitor() { + public KotlinVisitor buildVisitor() { return INSTANCE; } From 68c91b766d469304cbcf43c0e576858018105375 Mon Sep 17 00:00:00 2001 From: Andreas Dangel Date: Fri, 4 Mar 2022 19:52:25 +0100 Subject: [PATCH 038/198] [doc] Update sidebar for new Kotlin rule category errorprone --- docs/_data/sidebars/pmd_sidebar.yml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/docs/_data/sidebars/pmd_sidebar.yml b/docs/_data/sidebars/pmd_sidebar.yml index 3e812c5ffe..a010920dfb 100644 --- a/docs/_data/sidebars/pmd_sidebar.yml +++ b/docs/_data/sidebars/pmd_sidebar.yml @@ -244,6 +244,9 @@ entries: - title: Best Practices output: web, pdf url: /pmd_rules_kotlin_bestpractices.html + - title: Error Prone + output: web, pdf + url: /pmd_rules_kotlin_errorprone.html - title: null output: web, pdf subfolders: From 2a73c2b312167f116e829903329bab340a89be0a Mon Sep 17 00:00:00 2001 From: Andreas Dangel Date: Fri, 4 Mar 2022 20:06:21 +0100 Subject: [PATCH 039/198] Refactor OverrideBothEqualsAndHashcode --- .../OverrideBothEqualsAndHashcodeRule.java | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/pmd-kotlin/src/main/java/net/sourceforge/pmd/lang/kotlin/rule/errorprone/OverrideBothEqualsAndHashcodeRule.java b/pmd-kotlin/src/main/java/net/sourceforge/pmd/lang/kotlin/rule/errorprone/OverrideBothEqualsAndHashcodeRule.java index de5f8a21be..0dc432b5bb 100644 --- a/pmd-kotlin/src/main/java/net/sourceforge/pmd/lang/kotlin/rule/errorprone/OverrideBothEqualsAndHashcodeRule.java +++ b/pmd-kotlin/src/main/java/net/sourceforge/pmd/lang/kotlin/rule/errorprone/OverrideBothEqualsAndHashcodeRule.java @@ -14,10 +14,6 @@ import net.sourceforge.pmd.lang.kotlin.ast.KotlinParser.KtClassMemberDeclaration import net.sourceforge.pmd.lang.kotlin.ast.KotlinParser.KtClassMemberDeclarations; import net.sourceforge.pmd.lang.kotlin.ast.KotlinParser.KtDeclaration; import net.sourceforge.pmd.lang.kotlin.ast.KotlinParser.KtFunctionDeclaration; -import net.sourceforge.pmd.lang.kotlin.ast.KotlinParser.KtFunctionValueParameter; -import net.sourceforge.pmd.lang.kotlin.ast.KotlinParser.KtFunctionValueParameters; -import net.sourceforge.pmd.lang.kotlin.ast.KotlinParser.KtModifiers; -import net.sourceforge.pmd.lang.kotlin.ast.KotlinParser.KtSimpleIdentifier; import net.sourceforge.pmd.lang.kotlin.ast.KotlinTerminalNode; import net.sourceforge.pmd.lang.kotlin.ast.KotlinVisitor; import net.sourceforge.pmd.lang.kotlin.ast.KotlinVisitorBase; @@ -51,23 +47,27 @@ public class OverrideBothEqualsAndHashcodeRule extends AbstractKotlinRule { private boolean isEqualsMethod(KtFunctionDeclaration fun) { String name = getFunctionName(fun); - int arity = fun.children(KtFunctionValueParameters.class).children(KtFunctionValueParameter.class).count(); + int arity = getArity(fun); return "equals".equals(name) && hasOverrideModifier(fun) && arity == 1; } private boolean isHashCodeMethod(KtFunctionDeclaration fun) { String name = getFunctionName(fun); - int arity = fun.children(KtFunctionValueParameters.class).children(KtFunctionValueParameter.class).count(); + int arity = getArity(fun); return "hashCode".equals(name) && hasOverrideModifier(fun) && arity == 0; } private String getFunctionName(KtFunctionDeclaration fun) { - return fun.children(KtSimpleIdentifier.class).children(KotlinTerminalNode.class).first().getText(); + return fun.simpleIdentifier().children(KotlinTerminalNode.class).first().getText(); } private boolean hasOverrideModifier(KtFunctionDeclaration fun) { - return fun.children(KtModifiers.class).descendants(KotlinTerminalNode.class) + return fun.modifiers().descendants(KotlinTerminalNode.class) .any(t -> "override".equals(t.getText())); } + + private int getArity(KtFunctionDeclaration fun) { + return fun.functionValueParameters().functionValueParameter().size(); + } } } From 3db42ba1e9cff6632c8a53d84f6b229b2d4d9af2 Mon Sep 17 00:00:00 2001 From: Andreas Dangel Date: Fri, 4 Mar 2022 20:11:23 +0100 Subject: [PATCH 040/198] Removed unnecessary XPath function "hasChildren" --- docs/_data/xpath_funs.yml | 15 ----- .../pmd/lang/kotlin/KotlinHandler.java | 6 +- .../internal/BaseContextNodeTestFun.java | 64 ------------------- 3 files changed, 1 insertion(+), 84 deletions(-) delete mode 100644 pmd-kotlin/src/main/java/net/sourceforge/pmd/lang/kotlin/rule/xpath/internal/BaseContextNodeTestFun.java diff --git a/docs/_data/xpath_funs.yml b/docs/_data/xpath_funs.yml index 761289506f..830217ae71 100644 --- a/docs/_data/xpath_funs.yml +++ b/docs/_data/xpath_funs.yml @@ -172,18 +172,3 @@ langs: outcome: "Matches calls to any method with 2 `int` parameters (!= argument)" - code: '//ConstructorCall[pmd-java:matchesSig("java.util.ArrayList#new(int)")]' outcome: "Matches constructors calls of ArrayList with a single int parameter" - - - name: "Kotlin" - ns: "pmd-kotlin" - funs: - - name: hasChildren - returnType: "xs:boolean" - shortDescription: "Tests if a node has children" - description: "Returns true if the Node has children. This is for test purposes only." - parameters: - - name: "count" - type: "xs:decimal" - description: "The number of children." - examples: - - code: '//Identifier[pmd-kotlin:hasChildren(3)]' - outcome: "true or false" \ No newline at end of file diff --git a/pmd-kotlin/src/main/java/net/sourceforge/pmd/lang/kotlin/KotlinHandler.java b/pmd-kotlin/src/main/java/net/sourceforge/pmd/lang/kotlin/KotlinHandler.java index bfb5c9cc48..4302bf39d4 100644 --- a/pmd-kotlin/src/main/java/net/sourceforge/pmd/lang/kotlin/KotlinHandler.java +++ b/pmd-kotlin/src/main/java/net/sourceforge/pmd/lang/kotlin/KotlinHandler.java @@ -7,16 +7,12 @@ package net.sourceforge.pmd.lang.kotlin; import net.sourceforge.pmd.lang.AbstractPmdLanguageVersionHandler; import net.sourceforge.pmd.lang.ast.Parser; import net.sourceforge.pmd.lang.kotlin.ast.PmdKotlinParser; -import net.sourceforge.pmd.lang.kotlin.rule.xpath.internal.BaseContextNodeTestFun; import net.sourceforge.pmd.lang.rule.xpath.impl.XPathHandler; public class KotlinHandler extends AbstractPmdLanguageVersionHandler { - private static final XPathHandler XPATH_HANDLER = - XPathHandler.getHandlerForFunctionDefs( - BaseContextNodeTestFun.HAS_CHILDREN - ); + private static final XPathHandler XPATH_HANDLER = XPathHandler.noFunctionDefinitions(); @Override public XPathHandler getXPathHandler() { diff --git a/pmd-kotlin/src/main/java/net/sourceforge/pmd/lang/kotlin/rule/xpath/internal/BaseContextNodeTestFun.java b/pmd-kotlin/src/main/java/net/sourceforge/pmd/lang/kotlin/rule/xpath/internal/BaseContextNodeTestFun.java deleted file mode 100644 index 37bfb353c0..0000000000 --- a/pmd-kotlin/src/main/java/net/sourceforge/pmd/lang/kotlin/rule/xpath/internal/BaseContextNodeTestFun.java +++ /dev/null @@ -1,64 +0,0 @@ -/* - * BSD-style license; for more info see http://pmd.sourceforge.net/license.html - */ - -package net.sourceforge.pmd.lang.kotlin.rule.xpath.internal; - -import net.sourceforge.pmd.lang.ast.Node; -import net.sourceforge.pmd.lang.kotlin.ast.KotlinNode; -import net.sourceforge.pmd.lang.rule.xpath.internal.AstElementNode; - -import net.sf.saxon.expr.XPathContext; -import net.sf.saxon.lib.ExtensionFunctionCall; -import net.sf.saxon.om.Sequence; -import net.sf.saxon.trans.XPathException; -import net.sf.saxon.value.BooleanValue; -import net.sf.saxon.value.SequenceType; - -/** - * XPath function {@code pmd-kotlin:hasChildren(count as xs:decimal) as xs:boolean} - * - *

Example XPath 3.1: {@code //Identifier[pmd-kotlin:hasChildren(3)]} - * - *

Returns true if the node has children, false otherwise. - */ -public class BaseContextNodeTestFun extends BaseKotlinXPathFunction { - - static final SequenceType[] NO_ARGUMENTS = { SequenceType.SINGLE_INTEGER }; - private final Class klass; - - public static final BaseKotlinXPathFunction HAS_CHILDREN = new BaseContextNodeTestFun<>(KotlinNode.class, "hasChildren"); - - protected BaseContextNodeTestFun(Class klass, String localName) { - super(localName); - this.klass = klass; - } - - @Override - public SequenceType[] getArgumentTypes() { - return NO_ARGUMENTS; - } - - @Override - public SequenceType getResultType(SequenceType[] suppliedArgumentTypes) { - return SequenceType.SINGLE_BOOLEAN; - } - - @Override - public boolean dependsOnFocus() { - return true; - } - - @Override - public ExtensionFunctionCall makeCallExpression() { - return new ExtensionFunctionCall() { - @Override - public Sequence call(XPathContext context, Sequence[] arguments) throws XPathException { - Node contextNode = ((AstElementNode) context.getContextItem()).getUnderlyingNode(); - boolean hasChildren = contextNode.getNumChildren() == Integer.parseInt(arguments[0].head().getStringValue()); - return BooleanValue.get(klass.isInstance(contextNode) && hasChildren); - } - }; - } - -} From e1f02e8d11c6b6be04ba780d69d331687c901818 Mon Sep 17 00:00:00 2001 From: Andreas Dangel Date: Fri, 4 Mar 2022 20:19:52 +0100 Subject: [PATCH 041/198] Use rulechain --- .../errorprone/OverrideBothEqualsAndHashcodeRule.java | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/pmd-kotlin/src/main/java/net/sourceforge/pmd/lang/kotlin/rule/errorprone/OverrideBothEqualsAndHashcodeRule.java b/pmd-kotlin/src/main/java/net/sourceforge/pmd/lang/kotlin/rule/errorprone/OverrideBothEqualsAndHashcodeRule.java index 0dc432b5bb..7e6db39838 100644 --- a/pmd-kotlin/src/main/java/net/sourceforge/pmd/lang/kotlin/rule/errorprone/OverrideBothEqualsAndHashcodeRule.java +++ b/pmd-kotlin/src/main/java/net/sourceforge/pmd/lang/kotlin/rule/errorprone/OverrideBothEqualsAndHashcodeRule.java @@ -7,6 +7,8 @@ package net.sourceforge.pmd.lang.kotlin.rule.errorprone; import java.util.List; +import org.checkerframework.checker.nullness.qual.NonNull; + import net.sourceforge.pmd.RuleContext; import net.sourceforge.pmd.lang.kotlin.AbstractKotlinRule; import net.sourceforge.pmd.lang.kotlin.ast.KotlinParser.KtClassDeclaration; @@ -17,6 +19,7 @@ import net.sourceforge.pmd.lang.kotlin.ast.KotlinParser.KtFunctionDeclaration; import net.sourceforge.pmd.lang.kotlin.ast.KotlinTerminalNode; import net.sourceforge.pmd.lang.kotlin.ast.KotlinVisitor; import net.sourceforge.pmd.lang.kotlin.ast.KotlinVisitorBase; +import net.sourceforge.pmd.lang.rule.RuleTargetSelector; public class OverrideBothEqualsAndHashcodeRule extends AbstractKotlinRule { @@ -27,6 +30,11 @@ public class OverrideBothEqualsAndHashcodeRule extends AbstractKotlinRule { return INSTANCE; } + @Override + protected @NonNull RuleTargetSelector buildTargetSelector() { + return RuleTargetSelector.forTypes(KtClassMemberDeclarations.class); + } + private static class Visitor extends KotlinVisitorBase { @Override public Void visitClassMemberDeclarations(KtClassMemberDeclarations node, RuleContext data) { From 5dc797bae530f4f5cc75142c1508db607f1a4f02 Mon Sep 17 00:00:00 2001 From: Andreas Dangel Date: Fri, 11 Mar 2022 10:52:38 +0100 Subject: [PATCH 042/198] Fix build after merge --- .../sourceforge/pmd/lang/kotlin/ast/KotlinParsingHelper.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pmd-kotlin/src/test/java/net/sourceforge/pmd/lang/kotlin/ast/KotlinParsingHelper.java b/pmd-kotlin/src/test/java/net/sourceforge/pmd/lang/kotlin/ast/KotlinParsingHelper.java index 3b2d2331ce..43cf4898e9 100644 --- a/pmd-kotlin/src/test/java/net/sourceforge/pmd/lang/kotlin/ast/KotlinParsingHelper.java +++ b/pmd-kotlin/src/test/java/net/sourceforge/pmd/lang/kotlin/ast/KotlinParsingHelper.java @@ -14,7 +14,7 @@ import net.sourceforge.pmd.lang.kotlin.KotlinLanguageModule; */ public class KotlinParsingHelper extends BaseParsingHelper { - public static final KotlinParsingHelper DEFAULT = new KotlinParsingHelper(Params.getDefaultNoProcess()); + public static final KotlinParsingHelper DEFAULT = new KotlinParsingHelper(Params.getDefault()); public KotlinParsingHelper(@NotNull Params params) { From cd57e8c79dd6929d41d1afce68068d5966013692 Mon Sep 17 00:00:00 2001 From: Andreas Dangel Date: Fri, 11 Mar 2022 10:53:08 +0100 Subject: [PATCH 043/198] Fix PMD dogfood issue - inner Visitor class should be final --- .../rule/errorprone/OverrideBothEqualsAndHashcodeRule.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pmd-kotlin/src/main/java/net/sourceforge/pmd/lang/kotlin/rule/errorprone/OverrideBothEqualsAndHashcodeRule.java b/pmd-kotlin/src/main/java/net/sourceforge/pmd/lang/kotlin/rule/errorprone/OverrideBothEqualsAndHashcodeRule.java index 7e6db39838..224ea1b7b0 100644 --- a/pmd-kotlin/src/main/java/net/sourceforge/pmd/lang/kotlin/rule/errorprone/OverrideBothEqualsAndHashcodeRule.java +++ b/pmd-kotlin/src/main/java/net/sourceforge/pmd/lang/kotlin/rule/errorprone/OverrideBothEqualsAndHashcodeRule.java @@ -35,7 +35,7 @@ public class OverrideBothEqualsAndHashcodeRule extends AbstractKotlinRule { return RuleTargetSelector.forTypes(KtClassMemberDeclarations.class); } - private static class Visitor extends KotlinVisitorBase { + private static final class Visitor extends KotlinVisitorBase { @Override public Void visitClassMemberDeclarations(KtClassMemberDeclarations node, RuleContext data) { List functions = node.children(KtClassMemberDeclaration.class) From 087f97f2a360fcabdf7c648e96c9dba282a92354 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9ment=20Fournier?= Date: Sat, 23 Apr 2022 20:01:18 +0200 Subject: [PATCH 044/198] checkstyle --- .../test/java/net/sourceforge/pmd/lang/DummyLanguageModule.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pmd-core/src/test/java/net/sourceforge/pmd/lang/DummyLanguageModule.java b/pmd-core/src/test/java/net/sourceforge/pmd/lang/DummyLanguageModule.java index a56b80a7c7..f1b166ea89 100644 --- a/pmd-core/src/test/java/net/sourceforge/pmd/lang/DummyLanguageModule.java +++ b/pmd-core/src/test/java/net/sourceforge/pmd/lang/DummyLanguageModule.java @@ -13,8 +13,8 @@ import net.sourceforge.pmd.lang.ast.DummyNode.DummyRootNode; import net.sourceforge.pmd.lang.ast.Node; import net.sourceforge.pmd.lang.ast.ParseException; import net.sourceforge.pmd.lang.ast.Parser; -import net.sourceforge.pmd.lang.ast.SourceCodePositioner; import net.sourceforge.pmd.lang.ast.RootNode; +import net.sourceforge.pmd.lang.ast.SourceCodePositioner; import net.sourceforge.pmd.lang.rule.ParametricRuleViolation; import net.sourceforge.pmd.lang.rule.impl.DefaultRuleViolationFactory; From 9b965eb97cda8e3a387fb20e2256e8f403aae1bb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9ment=20Fournier?= Date: Sat, 23 Apr 2022 20:11:09 +0200 Subject: [PATCH 045/198] Add a test, cleanup PmdRunnable tests --- .../pmd/lang/DummyLanguageModule.java | 32 ++++++++++++++++--- .../pmd/processor/PmdRunnableTest.java | 22 ++++++------- 2 files changed, 37 insertions(+), 17 deletions(-) diff --git a/pmd-core/src/test/java/net/sourceforge/pmd/lang/DummyLanguageModule.java b/pmd-core/src/test/java/net/sourceforge/pmd/lang/DummyLanguageModule.java index f1b166ea89..5c23b6112b 100644 --- a/pmd-core/src/test/java/net/sourceforge/pmd/lang/DummyLanguageModule.java +++ b/pmd-core/src/test/java/net/sourceforge/pmd/lang/DummyLanguageModule.java @@ -25,6 +25,9 @@ public class DummyLanguageModule extends BaseLanguageModule { public static final String NAME = "Dummy"; public static final String TERSE_NAME = "dummy"; + private static final String PARSER_REPORTS_SEMANTIC_ERROR = "1.9-semantic_error"; + private static final String THROWS_SEMANTIC_ERROR = "1.9-throws_semantic_error"; + private static final String THROWS_ASSERTION_ERROR = "1.9-throws"; public DummyLanguageModule() { super(NAME, null, TERSE_NAME, "dummy"); @@ -37,12 +40,23 @@ public class DummyLanguageModule extends BaseLanguageModule { addVersion("1.6", new Handler(), "6"); addDefaultVersion("1.7", new Handler(), "7"); addVersion("1.8", new Handler(), "8"); - addVersion("1.9-throws", new HandlerWithParserThatThrows()); - addVersion("1.9-semantic_error", new HandlerWithParserThatReportsSemanticError()); + addVersion(THROWS_ASSERTION_ERROR, new HandlerWithParserThatThrows()); + addVersion(PARSER_REPORTS_SEMANTIC_ERROR, new HandlerWithParserThatReportsSemanticError()); + addVersion(THROWS_SEMANTIC_ERROR, new HandlerWithParserThatThrowsSemanticError()); } - public static Language getInstance() { - return LanguageRegistry.getLanguage(NAME); + public LanguageVersion getVersionWithParserThatThrowsAssertionError() { + return getVersion(THROWS_ASSERTION_ERROR); + } + public LanguageVersion getVersionWithParserThatThrowsSemanticError() { + return getVersion(THROWS_SEMANTIC_ERROR); + } + public LanguageVersion getVersionWithParserThatReportsSemanticError() { + return getVersion(PARSER_REPORTS_SEMANTIC_ERROR); + } + + public static DummyLanguageModule getInstance() { + return (DummyLanguageModule) LanguageRegistry.getLanguage(NAME); } public static DummyRootNode parse(String code) { @@ -94,6 +108,16 @@ public class DummyLanguageModule extends BaseLanguageModule { } } + public static class HandlerWithParserThatThrowsSemanticError extends Handler { + @Override + public Parser getParser() { + return task -> { + RootNode root = super.getParser().parse(task); + throw task.getReporter().error(root, "An error occurred!"); + }; + } + } + /** * Creates a tree of nodes that corresponds to the nesting structures * of parentheses in the text. The image of each node is also populated. diff --git a/pmd-core/src/test/java/net/sourceforge/pmd/processor/PmdRunnableTest.java b/pmd-core/src/test/java/net/sourceforge/pmd/processor/PmdRunnableTest.java index fab2edd9ab..a0a4448738 100644 --- a/pmd-core/src/test/java/net/sourceforge/pmd/processor/PmdRunnableTest.java +++ b/pmd-core/src/test/java/net/sourceforge/pmd/processor/PmdRunnableTest.java @@ -37,7 +37,6 @@ import net.sourceforge.pmd.internal.util.ContextedAssertionError; import net.sourceforge.pmd.lang.DummyLanguageModule; import net.sourceforge.pmd.lang.Language; import net.sourceforge.pmd.lang.LanguageRegistry; -import net.sourceforge.pmd.lang.LanguageVersion; import net.sourceforge.pmd.lang.ast.Node; import net.sourceforge.pmd.lang.rule.AbstractRule; import net.sourceforge.pmd.processor.MonoThreadProcessor.MonothreadRunnable; @@ -49,9 +48,10 @@ public class PmdRunnableTest { @org.junit.Rule public TestRule restoreSystemProperties = new RestoreSystemProperties(); - private LanguageVersion dummyThrows; - private LanguageVersion dummyDefault; - private LanguageVersion dummySemanticError; + + + private final DummyLanguageModule dummyLang = DummyLanguageModule.getInstance(); + private PMDConfiguration configuration; private PmdRunnable pmdRunnable; private GlobalReportBuilderListener reportBuilder; @@ -60,10 +60,6 @@ public class PmdRunnableTest { @Before public void prepare() { - Language dummyLanguage = LanguageRegistry.findLanguageByTerseName(DummyLanguageModule.TERSE_NAME); - dummyDefault = dummyLanguage.getDefaultVersion(); - dummyThrows = dummyLanguage.getVersion("1.9-throws"); - dummySemanticError = dummyLanguage.getVersion("1.9-semantic_error"); DataSource dataSource = DataSource.forString("test", "test.dummy"); @@ -82,7 +78,7 @@ public class PmdRunnableTest { @Test public void inErrorRecoveryModeErrorsShouldBeLoggedByParser() { System.setProperty(SystemProps.PMD_ERROR_RECOVERY, ""); - configuration.setDefaultLanguageVersion(dummyThrows); + configuration.setDefaultLanguageVersion(dummyLang.getVersionWithParserThatThrowsAssertionError()); pmdRunnable.run(); reportBuilder.close(); @@ -92,7 +88,7 @@ public class PmdRunnableTest { @Test public void inErrorRecoveryModeErrorsShouldBeLoggedByRule() { System.setProperty(SystemProps.PMD_ERROR_RECOVERY, ""); - configuration.setDefaultLanguageVersion(dummyDefault); + configuration.setDefaultLanguageVersion(dummyLang.getDefaultVersion()); pmdRunnable.run(); reportBuilder.close(); @@ -105,7 +101,7 @@ public class PmdRunnableTest { @Test public void withoutErrorRecoveryModeProcessingShouldBeAbortedByParser() { Assert.assertNull(System.getProperty(SystemProps.PMD_ERROR_RECOVERY)); - configuration.setDefaultLanguageVersion(dummyThrows); + configuration.setDefaultLanguageVersion(dummyLang.getVersionWithParserThatThrowsAssertionError()); Assert.assertThrows(AssertionError.class, pmdRunnable::run); } @@ -113,7 +109,7 @@ public class PmdRunnableTest { @Test public void withoutErrorRecoveryModeProcessingShouldBeAbortedByRule() { Assert.assertNull(System.getProperty(SystemProps.PMD_ERROR_RECOVERY)); - configuration.setDefaultLanguageVersion(dummyDefault); + configuration.setDefaultLanguageVersion(dummyLang.getDefaultVersion()); Assert.assertThrows(AssertionError.class, pmdRunnable::run); } @@ -121,7 +117,7 @@ public class PmdRunnableTest { @Test public void semanticErrorShouldAbortTheRun() { - configuration.setDefaultLanguageVersion(dummySemanticError); + configuration.setDefaultLanguageVersion(dummyLang.getVersionWithParserThatReportsSemanticError()); pmdRunnable.run(); From ff2f5ef93c1b3150583e9611b2a8fd8159e3aa66 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9ment=20Fournier?= Date: Sat, 23 Apr 2022 20:29:11 +0200 Subject: [PATCH 046/198] Remove coupling between BaseLanguageModule and PmdRunnableTest --- .../pmd/lang/DummyLanguageModule.java | 49 +---------- .../pmd/processor/PmdRunnableTest.java | 81 ++++++++++++++++++- 2 files changed, 79 insertions(+), 51 deletions(-) diff --git a/pmd-core/src/test/java/net/sourceforge/pmd/lang/DummyLanguageModule.java b/pmd-core/src/test/java/net/sourceforge/pmd/lang/DummyLanguageModule.java index 5c23b6112b..1a5fc3eefc 100644 --- a/pmd-core/src/test/java/net/sourceforge/pmd/lang/DummyLanguageModule.java +++ b/pmd-core/src/test/java/net/sourceforge/pmd/lang/DummyLanguageModule.java @@ -13,10 +13,10 @@ import net.sourceforge.pmd.lang.ast.DummyNode.DummyRootNode; import net.sourceforge.pmd.lang.ast.Node; import net.sourceforge.pmd.lang.ast.ParseException; import net.sourceforge.pmd.lang.ast.Parser; -import net.sourceforge.pmd.lang.ast.RootNode; import net.sourceforge.pmd.lang.ast.SourceCodePositioner; import net.sourceforge.pmd.lang.rule.ParametricRuleViolation; import net.sourceforge.pmd.lang.rule.impl.DefaultRuleViolationFactory; +import net.sourceforge.pmd.processor.PmdRunnableTest; /** * Dummy language used for testing PMD. @@ -25,9 +25,6 @@ public class DummyLanguageModule extends BaseLanguageModule { public static final String NAME = "Dummy"; public static final String TERSE_NAME = "dummy"; - private static final String PARSER_REPORTS_SEMANTIC_ERROR = "1.9-semantic_error"; - private static final String THROWS_SEMANTIC_ERROR = "1.9-throws_semantic_error"; - private static final String THROWS_ASSERTION_ERROR = "1.9-throws"; public DummyLanguageModule() { super(NAME, null, TERSE_NAME, "dummy"); @@ -40,19 +37,7 @@ public class DummyLanguageModule extends BaseLanguageModule { addVersion("1.6", new Handler(), "6"); addDefaultVersion("1.7", new Handler(), "7"); addVersion("1.8", new Handler(), "8"); - addVersion(THROWS_ASSERTION_ERROR, new HandlerWithParserThatThrows()); - addVersion(PARSER_REPORTS_SEMANTIC_ERROR, new HandlerWithParserThatReportsSemanticError()); - addVersion(THROWS_SEMANTIC_ERROR, new HandlerWithParserThatThrowsSemanticError()); - } - - public LanguageVersion getVersionWithParserThatThrowsAssertionError() { - return getVersion(THROWS_ASSERTION_ERROR); - } - public LanguageVersion getVersionWithParserThatThrowsSemanticError() { - return getVersion(THROWS_SEMANTIC_ERROR); - } - public LanguageVersion getVersionWithParserThatReportsSemanticError() { - return getVersion(PARSER_REPORTS_SEMANTIC_ERROR); + PmdRunnableTest.registerCustomVersions(this::addVersion); } public static DummyLanguageModule getInstance() { @@ -88,36 +73,6 @@ public class DummyLanguageModule extends BaseLanguageModule { } } - public static class HandlerWithParserThatThrows extends Handler { - @Override - public Parser getParser() { - return task -> { - throw new AssertionError("test error while parsing"); - }; - } - } - - public static class HandlerWithParserThatReportsSemanticError extends Handler { - @Override - public Parser getParser() { - return task -> { - RootNode root = super.getParser().parse(task); - task.getReporter().error(root, "An error occurred!"); - return root; - }; - } - } - - public static class HandlerWithParserThatThrowsSemanticError extends Handler { - @Override - public Parser getParser() { - return task -> { - RootNode root = super.getParser().parse(task); - throw task.getReporter().error(root, "An error occurred!"); - }; - } - } - /** * Creates a tree of nodes that corresponds to the nesting structures * of parentheses in the text. The image of each node is also populated. diff --git a/pmd-core/src/test/java/net/sourceforge/pmd/processor/PmdRunnableTest.java b/pmd-core/src/test/java/net/sourceforge/pmd/processor/PmdRunnableTest.java index a0a4448738..e6f8cde7e0 100644 --- a/pmd-core/src/test/java/net/sourceforge/pmd/processor/PmdRunnableTest.java +++ b/pmd-core/src/test/java/net/sourceforge/pmd/processor/PmdRunnableTest.java @@ -12,9 +12,11 @@ import static org.mockito.Mockito.eq; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.never; import static org.mockito.Mockito.spy; +import static org.mockito.Mockito.times; import static org.mockito.Mockito.verify; import java.util.List; +import java.util.function.BiConsumer; import org.junit.Assert; import org.junit.Before; @@ -35,9 +37,13 @@ import net.sourceforge.pmd.RuleSets; import net.sourceforge.pmd.internal.SystemProps; import net.sourceforge.pmd.internal.util.ContextedAssertionError; import net.sourceforge.pmd.lang.DummyLanguageModule; +import net.sourceforge.pmd.lang.DummyLanguageModule.Handler; import net.sourceforge.pmd.lang.Language; import net.sourceforge.pmd.lang.LanguageRegistry; +import net.sourceforge.pmd.lang.LanguageVersion; import net.sourceforge.pmd.lang.ast.Node; +import net.sourceforge.pmd.lang.ast.Parser; +import net.sourceforge.pmd.lang.ast.RootNode; import net.sourceforge.pmd.lang.rule.AbstractRule; import net.sourceforge.pmd.processor.MonoThreadProcessor.MonothreadRunnable; import net.sourceforge.pmd.util.datasource.DataSource; @@ -45,11 +51,16 @@ import net.sourceforge.pmd.util.log.MessageReporter; public class PmdRunnableTest { + public static final String TEST_MESSAGE_SEMANTIC_ERROR = "An error occurred!"; + private static final String PARSER_REPORTS_SEMANTIC_ERROR = "1.9-semantic_error"; + private static final String THROWS_SEMANTIC_ERROR = "1.9-throws_semantic_error"; + private static final String THROWS_ASSERTION_ERROR = "1.9-throws"; + + @org.junit.Rule public TestRule restoreSystemProperties = new RestoreSystemProperties(); - private final DummyLanguageModule dummyLang = DummyLanguageModule.getInstance(); private PMDConfiguration configuration; @@ -78,7 +89,7 @@ public class PmdRunnableTest { @Test public void inErrorRecoveryModeErrorsShouldBeLoggedByParser() { System.setProperty(SystemProps.PMD_ERROR_RECOVERY, ""); - configuration.setDefaultLanguageVersion(dummyLang.getVersionWithParserThatThrowsAssertionError()); + configuration.setDefaultLanguageVersion(versionWithParserThatThrowsAssertionError()); pmdRunnable.run(); reportBuilder.close(); @@ -101,7 +112,7 @@ public class PmdRunnableTest { @Test public void withoutErrorRecoveryModeProcessingShouldBeAbortedByParser() { Assert.assertNull(System.getProperty(SystemProps.PMD_ERROR_RECOVERY)); - configuration.setDefaultLanguageVersion(dummyLang.getVersionWithParserThatThrowsAssertionError()); + configuration.setDefaultLanguageVersion(versionWithParserThatThrowsAssertionError()); Assert.assertThrows(AssertionError.class, pmdRunnable::run); } @@ -117,7 +128,7 @@ public class PmdRunnableTest { @Test public void semanticErrorShouldAbortTheRun() { - configuration.setDefaultLanguageVersion(dummyLang.getVersionWithParserThatReportsSemanticError()); + configuration.setDefaultLanguageVersion(versionWithParserThatReportsSemanticError()); pmdRunnable.run(); @@ -125,6 +136,35 @@ public class PmdRunnableTest { verify(rule, never()).apply(Mockito.any(), Mockito.any()); } + @Test + public void semanticErrorThrownShouldAbortTheRun() { + configuration.setDefaultLanguageVersion(getVersionWithParserThatThrowsSemanticError()); + + pmdRunnable.run(); + + verify(reporter, times(1)).log(eq(Level.ERROR), contains(TEST_MESSAGE_SEMANTIC_ERROR)); + verify(rule, never()).apply(Mockito.any(), Mockito.any()); + } + + public static void registerCustomVersions(BiConsumer addVersion) { + addVersion.accept(THROWS_ASSERTION_ERROR, new HandlerWithParserThatThrows()); + addVersion.accept(PARSER_REPORTS_SEMANTIC_ERROR, new HandlerWithParserThatReportsSemanticError()); + addVersion.accept(THROWS_SEMANTIC_ERROR, new HandlerWithParserThatThrowsSemanticError()); + + } + + public LanguageVersion versionWithParserThatThrowsAssertionError() { + return dummyLang.getVersion(THROWS_ASSERTION_ERROR); + } + + public LanguageVersion getVersionWithParserThatThrowsSemanticError() { + return dummyLang.getVersion(THROWS_SEMANTIC_ERROR); + } + + public LanguageVersion versionWithParserThatReportsSemanticError() { + return dummyLang.getVersion(PARSER_REPORTS_SEMANTIC_ERROR); + } + private static class RuleThatThrows extends AbstractRule { RuleThatThrows() { @@ -137,4 +177,37 @@ public class PmdRunnableTest { throw new AssertionError("test"); } } + + public static class HandlerWithParserThatThrowsSemanticError extends Handler { + + @Override + public Parser getParser() { + return task -> { + RootNode root = super.getParser().parse(task); + throw task.getReporter().error(root, TEST_MESSAGE_SEMANTIC_ERROR); + }; + } + } + + public static class HandlerWithParserThatThrows extends Handler { + + @Override + public Parser getParser() { + return task -> { + throw new AssertionError("test error while parsing"); + }; + } + } + + public static class HandlerWithParserThatReportsSemanticError extends Handler { + + @Override + public Parser getParser() { + return task -> { + RootNode root = super.getParser().parse(task); + task.getReporter().error(root, TEST_MESSAGE_SEMANTIC_ERROR); + return root; + }; + } + } } From de1368275381c8a1511574759113d5813990ba64 Mon Sep 17 00:00:00 2001 From: Andreas Dangel Date: Thu, 28 Apr 2022 12:53:28 +0200 Subject: [PATCH 047/198] [core] Support #text and #comment nodes --- .../pmd/lang/ast/xpath/saxon/ElementNode.java | 22 ++++++++++++-- .../pmd/lang/html/HtmlXPathRuleTest.java | 30 +++++++++++++++++-- 2 files changed, 47 insertions(+), 5 deletions(-) diff --git a/pmd-core/src/main/java/net/sourceforge/pmd/lang/ast/xpath/saxon/ElementNode.java b/pmd-core/src/main/java/net/sourceforge/pmd/lang/ast/xpath/saxon/ElementNode.java index e9341542ea..ce9604fe79 100644 --- a/pmd-core/src/main/java/net/sourceforge/pmd/lang/ast/xpath/saxon/ElementNode.java +++ b/pmd-core/src/main/java/net/sourceforge/pmd/lang/ast/xpath/saxon/ElementNode.java @@ -61,7 +61,7 @@ public class ElementNode extends BaseNodeInfo implements AstNodeOwner { Node node, int siblingPosition, NamePool namePool) { - super(Type.ELEMENT, namePool, node.getXPathNodeName(), parent); + super(determineType(node), namePool, node.getXPathNodeName(), parent); this.document = document; this.parent = parent; @@ -80,6 +80,16 @@ public class ElementNode extends BaseNodeInfo implements AstNodeOwner { document.nodeToElementNode.put(node, this); } + private static short determineType(Node node) { + String name = node.getXPathNodeName(); + if ("#text".equals(name)) { + return Type.TEXT; + } else if ("#comment".equals(name)) { + return Type.COMMENT; + } + return Type.ELEMENT; + } + private Map getAttributes() { if (attributes == null) { attributes = new HashMap<>(); @@ -147,10 +157,18 @@ public class ElementNode extends BaseNodeInfo implements AstNodeOwner { } @Override - public CharSequence getStringValueCS() { + public String getStringValue() { + if (determineType(getUnderlyingNode()) == Type.TEXT) { + return getUnderlyingNode().getImage(); + } return ""; } + @Override + public CharSequence getStringValueCS() { + return getStringValue(); + } + @Override public int compareOrder(NodeInfo other) { int result; diff --git a/pmd-html/src/test/java/net/sourceforge/pmd/lang/html/HtmlXPathRuleTest.java b/pmd-html/src/test/java/net/sourceforge/pmd/lang/html/HtmlXPathRuleTest.java index 6c2c53e2f9..1a70e5c0fc 100644 --- a/pmd-html/src/test/java/net/sourceforge/pmd/lang/html/HtmlXPathRuleTest.java +++ b/pmd-html/src/test/java/net/sourceforge/pmd/lang/html/HtmlXPathRuleTest.java @@ -24,19 +24,22 @@ public class HtmlXPathRuleTest { private static final String LIGHTNING_WEB_COMPONENT = "\n" + ""; @Test public void selectTextNode() { // from https://developer.salesforce.com/docs/component-library/documentation/en/lwc/lwc.js_props_getter // "Don’t add spaces around the property, for example, { data } is not valid HTML." - String xpath = "//*[local-name() = '#text'][contains(@Text, '{ ')]"; + String xpath = "//text()[contains(., '{ ')]"; Report report = runXPath(LIGHTNING_WEB_COMPONENT, xpath); Assert.assertEquals(1, report.getViolations().size()); @@ -54,6 +57,27 @@ public class HtmlXPathRuleTest { Assert.assertEquals(4, report.getViolations().get(0).getBeginLine()); } + @Test + public void selectAttributesMultiple() { + // from https://developer.salesforce.com/docs/component-library/documentation/en/lwc/lwc.js_props_getter + // "Don’t add spaces around the property, for example, { data } is not valid HTML." + String xpath = "//*[@*[local-name() = ('value', 'onchange')] = '{']"; + + Report report = runXPath(LIGHTNING_WEB_COMPONENT, xpath); + Assert.assertEquals(2, report.getViolations().size()); + Assert.assertEquals(4, report.getViolations().get(0).getBeginLine()); + Assert.assertEquals(6, report.getViolations().get(1).getBeginLine()); + } + + @Test + public void selectAttributeByName() { + String xpath = "//*[@*[local-name() = 'if:true']]"; + + Report report = runXPath(LIGHTNING_WEB_COMPONENT, xpath); + Assert.assertEquals(1, report.getViolations().size()); + Assert.assertEquals(10, report.getViolations().get(0).getBeginLine()); + } + private Report runXPath(String html, String xpath) { LanguageVersion htmlLanguage = LanguageRegistry.findLanguageByTerseName(HtmlLanguageModule.TERSE_NAME).getDefaultVersion(); Parser parser = htmlLanguage.getLanguageVersionHandler().getParser(htmlLanguage.getLanguageVersionHandler().getDefaultParserOptions()); From 98f44b7e3f4abe75112361b5aa92a5db76db7603 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9ment=20Fournier?= Date: Sun, 1 May 2022 16:00:25 +0200 Subject: [PATCH 048/198] Allow Phonetic Extensions block in java Fix #3423 --- pmd-java/etc/grammar/Java.jjt | 4 ++-- .../pmd/lang/java/ast/ParserCornersTest.java | 6 ++++++ .../pmd/lang/java/ast/UnicodeIndent.java | 18 ++++++++++++++++++ 3 files changed, 26 insertions(+), 2 deletions(-) create mode 100644 pmd-java/src/test/resources/net/sourceforge/pmd/lang/java/ast/UnicodeIndent.java diff --git a/pmd-java/etc/grammar/Java.jjt b/pmd-java/etc/grammar/Java.jjt index e9eaacf5e5..f455a765e6 100644 --- a/pmd-java/etc/grammar/Java.jjt +++ b/pmd-java/etc/grammar/Java.jjt @@ -953,7 +953,7 @@ TOKEN : "\u1310","\u1312"-"\u1315","\u1318"-"\u131e","\u1320"-"\u1346","\u1348"-"\u135a", "\u13a0"-"\u13f4","\u1401"-"\u166c","\u166f"-"\u1676","\u1681"-"\u169a","\u16a0"-"\u16ea", "\u1780"-"\u17b3","\u17db","\u1820"-"\u1877","\u1880"-"\u18a8","\u1e00"-"\u1e9b", - "\u1ea0"-"\u1ef9","\u1f00"-"\u1f15","\u1f18"-"\u1f1d","\u1f20"-"\u1f45","\u1f48"-"\u1f4d", + "\u1ea0"-"\u1ef9","\u1d00"-"\u1d7f","\u1f00"-"\u1f15","\u1f18"-"\u1f1d","\u1f20"-"\u1f45","\u1f48"-"\u1f4d", "\u1f50"-"\u1f57","\u1f59","\u1f5b","\u1f5d","\u1f5f"-"\u1f7d","\u1f80"-"\u1fb4", "\u1fb6"-"\u1fbc","\u1fbe","\u1fc2"-"\u1fc4","\u1fc6"-"\u1fcc","\u1fd0"-"\u1fd3", "\u1fd6"-"\u1fdb","\u1fe0"-"\u1fec","\u1ff2"-"\u1ff4","\u1ff6"-"\u1ffc","\u203f"-"\u2040", @@ -1022,7 +1022,7 @@ TOKEN : "\u12f0"-"\u130e","\u1310","\u1312"-"\u1315","\u1318"-"\u131e","\u1320"-"\u1346", "\u1348"-"\u135a","\u1369"-"\u1371","\u13a0"-"\u13f4","\u1401"-"\u166c","\u166f"-"\u1676", "\u1681"-"\u169a","\u16a0"-"\u16ea","\u1780"-"\u17d3","\u17db","\u17e0"-"\u17e9", - "\u180b"-"\u180e","\u1810"-"\u1819","\u1820"-"\u1877","\u1880"-"\u18a9","\u1e00"-"\u1e9b", + "\u180b"-"\u180e","\u1810"-"\u1819","\u1820"-"\u1877","\u1880"-"\u18a9","\u1d00"-"\u1d7f","\u1e00"-"\u1e9b", "\u1ea0"-"\u1ef9","\u1f00"-"\u1f15","\u1f18"-"\u1f1d","\u1f20"-"\u1f45","\u1f48"-"\u1f4d", "\u1f50"-"\u1f57","\u1f59","\u1f5b","\u1f5d","\u1f5f"-"\u1f7d","\u1f80"-"\u1fb4", "\u1fb6"-"\u1fbc","\u1fbe","\u1fc2"-"\u1fc4","\u1fc6"-"\u1fcc","\u1fd0"-"\u1fd3", diff --git a/pmd-java/src/test/java/net/sourceforge/pmd/lang/java/ast/ParserCornersTest.java b/pmd-java/src/test/java/net/sourceforge/pmd/lang/java/ast/ParserCornersTest.java index ef40440835..8f513b2690 100644 --- a/pmd-java/src/test/java/net/sourceforge/pmd/lang/java/ast/ParserCornersTest.java +++ b/pmd-java/src/test/java/net/sourceforge/pmd/lang/java/ast/ParserCornersTest.java @@ -128,6 +128,12 @@ public class ParserCornersTest { java7.parse(GENERICS_PROBLEM); } + @Test + public void testUnicodeIndent() { + // https://github.com/pmd/pmd/issues/3423 + java7.parseResource("UnicodeIndent.java"); + } + @Test public void testParsersCases15() { java5.parseResource("ParserCornerCases.java"); diff --git a/pmd-java/src/test/resources/net/sourceforge/pmd/lang/java/ast/UnicodeIndent.java b/pmd-java/src/test/resources/net/sourceforge/pmd/lang/java/ast/UnicodeIndent.java new file mode 100644 index 0000000000..d6cbab3b84 --- /dev/null +++ b/pmd-java/src/test/resources/net/sourceforge/pmd/lang/java/ast/UnicodeIndent.java @@ -0,0 +1,18 @@ +/* + * BSD-style license; for more info see http://pmd.sourceforge.net/license.html + */ + +// https://github.com/pmd/pmd/issues/3423 + +package com.example.pmdtest; + +public class PmdTest { + + private static final int lᵤ = 1; + private static final int μᵤ = 2; + + public static void main(String[] args) { + System.out.println(lᵤ + μᵤ); + } + +} From b328bc5fdc543f8605a99b8fc65251006bd7639f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9ment=20Fournier?= Date: Sun, 1 May 2022 17:47:06 +0200 Subject: [PATCH 049/198] Add more cjk and exotic scripts, also to JS Fix #2605 --- pmd-java/etc/grammar/Java.jjt | 3 ++- pmd-javascript/etc/grammar/es5.jj | 7 +++---- .../pmd/lang/ecmascript/ast/EcmascriptParserTest.java | 10 ++++++++++ 3 files changed, 15 insertions(+), 5 deletions(-) diff --git a/pmd-java/etc/grammar/Java.jjt b/pmd-java/etc/grammar/Java.jjt index f455a765e6..004a571453 100644 --- a/pmd-java/etc/grammar/Java.jjt +++ b/pmd-java/etc/grammar/Java.jjt @@ -961,7 +961,7 @@ TOKEN : "\u2124","\u2126","\u2128","\u212a"-"\u212d","\u212f"-"\u2131","\u2133"-"\u2139", "\u2160"-"\u2183","\u3005"-"\u3007","\u3021"-"\u3029","\u3031"-"\u3035","\u3038"-"\u303a", "\u3041"-"\u3094","\u309d"-"\u309e","\u30a1"-"\u30fe","\u3105"-"\u312c","\u3131"-"\u318e", - "\u31a0"-"\u31b7","\u3400"-"\u4db5","\u4e00"-"\u9fa5","\ua000"-"\ua48c","\uac00"-"\ud7a3", + "\u31a0"-"\u31b7","\u3400"-"\u4db5","\u4e00"-"\u9fa5","\ua000"-"\ua48c","\ua490"-"\uabff","\uac00"-"\ud7a3", "\uf900"-"\ufa2d","\ufb00"-"\ufb06","\ufb13"-"\ufb17","\ufb1d","\ufb1f"-"\ufb28", "\ufb2a"-"\ufb36","\ufb38"-"\ufb3c","\ufb3e","\ufb40"-"\ufb41","\ufb43"-"\ufb44", "\ufb46"-"\ufbb1","\ufbd3"-"\ufd3d","\ufd50"-"\ufd8f","\ufd92"-"\ufdc7","\ufdf0"-"\ufdfb", @@ -1033,6 +1033,7 @@ TOKEN : "\u2160"-"\u2183","\u3005"-"\u3007","\u3021"-"\u302f","\u3031"-"\u3035","\u3038"-"\u303a", "\u3041"-"\u3094","\u3099"-"\u309a","\u309d"-"\u309e","\u30a1"-"\u30fe","\u3105"-"\u312c", "\u3131"-"\u318e","\u31a0"-"\u31b7","\u3400"-"\u4db5","\u4e00"-"\u9fa5","\ua000"-"\ua48c", + "\ua490"-"\uabff", "\uac00"-"\ud7a3","\uf900"-"\ufa2d","\ufb00"-"\ufb06","\ufb13"-"\ufb17","\ufb1d"-"\ufb28", "\ufb2a"-"\ufb36","\ufb38"-"\ufb3c","\ufb3e","\ufb40"-"\ufb41","\ufb43"-"\ufb44", "\ufb46"-"\ufbb1","\ufbd3"-"\ufd3d","\ufd50"-"\ufd8f","\ufd92"-"\ufdc7","\ufdf0"-"\ufdfb", diff --git a/pmd-javascript/etc/grammar/es5.jj b/pmd-javascript/etc/grammar/es5.jj index 688692d61d..9e2b28be82 100644 --- a/pmd-javascript/etc/grammar/es5.jj +++ b/pmd-javascript/etc/grammar/es5.jj @@ -534,11 +534,10 @@ TOKEN : "\u31A0"-"\u31B7", "\u3400", "\u4DB5", - "\u4E00", - "\u9FA5", + "\u4E00"-"\u9EA5", "\uA000"-"\uA48C", - "\uAC00", - "\uD7A3", + "\uA490"-"\uABFF", + "\uAC00"-"\ud7AF", "\uF900"-"\uFA2D", "\uFB00"-"\uFB06", "\uFB13"-"\uFB17", diff --git a/pmd-javascript/src/test/java/net/sourceforge/pmd/lang/ecmascript/ast/EcmascriptParserTest.java b/pmd-javascript/src/test/java/net/sourceforge/pmd/lang/ecmascript/ast/EcmascriptParserTest.java index f6fe15ce3f..73a066e41a 100644 --- a/pmd-javascript/src/test/java/net/sourceforge/pmd/lang/ecmascript/ast/EcmascriptParserTest.java +++ b/pmd-javascript/src/test/java/net/sourceforge/pmd/lang/ecmascript/ast/EcmascriptParserTest.java @@ -183,6 +183,16 @@ public class EcmascriptParserTest extends EcmascriptParserTestBase { assertEquals("^=", infix.getImage()); } + @Test + public void testUnicodeCjk() { + // the first is u+4F60 + js.parse("import { Test } from 'test2'\n" + + "define('element', class extends Test {\n" + + " \n" + + " }\n" + + "})"); + } + /** * [javascript] Failing with OutOfMemoryError parsing a Javascript file #2081 */ From 71b936282854eacc008a4e2dfffea28bace0935a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9ment=20Fournier?= Date: Sun, 1 May 2022 17:51:38 +0200 Subject: [PATCH 050/198] [python] unicode support Fix #2604 --- pmd-python/etc/grammar/python.jj | 52 ++++++++++++++++++- .../pmd/cpd/PythonTokenizerTest.java | 5 ++ .../python/cpd/testdata/sample_unicode.py | 4 ++ .../python/cpd/testdata/sample_unicode.txt | 13 +++++ 4 files changed, 73 insertions(+), 1 deletion(-) create mode 100644 pmd-python/src/test/resources/net/sourceforge/pmd/lang/python/cpd/testdata/sample_unicode.py create mode 100644 pmd-python/src/test/resources/net/sourceforge/pmd/lang/python/cpd/testdata/sample_unicode.txt diff --git a/pmd-python/etc/grammar/python.jj b/pmd-python/etc/grammar/python.jj index 1f97f9d948..5ca99e7331 100644 --- a/pmd-python/etc/grammar/python.jj +++ b/pmd-python/etc/grammar/python.jj @@ -133,7 +133,57 @@ TOKEN : /* KEYWORDS */ TOKEN : /* Python identifiers */ { < NAME: ( | )* > -| < #LETTER: ["_","a"-"z","A"-"Z"] > +| < #LETTER : ["$","A"-"Z","_","a"-"z","\u00a2"-"\u00a5","\u00aa","\u00b5","\u00ba", + "\u00c0"-"\u00d6","\u00d8"-"\u00f6","\u00f8"-"\u021f","\u0222"-"\u0233","\u0250"-"\u02ad", + "\u02b0"-"\u02b8","\u02bb"-"\u02c1","\u02d0"-"\u02d1","\u02e0"-"\u02e4","\u02ee","\u037a", + "\u0386","\u0388"-"\u038a","\u038c","\u038e"-"\u03a1","\u03a3"-"\u03ce","\u03d0"-"\u03d7", + "\u03da"-"\u03f3","\u0400"-"\u0481","\u048c"-"\u04c4","\u04c7"-"\u04c8","\u04cb"-"\u04cc", + "\u04d0"-"\u04f5","\u04f8"-"\u04f9","\u0531"-"\u0556","\u0559","\u0561"-"\u0587", + "\u05d0"-"\u05ea","\u05f0"-"\u05f2","\u0621"-"\u063a","\u0640"-"\u064a","\u0671"-"\u06d3", + "\u06d5","\u06e5"-"\u06e6","\u06fa"-"\u06fc","\u0710","\u0712"-"\u072c","\u0780"-"\u07a5", + "\u0905"-"\u0939","\u093d","\u0950","\u0958"-"\u0961","\u0985"-"\u098c","\u098f"-"\u0990", + "\u0993"-"\u09a8","\u09aa"-"\u09b0","\u09b2","\u09b6"-"\u09b9","\u09dc"-"\u09dd", + "\u09df"-"\u09e1","\u09f0"-"\u09f3","\u0a05"-"\u0a0a","\u0a0f"-"\u0a10","\u0a13"-"\u0a28", + "\u0a2a"-"\u0a30","\u0a32"-"\u0a33","\u0a35"-"\u0a36","\u0a38"-"\u0a39","\u0a59"-"\u0a5c", + "\u0a5e","\u0a72"-"\u0a74","\u0a85"-"\u0a8b","\u0a8d","\u0a8f"-"\u0a91","\u0a93"-"\u0aa8", + "\u0aaa"-"\u0ab0","\u0ab2"-"\u0ab3","\u0ab5"-"\u0ab9","\u0abd","\u0ad0","\u0ae0", + "\u0b05"-"\u0b0c","\u0b0f"-"\u0b10","\u0b13"-"\u0b28","\u0b2a"-"\u0b30","\u0b32"-"\u0b33", + "\u0b36"-"\u0b39","\u0b3d","\u0b5c"-"\u0b5d","\u0b5f"-"\u0b61","\u0b85"-"\u0b8a", + "\u0b8e"-"\u0b90","\u0b92"-"\u0b95","\u0b99"-"\u0b9a","\u0b9c","\u0b9e"-"\u0b9f", + "\u0ba3"-"\u0ba4","\u0ba8"-"\u0baa","\u0bae"-"\u0bb5","\u0bb7"-"\u0bb9","\u0c05"-"\u0c0c", + "\u0c0e"-"\u0c10","\u0c12"-"\u0c28","\u0c2a"-"\u0c33","\u0c35"-"\u0c39","\u0c60"-"\u0c61", + "\u0c85"-"\u0c8c","\u0c8e"-"\u0c90","\u0c92"-"\u0ca8","\u0caa"-"\u0cb3","\u0cb5"-"\u0cb9", + "\u0cde","\u0ce0"-"\u0ce1","\u0d05"-"\u0d0c","\u0d0e"-"\u0d10","\u0d12"-"\u0d28", + "\u0d2a"-"\u0d39","\u0d60"-"\u0d61","\u0d85"-"\u0d96","\u0d9a"-"\u0db1","\u0db3"-"\u0dbb", + "\u0dbd","\u0dc0"-"\u0dc6","\u0e01"-"\u0e30","\u0e32"-"\u0e33","\u0e3f"-"\u0e46", + "\u0e81"-"\u0e82","\u0e84","\u0e87"-"\u0e88","\u0e8a","\u0e8d","\u0e94"-"\u0e97", + "\u0e99"-"\u0e9f","\u0ea1"-"\u0ea3","\u0ea5","\u0ea7","\u0eaa"-"\u0eab","\u0ead"-"\u0eb0", + "\u0eb2"-"\u0eb3","\u0ebd","\u0ec0"-"\u0ec4","\u0ec6","\u0edc"-"\u0edd","\u0f00", + "\u0f40"-"\u0f47","\u0f49"-"\u0f6a","\u0f88"-"\u0f8b","\u1000"-"\u1021","\u1023"-"\u1027", + "\u1029"-"\u102a","\u1050"-"\u1055","\u10a0"-"\u10c5","\u10d0"-"\u10f6","\u1100"-"\u1159", + "\u115f"-"\u11a2","\u11a8"-"\u11f9","\u1200"-"\u1206","\u1208"-"\u1246","\u1248", + "\u124a"-"\u124d","\u1250"-"\u1256","\u1258","\u125a"-"\u125d","\u1260"-"\u1286","\u1288", + "\u128a"-"\u128d","\u1290"-"\u12ae","\u12b0","\u12b2"-"\u12b5","\u12b8"-"\u12be","\u12c0", + "\u12c2"-"\u12c5","\u12c8"-"\u12ce","\u12d0"-"\u12d6","\u12d8"-"\u12ee","\u12f0"-"\u130e", + "\u1310","\u1312"-"\u1315","\u1318"-"\u131e","\u1320"-"\u1346","\u1348"-"\u135a", + "\u13a0"-"\u13f4","\u1401"-"\u166c","\u166f"-"\u1676","\u1681"-"\u169a","\u16a0"-"\u16ea", + "\u1780"-"\u17b3","\u17db","\u1820"-"\u1877","\u1880"-"\u18a8","\u1e00"-"\u1e9b", + "\u1ea0"-"\u1ef9","\u1d00"-"\u1d7f","\u1f00"-"\u1f15","\u1f18"-"\u1f1d","\u1f20"-"\u1f45","\u1f48"-"\u1f4d", + "\u1f50"-"\u1f57","\u1f59","\u1f5b","\u1f5d","\u1f5f"-"\u1f7d","\u1f80"-"\u1fb4", + "\u1fb6"-"\u1fbc","\u1fbe","\u1fc2"-"\u1fc4","\u1fc6"-"\u1fcc","\u1fd0"-"\u1fd3", + "\u1fd6"-"\u1fdb","\u1fe0"-"\u1fec","\u1ff2"-"\u1ff4","\u1ff6"-"\u1ffc","\u203f"-"\u2040", + "\u207f","\u20a0"-"\u20af","\u2102","\u2107","\u210a"-"\u2113","\u2115","\u2119"-"\u211d", + "\u2124","\u2126","\u2128","\u212a"-"\u212d","\u212f"-"\u2131","\u2133"-"\u2139", + "\u2160"-"\u2183","\u3005"-"\u3007","\u3021"-"\u3029","\u3031"-"\u3035","\u3038"-"\u303a", + "\u3041"-"\u3094","\u309d"-"\u309e","\u30a1"-"\u30fe","\u3105"-"\u312c","\u3131"-"\u318e", + "\u31a0"-"\u31b7","\u3400"-"\u4db5","\u4e00"-"\u9fa5","\ua000"-"\ua48c","\ua490"-"\uabff","\uac00"-"\ud7a3", + "\uf900"-"\ufa2d","\ufb00"-"\ufb06","\ufb13"-"\ufb17","\ufb1d","\ufb1f"-"\ufb28", + "\ufb2a"-"\ufb36","\ufb38"-"\ufb3c","\ufb3e","\ufb40"-"\ufb41","\ufb43"-"\ufb44", + "\ufb46"-"\ufbb1","\ufbd3"-"\ufd3d","\ufd50"-"\ufd8f","\ufd92"-"\ufdc7","\ufdf0"-"\ufdfb", + "\ufe33"-"\ufe34","\ufe4d"-"\ufe4f","\ufe69","\ufe70"-"\ufe72","\ufe74","\ufe76"-"\ufefc", + "\uff04","\uff21"-"\uff3a","\uff3f","\uff41"-"\uff5a","\uff65"-"\uffbe","\uffc2"-"\uffc7", + "\uffca"-"\uffcf","\uffd2"-"\uffd7","\uffda"-"\uffdc","\uffe0"-"\uffe1","\uffe5"-"\uffe6"]> + } diff --git a/pmd-python/src/test/java/net/sourceforge/pmd/cpd/PythonTokenizerTest.java b/pmd-python/src/test/java/net/sourceforge/pmd/cpd/PythonTokenizerTest.java index 254b8cdbe8..ad15fbe661 100644 --- a/pmd-python/src/test/java/net/sourceforge/pmd/cpd/PythonTokenizerTest.java +++ b/pmd-python/src/test/java/net/sourceforge/pmd/cpd/PythonTokenizerTest.java @@ -42,6 +42,11 @@ public class PythonTokenizerTest extends CpdTextComparisonTest { doTest("backticks"); } + @Test + public void testUnicode() { + doTest("sample_unicode"); + } + @Test public void testTabWidth() { doTest("tabWidth"); diff --git a/pmd-python/src/test/resources/net/sourceforge/pmd/lang/python/cpd/testdata/sample_unicode.py b/pmd-python/src/test/resources/net/sourceforge/pmd/lang/python/cpd/testdata/sample_unicode.py new file mode 100644 index 0000000000..b0143e7e1a --- /dev/null +++ b/pmd-python/src/test/resources/net/sourceforge/pmd/lang/python/cpd/testdata/sample_unicode.py @@ -0,0 +1,4 @@ +# note: add more examples here when bugs arise + +def check(): + total_cost_μs = [] # https://github.com/pmd/pmd/issues/2604 diff --git a/pmd-python/src/test/resources/net/sourceforge/pmd/lang/python/cpd/testdata/sample_unicode.txt b/pmd-python/src/test/resources/net/sourceforge/pmd/lang/python/cpd/testdata/sample_unicode.txt new file mode 100644 index 0000000000..9476d45ba4 --- /dev/null +++ b/pmd-python/src/test/resources/net/sourceforge/pmd/lang/python/cpd/testdata/sample_unicode.txt @@ -0,0 +1,13 @@ + [Image] or [Truncated image[ Bcol Ecol +L3 + [def] 1 3 + [check] 5 9 + [(] 10 10 + [)] 11 11 + [:] 12 12 +L4 + [total_cost_μs] 5 17 + [=] 19 19 + [\[] 21 21 + [\]] 22 22 +EOF From 669f2fecbd36025ddba0661ccd6378f4d56e4cd5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9ment=20Fournier?= Date: Sun, 1 May 2022 17:58:52 +0200 Subject: [PATCH 051/198] Same for go Fix #2752 --- .../sourceforge/pmd/lang/go/antlr4/Golang.g4 | 7 +- .../sourceforge/pmd/cpd/GoTokenizerTest.java | 7 ++ .../lang/go/cpd/testdata/sample_unicode.go | 20 +++++ .../lang/go/cpd/testdata/sample_unicode.txt | 89 +++++++++++++++++++ 4 files changed, 119 insertions(+), 4 deletions(-) create mode 100644 pmd-go/src/test/resources/net/sourceforge/pmd/lang/go/cpd/testdata/sample_unicode.go create mode 100644 pmd-go/src/test/resources/net/sourceforge/pmd/lang/go/cpd/testdata/sample_unicode.txt diff --git a/pmd-go/src/main/antlr4/net/sourceforge/pmd/lang/go/antlr4/Golang.g4 b/pmd-go/src/main/antlr4/net/sourceforge/pmd/lang/go/antlr4/Golang.g4 index 673c0b6682..4f68b09231 100644 --- a/pmd-go/src/main/antlr4/net/sourceforge/pmd/lang/go/antlr4/Golang.g4 +++ b/pmd-go/src/main/antlr4/net/sourceforge/pmd/lang/go/antlr4/Golang.g4 @@ -1264,11 +1264,10 @@ fragment UNICODE_LETTER | [\u31A0-\u31B7] | [\u3400] | [\u4DB5] - | [\u4E00] - | [\u9FA5] + | [\u4E00-\u9EA5] | [\uA000-\uA48C] - | [\uAC00] - | [\uD7A3] + | [\uA490-\uABFF] + | [\uAC00-\uD7AF] | [\uF900-\uFA2D] | [\uFB00-\uFB06] | [\uFB13-\uFB17] diff --git a/pmd-go/src/test/java/net/sourceforge/pmd/cpd/GoTokenizerTest.java b/pmd-go/src/test/java/net/sourceforge/pmd/cpd/GoTokenizerTest.java index 309867e995..0a21eb2e1b 100644 --- a/pmd-go/src/test/java/net/sourceforge/pmd/cpd/GoTokenizerTest.java +++ b/pmd-go/src/test/java/net/sourceforge/pmd/cpd/GoTokenizerTest.java @@ -40,4 +40,11 @@ public class GoTokenizerTest extends CpdTextComparisonTest { public void testIssue1751() { doTest("issue-1751"); } + + @Test + public void testUnicode() { + // https://github.com/pmd/pmd/issues/2752 + doTest("sample_unicode"); + } + } diff --git a/pmd-go/src/test/resources/net/sourceforge/pmd/lang/go/cpd/testdata/sample_unicode.go b/pmd-go/src/test/resources/net/sourceforge/pmd/lang/go/cpd/testdata/sample_unicode.go new file mode 100644 index 0000000000..02325f94df --- /dev/null +++ b/pmd-go/src/test/resources/net/sourceforge/pmd/lang/go/cpd/testdata/sample_unicode.go @@ -0,0 +1,20 @@ +func main() { + //string底层是一个byte数组,因此string也可以进行切片操作 + str := "hello world"//string是不可变的 + slice := str[4:] + fmt.Println(slice) + + //若要对string进行修改需要将string修改为byte或rune的切片在操作 + //但是转为byte无法进行中文操作 + bytes := []byte(str) + bytes[2] = 'x' + str = string(bytes) + fmt.Println(str) + + //转换成rune可以对中文进行操作 + runes := []rune(str) + runes[0] = '哈' + str = string(runes) + fmt.Println(str) + +} diff --git a/pmd-go/src/test/resources/net/sourceforge/pmd/lang/go/cpd/testdata/sample_unicode.txt b/pmd-go/src/test/resources/net/sourceforge/pmd/lang/go/cpd/testdata/sample_unicode.txt new file mode 100644 index 0000000000..f1b02aef86 --- /dev/null +++ b/pmd-go/src/test/resources/net/sourceforge/pmd/lang/go/cpd/testdata/sample_unicode.txt @@ -0,0 +1,89 @@ + [Image] or [Truncated image[ Bcol Ecol +L1 + [func] 1 4 + [main] 6 9 + [(] 10 10 + [)] 11 11 + [{] 13 13 +L3 + [str] 2 4 + [:=] 6 7 + ["hello world"] 9 21 +L4 + [slice] 2 6 + [:=] 8 9 + [str] 11 13 + [\[] 14 14 + [4] 15 15 + [:] 16 16 + [\]] 17 17 +L5 + [fmt] 2 4 + [.] 5 5 + [Println] 6 12 + [(] 13 13 + [slice] 14 18 + [)] 19 19 +L9 + [bytes] 2 6 + [:=] 8 9 + [\[] 11 11 + [\]] 12 12 + [byte] 13 16 + [(] 17 17 + [str] 18 20 + [)] 21 21 +L10 + [bytes] 2 6 + [\[] 7 7 + [2] 8 8 + [\]] 9 9 + [=] 11 11 + ['x'] 13 15 +L11 + [str] 2 4 + [=] 6 6 + [string] 8 13 + [(] 14 14 + [bytes] 15 19 + [)] 20 20 +L12 + [fmt] 2 4 + [.] 5 5 + [Println] 6 12 + [(] 13 13 + [str] 14 16 + [)] 17 17 +L15 + [runes] 2 6 + [:=] 8 9 + [\[] 11 11 + [\]] 12 12 + [rune] 13 16 + [(] 17 17 + [str] 18 20 + [)] 21 21 +L16 + [runes] 2 6 + [\[] 7 7 + [0] 8 8 + [\]] 9 9 + [=] 11 11 + ['哈'] 13 15 +L17 + [str] 2 4 + [=] 6 6 + [string] 8 13 + [(] 14 14 + [runes] 15 19 + [)] 20 20 +L18 + [fmt] 2 4 + [.] 5 5 + [Println] 6 12 + [(] 13 13 + [str] 14 16 + [)] 17 17 +L20 + [}] 1 1 +EOF From e6054e4b653f9f3e2fa77c27623f1a3cdbc82c77 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9ment=20Fournier?= Date: Sun, 1 May 2022 18:09:04 +0200 Subject: [PATCH 052/198] Add another test case for java --- .../pmd/lang/java/ast/ParserCornersTest.java | 2 +- ...codeIndent.java => UnicodeIdentifier.java} | 19 +++++++++++++++++++ 2 files changed, 20 insertions(+), 1 deletion(-) rename pmd-java/src/test/resources/net/sourceforge/pmd/lang/java/ast/{UnicodeIndent.java => UnicodeIdentifier.java} (53%) diff --git a/pmd-java/src/test/java/net/sourceforge/pmd/lang/java/ast/ParserCornersTest.java b/pmd-java/src/test/java/net/sourceforge/pmd/lang/java/ast/ParserCornersTest.java index 8f513b2690..686e9f3c6c 100644 --- a/pmd-java/src/test/java/net/sourceforge/pmd/lang/java/ast/ParserCornersTest.java +++ b/pmd-java/src/test/java/net/sourceforge/pmd/lang/java/ast/ParserCornersTest.java @@ -131,7 +131,7 @@ public class ParserCornersTest { @Test public void testUnicodeIndent() { // https://github.com/pmd/pmd/issues/3423 - java7.parseResource("UnicodeIndent.java"); + java7.parseResource("UnicodeIdentifier.java"); } @Test diff --git a/pmd-java/src/test/resources/net/sourceforge/pmd/lang/java/ast/UnicodeIndent.java b/pmd-java/src/test/resources/net/sourceforge/pmd/lang/java/ast/UnicodeIdentifier.java similarity index 53% rename from pmd-java/src/test/resources/net/sourceforge/pmd/lang/java/ast/UnicodeIndent.java rename to pmd-java/src/test/resources/net/sourceforge/pmd/lang/java/ast/UnicodeIdentifier.java index d6cbab3b84..3eae15d2a9 100644 --- a/pmd-java/src/test/resources/net/sourceforge/pmd/lang/java/ast/UnicodeIndent.java +++ b/pmd-java/src/test/resources/net/sourceforge/pmd/lang/java/ast/UnicodeIdentifier.java @@ -16,3 +16,22 @@ public class PmdTest { } } + +enum CodeSet { + + START_CODE_A('Ë'), + START_CODE_B('Ì'), + START_CODE_C('Í'), + A_TILDE('\u00c3'), + STOP_CODE('Î'); + + private final char encoding; + + CodeSet(final char encoding) { + this.encoding = encoding; + } + + public char getEncoding() { + return encoding; + } +} From 078345fbca6970113b5b7ed17523980b30c76789 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9ment=20Fournier?= Date: Sun, 1 May 2022 18:16:39 +0200 Subject: [PATCH 053/198] Add phonetic extensions to other langs --- .../main/antlr4/net/sourceforge/pmd/lang/go/antlr4/Golang.g4 | 1 + pmd-java/etc/grammar/Java.jjt | 2 +- pmd-javascript/etc/grammar/es5.jj | 1 + pmd-python/etc/grammar/python.jj | 2 +- 4 files changed, 4 insertions(+), 2 deletions(-) diff --git a/pmd-go/src/main/antlr4/net/sourceforge/pmd/lang/go/antlr4/Golang.g4 b/pmd-go/src/main/antlr4/net/sourceforge/pmd/lang/go/antlr4/Golang.g4 index 4f68b09231..c54605fc85 100644 --- a/pmd-go/src/main/antlr4/net/sourceforge/pmd/lang/go/antlr4/Golang.g4 +++ b/pmd-go/src/main/antlr4/net/sourceforge/pmd/lang/go/antlr4/Golang.g4 @@ -1215,6 +1215,7 @@ fragment UNICODE_LETTER | [\u1780-\u17B3] | [\u1820-\u1877] | [\u1880-\u18A8] + | [\u1D00-\u1DFF] | [\u1E00-\u1E9B] | [\u1EA0-\u1EE0] | [\u1EE1-\u1EF9] diff --git a/pmd-java/etc/grammar/Java.jjt b/pmd-java/etc/grammar/Java.jjt index 004a571453..4e655ead41 100644 --- a/pmd-java/etc/grammar/Java.jjt +++ b/pmd-java/etc/grammar/Java.jjt @@ -953,7 +953,7 @@ TOKEN : "\u1310","\u1312"-"\u1315","\u1318"-"\u131e","\u1320"-"\u1346","\u1348"-"\u135a", "\u13a0"-"\u13f4","\u1401"-"\u166c","\u166f"-"\u1676","\u1681"-"\u169a","\u16a0"-"\u16ea", "\u1780"-"\u17b3","\u17db","\u1820"-"\u1877","\u1880"-"\u18a8","\u1e00"-"\u1e9b", - "\u1ea0"-"\u1ef9","\u1d00"-"\u1d7f","\u1f00"-"\u1f15","\u1f18"-"\u1f1d","\u1f20"-"\u1f45","\u1f48"-"\u1f4d", + "\u1ea0"-"\u1ef9","\u1d00"-"\u1eef","\u1f00"-"\u1f15","\u1f18"-"\u1f1d","\u1f20"-"\u1f45","\u1f48"-"\u1f4d", "\u1f50"-"\u1f57","\u1f59","\u1f5b","\u1f5d","\u1f5f"-"\u1f7d","\u1f80"-"\u1fb4", "\u1fb6"-"\u1fbc","\u1fbe","\u1fc2"-"\u1fc4","\u1fc6"-"\u1fcc","\u1fd0"-"\u1fd3", "\u1fd6"-"\u1fdb","\u1fe0"-"\u1fec","\u1ff2"-"\u1ff4","\u1ff6"-"\u1ffc","\u203f"-"\u2040", diff --git a/pmd-javascript/etc/grammar/es5.jj b/pmd-javascript/etc/grammar/es5.jj index 9e2b28be82..a237b0899e 100644 --- a/pmd-javascript/etc/grammar/es5.jj +++ b/pmd-javascript/etc/grammar/es5.jj @@ -488,6 +488,7 @@ TOKEN : "\u1E00"-"\u1E9B", "\u1EA0"-"\u1EE0", "\u1EE1"-"\u1EF9", + "\u1EE1"-"\u1EEF", "\u1F00"-"\u1F15", "\u1F18"-"\u1F1D", "\u1F20"-"\u1F39", diff --git a/pmd-python/etc/grammar/python.jj b/pmd-python/etc/grammar/python.jj index 5ca99e7331..41640cd724 100644 --- a/pmd-python/etc/grammar/python.jj +++ b/pmd-python/etc/grammar/python.jj @@ -168,7 +168,7 @@ TOKEN : /* Python identifiers */ "\u1310","\u1312"-"\u1315","\u1318"-"\u131e","\u1320"-"\u1346","\u1348"-"\u135a", "\u13a0"-"\u13f4","\u1401"-"\u166c","\u166f"-"\u1676","\u1681"-"\u169a","\u16a0"-"\u16ea", "\u1780"-"\u17b3","\u17db","\u1820"-"\u1877","\u1880"-"\u18a8","\u1e00"-"\u1e9b", - "\u1ea0"-"\u1ef9","\u1d00"-"\u1d7f","\u1f00"-"\u1f15","\u1f18"-"\u1f1d","\u1f20"-"\u1f45","\u1f48"-"\u1f4d", + "\u1ea0"-"\u1ef9","\u1d00"-"\u1eef","\u1f00"-"\u1f15","\u1f18"-"\u1f1d","\u1f20"-"\u1f45","\u1f48"-"\u1f4d", "\u1f50"-"\u1f57","\u1f59","\u1f5b","\u1f5d","\u1f5f"-"\u1f7d","\u1f80"-"\u1fb4", "\u1fb6"-"\u1fbc","\u1fbe","\u1fc2"-"\u1fc4","\u1fc6"-"\u1fcc","\u1fd0"-"\u1fd3", "\u1fd6"-"\u1fdb","\u1fe0"-"\u1fec","\u1ff2"-"\u1ff4","\u1ff6"-"\u1ffc","\u203f"-"\u2040", From f80c73e44f813d300252a389546ec14e58787a78 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9ment=20Fournier?= Date: Sun, 1 May 2022 18:21:43 +0200 Subject: [PATCH 054/198] Test dollar in ident in python --- .../sourceforge/pmd/cpd/PythonTokenizerTest.java | 6 ++++++ .../pmd/lang/python/cpd/testdata/var_with_dollar.py | 2 ++ .../lang/python/cpd/testdata/var_with_dollar.txt | 13 +++++++++++++ 3 files changed, 21 insertions(+) create mode 100644 pmd-python/src/test/resources/net/sourceforge/pmd/lang/python/cpd/testdata/var_with_dollar.py create mode 100644 pmd-python/src/test/resources/net/sourceforge/pmd/lang/python/cpd/testdata/var_with_dollar.txt diff --git a/pmd-python/src/test/java/net/sourceforge/pmd/cpd/PythonTokenizerTest.java b/pmd-python/src/test/java/net/sourceforge/pmd/cpd/PythonTokenizerTest.java index ad15fbe661..e72eb3e489 100644 --- a/pmd-python/src/test/java/net/sourceforge/pmd/cpd/PythonTokenizerTest.java +++ b/pmd-python/src/test/java/net/sourceforge/pmd/cpd/PythonTokenizerTest.java @@ -51,4 +51,10 @@ public class PythonTokenizerTest extends CpdTextComparisonTest { public void testTabWidth() { doTest("tabWidth"); } + + @Test + public void testVarWithDollar() { + doTest("var_with_dollar"); + } + } diff --git a/pmd-python/src/test/resources/net/sourceforge/pmd/lang/python/cpd/testdata/var_with_dollar.py b/pmd-python/src/test/resources/net/sourceforge/pmd/lang/python/cpd/testdata/var_with_dollar.py new file mode 100644 index 0000000000..5c42520282 --- /dev/null +++ b/pmd-python/src/test/resources/net/sourceforge/pmd/lang/python/cpd/testdata/var_with_dollar.py @@ -0,0 +1,2 @@ +def check(): + a$a = [] diff --git a/pmd-python/src/test/resources/net/sourceforge/pmd/lang/python/cpd/testdata/var_with_dollar.txt b/pmd-python/src/test/resources/net/sourceforge/pmd/lang/python/cpd/testdata/var_with_dollar.txt new file mode 100644 index 0000000000..39607ea38f --- /dev/null +++ b/pmd-python/src/test/resources/net/sourceforge/pmd/lang/python/cpd/testdata/var_with_dollar.txt @@ -0,0 +1,13 @@ + [Image] or [Truncated image[ Bcol Ecol +L1 + [def] 1 3 + [check] 5 9 + [(] 10 10 + [)] 11 11 + [:] 12 12 +L2 + [a$a] 5 7 + [=] 9 9 + [\[] 11 11 + [\]] 12 12 +EOF From 3538c6d3bd8d7c9a74df96399219277342ecbfbc Mon Sep 17 00:00:00 2001 From: Andreas Dangel Date: Fri, 6 May 2022 15:52:12 +0200 Subject: [PATCH 055/198] [core] Improve support for #text and #comment node types --- .../pmd/lang/ast/xpath/saxon/ElementNode.java | 2 +- .../rule/xpath/saxon/ElementNodeTest.java | 30 +++++++++++++++++++ 2 files changed, 31 insertions(+), 1 deletion(-) diff --git a/pmd-core/src/main/java/net/sourceforge/pmd/lang/ast/xpath/saxon/ElementNode.java b/pmd-core/src/main/java/net/sourceforge/pmd/lang/ast/xpath/saxon/ElementNode.java index ce9604fe79..702e6605d4 100644 --- a/pmd-core/src/main/java/net/sourceforge/pmd/lang/ast/xpath/saxon/ElementNode.java +++ b/pmd-core/src/main/java/net/sourceforge/pmd/lang/ast/xpath/saxon/ElementNode.java @@ -80,7 +80,7 @@ public class ElementNode extends BaseNodeInfo implements AstNodeOwner { document.nodeToElementNode.put(node, this); } - private static short determineType(Node node) { + private static int determineType(Node node) { String name = node.getXPathNodeName(); if ("#text".equals(name)) { return Type.TEXT; diff --git a/pmd-core/src/test/java/net/sourceforge/pmd/lang/rule/xpath/saxon/ElementNodeTest.java b/pmd-core/src/test/java/net/sourceforge/pmd/lang/rule/xpath/saxon/ElementNodeTest.java index ead5c73553..756e41eb46 100644 --- a/pmd-core/src/test/java/net/sourceforge/pmd/lang/rule/xpath/saxon/ElementNodeTest.java +++ b/pmd-core/src/test/java/net/sourceforge/pmd/lang/rule/xpath/saxon/ElementNodeTest.java @@ -11,6 +11,8 @@ import net.sourceforge.pmd.lang.ast.DummyNode; import net.sourceforge.pmd.lang.ast.xpath.saxon.DocumentNode; import net.sourceforge.pmd.lang.ast.xpath.saxon.ElementNode; +import net.sf.saxon.type.Type; + public class ElementNodeTest { @Test @@ -56,4 +58,32 @@ public class ElementNodeTest { Assert.assertTrue(elementFoo1.compareOrder(elementFoo2) < 0); Assert.assertTrue(elementFoo2.compareOrder(elementFoo1) > 0); } + + @Test + public void verifyTextNodeType() { + DummyNode node = new DummyNode(1, false, "dummy"); + DummyNode foo1 = new DummyNode(2, false, "foo"); + DummyNode foo2 = new DummyNode(2, false, "#text"); + node.jjtAddChild(foo1, 0); + node.jjtAddChild(foo2, 1); + + DocumentNode document = new DocumentNode(node); + ElementNode elementFoo1 = document.nodeToElementNode.get(foo1); + ElementNode elementFoo2 = document.nodeToElementNode.get(foo2); + + Assert.assertEquals(Type.ELEMENT, elementFoo1.getNodeKind()); + Assert.assertEquals(Type.TEXT, elementFoo2.getNodeKind()); + } + + @Test + public void verifyCommentNodeType() { + DummyNode node = new DummyNode(1, false, "dummy"); + DummyNode foo = new DummyNode(2, false, "#comment"); + node.jjtAddChild(foo, 0); + + DocumentNode document = new DocumentNode(node); + ElementNode elementFoo = document.nodeToElementNode.get(foo); + + Assert.assertEquals(Type.COMMENT, elementFoo.getNodeKind()); + } } From 46727eb5d72e8dfff3d947aa1156e109ad28e8bd Mon Sep 17 00:00:00 2001 From: Andreas Dangel Date: Fri, 6 May 2022 15:52:59 +0200 Subject: [PATCH 056/198] [html] Document XPath 2.0 only and text nodes handling --- docs/pages/pmd/languages/html.md | 10 ++++- .../pmd/lang/html/HtmlXPathRuleTest.java | 37 ++++++++++--------- 2 files changed, 28 insertions(+), 19 deletions(-) diff --git a/docs/pages/pmd/languages/html.md b/docs/pages/pmd/languages/html.md index acb96fc416..9c905571e1 100644 --- a/docs/pages/pmd/languages/html.md +++ b/docs/pages/pmd/languages/html.md @@ -14,5 +14,11 @@ last_updated: April 2022 (6.45.0) The HTML language module uses [jsoup](https://jsoup.org/) for parsing. -XPath rules are supported, but the DOM is not a typical XML/XPath DOM. E.g. -text nodes are normal nodes. This might change in the future. +XPath 2.0 rules are supported, but the DOM is not always a typical XML/XPath DOM. +In the Designer, text nodes appear as nodes with name "#text", but they can +be selected as usual using `text()`. + +XML Namespaces are not supported. The local name of attributes include the prefix, +so that you have to select attributes by e.g. `//*[@*[local-name() = 'if:true']]`. + +Only XPath 1.0 rules are not supported. diff --git a/pmd-html/src/test/java/net/sourceforge/pmd/lang/html/HtmlXPathRuleTest.java b/pmd-html/src/test/java/net/sourceforge/pmd/lang/html/HtmlXPathRuleTest.java index 1a70e5c0fc..1a6272dab8 100644 --- a/pmd-html/src/test/java/net/sourceforge/pmd/lang/html/HtmlXPathRuleTest.java +++ b/pmd-html/src/test/java/net/sourceforge/pmd/lang/html/HtmlXPathRuleTest.java @@ -4,18 +4,14 @@ package net.sourceforge.pmd.lang.html; -import java.io.StringReader; -import java.util.Arrays; - import org.junit.Assert; import org.junit.Test; import net.sourceforge.pmd.Report; -import net.sourceforge.pmd.RuleContext; -import net.sourceforge.pmd.lang.LanguageRegistry; -import net.sourceforge.pmd.lang.LanguageVersion; -import net.sourceforge.pmd.lang.Parser; -import net.sourceforge.pmd.lang.ast.Node; +import net.sourceforge.pmd.lang.html.ast.ASTHtmlComment; +import net.sourceforge.pmd.lang.html.ast.ASTHtmlDocument; +import net.sourceforge.pmd.lang.html.ast.ASTHtmlTextNode; +import net.sourceforge.pmd.lang.html.ast.HtmlParsingHelper; import net.sourceforge.pmd.lang.rule.XPathRule; import net.sourceforge.pmd.lang.rule.xpath.XPathVersion; @@ -46,6 +42,20 @@ public class HtmlXPathRuleTest { Assert.assertEquals(3, report.getViolations().get(0).getBeginLine()); } + @Test + public void verifyTextNodeName() { + ASTHtmlDocument document = HtmlParsingHelper.DEFAULT.parse("

foobar

"); + ASTHtmlTextNode textNode = document.getFirstDescendantOfType(ASTHtmlTextNode.class); + Assert.assertEquals("#text", textNode.getXPathNodeName()); + } + + @Test + public void verifyCommentNodeName() { + ASTHtmlDocument document = HtmlParsingHelper.DEFAULT.parse("

"); + ASTHtmlComment comment = document.getFirstDescendantOfType(ASTHtmlComment.class); + Assert.assertEquals("#comment", comment.getXPathNodeName()); + } + @Test public void selectAttributes() { // from https://developer.salesforce.com/docs/component-library/documentation/en/lwc/lwc.js_props_getter @@ -79,16 +89,9 @@ public class HtmlXPathRuleTest { } private Report runXPath(String html, String xpath) { - LanguageVersion htmlLanguage = LanguageRegistry.findLanguageByTerseName(HtmlLanguageModule.TERSE_NAME).getDefaultVersion(); - Parser parser = htmlLanguage.getLanguageVersionHandler().getParser(htmlLanguage.getLanguageVersionHandler().getDefaultParserOptions()); - XPathRule rule = new XPathRule(XPathVersion.XPATH_2_0, xpath); rule.setMessage("test"); - Node node = parser.parse("n/a", new StringReader(html)); - RuleContext context = new RuleContext(); - context.setLanguageVersion(htmlLanguage); - context.setCurrentRule(rule); - rule.apply(Arrays.asList(node), context); - return context.getReport(); + rule.setLanguage(HtmlParsingHelper.DEFAULT.getLanguage()); + return HtmlParsingHelper.DEFAULT.executeRule(rule, html); } } From db9a1d9067134c7a4f68bc5f177f0447f002ca77 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9ment=20Fournier?= Date: Sat, 7 May 2022 13:45:45 +0200 Subject: [PATCH 057/198] Deprecate some syntax about ruleset references Some undocumented ruleset reference forms are deprecated: - java-basic (resolves to rulesets/java/basic.xml), refs #2352 - 641 (resolves to rulesets/releases/641.xml) Also using `` is deprecated. As before, only the first ruleset is considered, but now the rest is not ignored silently. Refs #2612 --- .../net/sourceforge/pmd/RuleSetFactory.java | 24 ++++- .../net/sourceforge/pmd/RuleSetLoader.java | 4 +- .../sourceforge/pmd/RuleSetReferenceId.java | 101 ++++++++++++------ 3 files changed, 92 insertions(+), 37 deletions(-) diff --git a/pmd-core/src/main/java/net/sourceforge/pmd/RuleSetFactory.java b/pmd-core/src/main/java/net/sourceforge/pmd/RuleSetFactory.java index 70af9df68b..83454453df 100644 --- a/pmd-core/src/main/java/net/sourceforge/pmd/RuleSetFactory.java +++ b/pmd-core/src/main/java/net/sourceforge/pmd/RuleSetFactory.java @@ -539,7 +539,11 @@ public class RuleSetFactory { // load the ruleset with minimum priority low, so that we get all rules, to be able to exclude any rule // minimum priority will be applied again, before constructing the final ruleset RuleSetFactory ruleSetFactory = toLoader().filterAbovePriority(RulePriority.LOW).warnDeprecated(false).toFactory(); - RuleSet otherRuleSet = ruleSetFactory.createRuleSet(RuleSetReferenceId.parse(ref).get(0)); + RuleSetReferenceId ruleSetReferenceId = parseReferenceAndWarn(ruleSetBuilder, ref, "ruleset"); + if (ruleSetReferenceId == null) { + return; + } + RuleSet otherRuleSet = ruleSetFactory.createRuleSet(ruleSetReferenceId); List potentialRules = new ArrayList<>(); int countDeprecated = 0; for (Rule rule : otherRuleSet.getRules()) { @@ -589,6 +593,18 @@ public class RuleSetFactory { rulesetReferences.add(ref); } + private RuleSetReferenceId parseReferenceAndWarn(RuleSetBuilder ruleSetBuilder, String ref, String refKind) { + List references = RuleSetReferenceId.parse(ref, warnDeprecated); + if (references.size() > 1 && warnDeprecated) { + LOG.warning("Referencing several " + refKind + "s as a comma separated list is deprecated. " + + "All " + refKind + "s but the first are ignored. Reference: '" + ref + "'"); + } else if (references.isEmpty()) { + LOG.warning("Empty " + refKind + " reference in ruleset " + ruleSetBuilder.getName()); + return null; + } + return references.get(0); + } + /** * Parse a rule node as a single Rule. The Rule has been fully defined * within the context of the current RuleSet. @@ -656,7 +672,10 @@ public class RuleSetFactory { RuleSetFactory ruleSetFactory = toLoader().filterAbovePriority(RulePriority.LOW).warnDeprecated(false).toFactory(); boolean isSameRuleSet = false; - RuleSetReferenceId otherRuleSetReferenceId = RuleSetReferenceId.parse(ref).get(0); + RuleSetReferenceId otherRuleSetReferenceId = parseReferenceAndWarn(ruleSetBuilder, ref, "rule"); + if (otherRuleSetReferenceId == null) { + return; + } if (!otherRuleSetReferenceId.isExternal() && containsRule(ruleSetReferenceId, otherRuleSetReferenceId.getRuleName())) { otherRuleSetReferenceId = new RuleSetReferenceId(ref, ruleSetReferenceId); @@ -743,6 +762,7 @@ public class RuleSetFactory { * @return {@code true} if the ruleName exists */ private boolean containsRule(RuleSetReferenceId ruleSetReferenceId, String ruleName) { + // unbelievable... boolean found = false; try (InputStream ruleSet = ruleSetReferenceId.getInputStream(resourceLoader)) { DocumentBuilder builder = createDocumentBuilder(); diff --git a/pmd-core/src/main/java/net/sourceforge/pmd/RuleSetLoader.java b/pmd-core/src/main/java/net/sourceforge/pmd/RuleSetLoader.java index efe727ac60..d071d585de 100644 --- a/pmd-core/src/main/java/net/sourceforge/pmd/RuleSetLoader.java +++ b/pmd-core/src/main/java/net/sourceforge/pmd/RuleSetLoader.java @@ -150,7 +150,7 @@ public final class RuleSetLoader { * @throws RuleSetLoadException If any error occurs (eg, invalid syntax, or resource not found) */ public RuleSet loadFromResource(String rulesetPath) { - return loadFromResource(new RuleSetReferenceId(rulesetPath)); + return loadFromResource(new RuleSetReferenceId(rulesetPath, null, warnDeprecated)); } /** @@ -162,7 +162,7 @@ public final class RuleSetLoader { * @throws RuleSetLoadException If any error occurs (eg, invalid syntax) */ public RuleSet loadFromString(String filename, final String rulesetXmlContent) { - return loadFromResource(new RuleSetReferenceId(filename) { + return loadFromResource(new RuleSetReferenceId(filename, null, warnDeprecated) { @Override public InputStream getInputStream(ResourceLoader rl) { return new ByteArrayInputStream(rulesetXmlContent.getBytes(StandardCharsets.UTF_8)); diff --git a/pmd-core/src/main/java/net/sourceforge/pmd/RuleSetReferenceId.java b/pmd-core/src/main/java/net/sourceforge/pmd/RuleSetReferenceId.java index 66dd5e47c9..96c49b4597 100644 --- a/pmd-core/src/main/java/net/sourceforge/pmd/RuleSetReferenceId.java +++ b/pmd-core/src/main/java/net/sourceforge/pmd/RuleSetReferenceId.java @@ -11,6 +11,7 @@ import java.net.HttpURLConnection; import java.net.URL; import java.util.ArrayList; import java.util.List; +import java.util.logging.Logger; import org.apache.commons.lang3.StringUtils; @@ -85,6 +86,9 @@ import net.sourceforge.pmd.util.ResourceLoader; @Deprecated @InternalApi public class RuleSetReferenceId { + + private static final Logger LOG = Logger.getLogger(RuleSetReferenceId.class.getName()); + private final boolean external; private final String ruleSetFileName; private final boolean allRules; @@ -110,19 +114,33 @@ public class RuleSetReferenceId { * Rule. The external RuleSetReferenceId will be responsible for producing * the InputStream containing the Rule. * - * @param id - * The id string. - * @param externalRuleSetReferenceId - * A RuleSetReferenceId to associate with this new instance. - * @throws IllegalArgumentException - * If the ID contains a comma character. - * @throws IllegalArgumentException - * If external RuleSetReferenceId is not external. - * @throws IllegalArgumentException - * If the ID is not Rule reference when there is an external - * RuleSetReferenceId. + * @param id The id string. + * @param externalRuleSetReferenceId A RuleSetReferenceId to associate with this new instance. + * + * @throws IllegalArgumentException If the ID contains a comma character. + * @throws IllegalArgumentException If external RuleSetReferenceId is not external. + * @throws IllegalArgumentException If the ID is not Rule reference when there is an external + * RuleSetReferenceId. */ public RuleSetReferenceId(final String id, final RuleSetReferenceId externalRuleSetReferenceId) { + this(id, externalRuleSetReferenceId, false); + } + + /** + * Construct a RuleSetReferenceId for the given single ID string. If an + * external RuleSetReferenceId is given, the ID must refer to a non-external + * Rule. The external RuleSetReferenceId will be responsible for producing + * the InputStream containing the Rule. + * + * @param id The id string. + * @param externalRuleSetReferenceId A RuleSetReferenceId to associate with this new instance. + * + * @throws IllegalArgumentException If the ID contains a comma character. + * @throws IllegalArgumentException If external RuleSetReferenceId is not external. + * @throws IllegalArgumentException If the ID is not Rule reference when there is an external + * RuleSetReferenceId. + */ + RuleSetReferenceId(final String id, final RuleSetReferenceId externalRuleSetReferenceId, boolean warnDeprecated) { if (externalRuleSetReferenceId != null && !externalRuleSetReferenceId.isExternal()) { throw new IllegalArgumentException("Cannot pair with non-external <" + externalRuleSetReferenceId + ">."); @@ -177,8 +195,16 @@ public class RuleSetReferenceId { allRules = tempRuleName == null; } else { // resolve the ruleset name - it's maybe a built in ruleset - String builtinRuleSet = resolveBuiltInRuleset(tempRuleSetFileName); + String expandedRuleset = resolveDeprecatedBuiltInRulesetShorthand(tempRuleSetFileName); + String builtinRuleSet = expandedRuleset == null ? tempRuleSetFileName : expandedRuleset; if (checkRulesetExists(builtinRuleSet)) { + if (expandedRuleset != null && warnDeprecated) { + LOG.warning( + "Ruleset reference '" + tempRuleSetFileName + "' uses a deprecated form, use '" + + builtinRuleSet + "' instead" + ); + } + external = true; ruleSetFileName = builtinRuleSet; ruleName = tempRuleName; @@ -249,25 +275,22 @@ public class RuleSetReferenceId { * the ruleset name * @return the full classpath to the ruleset */ - private String resolveBuiltInRuleset(final String name) { - String result = null; - if (name != null) { - // Likely a simple RuleSet name - int index = name.indexOf('-'); - if (index >= 0) { - // Standard short name - result = "rulesets/" + name.substring(0, index) + '/' + name.substring(index + 1) + ".xml"; - } else { - // A release RuleSet? - if (name.matches("[0-9]+.*")) { - result = "rulesets/releases/" + name + ".xml"; - } else { - // Appears to be a non-standard RuleSet name - result = name; - } - } + private String resolveDeprecatedBuiltInRulesetShorthand(final String name) { + if (name == null) { + return null; } - return result; + // Likely a simple RuleSet name + int index = name.indexOf('-'); + if (index >= 0) { + // Standard short name + return "rulesets/" + name.substring(0, index) + '/' + name.substring(index + 1) + ".xml"; + } + // A release RuleSet? + if (name.matches("[0-9]+.*")) { + return "rulesets/releases/" + name + ".xml"; + } + // Appears to be a non-standard RuleSet name + return null; } /** @@ -330,11 +353,23 @@ public class RuleSetReferenceId { * Parse a String comma separated list of RuleSet reference IDs into a List * of RuleReferenceId instances. * - * @param referenceString - * A comma separated list of RuleSet reference IDs. + * @param referenceString A comma separated list of RuleSet reference IDs. + * * @return The corresponding List of RuleSetReferenceId instances. */ public static List parse(String referenceString) { + return parse(referenceString, false); + } + + /** + * Parse a String comma separated list of RuleSet reference IDs into a List + * of RuleReferenceId instances. + * + * @param referenceString A comma separated list of RuleSet reference IDs. + * + * @return The corresponding List of RuleSetReferenceId instances. + */ + public static List parse(String referenceString, boolean warnDeprecated) { List references = new ArrayList<>(); if (referenceString != null && referenceString.trim().length() > 0) { @@ -342,7 +377,7 @@ public class RuleSetReferenceId { references.add(new RuleSetReferenceId(referenceString)); } else { for (String name : referenceString.split(",")) { - references.add(new RuleSetReferenceId(name.trim())); + references.add(new RuleSetReferenceId(name.trim(), null, warnDeprecated)); } } } From 0542b333a626506960b6231a8dd3e14f72077bdd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9ment=20Fournier?= Date: Sat, 7 May 2022 14:14:50 +0200 Subject: [PATCH 058/198] Add tests and fix logic Another change is that the error in case of unresolved ruleset doesn't just dump the entire classpath, which is unreadable. Instead the classpath is logged with a debug level at the start of execution. --- .../main/java/net/sourceforge/pmd/PMD.java | 1 + .../net/sourceforge/pmd/RuleSetFactory.java | 51 ++++++++++--------- .../sourceforge/pmd/RuleSetReferenceId.java | 17 +++++-- .../sourceforge/pmd/RuleSetFactoryTest.java | 44 ++++++++++++++++ .../net/sourceforge/pmd/cli/CoreCliTest.java | 8 +++ 5 files changed, 91 insertions(+), 30 deletions(-) diff --git a/pmd-core/src/main/java/net/sourceforge/pmd/PMD.java b/pmd-core/src/main/java/net/sourceforge/pmd/PMD.java index 714bfb0e64..70dcecaacf 100644 --- a/pmd-core/src/main/java/net/sourceforge/pmd/PMD.java +++ b/pmd-core/src/main/java/net/sourceforge/pmd/PMD.java @@ -242,6 +242,7 @@ public class PMD { @Deprecated @InternalApi public static int doPMD(PMDConfiguration configuration) { + LOG.fine("Current classpath:\n" + System.getProperty("java.class.path")); try (PmdAnalysis pmd = PmdAnalysis.create(configuration)) { if (pmd.getRulesets().isEmpty()) { return pmd.getReporter().numErrors() > 0 ? -1 : 0; diff --git a/pmd-core/src/main/java/net/sourceforge/pmd/RuleSetFactory.java b/pmd-core/src/main/java/net/sourceforge/pmd/RuleSetFactory.java index 83454453df..3ae70c6dbe 100644 --- a/pmd-core/src/main/java/net/sourceforge/pmd/RuleSetFactory.java +++ b/pmd-core/src/main/java/net/sourceforge/pmd/RuleSetFactory.java @@ -492,17 +492,22 @@ public class RuleSetFactory { * @param rulesetReferences keeps track of already processed complete ruleset references in order to log a warning */ private void parseRuleNode(RuleSetReferenceId ruleSetReferenceId, RuleSetBuilder ruleSetBuilder, Node ruleNode, - boolean withDeprecatedRuleReferences, Set rulesetReferences) - throws RuleSetNotFoundException { + boolean withDeprecatedRuleReferences, Set rulesetReferences) + throws RuleSetNotFoundException { Element ruleElement = (Element) ruleNode; - String ref = ruleElement.getAttribute("ref"); - if (ref.endsWith("xml")) { - parseRuleSetReferenceNode(ruleSetBuilder, ruleElement, ref, rulesetReferences); - } else if (StringUtils.isBlank(ref)) { - parseSingleRuleNode(ruleSetReferenceId, ruleSetBuilder, ruleNode); - } else { - parseRuleReferenceNode(ruleSetReferenceId, ruleSetBuilder, ruleNode, ref, withDeprecatedRuleReferences); + if (ruleElement.hasAttribute("ref")) { + String ref = ruleElement.getAttribute("ref"); + RuleSetReferenceId refId = parseReferenceAndWarn(ruleSetBuilder, ref); + if (refId != null) { + if (refId.isAllRules()) { + parseRuleSetReferenceNode(ruleSetBuilder, ruleElement, ref, refId, rulesetReferences); + } else { + parseRuleReferenceNode(ruleSetReferenceId, ruleSetBuilder, ruleNode, ref, refId, withDeprecatedRuleReferences); + } + return; + } } + parseSingleRuleNode(ruleSetReferenceId, ruleSetBuilder, ruleNode); } /** @@ -519,8 +524,10 @@ public class RuleSetFactory { * The RuleSet reference. * @param rulesetReferences keeps track of already processed complete ruleset references in order to log a warning */ - private void parseRuleSetReferenceNode(RuleSetBuilder ruleSetBuilder, Element ruleElement, String ref, Set rulesetReferences) - throws RuleSetNotFoundException { + private void parseRuleSetReferenceNode(RuleSetBuilder ruleSetBuilder, Element ruleElement, + String ref, + RuleSetReferenceId ruleSetReferenceId, Set rulesetReferences) + throws RuleSetNotFoundException { String priority = null; NodeList childNodes = ruleElement.getChildNodes(); Set excludedRulesCheck = new HashSet<>(); @@ -539,10 +546,6 @@ public class RuleSetFactory { // load the ruleset with minimum priority low, so that we get all rules, to be able to exclude any rule // minimum priority will be applied again, before constructing the final ruleset RuleSetFactory ruleSetFactory = toLoader().filterAbovePriority(RulePriority.LOW).warnDeprecated(false).toFactory(); - RuleSetReferenceId ruleSetReferenceId = parseReferenceAndWarn(ruleSetBuilder, ref, "ruleset"); - if (ruleSetReferenceId == null) { - return; - } RuleSet otherRuleSet = ruleSetFactory.createRuleSet(ruleSetReferenceId); List potentialRules = new ArrayList<>(); int countDeprecated = 0; @@ -588,18 +591,18 @@ public class RuleSetFactory { if (rulesetReferences.contains(ref)) { LOG.warning("The ruleset " + ref + " is referenced multiple times in \"" - + ruleSetBuilder.getName() + "\"."); + + ruleSetBuilder.getName() + "\"."); } rulesetReferences.add(ref); } - private RuleSetReferenceId parseReferenceAndWarn(RuleSetBuilder ruleSetBuilder, String ref, String refKind) { + private RuleSetReferenceId parseReferenceAndWarn(RuleSetBuilder ruleSetBuilder, String ref) { List references = RuleSetReferenceId.parse(ref, warnDeprecated); if (references.size() > 1 && warnDeprecated) { - LOG.warning("Referencing several " + refKind + "s as a comma separated list is deprecated. " - + "All " + refKind + "s but the first are ignored. Reference: '" + ref + "'"); + LOG.warning("Using a comma separated list as a ref attribute is deprecated. " + + "All references but the first are ignored. Reference: '" + ref + "'"); } else if (references.isEmpty()) { - LOG.warning("Empty " + refKind + " reference in ruleset " + ruleSetBuilder.getName()); + LOG.warning("Empty ref attribute in ruleset '" + ruleSetBuilder.getName() + "'"); return null; } return references.get(0); @@ -657,7 +660,9 @@ public class RuleSetFactory { * or not */ private void parseRuleReferenceNode(RuleSetReferenceId ruleSetReferenceId, RuleSetBuilder ruleSetBuilder, - Node ruleNode, String ref, boolean withDeprecatedRuleReferences) throws RuleSetNotFoundException { + Node ruleNode, String ref, + RuleSetReferenceId otherRuleSetReferenceId, + boolean withDeprecatedRuleReferences) throws RuleSetNotFoundException { Element ruleElement = (Element) ruleNode; // Stop if we're looking for a particular Rule, and this element is not @@ -672,10 +677,6 @@ public class RuleSetFactory { RuleSetFactory ruleSetFactory = toLoader().filterAbovePriority(RulePriority.LOW).warnDeprecated(false).toFactory(); boolean isSameRuleSet = false; - RuleSetReferenceId otherRuleSetReferenceId = parseReferenceAndWarn(ruleSetBuilder, ref, "rule"); - if (otherRuleSetReferenceId == null) { - return; - } if (!otherRuleSetReferenceId.isExternal() && containsRule(ruleSetReferenceId, otherRuleSetReferenceId.getRuleName())) { otherRuleSetReferenceId = new RuleSetReferenceId(ref, ruleSetReferenceId); diff --git a/pmd-core/src/main/java/net/sourceforge/pmd/RuleSetReferenceId.java b/pmd-core/src/main/java/net/sourceforge/pmd/RuleSetReferenceId.java index 96c49b4597..94f8959bbb 100644 --- a/pmd-core/src/main/java/net/sourceforge/pmd/RuleSetReferenceId.java +++ b/pmd-core/src/main/java/net/sourceforge/pmd/RuleSetReferenceId.java @@ -87,7 +87,8 @@ import net.sourceforge.pmd.util.ResourceLoader; @InternalApi public class RuleSetReferenceId { - private static final Logger LOG = Logger.getLogger(RuleSetReferenceId.class.getName()); + // use the logger of RuleSetFactory, because the warnings conceptually come from there. + private static final Logger LOG = Logger.getLogger(RuleSetFactory.class.getName()); private final boolean external; private final String ruleSetFileName; @@ -95,6 +96,8 @@ public class RuleSetReferenceId { private final String ruleName; private final RuleSetReferenceId externalRuleSetReferenceId; + private final String originalRef; + /** * Construct a RuleSetReferenceId for the given single ID string. * @@ -141,6 +144,7 @@ public class RuleSetReferenceId { * RuleSetReferenceId. */ RuleSetReferenceId(final String id, final RuleSetReferenceId externalRuleSetReferenceId, boolean warnDeprecated) { + this.originalRef = id; if (externalRuleSetReferenceId != null && !externalRuleSetReferenceId.isExternal()) { throw new IllegalArgumentException("Cannot pair with non-external <" + externalRuleSetReferenceId + ">."); @@ -281,7 +285,7 @@ public class RuleSetReferenceId { } // Likely a simple RuleSet name int index = name.indexOf('-'); - if (index >= 0) { + if (index > 0) { // Standard short name return "rulesets/" + name.substring(0, index) + '/' + name.substring(index + 1) + ".xml"; } @@ -374,7 +378,7 @@ public class RuleSetReferenceId { if (referenceString != null && referenceString.trim().length() > 0) { if (referenceString.indexOf(',') == -1) { - references.add(new RuleSetReferenceId(referenceString)); + references.add(new RuleSetReferenceId(referenceString, null, warnDeprecated)); } else { for (String name : referenceString.split(",")) { references.add(new RuleSetReferenceId(name.trim(), null, warnDeprecated)); @@ -440,9 +444,9 @@ public class RuleSetReferenceId { InputStream in = StringUtils.isBlank(ruleSetFileName) ? null : rl.loadResourceAsStream(ruleSetFileName); if (in == null) { - throw new RuleSetNotFoundException("Can't find resource '" + ruleSetFileName + "' for rule '" + ruleName + throw new RuleSetNotFoundException("Cannot resolve rule/ruleset reference '" + originalRef + "'" + ". Make sure the resource is a valid file or URL and is on the CLASSPATH. " - + "Here's the current classpath: " + System.getProperty("java.class.path")); + + "Use --debug (or a fine log level) to see the current classpath."); } return in; } else { @@ -457,8 +461,11 @@ public class RuleSetReferenceId { * ruleSetFileName for all Rule external references, * ruleSetFileName/ruleName, for a single Rule external * references, or ruleName otherwise. + * + * @deprecated Do not rely on the format of this method, it may be changed in PMD 7. */ @Override + @Deprecated public String toString() { if (ruleSetFileName != null) { if (allRules) { diff --git a/pmd-core/src/test/java/net/sourceforge/pmd/RuleSetFactoryTest.java b/pmd-core/src/test/java/net/sourceforge/pmd/RuleSetFactoryTest.java index bfbc7ce547..365754b9c6 100644 --- a/pmd-core/src/test/java/net/sourceforge/pmd/RuleSetFactoryTest.java +++ b/pmd-core/src/test/java/net/sourceforge/pmd/RuleSetFactoryTest.java @@ -4,6 +4,7 @@ package net.sourceforge.pmd; +import static org.hamcrest.Matchers.containsString; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertNotNull; @@ -20,6 +21,7 @@ import java.util.List; import java.util.Set; import org.apache.commons.lang3.StringUtils; +import org.hamcrest.MatcherAssert; import org.junit.Test; import org.junit.rules.ExpectedException; @@ -148,6 +150,19 @@ public class RuleSetFactoryTest { assertEquals("avoid the mock rule", r.getMessage()); } + @Test + public void testSingleRuleEmptyRef() throws RuleSetNotFoundException { + RuleSet rs = loadRuleSet(SINGLE_RULE_EMPTY_REF); + assertEquals(1, rs.size()); + + MatcherAssert.assertThat(logging.getLog(), containsString("Empty ref attribute in ruleset 'test'")); + + Rule r = rs.getRules().iterator().next(); + assertEquals("MockRuleName", r.getName()); + assertEquals("net.sourceforge.pmd.lang.rule.MockRule", r.getRuleClass()); + assertEquals("avoid the mock rule", r.getMessage()); + } + @Test public void testMultipleRules() throws RuleSetNotFoundException { RuleSet rs = loadRuleSet(MULTIPLE_RULES); @@ -926,6 +941,23 @@ public class RuleSetFactoryTest { assertTrue(logging.getLog().contains("RuleSet name is missing.")); } + @Test + public void testDeprecatedRulesetReferenceProducesWarning() throws Exception { + RuleSetReferenceId ref = createRuleSetReferenceId( + "\n" + "\n" + + " Custom ruleset for tests\n" + + " \n" + + " \n"); + RuleSetLoader ruleSetFactory = new RuleSetLoader().warnDeprecated(true); + ruleSetFactory.loadFromResource(ref); + + MatcherAssert.assertThat(logging.getLog(), containsString("Ruleset reference 'dummy-basic' uses a deprecated form, use 'rulesets/dummy/basic.xml' instead")); + } + @Test public void testMissingRuleSetDescriptionIsWarning() throws Exception { RuleSetReferenceId ref = createRuleSetReferenceId( @@ -1066,6 +1098,18 @@ public class RuleSetFactoryTest { + "3\n" + ""; + private static final String SINGLE_RULE_EMPTY_REF = "\n" + + "\n" + + "testdesc\n" + + "\n" + + "3\n" + + ""; + private static final String MULTIPLE_RULES = "\n" + "\n" + "\n" diff --git a/pmd-core/src/test/java/net/sourceforge/pmd/cli/CoreCliTest.java b/pmd-core/src/test/java/net/sourceforge/pmd/cli/CoreCliTest.java index 157caf975d..dacc665ba1 100644 --- a/pmd-core/src/test/java/net/sourceforge/pmd/cli/CoreCliTest.java +++ b/pmd-core/src/test/java/net/sourceforge/pmd/cli/CoreCliTest.java @@ -5,6 +5,7 @@ package net.sourceforge.pmd.cli; import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.Matchers.containsString; import static org.hamcrest.Matchers.containsStringIgnoringCase; import static org.hamcrest.Matchers.not; import static org.junit.Assert.assertEquals; @@ -22,6 +23,7 @@ import java.util.logging.Logger; import org.apache.commons.io.IOUtils; import org.hamcrest.Matcher; +import org.hamcrest.MatcherAssert; import org.junit.Before; import org.junit.Rule; import org.junit.Test; @@ -188,6 +190,12 @@ public class CoreCliTest { } } + @Test + public void testDeprecatedRulesetSyntaxOnCommandLine() { + runPmdSuccessfully("--no-cache", "--dir", srcDir, "--rulesets", "dummy-basic"); + MatcherAssert.assertThat(loggingRule.getLog(), containsString("Ruleset reference 'dummy-basic' uses a deprecated form, use 'rulesets/dummy/basic.xml' instead")); + } + @Test public void testWrongCliOptionsDoNotPrintUsage() { From b0fd5c44006272fc4b2c7f46eaa575f73ca2ba3a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9ment=20Fournier?= Date: Sat, 7 May 2022 14:36:16 +0200 Subject: [PATCH 059/198] Update release notes --- docs/pages/release_notes.md | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/docs/pages/release_notes.md b/docs/pages/release_notes.md index c31a705241..e8339a5c95 100644 --- a/docs/pages/release_notes.md +++ b/docs/pages/release_notes.md @@ -21,6 +21,21 @@ This is a {{ site.pmd.release_type }} release. ### API Changes +#### Deprecated ruleset references + +Ruleset references with the following formats are now deprecated and will produce a warning +when used on the CLI or in a ruleset XML file: +- `-`, eg `java-basic`, which resolves to `rulesets/java/basic.xml` +- the internal release number, eg `600`, which resolves to `rulesets/releases/600.xml` + +Use the explicit forms of these references + +#### Deprecated API + +- {% jdoc core::RuleSetReferenceId#toString() %} is now deprecated. The format of this + method will remain the same until PMD 7. The deprecation is intended to steer users + away from relying on this format, as it may be changed in PMD 7. + ### External Contributions {% endtocmaker %} From abf7d71e2e5b03d6743951efe8b858ba246e82a0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9ment=20Fournier?= Date: Sat, 7 May 2022 14:47:04 +0200 Subject: [PATCH 060/198] Remove doc for deprecated things --- .../java/net/sourceforge/pmd/RuleSetReferenceId.java | 10 ---------- 1 file changed, 10 deletions(-) diff --git a/pmd-core/src/main/java/net/sourceforge/pmd/RuleSetReferenceId.java b/pmd-core/src/main/java/net/sourceforge/pmd/RuleSetReferenceId.java index 94f8959bbb..79ef421fe1 100644 --- a/pmd-core/src/main/java/net/sourceforge/pmd/RuleSetReferenceId.java +++ b/pmd-core/src/main/java/net/sourceforge/pmd/RuleSetReferenceId.java @@ -59,16 +59,6 @@ import net.sourceforge.pmd.util.ResourceLoader; * all * * - * java-basic - * rulesets/java/basic.xml - * all - * - * - * 50 - * rulesets/releases/50.xml - * all - * - * * rulesets/java/basic.xml/EmptyCatchBlock * rulesets/java/basic.xml * EmptyCatchBlock From f27ea900ab15decbaad1d8b702d211a56bb77969 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9ment=20Fournier?= Date: Sat, 7 May 2022 17:02:14 +0200 Subject: [PATCH 061/198] Fix test --- .../java/net/sourceforge/pmd/cli/CoreCliTest.java | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/pmd-core/src/test/java/net/sourceforge/pmd/cli/CoreCliTest.java b/pmd-core/src/test/java/net/sourceforge/pmd/cli/CoreCliTest.java index dacc665ba1..b420eebcbd 100644 --- a/pmd-core/src/test/java/net/sourceforge/pmd/cli/CoreCliTest.java +++ b/pmd-core/src/test/java/net/sourceforge/pmd/cli/CoreCliTest.java @@ -192,8 +192,9 @@ public class CoreCliTest { @Test public void testDeprecatedRulesetSyntaxOnCommandLine() { - runPmdSuccessfully("--no-cache", "--dir", srcDir, "--rulesets", "dummy-basic"); - MatcherAssert.assertThat(loggingRule.getLog(), containsString("Ruleset reference 'dummy-basic' uses a deprecated form, use 'rulesets/dummy/basic.xml' instead")); + startCapturingErrAndOut(); + runPmd(StatusCode.VIOLATIONS_FOUND, "--no-cache", "--dir", srcDir, "--rulesets", "dummy-basic"); + MatcherAssert.assertThat(errStreamCaptor.getLog(), containsString("Ruleset reference 'dummy-basic' uses a deprecated form, use 'rulesets/dummy/basic.xml' instead")); } @@ -231,7 +232,7 @@ public class CoreCliTest { private static void runPmdSuccessfully(Object... args) { - runPmd(0, args); + runPmd(StatusCode.OK, args); } private static String[] argsToString(Object... args) { @@ -256,9 +257,9 @@ public class CoreCliTest { return StandardCharsets.UTF_8.decode(buf).toString(); } - private static void runPmd(int expectedExitCode, Object[] args) { + private static void runPmd(StatusCode expectedExitCode, Object... args) { StatusCode actualExitCode = PMD.runPmd(argsToString(args)); - assertEquals("Exit code", expectedExitCode, actualExitCode.toInt()); + assertEquals("Exit code", expectedExitCode, actualExitCode); } From 686e878caf2ccf67e998697cd06193c0fd640083 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9ment=20Fournier?= Date: Sat, 7 May 2022 18:42:45 +0200 Subject: [PATCH 062/198] Fix #1445 - Allow CLI to take globs as parameters This doesn't interpret globs or anything, only makes the parameter parsing compatible with shell expansion. Globs are therefore available provided you use a shell with that feature --- .../net/sourceforge/pmd/PMDConfiguration.java | 48 ++++++++++++++++--- .../sourceforge/pmd/cli/PMDParameters.java | 27 +++++++---- .../pmd/cli/PmdParametersParseResult.java | 15 +++++- .../net/sourceforge/pmd/cli/CoreCliTest.java | 23 ++++++++- .../net/sourceforge/pmd/cli/FakeRuleset2.xml | 20 ++++++++ 5 files changed, 116 insertions(+), 17 deletions(-) create mode 100644 pmd-core/src/test/resources/net/sourceforge/pmd/cli/FakeRuleset2.xml diff --git a/pmd-core/src/main/java/net/sourceforge/pmd/PMDConfiguration.java b/pmd-core/src/main/java/net/sourceforge/pmd/PMDConfiguration.java index 9d3c67aead..a44ec4b421 100644 --- a/pmd-core/src/main/java/net/sourceforge/pmd/PMDConfiguration.java +++ b/pmd-core/src/main/java/net/sourceforge/pmd/PMDConfiguration.java @@ -8,6 +8,7 @@ import java.io.File; import java.io.IOException; import java.util.ArrayList; import java.util.Arrays; +import java.util.Collections; import java.util.List; import java.util.Objects; import java.util.Properties; @@ -102,7 +103,7 @@ public class PMDConfiguration extends AbstractConfiguration { // Rule and source file options private List ruleSets = new ArrayList<>(); private RulePriority minimumPriority = RulePriority.LOW; - private String inputPaths; + private List inputPaths; private String inputUri; private String inputFilePath; private String ignoreFilePath; @@ -420,19 +421,54 @@ public class PMDConfiguration extends AbstractConfiguration { * Get the comma separated list of input paths to process for source files. * * @return A comma separated list. + * + * @deprecated Use {@link #getAllInputPaths()} */ + @Deprecated public String getInputPaths() { - return inputPaths; + return inputPaths.isEmpty() ? null : StringUtils.join(inputPaths, ","); + } + + /** + * Returns an unmodifiable list. + * + * @throws NullPointerException If the parameter is null + */ + public List getAllInputPaths() { + return Collections.unmodifiableList(inputPaths); } /** * Set the comma separated list of input paths to process for source files. * - * @param inputPaths - * The comma separated list. + * @param inputPaths The comma separated list. + * + * @throws NullPointerException If the parameter is null + * @deprecated Use {@link #setInputPaths(List)} or {@link #addInputPath(String)} */ + @Deprecated public void setInputPaths(String inputPaths) { - this.inputPaths = inputPaths; + List paths = new ArrayList<>(); + Collections.addAll(paths, inputPaths.split(",")); + this.inputPaths = paths; + } + + /** + * Set the input paths to the given list of paths. + * @throws NullPointerException If the parameter is null + */ + public void setInputPaths(List inputPaths) { + this.inputPaths = new ArrayList<>(inputPaths); + } + + /** + * Add an input path. It is not split on commas. + * + * @throws NullPointerException If the parameter is null + */ + public void addInputPath(String inputPath) { + Objects.requireNonNull(inputPath); + this.inputPaths.add(inputPath); } public String getInputFilePath() { @@ -526,7 +562,7 @@ public class PMDConfiguration extends AbstractConfiguration { Renderer renderer = RendererFactory.createRenderer(reportFormat, reportProperties); renderer.setShowSuppressedViolations(showSuppressedViolations); if (reportShortNames && inputPaths != null) { - renderer.setUseShortNames(Arrays.asList(inputPaths.split(","))); + renderer.setUseShortNames(Collections.unmodifiableList(new ArrayList<>(inputPaths))); } if (withReportWriter) { renderer.setReportFile(reportFile); diff --git a/pmd-core/src/main/java/net/sourceforge/pmd/cli/PMDParameters.java b/pmd-core/src/main/java/net/sourceforge/pmd/cli/PMDParameters.java index f80dad49bd..129483ee81 100644 --- a/pmd-core/src/main/java/net/sourceforge/pmd/cli/PMDParameters.java +++ b/pmd-core/src/main/java/net/sourceforge/pmd/cli/PMDParameters.java @@ -8,6 +8,8 @@ import java.util.ArrayList; import java.util.List; import java.util.Properties; +import org.apache.commons.lang3.StringUtils; + import net.sourceforge.pmd.PMD; import net.sourceforge.pmd.PMDConfiguration; import net.sourceforge.pmd.RulePriority; @@ -29,14 +31,15 @@ import com.beust.jcommander.validators.PositiveInteger; public class PMDParameters { @Parameter(names = { "--rulesets", "-rulesets", "-R" }, description = "Comma separated list of ruleset names to use.", - required = true) - private String rulesets; + required = true, + variableArity = true) + private List rulesets; @Parameter(names = { "--uri", "-uri", "-u" }, description = "Database URI for sources.") private String uri; - @Parameter(names = { "--dir", "-dir", "-d" }, description = "Root directory for sources.") - private String sourceDir; + @Parameter(names = { "--dir", "-dir", "-d" }, description = "Root directory for sources.", variableArity = true) + private List inputPaths; @Parameter(names = { "--file-list", "-filelist" }, description = "Path to a file containing a list of files to analyze.") private String fileListPath; @@ -192,10 +195,6 @@ public class PMDParameters { * @throws IllegalArgumentException if the parameters are inconsistent or incomplete */ public PMDConfiguration toConfiguration() { - if (null == this.getSourceDir() && null == this.getUri() && null == this.getFileListPath()) { - throw new IllegalArgumentException( - "Please provide a parameter for source root directory (-dir or -d), database URI (-uri or -u), or file list path (-filelist)."); - } PMDConfiguration configuration = new PMDConfiguration(); configuration.setInputPaths(this.getSourceDir()); configuration.setInputFilePath(this.getFileListPath()); @@ -329,12 +328,22 @@ public class PMDParameters { return auxclasspath; } + @Deprecated public String getRulesets() { + return StringUtils.join(rulesets, ","); + } + + public List getRulesetRefs() { return rulesets; } + public List getInputPaths() { + return inputPaths; + } + + @Deprecated public String getSourceDir() { - return sourceDir; + return StringUtils.join(inputPaths, ","); } public String getFileListPath() { diff --git a/pmd-core/src/main/java/net/sourceforge/pmd/cli/PmdParametersParseResult.java b/pmd-core/src/main/java/net/sourceforge/pmd/cli/PmdParametersParseResult.java index 0ffc8465d0..9f33d4e470 100644 --- a/pmd-core/src/main/java/net/sourceforge/pmd/cli/PmdParametersParseResult.java +++ b/pmd-core/src/main/java/net/sourceforge/pmd/cli/PmdParametersParseResult.java @@ -105,13 +105,26 @@ public final class PmdParametersParseResult { jcommander.setProgramName("pmd"); try { - jcommander.parse(args); + parseAndValidate(jcommander, result, args); return new PmdParametersParseResult(result, filterDeprecatedOptions(args)); } catch (ParameterException e) { return new PmdParametersParseResult(e, filterDeprecatedOptions(args)); } } + private static void parseAndValidate(JCommander jcommander, PMDParameters result, String[] args) { + jcommander.parse(args); + // jcommander has no special support for global parameter validation like this + // For consistency we report this with a ParameterException + if (null == result.getSourceDir() + && null == result.getUri() + && null == result.getFileListPath()) { + throw new ParameterException( + "Please provide a parameter for source root directory (-dir or -d), database URI (-uri or -u), or file list path (-filelist)."); + } + + } + private static Map filterDeprecatedOptions(String... args) { Map argSet = new LinkedHashMap<>(SUGGESTED_REPLACEMENT); argSet.keySet().retainAll(new HashSet<>(Arrays.asList(args))); diff --git a/pmd-core/src/test/java/net/sourceforge/pmd/cli/CoreCliTest.java b/pmd-core/src/test/java/net/sourceforge/pmd/cli/CoreCliTest.java index 157caf975d..56e7337fdf 100644 --- a/pmd-core/src/test/java/net/sourceforge/pmd/cli/CoreCliTest.java +++ b/pmd-core/src/test/java/net/sourceforge/pmd/cli/CoreCliTest.java @@ -40,6 +40,7 @@ import net.sourceforge.pmd.junit.JavaUtilLoggingRule; public class CoreCliTest { private static final String DUMMY_RULESET = "net/sourceforge/pmd/cli/FakeRuleset.xml"; + private static final String DUMMY_RULESET2 = "net/sourceforge/pmd/cli/FakeRuleset2.xml"; private static final String STRING_TO_REPLACE = "__should_be_replaced__"; @Rule @@ -54,6 +55,7 @@ public class CoreCliTest { public final SystemErrRule errStreamCaptor = new SystemErrRule(); private Path srcDir; + private Path srcDir2; @Before public void setup() throws IOException { @@ -63,8 +65,10 @@ public class CoreCliTest { // create a few files srcDir = Files.createDirectories(root.resolve("src")); + srcDir2 = Files.createDirectories(root.resolve("src2")); writeString(srcDir.resolve("someSource.dummy"), "dummy text"); - + writeString(srcDir2.resolve("someSource.dummy"), "dummy text"); + // reset logger? Logger.getLogger("net.sourceforge.pmd"); } @@ -201,6 +205,23 @@ public class CoreCliTest { assertThatErrAndOut(not(containsStringIgnoringCase("Available report formats and"))); } + @Test + public void testMultipleRulesets() { + startCapturingErrAndOut(); + runPmdSuccessfully("--no-cache", "-d", srcDir, "-R", DUMMY_RULESET, DUMMY_RULESET2); + runPmdSuccessfully("--no-cache", "-d", srcDir, "-R", DUMMY_RULESET, DUMMY_RULESET2, "--"); + // ensure -d is not considered a ruleset + runPmdSuccessfully("--no-cache", "-R", DUMMY_RULESET, DUMMY_RULESET2, "-d", srcDir); + } + + @Test + public void testMultipleDirectories() { + startCapturingErrAndOut(); + runPmdSuccessfully("--no-cache", "-d", srcDir, srcDir2, "-R", DUMMY_RULESET); + runPmdSuccessfully("--no-cache", "-R", DUMMY_RULESET, "-d", srcDir, srcDir2); + runPmdSuccessfully("--no-cache", "-R", DUMMY_RULESET, "-d", srcDir, srcDir2, "--"); + } + private void assertThatErrAndOut(Matcher matcher) { assertThat("stdout", outStreamCaptor.getLog(), matcher); assertThat("stderr", errStreamCaptor.getLog(), matcher); diff --git a/pmd-core/src/test/resources/net/sourceforge/pmd/cli/FakeRuleset2.xml b/pmd-core/src/test/resources/net/sourceforge/pmd/cli/FakeRuleset2.xml new file mode 100644 index 0000000000..eebe094a76 --- /dev/null +++ b/pmd-core/src/test/resources/net/sourceforge/pmd/cli/FakeRuleset2.xml @@ -0,0 +1,20 @@ + + + + + Ruleset used by test RuleSetFactoryTest + + + + +Just for test + + 3 + + + + + From 06d0d6b0fba0a0fcec3b323f5da008fa1f6bc966 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9ment=20Fournier?= Date: Sat, 7 May 2022 18:54:49 +0200 Subject: [PATCH 063/198] More tests, release notes --- docs/pages/release_notes.md | 19 ++++++ .../net/sourceforge/pmd/cli/CoreCliTest.java | 21 ------- .../pmd/cli/PMDParametersTest.java | 63 +++++++++++++++++++ .../net/sourceforge/pmd/cli/FakeRuleset2.xml | 20 ------ 4 files changed, 82 insertions(+), 41 deletions(-) delete mode 100644 pmd-core/src/test/resources/net/sourceforge/pmd/cli/FakeRuleset2.xml diff --git a/docs/pages/release_notes.md b/docs/pages/release_notes.md index c31a705241..647a57daf2 100644 --- a/docs/pages/release_notes.md +++ b/docs/pages/release_notes.md @@ -14,6 +14,19 @@ This is a {{ site.pmd.release_type }} release. ### New and noteworthy +#### CLI improvements + +The PMD CLI now allows repeating the `--dir` (`-d`) and `--rulesets` (`-R`) options, + as well as providing several space-separated arguments to either of them. For instance: +```shell +pmd -d src/main/java src/test/java -R rset1.xml -R rset2.xml +``` +This also allows globs to be used on the CLI if your shell supports shell expansion. +For instance, the above can be written +```shell +pmd -d src/*/java -R rset*.xml +``` + ### Fixed Issues * javascript @@ -21,6 +34,12 @@ This is a {{ site.pmd.release_type }} release. ### API Changes +#### Deprecated API + +- {% jdoc core::PMDConfiguration#getInputPaths() %} and +{% jdoc core::PMDConfiguration#setInputPaths(java.lang.String) %} are now deprecated. +A new set of methods have been added, which use lists and do not rely on comma splitting. + ### External Contributions {% endtocmaker %} diff --git a/pmd-core/src/test/java/net/sourceforge/pmd/cli/CoreCliTest.java b/pmd-core/src/test/java/net/sourceforge/pmd/cli/CoreCliTest.java index 56e7337fdf..70c140023e 100644 --- a/pmd-core/src/test/java/net/sourceforge/pmd/cli/CoreCliTest.java +++ b/pmd-core/src/test/java/net/sourceforge/pmd/cli/CoreCliTest.java @@ -40,7 +40,6 @@ import net.sourceforge.pmd.junit.JavaUtilLoggingRule; public class CoreCliTest { private static final String DUMMY_RULESET = "net/sourceforge/pmd/cli/FakeRuleset.xml"; - private static final String DUMMY_RULESET2 = "net/sourceforge/pmd/cli/FakeRuleset2.xml"; private static final String STRING_TO_REPLACE = "__should_be_replaced__"; @Rule @@ -55,7 +54,6 @@ public class CoreCliTest { public final SystemErrRule errStreamCaptor = new SystemErrRule(); private Path srcDir; - private Path srcDir2; @Before public void setup() throws IOException { @@ -65,9 +63,7 @@ public class CoreCliTest { // create a few files srcDir = Files.createDirectories(root.resolve("src")); - srcDir2 = Files.createDirectories(root.resolve("src2")); writeString(srcDir.resolve("someSource.dummy"), "dummy text"); - writeString(srcDir2.resolve("someSource.dummy"), "dummy text"); // reset logger? Logger.getLogger("net.sourceforge.pmd"); } @@ -205,23 +201,6 @@ public class CoreCliTest { assertThatErrAndOut(not(containsStringIgnoringCase("Available report formats and"))); } - @Test - public void testMultipleRulesets() { - startCapturingErrAndOut(); - runPmdSuccessfully("--no-cache", "-d", srcDir, "-R", DUMMY_RULESET, DUMMY_RULESET2); - runPmdSuccessfully("--no-cache", "-d", srcDir, "-R", DUMMY_RULESET, DUMMY_RULESET2, "--"); - // ensure -d is not considered a ruleset - runPmdSuccessfully("--no-cache", "-R", DUMMY_RULESET, DUMMY_RULESET2, "-d", srcDir); - } - - @Test - public void testMultipleDirectories() { - startCapturingErrAndOut(); - runPmdSuccessfully("--no-cache", "-d", srcDir, srcDir2, "-R", DUMMY_RULESET); - runPmdSuccessfully("--no-cache", "-R", DUMMY_RULESET, "-d", srcDir, srcDir2); - runPmdSuccessfully("--no-cache", "-R", DUMMY_RULESET, "-d", srcDir, srcDir2, "--"); - } - private void assertThatErrAndOut(Matcher matcher) { assertThat("stdout", outStreamCaptor.getLog(), matcher); assertThat("stderr", errStreamCaptor.getLog(), matcher); diff --git a/pmd-core/src/test/java/net/sourceforge/pmd/cli/PMDParametersTest.java b/pmd-core/src/test/java/net/sourceforge/pmd/cli/PMDParametersTest.java index 22ca614a06..40ff67955e 100644 --- a/pmd-core/src/test/java/net/sourceforge/pmd/cli/PMDParametersTest.java +++ b/pmd-core/src/test/java/net/sourceforge/pmd/cli/PMDParametersTest.java @@ -4,10 +4,17 @@ package net.sourceforge.pmd.cli; +import static net.sourceforge.pmd.util.CollectionUtil.listOf; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; + import org.apache.commons.lang3.reflect.FieldUtils; import org.junit.Assert; import org.junit.Test; +import net.sourceforge.pmd.PMDConfiguration; + public class PMDParametersTest { @Test @@ -20,4 +27,60 @@ public class PMDParametersTest { FieldUtils.writeDeclaredField(parameters, "language", "dummy2", true); Assert.assertEquals("1.0", parameters.getVersion()); } + + @Test + public void testMultipleDirsAndRuleSets() { + PmdParametersParseResult result = PmdParametersParseResult.extractParameters( + "-d", "a", "b", "-R", "x.xml", "y.xml" + ); + assertMultipleDirsAndRulesets(result); + } + + @Test + public void testMultipleDirsAndRuleSetsWithCommas() { + PmdParametersParseResult result = PmdParametersParseResult.extractParameters( + "-d", "a,b", "-R", "x.xml,y.xml" + ); + assertMultipleDirsAndRulesets(result); + } + + @Test + public void testMultipleDirsAndRuleSetsWithRepeatedOption() { + PmdParametersParseResult result = PmdParametersParseResult.extractParameters( + "-d", "a", "-d", "b", "-R", "x.xml", "-R", "y.xml" + ); + assertMultipleDirsAndRulesets(result); + } + + @Test + public void testNoPositionalParametersAllowed() { + assertError( + // vvvv + "-R", "x.xml", "-d", "a", "--", "-d", "b" + ); + } + + + private void assertMultipleDirsAndRulesets(PmdParametersParseResult result) { + assertFalse(result.isError()); + PMDConfiguration config = result.toConfiguration(); + assertEquals(config.getAllInputPaths(), listOf("a", "b")); + assertEquals(config.getRuleSetPaths(), listOf("x.xml", "y.xml")); + } + + @Test + public void testEmptyDirOption() { + assertError("-d", "-R", "y.xml"); + } + + @Test + public void testEmptyRulesetOption() { + assertError("-R", "-d", "something"); + } + + private void assertError(String... params) { + PmdParametersParseResult result = PmdParametersParseResult.extractParameters(params); + assertTrue(result.isError()); + } + } diff --git a/pmd-core/src/test/resources/net/sourceforge/pmd/cli/FakeRuleset2.xml b/pmd-core/src/test/resources/net/sourceforge/pmd/cli/FakeRuleset2.xml deleted file mode 100644 index eebe094a76..0000000000 --- a/pmd-core/src/test/resources/net/sourceforge/pmd/cli/FakeRuleset2.xml +++ /dev/null @@ -1,20 +0,0 @@ - - - - - Ruleset used by test RuleSetFactoryTest - - - - -Just for test - - 3 - - - - - From e7229407d4ed061910a84633a09057f4b73f1e01 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9ment=20Fournier?= Date: Sat, 7 May 2022 19:29:00 +0200 Subject: [PATCH 064/198] Fix tests --- .../net/sourceforge/pmd/PMDConfiguration.java | 2 +- .../sourceforge/pmd/cli/PMDParameters.java | 2 +- .../pmd/cli/PmdParametersParseResult.java | 7 ++- .../pmd/it/BinaryDistributionIT.java | 43 +++++++++++-------- 4 files changed, 33 insertions(+), 21 deletions(-) diff --git a/pmd-core/src/main/java/net/sourceforge/pmd/PMDConfiguration.java b/pmd-core/src/main/java/net/sourceforge/pmd/PMDConfiguration.java index a44ec4b421..ad3b9603c1 100644 --- a/pmd-core/src/main/java/net/sourceforge/pmd/PMDConfiguration.java +++ b/pmd-core/src/main/java/net/sourceforge/pmd/PMDConfiguration.java @@ -103,7 +103,7 @@ public class PMDConfiguration extends AbstractConfiguration { // Rule and source file options private List ruleSets = new ArrayList<>(); private RulePriority minimumPriority = RulePriority.LOW; - private List inputPaths; + private List inputPaths = new ArrayList<>(); private String inputUri; private String inputFilePath; private String ignoreFilePath; diff --git a/pmd-core/src/main/java/net/sourceforge/pmd/cli/PMDParameters.java b/pmd-core/src/main/java/net/sourceforge/pmd/cli/PMDParameters.java index 129483ee81..fd4c8408e1 100644 --- a/pmd-core/src/main/java/net/sourceforge/pmd/cli/PMDParameters.java +++ b/pmd-core/src/main/java/net/sourceforge/pmd/cli/PMDParameters.java @@ -39,7 +39,7 @@ public class PMDParameters { private String uri; @Parameter(names = { "--dir", "-dir", "-d" }, description = "Root directory for sources.", variableArity = true) - private List inputPaths; + private List inputPaths = new ArrayList<>(); @Parameter(names = { "--file-list", "-filelist" }, description = "Path to a file containing a list of files to analyze.") private String fileListPath; diff --git a/pmd-core/src/main/java/net/sourceforge/pmd/cli/PmdParametersParseResult.java b/pmd-core/src/main/java/net/sourceforge/pmd/cli/PmdParametersParseResult.java index 9f33d4e470..2f863ba4d9 100644 --- a/pmd-core/src/main/java/net/sourceforge/pmd/cli/PmdParametersParseResult.java +++ b/pmd-core/src/main/java/net/sourceforge/pmd/cli/PmdParametersParseResult.java @@ -114,13 +114,16 @@ public final class PmdParametersParseResult { private static void parseAndValidate(JCommander jcommander, PMDParameters result, String[] args) { jcommander.parse(args); + if (result.isHelp() || result.isVersion()) { + return; + } // jcommander has no special support for global parameter validation like this // For consistency we report this with a ParameterException - if (null == result.getSourceDir() + if (result.getInputPaths().isEmpty() && null == result.getUri() && null == result.getFileListPath()) { throw new ParameterException( - "Please provide a parameter for source root directory (-dir or -d), database URI (-uri or -u), or file list path (-filelist)."); + "Please provide a parameter for source root directory (--dir or -d), database URI (--uri or -u), or file list path (--file-list)."); } } 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 48c9bc3ee3..fdb2a97706 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 @@ -36,6 +36,8 @@ public class BinaryDistributionIT extends AbstractBinaryDistributionTest { } } + private final String srcDir = new File(".", "src/test/resources/sample-source/java/").getAbsolutePath(); + @Test public void testFileExistence() { assertTrue(getBinaryDistribution().exists()); @@ -75,27 +77,34 @@ public class BinaryDistributionIT extends AbstractBinaryDistributionTest { } @Test - public void runPMD() throws Exception { - String srcDir = new File(".", "src/test/resources/sample-source/java/").getAbsolutePath(); + public void testPmdJavaQuickstart() throws Exception { + ExecutionResult result = PMDExecutor.runPMDRules(folder.newFile().toPath(), tempDir, srcDir, "rulesets/java/quickstart.xml"); + result.assertExecutionResult(4, ""); + } - ExecutionResult result; - - result = PMDExecutor.runPMD(tempDir); // without any argument, display usage help and error - result.assertExecutionResultErrOutput(1, CliMessages.runWithHelpFlagMessage()); - - result = PMDExecutor.runPMD(tempDir, "-h"); - result.assertExecutionResult(0, SUPPORTED_LANGUAGES_PMD); - - result = PMDExecutor.runPMDRules(folder.newFile().toPath(), tempDir, srcDir, "src/test/resources/rulesets/sample-ruleset.xml"); - result.assertExecutionResult(4, "", "JumbledIncrementer.java:8:"); - - // also test XML format - result = PMDExecutor.runPMDRules(folder.newFile().toPath(), tempDir, srcDir, "src/test/resources/rulesets/sample-ruleset.xml", "xml"); + @Test + public void testPmdXmlFormat() throws Exception { + ExecutionResult result = PMDExecutor.runPMDRules(folder.newFile().toPath(), tempDir, srcDir, "src/test/resources/rulesets/sample-ruleset.xml", "xml"); result.assertExecutionResult(4, "", "JumbledIncrementer.java\">"); result.assertExecutionResult(4, "", " Date: Sat, 7 May 2022 19:33:29 +0200 Subject: [PATCH 065/198] release notes --- docs/pages/release_notes.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/docs/pages/release_notes.md b/docs/pages/release_notes.md index 647a57daf2..9c87026392 100644 --- a/docs/pages/release_notes.md +++ b/docs/pages/release_notes.md @@ -29,6 +29,8 @@ pmd -d src/*/java -R rset*.xml ### Fixed Issues +* cli + * [#1445](https://github.com/pmd/pmd/issues/1445): \[core] Allow CLI to take globs as parameters * javascript * [#3948](https://github.com/pmd/pmd/issues/3948): \[js] Invalid operator error for method property in object literal From 5657559026f5d7584b35172b87b9eff4d860c89a Mon Sep 17 00:00:00 2001 From: Per Abich Date: Sun, 8 May 2022 11:55:20 +0200 Subject: [PATCH 066/198] Fixed #3954 and wrote test confirming it. --- .../bestpractices/UseCollectionIsEmptyRule.java | 15 ++++----------- .../bestpractices/xml/UseCollectionIsEmpty.xml | 13 +++++++++++++ 2 files changed, 17 insertions(+), 11 deletions(-) diff --git a/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/rule/bestpractices/UseCollectionIsEmptyRule.java b/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/rule/bestpractices/UseCollectionIsEmptyRule.java index 27974ec845..5ddf60c787 100644 --- a/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/rule/bestpractices/UseCollectionIsEmptyRule.java +++ b/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/rule/bestpractices/UseCollectionIsEmptyRule.java @@ -12,17 +12,7 @@ import java.util.List; import java.util.Map; import net.sourceforge.pmd.lang.ast.Node; -import net.sourceforge.pmd.lang.java.ast.ASTClassOrInterfaceBody; -import net.sourceforge.pmd.lang.java.ast.ASTEnumBody; -import net.sourceforge.pmd.lang.java.ast.ASTMethodDeclaration; -import net.sourceforge.pmd.lang.java.ast.ASTName; -import net.sourceforge.pmd.lang.java.ast.ASTPrimaryExpression; -import net.sourceforge.pmd.lang.java.ast.ASTPrimaryPrefix; -import net.sourceforge.pmd.lang.java.ast.ASTPrimarySuffix; -import net.sourceforge.pmd.lang.java.ast.ASTResultType; -import net.sourceforge.pmd.lang.java.ast.ASTType; -import net.sourceforge.pmd.lang.java.ast.ASTVariableDeclarator; -import net.sourceforge.pmd.lang.java.ast.ASTVariableDeclaratorId; +import net.sourceforge.pmd.lang.java.ast.*; import net.sourceforge.pmd.lang.java.rule.AbstractInefficientZeroCheck; import net.sourceforge.pmd.lang.java.symboltable.ClassScope; import net.sourceforge.pmd.lang.java.symboltable.JavaNameOccurrence; @@ -124,6 +114,9 @@ public class UseCollectionIsEmptyRule extends AbstractInefficientZeroCheck { if (classOrEnumBody == null) { classOrEnumBody = expr.getFirstParentOfType(ASTEnumBody.class); } + if (classOrEnumBody == null) { + classOrEnumBody = expr.getFirstParentOfType(ASTRecordBody.class); + } List varDeclarators = classOrEnumBody.findDescendantsOfType(ASTVariableDeclarator.class); for (ASTVariableDeclarator varDeclarator : varDeclarators) { if (varDeclarator.getName().equals(varName)) { diff --git a/pmd-java/src/test/resources/net/sourceforge/pmd/lang/java/rule/bestpractices/xml/UseCollectionIsEmpty.xml b/pmd-java/src/test/resources/net/sourceforge/pmd/lang/java/rule/bestpractices/xml/UseCollectionIsEmpty.xml index 77e39ab95d..5e5439f3ff 100644 --- a/pmd-java/src/test/resources/net/sourceforge/pmd/lang/java/rule/bestpractices/xml/UseCollectionIsEmpty.xml +++ b/pmd-java/src/test/resources/net/sourceforge/pmd/lang/java/rule/bestpractices/xml/UseCollectionIsEmpty.xml @@ -489,4 +489,17 @@ public class Foo { } ]]>
+ + With records + 0 + stringSet) { + + public boolean hasMoreThanOneItem() { + return this.stringSet.size() > 1; + } +} ]]> + From 418fe220b9ab541ba06a2b7b0fec3f7d25602e70 Mon Sep 17 00:00:00 2001 From: Per Abich Date: Sun, 8 May 2022 12:45:40 +0200 Subject: [PATCH 067/198] Fixed #3954 missing reporting of issue on records. --- .../bestpractices/UseCollectionIsEmptyRule.java | 8 +++++++- .../bestpractices/xml/UseCollectionIsEmpty.xml | 14 ++++++++++++++ 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/rule/bestpractices/UseCollectionIsEmptyRule.java b/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/rule/bestpractices/UseCollectionIsEmptyRule.java index 5ddf60c787..d0abde1db2 100644 --- a/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/rule/bestpractices/UseCollectionIsEmptyRule.java +++ b/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/rule/bestpractices/UseCollectionIsEmptyRule.java @@ -115,7 +115,13 @@ public class UseCollectionIsEmptyRule extends AbstractInefficientZeroCheck { classOrEnumBody = expr.getFirstParentOfType(ASTEnumBody.class); } if (classOrEnumBody == null) { - classOrEnumBody = expr.getFirstParentOfType(ASTRecordBody.class); + classOrEnumBody = expr.getFirstParentOfType(ASTRecordDeclaration.class); + List descendantsOfType = classOrEnumBody.findDescendantsOfType(ASTVariableDeclaratorId.class); + for (ASTVariableDeclaratorId variableDeclaratorId : descendantsOfType) { + if (variableDeclaratorId.getName().equals(varName)) { + return variableDeclaratorId.getTypeNode().getTypeDefinition(); + } + } } List varDeclarators = classOrEnumBody.findDescendantsOfType(ASTVariableDeclarator.class); for (ASTVariableDeclarator varDeclarator : varDeclarators) { diff --git a/pmd-java/src/test/resources/net/sourceforge/pmd/lang/java/rule/bestpractices/xml/UseCollectionIsEmpty.xml b/pmd-java/src/test/resources/net/sourceforge/pmd/lang/java/rule/bestpractices/xml/UseCollectionIsEmpty.xml index 5e5439f3ff..d296c995dc 100644 --- a/pmd-java/src/test/resources/net/sourceforge/pmd/lang/java/rule/bestpractices/xml/UseCollectionIsEmpty.xml +++ b/pmd-java/src/test/resources/net/sourceforge/pmd/lang/java/rule/bestpractices/xml/UseCollectionIsEmpty.xml @@ -500,6 +500,20 @@ public record Record(Set stringSet) { public boolean hasMoreThanOneItem() { return this.stringSet.size() > 1; } +} ]]> + + + With records and size check + 1 + 6 + stringSet) { + + public boolean hasMoreThanOneItem() { + return this.stringSet.size() == 0; + } } ]]> From f85a635669de95234f027ea1b6a1681d91abd529 Mon Sep 17 00:00:00 2001 From: Per Abich Date: Sun, 8 May 2022 13:02:15 +0200 Subject: [PATCH 068/198] Fixed checkstyle violations --- .../bestpractices/UseCollectionIsEmptyRule.java | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/rule/bestpractices/UseCollectionIsEmptyRule.java b/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/rule/bestpractices/UseCollectionIsEmptyRule.java index d0abde1db2..c1cc304e6a 100644 --- a/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/rule/bestpractices/UseCollectionIsEmptyRule.java +++ b/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/rule/bestpractices/UseCollectionIsEmptyRule.java @@ -12,7 +12,18 @@ import java.util.List; import java.util.Map; import net.sourceforge.pmd.lang.ast.Node; -import net.sourceforge.pmd.lang.java.ast.*; +import net.sourceforge.pmd.lang.java.ast.ASTClassOrInterfaceBody; +import net.sourceforge.pmd.lang.java.ast.ASTEnumBody; +import net.sourceforge.pmd.lang.java.ast.ASTMethodDeclaration; +import net.sourceforge.pmd.lang.java.ast.ASTName; +import net.sourceforge.pmd.lang.java.ast.ASTPrimaryExpression; +import net.sourceforge.pmd.lang.java.ast.ASTPrimaryPrefix; +import net.sourceforge.pmd.lang.java.ast.ASTPrimarySuffix; +import net.sourceforge.pmd.lang.java.ast.ASTRecordDeclaration; +import net.sourceforge.pmd.lang.java.ast.ASTResultType; +import net.sourceforge.pmd.lang.java.ast.ASTType; +import net.sourceforge.pmd.lang.java.ast.ASTVariableDeclarator; +import net.sourceforge.pmd.lang.java.ast.ASTVariableDeclaratorId; import net.sourceforge.pmd.lang.java.rule.AbstractInefficientZeroCheck; import net.sourceforge.pmd.lang.java.symboltable.ClassScope; import net.sourceforge.pmd.lang.java.symboltable.JavaNameOccurrence; From 8d7074dbaa5d2ce5d921788a5cdac401f01e3161 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9ment=20Fournier?= Date: Sun, 8 May 2022 15:17:40 +0200 Subject: [PATCH 069/198] Improve doc for parameters --- docs/pages/pmd/userdocs/cli_reference.md | 10 ++--- docs/pages/release_notes.md | 1 + .../sourceforge/pmd/cli/PMDParameters.java | 42 +++++++++++++++---- 3 files changed, 41 insertions(+), 12 deletions(-) diff --git a/docs/pages/pmd/userdocs/cli_reference.md b/docs/pages/pmd/userdocs/cli_reference.md index 0a27287864..69a29d966d 100644 --- a/docs/pages/pmd/userdocs/cli_reference.md +++ b/docs/pages/pmd/userdocs/cli_reference.md @@ -76,14 +76,14 @@ The tool comes with a rather extensive help text, simply running with `--help`! %} {% include custom/cli_option_row.html options="--file-list" option_arg="filepath" - description="Path to file containing a comma delimited list of files to analyze. + description="Path to file containing a list of files to analyze, one path per line. If this is given, then you don't need to provide `--dir`." %} {% include custom/cli_option_row.html options="--force-language" option_arg="lang" description="Force a language to be used for all input files, irrespective of - filenames. When using this option, the automatic language selection - by extension is disabled and all files are tried to be parsed with + file names. When using this option, the automatic language selection + by extension is disabled and PMD tries to parse all files with the given language `<lang>`. Parsing errors are ignored and unparsable files are skipped. @@ -92,9 +92,9 @@ The tool comes with a rather extensive help text, simply running with `--help`! %} {% include custom/cli_option_row.html options="--ignore-list" option_arg="filepath" - description="Path to file containing a comma delimited list of files to ignore. + description="Path to file containing a list of files to ignore, one path per line. This option can be combined with `--dir` and `--file-list`. - This ignore list takes precedence over any files in the filelist." + This ignore list takes precedence over any files in the file-list." %} {% include custom/cli_option_row.html options="--help,-h,-H" description="Display help on usage." diff --git a/docs/pages/release_notes.md b/docs/pages/release_notes.md index 9c87026392..dea79b1d19 100644 --- a/docs/pages/release_notes.md +++ b/docs/pages/release_notes.md @@ -26,6 +26,7 @@ For instance, the above can be written ```shell pmd -d src/*/java -R rset*.xml ``` +Please use theses new forms instead of using comma-separated list as argument to these options. ### Fixed Issues diff --git a/pmd-core/src/main/java/net/sourceforge/pmd/cli/PMDParameters.java b/pmd-core/src/main/java/net/sourceforge/pmd/cli/PMDParameters.java index fd4c8408e1..18c1da8a28 100644 --- a/pmd-core/src/main/java/net/sourceforge/pmd/cli/PMDParameters.java +++ b/pmd-core/src/main/java/net/sourceforge/pmd/cli/PMDParameters.java @@ -30,21 +30,44 @@ import com.beust.jcommander.validators.PositiveInteger; @InternalApi public class PMDParameters { - @Parameter(names = { "--rulesets", "-rulesets", "-R" }, description = "Comma separated list of ruleset names to use.", + @Parameter(names = { "--rulesets", "-rulesets", "-R" }, + description = "Path to a ruleset xml file. " + + "The path may reference a resource on the classpath of the application, be a local file system path, or a URL. " + + "The option can be repeated, and multiple arguments can be provided to a single occurrence of the option.", required = true, variableArity = true) private List rulesets; - @Parameter(names = { "--uri", "-uri", "-u" }, description = "Database URI for sources.") + @Parameter(names = { "--uri", "-uri", "-u" }, + description = "Database URI for sources. " + + "One of --dir, --file-list or --uri must be provided. " + ) private String uri; - @Parameter(names = { "--dir", "-dir", "-d" }, description = "Root directory for sources.", variableArity = true) + @Parameter(names = { "--dir", "-dir", "-d" }, + description = "Path to a source file, or directory containing source files to analyze. " + // About the following line: + // In PMD 6, this is only the case for files found in directories. If you + // specify a file directly, and it is unknown, then the Java parser is used. + + "Note that a file is only effectively added if it matches a language known by PMD. " + + "Zip and Jar files are also supported, if they are specified directly " + + "(archive files found while exploring a directory are not recursively expanded). " + + "This option can be repeated, and multiple arguments can be provided to a single occurrence of the option. " + + "One of --dir, --file-list or --uri must be provided. ", + variableArity = true) private List inputPaths = new ArrayList<>(); - @Parameter(names = { "--file-list", "-filelist" }, description = "Path to a file containing a list of files to analyze.") + @Parameter(names = { "--file-list", "-filelist" }, + description = + "Path to a file containing a list of files to analyze, one path per line. " + + "One of --dir, --file-list or --uri must be provided. " + ) private String fileListPath; - @Parameter(names = { "--ignore-list", "-ignorelist" }, description = "Path to a file containing a list of files to ignore.") + @Parameter(names = { "--ignore-list", "-ignorelist" }, + description = "Path to a file containing a list of files to exclude from the analysis, one path per line. " + + "This option can be combined with --dir and --file-list. " + ) private String ignoreListPath; @Parameter(names = { "--format", "-format", "-f" }, description = "Report format type.") @@ -106,12 +129,17 @@ public class PMDParameters { @Parameter(names = { "-language", "-l" }, description = "Specify a language PMD should use.") private String language = null; - @Parameter(names = { "--force-language", "-force-language" }, description = "Force a language to be used for all input files, irrespective of filenames.") + @Parameter(names = { "--force-language", "-force-language" }, + description = "Force a language to be used for all input files, irrespective of file names. " + + "When using this option, the automatic language selection by extension is disabled, and PMD " + + "tries to parse all input files with the given language's parser. " + + "Parsing errors are ignored." + ) private String forceLanguage = null; @Parameter(names = { "--aux-classpath", "-auxclasspath" }, description = "Specifies the classpath for libraries used by the source code. " - + "This is used by the type resolution. The platform specific path delimiter " + + "This is used to resolve types in Java source files. The platform specific path delimiter " + "(\":\" on Linux, \";\" on Windows) is used to separate the entries. " + "Alternatively, a single 'file:' URL to a text file containing path elements on consecutive lines " + "can be specified.") From d0ed105b9060aaa59a87e59d5bc7cef03bd5acf8 Mon Sep 17 00:00:00 2001 From: Per Abich Date: Mon, 9 May 2022 09:12:33 +0200 Subject: [PATCH 070/198] Slight refactoring of my changes to reduce complexity --- .../bestpractices/UseCollectionIsEmptyRule.java | 17 +++++------------ 1 file changed, 5 insertions(+), 12 deletions(-) diff --git a/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/rule/bestpractices/UseCollectionIsEmptyRule.java b/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/rule/bestpractices/UseCollectionIsEmptyRule.java index c1cc304e6a..b780c22291 100644 --- a/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/rule/bestpractices/UseCollectionIsEmptyRule.java +++ b/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/rule/bestpractices/UseCollectionIsEmptyRule.java @@ -22,7 +22,6 @@ import net.sourceforge.pmd.lang.java.ast.ASTPrimarySuffix; import net.sourceforge.pmd.lang.java.ast.ASTRecordDeclaration; import net.sourceforge.pmd.lang.java.ast.ASTResultType; import net.sourceforge.pmd.lang.java.ast.ASTType; -import net.sourceforge.pmd.lang.java.ast.ASTVariableDeclarator; import net.sourceforge.pmd.lang.java.ast.ASTVariableDeclaratorId; import net.sourceforge.pmd.lang.java.rule.AbstractInefficientZeroCheck; import net.sourceforge.pmd.lang.java.symboltable.ClassScope; @@ -124,20 +123,14 @@ public class UseCollectionIsEmptyRule extends AbstractInefficientZeroCheck { Node classOrEnumBody = expr.getFirstParentOfType(ASTClassOrInterfaceBody.class); if (classOrEnumBody == null) { classOrEnumBody = expr.getFirstParentOfType(ASTEnumBody.class); - } + } if (classOrEnumBody == null) { classOrEnumBody = expr.getFirstParentOfType(ASTRecordDeclaration.class); - List descendantsOfType = classOrEnumBody.findDescendantsOfType(ASTVariableDeclaratorId.class); - for (ASTVariableDeclaratorId variableDeclaratorId : descendantsOfType) { - if (variableDeclaratorId.getName().equals(varName)) { - return variableDeclaratorId.getTypeNode().getTypeDefinition(); - } - } } - List varDeclarators = classOrEnumBody.findDescendantsOfType(ASTVariableDeclarator.class); - for (ASTVariableDeclarator varDeclarator : varDeclarators) { - if (varDeclarator.getName().equals(varName)) { - return varDeclarator.getVariableId().getTypeNode().getTypeDefinition(); + List varDeclaratorIds = classOrEnumBody.findDescendantsOfType(ASTVariableDeclaratorId.class); + for (ASTVariableDeclaratorId variableDeclaratorId : varDeclaratorIds) { + if (variableDeclaratorId.getName().equals(varName)) { + return variableDeclaratorId.getTypeNode().getTypeDefinition(); } } return null; From 402939f9cc928fddab8a72df85993718cc610cd8 Mon Sep 17 00:00:00 2001 From: Luke Lukes <45536418+lukelukes@users.noreply.github.com> Date: Tue, 10 May 2022 10:13:30 +0300 Subject: [PATCH 071/198] [java] ImmutableField: fix mockito/spring false positives --- .../java/rule/design/ImmutableFieldRule.java | 13 ++++++++++ .../java/rule/design/xml/ImmutableField.xml | 26 +++++++++++++++++++ 2 files changed, 39 insertions(+) diff --git a/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/rule/design/ImmutableFieldRule.java b/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/rule/design/ImmutableFieldRule.java index 76fb6639f1..69baff8219 100644 --- a/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/rule/design/ImmutableFieldRule.java +++ b/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/rule/design/ImmutableFieldRule.java @@ -4,6 +4,8 @@ package net.sourceforge.pmd.lang.java.rule.design; +import java.util.ArrayList; +import java.util.Collection; import java.util.HashSet; import java.util.List; import java.util.Map; @@ -41,6 +43,17 @@ public class ImmutableFieldRule extends AbstractLombokAwareRule { CHECKDECL } + @Override + protected Collection defaultSuppressionAnnotations() { + Collection defaultValues = new ArrayList<>(super.defaultSuppressionAnnotations()); + defaultValues.add("org.mockito.Mock"); + defaultValues.add("org.mockito.InjectMocks"); + defaultValues.add("org.springframework.beans.factory.annotation.Autowired"); + defaultValues.add("org.springframework.boot.test.mock.mockito.MockBean"); + + return defaultValues; + } + @Override public Object visit(ASTClassOrInterfaceDeclaration node, Object data) { Object result = super.visit(node, data); diff --git a/pmd-java/src/test/resources/net/sourceforge/pmd/lang/java/rule/design/xml/ImmutableField.xml b/pmd-java/src/test/resources/net/sourceforge/pmd/lang/java/rule/design/xml/ImmutableField.xml index 359a1ce214..2b645e9839 100644 --- a/pmd-java/src/test/resources/net/sourceforge/pmd/lang/java/rule/design/xml/ImmutableField.xml +++ b/pmd-java/src/test/resources/net/sourceforge/pmd/lang/java/rule/design/xml/ImmutableField.xml @@ -569,6 +569,32 @@ public class ExampleImmutableField { this.str = strLocal+"123"; } } +} + ]]> + + + + #3874 [java] ImmutableField - false positive when using field setter annotations + 0 + From 28b0d13da9cfb519b925ed80199ebfcf5b7b1ec5 Mon Sep 17 00:00:00 2001 From: Andreas Dangel Date: Thu, 12 May 2022 15:16:49 +0200 Subject: [PATCH 072/198] [java] UseArraysAsList - ignore non-trivial loops Fixes #3965 --- docs/pages/release_notes.md | 2 + .../resources/category/java/performance.xml | 1 + .../rule/performance/xml/UseArraysAsList.xml | 38 +++++++++++++++++++ 3 files changed, 41 insertions(+) diff --git a/docs/pages/release_notes.md b/docs/pages/release_notes.md index c31a705241..d50ee17ddc 100644 --- a/docs/pages/release_notes.md +++ b/docs/pages/release_notes.md @@ -16,6 +16,8 @@ This is a {{ site.pmd.release_type }} release. ### Fixed Issues +* java-performance + * [#3965](https://github.com/pmd/pmd/issues/3965): \[java] UseArraysAsList false positive with non-trivial loops * javascript * [#3948](https://github.com/pmd/pmd/issues/3948): \[js] Invalid operator error for method property in object literal diff --git a/pmd-java/src/main/resources/category/java/performance.xml b/pmd-java/src/main/resources/category/java/performance.xml index de0987520d..2c0f9cd450 100644 --- a/pmd-java/src/main/resources/category/java/performance.xml +++ b/pmd-java/src/main/resources/category/java/performance.xml @@ -968,6 +968,7 @@ You must use `new ArrayList<>(Arrays.asList(...))` if that is inconvenient for y + + + [java] UseArraysAsList false positive with non-trivial loops #3965 + 0 + l = new ArrayList<>(100); + for (int i = 0; i < 100; i++) { + switch (lookup(ints[i])) { + case 1: l.add(ints[i]); break; // line 10 - false positive + case 2: l.addAll(getInts(i)); break; + } + } + + List anotherList = new ArrayList<>(); + for (int i : ints) { + switch (lookup(i)) { + case 1: anotherList.add(i); break; // line 18 - false positive + case 2: anotherList.addAll(getInts(i)); break; + } + } + } + + int lookup(int a) { + return a; + } + + List getInts(int a) { + return Arrays.asList(a); + } +} +]]> + From f81752dc57c4c15b89e2da25c2963607e3eec1f6 Mon Sep 17 00:00:00 2001 From: Andreas Dangel Date: Thu, 12 May 2022 15:54:47 +0200 Subject: [PATCH 073/198] [java] UseArraysAsList - skip primitive arrays Fixes #3379 --- docs/pages/release_notes.md | 1 + .../resources/category/java/performance.xml | 10 ++++- .../rule/performance/xml/UseArraysAsList.xml | 42 +++++++++++++++---- 3 files changed, 43 insertions(+), 10 deletions(-) diff --git a/docs/pages/release_notes.md b/docs/pages/release_notes.md index d50ee17ddc..a6e1fe7d24 100644 --- a/docs/pages/release_notes.md +++ b/docs/pages/release_notes.md @@ -17,6 +17,7 @@ This is a {{ site.pmd.release_type }} release. ### Fixed Issues * java-performance + * [#3379](https://github.com/pmd/pmd/issues/3379): \[java] UseArraysAsList must ignore primitive arrays * [#3965](https://github.com/pmd/pmd/issues/3965): \[java] UseArraysAsList false positive with non-trivial loops * javascript * [#3948](https://github.com/pmd/pmd/issues/3948): \[js] Invalid operator error for method property in object literal diff --git a/pmd-java/src/main/resources/category/java/performance.xml b/pmd-java/src/main/resources/category/java/performance.xml index 2c0f9cd450..8411f35603 100644 --- a/pmd-java/src/main/resources/category/java/performance.xml +++ b/pmd-java/src/main/resources/category/java/performance.xml @@ -970,6 +970,12 @@ You must use `new ArrayList<>(Arrays.asList(...))` if that is inconvenient for y [not(.//IfStatement)] [count(Statement//StatementExpression)=1] [@Foreach = true() or ForInit//VariableInitializer//Literal[@IntLiteral= true() and @Image='0']] + (: skip primitive types :) + [@Foreach = true() and Expression[not(pmd-java:typeIs('boolean[]') or pmd-java:typeIs('char[]') or pmd-java:typeIs('byte[]') or pmd-java:typeIs('short[]') or pmd-java:typeIs('int[]') or pmd-java:typeIs('long[]') or pmd-java:typeIs('float[]') or pmd-java:typeIs('double[]'))] + or Expression/RelationalExpression/PrimaryExpression/PrimaryPrefix/Name[substring-before(@Image, '.length') = + ancestor::MethodDeclaration[1]//VariableDeclaratorId[not(pmd-java:typeIs('boolean[]') or pmd-java:typeIs('char[]') or pmd-java:typeIs('byte[]') or pmd-java:typeIs('short[]') or pmd-java:typeIs('int[]') or pmd-java:typeIs('long[]') or pmd-java:typeIs('float[]') or pmd-java:typeIs('double[]'))] + /@Name] + ] //StatementExpression [PrimaryExpression [PrimaryPrefix/Name @@ -1013,12 +1019,12 @@ public class Test { public void foo(Integer[] ints) { // could just use Arrays.asList(ints) List l = new ArrayList<>(100); - for (int i = 0; i < 100; i++) { + for (int i = 0; i < ints.length; i++) { l.add(ints[i]); } List anotherList = new ArrayList<>(); - for (int i = 0; i < 100; i++) { + for (int i = 0; i < ints.length; i++) { anotherList.add(ints[i].toString()); // won't trigger the rule } } diff --git a/pmd-java/src/test/resources/net/sourceforge/pmd/lang/java/rule/performance/xml/UseArraysAsList.xml b/pmd-java/src/test/resources/net/sourceforge/pmd/lang/java/rule/performance/xml/UseArraysAsList.xml index 11ba87f95b..a3ad5af636 100644 --- a/pmd-java/src/test/resources/net/sourceforge/pmd/lang/java/rule/performance/xml/UseArraysAsList.xml +++ b/pmd-java/src/test/resources/net/sourceforge/pmd/lang/java/rule/performance/xml/UseArraysAsList.xml @@ -14,9 +14,9 @@ import java.util.List; public class Bar { void foo() { - Integer[] ints = new Integer(10); - List l = new ArrayList(10); - for (int i = 0; i < 100; i++) { + Integer[] ints = new Integer[10]; + List l = new ArrayList(ints.length); + for (int i = 0; i < ints.length; i++) { l.add(ints[i]); } } @@ -114,11 +114,13 @@ public class Test { public void foo(Integer[] ints) { // could just use Arrays.asList(ints) List l = new ArrayList(10); - for (int i = 0; i < 100; i++) { + for (int i = 0; i < ints.length; i++) { l.add(ints[i]); } - for (int i = 0; i < 100; i++) { - l.add(a[i].toString()); // won't trigger the rule + + List l2 = new ArrayList(10); + for (int i = 0; i < ints.length; i++) { + l2.add(ints[i].toString()); // won't trigger the rule } } } @@ -179,11 +181,11 @@ public class Test { public void foo(Integer[] ints) { // could just use Arrays.asList(ints) List l = new ArrayList<>(100); - for (int i = 0; i < 100; i++) { + for (int i = 0; i < ints.length; i++) { l.add(ints[i]); // line 9, here is the violation } List anotherList = new ArrayList<>(); - for (int i = 0; i < 100; i++) { + for (int i = 0; i < ints.length; i++) { anotherList.add(ints[i].toString()); // line 13 - false positive } } @@ -226,6 +228,30 @@ public class Test { return Arrays.asList(a); } } +]]> + + + + [java] UseArraysAsList must ignore primitive arrays #3379 + 0 + arrayList = new ArrayList<>(array.length); + for (short v : array) { + arrayList.add(v); // line 9 - false positive + } + + List arrayList2 = new ArrayList<>(array.length); + for (int i = 0; i < array.length; i++) { + arrayList2.add(array[i]); // line 14 - false positive + } + } +} ]]> From dc512e8a04cb4a6fbb74e16c737ac204394b11a2 Mon Sep 17 00:00:00 2001 From: Andreas Dangel Date: Thu, 12 May 2022 17:33:54 +0200 Subject: [PATCH 074/198] [ci] Update gems - update pmdtester from 1.5.0 to 1.5.1 - update nokogiri from 1.13.5 to 1.13.6 - update activesupport from 6.0.4.8 to 6.0.5 --- Gemfile.lock | 4 ++-- docs/Gemfile.lock | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/Gemfile.lock b/Gemfile.lock index f20255105a..b41e9645e9 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -68,14 +68,14 @@ GEM multipart-post (2.1.1) nap (1.1.0) no_proxy_fix (0.1.2) - nokogiri (1.13.5) + nokogiri (1.13.6) mini_portile2 (~> 2.8.0) racc (~> 1.4) octokit (4.22.0) faraday (>= 0.9) sawyer (~> 0.8.0, >= 0.5.3) open4 (1.3.4) - pmdtester (1.5.0) + pmdtester (1.5.1) differ (~> 0.1) liquid (~> 5.2) logger-colors (~> 1.0) diff --git a/docs/Gemfile.lock b/docs/Gemfile.lock index 020814c547..af044ad8d5 100644 --- a/docs/Gemfile.lock +++ b/docs/Gemfile.lock @@ -1,7 +1,7 @@ GEM remote: https://rubygems.org/ specs: - activesupport (6.0.4.8) + activesupport (6.0.5) concurrent-ruby (~> 1.0, >= 1.0.2) i18n (>= 0.7, < 2) minitest (~> 5.1) @@ -232,7 +232,7 @@ GEM jekyll-seo-tag (~> 2.1) minitest (5.15.0) multipart-post (2.1.1) - nokogiri (1.13.5) + nokogiri (1.13.6) mini_portile2 (~> 2.8.0) racc (~> 1.4) octokit (4.22.0) From 03a51a73a5cc1c2c8d6fea15e03bffe4b91872c1 Mon Sep 17 00:00:00 2001 From: Andreas Dangel Date: Thu, 12 May 2022 17:48:04 +0200 Subject: [PATCH 075/198] Bump kotlin from 1.4.10 to 1.4.32 Fixes https://nvd.nist.gov/vuln/detail/CVE-2020-29582 --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 08d245b8ff..8387d38853 100644 --- a/pom.xml +++ b/pom.xml @@ -85,7 +85,7 @@ ${maven.compiler.test.target} - 1.4.10 + 1.4.32 4.3.1 1.4.32 From a28c2399218b17d799cbae3b5cc9adbede46ca77 Mon Sep 17 00:00:00 2001 From: Andreas Dangel Date: Thu, 12 May 2022 17:54:20 +0200 Subject: [PATCH 076/198] Bump kotest from 4.3.1 to 4.4.3 --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 8387d38853..7b503ac88e 100644 --- a/pom.xml +++ b/pom.xml @@ -86,7 +86,7 @@ ${maven.compiler.test.target} 1.4.32 - 4.3.1 + 4.4.3 1.4.32 From 4944177cc4a8a6b3467950bab061795e1c261813 Mon Sep 17 00:00:00 2001 From: Andreas Dangel Date: Sat, 7 May 2022 21:30:47 +0200 Subject: [PATCH 077/198] [core] Add missing methods to IOUtil as replacement for IOUtils --- .../java/net/sourceforge/pmd/util/IOUtil.java | 318 +++++++++++++++++- .../net/sourceforge/pmd/util/IOUtilTest.java | 258 ++++++++++++++ 2 files changed, 574 insertions(+), 2 deletions(-) create mode 100644 pmd-core/src/test/java/net/sourceforge/pmd/util/IOUtilTest.java diff --git a/pmd-core/src/main/java/net/sourceforge/pmd/util/IOUtil.java b/pmd-core/src/main/java/net/sourceforge/pmd/util/IOUtil.java index d4833987d1..791561bc7a 100644 --- a/pmd-core/src/main/java/net/sourceforge/pmd/util/IOUtil.java +++ b/pmd-core/src/main/java/net/sourceforge/pmd/util/IOUtil.java @@ -7,21 +7,30 @@ package net.sourceforge.pmd.util; import java.io.BufferedReader; import java.io.Closeable; import java.io.File; +import java.io.FilterInputStream; import java.io.IOException; +import java.io.InputStream; +import java.io.OutputStream; import java.io.OutputStreamWriter; import java.io.Reader; import java.io.Writer; +import java.nio.ByteBuffer; +import java.nio.CharBuffer; import java.nio.charset.Charset; +import java.nio.charset.CharsetDecoder; +import java.nio.charset.CharsetEncoder; +import java.nio.charset.CodingErrorAction; import java.nio.charset.StandardCharsets; import java.nio.charset.UnsupportedCharsetException; import java.nio.file.Files; import java.nio.file.Path; +import java.nio.file.Paths; import java.security.AccessController; import java.security.PrivilegedAction; import java.util.Collection; import java.util.List; +import java.util.Objects; -import org.apache.commons.io.IOUtils; import org.apache.commons.lang3.StringUtils; import net.sourceforge.pmd.annotation.InternalApi; @@ -35,6 +44,8 @@ import net.sourceforge.pmd.annotation.InternalApi; @Deprecated public final class IOUtil { + private static final int BUFFER_SIZE = 8192; + private IOUtil() { } @@ -119,7 +130,7 @@ public final class IOUtil { public static void tryCloseClassLoader(ClassLoader classLoader) { if (classLoader instanceof Closeable) { - IOUtils.closeQuietly((Closeable) classLoader); + closeQuietly((Closeable) classLoader); } } @@ -169,4 +180,307 @@ public final class IOUtil { } } + public static void closeQuietly(Closeable closeable) { + try { + closeable.close(); + } catch (IOException ignored) { + // ignored + } + } + + public static byte[] toByteArray(InputStream stream) throws IOException { + byte[] result = new byte[0]; + byte[] buffer = new byte[BUFFER_SIZE]; + int count = stream.read(buffer); + while (count > -1) { + byte[] newResult = new byte[result.length + count]; + System.arraycopy(result, 0, newResult, 0, result.length); + System.arraycopy(buffer, 0, newResult, result.length, count); + result = newResult; + count = stream.read(buffer); + } + return result; + } + + public static long skipFully(InputStream stream, long n) throws IOException { + if (n < 0) { + throw new IllegalArgumentException(); + } + + long bytesToSkip = n; + byte[] buffer = new byte[(int) Math.min(BUFFER_SIZE, bytesToSkip)]; + while (bytesToSkip > 0) { + int count = stream.read(buffer, 0, (int) Math.min(BUFFER_SIZE, bytesToSkip)); + if (count < 0) { + // reached eof + break; + } + bytesToSkip -= count; + } + return n - bytesToSkip; + } + + public static String normalizePath(String path) { + Path path1 = Paths.get(path); + path1.isAbsolute(); + String normalized = path1.normalize().toString(); + if (normalized.contains("." + File.separator) || normalized.contains(".." + File.separator) || "".equals(normalized)) { + return null; + } + return normalized; + } + + public static boolean equalsNormalizedPaths(String path1, String path2) { + return Objects.equals(normalizePath(path1), normalizePath(path2)); + } + + public static String getFilenameExtension(String name) { + String filename = Paths.get(name).getFileName().toString(); + int dot = filename.lastIndexOf('.'); + if (dot > -1) { + return filename.substring(dot + 1); + } + return ""; + } + + public static String getFilenameBase(String name) { + String filename = Paths.get(name).getFileName().toString(); + int dot = filename.lastIndexOf('.'); + if (dot > -1) { + return filename.substring(0, dot); + } + return filename; + } + + public static void copy(InputStream from, OutputStream to) throws IOException { + byte[] buffer = new byte[BUFFER_SIZE]; + int count = from.read(buffer); + while (count > -1) { + to.write(buffer, 0, count); + count = from.read(buffer); + } + } + + public static void copy(Reader from, Writer to) throws IOException { + char[] buffer = new char[BUFFER_SIZE]; + int count = from.read(buffer); + while (count > -1) { + to.write(buffer, 0, count); + count = from.read(buffer); + } + } + + public static String readFileToString(File file) throws IOException { + return readFileToString(file, Charset.defaultCharset()); + } + + public static String readFileToString(File file, Charset charset) throws IOException { + byte[] bytes = Files.readAllBytes(file.toPath()); + return charset.decode(ByteBuffer.wrap(bytes)).toString(); + } + + public static String readToString(Reader reader) throws IOException { + StringBuilder sb = new StringBuilder(BUFFER_SIZE); + char[] buffer = new char[BUFFER_SIZE]; + int count = reader.read(buffer); + while (count > -1) { + sb.append(buffer, 0, count); + count = reader.read(buffer); + } + return sb.toString(); + } + + public static String readToString(InputStream stream, Charset charset) throws IOException { + byte[] bytes = toByteArray(stream); + return charset.decode(ByteBuffer.wrap(bytes)).toString(); + } + + public static InputStream fromReader(Reader reader) throws IOException { + class ReaderInputStream extends InputStream { + private final Reader reader; + private final CharBuffer charBuffer = CharBuffer.allocate(BUFFER_SIZE); + private final ByteBuffer byteBuffer = ByteBuffer.allocate(BUFFER_SIZE); + private final CharsetEncoder encoder; + + private boolean eof; + + ReaderInputStream(Reader reader) { + this.reader = reader; + encoder = Charset.defaultCharset().newEncoder() + .onMalformedInput(CodingErrorAction.REPLACE) + .onUnmappableCharacter(CodingErrorAction.REPLACE); + charBuffer.clear(); + byteBuffer.clear(); + byteBuffer.flip(); // byte buffer is empty at the beginning, no bytes read yet + } + + @Override + public int read() throws IOException { + if (!byteBuffer.hasRemaining()) { + if (charBuffer.hasRemaining() && !eof) { + int count = reader.read(charBuffer); + eof = count == -1; + } + byteBuffer.clear(); + charBuffer.flip(); + encoder.encode(charBuffer, byteBuffer, eof); + byteBuffer.flip(); + charBuffer.flip(); + } + + if (byteBuffer.hasRemaining()) { + return byteBuffer.get(); + } + + return -1; + } + + @Override + public int available() throws IOException { + return byteBuffer.remaining(); + } + + @Override + public void close() throws IOException { + reader.close(); + } + } + + return new ReaderInputStream(reader); + } + + public static OutputStream fromWriter(Writer writer, String encoding) throws UnsupportedCharsetException { + class WriterOutputStream extends OutputStream { + private final Writer writer; + private final CharsetDecoder decoder; + private final ByteBuffer byteBuffer = ByteBuffer.allocate(BUFFER_SIZE); + private final CharBuffer charBuffer = CharBuffer.allocate(BUFFER_SIZE); + + WriterOutputStream(Writer writer, String encoding) throws UnsupportedCharsetException { + this.writer = writer; + Charset charset = Charset.forName(encoding); + decoder = charset.newDecoder() + .onMalformedInput(CodingErrorAction.REPLACE) + .onUnmappableCharacter(CodingErrorAction.REPLACE); + byteBuffer.clear(); + charBuffer.clear(); + } + + @Override + public void write(int b) throws IOException { + if (!byteBuffer.hasRemaining()) { + decodeByteBuffer(false); + } + byteBuffer.put((byte) b); + } + + @Override + public void flush() throws IOException { + decodeByteBuffer(false); + } + + private void decodeByteBuffer(boolean isClosing) throws IOException { + byteBuffer.flip(); + charBuffer.clear(); + decoder.decode(byteBuffer, charBuffer, isClosing); + writer.write(charBuffer.array(), 0, charBuffer.position()); + writer.flush(); + byteBuffer.compact(); + } + + @Override + public void close() throws IOException { + flush(); + decodeByteBuffer(true); + writer.close(); + } + } + + return new WriterOutputStream(writer, encoding); + } + + /** + *

+ * Input stream that skips an optional byte order mark at the beginning + * of the stream. Whether the stream had a byte order mark (encoded in either UTF-8, + * UTF-16LE or UTF-16BE) can be checked with {@link #hasBom()}. The corresponding + * charset can be retrieved with {@link #getBomCharsetName()}. + *

+ * + *

+ * If the stream didn't had a BOM, then no bytes are skipped. + *

+ */ + public static class BomAwareInputStream extends FilterInputStream { + + private byte[] begin; + int beginIndex; + + private String charset; + + public BomAwareInputStream(InputStream in) { + super(in); + begin = determineBom(); + } + + private byte[] determineBom() { + byte[] bytes = new byte[3]; + try { + int count = in.read(bytes); + if (count == 3 && bytes[0] == (byte) 0xef && bytes[1] == (byte) 0xbb && bytes[2] == (byte) 0xbf) { + charset = StandardCharsets.UTF_8.name(); + return new byte[0]; // skip all 3 bytes + } else if (count >= 2 && bytes[0] == (byte) 0xfe && bytes[1] == (byte) 0xff) { + charset = StandardCharsets.UTF_16BE.name(); + return new byte[] { bytes[2] }; + } else if (count >= 2 && bytes[0] == (byte) 0xff && bytes[1] == (byte) 0xfe) { + charset = StandardCharsets.UTF_16LE.name(); + return new byte[] { bytes[2] }; + } else if (count == 3) { + return bytes; + } + + if (count < 0) { + return new byte[0]; + } + + byte[] read = new byte[count]; + for (int i = 0; i < count; i++) { + read[i] = bytes[i]; + } + return read; + } catch (IOException e) { + throw new RuntimeException(e); + } + } + + @Override + public int read() throws IOException { + if (beginIndex < begin.length) { + return begin[beginIndex++]; + } + return super.read(); + } + + @Override + public int read(byte[] b, int off, int len) throws IOException { + if (beginIndex < begin.length) { + int count = 0; + for (; count < len && beginIndex < begin.length; beginIndex++) { + b[off + count] = begin[beginIndex]; + count++; + } + return count; + } + return super.read(b, off, len); + } + + public boolean hasBom() { + return charset != null; + } + + public String getBomCharsetName() { + return charset; + } + } } diff --git a/pmd-core/src/test/java/net/sourceforge/pmd/util/IOUtilTest.java b/pmd-core/src/test/java/net/sourceforge/pmd/util/IOUtilTest.java new file mode 100644 index 0000000000..35e772cfc9 --- /dev/null +++ b/pmd-core/src/test/java/net/sourceforge/pmd/util/IOUtilTest.java @@ -0,0 +1,258 @@ +/* + * BSD-style license; for more info see http://pmd.sourceforge.net/license.html + */ + +package net.sourceforge.pmd.util; + +import java.io.ByteArrayInputStream; +import java.io.ByteArrayOutputStream; +import java.io.CharArrayReader; +import java.io.IOException; +import java.io.InputStream; +import java.io.OutputStream; +import java.io.Reader; +import java.io.StringReader; +import java.io.StringWriter; +import java.nio.charset.Charset; +import java.nio.charset.StandardCharsets; +import java.nio.file.Files; +import java.nio.file.Path; + +import org.apache.commons.lang3.SystemUtils; +import org.junit.Assert; +import org.junit.Test; +import org.junit.function.ThrowingRunnable; + +public class IOUtilTest { + + @Test + public void testReadAllBytes() throws IOException { + byte[] data = "12345".getBytes(StandardCharsets.UTF_8); + try (InputStream stream = new ByteArrayInputStream(data)) { + byte[] bytes = IOUtil.toByteArray(stream); + Assert.assertEquals(5, bytes.length); + Assert.assertArrayEquals(data, bytes); + } + } + + @Test + public void testToByteArrayResize() throws IOException { + int size = 8192 + 8192 + 10; + byte[] data = new byte[size]; + for (int i = 0; i < size; i++) { + data[i] = 'A'; + } + try (InputStream stream = new ByteArrayInputStream(data)) { + byte[] bytes = IOUtil.toByteArray(stream); + Assert.assertEquals(size, bytes.length); + Assert.assertArrayEquals(data, bytes); + } + } + + @Test + public void testSkipFully() throws IOException { + byte[] data = "12345".getBytes(StandardCharsets.UTF_8); + try (InputStream stream = new ByteArrayInputStream(data)) { + Assert.assertThrows(IllegalArgumentException.class, new ThrowingRunnable() { + @Override + public void run() throws Throwable { + IOUtil.skipFully(stream, -1); + } + }); + + Assert.assertEquals(3, IOUtil.skipFully(stream, 3)); + byte[] bytes = IOUtil.toByteArray(stream); + Assert.assertEquals(2, bytes.length); + Assert.assertArrayEquals("45".getBytes(StandardCharsets.UTF_8), bytes); + } + } + + @Test + public void testSkipFully2() throws IOException { + byte[] data = "12345".getBytes(StandardCharsets.UTF_8); + try (InputStream stream = new ByteArrayInputStream(data)) { + // skip more bytes than the stream contains + Assert.assertEquals(data.length, IOUtil.skipFully(stream, data.length + 1)); + byte[] bytes = IOUtil.toByteArray(stream); + Assert.assertEquals(0, bytes.length); + } + } + + @Test + public void testNormalizePath() { + Assert.assertEquals("ab/cd.txt", IOUtil.normalizePath("ab/ef/../cd.txt")); + Assert.assertEquals("/a.txt", IOUtil.normalizePath("/x/../../a.txt")); + Assert.assertEquals("/foo", IOUtil.normalizePath("//../foo")); + Assert.assertEquals("/foo", IOUtil.normalizePath("/foo//")); + Assert.assertEquals("/foo", IOUtil.normalizePath("/foo/./")); + Assert.assertEquals("/bar", IOUtil.normalizePath("/foo/../bar")); + Assert.assertEquals("/bar", IOUtil.normalizePath("/foo/../bar/")); + Assert.assertEquals("/baz", IOUtil.normalizePath("/foo/../bar/../baz")); + Assert.assertEquals("/foo/bar", IOUtil.normalizePath("//foo//./bar")); + Assert.assertEquals("foo", IOUtil.normalizePath("foo/bar/..")); + Assert.assertEquals("bar", IOUtil.normalizePath("foo/../bar")); + Assert.assertEquals("/foo/baz", IOUtil.normalizePath("//foo/bar/../baz")); + Assert.assertEquals("~/bar", IOUtil.normalizePath("~/foo/../bar/")); + Assert.assertEquals("/", IOUtil.normalizePath("/../")); + Assert.assertEquals("bar", IOUtil.normalizePath("~/../bar")); + Assert.assertEquals("bar", IOUtil.normalizePath("./bar")); + + Assert.assertNull(IOUtil.normalizePath("../foo")); + Assert.assertNull(IOUtil.normalizePath("foo/../../bar")); + Assert.assertNull(IOUtil.normalizePath(".")); + + Assert.assertTrue(IOUtil.equalsNormalizedPaths("foo/../bar", "bar/./")); + + if (SystemUtils.IS_OS_WINDOWS) { + Assert.assertEquals("C:\\bar", IOUtil.normalizePath("C:\\..\\bar")); + Assert.assertEquals("ab\\cd.txt", IOUtil.normalizePath("ab\\ef\\..\\cd.txt")); + Assert.assertEquals("C:\\ab\\cd.txt", IOUtil.normalizePath("C:\\ab\\ef\\..\\.\\cd.txt")); + Assert.assertNull(IOUtil.normalizePath("..\\foo")); + Assert.assertNull(IOUtil.normalizePath("foo\\..\\..\\bar")); + } + } + + @Test + public void testFilenameExtension() { + Assert.assertEquals("txt", IOUtil.getFilenameExtension("ab/cd.txt")); + Assert.assertEquals("txt", IOUtil.getFilenameExtension("ab.cd.txt")); + Assert.assertEquals("", IOUtil.getFilenameExtension("ab/cd")); + Assert.assertEquals("html", IOUtil.getFilenameExtension("cd.html")); + } + + @Test + public void testFilenameBase() { + Assert.assertEquals("cd", IOUtil.getFilenameBase("ab/cd.txt")); + Assert.assertEquals("ab.cd", IOUtil.getFilenameBase("ab.cd.txt")); + Assert.assertEquals("cd", IOUtil.getFilenameBase("ab/cd")); + } + + @Test + public void testBomAwareStream() throws IOException { + assertBomStream("No BOM".getBytes(StandardCharsets.UTF_8), "No BOM", null); + assertBomStream("\ufeffBOM".getBytes(StandardCharsets.UTF_8), "BOM", StandardCharsets.UTF_8.name()); + assertBomStream("\ufeffBOM".getBytes(StandardCharsets.UTF_16LE), "BOM", StandardCharsets.UTF_16LE.name()); + assertBomStream("\ufeffBOM".getBytes(StandardCharsets.UTF_16BE), "BOM", StandardCharsets.UTF_16BE.name()); + } + + private void assertBomStream(byte[] data, String expectedData, String expectedCharset) throws IOException { + try (IOUtil.BomAwareInputStream stream = new IOUtil.BomAwareInputStream(new ByteArrayInputStream(data))) { + if (expectedCharset != null) { + Assert.assertTrue(stream.hasBom()); + Assert.assertEquals(expectedCharset, stream.getBomCharsetName()); + Assert.assertEquals(expectedData, new String(IOUtil.toByteArray(stream), stream.getBomCharsetName())); + + } else { + Assert.assertFalse(stream.hasBom()); + Assert.assertNull(stream.getBomCharsetName()); + Assert.assertEquals(expectedData, new String(IOUtil.toByteArray(stream), StandardCharsets.UTF_8)); + } + } + } + + @Test + public void testOutputStreamFromWriter() throws IOException { + StringWriter writer = new StringWriter(); + try (OutputStream outputStream = IOUtil.fromWriter(writer, "UTF-8")) { + outputStream.write("abc".getBytes(StandardCharsets.UTF_8)); + } + Assert.assertEquals("abc", writer.toString()); + } + + @Test + public void testInputStreamFromReader() throws IOException { + try (InputStream inputStream = IOUtil.fromReader(new StringReader("abc"))) { + byte[] bytes = IOUtil.toByteArray(inputStream); + Assert.assertEquals("abc", new String(bytes, StandardCharsets.UTF_8)); + } + } + + @Test + public void testCopyStream() throws IOException { + int size = 8192 + 8192 + 10; + byte[] data = new byte[size]; + for (int i = 0; i < size; i++) { + data[i] = 'A'; + } + try (InputStream stream = new ByteArrayInputStream(data); + ByteArrayOutputStream out = new ByteArrayOutputStream()) { + IOUtil.copy(stream, out); + byte[] bytes = out.toByteArray(); + Assert.assertEquals(size, bytes.length); + Assert.assertArrayEquals(data, bytes); + } + } + + @Test + public void testCopyReader() throws IOException { + int size = 8192 + 8192 + 10; + char[] data = new char[size]; + for (int i = 0; i < size; i++) { + data[i] = 'A'; + } + try (Reader reader = new CharArrayReader(data); + StringWriter writer = new StringWriter()) { + IOUtil.copy(reader, writer); + char[] chars = writer.toString().toCharArray(); + Assert.assertEquals(size, chars.length); + Assert.assertArrayEquals(data, chars); + } + } + + @Test + public void testReadEmptyStream() throws IOException { + try (InputStream in = new ByteArrayInputStream(new byte[0])) { + byte[] bytes = IOUtil.toByteArray(in); + Assert.assertNotNull(bytes); + Assert.assertEquals(0, bytes.length); + } + } + + @Test + public void testCloseQuietly() { + class Stream extends InputStream { + private boolean closed = false; + + @Override + public int read() throws IOException { + return 0; + } + + @Override + public void close() throws IOException { + closed = true; + throw new IOException("test"); + } + + public boolean isClosed() { + return closed; + } + } + + Stream stream = new Stream(); + IOUtil.closeQuietly(stream); + Assert.assertTrue(stream.isClosed()); + } + + @Test + public void testReadFileToString() throws IOException { + String testString = "Test ABC"; + Path tempFile = Files.createTempFile("pmd", ".txt"); + Files.write(tempFile, testString.getBytes(Charset.defaultCharset())); + Assert.assertEquals(testString, IOUtil.readFileToString(tempFile.toFile())); + } + + @Test + public void testReadToString() throws IOException { + String testString = "testReadToString"; + Reader reader = new StringReader(testString); + Assert.assertEquals(testString, IOUtil.readToString(reader)); + } + + @Test + public void testReadStreamToString() throws IOException { + String testString = "testReadStreamToString"; + InputStream stream = new ByteArrayInputStream(testString.getBytes(StandardCharsets.UTF_8)); + Assert.assertEquals(testString, IOUtil.readToString(stream, StandardCharsets.UTF_8)); + } +} From 753cb49e403b71d683bc7bcc7104fd01cb813530 Mon Sep 17 00:00:00 2001 From: Andreas Dangel Date: Fri, 13 May 2022 09:51:54 +0200 Subject: [PATCH 078/198] [all] Remove dependency to commons-io --- pmd-apex/pom.xml | 4 ---- pmd-core/pom.xml | 4 ---- pmd-dist/pom.xml | 4 ---- pmd-doc/pom.xml | 4 ---- pmd-java/pom.xml | 4 ---- pmd-javascript/pom.xml | 4 ---- pmd-lang-test/pom.xml | 4 ---- pmd-plsql/pom.xml | 4 ---- pmd-scala-modules/pmd-scala-common/pom.xml | 4 ---- pmd-test/pom.xml | 4 ---- pmd-xml/pom.xml | 4 ---- pom.xml | 5 ----- 12 files changed, 49 deletions(-) diff --git a/pmd-apex/pom.xml b/pmd-apex/pom.xml index 9c0e6b93a9..4b7786ff4e 100644 --- a/pmd-apex/pom.xml +++ b/pmd-apex/pom.xml @@ -58,10 +58,6 @@ pom - - commons-io - commons-io - org.apache.commons commons-lang3 diff --git a/pmd-core/pom.xml b/pmd-core/pom.xml index bd5ed97a91..bd60fcdfad 100644 --- a/pmd-core/pom.xml +++ b/pmd-core/pom.xml @@ -111,10 +111,6 @@ com.beust jcommander - - commons-io - commons-io - jaxen jaxen diff --git a/pmd-dist/pom.xml b/pmd-dist/pom.xml index 66d4134964..58348f8bbf 100644 --- a/pmd-dist/pom.xml +++ b/pmd-dist/pom.xml @@ -236,10 +236,6 @@ - - commons-io - commons-io - org.apache.commons commons-lang3 diff --git a/pmd-doc/pom.xml b/pmd-doc/pom.xml index db23e84ae7..5fda1dc5b9 100644 --- a/pmd-doc/pom.xml +++ b/pmd-doc/pom.xml @@ -83,10 +83,6 @@ pmd-core ${project.version} - - commons-io - commons-io - org.apache.commons commons-lang3 diff --git a/pmd-java/pom.xml b/pmd-java/pom.xml index b85810aaeb..df12c9505f 100644 --- a/pmd-java/pom.xml +++ b/pmd-java/pom.xml @@ -127,10 +127,6 @@ org.ow2.asm asm - - commons-io - commons-io - org.apache.commons commons-lang3 diff --git a/pmd-javascript/pom.xml b/pmd-javascript/pom.xml index d4256cf9bc..d87540aceb 100644 --- a/pmd-javascript/pom.xml +++ b/pmd-javascript/pom.xml @@ -84,10 +84,6 @@ rhino 1.7.14 - - commons-io - commons-io - junit diff --git a/pmd-lang-test/pom.xml b/pmd-lang-test/pom.xml index c657cdd6b8..cbe2246ebd 100644 --- a/pmd-lang-test/pom.xml +++ b/pmd-lang-test/pom.xml @@ -81,10 +81,6 @@ org.apache.commons commons-lang3 - - commons-io - commons-io - - - commons-io - commons-io - 2.6 - org.apache.commons commons-lang3 From 2887fe3ae0e7cb573380142aa004d040b47f8877 Mon Sep 17 00:00:00 2001 From: Andreas Dangel Date: Fri, 13 May 2022 09:52:13 +0200 Subject: [PATCH 079/198] [core] Replace IOUtils with IOUtil --- .../sourceforge/pmd/RuleSetFactoryCompatibility.java | 5 ++--- .../main/java/net/sourceforge/pmd/RuleSetWriter.java | 4 ++-- .../main/java/net/sourceforge/pmd/ant/Formatter.java | 6 +++--- .../sourceforge/pmd/cache/AbstractAnalysisCache.java | 5 ++--- .../java/net/sourceforge/pmd/cache/AnalysisResult.java | 6 ++---- .../pmd/cache/internal/RawFileFingerprinter.java | 4 ++-- .../src/main/java/net/sourceforge/pmd/cpd/CPD.java | 6 ++---- .../main/java/net/sourceforge/pmd/cpd/SourceCode.java | 10 ++++------ .../net/sourceforge/pmd/document/DocumentFile.java | 4 ++-- .../pmd/internal/util/FileCollectionUtil.java | 5 ++--- .../net/sourceforge/pmd/lang/document/NioTextFile.java | 5 ++--- .../pmd/processor/AbstractPMDProcessor.java | 4 ++-- .../sourceforge/pmd/renderers/AbstractRenderer.java | 4 +--- .../net/sourceforge/pmd/renderers/XMLRenderer.java | 4 ++-- .../main/java/net/sourceforge/pmd/util/FileFinder.java | 10 +++++++--- .../main/java/net/sourceforge/pmd/util/FileUtil.java | 3 +-- .../pmd/util/datasource/ReaderDataSource.java | 5 ++--- .../pmd/RuleSetFactoryCompatibilityTest.java | 10 +++++----- .../net/sourceforge/pmd/RuleSetReferenceIdTest.java | 10 +++++----- .../src/test/java/net/sourceforge/pmd/RuleSetTest.java | 4 ++-- .../test/java/net/sourceforge/pmd/ant/PMDTaskTest.java | 9 +++++---- .../test/java/net/sourceforge/pmd/cli/CoreCliTest.java | 4 ++-- .../java/net/sourceforge/pmd/cpd/CPDFilelistTest.java | 6 +++--- .../test/java/net/sourceforge/pmd/cpd/CpdXsltTest.java | 5 +++-- .../net/sourceforge/pmd/document/DocumentFileTest.java | 7 ++++--- .../net/sourceforge/pmd/junit/JavaUtilLoggingRule.java | 9 +++++++-- .../net/sourceforge/pmd/lang/DummyLanguageModule.java | 4 ++-- .../pmd/renderers/AbstractRendererTest.java | 4 ++-- .../sourceforge/pmd/renderers/JsonRendererTest.java | 4 ++-- .../sourceforge/pmd/renderers/SarifRendererTest.java | 5 ++--- .../net/sourceforge/pmd/renderers/XMLRendererTest.java | 4 ++-- .../sourceforge/pmd/renderers/YAHTMLRendererTest.java | 10 +++++----- .../pmd/util/treeexport/TreeExportCliTest.java | 4 ++-- .../sourceforge/pmd/lang/ast/test/BaseParsingHelper.kt | 4 ++-- .../sourceforge/pmd/AbstractRuleSetFactoryTest.java | 4 ++-- 35 files changed, 97 insertions(+), 100 deletions(-) diff --git a/pmd-core/src/main/java/net/sourceforge/pmd/RuleSetFactoryCompatibility.java b/pmd-core/src/main/java/net/sourceforge/pmd/RuleSetFactoryCompatibility.java index 6ed1d189a4..2d4c1ab420 100644 --- a/pmd-core/src/main/java/net/sourceforge/pmd/RuleSetFactoryCompatibility.java +++ b/pmd-core/src/main/java/net/sourceforge/pmd/RuleSetFactoryCompatibility.java @@ -16,9 +16,8 @@ import java.util.logging.Logger; import java.util.regex.Matcher; import java.util.regex.Pattern; -import org.apache.commons.io.IOUtils; - import net.sourceforge.pmd.annotation.InternalApi; +import net.sourceforge.pmd.util.IOUtil; /** * Provides a simple filter mechanism to avoid failing to parse an old ruleset, @@ -116,7 +115,7 @@ public class RuleSetFactoryCompatibility { * @throws IOException if the stream couldn't be read */ public Reader filterRuleSetFile(InputStream stream) throws IOException { - byte[] bytes = IOUtils.toByteArray(stream); + byte[] bytes = IOUtil.toByteArray(stream); String encoding = determineEncoding(bytes); String ruleset = new String(bytes, encoding); diff --git a/pmd-core/src/main/java/net/sourceforge/pmd/RuleSetWriter.java b/pmd-core/src/main/java/net/sourceforge/pmd/RuleSetWriter.java index 97aa27ca45..07691f4e12 100644 --- a/pmd-core/src/main/java/net/sourceforge/pmd/RuleSetWriter.java +++ b/pmd-core/src/main/java/net/sourceforge/pmd/RuleSetWriter.java @@ -22,7 +22,6 @@ import javax.xml.transform.TransformerFactory; import javax.xml.transform.dom.DOMSource; import javax.xml.transform.stream.StreamResult; -import org.apache.commons.io.IOUtils; import org.w3c.dom.CDATASection; import org.w3c.dom.DOMException; import org.w3c.dom.Document; @@ -37,6 +36,7 @@ import net.sourceforge.pmd.lang.rule.XPathRule; import net.sourceforge.pmd.properties.PropertyDescriptor; import net.sourceforge.pmd.properties.PropertyDescriptorField; import net.sourceforge.pmd.properties.PropertyTypeId; +import net.sourceforge.pmd.util.IOUtil; /** * This class represents a way to serialize a RuleSet to an XML configuration @@ -62,7 +62,7 @@ public class RuleSetWriter { } public void close() { - IOUtils.closeQuietly(outputStream); + IOUtil.closeQuietly(outputStream); } public void write(RuleSet ruleSet) { diff --git a/pmd-core/src/main/java/net/sourceforge/pmd/ant/Formatter.java b/pmd-core/src/main/java/net/sourceforge/pmd/ant/Formatter.java index da031a0152..e248dc6f18 100644 --- a/pmd-core/src/main/java/net/sourceforge/pmd/ant/Formatter.java +++ b/pmd-core/src/main/java/net/sourceforge/pmd/ant/Formatter.java @@ -18,7 +18,6 @@ import java.util.ArrayList; import java.util.List; import java.util.Properties; -import org.apache.commons.io.IOUtils; import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.reflect.FieldUtils; import org.apache.commons.lang3.reflect.MethodUtils; @@ -30,6 +29,7 @@ import net.sourceforge.pmd.Report; import net.sourceforge.pmd.annotation.InternalApi; import net.sourceforge.pmd.renderers.Renderer; import net.sourceforge.pmd.renderers.RendererFactory; +import net.sourceforge.pmd.util.IOUtil; public class Formatter { @@ -187,8 +187,8 @@ public class Formatter { isOnError = false; } finally { if (isOnError) { - IOUtils.closeQuietly(output); - IOUtils.closeQuietly(writer); + IOUtil.closeQuietly(output); + IOUtil.closeQuietly(writer); } } return writer; diff --git a/pmd-core/src/main/java/net/sourceforge/pmd/cache/AbstractAnalysisCache.java b/pmd-core/src/main/java/net/sourceforge/pmd/cache/AbstractAnalysisCache.java index 57568be50c..ce3b5056cf 100644 --- a/pmd-core/src/main/java/net/sourceforge/pmd/cache/AbstractAnalysisCache.java +++ b/pmd-core/src/main/java/net/sourceforge/pmd/cache/AbstractAnalysisCache.java @@ -23,8 +23,6 @@ import java.util.concurrent.ConcurrentMap; import java.util.logging.Level; import java.util.logging.Logger; -import org.apache.commons.io.FilenameUtils; - import net.sourceforge.pmd.PMDVersion; import net.sourceforge.pmd.Rule; import net.sourceforge.pmd.RuleSets; @@ -35,6 +33,7 @@ import net.sourceforge.pmd.benchmark.TimedOperation; import net.sourceforge.pmd.benchmark.TimedOperationCategory; import net.sourceforge.pmd.cache.internal.ClasspathFingerprinter; import net.sourceforge.pmd.stat.Metric; +import net.sourceforge.pmd.util.IOUtil; /** * Abstract implementation of the analysis cache. Handles all operations, except for persistence. @@ -189,7 +188,7 @@ public abstract class AbstractAnalysisCache implements AnalysisCache { @Override public FileVisitResult visitFile(final Path file, final BasicFileAttributes attrs) throws IOException { - String extension = FilenameUtils.getExtension(file.toString()); + String extension = IOUtil.getFilenameExtension(file.toString()); if ("jar".equalsIgnoreCase(extension)) { fileVisitor.visitFile(file, attrs); } diff --git a/pmd-core/src/main/java/net/sourceforge/pmd/cache/AnalysisResult.java b/pmd-core/src/main/java/net/sourceforge/pmd/cache/AnalysisResult.java index 0e5f5d9736..4fa7f0e0f6 100644 --- a/pmd-core/src/main/java/net/sourceforge/pmd/cache/AnalysisResult.java +++ b/pmd-core/src/main/java/net/sourceforge/pmd/cache/AnalysisResult.java @@ -13,10 +13,9 @@ import java.util.List; import java.util.zip.Adler32; import java.util.zip.CheckedInputStream; -import org.apache.commons.io.IOUtils; - import net.sourceforge.pmd.RuleViolation; import net.sourceforge.pmd.annotation.InternalApi; +import net.sourceforge.pmd.util.IOUtil; /** * The result of a single file analysis. @@ -45,8 +44,7 @@ public class AnalysisResult { new BufferedInputStream(Files.newInputStream(sourceFile.toPath())), new Adler32()); ) { // Just read it, the CheckedInputStream will update the checksum on it's own - IOUtils.skipFully(stream, sourceFile.length()); - + IOUtil.skipFully(stream, sourceFile.length()); return stream.getChecksum().getValue(); } catch (final IOException ignored) { // We don't really care, if it's unreadable diff --git a/pmd-core/src/main/java/net/sourceforge/pmd/cache/internal/RawFileFingerprinter.java b/pmd-core/src/main/java/net/sourceforge/pmd/cache/internal/RawFileFingerprinter.java index 6f8854f09c..a183e69f09 100644 --- a/pmd-core/src/main/java/net/sourceforge/pmd/cache/internal/RawFileFingerprinter.java +++ b/pmd-core/src/main/java/net/sourceforge/pmd/cache/internal/RawFileFingerprinter.java @@ -14,7 +14,7 @@ import java.util.logging.Logger; import java.util.zip.CheckedInputStream; import java.util.zip.Checksum; -import org.apache.commons.io.IOUtils; +import net.sourceforge.pmd.util.IOUtil; /** * Base fingerprinter for raw files. @@ -40,7 +40,7 @@ public class RawFileFingerprinter implements ClasspathEntryFingerprinter { public void fingerprint(URL entry, Checksum checksum) throws IOException { try (CheckedInputStream inputStream = new CheckedInputStream(entry.openStream(), checksum)) { // Just read it, the CheckedInputStream will update the checksum on it's own - while (IOUtils.skip(inputStream, Long.MAX_VALUE) == Long.MAX_VALUE) { + while (IOUtil.skipFully(inputStream, Long.MAX_VALUE) == Long.MAX_VALUE) { // just loop } } catch (final FileNotFoundException ignored) { diff --git a/pmd-core/src/main/java/net/sourceforge/pmd/cpd/CPD.java b/pmd-core/src/main/java/net/sourceforge/pmd/cpd/CPD.java index a18b4d2791..130791c123 100644 --- a/pmd-core/src/main/java/net/sourceforge/pmd/cpd/CPD.java +++ b/pmd-core/src/main/java/net/sourceforge/pmd/cpd/CPD.java @@ -17,11 +17,10 @@ import java.util.TreeMap; import java.util.logging.Level; import java.util.logging.Logger; -import org.apache.commons.io.FilenameUtils; - import net.sourceforge.pmd.annotation.Experimental; import net.sourceforge.pmd.lang.ast.TokenMgrError; import net.sourceforge.pmd.util.FileFinder; +import net.sourceforge.pmd.util.IOUtil; import net.sourceforge.pmd.util.database.DBMSMetadata; import net.sourceforge.pmd.util.database.DBURI; import net.sourceforge.pmd.util.database.SourceObject; @@ -93,8 +92,7 @@ public class CPD { current.add(signature); } - if (!FilenameUtils.equalsNormalizedOnSystem(file.getAbsoluteFile().getCanonicalPath(), - file.getAbsolutePath())) { + if (!IOUtil.equalsNormalizedPaths(file.getAbsoluteFile().getCanonicalPath(), file.getAbsolutePath())) { System.err.println("Skipping " + file + " since it appears to be a symlink"); return; } diff --git a/pmd-core/src/main/java/net/sourceforge/pmd/cpd/SourceCode.java b/pmd-core/src/main/java/net/sourceforge/pmd/cpd/SourceCode.java index 99cf8f8829..b7ac55af7b 100644 --- a/pmd-core/src/main/java/net/sourceforge/pmd/cpd/SourceCode.java +++ b/pmd-core/src/main/java/net/sourceforge/pmd/cpd/SourceCode.java @@ -14,8 +14,7 @@ import java.nio.file.Files; import java.util.ArrayList; import java.util.List; -import org.apache.commons.io.ByteOrderMark; -import org.apache.commons.io.input.BOMInputStream; +import net.sourceforge.pmd.util.IOUtil; public class SourceCode { @@ -112,11 +111,10 @@ public class SourceCode { @Override public Reader getReader() throws Exception { - BOMInputStream inputStream = new BOMInputStream(Files.newInputStream(file.toPath()), ByteOrderMark.UTF_8, - ByteOrderMark.UTF_16BE, ByteOrderMark.UTF_16LE); + IOUtil.BomAwareInputStream inputStream = new IOUtil.BomAwareInputStream(Files.newInputStream(file.toPath())); - if (inputStream.hasBOM()) { - encoding = inputStream.getBOMCharsetName(); + if (inputStream.hasBom()) { + encoding = inputStream.getBomCharsetName(); } return new InputStreamReader(inputStream, encoding); } diff --git a/pmd-core/src/main/java/net/sourceforge/pmd/document/DocumentFile.java b/pmd-core/src/main/java/net/sourceforge/pmd/document/DocumentFile.java index 7c3e1640c0..0c1bae358a 100644 --- a/pmd-core/src/main/java/net/sourceforge/pmd/document/DocumentFile.java +++ b/pmd-core/src/main/java/net/sourceforge/pmd/document/DocumentFile.java @@ -21,7 +21,7 @@ import java.util.Scanner; import java.util.logging.Level; import java.util.logging.Logger; -import org.apache.commons.io.IOUtils; +import net.sourceforge.pmd.util.IOUtil; /** * Implementation that handles a Document as a file in the filesystem and receives operations in a sorted manner @@ -159,7 +159,7 @@ public class DocumentFile implements Document, Closeable { } private void writeUntilEOF() throws IOException { - IOUtils.copy(reader, writer); + IOUtil.copy(reader, writer); } /* package-private */ List getLineToOffset() { diff --git a/pmd-core/src/main/java/net/sourceforge/pmd/internal/util/FileCollectionUtil.java b/pmd-core/src/main/java/net/sourceforge/pmd/internal/util/FileCollectionUtil.java index 68e1ab16e1..e8041d3430 100644 --- a/pmd-core/src/main/java/net/sourceforge/pmd/internal/util/FileCollectionUtil.java +++ b/pmd-core/src/main/java/net/sourceforge/pmd/internal/util/FileCollectionUtil.java @@ -15,13 +15,12 @@ import java.util.ArrayList; import java.util.List; import java.util.Set; -import org.apache.commons.io.IOUtils; - import net.sourceforge.pmd.PMDConfiguration; import net.sourceforge.pmd.lang.Language; import net.sourceforge.pmd.lang.document.FileCollector; import net.sourceforge.pmd.lang.document.TextFile; import net.sourceforge.pmd.util.FileUtil; +import net.sourceforge.pmd.util.IOUtil; import net.sourceforge.pmd.util.database.DBMSMetadata; import net.sourceforge.pmd.util.database.DBURI; import net.sourceforge.pmd.util.database.SourceObject; @@ -157,7 +156,7 @@ public final class FileCollectionUtil { collector.getReporter().trace("Adding database source object {0}", falseFilePath); try (Reader sourceCode = dbmsMetadata.getSourceCode(sourceObject)) { - String source = IOUtils.toString(sourceCode); + String source = IOUtil.readToString(sourceCode); collector.addSourceFile(source, falseFilePath); } catch (SQLException ex) { collector.getReporter().warnEx("Cannot get SourceCode for {0} - skipping ...", diff --git a/pmd-core/src/main/java/net/sourceforge/pmd/lang/document/NioTextFile.java b/pmd-core/src/main/java/net/sourceforge/pmd/lang/document/NioTextFile.java index 705ef530a7..c7d77e1de8 100644 --- a/pmd-core/src/main/java/net/sourceforge/pmd/lang/document/NioTextFile.java +++ b/pmd-core/src/main/java/net/sourceforge/pmd/lang/document/NioTextFile.java @@ -12,11 +12,10 @@ import java.nio.file.Files; import java.nio.file.Path; import java.util.Objects; -import org.apache.commons.io.IOUtils; - import net.sourceforge.pmd.annotation.Experimental; import net.sourceforge.pmd.internal.util.AssertionUtil; import net.sourceforge.pmd.lang.LanguageVersion; +import net.sourceforge.pmd.util.IOUtil; import net.sourceforge.pmd.util.datasource.DataSource; import net.sourceforge.pmd.util.datasource.FileDataSource; @@ -68,7 +67,7 @@ class NioTextFile implements TextFile { } try (BufferedReader br = Files.newBufferedReader(path, charset)) { - return IOUtils.toString(br); + return IOUtil.readToString(br); } } diff --git a/pmd-core/src/main/java/net/sourceforge/pmd/processor/AbstractPMDProcessor.java b/pmd-core/src/main/java/net/sourceforge/pmd/processor/AbstractPMDProcessor.java index 8da879721f..93a1487e0f 100644 --- a/pmd-core/src/main/java/net/sourceforge/pmd/processor/AbstractPMDProcessor.java +++ b/pmd-core/src/main/java/net/sourceforge/pmd/processor/AbstractPMDProcessor.java @@ -11,7 +11,6 @@ import java.util.Set; import java.util.logging.Level; import java.util.logging.Logger; -import org.apache.commons.io.IOUtils; import org.apache.commons.lang3.exception.ContextedRuntimeException; import net.sourceforge.pmd.PMDConfiguration; @@ -27,6 +26,7 @@ import net.sourceforge.pmd.benchmark.TimeTracker; import net.sourceforge.pmd.benchmark.TimedOperation; import net.sourceforge.pmd.benchmark.TimedOperationCategory; import net.sourceforge.pmd.renderers.Renderer; +import net.sourceforge.pmd.util.IOUtil; import net.sourceforge.pmd.util.datasource.DataSource; /** @@ -151,7 +151,7 @@ public abstract class AbstractPMDProcessor { // in case we analyzed files within Zip Files/Jars, we need to close them after // the analysis is finished for (DataSource dataSource : files) { - IOUtils.closeQuietly(dataSource); + IOUtil.closeQuietly(dataSource); } } } diff --git a/pmd-core/src/main/java/net/sourceforge/pmd/renderers/AbstractRenderer.java b/pmd-core/src/main/java/net/sourceforge/pmd/renderers/AbstractRenderer.java index 88b69d2202..5ee89c4cc2 100644 --- a/pmd-core/src/main/java/net/sourceforge/pmd/renderers/AbstractRenderer.java +++ b/pmd-core/src/main/java/net/sourceforge/pmd/renderers/AbstractRenderer.java @@ -9,8 +9,6 @@ import java.io.Writer; import java.util.Collections; import java.util.List; -import org.apache.commons.io.IOUtils; - import net.sourceforge.pmd.PMDConfiguration; import net.sourceforge.pmd.annotation.Experimental; import net.sourceforge.pmd.cli.PMDParameters; @@ -108,7 +106,7 @@ public abstract class AbstractRenderer extends AbstractPropertySource implements } catch (IOException e) { throw new IllegalStateException(e); } finally { - IOUtils.closeQuietly(writer); + IOUtil.closeQuietly(writer); } } diff --git a/pmd-core/src/main/java/net/sourceforge/pmd/renderers/XMLRenderer.java b/pmd-core/src/main/java/net/sourceforge/pmd/renderers/XMLRenderer.java index f9dfd96a72..e7adaa6426 100644 --- a/pmd-core/src/main/java/net/sourceforge/pmd/renderers/XMLRenderer.java +++ b/pmd-core/src/main/java/net/sourceforge/pmd/renderers/XMLRenderer.java @@ -21,13 +21,13 @@ import javax.xml.stream.XMLOutputFactory; import javax.xml.stream.XMLStreamException; import javax.xml.stream.XMLStreamWriter; -import org.apache.commons.io.output.WriterOutputStream; import org.apache.commons.lang3.StringUtils; import net.sourceforge.pmd.PMDVersion; import net.sourceforge.pmd.Report; import net.sourceforge.pmd.RuleViolation; import net.sourceforge.pmd.properties.StringProperty; +import net.sourceforge.pmd.util.IOUtil; import net.sourceforge.pmd.util.StringUtil; /** @@ -256,7 +256,7 @@ public class XMLRenderer extends AbstractIncrementingRenderer { public void setWriter(final Writer writer) { String encoding = getProperty(ENCODING); // for backwards compatibility, create a OutputStream that writes to the writer. - this.stream = new WriterOutputStream(writer, encoding); + this.stream = IOUtil.fromWriter(writer, encoding); XMLOutputFactory outputFactory = XMLOutputFactory.newFactory(); try { diff --git a/pmd-core/src/main/java/net/sourceforge/pmd/util/FileFinder.java b/pmd-core/src/main/java/net/sourceforge/pmd/util/FileFinder.java index 874a004bcf..c632997409 100644 --- a/pmd-core/src/main/java/net/sourceforge/pmd/util/FileFinder.java +++ b/pmd-core/src/main/java/net/sourceforge/pmd/util/FileFinder.java @@ -8,10 +8,9 @@ import java.io.File; import java.io.FilenameFilter; import java.util.ArrayList; import java.util.Arrays; +import java.util.Comparator; import java.util.List; -import org.apache.commons.io.comparator.PathFileComparator; - import net.sourceforge.pmd.annotation.InternalApi; /** @@ -49,7 +48,12 @@ public class FileFinder { return; } - Arrays.sort(candidates, PathFileComparator.PATH_INSENSITIVE_COMPARATOR); + Arrays.sort(candidates, new Comparator() { + @Override + public int compare(File o1, File o2) { + return o1.getPath().compareToIgnoreCase(o2.getPath()); + } + }); for (File tmp : candidates) { if (tmp.isDirectory()) { diff --git a/pmd-core/src/main/java/net/sourceforge/pmd/util/FileUtil.java b/pmd-core/src/main/java/net/sourceforge/pmd/util/FileUtil.java index 7b2bd58d57..efb047050f 100644 --- a/pmd-core/src/main/java/net/sourceforge/pmd/util/FileUtil.java +++ b/pmd-core/src/main/java/net/sourceforge/pmd/util/FileUtil.java @@ -20,7 +20,6 @@ import java.util.regex.Pattern; import java.util.zip.ZipEntry; import java.util.zip.ZipFile; -import org.apache.commons.io.FileUtils; import org.apache.commons.lang3.StringUtils; import net.sourceforge.pmd.annotation.InternalApi; @@ -181,7 +180,7 @@ public final class FileUtil { * @throws IOException if the file couldn't be read */ public static String readFilelist(File filelist) throws IOException { - String filePaths = FileUtils.readFileToString(filelist); + String filePaths = IOUtil.readFileToString(filelist); filePaths = StringUtils.trimToEmpty(filePaths); filePaths = filePaths.replaceAll("\\r?\\n", ","); filePaths = filePaths.replaceAll(",+", ","); diff --git a/pmd-core/src/main/java/net/sourceforge/pmd/util/datasource/ReaderDataSource.java b/pmd-core/src/main/java/net/sourceforge/pmd/util/datasource/ReaderDataSource.java index ec21c09f4b..fe530ae40c 100644 --- a/pmd-core/src/main/java/net/sourceforge/pmd/util/datasource/ReaderDataSource.java +++ b/pmd-core/src/main/java/net/sourceforge/pmd/util/datasource/ReaderDataSource.java @@ -8,8 +8,7 @@ import java.io.IOException; import java.io.InputStream; import java.io.Reader; -import org.apache.commons.io.input.ReaderInputStream; - +import net.sourceforge.pmd.util.IOUtil; import net.sourceforge.pmd.util.datasource.internal.AbstractDataSource; /** @@ -50,7 +49,7 @@ public class ReaderDataSource extends AbstractDataSource { */ @Override public InputStream getInputStream() throws IOException { - return new ReaderInputStream(reader); + return IOUtil.fromReader(reader); } /** diff --git a/pmd-core/src/test/java/net/sourceforge/pmd/RuleSetFactoryCompatibilityTest.java b/pmd-core/src/test/java/net/sourceforge/pmd/RuleSetFactoryCompatibilityTest.java index 7dfb6e1f09..b573c371f1 100644 --- a/pmd-core/src/test/java/net/sourceforge/pmd/RuleSetFactoryCompatibilityTest.java +++ b/pmd-core/src/test/java/net/sourceforge/pmd/RuleSetFactoryCompatibilityTest.java @@ -9,10 +9,10 @@ import java.io.InputStream; import java.io.Reader; import java.nio.charset.StandardCharsets; -import org.apache.commons.io.IOUtils; import org.junit.Assert; import org.junit.Test; +import net.sourceforge.pmd.util.IOUtil; import net.sourceforge.pmd.util.ResourceLoader; public class RuleSetFactoryCompatibilityTest { @@ -48,7 +48,7 @@ public class RuleSetFactoryCompatibilityTest { InputStream stream = new ByteArrayInputStream(ruleset.getBytes(StandardCharsets.ISO_8859_1)); Reader filtered = rsfc.filterRuleSetFile(stream); - String out = IOUtils.toString(filtered); + String out = IOUtil.readToString(filtered); Assert.assertFalse(out.contains("notexisting.xml")); Assert.assertFalse(out.contains("OldDummyBasicMockRule")); @@ -90,7 +90,7 @@ public class RuleSetFactoryCompatibilityTest { InputStream stream = new ByteArrayInputStream(ruleset.getBytes(StandardCharsets.ISO_8859_1)); Reader filtered = rsfc.filterRuleSetFile(stream); - String out = IOUtils.toString(filtered); + String out = IOUtil.readToString(filtered); Assert.assertTrue(out.contains("OldDummyBasicMockRule")); } @@ -112,7 +112,7 @@ public class RuleSetFactoryCompatibilityTest { + " \n" + "\n"; InputStream stream = new ByteArrayInputStream(in.getBytes(StandardCharsets.ISO_8859_1)); Reader filtered = rsfc.filterRuleSetFile(stream); - String out = IOUtils.toString(filtered); + String out = IOUtil.readToString(filtered); Assert.assertFalse(out.contains("notexisting.xml")); Assert.assertTrue(out.contains("")); @@ -136,7 +136,7 @@ public class RuleSetFactoryCompatibilityTest { + " \n" + " \n" + "\n"; InputStream stream = new ByteArrayInputStream(in.getBytes(StandardCharsets.ISO_8859_1)); Reader filtered = rsfc.filterRuleSetFile(stream); - String out = IOUtils.toString(filtered); + String out = IOUtil.readToString(filtered); Assert.assertFalse(out.contains("OldNameOfBasicMockRule")); Assert.assertTrue(out.contains("")); diff --git a/pmd-core/src/test/java/net/sourceforge/pmd/RuleSetReferenceIdTest.java b/pmd-core/src/test/java/net/sourceforge/pmd/RuleSetReferenceIdTest.java index 0914045572..fa48c86698 100644 --- a/pmd-core/src/test/java/net/sourceforge/pmd/RuleSetReferenceIdTest.java +++ b/pmd-core/src/test/java/net/sourceforge/pmd/RuleSetReferenceIdTest.java @@ -22,9 +22,9 @@ import java.io.InputStream; import java.nio.charset.StandardCharsets; import java.util.List; -import org.apache.commons.io.IOUtils; import org.junit.Test; +import net.sourceforge.pmd.util.IOUtil; import net.sourceforge.pmd.util.ResourceLoader; import com.github.tomakehurst.wiremock.junit.WireMockRule; @@ -123,7 +123,7 @@ public class RuleSetReferenceIdTest { assertRuleSetReferenceId(true, rulesetUrl, true, null, rulesetUrl, ruleSetReferenceId); try (InputStream inputStream = ruleSetReferenceId.getInputStream(new ResourceLoader())) { - String loaded = IOUtils.toString(inputStream, StandardCharsets.UTF_8); + String loaded = IOUtil.readToString(inputStream, StandardCharsets.UTF_8); assertEquals("xyz", loaded); } @@ -139,8 +139,8 @@ public class RuleSetReferenceIdTest { String path = "/profiles/export?format=pmd&language=java&name=Sonar%2520way"; String completePath = path + "/DummyBasicMockRule"; String hostpart = "http://localhost:" + wireMockRule.port(); - String basicRuleSet = IOUtils - .toString(RuleSetReferenceId.class.getResourceAsStream("/rulesets/dummy/basic.xml"), StandardCharsets.UTF_8); + String basicRuleSet = IOUtil + .readToString(RuleSetReferenceId.class.getResourceAsStream("/rulesets/dummy/basic.xml"), StandardCharsets.UTF_8); stubFor(head(urlEqualTo(completePath)).willReturn(aResponse().withStatus(404))); stubFor(head(urlEqualTo(path)).willReturn(aResponse().withStatus(200).withHeader("Content-type", "text/xml"))); @@ -152,7 +152,7 @@ public class RuleSetReferenceIdTest { ruleSetReferenceId); try (InputStream inputStream = ruleSetReferenceId.getInputStream(new ResourceLoader())) { - String loaded = IOUtils.toString(inputStream, StandardCharsets.UTF_8); + String loaded = IOUtil.readToString(inputStream, StandardCharsets.UTF_8); assertEquals(basicRuleSet, loaded); } diff --git a/pmd-core/src/test/java/net/sourceforge/pmd/RuleSetTest.java b/pmd-core/src/test/java/net/sourceforge/pmd/RuleSetTest.java index 7c0f5c8813..14f4db1072 100644 --- a/pmd-core/src/test/java/net/sourceforge/pmd/RuleSetTest.java +++ b/pmd-core/src/test/java/net/sourceforge/pmd/RuleSetTest.java @@ -22,7 +22,6 @@ import java.util.Random; import java.util.Set; import java.util.regex.Pattern; -import org.apache.commons.io.FilenameUtils; import org.junit.Test; import net.sourceforge.pmd.Report.ProcessingError; @@ -35,6 +34,7 @@ import net.sourceforge.pmd.lang.ast.Node; import net.sourceforge.pmd.lang.rule.MockRule; import net.sourceforge.pmd.lang.rule.RuleReference; import net.sourceforge.pmd.util.CollectionUtil; +import net.sourceforge.pmd.util.IOUtil; public class RuleSetTest { @@ -582,7 +582,7 @@ public class RuleSetTest { assertTrue("Should be a RuntimeException", processingError.getError() instanceof RuntimeException); assertEquals("Wrong filename in processing error", "net.sourceforge.pmd.RuleSetTest/ruleExceptionShouldBeReported.java", - FilenameUtils.normalize(processingError.getFile(), true)); + IOUtil.normalizePath(processingError.getFile())); assertEquals("There should be a violation", 1, context.getReport().size()); } diff --git a/pmd-core/src/test/java/net/sourceforge/pmd/ant/PMDTaskTest.java b/pmd-core/src/test/java/net/sourceforge/pmd/ant/PMDTaskTest.java index 48acda9ba2..fba597a5f1 100644 --- a/pmd-core/src/test/java/net/sourceforge/pmd/ant/PMDTaskTest.java +++ b/pmd-core/src/test/java/net/sourceforge/pmd/ant/PMDTaskTest.java @@ -11,7 +11,6 @@ import java.io.IOException; import java.io.InputStream; import java.nio.charset.StandardCharsets; -import org.apache.commons.io.IOUtils; import org.apache.tools.ant.BuildException; import org.apache.tools.ant.BuildFileRule; import org.junit.Assert; @@ -19,6 +18,8 @@ import org.junit.Before; import org.junit.Rule; import org.junit.Test; +import net.sourceforge.pmd.util.IOUtil; + public class PMDTaskTest { @Rule @@ -74,7 +75,7 @@ public class PMDTaskTest { buildRule.executeTarget("testWithShortFilenames"); try (InputStream in = new FileInputStream("target/pmd-ant-test.txt")) { - String actual = IOUtils.toString(in, StandardCharsets.UTF_8); + String actual = IOUtil.readToString(in, StandardCharsets.UTF_8); // remove any trailing newline actual = actual.replaceAll("\n|\r", ""); Assert.assertEquals("sample.dummy:0:\tSampleXPathRule:\tTest Rule 2", actual); @@ -87,11 +88,11 @@ public class PMDTaskTest { try (InputStream in = new FileInputStream("target/pmd-ant-xml.xml"); InputStream expectedStream = PMDTaskTest.class.getResourceAsStream("xml/expected-pmd-ant-xml.xml")) { - String actual = IOUtils.toString(in, StandardCharsets.UTF_8); + String actual = IOUtil.readToString(in, StandardCharsets.UTF_8); actual = actual.replaceFirst("timestamp=\"[^\"]+\"", "timestamp=\"\""); actual = actual.replaceFirst("\\.xsd\" version=\"[^\"]+\"", ".xsd\" version=\"\""); - String expected = IOUtils.toString(expectedStream, StandardCharsets.UTF_8); + String expected = IOUtil.readToString(expectedStream, StandardCharsets.UTF_8); expected = expected.replaceFirst("timestamp=\"[^\"]+\"", "timestamp=\"\""); expected = expected.replaceFirst("\\.xsd\" version=\"[^\"]+\"", ".xsd\" version=\"\""); diff --git a/pmd-core/src/test/java/net/sourceforge/pmd/cli/CoreCliTest.java b/pmd-core/src/test/java/net/sourceforge/pmd/cli/CoreCliTest.java index 157caf975d..e8d19a0c36 100644 --- a/pmd-core/src/test/java/net/sourceforge/pmd/cli/CoreCliTest.java +++ b/pmd-core/src/test/java/net/sourceforge/pmd/cli/CoreCliTest.java @@ -20,7 +20,6 @@ import java.nio.file.Files; import java.nio.file.Path; import java.util.logging.Logger; -import org.apache.commons.io.IOUtils; import org.hamcrest.Matcher; import org.junit.Before; import org.junit.Rule; @@ -33,6 +32,7 @@ import org.junit.rules.TemporaryFolder; import net.sourceforge.pmd.PMD; import net.sourceforge.pmd.PMD.StatusCode; import net.sourceforge.pmd.junit.JavaUtilLoggingRule; +import net.sourceforge.pmd.util.IOUtil; /** * @@ -131,7 +131,7 @@ public class CoreCliTest { runPmdSuccessfully("--no-cache", "--dir", srcDir, "--rulesets", DUMMY_RULESET, "--report-file", reportFile, "--debug"); assertTrue("Report file should have been created", Files.exists(reportFile)); - String reportText = IOUtils.toString(Files.newBufferedReader(reportFile, StandardCharsets.UTF_8)); + String reportText = IOUtil.readToString(Files.newBufferedReader(reportFile, StandardCharsets.UTF_8)); assertThat(reportText, not(containsStringIgnoringCase("error"))); } diff --git a/pmd-core/src/test/java/net/sourceforge/pmd/cpd/CPDFilelistTest.java b/pmd-core/src/test/java/net/sourceforge/pmd/cpd/CPDFilelistTest.java index 5c21740f85..74604cc10a 100644 --- a/pmd-core/src/test/java/net/sourceforge/pmd/cpd/CPDFilelistTest.java +++ b/pmd-core/src/test/java/net/sourceforge/pmd/cpd/CPDFilelistTest.java @@ -7,11 +7,11 @@ package net.sourceforge.pmd.cpd; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertTrue; +import java.nio.file.Paths; import java.util.HashSet; import java.util.List; import java.util.Set; -import org.apache.commons.io.FilenameUtils; import org.junit.Test; public class CPDFilelistTest { @@ -28,7 +28,7 @@ public class CPDFilelistTest { assertEquals(2, paths.size()); Set simpleNames = new HashSet<>(); for (String path : paths) { - simpleNames.add(FilenameUtils.getName(path)); + simpleNames.add(Paths.get(path).getFileName().toString()); } assertTrue(simpleNames.contains("anotherfile.dummy")); assertTrue(simpleNames.contains("somefile.dummy")); @@ -46,7 +46,7 @@ public class CPDFilelistTest { assertEquals(2, paths.size()); Set simpleNames = new HashSet<>(); for (String path : paths) { - simpleNames.add(FilenameUtils.getName(path)); + simpleNames.add(Paths.get(path).getFileName().toString()); } assertTrue(simpleNames.contains("anotherfile.dummy")); assertTrue(simpleNames.contains("somefile.dummy")); diff --git a/pmd-core/src/test/java/net/sourceforge/pmd/cpd/CpdXsltTest.java b/pmd-core/src/test/java/net/sourceforge/pmd/cpd/CpdXsltTest.java index 085475f8d0..af8d5ada20 100644 --- a/pmd-core/src/test/java/net/sourceforge/pmd/cpd/CpdXsltTest.java +++ b/pmd-core/src/test/java/net/sourceforge/pmd/cpd/CpdXsltTest.java @@ -17,10 +17,11 @@ import javax.xml.transform.TransformerFactory; import javax.xml.transform.stream.StreamResult; import javax.xml.transform.stream.StreamSource; -import org.apache.commons.io.IOUtils; import org.junit.Assert; import org.junit.Test; +import net.sourceforge.pmd.util.IOUtil; + public class CpdXsltTest { /* Sample ant build.xml file. Run with "ant cpdxsl". @@ -49,7 +50,7 @@ public class CpdXsltTest { transformer.setErrorListener(errorListener); transformer.transform(cpdReport, result); - String expected = IOUtils.toString(CpdXsltTest.class.getResourceAsStream("ExpectedCpdHtmlReport.html"), StandardCharsets.UTF_8); + String expected = IOUtil.readToString(CpdXsltTest.class.getResourceAsStream("ExpectedCpdHtmlReport.html"), StandardCharsets.UTF_8); Assert.assertEquals(expected, result.getWriter().toString()); Assert.assertTrue("XSLT errors occured: " + errorListener, errorListener.hasNoErrors()); } diff --git a/pmd-core/src/test/java/net/sourceforge/pmd/document/DocumentFileTest.java b/pmd-core/src/test/java/net/sourceforge/pmd/document/DocumentFileTest.java index ece529938d..d578dec542 100644 --- a/pmd-core/src/test/java/net/sourceforge/pmd/document/DocumentFileTest.java +++ b/pmd-core/src/test/java/net/sourceforge/pmd/document/DocumentFileTest.java @@ -16,12 +16,13 @@ import java.util.ArrayList; import java.util.Arrays; import java.util.List; -import org.apache.commons.io.IOUtils; import org.junit.Before; import org.junit.Rule; import org.junit.Test; import org.junit.rules.TemporaryFolder; +import net.sourceforge.pmd.util.IOUtil; + public class DocumentFileTest { private static final String FILE_PATH = "psvm.java"; @@ -51,8 +52,8 @@ public class DocumentFileTest { @Test public void shouldPreserveNewlines() throws IOException { - final String testFileContent = IOUtils.toString( - DocumentFileTest.class.getResource("ShouldPreserveNewlines.java"), StandardCharsets.UTF_8); + final String testFileContent = IOUtil.readToString( + DocumentFileTest.class.getResourceAsStream("ShouldPreserveNewlines.java"), StandardCharsets.UTF_8); writeContentToTemporaryFile(testFileContent); try (DocumentFile documentFile = new DocumentFile(temporaryFile, StandardCharsets.UTF_8)) { diff --git a/pmd-core/src/test/java/net/sourceforge/pmd/junit/JavaUtilLoggingRule.java b/pmd-core/src/test/java/net/sourceforge/pmd/junit/JavaUtilLoggingRule.java index 572ed0388f..da674a405a 100644 --- a/pmd-core/src/test/java/net/sourceforge/pmd/junit/JavaUtilLoggingRule.java +++ b/pmd-core/src/test/java/net/sourceforge/pmd/junit/JavaUtilLoggingRule.java @@ -4,11 +4,12 @@ package net.sourceforge.pmd.junit; +import java.io.ByteArrayOutputStream; +import java.io.UnsupportedEncodingException; import java.nio.charset.StandardCharsets; import java.util.logging.Logger; import java.util.logging.StreamHandler; -import org.apache.commons.io.output.ByteArrayOutputStream; import org.junit.rules.ExternalResource; /** @@ -63,7 +64,11 @@ public class JavaUtilLoggingRule extends ExternalResource { */ public String getLog() { customLogHandler.flush(); - return stream.toString(StandardCharsets.UTF_8); + try { + return stream.toString(StandardCharsets.UTF_8.name()); + } catch (UnsupportedEncodingException e) { + throw new RuntimeException(e); + } } /** diff --git a/pmd-core/src/test/java/net/sourceforge/pmd/lang/DummyLanguageModule.java b/pmd-core/src/test/java/net/sourceforge/pmd/lang/DummyLanguageModule.java index a439fa10db..901ef70534 100644 --- a/pmd-core/src/test/java/net/sourceforge/pmd/lang/DummyLanguageModule.java +++ b/pmd-core/src/test/java/net/sourceforge/pmd/lang/DummyLanguageModule.java @@ -12,7 +12,6 @@ import java.util.Collections; import java.util.List; import java.util.Map; -import org.apache.commons.io.IOUtils; import org.jaxen.Navigator; import net.sourceforge.pmd.Rule; @@ -29,6 +28,7 @@ import net.sourceforge.pmd.lang.rule.AbstractRuleChainVisitor; import net.sourceforge.pmd.lang.rule.AbstractRuleViolationFactory; import net.sourceforge.pmd.lang.rule.ParametricRuleViolation; import net.sourceforge.pmd.lang.rule.RuleChainVisitor; +import net.sourceforge.pmd.util.IOUtil; import net.sf.saxon.expr.XPathContext; import net.sf.saxon.sxpath.IndependentContext; @@ -130,7 +130,7 @@ public class DummyLanguageModule extends BaseLanguageModule { @Override public Node parse(String fileName, Reader source) throws ParseException { try { - String text = IOUtils.toString(source); + String text = IOUtil.readToString(source); DummyRootNode rootNode = readLispNode(text); AbstractParser.setFileName(fileName, rootNode); return rootNode; diff --git a/pmd-core/src/test/java/net/sourceforge/pmd/renderers/AbstractRendererTest.java b/pmd-core/src/test/java/net/sourceforge/pmd/renderers/AbstractRendererTest.java index faa66b88e4..52a5a2e293 100644 --- a/pmd-core/src/test/java/net/sourceforge/pmd/renderers/AbstractRendererTest.java +++ b/pmd-core/src/test/java/net/sourceforge/pmd/renderers/AbstractRendererTest.java @@ -10,7 +10,6 @@ import java.io.File; import java.io.IOException; import java.nio.charset.Charset; -import org.apache.commons.io.FileUtils; import org.junit.Test; import org.junit.rules.TemporaryFolder; @@ -26,6 +25,7 @@ import net.sourceforge.pmd.RuleWithProperties; import net.sourceforge.pmd.lang.ast.DummyNode; import net.sourceforge.pmd.lang.ast.Node; import net.sourceforge.pmd.lang.rule.ParametricRuleViolation; +import net.sourceforge.pmd.util.IOUtil; public abstract class AbstractRendererTest { @@ -204,6 +204,6 @@ public abstract class AbstractRendererTest { renderer.renderFileReport(report); renderer.end(); renderer.flush(); - return FileUtils.readFileToString(file, expectedEncoding); + return IOUtil.readFileToString(file, expectedEncoding); } } diff --git a/pmd-core/src/test/java/net/sourceforge/pmd/renderers/JsonRendererTest.java b/pmd-core/src/test/java/net/sourceforge/pmd/renderers/JsonRendererTest.java index 38f3a1ad9a..2ef04e695a 100644 --- a/pmd-core/src/test/java/net/sourceforge/pmd/renderers/JsonRendererTest.java +++ b/pmd-core/src/test/java/net/sourceforge/pmd/renderers/JsonRendererTest.java @@ -11,7 +11,6 @@ import java.nio.charset.StandardCharsets; import java.util.HashMap; import java.util.Map; -import org.apache.commons.io.IOUtils; import org.junit.Assert; import org.junit.Test; @@ -19,6 +18,7 @@ import net.sourceforge.pmd.FooRule; import net.sourceforge.pmd.Report; import net.sourceforge.pmd.Report.ConfigurationError; import net.sourceforge.pmd.Report.ProcessingError; +import net.sourceforge.pmd.util.IOUtil; public class JsonRendererTest extends AbstractRendererTest { @@ -69,7 +69,7 @@ public class JsonRendererTest extends AbstractRendererTest { private String readFile(String name) { try (InputStream in = JsonRendererTest.class.getResourceAsStream("json/" + name)) { - return IOUtils.toString(in, StandardCharsets.UTF_8); + return IOUtil.readToString(in, StandardCharsets.UTF_8); } catch (IOException e) { throw new RuntimeException(e); } diff --git a/pmd-core/src/test/java/net/sourceforge/pmd/renderers/SarifRendererTest.java b/pmd-core/src/test/java/net/sourceforge/pmd/renderers/SarifRendererTest.java index ae6f605dd4..b13f03ca09 100644 --- a/pmd-core/src/test/java/net/sourceforge/pmd/renderers/SarifRendererTest.java +++ b/pmd-core/src/test/java/net/sourceforge/pmd/renderers/SarifRendererTest.java @@ -10,7 +10,6 @@ import java.io.IOException; import java.io.InputStream; import java.nio.charset.StandardCharsets; -import org.apache.commons.io.IOUtils; import org.json.JSONArray; import org.json.JSONObject; import org.junit.Test; @@ -18,7 +17,7 @@ import org.junit.contrib.java.lang.system.RestoreSystemProperties; import net.sourceforge.pmd.Report; import net.sourceforge.pmd.Rule; - +import net.sourceforge.pmd.util.IOUtil; public class SarifRendererTest extends AbstractRendererTest { @@ -112,7 +111,7 @@ public class SarifRendererTest extends AbstractRendererTest { private String readFile(String name) { try (InputStream in = SarifRendererTest.class.getResourceAsStream("sarif/" + name)) { - String asd = IOUtils.toString(in, StandardCharsets.UTF_8); + String asd = IOUtil.readToString(in, StandardCharsets.UTF_8); return asd; } catch (IOException e) { throw new RuntimeException(e); diff --git a/pmd-core/src/test/java/net/sourceforge/pmd/renderers/XMLRendererTest.java b/pmd-core/src/test/java/net/sourceforge/pmd/renderers/XMLRendererTest.java index e5ef41c5ed..9ead15cf85 100644 --- a/pmd-core/src/test/java/net/sourceforge/pmd/renderers/XMLRendererTest.java +++ b/pmd-core/src/test/java/net/sourceforge/pmd/renderers/XMLRendererTest.java @@ -12,7 +12,6 @@ import java.nio.charset.Charset; import java.nio.charset.StandardCharsets; import javax.xml.parsers.DocumentBuilderFactory; -import org.apache.commons.io.IOUtils; import org.junit.Assert; import org.junit.Rule; import org.junit.Test; @@ -33,6 +32,7 @@ import net.sourceforge.pmd.RuleViolation; import net.sourceforge.pmd.lang.ast.DummyNode; import net.sourceforge.pmd.lang.ast.Node; import net.sourceforge.pmd.lang.rule.ParametricRuleViolation; +import net.sourceforge.pmd.util.IOUtil; public class XMLRendererTest extends AbstractRendererTest { @Rule // Restores system properties after test @@ -177,7 +177,7 @@ public class XMLRendererTest extends AbstractRendererTest { renderer.flush(); try (FileInputStream input = new FileInputStream(reportFile)) { - return IOUtils.toString(input, expectedCharset); + return IOUtil.readToString(input, expectedCharset); } } } diff --git a/pmd-core/src/test/java/net/sourceforge/pmd/renderers/YAHTMLRendererTest.java b/pmd-core/src/test/java/net/sourceforge/pmd/renderers/YAHTMLRendererTest.java index f52cc72a23..0b9ff1dd1f 100644 --- a/pmd-core/src/test/java/net/sourceforge/pmd/renderers/YAHTMLRendererTest.java +++ b/pmd-core/src/test/java/net/sourceforge/pmd/renderers/YAHTMLRendererTest.java @@ -14,7 +14,6 @@ import java.nio.charset.StandardCharsets; import java.util.Arrays; import java.util.regex.Pattern; -import org.apache.commons.io.IOUtils; import org.junit.Before; import org.junit.Test; import org.junit.rules.TemporaryFolder; @@ -30,6 +29,7 @@ import net.sourceforge.pmd.RuleViolation; import net.sourceforge.pmd.lang.ast.DummyNode; import net.sourceforge.pmd.lang.ast.Node; import net.sourceforge.pmd.lang.rule.ParametricRuleViolation; +import net.sourceforge.pmd.util.IOUtil; public class YAHTMLRendererTest extends AbstractRendererTest { @@ -79,8 +79,8 @@ public class YAHTMLRendererTest extends AbstractRendererTest { for (String file : htmlFiles) { try (FileInputStream in = new FileInputStream(new File(outputDir, file)); InputStream expectedIn = YAHTMLRendererTest.class.getResourceAsStream("yahtml/" + file)) { - String data = IOUtils.toString(in, StandardCharsets.UTF_8); - String expected = normalizeLineSeparators(IOUtils.toString(expectedIn, StandardCharsets.UTF_8)); + String data = IOUtil.readToString(in, StandardCharsets.UTF_8); + String expected = normalizeLineSeparators(IOUtil.readToString(expectedIn, StandardCharsets.UTF_8)); assertEquals("File " + file + " is different", expected, data); } @@ -88,8 +88,8 @@ public class YAHTMLRendererTest extends AbstractRendererTest { } private static String normalizeLineSeparators(String s) { - return s.replaceAll(Pattern.quote(IOUtils.LINE_SEPARATOR_WINDOWS), IOUtils.LINE_SEPARATOR_UNIX) - .replaceAll(Pattern.quote(IOUtils.LINE_SEPARATOR_UNIX), PMD.EOL); + return s.replaceAll(Pattern.quote("\r\n"), "\n") + .replaceAll(Pattern.quote("\n"), PMD.EOL); } @Override diff --git a/pmd-core/src/test/java/net/sourceforge/pmd/util/treeexport/TreeExportCliTest.java b/pmd-core/src/test/java/net/sourceforge/pmd/util/treeexport/TreeExportCliTest.java index edcf3e660b..ccd5403350 100644 --- a/pmd-core/src/test/java/net/sourceforge/pmd/util/treeexport/TreeExportCliTest.java +++ b/pmd-core/src/test/java/net/sourceforge/pmd/util/treeexport/TreeExportCliTest.java @@ -7,6 +7,7 @@ package net.sourceforge.pmd.util.treeexport; import static org.hamcrest.Matchers.containsString; import java.io.BufferedWriter; +import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; import java.io.File; import java.io.IOException; @@ -15,7 +16,6 @@ import java.io.PrintStream; import java.nio.charset.StandardCharsets; import java.nio.file.Files; -import org.apache.commons.io.IOUtils; import org.hamcrest.Matcher; import org.hamcrest.MatcherAssert; import org.junit.Assert; @@ -67,7 +67,7 @@ public class TreeExportCliTest { } private static InputStream stdinContaining(String input) { - return IOUtils.toInputStream(input, StandardCharsets.UTF_8); + return new ByteArrayInputStream(input.getBytes(StandardCharsets.UTF_8)); } static class IoSpy { diff --git a/pmd-lang-test/src/main/kotlin/net/sourceforge/pmd/lang/ast/test/BaseParsingHelper.kt b/pmd-lang-test/src/main/kotlin/net/sourceforge/pmd/lang/ast/test/BaseParsingHelper.kt index 560512b189..2538932a14 100644 --- a/pmd-lang-test/src/main/kotlin/net/sourceforge/pmd/lang/ast/test/BaseParsingHelper.kt +++ b/pmd-lang-test/src/main/kotlin/net/sourceforge/pmd/lang/ast/test/BaseParsingHelper.kt @@ -7,7 +7,7 @@ import net.sourceforge.pmd.* import net.sourceforge.pmd.lang.* import net.sourceforge.pmd.lang.ast.Node import net.sourceforge.pmd.lang.ast.RootNode -import org.apache.commons.io.IOUtils +import net.sourceforge.pmd.util.IOUtil import java.io.File import java.io.InputStream import java.io.StringReader @@ -160,7 +160,7 @@ abstract class BaseParsingHelper, T : RootNode } private fun consume(input: InputStream) = - IOUtils.toString(input, StandardCharsets.UTF_8) + IOUtil.readToString(input, StandardCharsets.UTF_8) .replace("\r\n", "\n") // normalize line-endings /** diff --git a/pmd-test/src/main/java/net/sourceforge/pmd/AbstractRuleSetFactoryTest.java b/pmd-test/src/main/java/net/sourceforge/pmd/AbstractRuleSetFactoryTest.java index a1aa1327d5..3fca13161b 100644 --- a/pmd-test/src/main/java/net/sourceforge/pmd/AbstractRuleSetFactoryTest.java +++ b/pmd-test/src/main/java/net/sourceforge/pmd/AbstractRuleSetFactoryTest.java @@ -31,7 +31,6 @@ import javax.xml.parsers.ParserConfigurationException; import javax.xml.parsers.SAXParser; import javax.xml.parsers.SAXParserFactory; -import org.apache.commons.io.FilenameUtils; import org.junit.BeforeClass; import org.junit.Test; import org.junit.contrib.java.lang.system.SystemErrRule; @@ -45,6 +44,7 @@ import net.sourceforge.pmd.lang.LanguageRegistry; import net.sourceforge.pmd.lang.rule.RuleReference; import net.sourceforge.pmd.lang.rule.XPathRule; import net.sourceforge.pmd.properties.PropertyDescriptor; +import net.sourceforge.pmd.util.IOUtil; import net.sourceforge.pmd.util.ResourceLoader; /** @@ -155,7 +155,7 @@ public abstract class AbstractRuleSetFactoryTest { } else { String expectedExternalInfoURL = "https?://pmd.(sourceforge.net|github.io)/.+/pmd_rules_" + language.getTerseName() + "_" - + FilenameUtils.getBaseName(fileName) + + IOUtil.getFilenameBase(fileName) + ".html#" + rule.getName().toLowerCase(Locale.ROOT); if (rule.getExternalInfoUrl() == null From abfc463ef9003f2f3d85377b8b21882954550567 Mon Sep 17 00:00:00 2001 From: Andreas Dangel Date: Fri, 13 May 2022 09:46:46 +0200 Subject: [PATCH 080/198] Update build-tools to 18-SNAPSHOT --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 995f203476..459fe190c1 100644 --- a/pom.xml +++ b/pom.xml @@ -105,7 +105,7 @@ -Xmx512m -Dfile.encoding=${project.build.sourceEncoding} - 17 + 18-SNAPSHOT 6.37.0 From a4ebb66769e780cc9b2bbe85fa9eb24b6418821f Mon Sep 17 00:00:00 2001 From: Andreas Dangel Date: Fri, 13 May 2022 10:46:11 +0200 Subject: [PATCH 081/198] Replace IOUtils with IOUtil plsql, xml, apex, html, javascript, scala --- .../java/net/sourceforge/pmd/lang/apex/ast/ApexParser.java | 5 ++--- .../java/net/sourceforge/pmd/lang/html/ast/HtmlParser.java | 4 ++-- .../pmd/lang/ecmascript/ast/EcmascriptParser.java | 4 ++-- .../java/net/sourceforge/pmd/lang/plsql/PLSQLParser.java | 4 +--- .../java/net/sourceforge/pmd/lang/scala/ScalaParser.java | 5 ++--- .../java/net/sourceforge/pmd/lang/xml/ast/XmlParser.java | 4 ++-- 6 files changed, 11 insertions(+), 15 deletions(-) diff --git a/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/ast/ApexParser.java b/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/ast/ApexParser.java index a6ff552503..fea54903e7 100644 --- a/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/ast/ApexParser.java +++ b/pmd-apex/src/main/java/net/sourceforge/pmd/lang/apex/ast/ApexParser.java @@ -8,12 +8,11 @@ import java.io.IOException; import java.io.Reader; import java.util.Map; -import org.apache.commons.io.IOUtils; - import net.sourceforge.pmd.annotation.InternalApi; import net.sourceforge.pmd.lang.apex.ApexJorjeLogging; import net.sourceforge.pmd.lang.apex.ApexParserOptions; import net.sourceforge.pmd.lang.ast.ParseException; +import net.sourceforge.pmd.util.IOUtil; import apex.jorje.data.Locations; import apex.jorje.semantic.ast.compilation.Compilation; @@ -50,7 +49,7 @@ public class ApexParser { public ApexNode parse(final Reader reader) { try { - final String sourceCode = IOUtils.toString(reader); + final String sourceCode = IOUtil.readToString(reader); final Compilation astRoot = parseApex(sourceCode); final ApexTreeBuilder treeBuilder = new ApexTreeBuilder(sourceCode, parserOptions); suppressMap = treeBuilder.getSuppressMap(); diff --git a/pmd-html/src/main/java/net/sourceforge/pmd/lang/html/ast/HtmlParser.java b/pmd-html/src/main/java/net/sourceforge/pmd/lang/html/ast/HtmlParser.java index c61cb4f5a4..1c0b57f65c 100644 --- a/pmd-html/src/main/java/net/sourceforge/pmd/lang/html/ast/HtmlParser.java +++ b/pmd-html/src/main/java/net/sourceforge/pmd/lang/html/ast/HtmlParser.java @@ -10,7 +10,6 @@ import java.io.Reader; import java.util.HashMap; import java.util.Map; -import org.apache.commons.io.IOUtils; import org.jsoup.nodes.Document; import org.jsoup.parser.Parser; @@ -18,6 +17,7 @@ import net.sourceforge.pmd.lang.ParserOptions; import net.sourceforge.pmd.lang.TokenManager; import net.sourceforge.pmd.lang.ast.Node; import net.sourceforge.pmd.lang.ast.ParseException; +import net.sourceforge.pmd.util.IOUtil; public final class HtmlParser implements net.sourceforge.pmd.lang.Parser { @@ -29,7 +29,7 @@ public final class HtmlParser implements net.sourceforge.pmd.lang.Parser { @Override public Node parse(String fileName, Reader source) throws ParseException { try { - String data = IOUtils.toString(source); + String data = IOUtil.readToString(source); Document doc = Parser.xmlParser().parseInput(data, ""); HtmlTreeBuilder builder = new HtmlTreeBuilder(); return builder.build(doc, data); diff --git a/pmd-javascript/src/main/java/net/sourceforge/pmd/lang/ecmascript/ast/EcmascriptParser.java b/pmd-javascript/src/main/java/net/sourceforge/pmd/lang/ecmascript/ast/EcmascriptParser.java index 359d96b0b4..156728171c 100644 --- a/pmd-javascript/src/main/java/net/sourceforge/pmd/lang/ecmascript/ast/EcmascriptParser.java +++ b/pmd-javascript/src/main/java/net/sourceforge/pmd/lang/ecmascript/ast/EcmascriptParser.java @@ -11,7 +11,6 @@ import java.util.HashMap; import java.util.List; import java.util.Map; -import org.apache.commons.io.IOUtils; import org.mozilla.javascript.CompilerEnvirons; import org.mozilla.javascript.Parser; import org.mozilla.javascript.ast.AstRoot; @@ -22,6 +21,7 @@ import org.mozilla.javascript.ast.ParseProblem; import net.sourceforge.pmd.annotation.InternalApi; import net.sourceforge.pmd.lang.ast.ParseException; import net.sourceforge.pmd.lang.ecmascript.EcmascriptParserOptions; +import net.sourceforge.pmd.util.IOUtil; public class EcmascriptParser { @Deprecated @@ -64,7 +64,7 @@ public class EcmascriptParser { public EcmascriptNode parse(final Reader reader) { try { final List parseProblems = new ArrayList<>(); - final String sourceCode = IOUtils.toString(reader); + final String sourceCode = IOUtil.readToString(reader); final AstRoot astRoot = parseEcmascript(sourceCode, parseProblems); final EcmascriptTreeBuilder treeBuilder = new EcmascriptTreeBuilder(sourceCode, parseProblems); EcmascriptNode tree = treeBuilder.build(astRoot); diff --git a/pmd-plsql/src/main/java/net/sourceforge/pmd/lang/plsql/PLSQLParser.java b/pmd-plsql/src/main/java/net/sourceforge/pmd/lang/plsql/PLSQLParser.java index 4466d61480..442a6c8be0 100644 --- a/pmd-plsql/src/main/java/net/sourceforge/pmd/lang/plsql/PLSQLParser.java +++ b/pmd-plsql/src/main/java/net/sourceforge/pmd/lang/plsql/PLSQLParser.java @@ -10,8 +10,6 @@ import java.io.StringReader; import java.util.HashMap; import java.util.Map; -import org.apache.commons.io.IOUtils; - import net.sourceforge.pmd.annotation.InternalApi; import net.sourceforge.pmd.lang.AbstractParser; import net.sourceforge.pmd.lang.LanguageVersionHandler; @@ -56,7 +54,7 @@ public class PLSQLParser extends AbstractParser { @Override public Node parse(String fileName, Reader source) throws ParseException { try { - String sourcecode = IOUtils.toString(source); + String sourcecode = IOUtil.readToString(source); AbstractTokenManager.setFileName(fileName); return createPLSQLParser(new StringReader(sourcecode)).Input(sourcecode); } catch (IOException e) { diff --git a/pmd-scala-modules/pmd-scala-common/src/main/java/net/sourceforge/pmd/lang/scala/ScalaParser.java b/pmd-scala-modules/pmd-scala-common/src/main/java/net/sourceforge/pmd/lang/scala/ScalaParser.java index 8edb8d5ab9..ded0c0c04a 100644 --- a/pmd-scala-modules/pmd-scala-common/src/main/java/net/sourceforge/pmd/lang/scala/ScalaParser.java +++ b/pmd-scala-modules/pmd-scala-common/src/main/java/net/sourceforge/pmd/lang/scala/ScalaParser.java @@ -9,13 +9,12 @@ import java.io.Reader; import java.util.HashMap; import java.util.Map; -import org.apache.commons.io.IOUtils; - import net.sourceforge.pmd.lang.AbstractParser; import net.sourceforge.pmd.lang.ParserOptions; import net.sourceforge.pmd.lang.TokenManager; import net.sourceforge.pmd.lang.ast.ParseException; import net.sourceforge.pmd.lang.scala.ast.ASTSource; +import net.sourceforge.pmd.util.IOUtil; import scala.meta.Dialect; import scala.meta.Source; @@ -52,7 +51,7 @@ public class ScalaParser extends AbstractParser { public ASTSource parse(String fileName, Reader source) throws ParseException { Input.VirtualFile virtualFile; try { - String sourceString = IOUtils.toString(source); + String sourceString = IOUtil.readToString(source); virtualFile = new Input.VirtualFile(fileName, sourceString); } catch (IOException e) { throw new ParseException(e); diff --git a/pmd-xml/src/main/java/net/sourceforge/pmd/lang/xml/ast/XmlParser.java b/pmd-xml/src/main/java/net/sourceforge/pmd/lang/xml/ast/XmlParser.java index 2bf8d097f9..9ac2376389 100644 --- a/pmd-xml/src/main/java/net/sourceforge/pmd/lang/xml/ast/XmlParser.java +++ b/pmd-xml/src/main/java/net/sourceforge/pmd/lang/xml/ast/XmlParser.java @@ -13,7 +13,6 @@ import javax.xml.parsers.DocumentBuilder; import javax.xml.parsers.DocumentBuilderFactory; import javax.xml.parsers.ParserConfigurationException; -import org.apache.commons.io.IOUtils; import org.w3c.dom.Document; import org.w3c.dom.Node; import org.xml.sax.InputSource; @@ -22,6 +21,7 @@ import org.xml.sax.SAXException; import net.sourceforge.pmd.lang.ast.ParseException; import net.sourceforge.pmd.lang.ast.RootNode; import net.sourceforge.pmd.lang.xml.XmlParserOptions; +import net.sourceforge.pmd.util.IOUtil; public class XmlParser { @@ -37,7 +37,7 @@ public class XmlParser { protected Document parseDocument(Reader reader) throws ParseException { nodeCache.clear(); try { - String xmlData = IOUtils.toString(reader); + String xmlData = IOUtil.readToString(reader); DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); dbf.setNamespaceAware(parserOptions.isNamespaceAware()); From a1922c59565283c701dbb8aa8746badc11ca095f Mon Sep 17 00:00:00 2001 From: Andreas Dangel Date: Fri, 13 May 2022 11:18:55 +0200 Subject: [PATCH 082/198] [dist] Replace IOUtils with IOUtil --- .../java/net/sourceforge/pmd/it/AntIT.java | 36 +++++++++++++++---- .../net/sourceforge/pmd/it/PMDExecutor.java | 12 ++++--- .../sourceforge/pmd/it/ZipFileExtractor.java | 5 +-- 3 files changed, 40 insertions(+), 13 deletions(-) diff --git a/pmd-dist/src/test/java/net/sourceforge/pmd/it/AntIT.java b/pmd-dist/src/test/java/net/sourceforge/pmd/it/AntIT.java index 6d11b7d9d7..2c840d2487 100644 --- a/pmd-dist/src/test/java/net/sourceforge/pmd/it/AntIT.java +++ b/pmd-dist/src/test/java/net/sourceforge/pmd/it/AntIT.java @@ -8,15 +8,19 @@ import java.io.File; import java.io.IOException; import java.io.InputStream; import java.nio.charset.StandardCharsets; +import java.nio.file.FileVisitResult; +import java.nio.file.Files; +import java.nio.file.Path; +import java.nio.file.SimpleFileVisitor; +import java.nio.file.attribute.BasicFileAttributes; import java.util.concurrent.TimeUnit; -import org.apache.commons.io.FileUtils; -import org.apache.commons.io.IOUtils; import org.apache.commons.lang3.SystemUtils; import org.junit.Assume; import org.junit.Test; import net.sourceforge.pmd.PMDVersion; +import net.sourceforge.pmd.util.IOUtil; /** * This test calls ant in a fake terminal to make sure we have a {@link java.io.Console} connected. @@ -41,10 +45,28 @@ public class AntIT extends AbstractBinaryDistributionTest { private File prepareAntTestProjectFolder() throws IOException { - File sourceProjectFolder = new File("src/test/resources/ant-it"); - File projectFolder = folder.newFolder(); - FileUtils.copyDirectory(sourceProjectFolder, projectFolder); - return projectFolder; + final Path sourceProjectFolder = new File("src/test/resources/ant-it").toPath(); + final Path projectFolder = folder.newFolder().toPath(); + Files.walkFileTree(sourceProjectFolder, new SimpleFileVisitor() { + @Override + public FileVisitResult preVisitDirectory(Path dir, BasicFileAttributes attrs) throws IOException { + assert !dir.isAbsolute(); + Path target = projectFolder.resolve(sourceProjectFolder.relativize(dir)); + if (!target.toFile().exists()) { + target.toFile().mkdir(); + } + return FileVisitResult.CONTINUE; + } + + @Override + public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IOException { + assert !file.isAbsolute(); + Path target = projectFolder.resolve(sourceProjectFolder.relativize(file)); + Files.copy(file, target); + return FileVisitResult.CONTINUE; + } + }); + return projectFolder.toFile(); } @@ -64,7 +86,7 @@ public class AntIT extends AbstractBinaryDistributionTest { @Override public void run() { try (InputStream in = process.getInputStream()) { - String output = IOUtils.toString(process.getInputStream(), StandardCharsets.UTF_8); + String output = IOUtil.readToString(process.getInputStream(), StandardCharsets.UTF_8); result.withOutput(output); } catch (IOException e) { result.withOutput("Exception occurred: " + e.toString()); diff --git a/pmd-dist/src/test/java/net/sourceforge/pmd/it/PMDExecutor.java b/pmd-dist/src/test/java/net/sourceforge/pmd/it/PMDExecutor.java index fdfaf79acb..69bd4bb3ce 100644 --- a/pmd-dist/src/test/java/net/sourceforge/pmd/it/PMDExecutor.java +++ b/pmd-dist/src/test/java/net/sourceforge/pmd/it/PMDExecutor.java @@ -5,18 +5,20 @@ package net.sourceforge.pmd.it; import java.io.IOException; +import java.io.Reader; import java.nio.charset.StandardCharsets; +import java.nio.file.Files; import java.nio.file.Path; import java.util.ArrayList; import java.util.Arrays; import java.util.List; import java.util.concurrent.TimeUnit; -import org.apache.commons.io.IOUtils; import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.SystemUtils; import net.sourceforge.pmd.PMDVersion; +import net.sourceforge.pmd.util.IOUtil; /** * Executes PMD from command line. Deals with the differences, when PMD is run on Windows or on Linux. @@ -59,7 +61,7 @@ public class PMDExecutor { public void run() { String output; try { - output = IOUtils.toString(process.getInputStream(), StandardCharsets.UTF_8); + output = IOUtil.readToString(process.getInputStream(), StandardCharsets.UTF_8); result.withOutput(output); } catch (IOException e) { result.withOutput("Exception occurred: " + e.toString()); @@ -72,7 +74,7 @@ public class PMDExecutor { public void run() { String error; try { - error = IOUtils.toString(process.getErrorStream(), StandardCharsets.UTF_8); + error = IOUtil.readToString(process.getErrorStream(), StandardCharsets.UTF_8); result.withErrorOutput(error); } catch (IOException e) { result.withErrorOutput("Exception occurred: " + e.toString()); @@ -87,7 +89,9 @@ public class PMDExecutor { String report = null; if (reportFile != null) { - report = IOUtils.toString(reportFile.toUri(), StandardCharsets.UTF_8); + try (Reader reader = Files.newBufferedReader(reportFile, StandardCharsets.UTF_8)) { + report = IOUtil.readToString(reader); + } } return result.withExitCode(exitCode).withReport(report).build(); } diff --git a/pmd-dist/src/test/java/net/sourceforge/pmd/it/ZipFileExtractor.java b/pmd-dist/src/test/java/net/sourceforge/pmd/it/ZipFileExtractor.java index 27a8b325d6..dbfe2d13a5 100644 --- a/pmd-dist/src/test/java/net/sourceforge/pmd/it/ZipFileExtractor.java +++ b/pmd-dist/src/test/java/net/sourceforge/pmd/it/ZipFileExtractor.java @@ -17,7 +17,8 @@ import java.util.List; import org.apache.commons.compress.archivers.zip.ZipArchiveEntry; import org.apache.commons.compress.archivers.zip.ZipFile; -import org.apache.commons.io.IOUtils; + +import net.sourceforge.pmd.util.IOUtil; /** * Extracts a zip file with preserving the unix file permissions. @@ -49,7 +50,7 @@ public class ZipFileExtractor { } else { try (InputStream data = zip.getInputStream(entry); OutputStream fileOut = new FileOutputStream(file);) { - IOUtils.copy(data, fileOut); + IOUtil.copy(data, fileOut); } if ((entry.getUnixMode() & OWNER_EXECUTABLE) == OWNER_EXECUTABLE) { file.setExecutable(true); From bef7eed0ec1778427e54c03f0d2ec27ba90b3ad4 Mon Sep 17 00:00:00 2001 From: Andreas Dangel Date: Fri, 13 May 2022 11:39:22 +0200 Subject: [PATCH 083/198] [doc] Replace IOUtils with IOUtil --- .../pmd/docs/DeadLinksChecker.java | 5 ++- .../pmd/docs/GenerateRuleDocsCmd.java | 6 ++-- .../pmd/docs/RuleDocGenerator.java | 31 ++++++++++--------- .../sourceforge/pmd/docs/RuleSetUtils.java | 10 +++--- .../pmd/docs/MockedFileWriter.java | 5 ++- .../pmd/docs/RuleDocGeneratorTest.java | 12 +++---- .../pmd/docs/RuleSetResolverTest.java | 4 +-- .../pmd/docs/SidebarGeneratorTest.java | 4 +-- 8 files changed, 40 insertions(+), 37 deletions(-) diff --git a/pmd-doc/src/main/java/net/sourceforge/pmd/docs/DeadLinksChecker.java b/pmd-doc/src/main/java/net/sourceforge/pmd/docs/DeadLinksChecker.java index 750e7c934c..9f651c3610 100644 --- a/pmd-doc/src/main/java/net/sourceforge/pmd/docs/DeadLinksChecker.java +++ b/pmd-doc/src/main/java/net/sourceforge/pmd/docs/DeadLinksChecker.java @@ -37,8 +37,7 @@ import java.util.regex.Pattern; import java.util.stream.Collectors; import java.util.stream.Stream; -import org.apache.commons.io.IOUtils; - +import net.sourceforge.pmd.util.IOUtil; /** * Checks links to local pages for non-existing link-targets. @@ -298,7 +297,7 @@ public class DeadLinksChecker { private String fileToString(Path mdFile) { try (InputStream inputStream = Files.newInputStream(mdFile)) { - return IOUtils.toString(inputStream, StandardCharsets.UTF_8); + return IOUtil.readToString(inputStream, StandardCharsets.UTF_8); } catch (IOException ex) { throw new RuntimeException("error reading " + mdFile, ex); } diff --git a/pmd-doc/src/main/java/net/sourceforge/pmd/docs/GenerateRuleDocsCmd.java b/pmd-doc/src/main/java/net/sourceforge/pmd/docs/GenerateRuleDocsCmd.java index caf1cb67a5..d5b3002a6b 100644 --- a/pmd-doc/src/main/java/net/sourceforge/pmd/docs/GenerateRuleDocsCmd.java +++ b/pmd-doc/src/main/java/net/sourceforge/pmd/docs/GenerateRuleDocsCmd.java @@ -10,16 +10,16 @@ import java.nio.file.FileSystems; import java.nio.file.FileVisitResult; import java.nio.file.Files; import java.nio.file.Path; +import java.nio.file.Paths; import java.nio.file.SimpleFileVisitor; import java.nio.file.attribute.BasicFileAttributes; import java.util.ArrayList; import java.util.List; import java.util.regex.Pattern; -import org.apache.commons.io.FilenameUtils; - import net.sourceforge.pmd.RuleSet; import net.sourceforge.pmd.RuleSetLoader; +import net.sourceforge.pmd.util.IOUtil; public final class GenerateRuleDocsCmd { private GenerateRuleDocsCmd() { @@ -51,7 +51,7 @@ public final class GenerateRuleDocsCmd { try { List additionalRulesets = new ArrayList<>(); Pattern rulesetPattern = Pattern.compile("^.+" + Pattern.quote(File.separator) + "pmd-\\w+" - + Pattern.quote(FilenameUtils.normalize("/src/main/resources/rulesets/")) + + Pattern.quote(IOUtil.normalizePath(File.separator + Paths.get("src", "main", "resources", "rulesets").toString() + File.separator)) + "\\w+" + Pattern.quote(File.separator) + "\\w+.xml$"); Files.walkFileTree(basePath, new SimpleFileVisitor() { @Override diff --git a/pmd-doc/src/main/java/net/sourceforge/pmd/docs/RuleDocGenerator.java b/pmd-doc/src/main/java/net/sourceforge/pmd/docs/RuleDocGenerator.java index 891580ad84..a1e23965cd 100644 --- a/pmd-doc/src/main/java/net/sourceforge/pmd/docs/RuleDocGenerator.java +++ b/pmd-doc/src/main/java/net/sourceforge/pmd/docs/RuleDocGenerator.java @@ -30,8 +30,8 @@ import java.util.regex.Matcher; import java.util.regex.Pattern; import java.util.stream.Collectors; -import org.apache.commons.io.FilenameUtils; import org.apache.commons.lang3.StringUtils; +import org.apache.commons.lang3.SystemUtils; import org.apache.commons.text.StringEscapeUtils; import net.sourceforge.pmd.Rule; @@ -43,6 +43,7 @@ import net.sourceforge.pmd.lang.rule.RuleReference; import net.sourceforge.pmd.lang.rule.XPathRule; import net.sourceforge.pmd.properties.MultiValuePropertyDescriptor; import net.sourceforge.pmd.properties.PropertyDescriptor; +import net.sourceforge.pmd.util.IOUtil; public class RuleDocGenerator { private static final Logger LOG = Logger.getLogger(RuleDocGenerator.class.getName()); @@ -131,7 +132,7 @@ public class RuleDocGenerator { } private Path getAbsoluteOutputPath(String filename) { - return root.resolve(FilenameUtils.normalize(filename)); + return root.resolve(IOUtil.normalizePath(filename)); } private Map> sortRulesets(List rulesets) { @@ -608,17 +609,13 @@ public class RuleDocGenerator { // is replaced by a correct path. for (List rulesets : sortedRulesets.values()) { for (RuleSet ruleset : rulesets) { - // Note: the path is normalized to unix path separators, so that the editme link - // uses forward slashes - String rulesetFilename = FilenameUtils.normalize(StringUtils.chomp(ruleset.getFileName()), true); + String rulesetFilename = normalizeForwardSlashes(StringUtils.chomp(ruleset.getFileName())); allRulesets.put(ruleset.getFileName(), rulesetFilename); for (Rule rule : ruleset.getRules()) { String ruleClass = rule.getRuleClass(); String relativeSourceFilename = ruleClass.replaceAll("\\.", Matcher.quoteReplacement(File.separator)) + ".java"; - // Note: the path is normalized to unix path separators, so that the editme link - // uses forward slashes - allRules.put(ruleClass, FilenameUtils.normalize(relativeSourceFilename, true)); + allRules.put(ruleClass, normalizeForwardSlashes(relativeSourceFilename)); } } } @@ -640,9 +637,7 @@ public class RuleDocGenerator { } if (foundRuleClass != null) { Path foundPath = root.relativize(file); - // Note: the path is normalized to unix path separators, so that the editme link - // uses forward slashes - allRules.put(foundRuleClass, FilenameUtils.normalize(foundPath.toString(), true)); + allRules.put(foundRuleClass, normalizeForwardSlashes(foundPath.toString())); } String foundRuleset = null; @@ -654,9 +649,7 @@ public class RuleDocGenerator { } if (foundRuleset != null) { Path foundPath = root.relativize(file); - // Note: the path is normalized to unix path separators, so that the editme link - // uses forward slashes - allRulesets.put(foundRuleset, FilenameUtils.normalize(foundPath.toString(), true)); + allRulesets.put(foundRuleset, normalizeForwardSlashes(foundPath.toString())); } } return FileVisitResult.CONTINUE; @@ -666,4 +659,14 @@ public class RuleDocGenerator { throw new RuntimeException(e); } } + + private static String normalizeForwardSlashes(String path) { + String normalized = IOUtil.normalizePath(path); + if (SystemUtils.IS_OS_WINDOWS) { + // Note: windows path separators are changed to forward slashes, + // so that the editme link works + normalized = normalized.replaceAll(Pattern.quote(File.separator), "/"); + } + return normalized; + } } diff --git a/pmd-doc/src/main/java/net/sourceforge/pmd/docs/RuleSetUtils.java b/pmd-doc/src/main/java/net/sourceforge/pmd/docs/RuleSetUtils.java index f928fe1de6..a7afef7b5b 100644 --- a/pmd-doc/src/main/java/net/sourceforge/pmd/docs/RuleSetUtils.java +++ b/pmd-doc/src/main/java/net/sourceforge/pmd/docs/RuleSetUtils.java @@ -4,12 +4,14 @@ package net.sourceforge.pmd.docs; -import org.apache.commons.io.FilenameUtils; +import java.io.File; + import org.apache.commons.lang3.StringUtils; import net.sourceforge.pmd.Rule; import net.sourceforge.pmd.RuleSet; import net.sourceforge.pmd.lang.rule.RuleReference; +import net.sourceforge.pmd.util.IOUtil; public final class RuleSetUtils { @@ -28,7 +30,7 @@ public final class RuleSetUtils { } public static String getRuleSetFilename(String rulesetFileName) { - return FilenameUtils.getBaseName(StringUtils.chomp(rulesetFileName)); + return IOUtil.getFilenameBase(StringUtils.chomp(rulesetFileName)); } /** @@ -50,8 +52,8 @@ public final class RuleSetUtils { } public static String getRuleSetClasspath(RuleSet ruleset) { - final String RESOURCES_PATH = "/resources/"; - String filename = FilenameUtils.normalize(StringUtils.chomp(ruleset.getFileName()), true); + final String RESOURCES_PATH = File.separator + "resources" + File.separator; + String filename = IOUtil.normalizePath(StringUtils.chomp(ruleset.getFileName())); int startIndex = filename.lastIndexOf(RESOURCES_PATH); if (startIndex > -1) { return filename.substring(startIndex + RESOURCES_PATH.length()); diff --git a/pmd-doc/src/test/java/net/sourceforge/pmd/docs/MockedFileWriter.java b/pmd-doc/src/test/java/net/sourceforge/pmd/docs/MockedFileWriter.java index dc5ee7e626..3f90cbe4cb 100644 --- a/pmd-doc/src/test/java/net/sourceforge/pmd/docs/MockedFileWriter.java +++ b/pmd-doc/src/test/java/net/sourceforge/pmd/docs/MockedFileWriter.java @@ -10,7 +10,6 @@ import java.util.ArrayList; import java.util.List; import java.util.regex.Pattern; -import org.apache.commons.io.IOUtils; import org.apache.commons.lang3.StringUtils; import net.sourceforge.pmd.PMD; @@ -49,7 +48,7 @@ public class MockedFileWriter implements FileWriter { } public static String normalizeLineSeparators(String s) { - return s.replaceAll(Pattern.quote(IOUtils.LINE_SEPARATOR_WINDOWS), IOUtils.LINE_SEPARATOR_UNIX) - .replaceAll(Pattern.quote(IOUtils.LINE_SEPARATOR_UNIX), PMD.EOL); + return s.replaceAll(Pattern.quote("\r\n"), "\n") + .replaceAll(Pattern.quote("\n"), PMD.EOL); } } diff --git a/pmd-doc/src/test/java/net/sourceforge/pmd/docs/RuleDocGeneratorTest.java b/pmd-doc/src/test/java/net/sourceforge/pmd/docs/RuleDocGeneratorTest.java index dc96ec33a5..f994834900 100644 --- a/pmd-doc/src/test/java/net/sourceforge/pmd/docs/RuleDocGeneratorTest.java +++ b/pmd-doc/src/test/java/net/sourceforge/pmd/docs/RuleDocGeneratorTest.java @@ -11,11 +11,10 @@ import java.io.IOException; import java.nio.charset.StandardCharsets; import java.nio.file.Files; import java.nio.file.Path; +import java.nio.file.Paths; import java.util.Arrays; import java.util.List; -import org.apache.commons.io.FilenameUtils; -import org.apache.commons.io.IOUtils; import org.junit.Before; import org.junit.Rule; import org.junit.Test; @@ -24,6 +23,7 @@ import org.junit.rules.TemporaryFolder; import net.sourceforge.pmd.RuleSet; import net.sourceforge.pmd.RuleSetLoader; import net.sourceforge.pmd.docs.MockedFileWriter.FileEntry; +import net.sourceforge.pmd.util.IOUtil; public class RuleDocGeneratorTest { @@ -52,7 +52,7 @@ public class RuleDocGeneratorTest { private static String loadResource(String name) throws IOException { return MockedFileWriter.normalizeLineSeparators( - IOUtils.toString(RuleDocGeneratorTest.class.getResourceAsStream(name), StandardCharsets.UTF_8)); + IOUtil.readToString(RuleDocGeneratorTest.class.getResourceAsStream(name), StandardCharsets.UTF_8)); } @Test @@ -69,15 +69,15 @@ public class RuleDocGeneratorTest { assertEquals(3, writer.getData().size()); FileEntry languageIndex = writer.getData().get(0); - assertTrue(FilenameUtils.normalize(languageIndex.getFilename(), true).endsWith("docs/pages/pmd/rules/java.md")); + assertTrue(IOUtil.normalizePath(languageIndex.getFilename()).endsWith(Paths.get("docs", "pages", "pmd", "rules", "java.md").toString())); assertEquals(loadResource("/expected/java.md"), languageIndex.getContent()); FileEntry ruleSetIndex = writer.getData().get(1); - assertTrue(FilenameUtils.normalize(ruleSetIndex.getFilename(), true).endsWith("docs/pages/pmd/rules/java/sample.md")); + assertTrue(IOUtil.normalizePath(ruleSetIndex.getFilename()).endsWith(Paths.get("docs", "pages", "pmd", "rules", "java", "sample.md").toString())); assertEquals(loadResource("/expected/sample.md"), ruleSetIndex.getContent()); FileEntry sidebar = writer.getData().get(2); - assertTrue(FilenameUtils.normalize(sidebar.getFilename(), true).endsWith("docs/_data/sidebars/pmd_sidebar.yml")); + assertTrue(IOUtil.normalizePath(sidebar.getFilename()).endsWith(Paths.get("docs", "_data", "sidebars", "pmd_sidebar.yml").toString())); assertEquals(loadResource("/expected/pmd_sidebar.yml"), sidebar.getContent()); } } diff --git a/pmd-doc/src/test/java/net/sourceforge/pmd/docs/RuleSetResolverTest.java b/pmd-doc/src/test/java/net/sourceforge/pmd/docs/RuleSetResolverTest.java index c2c082c44f..3d85da8daa 100644 --- a/pmd-doc/src/test/java/net/sourceforge/pmd/docs/RuleSetResolverTest.java +++ b/pmd-doc/src/test/java/net/sourceforge/pmd/docs/RuleSetResolverTest.java @@ -12,19 +12,19 @@ import java.util.ArrayList; import java.util.Iterator; import java.util.List; -import org.apache.commons.io.FilenameUtils; import org.junit.Test; import net.sourceforge.pmd.RuleSetFactory; import net.sourceforge.pmd.RuleSetNotFoundException; import net.sourceforge.pmd.RulesetsFactoryUtils; +import net.sourceforge.pmd.util.IOUtil; public class RuleSetResolverTest { private static List excludedRulesets = new ArrayList<>(); static { - excludedRulesets.add(FilenameUtils.normalize("pmd-test/src/main/resources/rulesets/dummy/basic.xml")); + excludedRulesets.add(IOUtil.normalizePath("pmd-test/src/main/resources/rulesets/dummy/basic.xml")); } @Test diff --git a/pmd-doc/src/test/java/net/sourceforge/pmd/docs/SidebarGeneratorTest.java b/pmd-doc/src/test/java/net/sourceforge/pmd/docs/SidebarGeneratorTest.java index ea01604b3c..190a607bb1 100644 --- a/pmd-doc/src/test/java/net/sourceforge/pmd/docs/SidebarGeneratorTest.java +++ b/pmd-doc/src/test/java/net/sourceforge/pmd/docs/SidebarGeneratorTest.java @@ -15,7 +15,6 @@ import java.util.HashMap; import java.util.List; import java.util.Map; -import org.apache.commons.io.IOUtils; import org.apache.commons.lang3.SystemUtils; import org.junit.Before; import org.junit.Test; @@ -28,6 +27,7 @@ import net.sourceforge.pmd.RuleSet; import net.sourceforge.pmd.RulesetsFactoryUtils; import net.sourceforge.pmd.lang.Language; import net.sourceforge.pmd.lang.LanguageRegistry; +import net.sourceforge.pmd.util.IOUtil; public class SidebarGeneratorTest { private MockedFileWriter writer = new MockedFileWriter(); @@ -56,7 +56,7 @@ public class SidebarGeneratorTest { String yaml = new Yaml(options).dump(result); String expected = MockedFileWriter.normalizeLineSeparators( - IOUtils.toString(SidebarGeneratorTest.class.getResourceAsStream("sidebar.yml"), StandardCharsets.UTF_8)); + IOUtil.readToString(SidebarGeneratorTest.class.getResourceAsStream("sidebar.yml"), StandardCharsets.UTF_8)); assertEquals(expected, yaml); } } From cfacfbbff2e56041275fcf9b742e09bfc4b7b411 Mon Sep 17 00:00:00 2001 From: Andreas Dangel Date: Fri, 13 May 2022 15:18:03 +0200 Subject: [PATCH 084/198] Fix tests under Windows --- .../java/net/sourceforge/pmd/RuleSetTest.java | 3 +- .../net/sourceforge/pmd/util/IOUtilTest.java | 66 +++++++++++++------ 2 files changed, 48 insertions(+), 21 deletions(-) diff --git a/pmd-core/src/test/java/net/sourceforge/pmd/RuleSetTest.java b/pmd-core/src/test/java/net/sourceforge/pmd/RuleSetTest.java index 14f4db1072..3ff5ba5fb7 100644 --- a/pmd-core/src/test/java/net/sourceforge/pmd/RuleSetTest.java +++ b/pmd-core/src/test/java/net/sourceforge/pmd/RuleSetTest.java @@ -12,6 +12,7 @@ import static org.junit.Assert.assertNull; import static org.junit.Assert.assertTrue; import java.io.File; +import java.nio.file.Paths; import java.util.ArrayList; import java.util.Arrays; import java.util.Collection; @@ -581,7 +582,7 @@ public class RuleSetTest { assertEquals("Wrong error message", "RuntimeException: Test exception while applying rule", processingError.getMsg()); assertTrue("Should be a RuntimeException", processingError.getError() instanceof RuntimeException); assertEquals("Wrong filename in processing error", - "net.sourceforge.pmd.RuleSetTest/ruleExceptionShouldBeReported.java", + Paths.get("net.sourceforge.pmd.RuleSetTest", "ruleExceptionShouldBeReported.java").toString(), IOUtil.normalizePath(processingError.getFile())); assertEquals("There should be a violation", 1, context.getReport().size()); diff --git a/pmd-core/src/test/java/net/sourceforge/pmd/util/IOUtilTest.java b/pmd-core/src/test/java/net/sourceforge/pmd/util/IOUtilTest.java index 35e772cfc9..7b21230fb6 100644 --- a/pmd-core/src/test/java/net/sourceforge/pmd/util/IOUtilTest.java +++ b/pmd-core/src/test/java/net/sourceforge/pmd/util/IOUtilTest.java @@ -80,30 +80,56 @@ public class IOUtilTest { @Test public void testNormalizePath() { - Assert.assertEquals("ab/cd.txt", IOUtil.normalizePath("ab/ef/../cd.txt")); - Assert.assertEquals("/a.txt", IOUtil.normalizePath("/x/../../a.txt")); - Assert.assertEquals("/foo", IOUtil.normalizePath("//../foo")); - Assert.assertEquals("/foo", IOUtil.normalizePath("/foo//")); - Assert.assertEquals("/foo", IOUtil.normalizePath("/foo/./")); - Assert.assertEquals("/bar", IOUtil.normalizePath("/foo/../bar")); - Assert.assertEquals("/bar", IOUtil.normalizePath("/foo/../bar/")); - Assert.assertEquals("/baz", IOUtil.normalizePath("/foo/../bar/../baz")); - Assert.assertEquals("/foo/bar", IOUtil.normalizePath("//foo//./bar")); - Assert.assertEquals("foo", IOUtil.normalizePath("foo/bar/..")); - Assert.assertEquals("bar", IOUtil.normalizePath("foo/../bar")); - Assert.assertEquals("/foo/baz", IOUtil.normalizePath("//foo/bar/../baz")); - Assert.assertEquals("~/bar", IOUtil.normalizePath("~/foo/../bar/")); - Assert.assertEquals("/", IOUtil.normalizePath("/../")); - Assert.assertEquals("bar", IOUtil.normalizePath("~/../bar")); - Assert.assertEquals("bar", IOUtil.normalizePath("./bar")); + if (SystemUtils.IS_OS_UNIX) { + Assert.assertEquals("ab/cd.txt", IOUtil.normalizePath("ab/ef/../cd.txt")); + Assert.assertEquals("/a.txt", IOUtil.normalizePath("/x/../../a.txt")); + Assert.assertEquals("/foo", IOUtil.normalizePath("//../foo")); + Assert.assertEquals("/foo", IOUtil.normalizePath("/foo//")); + Assert.assertEquals("/foo", IOUtil.normalizePath("/foo/./")); + Assert.assertEquals("/bar", IOUtil.normalizePath("/foo/../bar")); + Assert.assertEquals("/bar", IOUtil.normalizePath("/foo/../bar/")); + Assert.assertEquals("/baz", IOUtil.normalizePath("/foo/../bar/../baz")); + Assert.assertEquals("/foo/bar", IOUtil.normalizePath("//foo//./bar")); + Assert.assertEquals("foo", IOUtil.normalizePath("foo/bar/..")); + Assert.assertEquals("bar", IOUtil.normalizePath("foo/../bar")); + Assert.assertEquals("/foo/baz", IOUtil.normalizePath("//foo/bar/../baz")); + Assert.assertEquals("~/bar", IOUtil.normalizePath("~/foo/../bar/")); + Assert.assertEquals("/", IOUtil.normalizePath("/../")); + Assert.assertEquals("bar", IOUtil.normalizePath("~/../bar")); + Assert.assertEquals("bar", IOUtil.normalizePath("./bar")); - Assert.assertNull(IOUtil.normalizePath("../foo")); - Assert.assertNull(IOUtil.normalizePath("foo/../../bar")); - Assert.assertNull(IOUtil.normalizePath(".")); + Assert.assertNull(IOUtil.normalizePath("../foo")); + Assert.assertNull(IOUtil.normalizePath("foo/../../bar")); + Assert.assertNull(IOUtil.normalizePath(".")); - Assert.assertTrue(IOUtil.equalsNormalizedPaths("foo/../bar", "bar/./")); + Assert.assertTrue(IOUtil.equalsNormalizedPaths("foo/../bar", "bar/./")); + } if (SystemUtils.IS_OS_WINDOWS) { + Assert.assertEquals("ab\\cd.txt", IOUtil.normalizePath("ab\\ef\\..\\cd.txt")); + Assert.assertEquals("\\a.txt", IOUtil.normalizePath("\\x\\..\\..\\a.txt")); + Assert.assertEquals("\\foo", IOUtil.normalizePath("\\foo\\\\")); + Assert.assertEquals("\\foo", IOUtil.normalizePath("\\foo\\.\\")); + Assert.assertEquals("\\bar", IOUtil.normalizePath("\\foo\\..\\bar")); + Assert.assertEquals("\\bar", IOUtil.normalizePath("\\foo\\..\\bar\\")); + Assert.assertEquals("\\baz", IOUtil.normalizePath("\\foo\\..\\bar\\..\\baz")); + Assert.assertEquals("\\\\foo\\bar\\", IOUtil.normalizePath("\\\\foo\\bar")); + Assert.assertEquals("\\\\foo\\bar\\baz", IOUtil.normalizePath("\\\\foo\\bar\\..\\baz")); + Assert.assertEquals("foo", IOUtil.normalizePath("foo\\bar\\..")); + Assert.assertEquals("bar", IOUtil.normalizePath("foo\\..\\bar")); + Assert.assertEquals("\\foo\\baz", IOUtil.normalizePath("\\foo\\bar\\..\\baz")); + Assert.assertEquals("\\", IOUtil.normalizePath("\\..\\")); + Assert.assertEquals("bar", IOUtil.normalizePath(".\\bar")); + + Assert.assertNull(IOUtil.normalizePath("\\\\..\\foo")); + Assert.assertNull(IOUtil.normalizePath("..\\foo")); + Assert.assertNull(IOUtil.normalizePath("foo\\..\\..\\bar")); + Assert.assertNull(IOUtil.normalizePath(".")); + Assert.assertNull(IOUtil.normalizePath("\\\\foo\\\\.\\bar")); + Assert.assertNull(IOUtil.normalizePath("\\\\foo\\.\\bar")); + + Assert.assertTrue(IOUtil.equalsNormalizedPaths("foo\\..\\bar", "bar\\.\\")); + Assert.assertEquals("C:\\bar", IOUtil.normalizePath("C:\\..\\bar")); Assert.assertEquals("ab\\cd.txt", IOUtil.normalizePath("ab\\ef\\..\\cd.txt")); Assert.assertEquals("C:\\ab\\cd.txt", IOUtil.normalizePath("C:\\ab\\ef\\..\\.\\cd.txt")); From 1c9096809dd2cda3922c7cd0c98d0bed92c09202 Mon Sep 17 00:00:00 2001 From: Andreas Dangel Date: Fri, 13 May 2022 15:25:24 +0200 Subject: [PATCH 085/198] [doc] Update release notes (#3942) --- docs/pages/release_notes.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/docs/pages/release_notes.md b/docs/pages/release_notes.md index c31a705241..7ac4b956c8 100644 --- a/docs/pages/release_notes.md +++ b/docs/pages/release_notes.md @@ -15,7 +15,8 @@ This is a {{ site.pmd.release_type }} release. ### New and noteworthy ### Fixed Issues - +* core + * [#3942](https://github.com/pmd/pmd/issues/3942): \[core] common-io path traversal vulnerability (CVE-2021-29425) * javascript * [#3948](https://github.com/pmd/pmd/issues/3948): \[js] Invalid operator error for method property in object literal From 17ba56e4548d9e5c12f0ddec79c290947cbba8d2 Mon Sep 17 00:00:00 2001 From: Andreas Dangel Date: Fri, 13 May 2022 16:07:15 +0200 Subject: [PATCH 086/198] Replace IOUtils with IOUtil, Fix compile errors --- .../net/sourceforge/pmd/cpd/internal/JavaCCTokenizer.java | 5 ++--- .../pmd/lang/ast/impl/javacc/CharStreamFactory.java | 5 ++--- .../net/sourceforge/pmd/util/datasource/DataSource.java | 8 +++----- .../sourceforge/pmd/util/treeexport/TreeExportCli.java | 4 ++-- .../test/java/net/sourceforge/pmd/ant/PMDTaskTest.java | 1 - .../java/net/sourceforge/pmd/cpd/FileReporterTest.java | 5 +++-- .../net/sourceforge/pmd/lang/html/ast/HtmlParser.java | 1 - .../sourceforge/pmd/test/util/JavaUtilLoggingRule.java | 4 ++-- 8 files changed, 14 insertions(+), 19 deletions(-) diff --git a/pmd-core/src/main/java/net/sourceforge/pmd/cpd/internal/JavaCCTokenizer.java b/pmd-core/src/main/java/net/sourceforge/pmd/cpd/internal/JavaCCTokenizer.java index 04b9ab04ef..cb3337c329 100644 --- a/pmd-core/src/main/java/net/sourceforge/pmd/cpd/internal/JavaCCTokenizer.java +++ b/pmd-core/src/main/java/net/sourceforge/pmd/cpd/internal/JavaCCTokenizer.java @@ -6,8 +6,7 @@ package net.sourceforge.pmd.cpd.internal; import java.io.IOException; import java.io.Reader; - -import org.apache.commons.io.input.CharSequenceReader; +import java.io.StringReader; import net.sourceforge.pmd.cpd.SourceCode; import net.sourceforge.pmd.cpd.TokenEntry; @@ -26,7 +25,7 @@ public abstract class JavaCCTokenizer implements Tokenizer { @SuppressWarnings("PMD.CloseResource") protected TokenManager getLexerForSource(SourceCode sourceCode) throws IOException { - Reader reader = IOUtil.skipBOM(new CharSequenceReader(sourceCode.getCodeBuffer())); + Reader reader = IOUtil.skipBOM(new StringReader(sourceCode.getCodeBuffer().toString())); return makeLexerImpl(makeCharStream(reader)); } diff --git a/pmd-core/src/main/java/net/sourceforge/pmd/lang/ast/impl/javacc/CharStreamFactory.java b/pmd-core/src/main/java/net/sourceforge/pmd/lang/ast/impl/javacc/CharStreamFactory.java index f579c8a0a2..d7b456d4ba 100644 --- a/pmd-core/src/main/java/net/sourceforge/pmd/lang/ast/impl/javacc/CharStreamFactory.java +++ b/pmd-core/src/main/java/net/sourceforge/pmd/lang/ast/impl/javacc/CharStreamFactory.java @@ -8,9 +8,8 @@ import java.io.IOException; import java.io.Reader; import java.util.function.Function; -import org.apache.commons.io.IOUtils; - import net.sourceforge.pmd.lang.ast.CharStream; +import net.sourceforge.pmd.util.IOUtil; public final class CharStreamFactory { @@ -58,7 +57,7 @@ public final class CharStreamFactory { @Deprecated public static String toString(Reader dstream) { try (Reader r = dstream) { - return IOUtils.toString(r); + return IOUtil.readToString(r); } catch (IOException e) { throw new RuntimeException(e); } diff --git a/pmd-core/src/main/java/net/sourceforge/pmd/util/datasource/DataSource.java b/pmd-core/src/main/java/net/sourceforge/pmd/util/datasource/DataSource.java index 3338c64a8a..35231e6ba1 100644 --- a/pmd-core/src/main/java/net/sourceforge/pmd/util/datasource/DataSource.java +++ b/pmd-core/src/main/java/net/sourceforge/pmd/util/datasource/DataSource.java @@ -12,9 +12,7 @@ import java.io.Reader; import java.io.StringReader; import java.nio.charset.Charset; -import org.apache.commons.io.ByteOrderMark; -import org.apache.commons.io.IOUtils; -import org.apache.commons.io.input.BOMInputStream; +import net.sourceforge.pmd.util.IOUtil; /** * Represents a source file to be analyzed. Different implementations can get @@ -59,10 +57,10 @@ public interface DataSource extends Closeable { String fullSource; try (InputStream stream = dataSource.getInputStream(); // Skips the byte-order mark - BOMInputStream bomIs = new BOMInputStream(stream, ByteOrderMark.UTF_8, ByteOrderMark.UTF_16BE); + IOUtil.BomAwareInputStream bomIs = new IOUtil.BomAwareInputStream(stream); Reader reader = new InputStreamReader(bomIs, sourceEncoding)) { - fullSource = IOUtils.toString(reader); // this already buffers properly + fullSource = IOUtil.readToString(reader); // this already buffers properly } return fullSource; } diff --git a/pmd-core/src/main/java/net/sourceforge/pmd/util/treeexport/TreeExportCli.java b/pmd-core/src/main/java/net/sourceforge/pmd/util/treeexport/TreeExportCli.java index 9f6d1faaca..85985f62ef 100644 --- a/pmd-core/src/main/java/net/sourceforge/pmd/util/treeexport/TreeExportCli.java +++ b/pmd-core/src/main/java/net/sourceforge/pmd/util/treeexport/TreeExportCli.java @@ -16,7 +16,6 @@ import java.util.HashMap; import java.util.List; import java.util.Map; -import org.apache.commons.io.IOUtils; import org.apache.commons.lang3.StringEscapeUtils; import net.sourceforge.pmd.annotation.Experimental; @@ -32,6 +31,7 @@ import net.sourceforge.pmd.lang.ast.SemanticErrorReporter; import net.sourceforge.pmd.lang.rule.xpath.Attribute; import net.sourceforge.pmd.properties.PropertyDescriptor; import net.sourceforge.pmd.properties.PropertySource; +import net.sourceforge.pmd.util.IOUtil; import com.beust.jcommander.DynamicParameter; import com.beust.jcommander.JCommander; @@ -200,7 +200,7 @@ public class TreeExportCli { Slf4jSimpleConfiguration.disableLogging(Attribute.class); try { - String fullSource = IOUtils.toString(source); + String fullSource = IOUtil.readToString(source); ParserTask task = new ParserTask(langVersion, fileName, fullSource, SemanticErrorReporter.noop()); RootNode root = parser.parse(task); diff --git a/pmd-core/src/test/java/net/sourceforge/pmd/ant/PMDTaskTest.java b/pmd-core/src/test/java/net/sourceforge/pmd/ant/PMDTaskTest.java index 4fa4b5fd8e..9707421d2c 100644 --- a/pmd-core/src/test/java/net/sourceforge/pmd/ant/PMDTaskTest.java +++ b/pmd-core/src/test/java/net/sourceforge/pmd/ant/PMDTaskTest.java @@ -22,7 +22,6 @@ import org.junit.contrib.java.lang.system.RestoreSystemProperties; import org.junit.rules.TestRule; import net.sourceforge.pmd.internal.Slf4jSimpleConfiguration; - import net.sourceforge.pmd.util.IOUtil; public class PMDTaskTest { diff --git a/pmd-core/src/test/java/net/sourceforge/pmd/cpd/FileReporterTest.java b/pmd-core/src/test/java/net/sourceforge/pmd/cpd/FileReporterTest.java index 69768f7ecb..b7d2612554 100644 --- a/pmd-core/src/test/java/net/sourceforge/pmd/cpd/FileReporterTest.java +++ b/pmd-core/src/test/java/net/sourceforge/pmd/cpd/FileReporterTest.java @@ -12,9 +12,10 @@ import java.io.FileReader; import java.io.IOException; import java.io.Reader; -import org.apache.commons.io.IOUtils; import org.junit.Test; +import net.sourceforge.pmd.util.IOUtil; + /** * @author Philippe T'Seyen */ @@ -56,7 +57,7 @@ public class FileReporterTest { private String readFile(File file) throws IOException { try (Reader reader = new FileReader(file)) { - String text = IOUtils.toString(reader); + String text = IOUtil.readToString(reader); return text.replaceAll("\\R", "\n"); } } diff --git a/pmd-html/src/main/java/net/sourceforge/pmd/lang/html/ast/HtmlParser.java b/pmd-html/src/main/java/net/sourceforge/pmd/lang/html/ast/HtmlParser.java index 9042c90243..a2ce2533b0 100644 --- a/pmd-html/src/main/java/net/sourceforge/pmd/lang/html/ast/HtmlParser.java +++ b/pmd-html/src/main/java/net/sourceforge/pmd/lang/html/ast/HtmlParser.java @@ -19,5 +19,4 @@ public final class HtmlParser implements net.sourceforge.pmd.lang.ast.Parser { HtmlTreeBuilder builder = new HtmlTreeBuilder(); return builder.build(doc, data, task, new HashMap<>()); } - } } diff --git a/pmd-test/src/main/java/net/sourceforge/pmd/test/util/JavaUtilLoggingRule.java b/pmd-test/src/main/java/net/sourceforge/pmd/test/util/JavaUtilLoggingRule.java index d1f0cb8494..e801e7f8c5 100644 --- a/pmd-test/src/main/java/net/sourceforge/pmd/test/util/JavaUtilLoggingRule.java +++ b/pmd-test/src/main/java/net/sourceforge/pmd/test/util/JavaUtilLoggingRule.java @@ -9,6 +9,7 @@ import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.containsStringIgnoringCase; import static org.hamcrest.Matchers.emptyString; +import java.io.ByteArrayOutputStream; import java.nio.charset.StandardCharsets; import java.util.ArrayList; import java.util.List; @@ -17,7 +18,6 @@ import java.util.logging.Handler; import java.util.logging.Logger; import java.util.logging.StreamHandler; -import org.apache.commons.io.output.ByteArrayOutputStream; import org.junit.contrib.java.lang.system.SystemErrRule; import org.junit.rules.TestRule; import org.junit.runner.Description; @@ -121,7 +121,7 @@ public class JavaUtilLoggingRule implements TestRule { */ public String getLog() { customLogHandler.flush(); - return stream.toString(StandardCharsets.UTF_8); + return new String(stream.toByteArray(), StandardCharsets.UTF_8); } /** From 8addd05369b60e5169a7db304fc92fff6c08c018 Mon Sep 17 00:00:00 2001 From: Andreas Dangel Date: Fri, 13 May 2022 16:43:17 +0200 Subject: [PATCH 087/198] Fix tests under Windows --- .../pmd/docs/RuleDocGenerator.java | 19 ++++--------------- .../sourceforge/pmd/docs/RuleSetUtils.java | 16 ++++++++++++++-- 2 files changed, 18 insertions(+), 17 deletions(-) diff --git a/pmd-doc/src/main/java/net/sourceforge/pmd/docs/RuleDocGenerator.java b/pmd-doc/src/main/java/net/sourceforge/pmd/docs/RuleDocGenerator.java index a1e23965cd..0cc2923649 100644 --- a/pmd-doc/src/main/java/net/sourceforge/pmd/docs/RuleDocGenerator.java +++ b/pmd-doc/src/main/java/net/sourceforge/pmd/docs/RuleDocGenerator.java @@ -31,7 +31,6 @@ import java.util.regex.Pattern; import java.util.stream.Collectors; import org.apache.commons.lang3.StringUtils; -import org.apache.commons.lang3.SystemUtils; import org.apache.commons.text.StringEscapeUtils; import net.sourceforge.pmd.Rule; @@ -609,13 +608,13 @@ public class RuleDocGenerator { // is replaced by a correct path. for (List rulesets : sortedRulesets.values()) { for (RuleSet ruleset : rulesets) { - String rulesetFilename = normalizeForwardSlashes(StringUtils.chomp(ruleset.getFileName())); + String rulesetFilename = RuleSetUtils.normalizeForwardSlashes(StringUtils.chomp(ruleset.getFileName())); allRulesets.put(ruleset.getFileName(), rulesetFilename); for (Rule rule : ruleset.getRules()) { String ruleClass = rule.getRuleClass(); String relativeSourceFilename = ruleClass.replaceAll("\\.", Matcher.quoteReplacement(File.separator)) + ".java"; - allRules.put(ruleClass, normalizeForwardSlashes(relativeSourceFilename)); + allRules.put(ruleClass, RuleSetUtils.normalizeForwardSlashes(relativeSourceFilename)); } } } @@ -637,7 +636,7 @@ public class RuleDocGenerator { } if (foundRuleClass != null) { Path foundPath = root.relativize(file); - allRules.put(foundRuleClass, normalizeForwardSlashes(foundPath.toString())); + allRules.put(foundRuleClass, RuleSetUtils.normalizeForwardSlashes(foundPath.toString())); } String foundRuleset = null; @@ -649,7 +648,7 @@ public class RuleDocGenerator { } if (foundRuleset != null) { Path foundPath = root.relativize(file); - allRulesets.put(foundRuleset, normalizeForwardSlashes(foundPath.toString())); + allRulesets.put(foundRuleset, RuleSetUtils.normalizeForwardSlashes(foundPath.toString())); } } return FileVisitResult.CONTINUE; @@ -659,14 +658,4 @@ public class RuleDocGenerator { throw new RuntimeException(e); } } - - private static String normalizeForwardSlashes(String path) { - String normalized = IOUtil.normalizePath(path); - if (SystemUtils.IS_OS_WINDOWS) { - // Note: windows path separators are changed to forward slashes, - // so that the editme link works - normalized = normalized.replaceAll(Pattern.quote(File.separator), "/"); - } - return normalized; - } } diff --git a/pmd-doc/src/main/java/net/sourceforge/pmd/docs/RuleSetUtils.java b/pmd-doc/src/main/java/net/sourceforge/pmd/docs/RuleSetUtils.java index a7afef7b5b..0ab05a68bc 100644 --- a/pmd-doc/src/main/java/net/sourceforge/pmd/docs/RuleSetUtils.java +++ b/pmd-doc/src/main/java/net/sourceforge/pmd/docs/RuleSetUtils.java @@ -5,8 +5,10 @@ package net.sourceforge.pmd.docs; import java.io.File; +import java.util.regex.Pattern; import org.apache.commons.lang3.StringUtils; +import org.apache.commons.lang3.SystemUtils; import net.sourceforge.pmd.Rule; import net.sourceforge.pmd.RuleSet; @@ -52,8 +54,8 @@ public final class RuleSetUtils { } public static String getRuleSetClasspath(RuleSet ruleset) { - final String RESOURCES_PATH = File.separator + "resources" + File.separator; - String filename = IOUtil.normalizePath(StringUtils.chomp(ruleset.getFileName())); + final String RESOURCES_PATH = "/resources/"; + String filename = normalizeForwardSlashes(StringUtils.chomp(ruleset.getFileName())); int startIndex = filename.lastIndexOf(RESOURCES_PATH); if (startIndex > -1) { return filename.substring(startIndex + RESOURCES_PATH.length()); @@ -62,6 +64,16 @@ public final class RuleSetUtils { } } + public static String normalizeForwardSlashes(String path) { + String normalized = IOUtil.normalizePath(path); + if (SystemUtils.IS_OS_WINDOWS) { + // Note: windows path separators are changed to forward slashes, + // so that the editme link works + normalized = normalized.replaceAll(Pattern.quote(File.separator), "/"); + } + return normalized; + } + /** * Recursively resolves rule references until the last reference. * The last reference is returned. From a9219b7967ed1fbbc3029625c40823fd49e84a5f Mon Sep 17 00:00:00 2001 From: Andreas Dangel Date: Fri, 13 May 2022 17:13:16 +0200 Subject: [PATCH 088/198] [core] Fix bug in IOUtil.fromReader --- .../java/net/sourceforge/pmd/util/IOUtil.java | 2 +- .../java/net/sourceforge/pmd/util/IOUtilTest.java | 15 +++++++++++++++ 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/pmd-core/src/main/java/net/sourceforge/pmd/util/IOUtil.java b/pmd-core/src/main/java/net/sourceforge/pmd/util/IOUtil.java index 791561bc7a..881bc7efa2 100644 --- a/pmd-core/src/main/java/net/sourceforge/pmd/util/IOUtil.java +++ b/pmd-core/src/main/java/net/sourceforge/pmd/util/IOUtil.java @@ -325,7 +325,7 @@ public final class IOUtil { charBuffer.flip(); encoder.encode(charBuffer, byteBuffer, eof); byteBuffer.flip(); - charBuffer.flip(); + charBuffer.compact(); } if (byteBuffer.hasRemaining()) { diff --git a/pmd-core/src/test/java/net/sourceforge/pmd/util/IOUtilTest.java b/pmd-core/src/test/java/net/sourceforge/pmd/util/IOUtilTest.java index 7b21230fb6..b577de8f11 100644 --- a/pmd-core/src/test/java/net/sourceforge/pmd/util/IOUtilTest.java +++ b/pmd-core/src/test/java/net/sourceforge/pmd/util/IOUtilTest.java @@ -193,6 +193,21 @@ public class IOUtilTest { } } + @Test + public void testInputStreamFromReader2() throws IOException { + int size = 8192 + 8192 + 10; + char[] data = new char[size]; + for (int i = 0; i < size; i++) { + data[i] = 'A'; + } + data[8192] = 'ä'; // block size border - in UTF-8 these are two bytes. Decoding needs to take the bytes + // from previous block and new block + try (InputStream inputStream = IOUtil.fromReader(new StringReader(new String(data)))) { + byte[] bytes = IOUtil.toByteArray(inputStream); + Assert.assertEquals(new String(data), new String(bytes, StandardCharsets.UTF_8)); + } + } + @Test public void testCopyStream() throws IOException { int size = 8192 + 8192 + 10; From fe414864a0565d3f4e26ec9de9909873ba16ecca Mon Sep 17 00:00:00 2001 From: Andreas Dangel Date: Fri, 13 May 2022 17:21:43 +0200 Subject: [PATCH 089/198] Replace IOUtils with IOUtil, Fix compile errors --- .../sourceforge/pmd/lang/vf/ast/ApexClassPropertyTypes.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pmd-visualforce/src/main/java/net/sourceforge/pmd/lang/vf/ast/ApexClassPropertyTypes.java b/pmd-visualforce/src/main/java/net/sourceforge/pmd/lang/vf/ast/ApexClassPropertyTypes.java index 57fd70b782..e20a1b8f0c 100644 --- a/pmd-visualforce/src/main/java/net/sourceforge/pmd/lang/vf/ast/ApexClassPropertyTypes.java +++ b/pmd-visualforce/src/main/java/net/sourceforge/pmd/lang/vf/ast/ApexClassPropertyTypes.java @@ -11,7 +11,6 @@ import java.nio.file.Files; import java.nio.file.Path; import java.util.List; -import org.apache.commons.io.IOUtils; import org.apache.commons.lang3.exception.ContextedRuntimeException; import org.apache.commons.lang3.tuple.Pair; import org.slf4j.Logger; @@ -25,6 +24,7 @@ import net.sourceforge.pmd.lang.ast.Parser; import net.sourceforge.pmd.lang.ast.Parser.ParserTask; import net.sourceforge.pmd.lang.ast.SemanticErrorReporter; import net.sourceforge.pmd.lang.vf.DataType; +import net.sourceforge.pmd.util.IOUtil; import apex.jorje.semantic.symbol.type.BasicType; @@ -69,7 +69,7 @@ class ApexClassPropertyTypes extends SalesforceFieldTypes { static Node parseApex(Path apexFilePath) { String fileText; try (BufferedReader reader = Files.newBufferedReader(apexFilePath, StandardCharsets.UTF_8)) { - fileText = IOUtils.toString(reader); + fileText = IOUtil.readToString(reader); } catch (IOException e) { throw new ContextedRuntimeException(e).addContextValue("apexFilePath", apexFilePath); } From 9d23d79802a963e4a4edee8ec7cfcf61cc1f4155 Mon Sep 17 00:00:00 2001 From: Andreas Dangel Date: Fri, 13 May 2022 18:40:05 +0200 Subject: [PATCH 090/198] [ci] regression test - skip patching/building spring The regression tester now does not anymore execute a "git reset"... and the patched files stay in place in the github actions cache. --- .ci/files/project-list.xml | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/.ci/files/project-list.xml b/.ci/files/project-list.xml index 3ecd924ece..ce357698bc 100644 --- a/.ci/files/project-list.xml +++ b/.ci/files/project-list.xml @@ -40,6 +40,11 @@ mvn dependency:build-classpath -DincludeScope=test -Dmdep.outputFile=classpath.t .*/build/generated-sources/.* classpath.txt ]]> From e8935523ed265eff42469c711ad3bd2ff7dd16fe Mon Sep 17 00:00:00 2001 From: Andreas Dangel Date: Fri, 13 May 2022 20:07:18 +0200 Subject: [PATCH 091/198] Update pmd-java/src/main/resources/category/java/performance.xml MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Clément Fournier --- pmd-java/src/main/resources/category/java/performance.xml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pmd-java/src/main/resources/category/java/performance.xml b/pmd-java/src/main/resources/category/java/performance.xml index 8411f35603..b93f71eb4a 100644 --- a/pmd-java/src/main/resources/category/java/performance.xml +++ b/pmd-java/src/main/resources/category/java/performance.xml @@ -971,9 +971,9 @@ You must use `new ArrayList<>(Arrays.asList(...))` if that is inconvenient for y [count(Statement//StatementExpression)=1] [@Foreach = true() or ForInit//VariableInitializer//Literal[@IntLiteral= true() and @Image='0']] (: skip primitive types :) - [@Foreach = true() and Expression[not(pmd-java:typeIs('boolean[]') or pmd-java:typeIs('char[]') or pmd-java:typeIs('byte[]') or pmd-java:typeIs('short[]') or pmd-java:typeIs('int[]') or pmd-java:typeIs('long[]') or pmd-java:typeIs('float[]') or pmd-java:typeIs('double[]'))] + [@Foreach = true() and Expression[pmd-java:typeIs('java.lang.Object[]')] or Expression/RelationalExpression/PrimaryExpression/PrimaryPrefix/Name[substring-before(@Image, '.length') = - ancestor::MethodDeclaration[1]//VariableDeclaratorId[not(pmd-java:typeIs('boolean[]') or pmd-java:typeIs('char[]') or pmd-java:typeIs('byte[]') or pmd-java:typeIs('short[]') or pmd-java:typeIs('int[]') or pmd-java:typeIs('long[]') or pmd-java:typeIs('float[]') or pmd-java:typeIs('double[]'))] + ancestor::MethodDeclaration[1]//VariableDeclaratorId[pmd-java:typeIs('java.lang.Object[]')] /@Name] ] //StatementExpression From f291a2917b40f7886bf01a1dad74eb063dcfc612 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9ment=20Fournier?= Date: Sun, 15 May 2022 14:09:58 +0200 Subject: [PATCH 092/198] Turn many semantic errors into warnings --- .../pmd/lang/ast/SemanticErrorReporter.java | 10 ++++++---- .../pmd/lang/ast/SemanticErrorReporterTest.java | 8 ++++++++ .../pmd/lang/java/ast/AstDisambiguationPass.java | 4 ++-- .../pmd/lang/java/ast/InternalApiBridge.java | 2 +- .../lang/java/symbols/table/internal/ReferenceCtx.java | 2 +- .../pmd/lang/java/types/ast/LazyTypeResolver.java | 2 +- 6 files changed, 19 insertions(+), 9 deletions(-) diff --git a/pmd-core/src/main/java/net/sourceforge/pmd/lang/ast/SemanticErrorReporter.java b/pmd-core/src/main/java/net/sourceforge/pmd/lang/ast/SemanticErrorReporter.java index 84df3a625c..03c0313fc9 100644 --- a/pmd-core/src/main/java/net/sourceforge/pmd/lang/ast/SemanticErrorReporter.java +++ b/pmd-core/src/main/java/net/sourceforge/pmd/lang/ast/SemanticErrorReporter.java @@ -34,7 +34,9 @@ public interface SemanticErrorReporter { /** * Report a warning at the given location. Warnings do not abort - * the analysis. + * the analysis. They are usually recoverable errors. They are used + * to warn the user that something wrong is going on, which may cause + * subsequent errors or inconsistent behavior. * * @param location Location where the warning should be reported * @param message Message (rendered using a {@link MessageFormat}) @@ -44,9 +46,9 @@ public interface SemanticErrorReporter { /** - * Report an error at the given location. Errors abort subsequent analysis. - * The produced error can be thrown by the caller if it cannot be recovered - * from. + * Report an error at the given location. Errors abort subsequent analysis + * and cause a processing error to be put in the report. The produced error + * can be thrown by the caller if it cannot be recovered from. * * @param location Location where the error should be reported * @param message Message (rendered using a {@link MessageFormat}) diff --git a/pmd-core/src/test/java/net/sourceforge/pmd/lang/ast/SemanticErrorReporterTest.java b/pmd-core/src/test/java/net/sourceforge/pmd/lang/ast/SemanticErrorReporterTest.java index 5497c9b93a..90e2952100 100644 --- a/pmd-core/src/test/java/net/sourceforge/pmd/lang/ast/SemanticErrorReporterTest.java +++ b/pmd-core/src/test/java/net/sourceforge/pmd/lang/ast/SemanticErrorReporterTest.java @@ -4,12 +4,15 @@ package net.sourceforge.pmd.lang.ast; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; import static org.mockito.Mockito.contains; import static org.mockito.Mockito.eq; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.spy; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.verifyNoMoreInteractions; +import static org.mockito.Mockito.when; import org.junit.Before; import org.junit.Test; @@ -36,6 +39,7 @@ public class SemanticErrorReporterTest { @Before public void setup() { mockReporter = mock(MessageReporter.class); + when(mockReporter.isLoggable(Level.ERROR)).thenReturn(true); mockLogger = spy(NOPLogger.class); } @@ -44,11 +48,15 @@ public class SemanticErrorReporterTest { SemanticErrorReporter reporter = SemanticErrorReporter.reportToLogger(mockReporter, mockLogger); RootNode node = parseMockNode(reporter); + assertFalse(reporter.hasError()); + String message = "an error occurred"; reporter.error(node, message); verify(mockReporter).log(eq(Level.ERROR), contains(message)); verifyNoMoreInteractions(mockLogger); + + assertTrue(reporter.hasError()); } @Test diff --git a/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/ast/AstDisambiguationPass.java b/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/ast/AstDisambiguationPass.java index 6a4fe24939..458b52d8b7 100644 --- a/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/ast/AstDisambiguationPass.java +++ b/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/ast/AstDisambiguationPass.java @@ -211,7 +211,7 @@ final class AstDisambiguationPass { JTypeDeclSymbol sym = type.getReferencedSym(); if (type.getParent() instanceof ASTAnnotation) { if (!(sym instanceof JClassSymbol && (sym.isUnresolved() || ((JClassSymbol) sym).isAnnotation()))) { - ctx.getLogger().error(type, JavaSemanticErrors.EXPECTED_ANNOTATION_TYPE); + ctx.getLogger().warning(type, JavaSemanticErrors.EXPECTED_ANNOTATION_TYPE); } return; } @@ -219,7 +219,7 @@ final class AstDisambiguationPass { int actualArity = ASTList.sizeOrZero(type.getTypeArguments()); int expectedArity = sym instanceof JClassSymbol ? ((JClassSymbol) sym).getTypeParameterCount() : 0; if (actualArity != 0 && actualArity != expectedArity) { - ctx.getLogger().error(type, JavaSemanticErrors.MALFORMED_GENERIC_TYPE, expectedArity, actualArity); + ctx.getLogger().warning(type, JavaSemanticErrors.MALFORMED_GENERIC_TYPE, expectedArity, actualArity); } } diff --git a/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/ast/InternalApiBridge.java b/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/ast/InternalApiBridge.java index 9dcc91966f..7cc7f1345c 100644 --- a/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/ast/InternalApiBridge.java +++ b/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/ast/InternalApiBridge.java @@ -98,7 +98,7 @@ public final class InternalApiBridge { try { it.getTypeMirror(); } catch (Exception e) { - processor.getLogger().error(it, "Error during type resolution of node " + it.getXPathNodeName()); + processor.getLogger().warning(it, "Error during type resolution of node " + it.getXPathNodeName()); } }); } diff --git a/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/symbols/table/internal/ReferenceCtx.java b/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/symbols/table/internal/ReferenceCtx.java index 800b67c249..b949c7973c 100644 --- a/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/symbols/table/internal/ReferenceCtx.java +++ b/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/symbols/table/internal/ReferenceCtx.java @@ -90,7 +90,7 @@ public final class ReferenceCtx { if (distinct.size() == 1) { return distinct.iterator().next(); } - processor.getLogger().error( + processor.getLogger().warning( errorLocation, AMBIGUOUS_NAME_REFERENCE, name, diff --git a/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/types/ast/LazyTypeResolver.java b/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/types/ast/LazyTypeResolver.java index c2d28ceb14..c1df639d18 100644 --- a/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/types/ast/LazyTypeResolver.java +++ b/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/types/ast/LazyTypeResolver.java @@ -564,7 +564,7 @@ public final class LazyTypeResolver extends JavaVisitorBase Date: Sun, 15 May 2022 14:14:17 +0200 Subject: [PATCH 093/198] Only use MessageReporter as backend of SemanticErrorReporter --- .../sourceforge/pmd/lang/ast/SemanticErrorReporter.java | 9 ++------- .../java/net/sourceforge/pmd/processor/PmdRunnable.java | 2 +- .../pmd/lang/ast/SemanticErrorReporterTest.java | 4 ++-- .../net/sourceforge/pmd/lang/html/ast/HtmlTokenizer.java | 6 +----- .../net/sourceforge/pmd/lang/java/JavaParsingHelper.java | 2 +- 5 files changed, 7 insertions(+), 16 deletions(-) diff --git a/pmd-core/src/main/java/net/sourceforge/pmd/lang/ast/SemanticErrorReporter.java b/pmd-core/src/main/java/net/sourceforge/pmd/lang/ast/SemanticErrorReporter.java index 03c0313fc9..5d7da3ef77 100644 --- a/pmd-core/src/main/java/net/sourceforge/pmd/lang/ast/SemanticErrorReporter.java +++ b/pmd-core/src/main/java/net/sourceforge/pmd/lang/ast/SemanticErrorReporter.java @@ -6,7 +6,6 @@ package net.sourceforge.pmd.lang.ast; import java.text.MessageFormat; -import org.slf4j.Logger; import org.slf4j.event.Level; import net.sourceforge.pmd.util.StringUtil; @@ -90,7 +89,7 @@ public interface SemanticErrorReporter { * Forwards to a {@link MessageReporter}, except trace and debug * messages which are reported on a logger. */ - static SemanticErrorReporter reportToLogger(MessageReporter reporter, Logger logger) { + static SemanticErrorReporter reportToLogger(MessageReporter reporter) { return new SemanticErrorReporter() { private boolean hasError = false; @@ -105,11 +104,7 @@ public interface SemanticErrorReporter { private String logMessage(Level level, Node location, String message, Object[] args) { String fullMessage = makeMessage(location, message, args); - if (level.compareTo(Level.INFO) > 0) { - logger.atLevel(level).log(fullMessage); - } else { - reporter.log(level, StringUtil.quoteMessageFormat(fullMessage)); // already formatted - } + reporter.log(level, StringUtil.quoteMessageFormat(fullMessage)); // already formatted return fullMessage; } diff --git a/pmd-core/src/main/java/net/sourceforge/pmd/processor/PmdRunnable.java b/pmd-core/src/main/java/net/sourceforge/pmd/processor/PmdRunnable.java index 20173a5247..667ac21f88 100644 --- a/pmd-core/src/main/java/net/sourceforge/pmd/processor/PmdRunnable.java +++ b/pmd-core/src/main/java/net/sourceforge/pmd/processor/PmdRunnable.java @@ -129,7 +129,7 @@ abstract class PmdRunnable implements Runnable { LanguageVersion languageVersion, String filename) throws FileAnalysisException { - SemanticErrorReporter reporter = SemanticErrorReporter.reportToLogger(configuration.getReporter(), LOG); + SemanticErrorReporter reporter = SemanticErrorReporter.reportToLogger(configuration.getReporter()); ParserTask task = new ParserTask( languageVersion, filename, diff --git a/pmd-core/src/test/java/net/sourceforge/pmd/lang/ast/SemanticErrorReporterTest.java b/pmd-core/src/test/java/net/sourceforge/pmd/lang/ast/SemanticErrorReporterTest.java index 90e2952100..c6ca31b805 100644 --- a/pmd-core/src/test/java/net/sourceforge/pmd/lang/ast/SemanticErrorReporterTest.java +++ b/pmd-core/src/test/java/net/sourceforge/pmd/lang/ast/SemanticErrorReporterTest.java @@ -45,7 +45,7 @@ public class SemanticErrorReporterTest { @Test public void testErrorLogging() { - SemanticErrorReporter reporter = SemanticErrorReporter.reportToLogger(mockReporter, mockLogger); + SemanticErrorReporter reporter = SemanticErrorReporter.reportToLogger(mockReporter); RootNode node = parseMockNode(reporter); assertFalse(reporter.hasError()); @@ -61,7 +61,7 @@ public class SemanticErrorReporterTest { @Test public void testEscaping() { - SemanticErrorReporter reporter = SemanticErrorReporter.reportToLogger(mockReporter, mockLogger); + SemanticErrorReporter reporter = SemanticErrorReporter.reportToLogger(mockReporter); RootNode node = parseMockNode(reporter); // this is a MessageFormat string diff --git a/pmd-html/src/main/java/net/sourceforge/pmd/lang/html/ast/HtmlTokenizer.java b/pmd-html/src/main/java/net/sourceforge/pmd/lang/html/ast/HtmlTokenizer.java index f99793cb55..94a3e7d205 100644 --- a/pmd-html/src/main/java/net/sourceforge/pmd/lang/html/ast/HtmlTokenizer.java +++ b/pmd-html/src/main/java/net/sourceforge/pmd/lang/html/ast/HtmlTokenizer.java @@ -4,9 +4,6 @@ package net.sourceforge.pmd.lang.html.ast; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - import net.sourceforge.pmd.cpd.SourceCode; import net.sourceforge.pmd.cpd.TokenEntry; import net.sourceforge.pmd.cpd.Tokenizer; @@ -17,7 +14,6 @@ import net.sourceforge.pmd.lang.ast.SemanticErrorReporter; import net.sourceforge.pmd.lang.html.HtmlLanguageModule; public class HtmlTokenizer implements Tokenizer { - private static final Logger LOG = LoggerFactory.getLogger(HtmlTokenizer.class); @Override public void tokenize(SourceCode sourceCode, Tokens tokenEntries) { @@ -25,7 +21,7 @@ public class HtmlTokenizer implements Tokenizer { LanguageRegistry.getLanguage(HtmlLanguageModule.NAME).getDefaultVersion(), sourceCode.getFileName(), sourceCode.getCodeBuffer().toString(), - SemanticErrorReporter.reportToLogger(LOG) + SemanticErrorReporter.noop() // todo ); HtmlParser parser = new HtmlParser(); diff --git a/pmd-java/src/test/java/net/sourceforge/pmd/lang/java/JavaParsingHelper.java b/pmd-java/src/test/java/net/sourceforge/pmd/lang/java/JavaParsingHelper.java index f6df0c19c9..3e2028b96e 100644 --- a/pmd-java/src/test/java/net/sourceforge/pmd/lang/java/JavaParsingHelper.java +++ b/pmd-java/src/test/java/net/sourceforge/pmd/lang/java/JavaParsingHelper.java @@ -125,7 +125,7 @@ public class JavaParsingHelper extends BaseParsingHelper Date: Sun, 15 May 2022 14:15:06 +0200 Subject: [PATCH 094/198] Remove info level of SemanticErrorReporter --- .../pmd/lang/ast/SemanticErrorReporter.java | 17 ----------------- .../sourceforge/pmd/processor/PmdRunnable.java | 2 +- 2 files changed, 1 insertion(+), 18 deletions(-) diff --git a/pmd-core/src/main/java/net/sourceforge/pmd/lang/ast/SemanticErrorReporter.java b/pmd-core/src/main/java/net/sourceforge/pmd/lang/ast/SemanticErrorReporter.java index 5d7da3ef77..9d5c96b9e5 100644 --- a/pmd-core/src/main/java/net/sourceforge/pmd/lang/ast/SemanticErrorReporter.java +++ b/pmd-core/src/main/java/net/sourceforge/pmd/lang/ast/SemanticErrorReporter.java @@ -19,18 +19,6 @@ public interface SemanticErrorReporter { // TODO use resource bundle keys instead of string messages. - /** - * Report an informational message at the given location. - * - * @param location Location where the message should be reported - * @param message Message (rendered using a {@link MessageFormat}) - * @param formatArgs Format arguments - */ - default void info(Node location, String message, Object... formatArgs) { - // noop - } - - /** * Report a warning at the given location. Warnings do not abort * the analysis. They are usually recoverable errors. They are used @@ -108,11 +96,6 @@ public interface SemanticErrorReporter { return fullMessage; } - @Override - public void info(Node location, String message, Object... formatArgs) { - logMessage(Level.INFO, location, message, formatArgs); - } - @Override public void warning(Node location, String message, Object... args) { logMessage(Level.WARN, location, message, args); diff --git a/pmd-core/src/main/java/net/sourceforge/pmd/processor/PmdRunnable.java b/pmd-core/src/main/java/net/sourceforge/pmd/processor/PmdRunnable.java index 667ac21f88..292461a225 100644 --- a/pmd-core/src/main/java/net/sourceforge/pmd/processor/PmdRunnable.java +++ b/pmd-core/src/main/java/net/sourceforge/pmd/processor/PmdRunnable.java @@ -149,7 +149,7 @@ abstract class PmdRunnable implements Runnable { RootNode rootNode = parse(parser, task); if (reporter.hasError()) { - reporter.info(rootNode, "Errors occurred in file, skipping rule analysis"); + configuration.getReporter().info("Errors occurred in file, skipping rule analysis: {0}", filename); return; } From e7590699563d96124f89af51ac06815d5a08b134 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9ment=20Fournier?= Date: Sun, 15 May 2022 14:23:35 +0200 Subject: [PATCH 095/198] Make semantic errors report processing errors --- .../pmd/lang/ast/SemanticErrorReporter.java | 37 ++++++++++++++----- .../pmd/processor/PmdRunnable.java | 8 ++-- .../lang/ast/SemanticErrorReporterTest.java | 8 ++-- .../pmd/processor/PmdRunnableTest.java | 8 +++- .../pmd/lang/java/JavaParsingHelper.java | 9 +++-- 5 files changed, 48 insertions(+), 22 deletions(-) diff --git a/pmd-core/src/main/java/net/sourceforge/pmd/lang/ast/SemanticErrorReporter.java b/pmd-core/src/main/java/net/sourceforge/pmd/lang/ast/SemanticErrorReporter.java index 9d5c96b9e5..88183eb65d 100644 --- a/pmd-core/src/main/java/net/sourceforge/pmd/lang/ast/SemanticErrorReporter.java +++ b/pmd-core/src/main/java/net/sourceforge/pmd/lang/ast/SemanticErrorReporter.java @@ -6,6 +6,7 @@ package net.sourceforge.pmd.lang.ast; import java.text.MessageFormat; +import org.checkerframework.checker.nullness.qual.Nullable; import org.slf4j.event.Level; import net.sourceforge.pmd.util.StringUtil; @@ -45,14 +46,17 @@ public interface SemanticErrorReporter { /** - * Returns true if at least one error has been reported. + * If {@link #error(Node, String, Object...)} has been called, return + * a semantic exception instance with the correct message. If it has been + * called more than once, return the first exception, possibly with suppressed + * exceptions for subsequent calls to {@link #error(Node, String, Object...)}. */ - boolean hasError(); + @Nullable SemanticException getFirstError(); static SemanticErrorReporter noop() { return new SemanticErrorReporter() { - private boolean hasError = false; + private SemanticException exception; @Override public void warning(Node location, String message, Object... formatArgs) { @@ -61,13 +65,18 @@ public interface SemanticErrorReporter { @Override public SemanticException error(Node location, String message, Object... formatArgs) { - hasError = true; - return new SemanticException(MessageFormat.format(message, formatArgs)); + SemanticException ex = new SemanticException(MessageFormat.format(message, formatArgs)); + if (this.exception == null) { + this.exception = ex; + } else { + this.exception.addSuppressed(ex); + } + return ex; } @Override - public boolean hasError() { - return hasError; + public @Nullable SemanticException getFirstError() { + return exception; } }; } @@ -81,6 +90,8 @@ public interface SemanticErrorReporter { return new SemanticErrorReporter() { private boolean hasError = false; + private SemanticException exception = null; + private String locPrefix(Node loc) { return "at " + loc.getAstInfo().getFileName() + " :" + loc.getBeginLine() + ":" + loc.getBeginColumn() + ": "; @@ -105,12 +116,18 @@ public interface SemanticErrorReporter { public SemanticException error(Node location, String message, Object... args) { hasError = true; String fullMessage = logMessage(Level.ERROR, location, message, args); - return new SemanticException(fullMessage); + SemanticException ex = new SemanticException(fullMessage); + if (this.exception == null) { + this.exception = ex; + } else { + this.exception.addSuppressed(ex); + } + return ex; } @Override - public boolean hasError() { - return hasError; + public @Nullable SemanticException getFirstError() { + return exception; } }; } diff --git a/pmd-core/src/main/java/net/sourceforge/pmd/processor/PmdRunnable.java b/pmd-core/src/main/java/net/sourceforge/pmd/processor/PmdRunnable.java index 292461a225..c86caaa29e 100644 --- a/pmd-core/src/main/java/net/sourceforge/pmd/processor/PmdRunnable.java +++ b/pmd-core/src/main/java/net/sourceforge/pmd/processor/PmdRunnable.java @@ -25,6 +25,7 @@ import net.sourceforge.pmd.lang.ast.Parser; import net.sourceforge.pmd.lang.ast.Parser.ParserTask; import net.sourceforge.pmd.lang.ast.RootNode; import net.sourceforge.pmd.lang.ast.SemanticErrorReporter; +import net.sourceforge.pmd.lang.ast.SemanticException; import net.sourceforge.pmd.reporting.FileAnalysisListener; import net.sourceforge.pmd.reporting.GlobalAnalysisListener; import net.sourceforge.pmd.util.datasource.DataSource; @@ -148,9 +149,10 @@ abstract class PmdRunnable implements Runnable { RootNode rootNode = parse(parser, task); - if (reporter.hasError()) { - configuration.getReporter().info("Errors occurred in file, skipping rule analysis: {0}", filename); - return; + SemanticException semanticError = reporter.getFirstError(); + if (semanticError != null) { + // cause a processing error to be reported and rule analysis to be skipped + throw semanticError; } ruleSets.apply(rootNode, listener); diff --git a/pmd-core/src/test/java/net/sourceforge/pmd/lang/ast/SemanticErrorReporterTest.java b/pmd-core/src/test/java/net/sourceforge/pmd/lang/ast/SemanticErrorReporterTest.java index c6ca31b805..b4c45d6f21 100644 --- a/pmd-core/src/test/java/net/sourceforge/pmd/lang/ast/SemanticErrorReporterTest.java +++ b/pmd-core/src/test/java/net/sourceforge/pmd/lang/ast/SemanticErrorReporterTest.java @@ -4,8 +4,8 @@ package net.sourceforge.pmd.lang.ast; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertTrue; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertNull; import static org.mockito.Mockito.contains; import static org.mockito.Mockito.eq; import static org.mockito.Mockito.mock; @@ -48,7 +48,7 @@ public class SemanticErrorReporterTest { SemanticErrorReporter reporter = SemanticErrorReporter.reportToLogger(mockReporter); RootNode node = parseMockNode(reporter); - assertFalse(reporter.hasError()); + assertNull(reporter.getFirstError()); String message = "an error occurred"; reporter.error(node, message); @@ -56,7 +56,7 @@ public class SemanticErrorReporterTest { verify(mockReporter).log(eq(Level.ERROR), contains(message)); verifyNoMoreInteractions(mockLogger); - assertTrue(reporter.hasError()); + assertNotNull(reporter.getFirstError()); } @Test diff --git a/pmd-core/src/test/java/net/sourceforge/pmd/processor/PmdRunnableTest.java b/pmd-core/src/test/java/net/sourceforge/pmd/processor/PmdRunnableTest.java index e6f8cde7e0..aa778a5cae 100644 --- a/pmd-core/src/test/java/net/sourceforge/pmd/processor/PmdRunnableTest.java +++ b/pmd-core/src/test/java/net/sourceforge/pmd/processor/PmdRunnableTest.java @@ -132,8 +132,11 @@ public class PmdRunnableTest { pmdRunnable.run(); - verify(reporter).log(eq(Level.INFO), contains("skipping rule analysis")); + verify(reporter, times(1)).log(eq(Level.ERROR), eq("at test.dummy :1:1: " + TEST_MESSAGE_SEMANTIC_ERROR)); verify(rule, never()).apply(Mockito.any(), Mockito.any()); + + reportBuilder.close(); + Assert.assertEquals(1, reportBuilder.getResult().getProcessingErrors().size()); } @Test @@ -144,6 +147,9 @@ public class PmdRunnableTest { verify(reporter, times(1)).log(eq(Level.ERROR), contains(TEST_MESSAGE_SEMANTIC_ERROR)); verify(rule, never()).apply(Mockito.any(), Mockito.any()); + + reportBuilder.close(); + Assert.assertEquals(1, reportBuilder.getResult().getProcessingErrors().size()); } public static void registerCustomVersions(BiConsumer addVersion) { diff --git a/pmd-java/src/test/java/net/sourceforge/pmd/lang/java/JavaParsingHelper.java b/pmd-java/src/test/java/net/sourceforge/pmd/lang/java/JavaParsingHelper.java index 3e2028b96e..0643500672 100644 --- a/pmd-java/src/test/java/net/sourceforge/pmd/lang/java/JavaParsingHelper.java +++ b/pmd-java/src/test/java/net/sourceforge/pmd/lang/java/JavaParsingHelper.java @@ -15,6 +15,7 @@ import java.util.Map; import org.apache.commons.lang3.StringUtils; import org.checkerframework.checker.nullness.qual.NonNull; +import org.checkerframework.checker.nullness.qual.Nullable; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -144,8 +145,8 @@ public class JavaParsingHelper extends BaseParsingHelper Date: Sun, 15 May 2022 14:31:16 +0200 Subject: [PATCH 096/198] Fix pmd warning --- .../net/sourceforge/pmd/lang/ast/SemanticErrorReporter.java | 2 -- 1 file changed, 2 deletions(-) diff --git a/pmd-core/src/main/java/net/sourceforge/pmd/lang/ast/SemanticErrorReporter.java b/pmd-core/src/main/java/net/sourceforge/pmd/lang/ast/SemanticErrorReporter.java index 88183eb65d..a3814820eb 100644 --- a/pmd-core/src/main/java/net/sourceforge/pmd/lang/ast/SemanticErrorReporter.java +++ b/pmd-core/src/main/java/net/sourceforge/pmd/lang/ast/SemanticErrorReporter.java @@ -88,7 +88,6 @@ public interface SemanticErrorReporter { */ static SemanticErrorReporter reportToLogger(MessageReporter reporter) { return new SemanticErrorReporter() { - private boolean hasError = false; private SemanticException exception = null; @@ -114,7 +113,6 @@ public interface SemanticErrorReporter { @Override public SemanticException error(Node location, String message, Object... args) { - hasError = true; String fullMessage = logMessage(Level.ERROR, location, message, args); SemanticException ex = new SemanticException(fullMessage); if (this.exception == null) { From 5ae11f4e8ac64307670b3371c9508bdf833e6465 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9ment=20Fournier?= Date: Sun, 15 May 2022 15:30:14 +0200 Subject: [PATCH 097/198] fix java tests --- .../pmd/lang/java/ast/TypeDisambiguationTest.kt | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/pmd-java/src/test/kotlin/net/sourceforge/pmd/lang/java/ast/TypeDisambiguationTest.kt b/pmd-java/src/test/kotlin/net/sourceforge/pmd/lang/java/ast/TypeDisambiguationTest.kt index c400d74f2e..3a7cd8ab47 100644 --- a/pmd-java/src/test/kotlin/net/sourceforge/pmd/lang/java/ast/TypeDisambiguationTest.kt +++ b/pmd-java/src/test/kotlin/net/sourceforge/pmd/lang/java/ast/TypeDisambiguationTest.kt @@ -157,12 +157,12 @@ class TypeDisambiguationTest : ParserTestSpec({ doTest("Ambiguous inner type should produce an error (ref in Foo)") { - val (_, args) = logger.errors[AMBIGUOUS_NAME_REFERENCE]?.first { it.first == refInFoo }!! + val (_, args) = logger.warnings[AMBIGUOUS_NAME_REFERENCE]?.first { it.first == refInFoo }!! args.map { it.toString() } shouldBe listOf("Mem", "p.Scratch.A.Mem", "p.Scratch.B.Mem") } doTest("Ambiguous inner type should produce an error (ref in Scratch)") { - val (_, args) = logger.errors[AMBIGUOUS_NAME_REFERENCE]?.first { it.first == refInScratch }!! + val (_, args) = logger.warnings[AMBIGUOUS_NAME_REFERENCE]?.first { it.first == refInScratch }!! args.map { it.toString() } shouldBe listOf("Mem", "p.Scratch.A.Mem", "p.Scratch.B.Mem") } @@ -206,14 +206,14 @@ class TypeDisambiguationTest : ParserTestSpec({ acu.descendants(ASTFieldDeclaration::class.java).map { it.typeNode as ASTClassOrInterfaceType }.toList() fun assertErrored(t: ASTClassOrInterfaceType, expected: Int, actual: Int) { - val errs = logger.errors[MALFORMED_GENERIC_TYPE]?.filter { it.first == t } + val errs = logger.warnings[MALFORMED_GENERIC_TYPE]?.filter { it.first == t } ?: emptyList() assertEquals(errs.size, 1, "`${t.text}` should have produced a single error") errs.single().second.toList() shouldBe listOf(expected, actual) } fun assertNoError(t: ASTClassOrInterfaceType) { - val err = logger.errors[MALFORMED_GENERIC_TYPE]?.firstOrNull { it.first == t } + val err = logger.warnings[MALFORMED_GENERIC_TYPE]?.firstOrNull { it.first == t } assertNull(err, "`${t.text}` should not have produced an error") } @@ -288,14 +288,14 @@ class TypeDisambiguationTest : ParserTestSpec({ acu.descendants(ASTAnnotation::class.java).map { it.typeNode }.toList() fun assertErrored(t: ASTClassOrInterfaceType) { - val errs = logger.errors[EXPECTED_ANNOTATION_TYPE]?.filter { it.first == t } + val errs = logger.warnings[EXPECTED_ANNOTATION_TYPE]?.filter { it.first == t } ?: emptyList() assertEquals(errs.size, 1, "`${t.text}` should have produced a single error") errs.single().second.toList() shouldBe emptyList() } fun assertNoError(t: ASTClassOrInterfaceType) { - val err = logger.errors[MALFORMED_GENERIC_TYPE]?.firstOrNull { it.first == t } + val err = logger.warnings[MALFORMED_GENERIC_TYPE]?.firstOrNull { it.first == t } assertNull(err, "`${t.text}` should not have produced an error") } From 7921e836b193df860a1866ac0415497711c4e531 Mon Sep 17 00:00:00 2001 From: Maikel Steneker Date: Mon, 16 May 2022 16:42:01 +0200 Subject: [PATCH 098/198] Add option to ignore C# attributes (annotations) --- .../java/net/sourceforge/pmd/cpd/GUI.java | 11 +- .../net/sourceforge/pmd/cpd/CsTokenizer.java | 45 +++- .../sourceforge/pmd/cpd/CsTokenizerTest.java | 21 +- .../pmd/lang/cs/cpd/testdata/attributes.cs | 42 ++++ .../pmd/lang/cs/cpd/testdata/attributes.txt | 229 ++++++++++++++++++ .../cs/cpd/testdata/attributes_ignored.txt | 109 +++++++++ 6 files changed, 441 insertions(+), 16 deletions(-) create mode 100644 pmd-cs/src/test/resources/net/sourceforge/pmd/lang/cs/cpd/testdata/attributes.cs create mode 100644 pmd-cs/src/test/resources/net/sourceforge/pmd/lang/cs/cpd/testdata/attributes.txt create mode 100644 pmd-cs/src/test/resources/net/sourceforge/pmd/lang/cs/cpd/testdata/attributes_ignored.txt diff --git a/pmd-core/src/main/java/net/sourceforge/pmd/cpd/GUI.java b/pmd-core/src/main/java/net/sourceforge/pmd/cpd/GUI.java index 540e972759..b970880aa0 100644 --- a/pmd-core/src/main/java/net/sourceforge/pmd/cpd/GUI.java +++ b/pmd-core/src/main/java/net/sourceforge/pmd/cpd/GUI.java @@ -147,7 +147,16 @@ public class GUI implements CPDListener { @Override public boolean canIgnoreAnnotations() { - return "java".equals(terseName); + if (terseName == null) { + return false; + } + switch (terseName) { + case "cs": + case "java": + return true; + default: + return false; + } } @Override diff --git a/pmd-cs/src/main/java/net/sourceforge/pmd/cpd/CsTokenizer.java b/pmd-cs/src/main/java/net/sourceforge/pmd/cpd/CsTokenizer.java index a48212290a..7a8cfd09f6 100644 --- a/pmd-cs/src/main/java/net/sourceforge/pmd/cpd/CsTokenizer.java +++ b/pmd-cs/src/main/java/net/sourceforge/pmd/cpd/CsTokenizer.java @@ -20,6 +20,7 @@ public class CsTokenizer extends AntlrTokenizer { private boolean ignoreUsings = false; private boolean ignoreLiteralSequences = false; + private boolean ignoreAttributes = false; /** * Sets the possible options for the C# tokenizer. @@ -27,19 +28,16 @@ public class CsTokenizer extends AntlrTokenizer { * @param properties the properties * @see #IGNORE_USINGS * @see #OPTION_IGNORE_LITERAL_SEQUENCES + * @see #IGNORE_ANNOTATIONS */ public void setProperties(Properties properties) { - ignoreUsings = Boolean.parseBoolean(properties.getProperty(IGNORE_USINGS, Boolean.FALSE.toString())); - ignoreLiteralSequences = Boolean.parseBoolean(properties.getProperty(OPTION_IGNORE_LITERAL_SEQUENCES, - Boolean.FALSE.toString())); + ignoreUsings = getBooleanProperty(properties, IGNORE_USINGS); + ignoreLiteralSequences = getBooleanProperty(properties, OPTION_IGNORE_LITERAL_SEQUENCES); + ignoreAttributes = getBooleanProperty(properties, IGNORE_ANNOTATIONS); } - public void setIgnoreUsings(boolean ignoreUsings) { - this.ignoreUsings = ignoreUsings; - } - - public void setIgnoreLiteralSequences(boolean ignoreLiteralSequences) { - this.ignoreLiteralSequences = ignoreLiteralSequences; + private boolean getBooleanProperty(final Properties properties, final String property) { + return Boolean.parseBoolean(properties.getProperty(property, Boolean.FALSE.toString())); } @Override @@ -50,7 +48,7 @@ public class CsTokenizer extends AntlrTokenizer { @Override protected AntlrTokenFilter getTokenFilter(final AntlrTokenManager tokenManager) { - return new CsTokenFilter(tokenManager, ignoreUsings, ignoreLiteralSequences); + return new CsTokenFilter(tokenManager, ignoreUsings, ignoreLiteralSequences, ignoreAttributes); } /** @@ -69,15 +67,18 @@ public class CsTokenizer extends AntlrTokenizer { private final boolean ignoreUsings; private final boolean ignoreLiteralSequences; + private final boolean ignoreAttributes; private boolean discardingUsings = false; private boolean discardingNL = false; + private boolean isDiscardingAttribute = false; private AntlrToken discardingLiteralsUntil = null; private boolean discardCurrent = false; - CsTokenFilter(final AntlrTokenManager tokenManager, boolean ignoreUsings, boolean ignoreLiteralSequences) { + CsTokenFilter(final AntlrTokenManager tokenManager, boolean ignoreUsings, boolean ignoreLiteralSequences, boolean ignoreAttributes) { super(tokenManager); this.ignoreUsings = ignoreUsings; this.ignoreLiteralSequences = ignoreLiteralSequences; + this.ignoreAttributes = ignoreAttributes; } @Override @@ -90,6 +91,7 @@ public class CsTokenizer extends AntlrTokenizer { discardCurrent = false; skipUsingDirectives(currentToken, remainingTokens); skipLiteralSequences(currentToken, remainingTokens); + skipAttributes(currentToken); } private void skipUsingDirectives(final AntlrToken currentToken, final Iterable remainingTokens) { @@ -166,6 +168,25 @@ public class CsTokenizer extends AntlrTokenizer { discardingNL = currentToken.getKind() == CSharpLexer.NL; } + private void skipAttributes(final AntlrToken currentToken) { + if (ignoreAttributes) { + switch (currentToken.getKind()) { + case CSharpLexer.OPEN_BRACKET: + // Start of an attribute. + isDiscardingAttribute = true; + break; + case CSharpLexer.CLOSE_BRACKET: + // End of an attribute. + isDiscardingAttribute = false; + discardCurrent = true; + break; + default: + // Skip any other token. + break; + } + } + } + private void skipLiteralSequences(final AntlrToken currentToken, final Iterable remainingTokens) { if (ignoreLiteralSequences) { final int type = currentToken.getKind(); @@ -221,7 +242,7 @@ public class CsTokenizer extends AntlrTokenizer { @Override protected boolean isLanguageSpecificDiscarding() { - return discardingUsings || discardingNL || isDiscardingLiterals() || discardCurrent; + return discardingUsings || discardingNL || isDiscardingAttribute || isDiscardingLiterals() || discardCurrent; } } } diff --git a/pmd-cs/src/test/java/net/sourceforge/pmd/cpd/CsTokenizerTest.java b/pmd-cs/src/test/java/net/sourceforge/pmd/cpd/CsTokenizerTest.java index 63c9cd5aee..d05797d726 100644 --- a/pmd-cs/src/test/java/net/sourceforge/pmd/cpd/CsTokenizerTest.java +++ b/pmd-cs/src/test/java/net/sourceforge/pmd/cpd/CsTokenizerTest.java @@ -105,18 +105,33 @@ public class CsTokenizerTest extends CpdTextComparisonTest { doTest("csharp7And8Additions"); } + @Test + public void testAttributesAreNotIgnored() { + doTest("attributes"); + } + + @Test + public void testAttributesAreIgnored() { + doTest("attributes", "_ignored", skipAttributes()); + } + private Properties ignoreUsings() { - return properties(true, false); + return properties(true, false, false); } private Properties skipLiteralSequences() { - return properties(false, true); + return properties(false, true, false); } - private Properties properties(boolean ignoreUsings, boolean ignoreLiteralSequences) { + private Properties skipAttributes() { + return properties(false, false, true); + } + + private Properties properties(boolean ignoreUsings, boolean ignoreLiteralSequences, boolean ignoreAttributes) { Properties properties = new Properties(); properties.setProperty(Tokenizer.IGNORE_USINGS, Boolean.toString(ignoreUsings)); properties.setProperty(Tokenizer.OPTION_IGNORE_LITERAL_SEQUENCES, Boolean.toString(ignoreLiteralSequences)); + properties.setProperty(Tokenizer.IGNORE_ANNOTATIONS, Boolean.toString(ignoreAttributes)); return properties; } } diff --git a/pmd-cs/src/test/resources/net/sourceforge/pmd/lang/cs/cpd/testdata/attributes.cs b/pmd-cs/src/test/resources/net/sourceforge/pmd/lang/cs/cpd/testdata/attributes.cs new file mode 100644 index 0000000000..811e151362 --- /dev/null +++ b/pmd-cs/src/test/resources/net/sourceforge/pmd/lang/cs/cpd/testdata/attributes.cs @@ -0,0 +1,42 @@ +[Serializable] +public class SampleClass +{ + // Objects of this type can be serialized. +} + +[System.Runtime.InteropServices.DllImport("user32.dll")] +extern static void SampleMethod(); + +void MethodA([In][Out] ref double x) { } +void MethodB([Out][In] ref double x) { } +void MethodC([In, Out] ref double x) { } + +[Conditional("DEBUG"), Conditional("TEST1")] +void TraceMethod() +{ + // ... +} + +[DllImport("user32.dll")] +[DllImport("user32.dll", SetLastError=false, ExactSpelling=false)] +[DllImport("user32.dll", ExactSpelling=false, SetLastError=false)] + +using System; +using System.Reflection; +[assembly: AssemblyTitleAttribute("Production assembly 4")] +[module: CLSCompliant(true)] + +// default: applies to method +[ValidatedContract] +int Method1() { return 0; } + +// applies to method +[method: ValidatedContract] +int Method2() { return 0; } + +// applies to parameter +int Method3([ValidatedContract] string contract) { return 0; } + +// applies to return value +[return: ValidatedContract] +int Method4() { return 0; } \ No newline at end of file diff --git a/pmd-cs/src/test/resources/net/sourceforge/pmd/lang/cs/cpd/testdata/attributes.txt b/pmd-cs/src/test/resources/net/sourceforge/pmd/lang/cs/cpd/testdata/attributes.txt new file mode 100644 index 0000000000..403064af38 --- /dev/null +++ b/pmd-cs/src/test/resources/net/sourceforge/pmd/lang/cs/cpd/testdata/attributes.txt @@ -0,0 +1,229 @@ + [Image] or [Truncated image[ Bcol Ecol +L1 + [\[] 1 1 + [Serializable] 2 13 + [\]] 14 14 +L2 + [public] 1 6 + [class] 8 12 + [SampleClass] 14 24 +L3 + [{] 1 1 +L5 + [}] 1 1 +L7 + [\[] 1 1 + [System] 2 7 + [.] 8 8 + [Runtime] 9 15 + [.] 16 16 + [InteropServices] 17 31 + [.] 32 32 + [DllImport] 33 41 + [(] 42 42 + ["user32.dll"] 43 54 + [)] 55 55 + [\]] 56 56 +L8 + [extern] 1 6 + [static] 8 13 + [void] 15 18 + [SampleMethod] 20 31 + [(] 32 32 + [)] 33 33 + [;] 34 34 +L10 + [void] 1 4 + [MethodA] 6 12 + [(] 13 13 + [\[] 14 14 + [In] 15 16 + [\]] 17 17 + [\[] 18 18 + [Out] 19 21 + [\]] 22 22 + [ref] 24 26 + [double] 28 33 + [x] 35 35 + [)] 36 36 + [{] 38 38 + [}] 40 40 +L11 + [void] 1 4 + [MethodB] 6 12 + [(] 13 13 + [\[] 14 14 + [Out] 15 17 + [\]] 18 18 + [\[] 19 19 + [In] 20 21 + [\]] 22 22 + [ref] 24 26 + [double] 28 33 + [x] 35 35 + [)] 36 36 + [{] 38 38 + [}] 40 40 +L12 + [void] 1 4 + [MethodC] 6 12 + [(] 13 13 + [\[] 14 14 + [In] 15 16 + [,] 17 17 + [Out] 19 21 + [\]] 22 22 + [ref] 24 26 + [double] 28 33 + [x] 35 35 + [)] 36 36 + [{] 38 38 + [}] 40 40 +L14 + [\[] 1 1 + [Conditional] 2 12 + [(] 13 13 + ["DEBUG"] 14 20 + [)] 21 21 + [,] 22 22 + [Conditional] 24 34 + [(] 35 35 + ["TEST1"] 36 42 + [)] 43 43 + [\]] 44 44 +L15 + [void] 1 4 + [TraceMethod] 6 16 + [(] 17 17 + [)] 18 18 +L16 + [{] 1 1 +L18 + [}] 1 1 +L20 + [\[] 1 1 + [DllImport] 2 10 + [(] 11 11 + ["user32.dll"] 12 23 + [)] 24 24 + [\]] 25 25 +L21 + [\[] 1 1 + [DllImport] 2 10 + [(] 11 11 + ["user32.dll"] 12 23 + [,] 24 24 + [SetLastError] 26 37 + [=] 38 38 + [false] 39 43 + [,] 44 44 + [ExactSpelling] 46 58 + [=] 59 59 + [false] 60 64 + [)] 65 65 + [\]] 66 66 +L22 + [\[] 1 1 + [DllImport] 2 10 + [(] 11 11 + ["user32.dll"] 12 23 + [,] 24 24 + [ExactSpelling] 26 38 + [=] 39 39 + [false] 40 44 + [,] 45 45 + [SetLastError] 47 58 + [=] 59 59 + [false] 60 64 + [)] 65 65 + [\]] 66 66 +L24 + [using] 1 5 + [System] 7 12 + [;] 13 13 +L25 + [using] 1 5 + [System] 7 12 + [.] 13 13 + [Reflection] 14 23 + [;] 24 24 +L26 + [\[] 1 1 + [assembly] 2 9 + [:] 10 10 + [AssemblyTitleAttribute] 12 33 + [(] 34 34 + ["Production assembly 4"] 35 57 + [)] 58 58 + [\]] 59 59 +L27 + [\[] 1 1 + [module] 2 7 + [:] 8 8 + [CLSCompliant] 10 21 + [(] 22 22 + [true] 23 26 + [)] 27 27 + [\]] 28 28 +L30 + [\[] 1 1 + [ValidatedContract] 2 18 + [\]] 19 19 +L31 + [int] 1 3 + [Method1] 5 11 + [(] 12 12 + [)] 13 13 + [{] 15 15 + [return] 17 22 + [0] 24 24 + [;] 25 25 + [}] 27 27 +L34 + [\[] 1 1 + [method] 2 7 + [:] 8 8 + [ValidatedContract] 10 26 + [\]] 27 27 +L35 + [int] 1 3 + [Method2] 5 11 + [(] 12 12 + [)] 13 13 + [{] 15 15 + [return] 17 22 + [0] 24 24 + [;] 25 25 + [}] 27 27 +L38 + [int] 1 3 + [Method3] 5 11 + [(] 12 12 + [\[] 13 13 + [ValidatedContract] 14 30 + [\]] 31 31 + [string] 33 38 + [contract] 40 47 + [)] 48 48 + [{] 50 50 + [return] 52 57 + [0] 59 59 + [;] 60 60 + [}] 62 62 +L41 + [\[] 1 1 + [return] 2 7 + [:] 8 8 + [ValidatedContract] 10 26 + [\]] 27 27 +L42 + [int] 1 3 + [Method4] 5 11 + [(] 12 12 + [)] 13 13 + [{] 15 15 + [return] 17 22 + [0] 24 24 + [;] 25 25 + [}] 27 27 +EOF diff --git a/pmd-cs/src/test/resources/net/sourceforge/pmd/lang/cs/cpd/testdata/attributes_ignored.txt b/pmd-cs/src/test/resources/net/sourceforge/pmd/lang/cs/cpd/testdata/attributes_ignored.txt new file mode 100644 index 0000000000..0796c4384c --- /dev/null +++ b/pmd-cs/src/test/resources/net/sourceforge/pmd/lang/cs/cpd/testdata/attributes_ignored.txt @@ -0,0 +1,109 @@ + [Image] or [Truncated image[ Bcol Ecol +L2 + [public] 1 6 + [class] 8 12 + [SampleClass] 14 24 +L3 + [{] 1 1 +L5 + [}] 1 1 +L8 + [extern] 1 6 + [static] 8 13 + [void] 15 18 + [SampleMethod] 20 31 + [(] 32 32 + [)] 33 33 + [;] 34 34 +L10 + [void] 1 4 + [MethodA] 6 12 + [(] 13 13 + [ref] 24 26 + [double] 28 33 + [x] 35 35 + [)] 36 36 + [{] 38 38 + [}] 40 40 +L11 + [void] 1 4 + [MethodB] 6 12 + [(] 13 13 + [ref] 24 26 + [double] 28 33 + [x] 35 35 + [)] 36 36 + [{] 38 38 + [}] 40 40 +L12 + [void] 1 4 + [MethodC] 6 12 + [(] 13 13 + [ref] 24 26 + [double] 28 33 + [x] 35 35 + [)] 36 36 + [{] 38 38 + [}] 40 40 +L15 + [void] 1 4 + [TraceMethod] 6 16 + [(] 17 17 + [)] 18 18 +L16 + [{] 1 1 +L18 + [}] 1 1 +L24 + [using] 1 5 + [System] 7 12 + [;] 13 13 +L25 + [using] 1 5 + [System] 7 12 + [.] 13 13 + [Reflection] 14 23 + [;] 24 24 +L31 + [int] 1 3 + [Method1] 5 11 + [(] 12 12 + [)] 13 13 + [{] 15 15 + [return] 17 22 + [0] 24 24 + [;] 25 25 + [}] 27 27 +L35 + [int] 1 3 + [Method2] 5 11 + [(] 12 12 + [)] 13 13 + [{] 15 15 + [return] 17 22 + [0] 24 24 + [;] 25 25 + [}] 27 27 +L38 + [int] 1 3 + [Method3] 5 11 + [(] 12 12 + [string] 33 38 + [contract] 40 47 + [)] 48 48 + [{] 50 50 + [return] 52 57 + [0] 59 59 + [;] 60 60 + [}] 62 62 +L42 + [int] 1 3 + [Method4] 5 11 + [(] 12 12 + [)] 13 13 + [{] 15 15 + [return] 17 22 + [0] 24 24 + [;] 25 25 + [}] 27 27 +EOF From fa415832543f6f8f7e18825194a76f15262eaf63 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9ment=20Fournier?= Date: Tue, 17 May 2022 21:31:43 +0200 Subject: [PATCH 099/198] Fix tests --- docs/pages/release_notes.md | 2 +- .../main/java/net/sourceforge/pmd/RuleSetReferenceId.java | 3 +++ .../src/test/java/net/sourceforge/pmd/cli/CLITest.java | 8 ++++---- 3 files changed, 8 insertions(+), 5 deletions(-) diff --git a/docs/pages/release_notes.md b/docs/pages/release_notes.md index e8339a5c95..35baaadd48 100644 --- a/docs/pages/release_notes.md +++ b/docs/pages/release_notes.md @@ -28,7 +28,7 @@ when used on the CLI or in a ruleset XML file: - `-`, eg `java-basic`, which resolves to `rulesets/java/basic.xml` - the internal release number, eg `600`, which resolves to `rulesets/releases/600.xml` -Use the explicit forms of these references +Use the explicit forms of these references to be compatible with PMD 7. #### Deprecated API diff --git a/pmd-core/src/main/java/net/sourceforge/pmd/RuleSetReferenceId.java b/pmd-core/src/main/java/net/sourceforge/pmd/RuleSetReferenceId.java index 79ef421fe1..82028f9993 100644 --- a/pmd-core/src/main/java/net/sourceforge/pmd/RuleSetReferenceId.java +++ b/pmd-core/src/main/java/net/sourceforge/pmd/RuleSetReferenceId.java @@ -77,6 +77,9 @@ import net.sourceforge.pmd.util.ResourceLoader; @InternalApi public class RuleSetReferenceId { + // todo this class has issues... What is even an "external" ruleset? + // terminology and API should be clarified. + // use the logger of RuleSetFactory, because the warnings conceptually come from there. private static final Logger LOG = Logger.getLogger(RuleSetFactory.class.getName()); diff --git a/pmd-java/src/test/java/net/sourceforge/pmd/cli/CLITest.java b/pmd-java/src/test/java/net/sourceforge/pmd/cli/CLITest.java index 22bcfca35e..defff23883 100644 --- a/pmd-java/src/test/java/net/sourceforge/pmd/cli/CLITest.java +++ b/pmd-java/src/test/java/net/sourceforge/pmd/cli/CLITest.java @@ -80,8 +80,8 @@ public class CLITest extends BaseCLITest { public void testWrongRuleset() { String[] args = { "-d", SOURCE_FOLDER, "-f", "text", "-R", "category/java/designn.xml", }; String log = runTest(StatusCode.ERROR, args); - assertThat(log, containsString("Can't find resource 'category/java/designn.xml' for rule 'null'." - + " Make sure the resource is a valid file")); + assertThat(log, containsString("Cannot resolve rule/ruleset reference " + + "'category/java/designn.xml'")); } /** @@ -91,8 +91,8 @@ public class CLITest extends BaseCLITest { public void testWrongRulesetWithRulename() { String[] args = { "-d", SOURCE_FOLDER, "-f", "text", "-R", "category/java/designn.xml/UseCollectionIsEmpty", }; String log = runTest(StatusCode.ERROR, args); - assertThat(log, containsString("Can't find resource 'category/java/designn.xml' for rule " - + "'UseCollectionIsEmpty'.")); + assertThat(log, containsString("Cannot resolve rule/ruleset reference" + + " 'category/java/designn.xml/UseCollectionIsEmpty'")); } /** From c53a64c688d0d6d9811df886ea0bb24ece64f6e0 Mon Sep 17 00:00:00 2001 From: Andreas Dangel Date: Fri, 20 May 2022 08:51:52 +0200 Subject: [PATCH 100/198] Update pmd-core/src/main/java/net/sourceforge/pmd/util/IOUtil.java MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Clément Fournier --- .../src/main/java/net/sourceforge/pmd/util/IOUtil.java | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/pmd-core/src/main/java/net/sourceforge/pmd/util/IOUtil.java b/pmd-core/src/main/java/net/sourceforge/pmd/util/IOUtil.java index 881bc7efa2..ebe98f9dbe 100644 --- a/pmd-core/src/main/java/net/sourceforge/pmd/util/IOUtil.java +++ b/pmd-core/src/main/java/net/sourceforge/pmd/util/IOUtil.java @@ -180,6 +180,13 @@ public final class IOUtil { } } + + // The following methods are taken from Apache Commons IO. + // The dependency was removed from PMD 6 because it had a security issue, + // and upgrading was not possible without upgrading to Java 8. + // See https://github.com/pmd/pmd/pull/3968 + // TODO PMD 7: consider bringing back commons-io and cleaning this class up. + public static void closeQuietly(Closeable closeable) { try { closeable.close(); From 2daa3381b4f646ca0b862998d12bb598ebe62a34 Mon Sep 17 00:00:00 2001 From: Andreas Dangel Date: Fri, 20 May 2022 09:06:29 +0200 Subject: [PATCH 101/198] [doc] Update release notes (#3874, #3964) --- docs/pages/release_notes.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/docs/pages/release_notes.md b/docs/pages/release_notes.md index c31a705241..b8bd840b4c 100644 --- a/docs/pages/release_notes.md +++ b/docs/pages/release_notes.md @@ -16,6 +16,8 @@ This is a {{ site.pmd.release_type }} release. ### Fixed Issues +* java-design + * [#3874](https://github.com/pmd/pmd/issues/3874): \[java] ImmutableField reports fields annotated with @Autowired (Spring) and @Mock (Mockito) * javascript * [#3948](https://github.com/pmd/pmd/issues/3948): \[js] Invalid operator error for method property in object literal @@ -23,5 +25,7 @@ This is a {{ site.pmd.release_type }} release. ### External Contributions +* [#3964](https://github.com/pmd/pmd/pull/3964): \[java] Fix #3874 - ImmutableField: fix mockito/spring false positives - [@lukelukes](https://github.com/lukelukes) + {% endtocmaker %} From 8a99dee9117769486c71c4f05e7beda8f865b488 Mon Sep 17 00:00:00 2001 From: Andreas Dangel Date: Fri, 20 May 2022 09:08:05 +0200 Subject: [PATCH 102/198] [java] Update test case (ImmutableField) --- .../pmd/lang/java/rule/design/xml/ImmutableField.xml | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/pmd-java/src/test/resources/net/sourceforge/pmd/lang/java/rule/design/xml/ImmutableField.xml b/pmd-java/src/test/resources/net/sourceforge/pmd/lang/java/rule/design/xml/ImmutableField.xml index 2b645e9839..b6f6bfb687 100644 --- a/pmd-java/src/test/resources/net/sourceforge/pmd/lang/java/rule/design/xml/ImmutableField.xml +++ b/pmd-java/src/test/resources/net/sourceforge/pmd/lang/java/rule/design/xml/ImmutableField.xml @@ -574,7 +574,7 @@ public class ExampleImmutableField { - #3874 [java] ImmutableField - false positive when using field setter annotations + #3874 [java] ImmutableField reports fields annotated with @Autowired (Spring) and @Mock (Mockito) 0 From d9fce6107e8228fd022e495bb61f67fc36245f75 Mon Sep 17 00:00:00 2001 From: Andreas Dangel Date: Fri, 20 May 2022 09:26:11 +0200 Subject: [PATCH 103/198] Add @lukelukes as a contributor --- .all-contributorsrc | 9 +++++++++ docs/pages/pmd/projectdocs/credits.md | 25 +++++++++++++------------ 2 files changed, 22 insertions(+), 12 deletions(-) diff --git a/.all-contributorsrc b/.all-contributorsrc index dcac68bf60..f5d880797e 100644 --- a/.all-contributorsrc +++ b/.all-contributorsrc @@ -6639,6 +6639,15 @@ "contributions": [ "code" ] + }, + { + "login": "lukelukes", + "name": "lukelukes", + "avatar_url": "https://avatars.githubusercontent.com/u/45536418?v=4", + "profile": "https://github.com/lukelukes", + "contributions": [ + "code" + ] } ], "contributorsPerLine": 7, diff --git a/docs/pages/pmd/projectdocs/credits.md b/docs/pages/pmd/projectdocs/credits.md index 3f6b6213cf..b2efb5841c 100644 --- a/docs/pages/pmd/projectdocs/credits.md +++ b/docs/pages/pmd/projectdocs/credits.md @@ -835,112 +835,113 @@ Thanks goes to these wonderful people ([emoji key](https://allcontributors.org/d
lpeddy

🐛
lujiefsi

💻 +
lukelukes

💻
lyriccoder

🐛
marcelmore

🐛
matchbox

🐛
matthiaskraaz

🐛 -
meandonlyme

🐛 +
meandonlyme

🐛
mikesive

🐛
milossesic

🐛
mriddell95

🐛
mrlzh

🐛
msloan

🐛
mucharlaravalika

🐛 -
mvenneman

🐛 +
mvenneman

🐛
nareshl119

🐛
nicolas-harraudeau-sonarsource

🐛
noerremark

🐛
novsirion

🐛
oggboy

🐛
oinume

🐛 -
orimarko

💻 🐛 +
orimarko

💻 🐛
pallavi agarwal

🐛
parksungrin

🐛
patpatpat123

🐛
patriksevallius

🐛
pbrajesh1

🐛
phoenix384

🐛 -
piotrszymanski-sc

💻 +
piotrszymanski-sc

💻
plan3d

🐛
poojasix

🐛
prabhushrikant

🐛
pujitha8783

🐛
r-r-a-j

🐛
raghujayjunk

🐛 -
rajeshveera

🐛 +
rajeshveera

🐛
rajeswarreddy88

🐛
recdevs

🐛
reudismam

💻 🐛
rijkt

🐛
rillig-tk

🐛
rmohan20

💻 🐛 -
rxmicro

🐛 +
rxmicro

🐛
ryan-gustafson

💻 🐛
sabi0

🐛
scais

🐛
sebbASF

🐛
sergeygorbaty

💻
shilko2013

🐛 -
simeonKondr

🐛 +
simeonKondr

🐛
snajberk

🐛
sniperrifle2004

🐛
snuyanzin

🐛 💻
sratz

🐛
stonio

🐛
sturton

💻 🐛 -
sudharmohan

🐛 +
sudharmohan

🐛
suruchidawar

🐛
svenfinitiv

🐛
tashiscool

🐛
test-git-hook

🐛
testation21

💻 🐛
thanosa

🐛 -
tiandiyixian

🐛 +
tiandiyixian

🐛
tobwoerk

🐛
tprouvot

🐛
trentchilders

🐛
triandicAnt

🐛
trishul14

🐛
tsui

🐛 -
winhkey

🐛 +
winhkey

🐛
witherspore

🐛
wjljack

🐛
wuchiuwong

🐛
xingsong

🐛
xioayuge

🐛
xnYi9wRezm

💻 🐛 -
xuanuy

🐛 +
xuanuy

🐛
xyf0921

🐛
yalechen-cyw3

🐛
yasuharu-sato

🐛
zenglian

🐛
zgrzyt93

💻 🐛
zh3ng

🐛 -
zt_soft

🐛 +
zt_soft

🐛
ztt79

🐛
zzzzfeng

🐛
Árpád Magosányi

🐛 From 91328436a01f33decb822f0bff10a0ef9ca19d31 Mon Sep 17 00:00:00 2001 From: Maikel Steneker Date: Fri, 20 May 2022 09:35:53 +0200 Subject: [PATCH 104/198] Clarify documentation on `--ignore-annotations` CLI option --- docs/pages/pmd/userdocs/cpd/cpd.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/pages/pmd/userdocs/cpd/cpd.md b/docs/pages/pmd/userdocs/cpd/cpd.md index dc4577e41d..d909eb4f2f 100644 --- a/docs/pages/pmd/userdocs/cpd/cpd.md +++ b/docs/pages/pmd/userdocs/cpd/cpd.md @@ -112,9 +112,9 @@ Novice as much as advanced readers may want to [read on on Refactoring Guru](htt languages="Java" %} {% include custom/cli_option_row.html options="--ignore-annotations" - description="Ignore language annotations when comparing text" + description="Ignore language annotations (Java) or attributes (C#) when comparing text" default="false" - languages="Java" + languages="C#, Java" %} {% include custom/cli_option_row.html options="--ignore-literal-sequences" description="Ignore sequences of literals (common e.g. in list initializers)" From 77369804755c5e328c4082744c755391c58fc0c4 Mon Sep 17 00:00:00 2001 From: Andreas Dangel Date: Fri, 20 May 2022 09:51:45 +0200 Subject: [PATCH 105/198] Apply suggestions from code review MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Clément Fournier --- .../sourceforge/pmd/lang/ast/xpath/saxon/ElementNode.java | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/pmd-core/src/main/java/net/sourceforge/pmd/lang/ast/xpath/saxon/ElementNode.java b/pmd-core/src/main/java/net/sourceforge/pmd/lang/ast/xpath/saxon/ElementNode.java index 702e6605d4..4568a28d35 100644 --- a/pmd-core/src/main/java/net/sourceforge/pmd/lang/ast/xpath/saxon/ElementNode.java +++ b/pmd-core/src/main/java/net/sourceforge/pmd/lang/ast/xpath/saxon/ElementNode.java @@ -81,6 +81,9 @@ public class ElementNode extends BaseNodeInfo implements AstNodeOwner { } private static int determineType(Node node) { + // As of PMD 6.48.0, only the experimental HTML module uses this naming + // convention to identify non-element nodes. + // TODO PMD 7: maybe generalize this to other languages String name = node.getXPathNodeName(); if ("#text".equals(name)) { return Type.TEXT; @@ -158,7 +161,7 @@ public class ElementNode extends BaseNodeInfo implements AstNodeOwner { @Override public String getStringValue() { - if (determineType(getUnderlyingNode()) == Type.TEXT) { + if (getNodeKind() == Type.TEXT || getNodeKind() == Type.COMMENT) { return getUnderlyingNode().getImage(); } return ""; From 85095f19d3a60f233d4313059d7a8c0aebd5ad0b Mon Sep 17 00:00:00 2001 From: Andreas Dangel Date: Fri, 20 May 2022 09:54:48 +0200 Subject: [PATCH 106/198] [html] Added test case to verify #text doesn't find text nodes anymore --- .../net/sourceforge/pmd/lang/html/HtmlXPathRuleTest.java | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/pmd-html/src/test/java/net/sourceforge/pmd/lang/html/HtmlXPathRuleTest.java b/pmd-html/src/test/java/net/sourceforge/pmd/lang/html/HtmlXPathRuleTest.java index 1a6272dab8..404b110251 100644 --- a/pmd-html/src/test/java/net/sourceforge/pmd/lang/html/HtmlXPathRuleTest.java +++ b/pmd-html/src/test/java/net/sourceforge/pmd/lang/html/HtmlXPathRuleTest.java @@ -42,6 +42,14 @@ public class HtmlXPathRuleTest { Assert.assertEquals(3, report.getViolations().get(0).getBeginLine()); } + @Test + public void selectTextNodeByNodeNameShouldNotWork() { + String xpath = "//*[local-name() = '#text'][contains(@Text, '{ ')]"; + + Report report = runXPath(LIGHTNING_WEB_COMPONENT, xpath); + Assert.assertEquals(0, report.getViolations().size()); + } + @Test public void verifyTextNodeName() { ASTHtmlDocument document = HtmlParsingHelper.DEFAULT.parse("

foobar

"); From 1a596693fdf37b7289bc085c332c822c299db115 Mon Sep 17 00:00:00 2001 From: Andreas Dangel Date: Fri, 20 May 2022 09:56:49 +0200 Subject: [PATCH 107/198] [html] Added test case to verify #text doesn't find text nodes anymore --- .../java/net/sourceforge/pmd/lang/html/HtmlXPathRuleTest.java | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/pmd-html/src/test/java/net/sourceforge/pmd/lang/html/HtmlXPathRuleTest.java b/pmd-html/src/test/java/net/sourceforge/pmd/lang/html/HtmlXPathRuleTest.java index 404b110251..1c9f81b1ca 100644 --- a/pmd-html/src/test/java/net/sourceforge/pmd/lang/html/HtmlXPathRuleTest.java +++ b/pmd-html/src/test/java/net/sourceforge/pmd/lang/html/HtmlXPathRuleTest.java @@ -44,8 +44,7 @@ public class HtmlXPathRuleTest { @Test public void selectTextNodeByNodeNameShouldNotWork() { - String xpath = "//*[local-name() = '#text'][contains(@Text, '{ ')]"; - + String xpath = "//*[local-name() = '#text']"; Report report = runXPath(LIGHTNING_WEB_COMPONENT, xpath); Assert.assertEquals(0, report.getViolations().size()); } From 380d81ca8f8de79060555c5832d4207c1fdc66e8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9ment=20Fournier?= Date: Fri, 20 May 2022 10:24:24 +0200 Subject: [PATCH 108/198] Add todo comment Co-authored-by: Andreas Dangel --- pmd-core/src/main/java/net/sourceforge/pmd/RuleSetFactory.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pmd-core/src/main/java/net/sourceforge/pmd/RuleSetFactory.java b/pmd-core/src/main/java/net/sourceforge/pmd/RuleSetFactory.java index 3ae70c6dbe..196eaa8c2e 100644 --- a/pmd-core/src/main/java/net/sourceforge/pmd/RuleSetFactory.java +++ b/pmd-core/src/main/java/net/sourceforge/pmd/RuleSetFactory.java @@ -763,7 +763,7 @@ public class RuleSetFactory { * @return {@code true} if the ruleName exists */ private boolean containsRule(RuleSetReferenceId ruleSetReferenceId, String ruleName) { - // unbelievable... + // TODO: avoid reloading the ruleset once again boolean found = false; try (InputStream ruleSet = ruleSetReferenceId.getInputStream(resourceLoader)) { DocumentBuilder builder = createDocumentBuilder(); From fd7cae278e35a36719ae867d3e065b18a50c1336 Mon Sep 17 00:00:00 2001 From: Andreas Dangel Date: Fri, 20 May 2022 14:24:42 +0200 Subject: [PATCH 109/198] [doc] Update release notes (#3955) --- docs/pages/release_notes.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/docs/pages/release_notes.md b/docs/pages/release_notes.md index c31a705241..d565716926 100644 --- a/docs/pages/release_notes.md +++ b/docs/pages/release_notes.md @@ -16,6 +16,8 @@ This is a {{ site.pmd.release_type }} release. ### Fixed Issues +* html + * [#3955](https://github.com/pmd/pmd/pull/3955): \[html] Improvements for handling text and comment nodes * javascript * [#3948](https://github.com/pmd/pmd/issues/3948): \[js] Invalid operator error for method property in object literal From 26f6682a8b467ec766fb7b1710ab2a9f4cec114a Mon Sep 17 00:00:00 2001 From: Andreas Dangel Date: Fri, 20 May 2022 14:58:56 +0200 Subject: [PATCH 110/198] Fix build --- pmd-core/src/main/java/net/sourceforge/pmd/PMDConfiguration.java | 1 + 1 file changed, 1 insertion(+) diff --git a/pmd-core/src/main/java/net/sourceforge/pmd/PMDConfiguration.java b/pmd-core/src/main/java/net/sourceforge/pmd/PMDConfiguration.java index d53bff721d..13e1a87606 100644 --- a/pmd-core/src/main/java/net/sourceforge/pmd/PMDConfiguration.java +++ b/pmd-core/src/main/java/net/sourceforge/pmd/PMDConfiguration.java @@ -13,6 +13,7 @@ import java.util.List; import java.util.Objects; import java.util.Properties; +import org.apache.commons.lang3.StringUtils; import org.checkerframework.checker.nullness.qual.NonNull; import org.checkerframework.checker.nullness.qual.Nullable; From 01c48e1ca7686fec520a687d30b8bb2e74b09ce6 Mon Sep 17 00:00:00 2001 From: Andreas Dangel Date: Thu, 26 May 2022 10:26:03 +0200 Subject: [PATCH 111/198] [doc] Update release notes (#3960) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Clément Fournier --- docs/pages/release_notes.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/pages/release_notes.md b/docs/pages/release_notes.md index fb3f28f11f..2c7c511a92 100644 --- a/docs/pages/release_notes.md +++ b/docs/pages/release_notes.md @@ -26,7 +26,7 @@ For instance, the above can be written ```shell pmd -d src/*/java -R rset*.xml ``` -Please use theses new forms instead of using comma-separated list as argument to these options. +Please use theses new forms instead of using comma-separated lists as argument to these options. ### Fixed Issues From aef06d4b3a763d3a41f56111c2055554a464003b Mon Sep 17 00:00:00 2001 From: Andreas Dangel Date: Thu, 26 May 2022 10:28:18 +0200 Subject: [PATCH 112/198] Add @vibhory2j as a contributor --- .all-contributorsrc | 9 ++++ docs/pages/pmd/projectdocs/credits.md | 59 ++++++++++++++------------- 2 files changed, 39 insertions(+), 29 deletions(-) diff --git a/.all-contributorsrc b/.all-contributorsrc index f5d880797e..240441581c 100644 --- a/.all-contributorsrc +++ b/.all-contributorsrc @@ -6648,6 +6648,15 @@ "contributions": [ "code" ] + }, + { + "login": "vibhory2j", + "name": "Vibhor Goyal", + "avatar_url": "https://avatars.githubusercontent.com/u/15845016?v=4", + "profile": "https://github.com/vibhory2j", + "contributions": [ + "bug" + ] } ], "contributorsPerLine": 7, diff --git a/docs/pages/pmd/projectdocs/credits.md b/docs/pages/pmd/projectdocs/credits.md index b2efb5841c..e243b5c134 100644 --- a/docs/pages/pmd/projectdocs/credits.md +++ b/docs/pages/pmd/projectdocs/credits.md @@ -685,262 +685,263 @@ Thanks goes to these wonderful people ([emoji key](https://allcontributors.org/d
Valentin Brandl

🐛
Valeria

🐛
Vasily Anisimov

🐛 +
Vibhor Goyal

🐛
Vickenty Fesunov

🐛 -
Victor Noël

🐛 +
Victor Noël

🐛
Vincent Galloy

💻
Vincent HUYNH

🐛
Vincent Maurin

🐛
Vincent Privat

🐛
Vishhwas

🐛
Vitaly

🐛 -
Vitaly Polonetsky

🐛 +
Vitaly Polonetsky

🐛
Vojtech Polivka

🐛
Vsevolod Zholobov

🐛
Vyom Yadav

💻
Wang Shidong

🐛
Waqas Ahmed

🐛
Wayne J. Earl

🐛 -
Wchenghui

🐛 +
Wchenghui

🐛
Will Winder

🐛
William Brockhus

💻 🐛
Wilson Kurniawan

🐛
Wim Deblauwe

🐛
Woongsik Choi

🐛
XenoAmess

💻 🐛 -
Yang

💻 +
Yang

💻
YaroslavTER

🐛
Young Chan

💻 🐛
YuJin Kim

🐛
Yuri Dolzhenko

🐛
Yurii Dubinka

🐛
Zoltan Farkas

🐛 -
Zustin

🐛 +
Zustin

🐛
aaronhurst-google

🐛
alexmodis

🐛
andreoss

🐛
andrey81inmd

💻 🐛
anicoara

🐛
arunprasathav

🐛 -
asiercamara

🐛 +
asiercamara

🐛
astillich-igniti

💻
avesolovksyy

🐛
avishvat

🐛
avivmu

🐛
axelbarfod1

🐛
b-3-n

🐛 -
balbhadra9

🐛 +
balbhadra9

🐛
base23de

🐛
bergander

🐛
berkam

💻 🐛
breizh31

🐛
caesarkim

🐛
carolyujing

🐛 -
cesares-basilico

🐛 +
cesares-basilico

🐛
chrite

🐛
cobratbq

🐛
coladict

🐛
cosmoJFH

🐛
cristalp

🐛
crunsk

🐛 -
cwholmes

🐛 +
cwholmes

🐛
cyberjj999

🐛
cyw3

🐛
d1ss0nanz

🐛
danbrycefairsailcom

🐛
dariansanity

🐛
darrenmiliband

🐛 -
davidburstrom

🐛 +
davidburstrom

🐛
dbirkman-paloalto

🐛
deepak-patra

🐛
dependabot[bot]

💻 🐛
dinesh150

🐛
diziaq

🐛
dreaminpast123

🐛 -
duanyanan

🐛 +
duanyanan

🐛
dutt-sanjay

🐛
dylanleung

🐛
dzeigler

🐛
ekkirala

🐛
emersonmoura

🐛
fairy

🐛 -
filiprafalowicz

💻 +
filiprafalowicz

💻
foxmason

🐛
frankegabor

🐛
frankl

🐛
freafrea

🐛
fsapatin

🐛
gracia19

🐛 -
guo fei

🐛 +
guo fei

🐛
gurmsc5

🐛
gwilymatgearset

💻 🐛
haigsn

🐛
hemanshu070

🐛
henrik242

🐛
hongpuwu

🐛 -
hvbtup

💻 🐛 +
hvbtup

💻 🐛
igniti GmbH

🐛
ilovezfs

🐛
itaigilo

🐛
jakivey32

🐛
jbennett2091

🐛
jcamerin

🐛 -
jkeener1

🐛 +
jkeener1

🐛
jmetertea

🐛
johnra2

💻
josemanuelrolon

💻 🐛
kabroxiko

💻 🐛
karwer

🐛
kaulonline

🐛 -
kdaemonv

🐛 +
kdaemonv

🐛
kenji21

💻 🐛
kfranic

🐛
khalidkh

🐛
krzyk

🐛
lasselindqvist

🐛
lihuaib

🐛 -
lonelyma1021

🐛 +
lonelyma1021

🐛
lpeddy

🐛
lujiefsi

💻
lukelukes

💻
lyriccoder

🐛
marcelmore

🐛
matchbox

🐛 -
matthiaskraaz

🐛 +
matthiaskraaz

🐛
meandonlyme

🐛
mikesive

🐛
milossesic

🐛
mriddell95

🐛
mrlzh

🐛
msloan

🐛 -
mucharlaravalika

🐛 +
mucharlaravalika

🐛
mvenneman

🐛
nareshl119

🐛
nicolas-harraudeau-sonarsource

🐛
noerremark

🐛
novsirion

🐛
oggboy

🐛 -
oinume

🐛 +
oinume

🐛
orimarko

💻 🐛
pallavi agarwal

🐛
parksungrin

🐛
patpatpat123

🐛
patriksevallius

🐛
pbrajesh1

🐛 -
phoenix384

🐛 +
phoenix384

🐛
piotrszymanski-sc

💻
plan3d

🐛
poojasix

🐛
prabhushrikant

🐛
pujitha8783

🐛
r-r-a-j

🐛 -
raghujayjunk

🐛 +
raghujayjunk

🐛
rajeshveera

🐛
rajeswarreddy88

🐛
recdevs

🐛
reudismam

💻 🐛
rijkt

🐛
rillig-tk

🐛 -
rmohan20

💻 🐛 +
rmohan20

💻 🐛
rxmicro

🐛
ryan-gustafson

💻 🐛
sabi0

🐛
scais

🐛
sebbASF

🐛
sergeygorbaty

💻 -
shilko2013

🐛 +
shilko2013

🐛
simeonKondr

🐛
snajberk

🐛
sniperrifle2004

🐛
snuyanzin

🐛 💻
sratz

🐛
stonio

🐛 -
sturton

💻 🐛 +
sturton

💻 🐛
sudharmohan

🐛
suruchidawar

🐛
svenfinitiv

🐛
tashiscool

🐛
test-git-hook

🐛
testation21

💻 🐛 -
thanosa

🐛 +
thanosa

🐛
tiandiyixian

🐛
tobwoerk

🐛
tprouvot

🐛
trentchilders

🐛
triandicAnt

🐛
trishul14

🐛 -
tsui

🐛 +
tsui

🐛
winhkey

🐛
witherspore

🐛
wjljack

🐛
wuchiuwong

🐛
xingsong

🐛
xioayuge

🐛 -
xnYi9wRezm

💻 🐛 +
xnYi9wRezm

💻 🐛
xuanuy

🐛
xyf0921

🐛
yalechen-cyw3

🐛
yasuharu-sato

🐛
zenglian

🐛
zgrzyt93

💻 🐛 -
zh3ng

🐛 +
zh3ng

🐛
zt_soft

🐛
ztt79

🐛
zzzzfeng

🐛 From aae06c45ac2d2e07804dc7ab79fb26c55a51c091 Mon Sep 17 00:00:00 2001 From: Andreas Dangel Date: Thu, 26 May 2022 10:36:55 +0200 Subject: [PATCH 113/198] [doc] Update release notes (#3946, #3423, #2605, #2604, #2752) --- docs/pages/release_notes.md | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/docs/pages/release_notes.md b/docs/pages/release_notes.md index 2c7c511a92..e4855f3b66 100644 --- a/docs/pages/release_notes.md +++ b/docs/pages/release_notes.md @@ -32,12 +32,19 @@ Please use theses new forms instead of using comma-separated lists as argument t * cli * [#1445](https://github.com/pmd/pmd/issues/1445): \[core] Allow CLI to take globs as parameters +* go + * [#2752](https://github.com/pmd/pmd/issues/2752): \[go] Error parsing unicode values * html * [#3955](https://github.com/pmd/pmd/pull/3955): \[html] Improvements for handling text and comment nodes +* java + * [#3423](https://github.com/pmd/pmd/issues/3423): \[java] Error processing identifiers with Unicode * java-design * [#3874](https://github.com/pmd/pmd/issues/3874): \[java] ImmutableField reports fields annotated with @Autowired (Spring) and @Mock (Mockito) * javascript + * [#2605](https://github.com/pmd/pmd/issues/2605): \[js] Support unicode characters * [#3948](https://github.com/pmd/pmd/issues/3948): \[js] Invalid operator error for method property in object literal +* python + * [#2604](https://github.com/pmd/pmd/issues/2604): \[python] Support unicode identifiers ### API Changes From d0873ff6fafa68a49910107426664eaf8caa8bfa Mon Sep 17 00:00:00 2001 From: Andreas Dangel Date: Thu, 26 May 2022 10:57:08 +0200 Subject: [PATCH 114/198] [doc] Update release notes (#3974) --- docs/pages/release_notes.md | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/docs/pages/release_notes.md b/docs/pages/release_notes.md index e4855f3b66..44874a9097 100644 --- a/docs/pages/release_notes.md +++ b/docs/pages/release_notes.md @@ -28,10 +28,18 @@ pmd -d src/*/java -R rset*.xml ``` Please use theses new forms instead of using comma-separated lists as argument to these options. +#### C# Improvements + +When executing CPD on C# sources, the option `--ignore-annotations` is now supported as well. +It ignores C# attributes when detecting duplicated code. This option can also be enabled via +the CPD GUI. See [#3974](https://github.com/pmd/pmd/pull/3974) for details. + ### Fixed Issues * cli * [#1445](https://github.com/pmd/pmd/issues/1445): \[core] Allow CLI to take globs as parameters +* cs (c#) + * [#3974](https://github.com/pmd/pmd/pull/3974): \[cs] Add option to ignore C# attributes (annotations) * go * [#2752](https://github.com/pmd/pmd/issues/2752): \[go] Error parsing unicode values * html @@ -57,6 +65,7 @@ A new set of methods have been added, which use lists and do not rely on comma s ### External Contributions * [#3964](https://github.com/pmd/pmd/pull/3964): \[java] Fix #3874 - ImmutableField: fix mockito/spring false positives - [@lukelukes](https://github.com/lukelukes) +* [#3974](https://github.com/pmd/pmd/pull/3974): \[cs] Add option to ignore C# attributes (annotations) - [@maikelsteneker](https://github.com/maikelsteneker) {% endtocmaker %} From 11cda428f1092530408896d5d587ac20509ab152 Mon Sep 17 00:00:00 2001 From: Andreas Dangel Date: Thu, 26 May 2022 11:03:01 +0200 Subject: [PATCH 115/198] [doc] Update release notes (#3954, #3961) --- docs/pages/release_notes.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/docs/pages/release_notes.md b/docs/pages/release_notes.md index 44874a9097..eca65c0e36 100644 --- a/docs/pages/release_notes.md +++ b/docs/pages/release_notes.md @@ -46,6 +46,8 @@ the CPD GUI. See [#3974](https://github.com/pmd/pmd/pull/3974) for details. * [#3955](https://github.com/pmd/pmd/pull/3955): \[html] Improvements for handling text and comment nodes * java * [#3423](https://github.com/pmd/pmd/issues/3423): \[java] Error processing identifiers with Unicode +* java-bestpractices + * [#3954](https://github.com/pmd/pmd/issues/3954): \[java] NPE in UseCollectionIsEmptyRule when .size() is called in a record * java-design * [#3874](https://github.com/pmd/pmd/issues/3874): \[java] ImmutableField reports fields annotated with @Autowired (Spring) and @Mock (Mockito) * javascript @@ -64,6 +66,7 @@ A new set of methods have been added, which use lists and do not rely on comma s ### External Contributions +* [#3961](https://github.com/pmd/pmd/pull/3961): \[java] Fix #3954 - NPE in UseCollectionIsEmptyRule with record - [@flyhard](https://github.com/flyhard) * [#3964](https://github.com/pmd/pmd/pull/3964): \[java] Fix #3874 - ImmutableField: fix mockito/spring false positives - [@lukelukes](https://github.com/lukelukes) * [#3974](https://github.com/pmd/pmd/pull/3974): \[cs] Add option to ignore C# attributes (annotations) - [@maikelsteneker](https://github.com/maikelsteneker) From 95d6619a6b28a0bbf42c762aacb02f4e8a3c683e Mon Sep 17 00:00:00 2001 From: Andreas Dangel Date: Thu, 26 May 2022 11:03:20 +0200 Subject: [PATCH 116/198] Add @Ramel0921 as a contributor --- .all-contributorsrc | 9 +++ docs/pages/pmd/projectdocs/credits.md | 85 ++++++++++++++------------- 2 files changed, 52 insertions(+), 42 deletions(-) diff --git a/.all-contributorsrc b/.all-contributorsrc index 240441581c..7a4c53bfd6 100644 --- a/.all-contributorsrc +++ b/.all-contributorsrc @@ -6657,6 +6657,15 @@ "contributions": [ "bug" ] + }, + { + "login": "Ramel0921", + "name": "Ramel0921", + "avatar_url": "https://avatars.githubusercontent.com/u/104978096?v=4", + "profile": "https://github.com/Ramel0921", + "contributions": [ + "bug" + ] } ], "contributorsPerLine": 7, diff --git a/docs/pages/pmd/projectdocs/credits.md b/docs/pages/pmd/projectdocs/credits.md index e243b5c134..71ac04355b 100644 --- a/docs/pages/pmd/projectdocs/credits.md +++ b/docs/pages/pmd/projectdocs/credits.md @@ -569,378 +569,379 @@ Thanks goes to these wonderful people ([emoji key](https://allcontributors.org/d
RaheemShaik999

🐛
RajeshR

💻 🐛
Ramachandra Mohan

🐛 -
Raquel Pau

🐛 +
Ramel0921

🐛 +
Raquel Pau

🐛
Ravikiran Janardhana

🐛
Reda Benhemmouche

🐛
Renato Oliveira

💻 🐛
Rich DiCroce

🐛
Riot R1cket

🐛
Rishabh Jain

🐛 -
RishabhDeep Singh

🐛 +
RishabhDeep Singh

🐛
Robbie Martinus

💻 🐛
Robert Henry

🐛
Robert Painsi

🐛
Robert Russell

🐛
Robert Sösemann

💻 📖 📢 🐛
Robert Whitebit

🐛 -
Robin Richtsfeld

🐛 +
Robin Richtsfeld

🐛
Robin Stocker

💻 🐛
Robin Wils

🐛
RochusOest

🐛
Rodolfo Noviski

🐛
Rodrigo Casara

🐛
Rodrigo Fernandes

🐛 -
Roman Salvador

💻 🐛 +
Roman Salvador

💻 🐛
Ronald Blaschke

🐛
Róbert Papp

🐛
Saikat Sengupta

🐛
Saksham Handu

🐛
Saladoc

🐛
Salesforce Bob Lightning

🐛 -
Sam Carlberg

🐛 +
Sam Carlberg

🐛
Satoshi Kubo

🐛
Scott Kennedy

🐛
Scott Wells

🐛 💻
Scrsloota

💻
Sebastian Bögl

🐛
Sebastian Schuberth

🐛 -
Sebastian Schwarz

🐛 +
Sebastian Schwarz

🐛
Sergey Gorbaty

🐛
Sergey Kozlov

🐛
Sergey Yanzin

💻 🐛
Seth Wilcox

💻
Shubham

💻 🐛
Simon Xiao

🐛 -
Srinivasan Venkatachalam

🐛 +
Srinivasan Venkatachalam

🐛
Stanislav Gromov

🐛
Stanislav Myachenkov

💻
Stefan Birkner

🐛
Stefan Bohn

🐛
Stefan Endrullis

🐛
Stefan Klöss-Schuster

🐛 -
Stefan Wolf

🐛 +
Stefan Wolf

🐛
Stephan H. Wissel

🐛
Stephen

🐛
Stephen Friedrich

🐛
Steve Babula

💻
Stexxe

🐛
Stian Lågstad

🐛 -
StuartClayton5

🐛 +
StuartClayton5

🐛
Supun Arunoda

🐛
Suren Abrahamyan

🐛
SwatiBGupta1110

🐛
SyedThoufich

🐛
Szymon Sasin

🐛
T-chuangxin

🐛 -
TERAI Atsuhiro

🐛 +
TERAI Atsuhiro

🐛
TIOBE Software

💻 🐛
Taylor Smock

🐛
Techeira Damián

💻 🐛
Ted Husted

🐛
TehBakker

🐛
The Gitter Badger

🐛 -
Theodoor

🐛 +
Theodoor

🐛
Thiago Henrique Hüpner

🐛
Thibault Meyer

🐛
Thomas Güttler

🐛
Thomas Jones-Low

🐛
Thomas Smith

💻 🐛
ThrawnCA

🐛 -
Thunderforge

💻 🐛 +
Thunderforge

💻 🐛
Tim van der Lippe

🐛
Tobias Weimer

💻 🐛
Tom Daly

🐛
Tomer Figenblat

🐛
Tomi De Lucca

💻 🐛
Torsten Kleiber

🐛 -
TrackerSB

🐛 +
TrackerSB

🐛
Ullrich Hafner

🐛
Utku Cuhadaroglu

💻 🐛
Valentin Brandl

🐛
Valeria

🐛
Vasily Anisimov

🐛
Vibhor Goyal

🐛 -
Vickenty Fesunov

🐛 +
Vickenty Fesunov

🐛
Victor Noël

🐛
Vincent Galloy

💻
Vincent HUYNH

🐛
Vincent Maurin

🐛
Vincent Privat

🐛
Vishhwas

🐛 -
Vitaly

🐛 +
Vitaly

🐛
Vitaly Polonetsky

🐛
Vojtech Polivka

🐛
Vsevolod Zholobov

🐛
Vyom Yadav

💻
Wang Shidong

🐛
Waqas Ahmed

🐛 -
Wayne J. Earl

🐛 +
Wayne J. Earl

🐛
Wchenghui

🐛
Will Winder

🐛
William Brockhus

💻 🐛
Wilson Kurniawan

🐛
Wim Deblauwe

🐛
Woongsik Choi

🐛 -
XenoAmess

💻 🐛 +
XenoAmess

💻 🐛
Yang

💻
YaroslavTER

🐛
Young Chan

💻 🐛
YuJin Kim

🐛
Yuri Dolzhenko

🐛
Yurii Dubinka

🐛 -
Zoltan Farkas

🐛 +
Zoltan Farkas

🐛
Zustin

🐛
aaronhurst-google

🐛
alexmodis

🐛
andreoss

🐛
andrey81inmd

💻 🐛
anicoara

🐛 -
arunprasathav

🐛 +
arunprasathav

🐛
asiercamara

🐛
astillich-igniti

💻
avesolovksyy

🐛
avishvat

🐛
avivmu

🐛
axelbarfod1

🐛 -
b-3-n

🐛 +
b-3-n

🐛
balbhadra9

🐛
base23de

🐛
bergander

🐛
berkam

💻 🐛
breizh31

🐛
caesarkim

🐛 -
carolyujing

🐛 +
carolyujing

🐛
cesares-basilico

🐛
chrite

🐛
cobratbq

🐛
coladict

🐛
cosmoJFH

🐛
cristalp

🐛 -
crunsk

🐛 +
crunsk

🐛
cwholmes

🐛
cyberjj999

🐛
cyw3

🐛
d1ss0nanz

🐛
danbrycefairsailcom

🐛
dariansanity

🐛 -
darrenmiliband

🐛 +
darrenmiliband

🐛
davidburstrom

🐛
dbirkman-paloalto

🐛
deepak-patra

🐛
dependabot[bot]

💻 🐛
dinesh150

🐛
diziaq

🐛 -
dreaminpast123

🐛 +
dreaminpast123

🐛
duanyanan

🐛
dutt-sanjay

🐛
dylanleung

🐛
dzeigler

🐛
ekkirala

🐛
emersonmoura

🐛 -
fairy

🐛 +
fairy

🐛
filiprafalowicz

💻
foxmason

🐛
frankegabor

🐛
frankl

🐛
freafrea

🐛
fsapatin

🐛 -
gracia19

🐛 +
gracia19

🐛
guo fei

🐛
gurmsc5

🐛
gwilymatgearset

💻 🐛
haigsn

🐛
hemanshu070

🐛
henrik242

🐛 -
hongpuwu

🐛 +
hongpuwu

🐛
hvbtup

💻 🐛
igniti GmbH

🐛
ilovezfs

🐛
itaigilo

🐛
jakivey32

🐛
jbennett2091

🐛 -
jcamerin

🐛 +
jcamerin

🐛
jkeener1

🐛
jmetertea

🐛
johnra2

💻
josemanuelrolon

💻 🐛
kabroxiko

💻 🐛
karwer

🐛 -
kaulonline

🐛 +
kaulonline

🐛
kdaemonv

🐛
kenji21

💻 🐛
kfranic

🐛
khalidkh

🐛
krzyk

🐛
lasselindqvist

🐛 -
lihuaib

🐛 +
lihuaib

🐛
lonelyma1021

🐛
lpeddy

🐛
lujiefsi

💻
lukelukes

💻
lyriccoder

🐛
marcelmore

🐛 -
matchbox

🐛 +
matchbox

🐛
matthiaskraaz

🐛
meandonlyme

🐛
mikesive

🐛
milossesic

🐛
mriddell95

🐛
mrlzh

🐛 -
msloan

🐛 +
msloan

🐛
mucharlaravalika

🐛
mvenneman

🐛
nareshl119

🐛
nicolas-harraudeau-sonarsource

🐛
noerremark

🐛
novsirion

🐛 -
oggboy

🐛 +
oggboy

🐛
oinume

🐛
orimarko

💻 🐛
pallavi agarwal

🐛
parksungrin

🐛
patpatpat123

🐛
patriksevallius

🐛 -
pbrajesh1

🐛 +
pbrajesh1

🐛
phoenix384

🐛
piotrszymanski-sc

💻
plan3d

🐛
poojasix

🐛
prabhushrikant

🐛
pujitha8783

🐛 -
r-r-a-j

🐛 +
r-r-a-j

🐛
raghujayjunk

🐛
rajeshveera

🐛
rajeswarreddy88

🐛
recdevs

🐛
reudismam

💻 🐛
rijkt

🐛 -
rillig-tk

🐛 +
rillig-tk

🐛
rmohan20

💻 🐛
rxmicro

🐛
ryan-gustafson

💻 🐛
sabi0

🐛
scais

🐛
sebbASF

🐛 -
sergeygorbaty

💻 +
sergeygorbaty

💻
shilko2013

🐛
simeonKondr

🐛
snajberk

🐛
sniperrifle2004

🐛
snuyanzin

🐛 💻
sratz

🐛 -
stonio

🐛 +
stonio

🐛
sturton

💻 🐛
sudharmohan

🐛
suruchidawar

🐛
svenfinitiv

🐛
tashiscool

🐛
test-git-hook

🐛 -
testation21

💻 🐛 +
testation21

💻 🐛
thanosa

🐛
tiandiyixian

🐛
tobwoerk

🐛
tprouvot

🐛
trentchilders

🐛
triandicAnt

🐛 -
trishul14

🐛 +
trishul14

🐛
tsui

🐛
winhkey

🐛
witherspore

🐛
wjljack

🐛
wuchiuwong

🐛
xingsong

🐛 -
xioayuge

🐛 +
xioayuge

🐛
xnYi9wRezm

💻 🐛
xuanuy

🐛
xyf0921

🐛
yalechen-cyw3

🐛
yasuharu-sato

🐛
zenglian

🐛 -
zgrzyt93

💻 🐛 +
zgrzyt93

💻 🐛
zh3ng

🐛
zt_soft

🐛
ztt79

🐛 From 6f234bab8dc174925d66423021ca44c2f455d679 Mon Sep 17 00:00:00 2001 From: Andreas Dangel Date: Thu, 26 May 2022 11:03:34 +0200 Subject: [PATCH 117/198] Add @flyhard as a contributor --- .all-contributorsrc | 9 +++ docs/pages/pmd/projectdocs/credits.md | 93 ++++++++++++++------------- 2 files changed, 57 insertions(+), 45 deletions(-) diff --git a/.all-contributorsrc b/.all-contributorsrc index 7a4c53bfd6..6efd00a779 100644 --- a/.all-contributorsrc +++ b/.all-contributorsrc @@ -6666,6 +6666,15 @@ "contributions": [ "bug" ] + }, + { + "login": "flyhard", + "name": "Per Abich", + "avatar_url": "https://avatars.githubusercontent.com/u/409466?v=4", + "profile": "https://github.com/flyhard", + "contributions": [ + "code" + ] } ], "contributorsPerLine": 7, diff --git a/docs/pages/pmd/projectdocs/credits.md b/docs/pages/pmd/projectdocs/credits.md index 71ac04355b..b00de0e0d8 100644 --- a/docs/pages/pmd/projectdocs/credits.md +++ b/docs/pages/pmd/projectdocs/credits.md @@ -540,413 +540,416 @@ Thanks goes to these wonderful people ([emoji key](https://allcontributors.org/d
Pedro Nuno Santos

🐛
Pedro Rijo

🐛
Pelisse Romain

💻 📖 🐛 +
Per Abich

💻
Pete Davids

🐛
Peter Bruin

🐛 -
Peter Chittum

💻 🐛 +
Peter Chittum

💻 🐛
Peter Cudmore

🐛
Peter Kasson

🐛
Peter Kofler

🐛
Pham Hai Trung

🐛
Philip Graf

💻 🐛
Philip Hachey

🐛 -
Philippe Ozil

🐛 +
Philippe Ozil

🐛
Phinehas Artemix

🐛
Phokham Nonava

🐛
Piotr Szymański

🐛
Piotrek Żygieło

💻 🐛
Pranay Jaiswal

🐛
Prasad Kamath

🐛 -
Prasanna

🐛 +
Prasanna

🐛
Presh-AR

🐛
Puneet1726

🐛
Rafael Cortês

🐛
RaheemShaik999

🐛
RajeshR

💻 🐛
Ramachandra Mohan

🐛 -
Ramel0921

🐛 +
Ramel0921

🐛
Raquel Pau

🐛
Ravikiran Janardhana

🐛
Reda Benhemmouche

🐛
Renato Oliveira

💻 🐛
Rich DiCroce

🐛
Riot R1cket

🐛 -
Rishabh Jain

🐛 +
Rishabh Jain

🐛
RishabhDeep Singh

🐛
Robbie Martinus

💻 🐛
Robert Henry

🐛
Robert Painsi

🐛
Robert Russell

🐛
Robert Sösemann

💻 📖 📢 🐛 -
Robert Whitebit

🐛 +
Robert Whitebit

🐛
Robin Richtsfeld

🐛
Robin Stocker

💻 🐛
Robin Wils

🐛
RochusOest

🐛
Rodolfo Noviski

🐛
Rodrigo Casara

🐛 -
Rodrigo Fernandes

🐛 +
Rodrigo Fernandes

🐛
Roman Salvador

💻 🐛
Ronald Blaschke

🐛
Róbert Papp

🐛
Saikat Sengupta

🐛
Saksham Handu

🐛
Saladoc

🐛 -
Salesforce Bob Lightning

🐛 +
Salesforce Bob Lightning

🐛
Sam Carlberg

🐛
Satoshi Kubo

🐛
Scott Kennedy

🐛
Scott Wells

🐛 💻
Scrsloota

💻
Sebastian Bögl

🐛 -
Sebastian Schuberth

🐛 +
Sebastian Schuberth

🐛
Sebastian Schwarz

🐛
Sergey Gorbaty

🐛
Sergey Kozlov

🐛
Sergey Yanzin

💻 🐛
Seth Wilcox

💻
Shubham

💻 🐛 -
Simon Xiao

🐛 +
Simon Xiao

🐛
Srinivasan Venkatachalam

🐛
Stanislav Gromov

🐛
Stanislav Myachenkov

💻
Stefan Birkner

🐛
Stefan Bohn

🐛
Stefan Endrullis

🐛 -
Stefan Klöss-Schuster

🐛 +
Stefan Klöss-Schuster

🐛
Stefan Wolf

🐛
Stephan H. Wissel

🐛
Stephen

🐛
Stephen Friedrich

🐛
Steve Babula

💻
Stexxe

🐛 -
Stian Lågstad

🐛 +
Stian Lågstad

🐛
StuartClayton5

🐛
Supun Arunoda

🐛
Suren Abrahamyan

🐛
SwatiBGupta1110

🐛
SyedThoufich

🐛
Szymon Sasin

🐛 -
T-chuangxin

🐛 +
T-chuangxin

🐛
TERAI Atsuhiro

🐛
TIOBE Software

💻 🐛
Taylor Smock

🐛
Techeira Damián

💻 🐛
Ted Husted

🐛
TehBakker

🐛 -
The Gitter Badger

🐛 +
The Gitter Badger

🐛
Theodoor

🐛
Thiago Henrique Hüpner

🐛
Thibault Meyer

🐛
Thomas Güttler

🐛
Thomas Jones-Low

🐛
Thomas Smith

💻 🐛 -
ThrawnCA

🐛 +
ThrawnCA

🐛
Thunderforge

💻 🐛
Tim van der Lippe

🐛
Tobias Weimer

💻 🐛
Tom Daly

🐛
Tomer Figenblat

🐛
Tomi De Lucca

💻 🐛 -
Torsten Kleiber

🐛 +
Torsten Kleiber

🐛
TrackerSB

🐛
Ullrich Hafner

🐛
Utku Cuhadaroglu

💻 🐛
Valentin Brandl

🐛
Valeria

🐛
Vasily Anisimov

🐛 -
Vibhor Goyal

🐛 +
Vibhor Goyal

🐛
Vickenty Fesunov

🐛
Victor Noël

🐛
Vincent Galloy

💻
Vincent HUYNH

🐛
Vincent Maurin

🐛
Vincent Privat

🐛 -
Vishhwas

🐛 +
Vishhwas

🐛
Vitaly

🐛
Vitaly Polonetsky

🐛
Vojtech Polivka

🐛
Vsevolod Zholobov

🐛
Vyom Yadav

💻
Wang Shidong

🐛 -
Waqas Ahmed

🐛 +
Waqas Ahmed

🐛
Wayne J. Earl

🐛
Wchenghui

🐛
Will Winder

🐛
William Brockhus

💻 🐛
Wilson Kurniawan

🐛
Wim Deblauwe

🐛 -
Woongsik Choi

🐛 +
Woongsik Choi

🐛
XenoAmess

💻 🐛
Yang

💻
YaroslavTER

🐛
Young Chan

💻 🐛
YuJin Kim

🐛
Yuri Dolzhenko

🐛 -
Yurii Dubinka

🐛 +
Yurii Dubinka

🐛
Zoltan Farkas

🐛
Zustin

🐛
aaronhurst-google

🐛
alexmodis

🐛
andreoss

🐛
andrey81inmd

💻 🐛 -
anicoara

🐛 +
anicoara

🐛
arunprasathav

🐛
asiercamara

🐛
astillich-igniti

💻
avesolovksyy

🐛
avishvat

🐛
avivmu

🐛 -
axelbarfod1

🐛 +
axelbarfod1

🐛
b-3-n

🐛
balbhadra9

🐛
base23de

🐛
bergander

🐛
berkam

💻 🐛
breizh31

🐛 -
caesarkim

🐛 +
caesarkim

🐛
carolyujing

🐛
cesares-basilico

🐛
chrite

🐛
cobratbq

🐛
coladict

🐛
cosmoJFH

🐛 -
cristalp

🐛 +
cristalp

🐛
crunsk

🐛
cwholmes

🐛
cyberjj999

🐛
cyw3

🐛
d1ss0nanz

🐛
danbrycefairsailcom

🐛 -
dariansanity

🐛 +
dariansanity

🐛
darrenmiliband

🐛
davidburstrom

🐛
dbirkman-paloalto

🐛
deepak-patra

🐛
dependabot[bot]

💻 🐛
dinesh150

🐛 -
diziaq

🐛 +
diziaq

🐛
dreaminpast123

🐛
duanyanan

🐛
dutt-sanjay

🐛
dylanleung

🐛
dzeigler

🐛
ekkirala

🐛 -
emersonmoura

🐛 +
emersonmoura

🐛
fairy

🐛
filiprafalowicz

💻
foxmason

🐛
frankegabor

🐛
frankl

🐛
freafrea

🐛 -
fsapatin

🐛 +
fsapatin

🐛
gracia19

🐛
guo fei

🐛
gurmsc5

🐛
gwilymatgearset

💻 🐛
haigsn

🐛
hemanshu070

🐛 -
henrik242

🐛 +
henrik242

🐛
hongpuwu

🐛
hvbtup

💻 🐛
igniti GmbH

🐛
ilovezfs

🐛
itaigilo

🐛
jakivey32

🐛 -
jbennett2091

🐛 +
jbennett2091

🐛
jcamerin

🐛
jkeener1

🐛
jmetertea

🐛
johnra2

💻
josemanuelrolon

💻 🐛
kabroxiko

💻 🐛 -
karwer

🐛 +
karwer

🐛
kaulonline

🐛
kdaemonv

🐛
kenji21

💻 🐛
kfranic

🐛
khalidkh

🐛
krzyk

🐛 -
lasselindqvist

🐛 +
lasselindqvist

🐛
lihuaib

🐛
lonelyma1021

🐛
lpeddy

🐛
lujiefsi

💻
lukelukes

💻
lyriccoder

🐛 -
marcelmore

🐛 +
marcelmore

🐛
matchbox

🐛
matthiaskraaz

🐛
meandonlyme

🐛
mikesive

🐛
milossesic

🐛
mriddell95

🐛 -
mrlzh

🐛 +
mrlzh

🐛
msloan

🐛
mucharlaravalika

🐛
mvenneman

🐛
nareshl119

🐛
nicolas-harraudeau-sonarsource

🐛
noerremark

🐛 -
novsirion

🐛 +
novsirion

🐛
oggboy

🐛
oinume

🐛
orimarko

💻 🐛
pallavi agarwal

🐛
parksungrin

🐛
patpatpat123

🐛 -
patriksevallius

🐛 +
patriksevallius

🐛
pbrajesh1

🐛
phoenix384

🐛
piotrszymanski-sc

💻
plan3d

🐛
poojasix

🐛
prabhushrikant

🐛 -
pujitha8783

🐛 +
pujitha8783

🐛
r-r-a-j

🐛
raghujayjunk

🐛
rajeshveera

🐛
rajeswarreddy88

🐛
recdevs

🐛
reudismam

💻 🐛 -
rijkt

🐛 +
rijkt

🐛
rillig-tk

🐛
rmohan20

💻 🐛
rxmicro

🐛
ryan-gustafson

💻 🐛
sabi0

🐛
scais

🐛 -
sebbASF

🐛 +
sebbASF

🐛
sergeygorbaty

💻
shilko2013

🐛
simeonKondr

🐛
snajberk

🐛
sniperrifle2004

🐛
snuyanzin

🐛 💻 -
sratz

🐛 +
sratz

🐛
stonio

🐛
sturton

💻 🐛
sudharmohan

🐛
suruchidawar

🐛
svenfinitiv

🐛
tashiscool

🐛 -
test-git-hook

🐛 +
test-git-hook

🐛
testation21

💻 🐛
thanosa

🐛
tiandiyixian

🐛
tobwoerk

🐛
tprouvot

🐛
trentchilders

🐛 -
triandicAnt

🐛 +
triandicAnt

🐛
trishul14

🐛
tsui

🐛
winhkey

🐛
witherspore

🐛
wjljack

🐛
wuchiuwong

🐛 -
xingsong

🐛 +
xingsong

🐛
xioayuge

🐛
xnYi9wRezm

💻 🐛
xuanuy

🐛
xyf0921

🐛
yalechen-cyw3

🐛
yasuharu-sato

🐛 -
zenglian

🐛 +
zenglian

🐛
zgrzyt93

💻 🐛
zh3ng

🐛
zt_soft

🐛
ztt79

🐛
zzzzfeng

🐛
Árpád Magosányi

🐛 + +
任贵杰

🐛 From 8248f6e4e1f3bbda18fc924ed26bc58a10cfdd2b Mon Sep 17 00:00:00 2001 From: Andreas Dangel Date: Thu, 26 May 2022 11:49:51 +0200 Subject: [PATCH 118/198] Fix unit tests --- .../pmd/lang/cs/cpd/testdata/attributes.txt | 400 +++++++++--------- .../cs/cpd/testdata/attributes_ignored.txt | 182 ++++---- .../lang/go/cpd/testdata/sample_unicode.txt | 148 +++---- .../python/cpd/testdata/sample_unicode.txt | 18 +- .../python/cpd/testdata/var_with_dollar.txt | 18 +- 5 files changed, 383 insertions(+), 383 deletions(-) diff --git a/pmd-cs/src/test/resources/net/sourceforge/pmd/lang/cs/cpd/testdata/attributes.txt b/pmd-cs/src/test/resources/net/sourceforge/pmd/lang/cs/cpd/testdata/attributes.txt index 403064af38..ec85e49500 100644 --- a/pmd-cs/src/test/resources/net/sourceforge/pmd/lang/cs/cpd/testdata/attributes.txt +++ b/pmd-cs/src/test/resources/net/sourceforge/pmd/lang/cs/cpd/testdata/attributes.txt @@ -1,229 +1,229 @@ [Image] or [Truncated image[ Bcol Ecol L1 - [\[] 1 1 - [Serializable] 2 13 - [\]] 14 14 + [\[] 1 2 + [Serializable] 2 14 + [\]] 14 15 L2 - [public] 1 6 - [class] 8 12 - [SampleClass] 14 24 + [public] 1 7 + [class] 8 13 + [SampleClass] 14 25 L3 - [{] 1 1 + [{] 1 2 L5 - [}] 1 1 + [}] 1 2 L7 - [\[] 1 1 - [System] 2 7 - [.] 8 8 - [Runtime] 9 15 - [.] 16 16 - [InteropServices] 17 31 - [.] 32 32 - [DllImport] 33 41 - [(] 42 42 - ["user32.dll"] 43 54 - [)] 55 55 - [\]] 56 56 + [\[] 1 2 + [System] 2 8 + [.] 8 9 + [Runtime] 9 16 + [.] 16 17 + [InteropServices] 17 32 + [.] 32 33 + [DllImport] 33 42 + [(] 42 43 + ["user32.dll"] 43 55 + [)] 55 56 + [\]] 56 57 L8 - [extern] 1 6 - [static] 8 13 - [void] 15 18 - [SampleMethod] 20 31 - [(] 32 32 - [)] 33 33 - [;] 34 34 + [extern] 1 7 + [static] 8 14 + [void] 15 19 + [SampleMethod] 20 32 + [(] 32 33 + [)] 33 34 + [;] 34 35 L10 - [void] 1 4 - [MethodA] 6 12 - [(] 13 13 - [\[] 14 14 - [In] 15 16 - [\]] 17 17 - [\[] 18 18 - [Out] 19 21 - [\]] 22 22 - [ref] 24 26 - [double] 28 33 - [x] 35 35 - [)] 36 36 - [{] 38 38 - [}] 40 40 + [void] 1 5 + [MethodA] 6 13 + [(] 13 14 + [\[] 14 15 + [In] 15 17 + [\]] 17 18 + [\[] 18 19 + [Out] 19 22 + [\]] 22 23 + [ref] 24 27 + [double] 28 34 + [x] 35 36 + [)] 36 37 + [{] 38 39 + [}] 40 41 L11 - [void] 1 4 - [MethodB] 6 12 - [(] 13 13 - [\[] 14 14 - [Out] 15 17 - [\]] 18 18 - [\[] 19 19 - [In] 20 21 - [\]] 22 22 - [ref] 24 26 - [double] 28 33 - [x] 35 35 - [)] 36 36 - [{] 38 38 - [}] 40 40 + [void] 1 5 + [MethodB] 6 13 + [(] 13 14 + [\[] 14 15 + [Out] 15 18 + [\]] 18 19 + [\[] 19 20 + [In] 20 22 + [\]] 22 23 + [ref] 24 27 + [double] 28 34 + [x] 35 36 + [)] 36 37 + [{] 38 39 + [}] 40 41 L12 - [void] 1 4 - [MethodC] 6 12 - [(] 13 13 - [\[] 14 14 - [In] 15 16 - [,] 17 17 - [Out] 19 21 - [\]] 22 22 - [ref] 24 26 - [double] 28 33 - [x] 35 35 - [)] 36 36 - [{] 38 38 - [}] 40 40 + [void] 1 5 + [MethodC] 6 13 + [(] 13 14 + [\[] 14 15 + [In] 15 17 + [,] 17 18 + [Out] 19 22 + [\]] 22 23 + [ref] 24 27 + [double] 28 34 + [x] 35 36 + [)] 36 37 + [{] 38 39 + [}] 40 41 L14 - [\[] 1 1 - [Conditional] 2 12 - [(] 13 13 - ["DEBUG"] 14 20 - [)] 21 21 - [,] 22 22 - [Conditional] 24 34 - [(] 35 35 - ["TEST1"] 36 42 - [)] 43 43 - [\]] 44 44 + [\[] 1 2 + [Conditional] 2 13 + [(] 13 14 + ["DEBUG"] 14 21 + [)] 21 22 + [,] 22 23 + [Conditional] 24 35 + [(] 35 36 + ["TEST1"] 36 43 + [)] 43 44 + [\]] 44 45 L15 - [void] 1 4 - [TraceMethod] 6 16 - [(] 17 17 - [)] 18 18 + [void] 1 5 + [TraceMethod] 6 17 + [(] 17 18 + [)] 18 19 L16 - [{] 1 1 + [{] 1 2 L18 - [}] 1 1 + [}] 1 2 L20 - [\[] 1 1 - [DllImport] 2 10 - [(] 11 11 - ["user32.dll"] 12 23 - [)] 24 24 - [\]] 25 25 + [\[] 1 2 + [DllImport] 2 11 + [(] 11 12 + ["user32.dll"] 12 24 + [)] 24 25 + [\]] 25 26 L21 - [\[] 1 1 - [DllImport] 2 10 - [(] 11 11 - ["user32.dll"] 12 23 - [,] 24 24 - [SetLastError] 26 37 - [=] 38 38 - [false] 39 43 - [,] 44 44 - [ExactSpelling] 46 58 - [=] 59 59 - [false] 60 64 - [)] 65 65 - [\]] 66 66 + [\[] 1 2 + [DllImport] 2 11 + [(] 11 12 + ["user32.dll"] 12 24 + [,] 24 25 + [SetLastError] 26 38 + [=] 38 39 + [false] 39 44 + [,] 44 45 + [ExactSpelling] 46 59 + [=] 59 60 + [false] 60 65 + [)] 65 66 + [\]] 66 67 L22 - [\[] 1 1 - [DllImport] 2 10 - [(] 11 11 - ["user32.dll"] 12 23 - [,] 24 24 - [ExactSpelling] 26 38 - [=] 39 39 - [false] 40 44 - [,] 45 45 - [SetLastError] 47 58 - [=] 59 59 - [false] 60 64 - [)] 65 65 - [\]] 66 66 + [\[] 1 2 + [DllImport] 2 11 + [(] 11 12 + ["user32.dll"] 12 24 + [,] 24 25 + [ExactSpelling] 26 39 + [=] 39 40 + [false] 40 45 + [,] 45 46 + [SetLastError] 47 59 + [=] 59 60 + [false] 60 65 + [)] 65 66 + [\]] 66 67 L24 - [using] 1 5 - [System] 7 12 - [;] 13 13 + [using] 1 6 + [System] 7 13 + [;] 13 14 L25 - [using] 1 5 - [System] 7 12 - [.] 13 13 - [Reflection] 14 23 - [;] 24 24 + [using] 1 6 + [System] 7 13 + [.] 13 14 + [Reflection] 14 24 + [;] 24 25 L26 - [\[] 1 1 - [assembly] 2 9 - [:] 10 10 - [AssemblyTitleAttribute] 12 33 - [(] 34 34 - ["Production assembly 4"] 35 57 - [)] 58 58 - [\]] 59 59 + [\[] 1 2 + [assembly] 2 10 + [:] 10 11 + [AssemblyTitleAttribute] 12 34 + [(] 34 35 + ["Production assembly 4"] 35 58 + [)] 58 59 + [\]] 59 60 L27 - [\[] 1 1 - [module] 2 7 - [:] 8 8 - [CLSCompliant] 10 21 - [(] 22 22 - [true] 23 26 - [)] 27 27 - [\]] 28 28 + [\[] 1 2 + [module] 2 8 + [:] 8 9 + [CLSCompliant] 10 22 + [(] 22 23 + [true] 23 27 + [)] 27 28 + [\]] 28 29 L30 - [\[] 1 1 - [ValidatedContract] 2 18 - [\]] 19 19 + [\[] 1 2 + [ValidatedContract] 2 19 + [\]] 19 20 L31 - [int] 1 3 - [Method1] 5 11 - [(] 12 12 - [)] 13 13 - [{] 15 15 - [return] 17 22 - [0] 24 24 - [;] 25 25 - [}] 27 27 + [int] 1 4 + [Method1] 5 12 + [(] 12 13 + [)] 13 14 + [{] 15 16 + [return] 17 23 + [0] 24 25 + [;] 25 26 + [}] 27 28 L34 - [\[] 1 1 - [method] 2 7 - [:] 8 8 - [ValidatedContract] 10 26 - [\]] 27 27 + [\[] 1 2 + [method] 2 8 + [:] 8 9 + [ValidatedContract] 10 27 + [\]] 27 28 L35 - [int] 1 3 - [Method2] 5 11 - [(] 12 12 - [)] 13 13 - [{] 15 15 - [return] 17 22 - [0] 24 24 - [;] 25 25 - [}] 27 27 + [int] 1 4 + [Method2] 5 12 + [(] 12 13 + [)] 13 14 + [{] 15 16 + [return] 17 23 + [0] 24 25 + [;] 25 26 + [}] 27 28 L38 - [int] 1 3 - [Method3] 5 11 - [(] 12 12 - [\[] 13 13 - [ValidatedContract] 14 30 - [\]] 31 31 - [string] 33 38 - [contract] 40 47 - [)] 48 48 - [{] 50 50 - [return] 52 57 - [0] 59 59 - [;] 60 60 - [}] 62 62 + [int] 1 4 + [Method3] 5 12 + [(] 12 13 + [\[] 13 14 + [ValidatedContract] 14 31 + [\]] 31 32 + [string] 33 39 + [contract] 40 48 + [)] 48 49 + [{] 50 51 + [return] 52 58 + [0] 59 60 + [;] 60 61 + [}] 62 63 L41 - [\[] 1 1 - [return] 2 7 - [:] 8 8 - [ValidatedContract] 10 26 - [\]] 27 27 + [\[] 1 2 + [return] 2 8 + [:] 8 9 + [ValidatedContract] 10 27 + [\]] 27 28 L42 - [int] 1 3 - [Method4] 5 11 - [(] 12 12 - [)] 13 13 - [{] 15 15 - [return] 17 22 - [0] 24 24 - [;] 25 25 - [}] 27 27 + [int] 1 4 + [Method4] 5 12 + [(] 12 13 + [)] 13 14 + [{] 15 16 + [return] 17 23 + [0] 24 25 + [;] 25 26 + [}] 27 28 EOF diff --git a/pmd-cs/src/test/resources/net/sourceforge/pmd/lang/cs/cpd/testdata/attributes_ignored.txt b/pmd-cs/src/test/resources/net/sourceforge/pmd/lang/cs/cpd/testdata/attributes_ignored.txt index 0796c4384c..c2de96f13f 100644 --- a/pmd-cs/src/test/resources/net/sourceforge/pmd/lang/cs/cpd/testdata/attributes_ignored.txt +++ b/pmd-cs/src/test/resources/net/sourceforge/pmd/lang/cs/cpd/testdata/attributes_ignored.txt @@ -1,109 +1,109 @@ [Image] or [Truncated image[ Bcol Ecol L2 - [public] 1 6 - [class] 8 12 - [SampleClass] 14 24 + [public] 1 7 + [class] 8 13 + [SampleClass] 14 25 L3 - [{] 1 1 + [{] 1 2 L5 - [}] 1 1 + [}] 1 2 L8 - [extern] 1 6 - [static] 8 13 - [void] 15 18 - [SampleMethod] 20 31 - [(] 32 32 - [)] 33 33 - [;] 34 34 + [extern] 1 7 + [static] 8 14 + [void] 15 19 + [SampleMethod] 20 32 + [(] 32 33 + [)] 33 34 + [;] 34 35 L10 - [void] 1 4 - [MethodA] 6 12 - [(] 13 13 - [ref] 24 26 - [double] 28 33 - [x] 35 35 - [)] 36 36 - [{] 38 38 - [}] 40 40 + [void] 1 5 + [MethodA] 6 13 + [(] 13 14 + [ref] 24 27 + [double] 28 34 + [x] 35 36 + [)] 36 37 + [{] 38 39 + [}] 40 41 L11 - [void] 1 4 - [MethodB] 6 12 - [(] 13 13 - [ref] 24 26 - [double] 28 33 - [x] 35 35 - [)] 36 36 - [{] 38 38 - [}] 40 40 + [void] 1 5 + [MethodB] 6 13 + [(] 13 14 + [ref] 24 27 + [double] 28 34 + [x] 35 36 + [)] 36 37 + [{] 38 39 + [}] 40 41 L12 - [void] 1 4 - [MethodC] 6 12 - [(] 13 13 - [ref] 24 26 - [double] 28 33 - [x] 35 35 - [)] 36 36 - [{] 38 38 - [}] 40 40 + [void] 1 5 + [MethodC] 6 13 + [(] 13 14 + [ref] 24 27 + [double] 28 34 + [x] 35 36 + [)] 36 37 + [{] 38 39 + [}] 40 41 L15 - [void] 1 4 - [TraceMethod] 6 16 - [(] 17 17 - [)] 18 18 + [void] 1 5 + [TraceMethod] 6 17 + [(] 17 18 + [)] 18 19 L16 - [{] 1 1 + [{] 1 2 L18 - [}] 1 1 + [}] 1 2 L24 - [using] 1 5 - [System] 7 12 - [;] 13 13 + [using] 1 6 + [System] 7 13 + [;] 13 14 L25 - [using] 1 5 - [System] 7 12 - [.] 13 13 - [Reflection] 14 23 - [;] 24 24 + [using] 1 6 + [System] 7 13 + [.] 13 14 + [Reflection] 14 24 + [;] 24 25 L31 - [int] 1 3 - [Method1] 5 11 - [(] 12 12 - [)] 13 13 - [{] 15 15 - [return] 17 22 - [0] 24 24 - [;] 25 25 - [}] 27 27 + [int] 1 4 + [Method1] 5 12 + [(] 12 13 + [)] 13 14 + [{] 15 16 + [return] 17 23 + [0] 24 25 + [;] 25 26 + [}] 27 28 L35 - [int] 1 3 - [Method2] 5 11 - [(] 12 12 - [)] 13 13 - [{] 15 15 - [return] 17 22 - [0] 24 24 - [;] 25 25 - [}] 27 27 + [int] 1 4 + [Method2] 5 12 + [(] 12 13 + [)] 13 14 + [{] 15 16 + [return] 17 23 + [0] 24 25 + [;] 25 26 + [}] 27 28 L38 - [int] 1 3 - [Method3] 5 11 - [(] 12 12 - [string] 33 38 - [contract] 40 47 - [)] 48 48 - [{] 50 50 - [return] 52 57 - [0] 59 59 - [;] 60 60 - [}] 62 62 + [int] 1 4 + [Method3] 5 12 + [(] 12 13 + [string] 33 39 + [contract] 40 48 + [)] 48 49 + [{] 50 51 + [return] 52 58 + [0] 59 60 + [;] 60 61 + [}] 62 63 L42 - [int] 1 3 - [Method4] 5 11 - [(] 12 12 - [)] 13 13 - [{] 15 15 - [return] 17 22 - [0] 24 24 - [;] 25 25 - [}] 27 27 + [int] 1 4 + [Method4] 5 12 + [(] 12 13 + [)] 13 14 + [{] 15 16 + [return] 17 23 + [0] 24 25 + [;] 25 26 + [}] 27 28 EOF diff --git a/pmd-go/src/test/resources/net/sourceforge/pmd/lang/go/cpd/testdata/sample_unicode.txt b/pmd-go/src/test/resources/net/sourceforge/pmd/lang/go/cpd/testdata/sample_unicode.txt index f1b02aef86..ecc27507ff 100644 --- a/pmd-go/src/test/resources/net/sourceforge/pmd/lang/go/cpd/testdata/sample_unicode.txt +++ b/pmd-go/src/test/resources/net/sourceforge/pmd/lang/go/cpd/testdata/sample_unicode.txt @@ -1,89 +1,89 @@ [Image] or [Truncated image[ Bcol Ecol L1 - [func] 1 4 - [main] 6 9 - [(] 10 10 - [)] 11 11 - [{] 13 13 + [func] 1 5 + [main] 6 10 + [(] 10 11 + [)] 11 12 + [{] 13 14 L3 - [str] 2 4 - [:=] 6 7 - ["hello world"] 9 21 + [str] 2 5 + [:=] 6 8 + ["hello world"] 9 22 L4 - [slice] 2 6 - [:=] 8 9 - [str] 11 13 - [\[] 14 14 - [4] 15 15 - [:] 16 16 - [\]] 17 17 + [slice] 2 7 + [:=] 8 10 + [str] 11 14 + [\[] 14 15 + [4] 15 16 + [:] 16 17 + [\]] 17 18 L5 - [fmt] 2 4 - [.] 5 5 - [Println] 6 12 - [(] 13 13 - [slice] 14 18 - [)] 19 19 + [fmt] 2 5 + [.] 5 6 + [Println] 6 13 + [(] 13 14 + [slice] 14 19 + [)] 19 20 L9 - [bytes] 2 6 - [:=] 8 9 - [\[] 11 11 - [\]] 12 12 - [byte] 13 16 - [(] 17 17 - [str] 18 20 - [)] 21 21 + [bytes] 2 7 + [:=] 8 10 + [\[] 11 12 + [\]] 12 13 + [byte] 13 17 + [(] 17 18 + [str] 18 21 + [)] 21 22 L10 - [bytes] 2 6 - [\[] 7 7 - [2] 8 8 - [\]] 9 9 - [=] 11 11 - ['x'] 13 15 + [bytes] 2 7 + [\[] 7 8 + [2] 8 9 + [\]] 9 10 + [=] 11 12 + ['x'] 13 16 L11 - [str] 2 4 - [=] 6 6 - [string] 8 13 - [(] 14 14 - [bytes] 15 19 - [)] 20 20 + [str] 2 5 + [=] 6 7 + [string] 8 14 + [(] 14 15 + [bytes] 15 20 + [)] 20 21 L12 - [fmt] 2 4 - [.] 5 5 - [Println] 6 12 - [(] 13 13 - [str] 14 16 - [)] 17 17 + [fmt] 2 5 + [.] 5 6 + [Println] 6 13 + [(] 13 14 + [str] 14 17 + [)] 17 18 L15 - [runes] 2 6 - [:=] 8 9 - [\[] 11 11 - [\]] 12 12 - [rune] 13 16 - [(] 17 17 - [str] 18 20 - [)] 21 21 + [runes] 2 7 + [:=] 8 10 + [\[] 11 12 + [\]] 12 13 + [rune] 13 17 + [(] 17 18 + [str] 18 21 + [)] 21 22 L16 - [runes] 2 6 - [\[] 7 7 - [0] 8 8 - [\]] 9 9 - [=] 11 11 - ['哈'] 13 15 + [runes] 2 7 + [\[] 7 8 + [0] 8 9 + [\]] 9 10 + [=] 11 12 + ['哈'] 13 16 L17 - [str] 2 4 - [=] 6 6 - [string] 8 13 - [(] 14 14 - [runes] 15 19 - [)] 20 20 + [str] 2 5 + [=] 6 7 + [string] 8 14 + [(] 14 15 + [runes] 15 20 + [)] 20 21 L18 - [fmt] 2 4 - [.] 5 5 - [Println] 6 12 - [(] 13 13 - [str] 14 16 - [)] 17 17 + [fmt] 2 5 + [.] 5 6 + [Println] 6 13 + [(] 13 14 + [str] 14 17 + [)] 17 18 L20 - [}] 1 1 + [}] 1 2 EOF diff --git a/pmd-python/src/test/resources/net/sourceforge/pmd/lang/python/cpd/testdata/sample_unicode.txt b/pmd-python/src/test/resources/net/sourceforge/pmd/lang/python/cpd/testdata/sample_unicode.txt index 9476d45ba4..ec7d598bfc 100644 --- a/pmd-python/src/test/resources/net/sourceforge/pmd/lang/python/cpd/testdata/sample_unicode.txt +++ b/pmd-python/src/test/resources/net/sourceforge/pmd/lang/python/cpd/testdata/sample_unicode.txt @@ -1,13 +1,13 @@ [Image] or [Truncated image[ Bcol Ecol L3 - [def] 1 3 - [check] 5 9 - [(] 10 10 - [)] 11 11 - [:] 12 12 + [def] 1 4 + [check] 5 10 + [(] 10 11 + [)] 11 12 + [:] 12 13 L4 - [total_cost_μs] 5 17 - [=] 19 19 - [\[] 21 21 - [\]] 22 22 + [total_cost_μs] 5 18 + [=] 19 20 + [\[] 21 22 + [\]] 22 23 EOF diff --git a/pmd-python/src/test/resources/net/sourceforge/pmd/lang/python/cpd/testdata/var_with_dollar.txt b/pmd-python/src/test/resources/net/sourceforge/pmd/lang/python/cpd/testdata/var_with_dollar.txt index 39607ea38f..07eeb8ba7d 100644 --- a/pmd-python/src/test/resources/net/sourceforge/pmd/lang/python/cpd/testdata/var_with_dollar.txt +++ b/pmd-python/src/test/resources/net/sourceforge/pmd/lang/python/cpd/testdata/var_with_dollar.txt @@ -1,13 +1,13 @@ [Image] or [Truncated image[ Bcol Ecol L1 - [def] 1 3 - [check] 5 9 - [(] 10 10 - [)] 11 11 - [:] 12 12 + [def] 1 4 + [check] 5 10 + [(] 10 11 + [)] 11 12 + [:] 12 13 L2 - [a$a] 5 7 - [=] 9 9 - [\[] 11 11 - [\]] 12 12 + [a$a] 5 8 + [=] 9 10 + [\[] 11 12 + [\]] 12 13 EOF From 108b670268cef4e850bcc77027cd6e3293d5d661 Mon Sep 17 00:00:00 2001 From: Andreas Dangel Date: Thu, 26 May 2022 15:27:14 +0200 Subject: [PATCH 119/198] Add @filipponova as a contributor --- .all-contributorsrc | 9 ++ docs/pages/pmd/projectdocs/credits.md | 157 +++++++++++++------------- 2 files changed, 88 insertions(+), 78 deletions(-) diff --git a/.all-contributorsrc b/.all-contributorsrc index 6efd00a779..85095b18fe 100644 --- a/.all-contributorsrc +++ b/.all-contributorsrc @@ -6675,6 +6675,15 @@ "contributions": [ "code" ] + }, + { + "login": "filipponova", + "name": "Filippo Nova", + "avatar_url": "https://avatars.githubusercontent.com/u/12506636?v=4", + "profile": "https://github.com/filipponova", + "contributions": [ + "bug" + ] } ], "contributorsPerLine": 7, diff --git a/docs/pages/pmd/projectdocs/credits.md b/docs/pages/pmd/projectdocs/credits.md index b00de0e0d8..48913f3d00 100644 --- a/docs/pages/pmd/projectdocs/credits.md +++ b/docs/pages/pmd/projectdocs/credits.md @@ -252,704 +252,705 @@ Thanks goes to these wonderful people ([emoji key](https://allcontributors.org/d
Felix Lampe

🐛
Filip Golonka

🐛
Filipe Esperandio

💻 🐛 +
Filippo Nova

🐛
Francesco la Torre

🐛
Francisco Duarte

🐛 -
Frieder Bluemle

🐛 +
Frieder Bluemle

🐛
Frits Jalvingh

💻 🐛
G. Bazior

🐛
Gabe Henkes

🐛
Genoud Magloire

🐛
Geoffrey555

🐛
Georg Romstorfer

🐛 -
Gio

🐛 +
Gio

🐛
Gol

🐛
Gonzalo Exequiel Ibars Ingman

💻 🐛
GooDer

🐛
Gregor Riegler

🐛
Grzegorz Olszewski

🐛
Gunther Schrijvers

💻 🐛 -
Gustavo Krieger

🐛 +
Gustavo Krieger

🐛
Guy Elsmore-Paddock

🐛
Görkem Mülayim

🐛
Hanzel Godinez

🐛
Harsh Kukreja

🐛
Heber

🐛
Henning Schmiedehausen

💻 🐛 -
Henning von Bargen

💻 +
Henning von Bargen

💻
Hervé Boutemy

🐛
Himanshu Pandey

🐛
Hokwang Lee

🐛
Hooperbloob

💻
Hung PHAN

🐛
IDoCodingStuffs

💻 🐛 -
Iccen Gan

🐛 +
Iccen Gan

🐛
Ignacio Mariano Tirabasso

🐛
Igor Melnichenko

🐛
Igor Moreno

🐛
Intelesis-MS

🐛
Iroha_

🐛
Ishan Srivastava

🐛 -
Ivano Guerini

🐛 +
Ivano Guerini

🐛
Ivar Andreas Bonsaksen

🐛
Ivo Šmíd

🐛
JJengility

🐛
Jake Hemmerle

🐛
James Harrison

🐛
Jan

🐛 -
Jan Aertgeerts

💻 🐛 +
Jan Aertgeerts

💻 🐛
Jan Brümmer

🐛
Jan Tříska

🐛
Jan-Lukas Else

🐛
Jason Qiu

💻 📖
Jason Williams

🐛
Jean-Paul Mayer

🐛 -
Jean-Simon Larochelle

🐛 +
Jean-Simon Larochelle

🐛
Jeff Bartolotta

💻 🐛
Jeff Hube

💻 🐛
Jeff Jensen

🐛
Jeff May

🐛
Jens Gerdes

🐛
Jeroen Borgers

🐛 -
Jerome Russ

🐛 +
Jerome Russ

🐛
JerritEic

💻 📖
Jiri Pejchal

🐛
Jithin Sunny

🐛
Jiří Škorpil

🐛
Joao Machado

🐛
Jochen Krauss

🐛 -
Johan Hammar

🐛 +
Johan Hammar

🐛
John Karp

🐛
John Zhang

🐛
John-Teng

💻 🐛
Jon Moroney

💻 🐛
Jonas Geiregat

🐛
Jonathan Wiesel

💻 🐛 -
Jordan

🐛 +
Jordan

🐛
Jordi Llach

🐛
Jorge Solórzano

🐛
JorneVL

🐛
Jose Palafox

🐛
Jose Stovall

🐛
Joseph

💻 -
Joseph Heenan

🐛 +
Joseph Heenan

🐛
Josh Feingold

💻 🐛
Josh Holthaus

🐛
Joshua S Arquilevich

🐛
João Ferreira

💻 🐛
João Pedro Schmitt

🐛
Juan Martín Sotuyo Dodero

💻 📖 🐛 🚧 -
Juan Pablo Civile

🐛 +
Juan Pablo Civile

🐛
Julian Voronetsky

🐛
Julien

🐛
Julius

🐛
JustPRV

🐛
Jörn Huxhorn

🐛
KThompso

🐛 -
Kai Amundsen

🐛 +
Kai Amundsen

🐛
Karel Vervaeke

🐛
Karl-Andero Mere

🐛
Karl-Philipp Richter

🐛
Karsten Silz

🐛
Kazuma Watanabe

🐛
Kev

🐛 -
Keve Müller

🐛 +
Keve Müller

🐛
Kevin Guerra

💻
Kevin Jones

🐛
Kevin Wayne

🐛
Kieran Black

🐛
Kirill Zubov

🐛
Kirk Clemens

💻 🐛 -
Klaus Hartl

🐛 +
Klaus Hartl

🐛
Koen Van Looveren

🐛
Kris Scheibe

💻 🐛
Kunal Thanki

🐛
LaLucid

💻
Larry Diamond

💻 🐛
Lars Knickrehm

🐛 -
Leo Gutierrez

🐛 +
Leo Gutierrez

🐛
LiGaOg

💻
Lintsi

🐛
Linus Fernandes

🐛
Lixon Lookose

🐛
Logesh

🐛
Lorenzo Gabriele

🐛 -
Loïc Ledoyen

🐛 +
Loïc Ledoyen

🐛
Lucas Silva

🐛
Lucas Soncini

💻 🐛
Lukasz Slonina

🐛
Lukebray

🐛
Lyor Goldstein

🐛
MCMicS

🐛 -
Macarse

🐛 +
Macarse

🐛
Machine account for PMD

💻
Maciek Siemczyk

🐛
Maikel Steneker

💻 🐛
Maksim Moiseikin

🐛
Manfred Koch

🐛
Manuel Moya Ferrer

💻 🐛 -
Manuel Ryan

🐛 +
Manuel Ryan

🐛
Marat Vyshegorodtsev

🐛
Marcel Härle

🐛
Marcello Fialho

🐛
Marcin Rataj

🐛
Mark Adamcin

🐛
Mark Hall

💻 🐛 -
Mark Kolich

🐛 +
Mark Kolich

🐛
Mark Pritchard

🐛
Markus Rathgeb

🐛
Marquis Wang

🐛
Martin Feldsztejn

🐛
Martin Lehmann

🐛
Martin Spamer

🐛 -
Martin Tarjányi

🐛 +
Martin Tarjányi

🐛
MatFl

🐛
Mateusz Stefanski

🐛
Mathieu Gouin

🐛
MatiasComercio

💻 🐛
Matt Benson

🐛
Matt De Poorter

🐛 -
Matt Harrah

🐛 +
Matt Harrah

🐛
Matt Nelson

🐛
Matthew Amos

🐛
Matthew Duggan

🐛
Matthew Hall

🐛
Matías Fraga

💻 🐛
Maxime Robert

💻 🐛 -
MetaBF

🐛 +
MetaBF

🐛
Michael

🐛
Michael Bell

🐛
Michael Bernstein

🐛
Michael Clay

🐛
Michael Dombrowski

🐛
Michael Hausegger

🐛 -
Michael Hoefer

🐛 +
Michael Hoefer

🐛
Michael Möbius

🐛
Michael N. Lipp

🐛
Michael Pellegrini

🐛
Michal Kordas

🐛
Michał Borek

🐛
Michał Kuliński

🐛 -
Miguel Núñez Díaz-Montes

🐛 +
Miguel Núñez Díaz-Montes

🐛
Mihai Ionut

🐛
Mirek Hankus

🐛
Mladjan Gadzic

🐛
MrAngry52

🐛
Muminur Choudhury

🐛
Mykhailo Palahuta

💻 🐛 -
Nagendra Kumar Singh

🐛 +
Nagendra Kumar Singh

🐛
Nahuel Barrios

🐛
Nathan Braun

🐛
Nathan Reynolds

🐛
Nathan Reynolds

🐛
Nathanaël

🐛
Naveen

💻 -
Nazdravi

🐛 +
Nazdravi

🐛
Neha-Dhonde

🐛
Nicholas Doyle

🐛
Nick Butcher

🐛
Nico Gallinal

🐛
Nicola Dal Maso

🐛
Nicolas Filotto

💻 -
Nikita Chursin

🐛 +
Nikita Chursin

🐛
Niklas Baudy

🐛
Nikolas Havrikov

🐛
Nilesh Virkar

🐛
Nimit Patel

🐛
Niranjan Harpale

🐛
Noah Sussman

🐛 -
Noah0120

🐛 +
Noah0120

🐛
Noam Tamim

🐛
Noel Grandin

🐛
Olaf Haalstra

🐛
Oleg Pavlenko

🐛
Oleksii Dykov

💻
Oliver Eikemeier

🐛 -
Olivier Parent

💻 🐛 +
Olivier Parent

💻 🐛
Ollie Abbey

💻 🐛
OverDrone

🐛
Ozan Gulle

💻 🐛
PUNEET JAIN

🐛
Parbati Bose

🐛
Paul Berg

🐛 -
Pavel Bludov

🐛 +
Pavel Bludov

🐛
Pavel Mička

🐛
Pedro Nuno Santos

🐛
Pedro Rijo

🐛
Pelisse Romain

💻 📖 🐛
Per Abich

💻
Pete Davids

🐛 -
Peter Bruin

🐛 +
Peter Bruin

🐛
Peter Chittum

💻 🐛
Peter Cudmore

🐛
Peter Kasson

🐛
Peter Kofler

🐛
Pham Hai Trung

🐛
Philip Graf

💻 🐛 -
Philip Hachey

🐛 +
Philip Hachey

🐛
Philippe Ozil

🐛
Phinehas Artemix

🐛
Phokham Nonava

🐛
Piotr Szymański

🐛
Piotrek Żygieło

💻 🐛
Pranay Jaiswal

🐛 -
Prasad Kamath

🐛 +
Prasad Kamath

🐛
Prasanna

🐛
Presh-AR

🐛
Puneet1726

🐛
Rafael Cortês

🐛
RaheemShaik999

🐛
RajeshR

💻 🐛 -
Ramachandra Mohan

🐛 +
Ramachandra Mohan

🐛
Ramel0921

🐛
Raquel Pau

🐛
Ravikiran Janardhana

🐛
Reda Benhemmouche

🐛
Renato Oliveira

💻 🐛
Rich DiCroce

🐛 -
Riot R1cket

🐛 +
Riot R1cket

🐛
Rishabh Jain

🐛
RishabhDeep Singh

🐛
Robbie Martinus

💻 🐛
Robert Henry

🐛
Robert Painsi

🐛
Robert Russell

🐛 -
Robert Sösemann

💻 📖 📢 🐛 +
Robert Sösemann

💻 📖 📢 🐛
Robert Whitebit

🐛
Robin Richtsfeld

🐛
Robin Stocker

💻 🐛
Robin Wils

🐛
RochusOest

🐛
Rodolfo Noviski

🐛 -
Rodrigo Casara

🐛 +
Rodrigo Casara

🐛
Rodrigo Fernandes

🐛
Roman Salvador

💻 🐛
Ronald Blaschke

🐛
Róbert Papp

🐛
Saikat Sengupta

🐛
Saksham Handu

🐛 -
Saladoc

🐛 +
Saladoc

🐛
Salesforce Bob Lightning

🐛
Sam Carlberg

🐛
Satoshi Kubo

🐛
Scott Kennedy

🐛
Scott Wells

🐛 💻
Scrsloota

💻 -
Sebastian Bögl

🐛 +
Sebastian Bögl

🐛
Sebastian Schuberth

🐛
Sebastian Schwarz

🐛
Sergey Gorbaty

🐛
Sergey Kozlov

🐛
Sergey Yanzin

💻 🐛
Seth Wilcox

💻 -
Shubham

💻 🐛 +
Shubham

💻 🐛
Simon Xiao

🐛
Srinivasan Venkatachalam

🐛
Stanislav Gromov

🐛
Stanislav Myachenkov

💻
Stefan Birkner

🐛
Stefan Bohn

🐛 -
Stefan Endrullis

🐛 +
Stefan Endrullis

🐛
Stefan Klöss-Schuster

🐛
Stefan Wolf

🐛
Stephan H. Wissel

🐛
Stephen

🐛
Stephen Friedrich

🐛
Steve Babula

💻 -
Stexxe

🐛 +
Stexxe

🐛
Stian Lågstad

🐛
StuartClayton5

🐛
Supun Arunoda

🐛
Suren Abrahamyan

🐛
SwatiBGupta1110

🐛
SyedThoufich

🐛 -
Szymon Sasin

🐛 +
Szymon Sasin

🐛
T-chuangxin

🐛
TERAI Atsuhiro

🐛
TIOBE Software

💻 🐛
Taylor Smock

🐛
Techeira Damián

💻 🐛
Ted Husted

🐛 -
TehBakker

🐛 +
TehBakker

🐛
The Gitter Badger

🐛
Theodoor

🐛
Thiago Henrique Hüpner

🐛
Thibault Meyer

🐛
Thomas Güttler

🐛
Thomas Jones-Low

🐛 -
Thomas Smith

💻 🐛 +
Thomas Smith

💻 🐛
ThrawnCA

🐛
Thunderforge

💻 🐛
Tim van der Lippe

🐛
Tobias Weimer

💻 🐛
Tom Daly

🐛
Tomer Figenblat

🐛 -
Tomi De Lucca

💻 🐛 +
Tomi De Lucca

💻 🐛
Torsten Kleiber

🐛
TrackerSB

🐛
Ullrich Hafner

🐛
Utku Cuhadaroglu

💻 🐛
Valentin Brandl

🐛
Valeria

🐛 -
Vasily Anisimov

🐛 +
Vasily Anisimov

🐛
Vibhor Goyal

🐛
Vickenty Fesunov

🐛
Victor Noël

🐛
Vincent Galloy

💻
Vincent HUYNH

🐛
Vincent Maurin

🐛 -
Vincent Privat

🐛 +
Vincent Privat

🐛
Vishhwas

🐛
Vitaly

🐛
Vitaly Polonetsky

🐛
Vojtech Polivka

🐛
Vsevolod Zholobov

🐛
Vyom Yadav

💻 -
Wang Shidong

🐛 +
Wang Shidong

🐛
Waqas Ahmed

🐛
Wayne J. Earl

🐛
Wchenghui

🐛
Will Winder

🐛
William Brockhus

💻 🐛
Wilson Kurniawan

🐛 -
Wim Deblauwe

🐛 +
Wim Deblauwe

🐛
Woongsik Choi

🐛
XenoAmess

💻 🐛
Yang

💻
YaroslavTER

🐛
Young Chan

💻 🐛
YuJin Kim

🐛 -
Yuri Dolzhenko

🐛 +
Yuri Dolzhenko

🐛
Yurii Dubinka

🐛
Zoltan Farkas

🐛
Zustin

🐛
aaronhurst-google

🐛
alexmodis

🐛
andreoss

🐛 -
andrey81inmd

💻 🐛 +
andrey81inmd

💻 🐛
anicoara

🐛
arunprasathav

🐛
asiercamara

🐛
astillich-igniti

💻
avesolovksyy

🐛
avishvat

🐛 -
avivmu

🐛 +
avivmu

🐛
axelbarfod1

🐛
b-3-n

🐛
balbhadra9

🐛
base23de

🐛
bergander

🐛
berkam

💻 🐛 -
breizh31

🐛 +
breizh31

🐛
caesarkim

🐛
carolyujing

🐛
cesares-basilico

🐛
chrite

🐛
cobratbq

🐛
coladict

🐛 -
cosmoJFH

🐛 +
cosmoJFH

🐛
cristalp

🐛
crunsk

🐛
cwholmes

🐛
cyberjj999

🐛
cyw3

🐛
d1ss0nanz

🐛 -
danbrycefairsailcom

🐛 +
danbrycefairsailcom

🐛
dariansanity

🐛
darrenmiliband

🐛
davidburstrom

🐛
dbirkman-paloalto

🐛
deepak-patra

🐛
dependabot[bot]

💻 🐛 -
dinesh150

🐛 +
dinesh150

🐛
diziaq

🐛
dreaminpast123

🐛
duanyanan

🐛
dutt-sanjay

🐛
dylanleung

🐛
dzeigler

🐛 -
ekkirala

🐛 +
ekkirala

🐛
emersonmoura

🐛
fairy

🐛
filiprafalowicz

💻
foxmason

🐛
frankegabor

🐛
frankl

🐛 -
freafrea

🐛 +
freafrea

🐛
fsapatin

🐛
gracia19

🐛
guo fei

🐛
gurmsc5

🐛
gwilymatgearset

💻 🐛
haigsn

🐛 -
hemanshu070

🐛 +
hemanshu070

🐛
henrik242

🐛
hongpuwu

🐛
hvbtup

💻 🐛
igniti GmbH

🐛
ilovezfs

🐛
itaigilo

🐛 -
jakivey32

🐛 +
jakivey32

🐛
jbennett2091

🐛
jcamerin

🐛
jkeener1

🐛
jmetertea

🐛
johnra2

💻
josemanuelrolon

💻 🐛 -
kabroxiko

💻 🐛 +
kabroxiko

💻 🐛
karwer

🐛
kaulonline

🐛
kdaemonv

🐛
kenji21

💻 🐛
kfranic

🐛
khalidkh

🐛 -
krzyk

🐛 +
krzyk

🐛
lasselindqvist

🐛
lihuaib

🐛
lonelyma1021

🐛
lpeddy

🐛
lujiefsi

💻
lukelukes

💻 -
lyriccoder

🐛 +
lyriccoder

🐛
marcelmore

🐛
matchbox

🐛
matthiaskraaz

🐛
meandonlyme

🐛
mikesive

🐛
milossesic

🐛 -
mriddell95

🐛 +
mriddell95

🐛
mrlzh

🐛
msloan

🐛
mucharlaravalika

🐛
mvenneman

🐛
nareshl119

🐛
nicolas-harraudeau-sonarsource

🐛 -
noerremark

🐛 +
noerremark

🐛
novsirion

🐛
oggboy

🐛
oinume

🐛
orimarko

💻 🐛
pallavi agarwal

🐛
parksungrin

🐛 -
patpatpat123

🐛 +
patpatpat123

🐛
patriksevallius

🐛
pbrajesh1

🐛
phoenix384

🐛
piotrszymanski-sc

💻
plan3d

🐛
poojasix

🐛 -
prabhushrikant

🐛 +
prabhushrikant

🐛
pujitha8783

🐛
r-r-a-j

🐛
raghujayjunk

🐛
rajeshveera

🐛
rajeswarreddy88

🐛
recdevs

🐛 -
reudismam

💻 🐛 +
reudismam

💻 🐛
rijkt

🐛
rillig-tk

🐛
rmohan20

💻 🐛
rxmicro

🐛
ryan-gustafson

💻 🐛
sabi0

🐛 -
scais

🐛 +
scais

🐛
sebbASF

🐛
sergeygorbaty

💻
shilko2013

🐛
simeonKondr

🐛
snajberk

🐛
sniperrifle2004

🐛 -
snuyanzin

🐛 💻 +
snuyanzin

🐛 💻
sratz

🐛
stonio

🐛
sturton

💻 🐛
sudharmohan

🐛
suruchidawar

🐛
svenfinitiv

🐛 -
tashiscool

🐛 +
tashiscool

🐛
test-git-hook

🐛
testation21

💻 🐛
thanosa

🐛
tiandiyixian

🐛
tobwoerk

🐛
tprouvot

🐛 -
trentchilders

🐛 +
trentchilders

🐛
triandicAnt

🐛
trishul14

🐛
tsui

🐛
winhkey

🐛
witherspore

🐛
wjljack

🐛 -
wuchiuwong

🐛 +
wuchiuwong

🐛
xingsong

🐛
xioayuge

🐛
xnYi9wRezm

💻 🐛
xuanuy

🐛
xyf0921

🐛
yalechen-cyw3

🐛 -
yasuharu-sato

🐛 +
yasuharu-sato

🐛
zenglian

🐛
zgrzyt93

💻 🐛
zh3ng

🐛
zt_soft

🐛
ztt79

🐛
zzzzfeng

🐛 -
Árpád Magosányi

🐛 +
Árpád Magosányi

🐛
任贵杰

🐛 From a40cc0bbade3817a260a591b9dd828bec0a672ea Mon Sep 17 00:00:00 2001 From: Andreas Dangel Date: Thu, 26 May 2022 16:11:19 +0200 Subject: [PATCH 120/198] [java] Fix rule UseArraysAsList --- pmd-java/src/main/resources/category/java/performance.xml | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/pmd-java/src/main/resources/category/java/performance.xml b/pmd-java/src/main/resources/category/java/performance.xml index ded5309b48..3b3be08128 100644 --- a/pmd-java/src/main/resources/category/java/performance.xml +++ b/pmd-java/src/main/resources/category/java/performance.xml @@ -671,8 +671,8 @@ You must use `new ArrayList<>(Arrays.asList(...))` if that is inconvenient for y [VariableDeclarator[NumericLiteral[@IntLiteral][@Image = '0']]] ] ] - [not(.//IfStatement)] - /*[last()]// + [*[2]//FieldAccess[@Name = 'length']/VariableAccess[pmd-java:typeIs("java.lang.Object[]")]] + /*[last()]/ExpressionStatement/ MethodCall [pmd-java:matchesSig('java.util.Collection#add(_)')] [ArgumentList/ArrayAccess @@ -680,9 +680,8 @@ You must use `new ArrayList<>(Arrays.asList(...))` if that is inconvenient for y ] | //ForeachStatement - [not(.//IfStatement)] [VariableAccess[pmd-java:typeIs("java.lang.Object[]")]] - /*[last()]//MethodCall + /*[last()]/ExpressionStatement/MethodCall [pmd-java:matchesSig('java.util.Collection#add(_)')] [ArgumentList [VariableAccess[@Name = ancestor::ForeachStatement/LocalVariableDeclaration/VariableDeclarator/VariableDeclaratorId/@Name]] From 3d898527ee30883a6b7f9503a4a39189d7330686 Mon Sep 17 00:00:00 2001 From: Andreas Dangel Date: Thu, 26 May 2022 18:45:30 +0200 Subject: [PATCH 121/198] [html] Add additional file extensions htm, xhtml, xht, shtml xhtml and xht is application/xhtml+xml shtml is text/html with server side includes --- .../java/net/sourceforge/pmd/lang/html/HtmlLanguageModule.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pmd-html/src/main/java/net/sourceforge/pmd/lang/html/HtmlLanguageModule.java b/pmd-html/src/main/java/net/sourceforge/pmd/lang/html/HtmlLanguageModule.java index d3389fe55c..e9614c1e3e 100644 --- a/pmd-html/src/main/java/net/sourceforge/pmd/lang/html/HtmlLanguageModule.java +++ b/pmd-html/src/main/java/net/sourceforge/pmd/lang/html/HtmlLanguageModule.java @@ -13,7 +13,7 @@ public final class HtmlLanguageModule extends BaseLanguageModule { public static final String TERSE_NAME = "html"; public HtmlLanguageModule() { - super(NAME, null, TERSE_NAME, "html"); + super(NAME, null, TERSE_NAME, "html", "htm", "xhtml", "xht", "shtml"); addDefaultVersion("", new HtmlHandler()); } From 0eb745e1871da1fb96b2594faf9c618b677a578c Mon Sep 17 00:00:00 2001 From: Andreas Dangel Date: Thu, 26 May 2022 18:48:26 +0200 Subject: [PATCH 122/198] [doc] Update release notes (#3978) --- docs/pages/release_notes.md | 1 + 1 file changed, 1 insertion(+) diff --git a/docs/pages/release_notes.md b/docs/pages/release_notes.md index 9cf3b8ec60..495178e05a 100644 --- a/docs/pages/release_notes.md +++ b/docs/pages/release_notes.md @@ -46,6 +46,7 @@ the CPD GUI. See [#3974](https://github.com/pmd/pmd/pull/3974) for details. * [#2752](https://github.com/pmd/pmd/issues/2752): \[go] Error parsing unicode values * html * [#3955](https://github.com/pmd/pmd/pull/3955): \[html] Improvements for handling text and comment nodes + * [#3978](https://github.com/pmd/pmd/pull/3978): \[html] Add additional file extensions htm, xhtml, xht, shtml * java * [#3423](https://github.com/pmd/pmd/issues/3423): \[java] Error processing identifiers with Unicode * java-bestpractices From e530bff3f938eb226e1bffa5cd33c549739be5ed Mon Sep 17 00:00:00 2001 From: Andreas Dangel Date: Thu, 26 May 2022 20:13:22 +0200 Subject: [PATCH 123/198] [core] Internalize CPDCommandLineInterface Fixes #3835 --- docs/pages/release_notes.md | 10 +++ .../java/net/sourceforge/pmd/cpd/CPD.java | 73 +++++++++++++++++- .../pmd/cpd/CPDCommandLineInterface.java | 76 +++++++++---------- .../pmd/cpd/CPDCommandLineInterfaceTest.java | 21 ++--- .../pmd/cpd/CPDCommandLineInterfaceTest.java | 38 +++------- .../pmd/cpd/CPDCommandLineInterfaceTest.java | 8 +- .../sourceforge/pmd/cli/BaseCPDCLITest.java | 15 ++++ 7 files changed, 153 insertions(+), 88 deletions(-) diff --git a/docs/pages/release_notes.md b/docs/pages/release_notes.md index 9cf3b8ec60..f0faefbaad 100644 --- a/docs/pages/release_notes.md +++ b/docs/pages/release_notes.md @@ -39,6 +39,7 @@ the CPD GUI. See [#3974](https://github.com/pmd/pmd/pull/3974) for details. * cli * [#1445](https://github.com/pmd/pmd/issues/1445): \[core] Allow CLI to take globs as parameters * core + * [#3835](https://github.com/pmd/pmd/issues/3835): \[core] Deprecate system properties of CPDCommandLineInterface * [#3942](https://github.com/pmd/pmd/issues/3942): \[core] common-io path traversal vulnerability (CVE-2021-29425) * cs (c#) * [#3974](https://github.com/pmd/pmd/pull/3974): \[cs] Add option to ignore C# attributes (annotations) @@ -69,6 +70,15 @@ the CPD GUI. See [#3974](https://github.com/pmd/pmd/pull/3974) for details. {% jdoc core::PMDConfiguration#setInputPaths(java.lang.String) %} are now deprecated. A new set of methods have been added, which use lists and do not rely on comma splitting. +#### Internal API + +Those APIs are not intended to be used by clients, and will be hidden or removed with PMD 7.0.0. +You can identify them with the `@InternalApi` annotation. You'll also get a deprecation warning. + +- {% jdoc core::cpd.CPDCommandLineInterface %} has been internalized. In order to execute CPD either +{% jdoc !!core::cpd.CPD#run(String...) %} or {% jdoc !!core::cpd.CPD#main(String[]) %} should be used. +- Several members of {% jdoc test::cli.BaseCPDCLITest %} have been deprecated with replacements. + ### External Contributions * [#3961](https://github.com/pmd/pmd/pull/3961): \[java] Fix #3954 - NPE in UseCollectionIsEmptyRule with record - [@flyhard](https://github.com/flyhard) diff --git a/pmd-core/src/main/java/net/sourceforge/pmd/cpd/CPD.java b/pmd-core/src/main/java/net/sourceforge/pmd/cpd/CPD.java index 130791c123..47bc1c021c 100644 --- a/pmd-core/src/main/java/net/sourceforge/pmd/cpd/CPD.java +++ b/pmd-core/src/main/java/net/sourceforge/pmd/cpd/CPD.java @@ -4,9 +4,11 @@ package net.sourceforge.pmd.cpd; +import java.io.BufferedWriter; import java.io.File; import java.io.FileNotFoundException; import java.io.IOException; +import java.io.OutputStreamWriter; import java.util.ArrayList; import java.util.HashSet; import java.util.Iterator; @@ -18,6 +20,7 @@ import java.util.logging.Level; import java.util.logging.Logger; import net.sourceforge.pmd.annotation.Experimental; +import net.sourceforge.pmd.cli.internal.CliMessages; import net.sourceforge.pmd.lang.ast.TokenMgrError; import net.sourceforge.pmd.util.FileFinder; import net.sourceforge.pmd.util.IOUtil; @@ -172,7 +175,75 @@ public class CPD { return new ArrayList<>(source.values()); } + /** + * Entry to invoke CPD as command line tool. Note that this will + * invoke {@link System#exit(int)}. + * + * @param args command line arguments + */ public static void main(String[] args) { - CPDCommandLineInterface.main(args); + StatusCode statusCode = runCpd(args); + CPDCommandLineInterface.setStatusCodeOrExit(statusCode.toInt()); + } + + /** + * Parses the command line and executes CPD. Returns the status code + * without exiting the VM. + * + * @param args command line arguments + * + * @return the status code + */ + public static StatusCode runCpd(String... args) { + CPDConfiguration arguments = new CPDConfiguration(); + CPD.StatusCode statusCode = CPDCommandLineInterface.parseArgs(arguments, args); + if (statusCode != null) { + return statusCode; + } + + CPD cpd = new CPD(arguments); + + try { + CPDCommandLineInterface.addSourceFilesToCPD(cpd, arguments); + + cpd.go(); + if (arguments.getCPDRenderer() == null) { + // legacy writer + System.out.println(arguments.getRenderer().render(cpd.getMatches())); + } else { + arguments.getCPDRenderer().render(cpd.getMatches(), new BufferedWriter(new OutputStreamWriter(System.out))); + } + if (cpd.getMatches().hasNext()) { + if (arguments.isFailOnViolation()) { + statusCode = StatusCode.DUPLICATE_CODE_FOUND; + } else { + statusCode = StatusCode.OK; + } + } else { + statusCode = StatusCode.OK; + } + } catch (IOException | RuntimeException e) { + e.printStackTrace(); + LOGGER.severe(CliMessages.errorDetectedMessage(1, CPDCommandLineInterface.PROGRAM_NAME)); + statusCode = StatusCode.ERROR; + } + return statusCode; + } + + public enum StatusCode { + OK(0), + ERROR(1), + DUPLICATE_CODE_FOUND(4); + + private final int code; + + StatusCode(int code) { + this.code = code; + } + + /** Returns the exit code as used in CLI. */ + public int toInt() { + return this.code; + } } } diff --git a/pmd-core/src/main/java/net/sourceforge/pmd/cpd/CPDCommandLineInterface.java b/pmd-core/src/main/java/net/sourceforge/pmd/cpd/CPDCommandLineInterface.java index 24eef6eea1..e43e8f8366 100644 --- a/pmd-core/src/main/java/net/sourceforge/pmd/cpd/CPDCommandLineInterface.java +++ b/pmd-core/src/main/java/net/sourceforge/pmd/cpd/CPDCommandLineInterface.java @@ -4,11 +4,9 @@ package net.sourceforge.pmd.cpd; -import java.io.BufferedWriter; import java.io.File; import java.io.FileNotFoundException; import java.io.IOException; -import java.io.OutputStreamWriter; import java.net.URISyntaxException; import java.util.ArrayList; import java.util.Arrays; @@ -17,32 +15,49 @@ import java.util.HashSet; import java.util.LinkedHashMap; import java.util.List; import java.util.Map; -import java.util.Map.Entry; import java.util.logging.Logger; import net.sourceforge.pmd.PMD; import net.sourceforge.pmd.PMDVersion; +import net.sourceforge.pmd.annotation.InternalApi; import net.sourceforge.pmd.cli.internal.CliMessages; +import net.sourceforge.pmd.cpd.CPD.StatusCode; import net.sourceforge.pmd.util.FileUtil; import net.sourceforge.pmd.util.database.DBURI; import com.beust.jcommander.JCommander; import com.beust.jcommander.ParameterException; +/** + * @deprecated Internal API. Use {@link CPD#runCpd(String...)} or {@link CPD#main(String[])} + * in order to execute CPD. + */ +@Deprecated +@InternalApi public final class CPDCommandLineInterface { private static final Logger LOGGER = Logger.getLogger(CPDCommandLineInterface.class.getName()); - private static final int NO_ERRORS_STATUS = 0; - private static final int ERROR_STATUS = 1; - private static final int DUPLICATE_CODE_FOUND = 4; - + /** + * @deprecated This is used for testing, but support for it will be removed in PMD 7. + * Use {@link CPD#runCpd(String...)} to avoid exiting the VM. In PMD 7, + * {@link CPD#main(String[])} will call {@link System#exit(int)} always. + */ + @Deprecated public static final String NO_EXIT_AFTER_RUN = "net.sourceforge.pmd.cli.noExit"; + + /** + * @deprecated This is used for testing, but support for it will be removed in PMD 7. + * Use {@link CPD#runCpd(String...)} to avoid exiting the VM. In PMD 7, + * {@link CPD#main(String[])} will call {@link System#exit(int)} always. + */ + @Deprecated public static final String STATUS_CODE_PROPERTY = "net.sourceforge.pmd.cli.status"; - private static final String PROGRAM_NAME = "cpd"; + static final String PROGRAM_NAME = "cpd"; private CPDCommandLineInterface() { } + @Deprecated public static void setStatusCodeOrExit(int status) { if (isExitAfterRunSet()) { System.exit(status); @@ -63,8 +78,7 @@ public final class CPDCommandLineInterface { System.setProperty(STATUS_CODE_PROPERTY, Integer.toString(statusCode)); } - public static void main(String[] args) { - CPDConfiguration arguments = new CPDConfiguration(); + static StatusCode parseArgs(CPDConfiguration arguments, String... args) { JCommander jcommander = new JCommander(arguments); jcommander.setProgramName(PROGRAM_NAME); @@ -73,19 +87,17 @@ public final class CPDCommandLineInterface { if (arguments.isHelp()) { jcommander.usage(); System.out.println(buildUsageText()); - setStatusCodeOrExit(NO_ERRORS_STATUS); - return; + return StatusCode.OK; } } catch (ParameterException e) { System.err.println(e.getMessage()); System.err.println(CliMessages.runWithHelpFlagMessage()); - setStatusCodeOrExit(ERROR_STATUS); - return; + return StatusCode.ERROR; } Map deprecatedOptions = filterDeprecatedOptions(args); if (!deprecatedOptions.isEmpty()) { - Entry first = deprecatedOptions.entrySet().iterator().next(); + Map.Entry first = deprecatedOptions.entrySet().iterator().next(); LOGGER.warning("Some deprecated options were used on the command-line, including " + first.getKey()); LOGGER.warning("Consider replacing it with " + first.getValue()); } @@ -94,32 +106,16 @@ public final class CPDCommandLineInterface { // Pass extra parameters as System properties to allow language // implementation to retrieve their associate values... CPDConfiguration.setSystemProperties(arguments); - CPD cpd = new CPD(arguments); - try { - addSourceFilesToCPD(cpd, arguments); + return null; + } - cpd.go(); - if (arguments.getCPDRenderer() == null) { - // legacy writer - System.out.println(arguments.getRenderer().render(cpd.getMatches())); - } else { - arguments.getCPDRenderer().render(cpd.getMatches(), new BufferedWriter(new OutputStreamWriter(System.out))); - } - if (cpd.getMatches().hasNext()) { - if (arguments.isFailOnViolation()) { - setStatusCodeOrExit(DUPLICATE_CODE_FOUND); - } else { - setStatusCodeOrExit(NO_ERRORS_STATUS); - } - } else { - setStatusCodeOrExit(NO_ERRORS_STATUS); - } - } catch (IOException | RuntimeException e) { - e.printStackTrace(); - LOGGER.severe(CliMessages.errorDetectedMessage(1, "CPD")); - setStatusCodeOrExit(ERROR_STATUS); - } + /** + * @deprecated Use {@link CPD#main(String[])} + */ + @Deprecated + public static void main(String[] args) { + setStatusCodeOrExit(CPD.runCpd(args).toInt()); } private static Map filterDeprecatedOptions(String... args) { @@ -211,6 +207,8 @@ public final class CPDCommandLineInterface { } } + @Deprecated + @InternalApi public static String buildUsageText() { String helpText = " For example on Windows:" + PMD.EOL; diff --git a/pmd-core/src/test/java/net/sourceforge/pmd/cpd/CPDCommandLineInterfaceTest.java b/pmd-core/src/test/java/net/sourceforge/pmd/cpd/CPDCommandLineInterfaceTest.java index 4195438252..2a04e0120b 100644 --- a/pmd-core/src/test/java/net/sourceforge/pmd/cpd/CPDCommandLineInterfaceTest.java +++ b/pmd-core/src/test/java/net/sourceforge/pmd/cpd/CPDCommandLineInterfaceTest.java @@ -14,13 +14,10 @@ import java.nio.file.Files; import java.util.Arrays; import org.junit.Assert; -import org.junit.Before; import org.junit.Rule; import org.junit.Test; -import org.junit.contrib.java.lang.system.RestoreSystemProperties; import org.junit.contrib.java.lang.system.SystemOutRule; import org.junit.rules.TemporaryFolder; -import org.junit.rules.TestRule; import net.sourceforge.pmd.PMD; import net.sourceforge.pmd.junit.JavaUtilLoggingRule; @@ -28,8 +25,6 @@ import net.sourceforge.pmd.junit.JavaUtilLoggingRule; public class CPDCommandLineInterfaceTest { private static final String SRC_DIR = "src/test/resources/net/sourceforge/pmd/cpd/files/"; - @Rule - public final TestRule restoreSystemProperties = new RestoreSystemProperties(); @Rule public final SystemOutRule log = new SystemOutRule().enableLog().muteForSuccessfulTests(); @Rule @@ -38,15 +33,11 @@ public class CPDCommandLineInterfaceTest { public TemporaryFolder tempDir = new TemporaryFolder(); - @Before - public void setup() { - System.setProperty(CPDCommandLineInterface.NO_EXIT_AFTER_RUN, "true"); - } - @Test public void testEmptyResultRendering() { - CPDCommandLineInterface.main(new String[] { "--minimum-tokens", "340", "--language", "java", "--files", - SRC_DIR, "--format", "xml", }); + CPD.StatusCode statusCode = CPD.runCpd("--minimum-tokens", "340", "--language", "java", "--files", + SRC_DIR, "--format", "xml"); + Assert.assertEquals(CPD.StatusCode.OK, statusCode); Assert.assertEquals("" + "\n" + "", log.getLog()); } @@ -57,14 +48,14 @@ public class CPDCommandLineInterfaceTest { new File(SRC_DIR, "dup1.java").getAbsolutePath(), new File(SRC_DIR, "dup2.java").getAbsolutePath()), StandardCharsets.UTF_8); - CPDCommandLineInterface.main(new String[] { "--minimum-tokens", "340", "--language", "java", "--filelist", - filelist.getAbsolutePath(), "--format", "xml", "-failOnViolation", "true" }); + CPD.StatusCode statusCode = CPD.runCpd("--minimum-tokens", "340", "--language", "java", "--filelist", + filelist.getAbsolutePath(), "--format", "xml", "-failOnViolation", "true"); + Assert.assertEquals(CPD.StatusCode.OK, statusCode); Assert.assertEquals("" + "\n" + "", log.getLog()); assertTrue(loggingRule.getLog().contains("Some deprecated options were used on the command-line, including -failOnViolation")); assertTrue(loggingRule.getLog().contains("Consider replacing it with --fail-on-violation")); // only one parameter is logged assertFalse(loggingRule.getLog().contains("Some deprecated options were used on the command-line, including --filelist")); assertFalse(loggingRule.getLog().contains("Consider replacing it with --file-list")); - } } diff --git a/pmd-java/src/test/java/net/sourceforge/pmd/cpd/CPDCommandLineInterfaceTest.java b/pmd-java/src/test/java/net/sourceforge/pmd/cpd/CPDCommandLineInterfaceTest.java index 3bbf718134..a43be3d6d9 100644 --- a/pmd-java/src/test/java/net/sourceforge/pmd/cpd/CPDCommandLineInterfaceTest.java +++ b/pmd-java/src/test/java/net/sourceforge/pmd/cpd/CPDCommandLineInterfaceTest.java @@ -21,13 +21,10 @@ public class CPDCommandLineInterfaceTest extends BaseCPDCLITest { * Test ignore identifiers argument. */ @Test - public void testIgnoreIdentifiers() throws Exception { - runCPD("--minimum-tokens", "34", "--language", "java", "--files", + public void testIgnoreIdentifiers() { + String out = runTest(CPD.StatusCode.DUPLICATE_CODE_FOUND, "--minimum-tokens", "34", "--language", "java", "--files", "src/test/resources/net/sourceforge/pmd/cpd/clitest/", "--ignore-identifiers"); - - String out = getOutput(); Assert.assertTrue(out.contains("Found a 7 line (36 tokens) duplication")); - Assert.assertEquals(4, Integer.parseInt(System.getProperty(CPDCommandLineInterface.STATUS_CODE_PROPERTY))); } /** @@ -35,13 +32,10 @@ public class CPDCommandLineInterfaceTest extends BaseCPDCLITest { */ @Test public void testIgnoreIdentifiersFailOnViolationFalse() throws Exception { - runCPD("--minimum-tokens", "34", "--language", "java", "--files", + String out = runTest(CPD.StatusCode.OK, "--minimum-tokens", "34", "--language", "java", "--files", "src/test/resources/net/sourceforge/pmd/cpd/clitest/", "--ignore-identifiers", "--failOnViolation", "false"); - - String out = getOutput(); Assert.assertTrue(out.contains("Found a 7 line (36 tokens) duplication")); - Assert.assertEquals(0, Integer.parseInt(System.getProperty(CPDCommandLineInterface.STATUS_CODE_PROPERTY))); } /** @@ -49,13 +43,10 @@ public class CPDCommandLineInterfaceTest extends BaseCPDCLITest { */ @Test public void testIgnoreIdentifiersFailOnViolationFalseLongOption() throws Exception { - runCPD("--minimum-tokens", "34", "--language", "java", "--files", + String out = runTest(CPD.StatusCode.OK, "--minimum-tokens", "34", "--language", "java", "--files", "src/test/resources/net/sourceforge/pmd/cpd/clitest/", "--ignore-identifiers", "--fail-on-violation", "false"); - - String out = getOutput(); Assert.assertTrue(out.contains("Found a 7 line (36 tokens) duplication")); - Assert.assertEquals(0, Integer.parseInt(System.getProperty(CPDCommandLineInterface.STATUS_CODE_PROPERTY))); } /** @@ -63,13 +54,10 @@ public class CPDCommandLineInterfaceTest extends BaseCPDCLITest { */ @Test public void testExcludes() throws Exception { - runCPD("--minimum-tokens", "34", "--language", "java", "--ignore-identifiers", "--files", + String out = runTest(CPD.StatusCode.OK, "--minimum-tokens", "34", "--language", "java", "--ignore-identifiers", "--files", "src/test/resources/net/sourceforge/pmd/cpd/clitest/", "--exclude", "src/test/resources/net/sourceforge/pmd/cpd/clitest/File2.java"); - - String out = getOutput(); Assert.assertFalse(out.contains("Found a 7 line (34 tokens) duplication")); - Assert.assertEquals(0, Integer.parseInt(System.getProperty(CPDCommandLineInterface.STATUS_CODE_PROPERTY))); } /** @@ -82,17 +70,15 @@ public class CPDCommandLineInterfaceTest extends BaseCPDCLITest { // set the default encoding under Windows System.setProperty("file.encoding", "Cp1252"); - runCPD("--minimum-tokens", "34", "--language", "java", "--files", + String out = runTest(CPD.StatusCode.DUPLICATE_CODE_FOUND, "--minimum-tokens", "34", "--language", "java", "--files", "src/test/resources/net/sourceforge/pmd/cpd/clitest/", "--ignore-identifiers", "--format", "xml", // request UTF-8 for CPD "--encoding", "UTF-8"); // reset default encoding System.setProperty("file.encoding", origEncoding); - String out = getOutput(); Assert.assertTrue(out.startsWith("")); Assert.assertTrue(Pattern.compile("System\\.out\\.println\\([ij] \\+ \"ä\"\\);").matcher(out).find()); - Assert.assertEquals(4, Integer.parseInt(System.getProperty(CPDCommandLineInterface.STATUS_CODE_PROPERTY))); } /** @@ -103,30 +89,24 @@ public class CPDCommandLineInterfaceTest extends BaseCPDCLITest { */ @Test public void testBrokenAndValidFile() throws IOException { - runCPD("--minimum-tokens", "10", "--language", "java", "--files", + String out = runTest(CPD.StatusCode.DUPLICATE_CODE_FOUND, "--minimum-tokens", "10", "--language", "java", "--files", "src/test/resources/net/sourceforge/pmd/cpd/badandgood/", "--format", "text", "--skip-lexical-errors"); - String out = getOutput(); Assert.assertTrue( Pattern.compile("Skipping .*?BadFile\\.java\\. Reason: Lexical error in file").matcher(out).find()); Assert.assertTrue(out.contains("Found a 5 line (13 tokens) duplication")); - Assert.assertEquals(4, Integer.parseInt(System.getProperty(CPDCommandLineInterface.STATUS_CODE_PROPERTY))); } @Test public void testFormatXmlWithoutEncoding() throws Exception { - runCPD("--minimum-tokens", "10", "--language", "java", "--files", + String out = runTest(CPD.StatusCode.DUPLICATE_CODE_FOUND, "--minimum-tokens", "10", "--language", "java", "--files", "src/test/resources/net/sourceforge/pmd/cpd/clitest/", "--format", "xml"); - String out = getOutput(); Assert.assertTrue(out.contains("")); - Assert.assertEquals(4, Integer.parseInt(System.getProperty(CPDCommandLineInterface.STATUS_CODE_PROPERTY))); } @Test public void testCSVFormat() throws Exception { - runCPD("--minimum-tokens", "100", "--files", "src/test/resources/net/sourceforge/pmd/cpd/badandgood/", + String out = runTest(CPD.StatusCode.OK, "--minimum-tokens", "100", "--files", "src/test/resources/net/sourceforge/pmd/cpd/badandgood/", "--language", "c", "--format", "csv"); - String out = getOutput(); Assert.assertFalse(out.contains("Couldn't instantiate renderer")); - Assert.assertEquals(0, Integer.parseInt(System.getProperty(CPDCommandLineInterface.STATUS_CODE_PROPERTY))); } } diff --git a/pmd-javascript/src/test/java/net/sourceforge/pmd/cpd/CPDCommandLineInterfaceTest.java b/pmd-javascript/src/test/java/net/sourceforge/pmd/cpd/CPDCommandLineInterfaceTest.java index 4b92f726e5..c6b4df8f27 100644 --- a/pmd-javascript/src/test/java/net/sourceforge/pmd/cpd/CPDCommandLineInterfaceTest.java +++ b/pmd-javascript/src/test/java/net/sourceforge/pmd/cpd/CPDCommandLineInterfaceTest.java @@ -15,18 +15,18 @@ import net.sourceforge.pmd.cli.BaseCPDCLITest; public class CPDCommandLineInterfaceTest extends BaseCPDCLITest { @Test public void shouldFindDuplicatesWithDifferentFileExtensions() { - runCPD("--minimum-tokens", "5", "--language", "js", "--files", + String out = runTest(CPD.StatusCode.DUPLICATE_CODE_FOUND, "--minimum-tokens", "5", "--language", "js", "--files", "src/test/resources/net/sourceforge/pmd/cpd/ts/File1.ts", "src/test/resources/net/sourceforge/pmd/cpd/ts/File2.ts"); - assertThat(getOutput(), containsString("Found a 9 line (32 tokens) duplication in the following files")); + assertThat(out, containsString("Found a 9 line (32 tokens) duplication in the following files")); } @Test public void shouldFindNoDuplicatesWithDifferentFileExtensions() { - runCPD("--minimum-tokens", "5", "--language", "js", "--files", + String out = runTest(CPD.StatusCode.OK, "--minimum-tokens", "5", "--language", "js", "--files", "src/test/resources/net/sourceforge/pmd/cpd/ts/"); - assertThat(getOutput().trim(), emptyString()); + assertThat(out.trim(), emptyString()); } } diff --git a/pmd-test/src/main/java/net/sourceforge/pmd/cli/BaseCPDCLITest.java b/pmd-test/src/main/java/net/sourceforge/pmd/cli/BaseCPDCLITest.java index 5fb8ad8335..3380d7acc4 100644 --- a/pmd-test/src/main/java/net/sourceforge/pmd/cli/BaseCPDCLITest.java +++ b/pmd-test/src/main/java/net/sourceforge/pmd/cli/BaseCPDCLITest.java @@ -9,6 +9,7 @@ import java.io.PrintStream; import java.io.UnsupportedEncodingException; import org.junit.After; +import org.junit.Assert; import org.junit.Before; import net.sourceforge.pmd.cpd.CPD; @@ -34,6 +35,10 @@ public abstract class BaseCPDCLITest { System.setErr(originalStderr); } + /** + * @deprecated Use {@link #runTest(CPD.StatusCode, String...)} which returns the output. + */ + @Deprecated public final String getOutput() { try { return bufferStdout.toString("UTF-8"); @@ -42,8 +47,18 @@ public abstract class BaseCPDCLITest { } } + /** + * @deprecated Use {@link #runTest(CPD.StatusCode, String...)} + */ + @Deprecated protected void runCPD(String... args) { System.setProperty(CPDCommandLineInterface.NO_EXIT_AFTER_RUN, "true"); CPD.main(args); } + + protected String runTest(CPD.StatusCode expectedStatusCode, String... args) { + CPD.StatusCode statusCode = CPD.runCpd(args); + Assert.assertEquals("Unexpected status code", expectedStatusCode, statusCode); + return getOutput(); + } } From 4bc13520f0082b9214b50c95ddd2703389af8761 Mon Sep 17 00:00:00 2001 From: Andreas Dangel Date: Thu, 26 May 2022 20:34:47 +0200 Subject: [PATCH 124/198] [core] Internalize some methods in Ant Formatter - Fixes #3787 --- docs/pages/release_notes.md | 10 ++++++++++ .../main/java/net/sourceforge/pmd/ant/Formatter.java | 9 +++++++++ 2 files changed, 19 insertions(+) diff --git a/docs/pages/release_notes.md b/docs/pages/release_notes.md index 9cf3b8ec60..df36887951 100644 --- a/docs/pages/release_notes.md +++ b/docs/pages/release_notes.md @@ -39,6 +39,7 @@ the CPD GUI. See [#3974](https://github.com/pmd/pmd/pull/3974) for details. * cli * [#1445](https://github.com/pmd/pmd/issues/1445): \[core] Allow CLI to take globs as parameters * core + * [#3787](https://github.com/pmd/pmd/issues/3787): \[core] Internalize some methods in Ant Formatter * [#3942](https://github.com/pmd/pmd/issues/3942): \[core] common-io path traversal vulnerability (CVE-2021-29425) * cs (c#) * [#3974](https://github.com/pmd/pmd/pull/3974): \[cs] Add option to ignore C# attributes (annotations) @@ -69,6 +70,15 @@ the CPD GUI. See [#3974](https://github.com/pmd/pmd/pull/3974) for details. {% jdoc core::PMDConfiguration#setInputPaths(java.lang.String) %} are now deprecated. A new set of methods have been added, which use lists and do not rely on comma splitting. +#### Internal API + +Those APIs are not intended to be used by clients, and will be hidden or removed with PMD 7.0.0. +You can identify them with the `@InternalApi` annotation. You'll also get a deprecation warning. + +- The methods {% jdoc !!core::ant.Formatter#start(java.lang.String) %}, +{% jdoc !!core::ant.Formatter#end(net.sourceforge.pmd.Report) %}, {% jdoc !!core::ant.Formatter#getRenderer() %}, +and {% jdoc !!core::ant.Formatter#isNoOutputSupplied() %} have been internalized. + ### External Contributions * [#3961](https://github.com/pmd/pmd/pull/3961): \[java] Fix #3954 - NPE in UseCollectionIsEmptyRule with record - [@flyhard](https://github.com/flyhard) diff --git a/pmd-core/src/main/java/net/sourceforge/pmd/ant/Formatter.java b/pmd-core/src/main/java/net/sourceforge/pmd/ant/Formatter.java index e248dc6f18..37c4c190f2 100644 --- a/pmd-core/src/main/java/net/sourceforge/pmd/ant/Formatter.java +++ b/pmd-core/src/main/java/net/sourceforge/pmd/ant/Formatter.java @@ -61,10 +61,14 @@ public class Formatter { this.parameters.add(parameter); } + @Deprecated + @InternalApi public Renderer getRenderer() { return renderer; } + @Deprecated + @InternalApi public void start(String baseDir) { Properties properties = createProperties(); @@ -111,6 +115,8 @@ public class Formatter { } } + @Deprecated + @InternalApi public void end(Report errorReport) { try { renderer.renderFileReport(errorReport); @@ -125,6 +131,8 @@ public class Formatter { } } + @Deprecated + @InternalApi public boolean isNoOutputSupplied() { return toFile == null && !toConsole; } @@ -233,6 +241,7 @@ public class Formatter { return null; } + @Deprecated @InternalApi public Renderer toRenderer(final Project project, List inputPaths) { this.start(project.getBaseDir().toString()); From 42b4f366bce9a6603dd2e72e4f27be286b378e2d Mon Sep 17 00:00:00 2001 From: Andreas Dangel Date: Thu, 26 May 2022 20:39:06 +0200 Subject: [PATCH 125/198] [doc] Fix javadoc refs in release notes --- docs/pages/release_notes.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/docs/pages/release_notes.md b/docs/pages/release_notes.md index f0faefbaad..85abc05c9a 100644 --- a/docs/pages/release_notes.md +++ b/docs/pages/release_notes.md @@ -76,7 +76,8 @@ Those APIs are not intended to be used by clients, and will be hidden or removed You can identify them with the `@InternalApi` annotation. You'll also get a deprecation warning. - {% jdoc core::cpd.CPDCommandLineInterface %} has been internalized. In order to execute CPD either -{% jdoc !!core::cpd.CPD#run(String...) %} or {% jdoc !!core::cpd.CPD#main(String[]) %} should be used. +{% jdoc !!core::cpd.CPD#run(java.lang.String...) %} or {% jdoc !!core::cpd.CPD#main(java.lang.String[]) %} +should be used. - Several members of {% jdoc test::cli.BaseCPDCLITest %} have been deprecated with replacements. ### External Contributions From 0ef01e0fb556d95f9bad84f712c94dd28a84fd01 Mon Sep 17 00:00:00 2001 From: Andreas Dangel Date: Fri, 27 May 2022 14:47:43 +0200 Subject: [PATCH 126/198] [java] EmptyControlStatement: Fix NPE for if without else --- .../codestyle/EmptyControlStatementRule.java | 4 +- .../codestyle/xml/EmptyControlStatement.xml | 91 ++++++++++++++++++- 2 files changed, 90 insertions(+), 5 deletions(-) diff --git a/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/rule/codestyle/EmptyControlStatementRule.java b/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/rule/codestyle/EmptyControlStatementRule.java index 47bb4ced13..5de4bca7ed 100644 --- a/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/rule/codestyle/EmptyControlStatementRule.java +++ b/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/rule/codestyle/EmptyControlStatementRule.java @@ -80,8 +80,8 @@ public class EmptyControlStatementRule extends AbstractJavaRule { if (isEmpty(node.getThenBranch().getChild(0))) { addViolation(data, node, "Empty if statement"); } - if (isEmpty(node.getElseBranch().getChild(0))) { - addViolation(data, node, "Empty else statement"); + if (node.hasElse() && isEmpty(node.getElseBranch().getChild(0))) { + addViolation(data, node.getElseBranch(), "Empty else statement"); } return null; } diff --git a/pmd-java/src/test/resources/net/sourceforge/pmd/lang/java/rule/codestyle/xml/EmptyControlStatement.xml b/pmd-java/src/test/resources/net/sourceforge/pmd/lang/java/rule/codestyle/xml/EmptyControlStatement.xml index e4e3921737..69275f3bc9 100644 --- a/pmd-java/src/test/resources/net/sourceforge/pmd/lang/java/rule/codestyle/xml/EmptyControlStatement.xml +++ b/pmd-java/src/test/resources/net/sourceforge/pmd/lang/java/rule/codestyle/xml/EmptyControlStatement.xml @@ -185,7 +185,7 @@ - failure case (non static) + empty initializer failure case (non static) 1 - failure case (static) + empty initializer failure case (static) 1 - not an initializer + not an initializer - empty statement block 1 + + + one empty if statement + 1 + 3 + 2) { + } + } +} + ]]> + + + + empty if with else statement + 2 + 3,4 + 2) { + } else { + } + } +} + ]]> + + + + empty if with else and else if statement + 3 + 3,4,5 + 2) { + } else if (x > 3) { + } else { + } + } +} + ]]> + + + + one not empty if statement + 0 + 2) { + x = 1; + } + } +} + ]]> + + + + empty if statement + 1 + 2); + } +} + ]]> + + + + empty if statement with comment + 1 + + From 7ed7fc0e42a5e51089ea76b4b0ad08af8827334a Mon Sep 17 00:00:00 2001 From: Andreas Dangel Date: Fri, 27 May 2022 15:04:36 +0200 Subject: [PATCH 127/198] [java] EmptyControlStatement: Fix NPE for concise try-with-resources --- .../sourceforge/pmd/lang/java/ast/ASTResource.java | 9 +++++++++ .../rule/codestyle/EmptyControlStatementRule.java | 2 +- .../rule/codestyle/xml/EmptyControlStatement.xml | 14 ++++++++++++++ 3 files changed, 24 insertions(+), 1 deletion(-) diff --git a/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/ast/ASTResource.java b/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/ast/ASTResource.java index f6ce7781cb..b9aafd7f83 100644 --- a/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/ast/ASTResource.java +++ b/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/ast/ASTResource.java @@ -25,6 +25,15 @@ public class ASTResource extends ASTFormalParameter { return visitor.visit(this, data); } + public String getName() { + ASTVariableDeclaratorId variableDeclaratorId = getVariableDeclaratorId(); + if (variableDeclaratorId != null) { + return variableDeclaratorId.getName(); + } + // concise try-with-resources + return getFirstChildOfType(ASTName.class).getImage(); + } + // TODO Should we deprecate all methods from ASTFormalParameter? } diff --git a/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/rule/codestyle/EmptyControlStatementRule.java b/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/rule/codestyle/EmptyControlStatementRule.java index 5de4bca7ed..c9b075f067 100644 --- a/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/rule/codestyle/EmptyControlStatementRule.java +++ b/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/rule/codestyle/EmptyControlStatementRule.java @@ -132,7 +132,7 @@ public class EmptyControlStatementRule extends AbstractJavaRule { if (resources != null) { for (ASTResource resource : resources.findDescendantsOfType(ASTResource.class)) { hasResource = true; - String name = resource.getVariableDeclaratorId().getName(); + String name = resource.getName(); if (!JavaRuleUtil.isExplicitUnusedVarName(name)) { allResourcesIgnored = false; break; diff --git a/pmd-java/src/test/resources/net/sourceforge/pmd/lang/java/rule/codestyle/xml/EmptyControlStatement.xml b/pmd-java/src/test/resources/net/sourceforge/pmd/lang/java/rule/codestyle/xml/EmptyControlStatement.xml index 69275f3bc9..1ccd313fff 100644 --- a/pmd-java/src/test/resources/net/sourceforge/pmd/lang/java/rule/codestyle/xml/EmptyControlStatement.xml +++ b/pmd-java/src/test/resources/net/sourceforge/pmd/lang/java/rule/codestyle/xml/EmptyControlStatement.xml @@ -106,6 +106,20 @@ ]]> + + empty concise try-with-resource - not ok + 1 + 4 + + pos, empty synchronized stmt From ee0e4f8685576dec8e28376892364b57c09eb126 Mon Sep 17 00:00:00 2001 From: Andreas Dangel Date: Fri, 27 May 2022 15:19:47 +0200 Subject: [PATCH 128/198] [java] Fix rule reference --- pmd-java/src/main/resources/category/java/codestyle.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pmd-java/src/main/resources/category/java/codestyle.xml b/pmd-java/src/main/resources/category/java/codestyle.xml index de65c0a536..bf9edbfa19 100644 --- a/pmd-java/src/main/resources/category/java/codestyle.xml +++ b/pmd-java/src/main/resources/category/java/codestyle.xml @@ -736,7 +736,7 @@ public abstract class ShouldBeAbstract { EmptyIfStmt, EmptyInitializer, EmptyStatementBlock, EmptySwitchStatements, EmptySynchronizedBlock, EmptyTryBlock, and EmptyWhileStmt. Notice that EmptyCatchBlock is still an independent rule. - EmptyStatementNotInLoop is replaced by {% rule java/codestyle/UnnecessarySemiColon %}. + EmptyStatementNotInLoop is replaced by {% rule java/codestyle/UnnecessarySemicolon %}. ]]> 3 From 3630c3732aba4144da17053bde07d765368ac8bf Mon Sep 17 00:00:00 2001 From: Andreas Dangel Date: Fri, 27 May 2022 15:23:31 +0200 Subject: [PATCH 129/198] Apply suggestions from code review MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Clément Fournier --- pmd-java/src/main/resources/category/java/codestyle.xml | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/pmd-java/src/main/resources/category/java/codestyle.xml b/pmd-java/src/main/resources/category/java/codestyle.xml index bf9edbfa19..e39c0b0b96 100644 --- a/pmd-java/src/main/resources/category/java/codestyle.xml +++ b/pmd-java/src/main/resources/category/java/codestyle.xml @@ -712,7 +712,7 @@ public abstract class ShouldBeAbstract { @@ -724,13 +724,14 @@ public abstract class ShouldBeAbstract { Reports control statements whose body is empty, as well as empty initializers. The checked code constructs are the following: - - bodies of `try` statements (not try-with-resources) + - bodies of `try` statements - `finally` clauses of `try` statements - `switch` statements - `synchronized` statements - `if` statements - loop statements: `while`, `for`, `do .. while` - initializers + - blocks used as statements (for scoping) This rule replaces the rules EmptyFinallyBlock, EmptyIfStmt, EmptyInitializer, EmptyStatementBlock, @@ -2173,7 +2174,7 @@ public class Foo { @@ -2184,6 +2185,8 @@ public class Foo { This rule will not report empty statements that are syntactically required, for instance, because they are the body of a control statement. + + This rule replaces EmptyStatementNotInLoop. 3 From 8b4d16b029d6c674e8c91be49164f383f74ea7f0 Mon Sep 17 00:00:00 2001 From: Andreas Dangel Date: Fri, 27 May 2022 15:24:06 +0200 Subject: [PATCH 130/198] Update pmd-java/src/test/resources/net/sourceforge/pmd/lang/java/rule/codestyle/xml/EmptyControlStatement.xml --- .../lang/java/rule/codestyle/xml/EmptyControlStatement.xml | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/pmd-java/src/test/resources/net/sourceforge/pmd/lang/java/rule/codestyle/xml/EmptyControlStatement.xml b/pmd-java/src/test/resources/net/sourceforge/pmd/lang/java/rule/codestyle/xml/EmptyControlStatement.xml index 1ccd313fff..06a5c97099 100644 --- a/pmd-java/src/test/resources/net/sourceforge/pmd/lang/java/rule/codestyle/xml/EmptyControlStatement.xml +++ b/pmd-java/src/test/resources/net/sourceforge/pmd/lang/java/rule/codestyle/xml/EmptyControlStatement.xml @@ -86,7 +86,10 @@ class X { void method() { try (ClientResponse response = execute(() -> target.request(mediaTypes).delete(), DELETE, new ExpectedResponse(status, required))) { - // false positive + // was false positive + // EmptyTryBlock was fixed to ignore empty try-with-resources. + // This new rule will by default report also empty try-with-resource blocks, + // if the resource name is not "ignored", see next test case. } } } From 0224b6bd01565df25f12a5aaff3e643e57400289 Mon Sep 17 00:00:00 2001 From: Andreas Dangel Date: Fri, 27 May 2022 15:48:38 +0200 Subject: [PATCH 131/198] [java] Deprecate Empty* rules --- docs/pages/release_notes.md | 17 ++++++++++ .../resources/category/java/codestyle.xml | 26 +++++++------- .../resources/category/java/errorprone.xml | 34 ++++++++++++++++++- .../resources/rulesets/java/quickstart.xml | 9 ----- 4 files changed, 64 insertions(+), 22 deletions(-) diff --git a/docs/pages/release_notes.md b/docs/pages/release_notes.md index 9cf3b8ec60..37e509086c 100644 --- a/docs/pages/release_notes.md +++ b/docs/pages/release_notes.md @@ -34,6 +34,23 @@ When executing CPD on C# sources, the option `--ignore-annotations` is now suppo It ignores C# attributes when detecting duplicated code. This option can also be enabled via the CPD GUI. See [#3974](https://github.com/pmd/pmd/pull/3974) for details. +#### New Rules + +#### Deprecated Rules + +* The following Java rules are deprecated and removed from the quickstart ruleset, as the new rule +{% rule java/codestyle/EmptyControlStatement %} merges their functionality: + * {% rule java/errorprone/EmptyFinallyBlock %} + * {% rule java/errorprone/EmptyIfStmt %} + * {% rule java/errorprone/EmptyInitializer %} + * {% rule java/errorprone/EmptyStatementBlock %} + * {% rule java/errorprone/EmptySwitchStatements %} + * {% rule java/errorprone/EmptySynchronizedBlock %} + * {% rule java/errorprone/EmptyTryBlock %} + * {% rule java/errorprone/EmptyWhileStmt %} +* The Java rule {% rule java/errorprone/EmptyStatementNotInLoop %} is deprecated and removed from the quickstart +ruleset. Use the new rule {% rule java/codestyle/UnnecessarySemicolon %} instead. + ### Fixed Issues * cli diff --git a/pmd-java/src/main/resources/category/java/codestyle.xml b/pmd-java/src/main/resources/category/java/codestyle.xml index e39c0b0b96..8096ce8309 100644 --- a/pmd-java/src/main/resources/category/java/codestyle.xml +++ b/pmd-java/src/main/resources/category/java/codestyle.xml @@ -736,22 +736,24 @@ public abstract class ShouldBeAbstract { This rule replaces the rules EmptyFinallyBlock, EmptyIfStmt, EmptyInitializer, EmptyStatementBlock, EmptySwitchStatements, EmptySynchronizedBlock, EmptyTryBlock, and EmptyWhileStmt. - Notice that EmptyCatchBlock is still an independent rule. + + Notice that {% rule java/errorprone/EmptyCatchBlock %} is still an independent rule. + EmptyStatementNotInLoop is replaced by {% rule java/codestyle/UnnecessarySemicolon %}. ]]> 3 - + {} // empty initializer +} +]]> @@ -2207,7 +2209,7 @@ public class Foo { - Empty finally blocks serve no purpose and should be removed. + +This rule is deprecated since PMD 6.46.0. Use the rule {% rule "java/codestyle/EmptyControlStatement" %} +from category codestyle instead. 3 @@ -1652,6 +1656,7 @@ public class Foo { Empty If Statement finds instances where a condition is checked but nothing is done about it. + +This rule is deprecated since PMD 6.46.0. Use the rule {% rule "java/codestyle/EmptyControlStatement" %} +from category codestyle instead. 3 @@ -1686,6 +1694,7 @@ public class Foo { Empty initializers serve no purpose and should be removed. + +This rule is deprecated since PMD 6.46.0. Use the rule {% rule "java/codestyle/EmptyControlStatement" %} +from category codestyle instead. 3 @@ -1715,6 +1727,7 @@ public class Foo { Empty block statements serve no purpose and should be removed. + +This rule is deprecated since PMD 6.46.0. Use the rule {% rule "java/codestyle/EmptyControlStatement" %} +from category codestyle instead. 3 @@ -1790,13 +1806,17 @@ public void doit() { -Empty switch statements serve no purpose and should be removed. +Empty switch statements serve no purpose and should be removed.# + +This rule is deprecated since PMD 6.46.0. Use the rule {% rule "java/codestyle/EmptyControlStatement" %} +from category codestyle instead. 3 @@ -1819,6 +1839,7 @@ public void bar() { Empty synchronized blocks serve no purpose and should be removed. + +This rule is deprecated since PMD 6.46.0. Use the rule {% rule "java/codestyle/EmptyControlStatement" %} +from category codestyle instead. 3 @@ -1848,6 +1872,7 @@ public class Foo { Avoid empty try blocks - what's the point? + +This rule is deprecated since PMD 6.46.0. Use the rule {% rule "java/codestyle/EmptyControlStatement" %} +from category codestyle instead. 3 @@ -1882,6 +1910,7 @@ public class Foo { 3 diff --git a/pmd-java/src/main/resources/rulesets/java/quickstart.xml b/pmd-java/src/main/resources/rulesets/java/quickstart.xml index b4455a998e..68a8dc37fa 100644 --- a/pmd-java/src/main/resources/rulesets/java/quickstart.xml +++ b/pmd-java/src/main/resources/rulesets/java/quickstart.xml @@ -268,15 +268,6 @@ - - - - - - - - - From 88a1ae80a6102c436406c3c28b06c4b4ce6a514f Mon Sep 17 00:00:00 2001 From: Andreas Dangel Date: Fri, 27 May 2022 15:55:03 +0200 Subject: [PATCH 132/198] [doc] Update release notes with new rules --- docs/pages/release_notes.md | 28 +++++++++++++++++++ .../main/resources/rulesets/releases/6460.xml | 14 ++++++++++ .../resources/rulesets/java/quickstart.xml | 2 ++ 3 files changed, 44 insertions(+) create mode 100644 pmd-core/src/main/resources/rulesets/releases/6460.xml diff --git a/docs/pages/release_notes.md b/docs/pages/release_notes.md index 37e509086c..dbc4e42076 100644 --- a/docs/pages/release_notes.md +++ b/docs/pages/release_notes.md @@ -36,6 +36,34 @@ the CPD GUI. See [#3974](https://github.com/pmd/pmd/pull/3974) for details. #### New Rules +This release ships with 2 new Java rules. + +* {% rule java/codestyle/EmptyControlStatement %} reports many instances of empty things, e.g. control statements whose + body is empty, as well as empty initializers. + + EmptyControlStatement also works for empty `for` and `do` loops, while there were previously + no corresponding rules. + + This new rule replaces the rules EmptyFinallyBlock, EmptyIfStmt, EmptyInitializer, EmptyStatementBlock, + EmptySwitchStatements, EmptySynchronizedBlock, EmptyTryBlock, and EmptyWhileStmt. + +```xml + +``` + +The rule is part of the quickstart.xml ruleset. + +* {%rule java/codestyle/UnnecessarySemicolon %} reports semicolons that are unnecessary (so called "empty statements" + and "empty declarations"). + + This new rule replaces the rule EmptyStatementNotInLoop. + +```xml + +``` + +The rule is part of the quickstart.xml ruleset. + #### Deprecated Rules * The following Java rules are deprecated and removed from the quickstart ruleset, as the new rule diff --git a/pmd-core/src/main/resources/rulesets/releases/6460.xml b/pmd-core/src/main/resources/rulesets/releases/6460.xml new file mode 100644 index 0000000000..9601247606 --- /dev/null +++ b/pmd-core/src/main/resources/rulesets/releases/6460.xml @@ -0,0 +1,14 @@ + + + + +This ruleset contains links to rules that are new in PMD v6.46.0 + + + + + + diff --git a/pmd-java/src/main/resources/rulesets/java/quickstart.xml b/pmd-java/src/main/resources/rulesets/java/quickstart.xml index 68a8dc37fa..c579b8ee17 100644 --- a/pmd-java/src/main/resources/rulesets/java/quickstart.xml +++ b/pmd-java/src/main/resources/rulesets/java/quickstart.xml @@ -266,6 +266,8 @@ + + From 6524ae9d3340452c760ede76bbe2f1f01129beb3 Mon Sep 17 00:00:00 2001 From: Andreas Dangel Date: Fri, 27 May 2022 17:16:02 +0200 Subject: [PATCH 133/198] [java] Rename ASTResource#getName to getStableName --- .../java/net/sourceforge/pmd/lang/java/ast/ASTResource.java | 2 +- .../pmd/lang/java/rule/codestyle/EmptyControlStatementRule.java | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/ast/ASTResource.java b/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/ast/ASTResource.java index b9aafd7f83..9aab09fe1d 100644 --- a/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/ast/ASTResource.java +++ b/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/ast/ASTResource.java @@ -25,7 +25,7 @@ public class ASTResource extends ASTFormalParameter { return visitor.visit(this, data); } - public String getName() { + public String getStableName() { ASTVariableDeclaratorId variableDeclaratorId = getVariableDeclaratorId(); if (variableDeclaratorId != null) { return variableDeclaratorId.getName(); diff --git a/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/rule/codestyle/EmptyControlStatementRule.java b/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/rule/codestyle/EmptyControlStatementRule.java index c9b075f067..69533488e5 100644 --- a/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/rule/codestyle/EmptyControlStatementRule.java +++ b/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/rule/codestyle/EmptyControlStatementRule.java @@ -132,7 +132,7 @@ public class EmptyControlStatementRule extends AbstractJavaRule { if (resources != null) { for (ASTResource resource : resources.findDescendantsOfType(ASTResource.class)) { hasResource = true; - String name = resource.getName(); + String name = resource.getStableName(); if (!JavaRuleUtil.isExplicitUnusedVarName(name)) { allResourcesIgnored = false; break; From 02581bcc4a20e0ae7dad78b588b97c80d2f6cded Mon Sep 17 00:00:00 2001 From: Andreas Dangel Date: Fri, 27 May 2022 17:36:01 +0200 Subject: [PATCH 134/198] [java] EmptyControlStatementRule - fix messages --- .../codestyle/EmptyControlStatementRule.java | 28 ++++++++++--------- .../resources/category/java/codestyle.xml | 2 +- 2 files changed, 16 insertions(+), 14 deletions(-) diff --git a/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/rule/codestyle/EmptyControlStatementRule.java b/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/rule/codestyle/EmptyControlStatementRule.java index 69533488e5..0a6c954d7a 100644 --- a/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/rule/codestyle/EmptyControlStatementRule.java +++ b/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/rule/codestyle/EmptyControlStatementRule.java @@ -18,6 +18,7 @@ import net.sourceforge.pmd.lang.java.ast.ASTStatement; import net.sourceforge.pmd.lang.java.ast.ASTSwitchStatement; import net.sourceforge.pmd.lang.java.ast.ASTSynchronizedStatement; import net.sourceforge.pmd.lang.java.ast.ASTTryStatement; +import net.sourceforge.pmd.lang.java.ast.ASTVariableDeclaratorId; import net.sourceforge.pmd.lang.java.ast.ASTWhileStatement; import net.sourceforge.pmd.lang.java.ast.JavaNode; import net.sourceforge.pmd.lang.java.rule.AbstractJavaRule; @@ -46,7 +47,7 @@ public class EmptyControlStatementRule extends AbstractJavaRule { @Override public Object visit(ASTFinallyStatement node, Object data) { if (isEmpty(node.getBody())) { - addViolation(data, node, "Empty finally clause"); + asCtx(data).addViolationWithMessage(node, "Empty finally clause"); } return null; } @@ -54,7 +55,7 @@ public class EmptyControlStatementRule extends AbstractJavaRule { @Override public Object visit(ASTSynchronizedStatement node, Object data) { if (isEmpty(node.getBody())) { - addViolation(data, node, "Empty synchronized statement"); + asCtx(data).addViolationWithMessage(node, "Empty synchronized statement"); } return null; } @@ -62,7 +63,7 @@ public class EmptyControlStatementRule extends AbstractJavaRule { @Override public Object visit(ASTSwitchStatement node, Object data) { if (node.getNumChildren() == 1) { - addViolation(data, node, "Empty switch statement"); + asCtx(data).addViolationWithMessage(node, "Empty switch statement"); } return null; } @@ -70,7 +71,7 @@ public class EmptyControlStatementRule extends AbstractJavaRule { @Override public Object visit(ASTBlock node, Object data) { if (isEmpty(node) && node.getNthParent(3) instanceof ASTBlock) { - addViolation(data, node, "Empty block"); + asCtx(data).addViolationWithMessage(node, "Empty block"); } return null; } @@ -78,10 +79,10 @@ public class EmptyControlStatementRule extends AbstractJavaRule { @Override public Object visit(ASTIfStatement node, Object data) { if (isEmpty(node.getThenBranch().getChild(0))) { - addViolation(data, node, "Empty if statement"); + asCtx(data).addViolationWithMessage(node, "Empty if statement"); } if (node.hasElse() && isEmpty(node.getElseBranch().getChild(0))) { - addViolation(data, node.getElseBranch(), "Empty else statement"); + asCtx(data).addViolationWithMessage(node.getElseBranch(), "Empty else statement"); } return null; } @@ -89,19 +90,20 @@ public class EmptyControlStatementRule extends AbstractJavaRule { @Override public Object visit(ASTWhileStatement node, Object data) { if (isEmpty(node.getBody())) { - addViolation(data, node, "Empty while statement"); + asCtx(data).addViolationWithMessage(node, "Empty while statement"); } return null; } @Override public Object visit(ASTForStatement node, Object data) { - if (node.isForeach() && JavaRuleUtil.isExplicitUnusedVarName(node.getFirstChildOfType(ASTLocalVariableDeclaration.class).getVariableName())) { + if (node.isForeach() && JavaRuleUtil.isExplicitUnusedVarName(node.getFirstChildOfType(ASTLocalVariableDeclaration.class) + .getFirstDescendantOfType(ASTVariableDeclaratorId.class).getName())) { // allow `for (ignored : iterable) {}` return null; } if (isEmpty(node.getBody())) { - addViolation(data, node, "Empty for statement"); + asCtx(data).addViolationWithMessage(node, "Empty for statement"); } return null; } @@ -109,7 +111,7 @@ public class EmptyControlStatementRule extends AbstractJavaRule { @Override public Object visit(ASTDoStatement node, Object data) { if (isEmpty(node.getBody())) { - addViolation(data, node, "Empty do..while statement"); + asCtx(data).addViolationWithMessage(node, "Empty do..while statement"); } return null; } @@ -117,7 +119,7 @@ public class EmptyControlStatementRule extends AbstractJavaRule { @Override public Object visit(ASTInitializer node, Object data) { if (isEmpty(node.getBody())) { - addViolation(data, node, "Empty initializer statement"); + asCtx(data).addViolationWithMessage(node, "Empty initializer statement"); } return null; } @@ -141,9 +143,9 @@ public class EmptyControlStatementRule extends AbstractJavaRule { } if (hasResource && !allResourcesIgnored) { - addViolation(data, node, "Empty try body - you could rename the resource to 'ignored'"); + asCtx(data).addViolationWithMessage(node, "Empty try body - you could rename the resource to 'ignored'"); } else if (!hasResource) { - addViolation(data, node, "Empty try body"); + asCtx(data).addViolationWithMessage(node, "Empty try body"); } } return null; diff --git a/pmd-java/src/main/resources/category/java/codestyle.xml b/pmd-java/src/main/resources/category/java/codestyle.xml index 8096ce8309..f9770a891b 100644 --- a/pmd-java/src/main/resources/category/java/codestyle.xml +++ b/pmd-java/src/main/resources/category/java/codestyle.xml @@ -2192,7 +2192,7 @@ public class Foo { 3 - + Date: Fri, 27 May 2022 17:59:29 +0200 Subject: [PATCH 135/198] [java] EmptyControlStatementRule - fix messages --- .../codestyle/EmptyControlStatementRule.java | 2 +- .../codestyle/xml/EmptyControlStatement.xml | 73 +++++++++++++++++++ 2 files changed, 74 insertions(+), 1 deletion(-) diff --git a/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/rule/codestyle/EmptyControlStatementRule.java b/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/rule/codestyle/EmptyControlStatementRule.java index 0a6c954d7a..5e7f02f60f 100644 --- a/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/rule/codestyle/EmptyControlStatementRule.java +++ b/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/rule/codestyle/EmptyControlStatementRule.java @@ -143,7 +143,7 @@ public class EmptyControlStatementRule extends AbstractJavaRule { } if (hasResource && !allResourcesIgnored) { - asCtx(data).addViolationWithMessage(node, "Empty try body - you could rename the resource to 'ignored'"); + asCtx(data).addViolationWithMessage(node, "Empty try body - you could rename the resource to ''ignored''"); } else if (!hasResource) { asCtx(data).addViolationWithMessage(node, "Empty try body"); } diff --git a/pmd-java/src/test/resources/net/sourceforge/pmd/lang/java/rule/codestyle/xml/EmptyControlStatement.xml b/pmd-java/src/test/resources/net/sourceforge/pmd/lang/java/rule/codestyle/xml/EmptyControlStatement.xml index 06a5c97099..c732f1ef5b 100644 --- a/pmd-java/src/test/resources/net/sourceforge/pmd/lang/java/rule/codestyle/xml/EmptyControlStatement.xml +++ b/pmd-java/src/test/resources/net/sourceforge/pmd/lang/java/rule/codestyle/xml/EmptyControlStatement.xml @@ -7,6 +7,9 @@ pos, empty try block 1 3 + + Empty try body + pos, empty try block 1 3 + + Empty try body + pos, empty finally block 1 5 + + Empty finally clause + pos, empty try and finally block 2 + + Empty try body + Empty finally clause + #432 empty try-with-resource - not ok 1 + + Empty try body - you could rename the resource to 'ignored' + empty concise try-with-resource - not ok 1 4 + + Empty try body - you could rename the resource to 'ignored' + pos, empty synchronized stmt 1 + + Empty synchronized statement + pos, empty switch stmt 1 + + Empty switch statement + pos, empty block 1 + + Empty block + empty initializer failure case (non static) 1 + + Empty initializer statement + empty initializer failure case (static) 1 + + Empty initializer statement + not an initializer - empty statement block 1 + + Empty block + pos, empty for 2 3,5 + + Empty for statement + Empty for statement + pos, empty do..while 2 4,6 + + Empty do..while statement + Empty do..while statement + pos, empty foreach 2 6,8 + + Empty for statement + Empty for statement + pos, empty while 1 3 + + Empty while statement + while(true); 1 + + Empty while statement + one empty if statement 1 3 + + Empty if statement + empty if with else statement 2 3,4 + + Empty if statement + Empty else statement + empty if with else and else if statement 3 3,4,5 + + Empty if statement + Empty if statement + Empty else statement + empty if statement 1 + + Empty if statement + empty if statement with comment 1 + + Empty if statement + Date: Fri, 27 May 2022 18:02:03 +0200 Subject: [PATCH 136/198] [java] Adjust new rules for PMD 7 --- .../rule/codestyle/EmptyControlStatementRule.java | 10 +++------- .../src/main/resources/category/java/codestyle.xml | 12 ++++-------- .../java/rule/codestyle/xml/UnnecessarySemicolon.xml | 2 +- 3 files changed, 8 insertions(+), 16 deletions(-) diff --git a/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/rule/codestyle/EmptyControlStatementRule.java b/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/rule/codestyle/EmptyControlStatementRule.java index 2d787cbf51..65e98bffeb 100644 --- a/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/rule/codestyle/EmptyControlStatementRule.java +++ b/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/rule/codestyle/EmptyControlStatementRule.java @@ -14,7 +14,6 @@ import net.sourceforge.pmd.lang.java.ast.ASTIfStatement; import net.sourceforge.pmd.lang.java.ast.ASTInitializer; import net.sourceforge.pmd.lang.java.ast.ASTResource; import net.sourceforge.pmd.lang.java.ast.ASTResourceList; -import net.sourceforge.pmd.lang.java.ast.ASTStatement; import net.sourceforge.pmd.lang.java.ast.ASTSwitchStatement; import net.sourceforge.pmd.lang.java.ast.ASTSynchronizedStatement; import net.sourceforge.pmd.lang.java.ast.ASTTryStatement; @@ -57,7 +56,7 @@ public class EmptyControlStatementRule extends AbstractJavaRulechainRule { @Override public Object visit(ASTBlock node, Object data) { - if (isEmpty(node) && node.getNthParent(3) instanceof ASTBlock) { + if (isEmpty(node) && node.getParent() instanceof ASTBlock) { addViolation(data, node, "Empty block"); } return null; @@ -65,10 +64,10 @@ public class EmptyControlStatementRule extends AbstractJavaRulechainRule { @Override public Object visit(ASTIfStatement node, Object data) { - if (isEmpty(node.getThenBranch().getChild(0))) { + if (isEmpty(node.getThenBranch())) { addViolation(data, node, "Empty if statement"); } - if (node.hasElse() && isEmpty(node.getElseBranch().getChild(0))) { + if (node.hasElse() && isEmpty(node.getElseBranch())) { addViolation(data, node.getElseBranch(), "Empty else statement"); } return null; @@ -146,9 +145,6 @@ public class EmptyControlStatementRule extends AbstractJavaRulechainRule { } private boolean isEmpty(JavaNode node) { - if (node instanceof ASTStatement) { - node = node.getChild(0); - } return node instanceof ASTBlock && node.getNumChildren() == 0 || node instanceof ASTEmptyStatement; } diff --git a/pmd-java/src/main/resources/category/java/codestyle.xml b/pmd-java/src/main/resources/category/java/codestyle.xml index 0e3659537f..f9dfc478ac 100644 --- a/pmd-java/src/main/resources/category/java/codestyle.xml +++ b/pmd-java/src/main/resources/category/java/codestyle.xml @@ -1807,17 +1807,13 @@ public class Foo { 3 - + diff --git a/pmd-java/src/test/resources/net/sourceforge/pmd/lang/java/rule/codestyle/xml/UnnecessarySemicolon.xml b/pmd-java/src/test/resources/net/sourceforge/pmd/lang/java/rule/codestyle/xml/UnnecessarySemicolon.xml index 7e89344964..1736521e76 100644 --- a/pmd-java/src/test/resources/net/sourceforge/pmd/lang/java/rule/codestyle/xml/UnnecessarySemicolon.xml +++ b/pmd-java/src/test/resources/net/sourceforge/pmd/lang/java/rule/codestyle/xml/UnnecessarySemicolon.xml @@ -51,7 +51,7 @@ 2 1,3 From 1a62ddffad8bf4e9beb30205a40f45ec22bb2cff Mon Sep 17 00:00:00 2001 From: Scrsloota <1912125562@qq.com> Date: Sat, 28 May 2022 00:17:11 +0800 Subject: [PATCH 137/198] fix AvoidFieldNameMatchingMethodName without enum --- .../AvoidFieldNameMatchingMethodNameRule.java | 54 +++++++++++-------- 1 file changed, 32 insertions(+), 22 deletions(-) diff --git a/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/rule/errorprone/AvoidFieldNameMatchingMethodNameRule.java b/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/rule/errorprone/AvoidFieldNameMatchingMethodNameRule.java index a84a2b8b3d..9fd52b984a 100644 --- a/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/rule/errorprone/AvoidFieldNameMatchingMethodNameRule.java +++ b/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/rule/errorprone/AvoidFieldNameMatchingMethodNameRule.java @@ -13,8 +13,11 @@ import java.util.Set; import net.sourceforge.pmd.lang.ast.Node; import net.sourceforge.pmd.lang.java.ast.ASTClassOrInterfaceBody; import net.sourceforge.pmd.lang.java.ast.ASTClassOrInterfaceDeclaration; +import net.sourceforge.pmd.lang.java.ast.ASTEnumBody; +import net.sourceforge.pmd.lang.java.ast.ASTEnumDeclaration; import net.sourceforge.pmd.lang.java.ast.ASTFieldDeclaration; import net.sourceforge.pmd.lang.java.ast.ASTMethodDeclaration; +import net.sourceforge.pmd.lang.java.ast.JavaNode; import net.sourceforge.pmd.lang.java.rule.AbstractJavaRule; public class AvoidFieldNameMatchingMethodNameRule extends AbstractJavaRule { @@ -28,29 +31,36 @@ public class AvoidFieldNameMatchingMethodNameRule extends AbstractJavaRule { } @Override - public Object visit(ASTClassOrInterfaceBody node, Object data) { - int n = node.getNumChildren(); - List fields = new ArrayList<>(); - Set methodNames = new HashSet<>(); - for (int i = 0; i < n; i++) { - Node child = node.getChild(i); - if (child.getNumChildren() == 0) { - continue; - } - child = child.getChild(child.getNumChildren() - 1); - if (child instanceof ASTFieldDeclaration) { - fields.add((ASTFieldDeclaration) child); - } else if (child instanceof ASTMethodDeclaration) { - methodNames.add(((ASTMethodDeclaration) child).getName().toLowerCase(Locale.ROOT)); - } - } - for (ASTFieldDeclaration field : fields) { - String varName = field.getVariableName().toLowerCase(Locale.ROOT); - if (methodNames.contains(varName)) { - addViolation(data, field, field.getVariableName()); - } - } + public Object visit(ASTEnumDeclaration node, Object data) { return super.visit(node, data); } + @Override + public Object visit(JavaNode node, Object data) { + if (node instanceof ASTClassOrInterfaceBody || node instanceof ASTEnumBody) { + int n = node.getNumChildren(); + List fields = new ArrayList<>(); + Set methodNames = new HashSet<>(); + for (int i = 0; i < n; i++) { + Node child = node.getChild(i); + if (child.getNumChildren() == 0) { + continue; + } + child = child.getChild(child.getNumChildren() - 1); + if (child instanceof ASTFieldDeclaration) { + fields.add((ASTFieldDeclaration) child); + } else if (child instanceof ASTMethodDeclaration) { + methodNames.add(((ASTMethodDeclaration) child).getName().toLowerCase(Locale.ROOT)); + } + } + for (ASTFieldDeclaration field : fields) { + String varName = field.getVariableName().toLowerCase(Locale.ROOT); + if (methodNames.contains(varName)) { + addViolation(data, field, field.getVariableName()); + } + } + return super.visit(node, data); + } + return super.visit(node, data); + } } From 7261b7fd10842fc15c3aab73de1ea8d0c7944dcc Mon Sep 17 00:00:00 2001 From: Scrsloota <1912125562@qq.com> Date: Sat, 28 May 2022 00:17:32 +0800 Subject: [PATCH 138/198] add test cases --- .../xml/AvoidFieldNameMatchingMethodName.xml | 42 +++++++++++++++++++ 1 file changed, 42 insertions(+) diff --git a/pmd-java/src/test/resources/net/sourceforge/pmd/lang/java/rule/errorprone/xml/AvoidFieldNameMatchingMethodName.xml b/pmd-java/src/test/resources/net/sourceforge/pmd/lang/java/rule/errorprone/xml/AvoidFieldNameMatchingMethodName.xml index 138d598230..ad0170102a 100644 --- a/pmd-java/src/test/resources/net/sourceforge/pmd/lang/java/rule/errorprone/xml/AvoidFieldNameMatchingMethodName.xml +++ b/pmd-java/src/test/resources/net/sourceforge/pmd/lang/java/rule/errorprone/xml/AvoidFieldNameMatchingMethodName.xml @@ -60,6 +60,48 @@ public class Bar { + + + + Test1 in Enum + 1 + + + + + Test2 in Enum + 0 + + + + + Test3 in Enum + 0 + From f663f33b208d591e5aee35a2901627eb9e04401f Mon Sep 17 00:00:00 2001 From: Andreas Dangel Date: Fri, 27 May 2022 18:18:03 +0200 Subject: [PATCH 139/198] Fix tests --- .../lang/java/rule/codestyle/xml/EmptyControlStatement.xml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pmd-java/src/test/resources/net/sourceforge/pmd/lang/java/rule/codestyle/xml/EmptyControlStatement.xml b/pmd-java/src/test/resources/net/sourceforge/pmd/lang/java/rule/codestyle/xml/EmptyControlStatement.xml index c732f1ef5b..b0a5134918 100644 --- a/pmd-java/src/test/resources/net/sourceforge/pmd/lang/java/rule/codestyle/xml/EmptyControlStatement.xml +++ b/pmd-java/src/test/resources/net/sourceforge/pmd/lang/java/rule/codestyle/xml/EmptyControlStatement.xml @@ -341,8 +341,8 @@ 2 6,8 - Empty for statement - Empty for statement + Empty foreach statement + Empty foreach statement Date: Fri, 27 May 2022 18:32:44 +0200 Subject: [PATCH 140/198] [doc] Update release notes (#2352, #3958) --- docs/pages/release_notes.md | 1 + 1 file changed, 1 insertion(+) diff --git a/docs/pages/release_notes.md b/docs/pages/release_notes.md index 5dee073b68..76625f443c 100644 --- a/docs/pages/release_notes.md +++ b/docs/pages/release_notes.md @@ -39,6 +39,7 @@ the CPD GUI. See [#3974](https://github.com/pmd/pmd/pull/3974) for details. * cli * [#1445](https://github.com/pmd/pmd/issues/1445): \[core] Allow CLI to take globs as parameters * core + * [#2352](https://github.com/pmd/pmd/issues/2352): \[core] Deprecate \-\ hyphen notation for ruleset references * [#3942](https://github.com/pmd/pmd/issues/3942): \[core] common-io path traversal vulnerability (CVE-2021-29425) * cs (c#) * [#3974](https://github.com/pmd/pmd/pull/3974): \[cs] Add option to ignore C# attributes (annotations) From 9f3abe4f5f7976fc9b9788bc128307559364a53b Mon Sep 17 00:00:00 2001 From: Andreas Dangel Date: Fri, 27 May 2022 19:14:31 +0200 Subject: [PATCH 141/198] Fix logging --- .../java/net/sourceforge/pmd/RuleSetReferenceId.java | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/pmd-core/src/main/java/net/sourceforge/pmd/RuleSetReferenceId.java b/pmd-core/src/main/java/net/sourceforge/pmd/RuleSetReferenceId.java index a977f19f00..6359c2aad4 100644 --- a/pmd-core/src/main/java/net/sourceforge/pmd/RuleSetReferenceId.java +++ b/pmd-core/src/main/java/net/sourceforge/pmd/RuleSetReferenceId.java @@ -12,9 +12,10 @@ import java.net.HttpURLConnection; import java.net.URL; import java.util.ArrayList; import java.util.List; -import java.util.logging.Logger; import org.apache.commons.lang3.StringUtils; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import net.sourceforge.pmd.annotation.InternalApi; import net.sourceforge.pmd.util.ResourceLoader; @@ -82,7 +83,7 @@ public class RuleSetReferenceId { // terminology and API should be clarified. // use the logger of RuleSetFactory, because the warnings conceptually come from there. - private static final Logger LOG = Logger.getLogger(RuleSetFactory.class.getName()); + private static final Logger LOG = LoggerFactory.getLogger(RuleSetFactory.class); private final boolean external; private final String ruleSetFileName; @@ -197,9 +198,9 @@ public class RuleSetReferenceId { String builtinRuleSet = expandedRuleset == null ? tempRuleSetFileName : expandedRuleset; if (checkRulesetExists(builtinRuleSet)) { if (expandedRuleset != null && warnDeprecated) { - LOG.warning( - "Ruleset reference '" + tempRuleSetFileName + "' uses a deprecated form, use '" - + builtinRuleSet + "' instead" + LOG.warn( + "Ruleset reference '{}' uses a deprecated form, use '{}' instead", + tempRuleSetFileName, builtinRuleSet ); } From 95ad4d3f0a84eb57c92e6fbef06d7eaabc551c41 Mon Sep 17 00:00:00 2001 From: Andreas Dangel Date: Sat, 28 May 2022 09:01:58 +0200 Subject: [PATCH 142/198] [doc] Update release notes (#3096) --- docs/pages/release_notes.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/docs/pages/release_notes.md b/docs/pages/release_notes.md index dbc4e42076..3aa0ba7210 100644 --- a/docs/pages/release_notes.md +++ b/docs/pages/release_notes.md @@ -97,6 +97,8 @@ ruleset. Use the new rule {% rule java/codestyle/UnnecessarySemicolon %} instead * [#3954](https://github.com/pmd/pmd/issues/3954): \[java] NPE in UseCollectionIsEmptyRule when .size() is called in a record * java-design * [#3874](https://github.com/pmd/pmd/issues/3874): \[java] ImmutableField reports fields annotated with @Autowired (Spring) and @Mock (Mockito) +* java-errorprone + * [#3096](https://github.com/pmd/pmd/issues/3096): \[java] EmptyStatementNotInLoop FP in 6.30.0 with IfStatement * java-performance * [#3379](https://github.com/pmd/pmd/issues/3379): \[java] UseArraysAsList must ignore primitive arrays * [#3965](https://github.com/pmd/pmd/issues/3965): \[java] UseArraysAsList false positive with non-trivial loops From 6f86a711f532bae40c1f26dac17159a15d34527d Mon Sep 17 00:00:00 2001 From: Andreas Dangel Date: Sat, 28 May 2022 10:50:43 +0200 Subject: [PATCH 143/198] Prepare pmd release 6.46.0 --- docs/_config.yml | 2 +- docs/pages/next_major_development.md | 91 +++++++++++++++++++++------- docs/pages/release_notes.md | 5 ++ 3 files changed, 75 insertions(+), 23 deletions(-) diff --git a/docs/_config.yml b/docs/_config.yml index 211a788da0..150e6e2fd1 100644 --- a/docs/_config.yml +++ b/docs/_config.yml @@ -1,7 +1,7 @@ repository: pmd/pmd pmd: - version: 6.46.0-SNAPSHOT + version: 6.46.0 previous_version: 6.45.0 date: 28-May-2022 release_type: minor diff --git a/docs/pages/next_major_development.md b/docs/pages/next_major_development.md index c95ad82a89..0c952b2741 100644 --- a/docs/pages/next_major_development.md +++ b/docs/pages/next_major_development.md @@ -125,6 +125,39 @@ the breaking API changes will be performed in 7.0.0. an API is tagged as `@Deprecated` or not in the latest minor release. During the development of 7.0.0, we may decide to remove some APIs that were not tagged as deprecated, though we'll try to avoid it." %} +#### 6.46.0 + +##### Deprecated ruleset references + +Ruleset references with the following formats are now deprecated and will produce a warning +when used on the CLI or in a ruleset XML file: +- `-`, eg `java-basic`, which resolves to `rulesets/java/basic.xml` +- the internal release number, eg `600`, which resolves to `rulesets/releases/600.xml` + +Use the explicit forms of these references to be compatible with PMD 7. + +##### Deprecated API + +- {% jdoc core::RuleSetReferenceId#toString() %} is now deprecated. The format of this + method will remain the same until PMD 7. The deprecation is intended to steer users + away from relying on this format, as it may be changed in PMD 7. +- {% jdoc core::PMDConfiguration#getInputPaths() %} and + {% jdoc core::PMDConfiguration#setInputPaths(java.lang.String) %} are now deprecated. + A new set of methods have been added, which use lists and do not rely on comma splitting. + +##### Internal API + +Those APIs are not intended to be used by clients, and will be hidden or removed with PMD 7.0.0. +You can identify them with the `@InternalApi` annotation. You'll also get a deprecation warning. + +- {% jdoc core::cpd.CPDCommandLineInterface %} has been internalized. In order to execute CPD either + {% jdoc !!core::cpd.CPD#run(java.lang.String...) %} or {% jdoc !!core::cpd.CPD#main(java.lang.String[]) %} + should be used. +- Several members of {% jdoc test::cli.BaseCPDCLITest %} have been deprecated with replacements. +- The methods {% jdoc !!core::ant.Formatter#start(java.lang.String) %}, + {% jdoc !!core::ant.Formatter#end(net.sourceforge.pmd.Report) %}, {% jdoc !!core::ant.Formatter#getRenderer() %}, + and {% jdoc !!core::ant.Formatter#isNoOutputSupplied() %} have been internalized. + #### 6.45.0 ##### Experimental APIs @@ -1332,70 +1365,70 @@ large projects, with many duplications, it was causing `OutOfMemoryError`s (see ### List of currently deprecated rules -* The Java rules {% rule java/codestyle/VariableNamingConventions %}, {% rule java/codestyle/MIsLeadingVariableName %}, +* The Java rules {% rule java/codestyle/VariableNamingConventions %}, {% rule java/codestyle/MIsLeadingVariableName %}, {% rule java/codestyle/SuspiciousConstantFieldName %}, and {% rule java/codestyle/AvoidPrefixingMethodParameters %} are now deprecated, and will be removed with version 7.0.0. They are replaced by the more general {% rule java/codestyle/FieldNamingConventions %}, {% rule java/codestyle/FormalParameterNamingConventions %}, and {% rule java/codestyle/LocalVariableNamingConventions %}. -* The Java rule {% rule java/codestyle/AbstractNaming %} is deprecated +* The Java rule {% rule java/codestyle/AbstractNaming %} is deprecated in favour of {% rule java/codestyle/ClassNamingConventions %}. -* The Java rules {% rule java/codestyle/WhileLoopsMustUseBraces %}, {% rule java/codestyle/ForLoopsMustUseBraces %}, {% rule java/codestyle/IfStmtsMustUseBraces %}, and {% rule java/codestyle/IfElseStmtsMustUseBraces %} +* The Java rules {% rule java/codestyle/WhileLoopsMustUseBraces %}, {% rule java/codestyle/ForLoopsMustUseBraces %}, {% rule java/codestyle/IfStmtsMustUseBraces %}, and {% rule java/codestyle/IfElseStmtsMustUseBraces %} are deprecated. They will be replaced by the new rule {% rule java/codestyle/ControlStatementBraces %}. -* The Java rules {% rule java/design/NcssConstructorCount %}, {% rule java/design/NcssMethodCount %}, and {% rule java/design/NcssTypeCount %} have been +* The Java rules {% rule java/design/NcssConstructorCount %}, {% rule java/design/NcssMethodCount %}, and {% rule java/design/NcssTypeCount %} have been deprecated. They will be replaced by the new rule {% rule java/design/NcssCount %} in the category `design`. -* The Java rule `LooseCoupling` in ruleset `java-typeresolution` is deprecated. Use the rule with the same name from category `bestpractices` instead. +* The Java rule `LooseCoupling` in ruleset `java-typeresolution` is deprecated. Use the rule with the same name from category `bestpractices` instead. -* The Java rule `CloneMethodMustImplementCloneable` in ruleset `java-typeresolution` is deprecated. Use the rule with the same name from category `errorprone` instead. +* The Java rule `CloneMethodMustImplementCloneable` in ruleset `java-typeresolution` is deprecated. Use the rule with the same name from category `errorprone` instead. -* The Java rule `UnusedImports` in ruleset `java-typeresolution` is deprecated. Use the rule with +* The Java rule `UnusedImports` in ruleset `java-typeresolution` is deprecated. Use the rule with the same name from category `bestpractices` instead. -* The Java rule `SignatureDeclareThrowsException` in ruleset `java-typeresolution` is deprecated. Use the rule with the same name from category `design` instead. +* The Java rule `SignatureDeclareThrowsException` in ruleset `java-typeresolution` is deprecated. Use the rule with the same name from category `design` instead. -* The Java rule `EmptyStaticInitializer` in ruleset `java-empty` is deprecated. Use the rule {% rule java/errorprone/EmptyInitializer %}, which covers both static and non-static empty initializers.` +* The Java rule `EmptyStaticInitializer` in ruleset `java-empty` is deprecated. Use the rule {% rule java/errorprone/EmptyInitializer %}, which covers both static and non-static empty initializers.` -* The Java rules `GuardDebugLogging` (ruleset `java-logging-jakarta-commons`) and `GuardLogStatementJavaUtil` +* The Java rules `GuardDebugLogging` (ruleset `java-logging-jakarta-commons`) and `GuardLogStatementJavaUtil` (ruleset `java-logging-java`) have been deprecated. Use the rule {% rule java/bestpractices/GuardLogStatement %}, which covers all cases regardless of the logging framework. -* The Java rule {% rule "java/multithreading/UnsynchronizedStaticDateFormatter" %} has been deprecated and +* The Java rule {% rule "java/multithreading/UnsynchronizedStaticDateFormatter" %} has been deprecated and will be removed with PMD 7.0.0. The rule is replaced by the more general {% rule "java/multithreading/UnsynchronizedStaticFormatter" %}. -* The two Java rules {% rule "java/bestpractices/PositionLiteralsFirstInComparisons" %} +* The two Java rules {% rule "java/bestpractices/PositionLiteralsFirstInComparisons" %} and {% rule "java/bestpractices/PositionLiteralsFirstInCaseInsensitiveComparisons" %} (ruleset `java-bestpractices`) have been deprecated in favor of the new rule {% rule "java/bestpractices/LiteralsFirstInComparisons" %}. -* The Java rule [`AvoidFinalLocalVariable`](https://pmd.github.io/pmd-6.16.0/pmd_rules_java_codestyle.html#avoidfinallocalvariable) (`java-codestyle`) has been deprecated +* The Java rule [`AvoidFinalLocalVariable`](https://pmd.github.io/pmd-6.16.0/pmd_rules_java_codestyle.html#avoidfinallocalvariable) (`java-codestyle`) has been deprecated and will be removed with PMD 7.0.0. The rule is controversial and also contradicts other existing rules such as [`LocalVariableCouldBeFinal`](https://pmd.github.io/pmd-6.16.0/pmd_rules_java_codestyle.html#localvariablecouldbefinal). If the goal is to avoid defining constants in a scope smaller than the class, then the rule [`AvoidDuplicateLiterals`](https://pmd.github.io/pmd-6.16.0/pmd_rules_java_errorprone.html#avoidduplicateliterals) should be used instead. -* The Apex rule [`VariableNamingConventions`](https://pmd.github.io/pmd-6.15.0/pmd_rules_apex_codestyle.html#variablenamingconventions) (`apex-codestyle`) has been deprecated and +* The Apex rule [`VariableNamingConventions`](https://pmd.github.io/pmd-6.15.0/pmd_rules_apex_codestyle.html#variablenamingconventions) (`apex-codestyle`) has been deprecated and will be removed with PMD 7.0.0. The rule is replaced by the more general rules [`FieldNamingConventions`](https://pmd.github.io/pmd-6.15.0/pmd_rules_apex_codestyle.html#fieldnamingconventions), [`FormalParameterNamingConventions`](https://pmd.github.io/pmd-6.15.0/pmd_rules_apex_codestyle.html#formalparameternamingconventions), [`LocalVariableNamingConventions`](https://pmd.github.io/pmd-6.15.0/pmd_rules_apex_codestyle.html#localvariablenamingconventions), and [`PropertyNamingConventions`](https://pmd.github.io/pmd-6.15.0/pmd_rules_apex_codestyle.html#propertynamingconventions). -* The Java rule [`LoggerIsNotStaticFinal`](https://pmd.github.io/pmd-6.15.0/pmd_rules_java_errorprone.html#loggerisnotstaticfinal) (`java-errorprone`) has been deprecated +* The Java rule [`LoggerIsNotStaticFinal`](https://pmd.github.io/pmd-6.15.0/pmd_rules_java_errorprone.html#loggerisnotstaticfinal) (`java-errorprone`) has been deprecated and will be removed with PMD 7.0.0. The rule is replaced by [`ProperLogger`](https://pmd.github.io/pmd-6.15.0/pmd_rules_java_errorprone.html#properlogger). -* The Java rule {% rule "java/errorprone/DataflowAnomalyAnalysis" %} (`java-errorprone`) +* The Java rule {% rule "java/errorprone/DataflowAnomalyAnalysis" %} (`java-errorprone`) is deprecated in favour of {% rule "java/bestpractices/UnusedAssignment" %} (`java-bestpractices`), which was introduced in PMD 6.26.0. -* The java rule {% rule "java/codestyle/DefaultPackage" %} has been deprecated in favor of +* The java rule {% rule "java/codestyle/DefaultPackage" %} has been deprecated in favor of {% rule "java/codestyle/CommentDefaultAccessModifier" %}. -* The Java rule {% rule "java/errorprone/CloneThrowsCloneNotSupportedException" %} has been deprecated without +* The Java rule {% rule "java/errorprone/CloneThrowsCloneNotSupportedException" %} has been deprecated without replacement. -* The following Java rules are deprecated and removed from the quickstart ruleset, +* The following Java rules are deprecated and removed from the quickstart ruleset, as the new rule {% rule java/bestpractices/SimplifiableTestAssertion %} merges their functionality: * {% rule java/bestpractices/UseAssertEqualsInsteadOfAssertTrue %} @@ -1404,11 +1437,11 @@ large projects, with many duplications, it was causing `OutOfMemoryError`s (see * {% rule java/bestpractices/UseAssertTrueInsteadOfAssertEquals %} * {% rule java/design/SimplifyBooleanAssertion %} -* The Java rule {% rule java/errorprone/ReturnEmptyArrayRatherThanNull %} is deprecated and removed from +* The Java rule {% rule java/errorprone/ReturnEmptyArrayRatherThanNull %} is deprecated and removed from the quickstart ruleset, as the new rule {% rule java/errorprone/ReturnEmptyCollectionRatherThanNull %} supersedes it. -* The following Java rules are deprecated and removed from the quickstart ruleset, +* The following Java rules are deprecated and removed from the quickstart ruleset, as the new rule {% rule java/bestpractices/PrimitiveWrapperInstantiation %} merges their functionality: * {% rule java/performance/BooleanInstantiation %} @@ -1417,8 +1450,22 @@ large projects, with many duplications, it was causing `OutOfMemoryError`s (see * {% rule java/performance/LongInstantiation %} * {% rule java/performance/ShortInstantiation %} -* The Java rule {% rule java/performance/UnnecessaryWrapperObjectCreation %} is deprecated +* The Java rule {% rule java/performance/UnnecessaryWrapperObjectCreation %} is deprecated with no planned replacement before PMD 7. In it's current state, the rule is not useful as it finds only contrived cases of creating a primitive wrapper and unboxing it explicitly in the same expression. In PMD 7 this and more cases will be covered by a new rule `UnnecessaryBoxing`. + +* Since 6.46.0: The following Java rules are deprecated and removed from the quickstart ruleset, as the new rule + {% rule java/codestyle/EmptyControlStatement %} merges their functionality: + * {% rule java/errorprone/EmptyFinallyBlock %} + * {% rule java/errorprone/EmptyIfStmt %} + * {% rule java/errorprone/EmptyInitializer %} + * {% rule java/errorprone/EmptyStatementBlock %} + * {% rule java/errorprone/EmptySwitchStatements %} + * {% rule java/errorprone/EmptySynchronizedBlock %} + * {% rule java/errorprone/EmptyTryBlock %} + * {% rule java/errorprone/EmptyWhileStmt %} + +* Since 6.46.0: The Java rule {% rule java/errorprone/EmptyStatementNotInLoop %} is deprecated and removed from the quickstart + ruleset. Use the new rule {% rule java/codestyle/UnnecessarySemicolon %} instead. diff --git a/docs/pages/release_notes.md b/docs/pages/release_notes.md index d9a513f75f..561254d8a8 100644 --- a/docs/pages/release_notes.md +++ b/docs/pages/release_notes.md @@ -151,5 +151,10 @@ and {% jdoc !!core::ant.Formatter#isNoOutputSupplied() %} have been internalized * [#3964](https://github.com/pmd/pmd/pull/3964): \[java] Fix #3874 - ImmutableField: fix mockito/spring false positives - [@lukelukes](https://github.com/lukelukes) * [#3974](https://github.com/pmd/pmd/pull/3974): \[cs] Add option to ignore C# attributes (annotations) - [@maikelsteneker](https://github.com/maikelsteneker) +### Stats +* 92 commits +* 30 closed tickets & PRs +* Days since last release: 28 + {% endtocmaker %} From a75acdeff8200223ddd2c1b24356a038f1fe7e6e Mon Sep 17 00:00:00 2001 From: Andreas Dangel Date: Sat, 28 May 2022 11:04:27 +0200 Subject: [PATCH 144/198] [maven-release-plugin] prepare release pmd_releases/6.46.0 --- pmd-apex-jorje/pom.xml | 2 +- pmd-apex/pom.xml | 2 +- pmd-core/pom.xml | 2 +- pmd-cpp/pom.xml | 2 +- pmd-cs/pom.xml | 2 +- pmd-dart/pom.xml | 2 +- pmd-dist/pom.xml | 2 +- pmd-doc/pom.xml | 2 +- pmd-fortran/pom.xml | 2 +- pmd-go/pom.xml | 2 +- pmd-groovy/pom.xml | 2 +- pmd-html/pom.xml | 2 +- pmd-java/pom.xml | 2 +- pmd-java8/pom.xml | 2 +- pmd-javascript/pom.xml | 2 +- pmd-jsp/pom.xml | 2 +- pmd-kotlin/pom.xml | 2 +- pmd-lang-test/pom.xml | 2 +- pmd-lua/pom.xml | 2 +- pmd-matlab/pom.xml | 2 +- pmd-modelica/pom.xml | 2 +- pmd-objectivec/pom.xml | 2 +- pmd-perl/pom.xml | 2 +- pmd-php/pom.xml | 2 +- pmd-plsql/pom.xml | 2 +- pmd-python/pom.xml | 2 +- pmd-ruby/pom.xml | 2 +- pmd-scala-modules/pmd-scala-common/pom.xml | 2 +- pmd-scala-modules/pmd-scala_2.12/pom.xml | 2 +- pmd-scala-modules/pmd-scala_2.13/pom.xml | 2 +- pmd-scala/pom.xml | 2 +- pmd-swift/pom.xml | 2 +- pmd-test/pom.xml | 2 +- pmd-visualforce/pom.xml | 2 +- pmd-vm/pom.xml | 2 +- pmd-xml/pom.xml | 2 +- pom.xml | 6 +++--- 37 files changed, 39 insertions(+), 39 deletions(-) diff --git a/pmd-apex-jorje/pom.xml b/pmd-apex-jorje/pom.xml index 778d8ff8f9..9e27b3bd62 100644 --- a/pmd-apex-jorje/pom.xml +++ b/pmd-apex-jorje/pom.xml @@ -8,7 +8,7 @@ net.sourceforge.pmd pmd - 6.46.0-SNAPSHOT + 6.46.0 ../ diff --git a/pmd-apex/pom.xml b/pmd-apex/pom.xml index 4b7786ff4e..cd0fae7517 100644 --- a/pmd-apex/pom.xml +++ b/pmd-apex/pom.xml @@ -7,7 +7,7 @@ net.sourceforge.pmd pmd - 6.46.0-SNAPSHOT + 6.46.0 ../ diff --git a/pmd-core/pom.xml b/pmd-core/pom.xml index bd60fcdfad..3d043e107c 100644 --- a/pmd-core/pom.xml +++ b/pmd-core/pom.xml @@ -7,7 +7,7 @@ net.sourceforge.pmd pmd - 6.46.0-SNAPSHOT + 6.46.0 ../ diff --git a/pmd-cpp/pom.xml b/pmd-cpp/pom.xml index 3c72c91f0c..56c4b00115 100644 --- a/pmd-cpp/pom.xml +++ b/pmd-cpp/pom.xml @@ -7,7 +7,7 @@ net.sourceforge.pmd pmd - 6.46.0-SNAPSHOT + 6.46.0 ../ diff --git a/pmd-cs/pom.xml b/pmd-cs/pom.xml index 220db5815e..f58a96465c 100644 --- a/pmd-cs/pom.xml +++ b/pmd-cs/pom.xml @@ -7,7 +7,7 @@ net.sourceforge.pmd pmd - 6.46.0-SNAPSHOT + 6.46.0 ../ diff --git a/pmd-dart/pom.xml b/pmd-dart/pom.xml index f49e28721e..af8f453116 100644 --- a/pmd-dart/pom.xml +++ b/pmd-dart/pom.xml @@ -7,7 +7,7 @@ net.sourceforge.pmd pmd - 6.46.0-SNAPSHOT + 6.46.0 ../ diff --git a/pmd-dist/pom.xml b/pmd-dist/pom.xml index 58348f8bbf..dd53c4f671 100644 --- a/pmd-dist/pom.xml +++ b/pmd-dist/pom.xml @@ -8,7 +8,7 @@ net.sourceforge.pmd pmd - 6.46.0-SNAPSHOT + 6.46.0 ../ diff --git a/pmd-doc/pom.xml b/pmd-doc/pom.xml index 5fda1dc5b9..fb7f1bcea7 100644 --- a/pmd-doc/pom.xml +++ b/pmd-doc/pom.xml @@ -8,7 +8,7 @@ net.sourceforge.pmd pmd - 6.46.0-SNAPSHOT + 6.46.0 ../ diff --git a/pmd-fortran/pom.xml b/pmd-fortran/pom.xml index d41d7c00db..23c851dbc9 100644 --- a/pmd-fortran/pom.xml +++ b/pmd-fortran/pom.xml @@ -7,7 +7,7 @@ net.sourceforge.pmd pmd - 6.46.0-SNAPSHOT + 6.46.0 ../ diff --git a/pmd-go/pom.xml b/pmd-go/pom.xml index 2b222b6828..ac43e2d153 100644 --- a/pmd-go/pom.xml +++ b/pmd-go/pom.xml @@ -7,7 +7,7 @@ net.sourceforge.pmd pmd - 6.46.0-SNAPSHOT + 6.46.0 ../ diff --git a/pmd-groovy/pom.xml b/pmd-groovy/pom.xml index 0ee77da952..aa9722fd1f 100644 --- a/pmd-groovy/pom.xml +++ b/pmd-groovy/pom.xml @@ -7,7 +7,7 @@ net.sourceforge.pmd pmd - 6.46.0-SNAPSHOT + 6.46.0 ../ diff --git a/pmd-html/pom.xml b/pmd-html/pom.xml index 60d5d84c58..2acc11cbbc 100644 --- a/pmd-html/pom.xml +++ b/pmd-html/pom.xml @@ -7,7 +7,7 @@ net.sourceforge.pmd pmd - 6.46.0-SNAPSHOT + 6.46.0 ../ diff --git a/pmd-java/pom.xml b/pmd-java/pom.xml index df12c9505f..41a3b8257c 100644 --- a/pmd-java/pom.xml +++ b/pmd-java/pom.xml @@ -7,7 +7,7 @@ net.sourceforge.pmd pmd - 6.46.0-SNAPSHOT + 6.46.0 ../ diff --git a/pmd-java8/pom.xml b/pmd-java8/pom.xml index 789472025c..433e5ab38e 100644 --- a/pmd-java8/pom.xml +++ b/pmd-java8/pom.xml @@ -7,7 +7,7 @@ net.sourceforge.pmd pmd - 6.46.0-SNAPSHOT + 6.46.0 ../ diff --git a/pmd-javascript/pom.xml b/pmd-javascript/pom.xml index d87540aceb..2e434a248e 100644 --- a/pmd-javascript/pom.xml +++ b/pmd-javascript/pom.xml @@ -7,7 +7,7 @@ net.sourceforge.pmd pmd - 6.46.0-SNAPSHOT + 6.46.0 ../ diff --git a/pmd-jsp/pom.xml b/pmd-jsp/pom.xml index baef67d1fc..87162d0053 100644 --- a/pmd-jsp/pom.xml +++ b/pmd-jsp/pom.xml @@ -7,7 +7,7 @@ net.sourceforge.pmd pmd - 6.46.0-SNAPSHOT + 6.46.0 ../ diff --git a/pmd-kotlin/pom.xml b/pmd-kotlin/pom.xml index fb25975fec..26cfd0df08 100644 --- a/pmd-kotlin/pom.xml +++ b/pmd-kotlin/pom.xml @@ -7,7 +7,7 @@ net.sourceforge.pmd pmd - 6.46.0-SNAPSHOT + 6.46.0 ../ diff --git a/pmd-lang-test/pom.xml b/pmd-lang-test/pom.xml index cbe2246ebd..1c73fb0000 100644 --- a/pmd-lang-test/pom.xml +++ b/pmd-lang-test/pom.xml @@ -12,7 +12,7 @@ net.sourceforge.pmd pmd - 6.46.0-SNAPSHOT + 6.46.0 ../ diff --git a/pmd-lua/pom.xml b/pmd-lua/pom.xml index 169eee58b6..81b9d10c7c 100644 --- a/pmd-lua/pom.xml +++ b/pmd-lua/pom.xml @@ -7,7 +7,7 @@ net.sourceforge.pmd pmd - 6.46.0-SNAPSHOT + 6.46.0 ../ diff --git a/pmd-matlab/pom.xml b/pmd-matlab/pom.xml index 278632df19..b15395cc55 100644 --- a/pmd-matlab/pom.xml +++ b/pmd-matlab/pom.xml @@ -7,7 +7,7 @@ net.sourceforge.pmd pmd - 6.46.0-SNAPSHOT + 6.46.0 ../ diff --git a/pmd-modelica/pom.xml b/pmd-modelica/pom.xml index 39ace11468..7a9d14ec91 100644 --- a/pmd-modelica/pom.xml +++ b/pmd-modelica/pom.xml @@ -7,7 +7,7 @@ net.sourceforge.pmd pmd - 6.46.0-SNAPSHOT + 6.46.0 ../ diff --git a/pmd-objectivec/pom.xml b/pmd-objectivec/pom.xml index fda16dfe0b..049ebe87ad 100644 --- a/pmd-objectivec/pom.xml +++ b/pmd-objectivec/pom.xml @@ -7,7 +7,7 @@ net.sourceforge.pmd pmd - 6.46.0-SNAPSHOT + 6.46.0 ../ diff --git a/pmd-perl/pom.xml b/pmd-perl/pom.xml index 53060f5e27..0a23d34200 100644 --- a/pmd-perl/pom.xml +++ b/pmd-perl/pom.xml @@ -7,7 +7,7 @@ net.sourceforge.pmd pmd - 6.46.0-SNAPSHOT + 6.46.0 ../ diff --git a/pmd-php/pom.xml b/pmd-php/pom.xml index 21fee6046d..e92c593502 100644 --- a/pmd-php/pom.xml +++ b/pmd-php/pom.xml @@ -7,7 +7,7 @@ net.sourceforge.pmd pmd - 6.46.0-SNAPSHOT + 6.46.0 ../ diff --git a/pmd-plsql/pom.xml b/pmd-plsql/pom.xml index dc302dc3d9..4faa75f082 100644 --- a/pmd-plsql/pom.xml +++ b/pmd-plsql/pom.xml @@ -7,7 +7,7 @@ net.sourceforge.pmd pmd - 6.46.0-SNAPSHOT + 6.46.0 ../ diff --git a/pmd-python/pom.xml b/pmd-python/pom.xml index 3170b0ba55..c174dd766b 100644 --- a/pmd-python/pom.xml +++ b/pmd-python/pom.xml @@ -7,7 +7,7 @@ net.sourceforge.pmd pmd - 6.46.0-SNAPSHOT + 6.46.0 ../ diff --git a/pmd-ruby/pom.xml b/pmd-ruby/pom.xml index 35fb4b5753..c5a210078b 100644 --- a/pmd-ruby/pom.xml +++ b/pmd-ruby/pom.xml @@ -7,7 +7,7 @@ net.sourceforge.pmd pmd - 6.46.0-SNAPSHOT + 6.46.0 ../ diff --git a/pmd-scala-modules/pmd-scala-common/pom.xml b/pmd-scala-modules/pmd-scala-common/pom.xml index fa9fff2d04..f2c8a9ed37 100644 --- a/pmd-scala-modules/pmd-scala-common/pom.xml +++ b/pmd-scala-modules/pmd-scala-common/pom.xml @@ -8,7 +8,7 @@ net.sourceforge.pmd pmd - 6.46.0-SNAPSHOT + 6.46.0 ../.. diff --git a/pmd-scala-modules/pmd-scala_2.12/pom.xml b/pmd-scala-modules/pmd-scala_2.12/pom.xml index 244b9c52ab..a39e6d9b02 100644 --- a/pmd-scala-modules/pmd-scala_2.12/pom.xml +++ b/pmd-scala-modules/pmd-scala_2.12/pom.xml @@ -7,7 +7,7 @@ net.sourceforge.pmd pmd-scala-common - 6.46.0-SNAPSHOT + 6.46.0 ../pmd-scala-common diff --git a/pmd-scala-modules/pmd-scala_2.13/pom.xml b/pmd-scala-modules/pmd-scala_2.13/pom.xml index 1206d12f5d..5d83479747 100644 --- a/pmd-scala-modules/pmd-scala_2.13/pom.xml +++ b/pmd-scala-modules/pmd-scala_2.13/pom.xml @@ -7,7 +7,7 @@ net.sourceforge.pmd pmd-scala-common - 6.46.0-SNAPSHOT + 6.46.0 ../pmd-scala-common diff --git a/pmd-scala/pom.xml b/pmd-scala/pom.xml index 211a199e81..c55882960b 100644 --- a/pmd-scala/pom.xml +++ b/pmd-scala/pom.xml @@ -9,7 +9,7 @@ net.sourceforge.pmd pmd - 6.46.0-SNAPSHOT + 6.46.0 ../ diff --git a/pmd-swift/pom.xml b/pmd-swift/pom.xml index dcfe7b980a..d4571d4db3 100644 --- a/pmd-swift/pom.xml +++ b/pmd-swift/pom.xml @@ -7,7 +7,7 @@ net.sourceforge.pmd pmd - 6.46.0-SNAPSHOT + 6.46.0 ../ diff --git a/pmd-test/pom.xml b/pmd-test/pom.xml index d60f6f2e66..93c0c7b6e1 100644 --- a/pmd-test/pom.xml +++ b/pmd-test/pom.xml @@ -8,7 +8,7 @@ net.sourceforge.pmd pmd - 6.46.0-SNAPSHOT + 6.46.0 ../ diff --git a/pmd-visualforce/pom.xml b/pmd-visualforce/pom.xml index deb955ece6..2b36937df5 100644 --- a/pmd-visualforce/pom.xml +++ b/pmd-visualforce/pom.xml @@ -7,7 +7,7 @@ net.sourceforge.pmd pmd - 6.46.0-SNAPSHOT + 6.46.0 ../ diff --git a/pmd-vm/pom.xml b/pmd-vm/pom.xml index 6faab019c3..1089c1b2f1 100644 --- a/pmd-vm/pom.xml +++ b/pmd-vm/pom.xml @@ -7,7 +7,7 @@ net.sourceforge.pmd pmd - 6.46.0-SNAPSHOT + 6.46.0 ../ diff --git a/pmd-xml/pom.xml b/pmd-xml/pom.xml index 993fc1a147..77f54c6b3b 100644 --- a/pmd-xml/pom.xml +++ b/pmd-xml/pom.xml @@ -7,7 +7,7 @@ net.sourceforge.pmd pmd - 6.46.0-SNAPSHOT + 6.46.0 ../ diff --git a/pom.xml b/pom.xml index d490311e5d..59965856b7 100644 --- a/pom.xml +++ b/pom.xml @@ -3,7 +3,7 @@ 4.0.0 net.sourceforge.pmd pmd - 6.46.0-SNAPSHOT + 6.46.0 pom PMD @@ -55,7 +55,7 @@ scm:git:git://github.com/pmd/pmd.git scm:git:ssh://git@github.com/pmd/pmd.git https://github.com/pmd/pmd - HEAD + pmd_releases/6.46.0 @@ -76,7 +76,7 @@ - 2022-04-30T07:38:24Z + 2022-05-28T08:50:57Z 7 From 04c1271d88ae1949f207a791c8085a018b303f0e Mon Sep 17 00:00:00 2001 From: Andreas Dangel Date: Sat, 28 May 2022 11:04:32 +0200 Subject: [PATCH 145/198] [maven-release-plugin] prepare for next development iteration --- pmd-apex-jorje/pom.xml | 2 +- pmd-apex/pom.xml | 2 +- pmd-core/pom.xml | 2 +- pmd-cpp/pom.xml | 2 +- pmd-cs/pom.xml | 2 +- pmd-dart/pom.xml | 2 +- pmd-dist/pom.xml | 2 +- pmd-doc/pom.xml | 2 +- pmd-fortran/pom.xml | 2 +- pmd-go/pom.xml | 2 +- pmd-groovy/pom.xml | 2 +- pmd-html/pom.xml | 2 +- pmd-java/pom.xml | 2 +- pmd-java8/pom.xml | 2 +- pmd-javascript/pom.xml | 2 +- pmd-jsp/pom.xml | 2 +- pmd-kotlin/pom.xml | 2 +- pmd-lang-test/pom.xml | 2 +- pmd-lua/pom.xml | 2 +- pmd-matlab/pom.xml | 2 +- pmd-modelica/pom.xml | 2 +- pmd-objectivec/pom.xml | 2 +- pmd-perl/pom.xml | 2 +- pmd-php/pom.xml | 2 +- pmd-plsql/pom.xml | 2 +- pmd-python/pom.xml | 2 +- pmd-ruby/pom.xml | 2 +- pmd-scala-modules/pmd-scala-common/pom.xml | 2 +- pmd-scala-modules/pmd-scala_2.12/pom.xml | 2 +- pmd-scala-modules/pmd-scala_2.13/pom.xml | 2 +- pmd-scala/pom.xml | 2 +- pmd-swift/pom.xml | 2 +- pmd-test/pom.xml | 2 +- pmd-visualforce/pom.xml | 2 +- pmd-vm/pom.xml | 2 +- pmd-xml/pom.xml | 2 +- pom.xml | 6 +++--- 37 files changed, 39 insertions(+), 39 deletions(-) diff --git a/pmd-apex-jorje/pom.xml b/pmd-apex-jorje/pom.xml index 9e27b3bd62..3666d840ce 100644 --- a/pmd-apex-jorje/pom.xml +++ b/pmd-apex-jorje/pom.xml @@ -8,7 +8,7 @@ net.sourceforge.pmd pmd - 6.46.0 + 6.47.0-SNAPSHOT ../ diff --git a/pmd-apex/pom.xml b/pmd-apex/pom.xml index cd0fae7517..9eebf20f95 100644 --- a/pmd-apex/pom.xml +++ b/pmd-apex/pom.xml @@ -7,7 +7,7 @@ net.sourceforge.pmd pmd - 6.46.0 + 6.47.0-SNAPSHOT ../ diff --git a/pmd-core/pom.xml b/pmd-core/pom.xml index 3d043e107c..09da20cebe 100644 --- a/pmd-core/pom.xml +++ b/pmd-core/pom.xml @@ -7,7 +7,7 @@ net.sourceforge.pmd pmd - 6.46.0 + 6.47.0-SNAPSHOT ../ diff --git a/pmd-cpp/pom.xml b/pmd-cpp/pom.xml index 56c4b00115..4a7287fcbf 100644 --- a/pmd-cpp/pom.xml +++ b/pmd-cpp/pom.xml @@ -7,7 +7,7 @@ net.sourceforge.pmd pmd - 6.46.0 + 6.47.0-SNAPSHOT ../ diff --git a/pmd-cs/pom.xml b/pmd-cs/pom.xml index f58a96465c..2de4e3d6b7 100644 --- a/pmd-cs/pom.xml +++ b/pmd-cs/pom.xml @@ -7,7 +7,7 @@ net.sourceforge.pmd pmd - 6.46.0 + 6.47.0-SNAPSHOT ../ diff --git a/pmd-dart/pom.xml b/pmd-dart/pom.xml index af8f453116..35c30a87c3 100644 --- a/pmd-dart/pom.xml +++ b/pmd-dart/pom.xml @@ -7,7 +7,7 @@ net.sourceforge.pmd pmd - 6.46.0 + 6.47.0-SNAPSHOT ../ diff --git a/pmd-dist/pom.xml b/pmd-dist/pom.xml index dd53c4f671..edaf2e9a89 100644 --- a/pmd-dist/pom.xml +++ b/pmd-dist/pom.xml @@ -8,7 +8,7 @@ net.sourceforge.pmd pmd - 6.46.0 + 6.47.0-SNAPSHOT ../ diff --git a/pmd-doc/pom.xml b/pmd-doc/pom.xml index fb7f1bcea7..5721c1a635 100644 --- a/pmd-doc/pom.xml +++ b/pmd-doc/pom.xml @@ -8,7 +8,7 @@ net.sourceforge.pmd pmd - 6.46.0 + 6.47.0-SNAPSHOT ../ diff --git a/pmd-fortran/pom.xml b/pmd-fortran/pom.xml index 23c851dbc9..5e5c483a30 100644 --- a/pmd-fortran/pom.xml +++ b/pmd-fortran/pom.xml @@ -7,7 +7,7 @@ net.sourceforge.pmd pmd - 6.46.0 + 6.47.0-SNAPSHOT ../ diff --git a/pmd-go/pom.xml b/pmd-go/pom.xml index ac43e2d153..9ec6b42466 100644 --- a/pmd-go/pom.xml +++ b/pmd-go/pom.xml @@ -7,7 +7,7 @@ net.sourceforge.pmd pmd - 6.46.0 + 6.47.0-SNAPSHOT ../ diff --git a/pmd-groovy/pom.xml b/pmd-groovy/pom.xml index aa9722fd1f..2ccd52164f 100644 --- a/pmd-groovy/pom.xml +++ b/pmd-groovy/pom.xml @@ -7,7 +7,7 @@ net.sourceforge.pmd pmd - 6.46.0 + 6.47.0-SNAPSHOT ../ diff --git a/pmd-html/pom.xml b/pmd-html/pom.xml index 2acc11cbbc..b77f7d296d 100644 --- a/pmd-html/pom.xml +++ b/pmd-html/pom.xml @@ -7,7 +7,7 @@ net.sourceforge.pmd pmd - 6.46.0 + 6.47.0-SNAPSHOT ../ diff --git a/pmd-java/pom.xml b/pmd-java/pom.xml index 41a3b8257c..ecb14302c2 100644 --- a/pmd-java/pom.xml +++ b/pmd-java/pom.xml @@ -7,7 +7,7 @@ net.sourceforge.pmd pmd - 6.46.0 + 6.47.0-SNAPSHOT ../ diff --git a/pmd-java8/pom.xml b/pmd-java8/pom.xml index 433e5ab38e..c367c8064a 100644 --- a/pmd-java8/pom.xml +++ b/pmd-java8/pom.xml @@ -7,7 +7,7 @@ net.sourceforge.pmd pmd - 6.46.0 + 6.47.0-SNAPSHOT ../ diff --git a/pmd-javascript/pom.xml b/pmd-javascript/pom.xml index 2e434a248e..09725d447e 100644 --- a/pmd-javascript/pom.xml +++ b/pmd-javascript/pom.xml @@ -7,7 +7,7 @@ net.sourceforge.pmd pmd - 6.46.0 + 6.47.0-SNAPSHOT ../ diff --git a/pmd-jsp/pom.xml b/pmd-jsp/pom.xml index 87162d0053..1fd17a18c2 100644 --- a/pmd-jsp/pom.xml +++ b/pmd-jsp/pom.xml @@ -7,7 +7,7 @@ net.sourceforge.pmd pmd - 6.46.0 + 6.47.0-SNAPSHOT ../ diff --git a/pmd-kotlin/pom.xml b/pmd-kotlin/pom.xml index 26cfd0df08..939c94f0e3 100644 --- a/pmd-kotlin/pom.xml +++ b/pmd-kotlin/pom.xml @@ -7,7 +7,7 @@ net.sourceforge.pmd pmd - 6.46.0 + 6.47.0-SNAPSHOT ../ diff --git a/pmd-lang-test/pom.xml b/pmd-lang-test/pom.xml index 1c73fb0000..ce1bc5067e 100644 --- a/pmd-lang-test/pom.xml +++ b/pmd-lang-test/pom.xml @@ -12,7 +12,7 @@ net.sourceforge.pmd pmd - 6.46.0 + 6.47.0-SNAPSHOT ../ diff --git a/pmd-lua/pom.xml b/pmd-lua/pom.xml index 81b9d10c7c..b7f3fbe731 100644 --- a/pmd-lua/pom.xml +++ b/pmd-lua/pom.xml @@ -7,7 +7,7 @@ net.sourceforge.pmd pmd - 6.46.0 + 6.47.0-SNAPSHOT ../ diff --git a/pmd-matlab/pom.xml b/pmd-matlab/pom.xml index b15395cc55..0de710099a 100644 --- a/pmd-matlab/pom.xml +++ b/pmd-matlab/pom.xml @@ -7,7 +7,7 @@ net.sourceforge.pmd pmd - 6.46.0 + 6.47.0-SNAPSHOT ../ diff --git a/pmd-modelica/pom.xml b/pmd-modelica/pom.xml index 7a9d14ec91..341803ec4e 100644 --- a/pmd-modelica/pom.xml +++ b/pmd-modelica/pom.xml @@ -7,7 +7,7 @@ net.sourceforge.pmd pmd - 6.46.0 + 6.47.0-SNAPSHOT ../ diff --git a/pmd-objectivec/pom.xml b/pmd-objectivec/pom.xml index 049ebe87ad..cedfce8126 100644 --- a/pmd-objectivec/pom.xml +++ b/pmd-objectivec/pom.xml @@ -7,7 +7,7 @@ net.sourceforge.pmd pmd - 6.46.0 + 6.47.0-SNAPSHOT ../ diff --git a/pmd-perl/pom.xml b/pmd-perl/pom.xml index 0a23d34200..558fa427c8 100644 --- a/pmd-perl/pom.xml +++ b/pmd-perl/pom.xml @@ -7,7 +7,7 @@ net.sourceforge.pmd pmd - 6.46.0 + 6.47.0-SNAPSHOT ../ diff --git a/pmd-php/pom.xml b/pmd-php/pom.xml index e92c593502..782f861703 100644 --- a/pmd-php/pom.xml +++ b/pmd-php/pom.xml @@ -7,7 +7,7 @@ net.sourceforge.pmd pmd - 6.46.0 + 6.47.0-SNAPSHOT ../ diff --git a/pmd-plsql/pom.xml b/pmd-plsql/pom.xml index 4faa75f082..c0a1762555 100644 --- a/pmd-plsql/pom.xml +++ b/pmd-plsql/pom.xml @@ -7,7 +7,7 @@ net.sourceforge.pmd pmd - 6.46.0 + 6.47.0-SNAPSHOT ../ diff --git a/pmd-python/pom.xml b/pmd-python/pom.xml index c174dd766b..1161024852 100644 --- a/pmd-python/pom.xml +++ b/pmd-python/pom.xml @@ -7,7 +7,7 @@ net.sourceforge.pmd pmd - 6.46.0 + 6.47.0-SNAPSHOT ../ diff --git a/pmd-ruby/pom.xml b/pmd-ruby/pom.xml index c5a210078b..5bc68ba973 100644 --- a/pmd-ruby/pom.xml +++ b/pmd-ruby/pom.xml @@ -7,7 +7,7 @@ net.sourceforge.pmd pmd - 6.46.0 + 6.47.0-SNAPSHOT ../ diff --git a/pmd-scala-modules/pmd-scala-common/pom.xml b/pmd-scala-modules/pmd-scala-common/pom.xml index f2c8a9ed37..20ace8b9c8 100644 --- a/pmd-scala-modules/pmd-scala-common/pom.xml +++ b/pmd-scala-modules/pmd-scala-common/pom.xml @@ -8,7 +8,7 @@ net.sourceforge.pmd pmd - 6.46.0 + 6.47.0-SNAPSHOT ../.. diff --git a/pmd-scala-modules/pmd-scala_2.12/pom.xml b/pmd-scala-modules/pmd-scala_2.12/pom.xml index a39e6d9b02..4765990084 100644 --- a/pmd-scala-modules/pmd-scala_2.12/pom.xml +++ b/pmd-scala-modules/pmd-scala_2.12/pom.xml @@ -7,7 +7,7 @@ net.sourceforge.pmd pmd-scala-common - 6.46.0 + 6.47.0-SNAPSHOT ../pmd-scala-common diff --git a/pmd-scala-modules/pmd-scala_2.13/pom.xml b/pmd-scala-modules/pmd-scala_2.13/pom.xml index 5d83479747..9b5c50f976 100644 --- a/pmd-scala-modules/pmd-scala_2.13/pom.xml +++ b/pmd-scala-modules/pmd-scala_2.13/pom.xml @@ -7,7 +7,7 @@ net.sourceforge.pmd pmd-scala-common - 6.46.0 + 6.47.0-SNAPSHOT ../pmd-scala-common diff --git a/pmd-scala/pom.xml b/pmd-scala/pom.xml index c55882960b..bc1c3e9ccd 100644 --- a/pmd-scala/pom.xml +++ b/pmd-scala/pom.xml @@ -9,7 +9,7 @@ net.sourceforge.pmd pmd - 6.46.0 + 6.47.0-SNAPSHOT ../ diff --git a/pmd-swift/pom.xml b/pmd-swift/pom.xml index d4571d4db3..10032db400 100644 --- a/pmd-swift/pom.xml +++ b/pmd-swift/pom.xml @@ -7,7 +7,7 @@ net.sourceforge.pmd pmd - 6.46.0 + 6.47.0-SNAPSHOT ../ diff --git a/pmd-test/pom.xml b/pmd-test/pom.xml index 93c0c7b6e1..b8757a44a0 100644 --- a/pmd-test/pom.xml +++ b/pmd-test/pom.xml @@ -8,7 +8,7 @@ net.sourceforge.pmd pmd - 6.46.0 + 6.47.0-SNAPSHOT ../ diff --git a/pmd-visualforce/pom.xml b/pmd-visualforce/pom.xml index 2b36937df5..4e2ef9d4ba 100644 --- a/pmd-visualforce/pom.xml +++ b/pmd-visualforce/pom.xml @@ -7,7 +7,7 @@ net.sourceforge.pmd pmd - 6.46.0 + 6.47.0-SNAPSHOT ../ diff --git a/pmd-vm/pom.xml b/pmd-vm/pom.xml index 1089c1b2f1..bfbb62269f 100644 --- a/pmd-vm/pom.xml +++ b/pmd-vm/pom.xml @@ -7,7 +7,7 @@ net.sourceforge.pmd pmd - 6.46.0 + 6.47.0-SNAPSHOT ../ diff --git a/pmd-xml/pom.xml b/pmd-xml/pom.xml index 77f54c6b3b..26c8a9faf8 100644 --- a/pmd-xml/pom.xml +++ b/pmd-xml/pom.xml @@ -7,7 +7,7 @@ net.sourceforge.pmd pmd - 6.46.0 + 6.47.0-SNAPSHOT ../ diff --git a/pom.xml b/pom.xml index 59965856b7..f354efbd91 100644 --- a/pom.xml +++ b/pom.xml @@ -3,7 +3,7 @@ 4.0.0 net.sourceforge.pmd pmd - 6.46.0 + 6.47.0-SNAPSHOT pom PMD @@ -55,7 +55,7 @@ scm:git:git://github.com/pmd/pmd.git scm:git:ssh://git@github.com/pmd/pmd.git https://github.com/pmd/pmd - pmd_releases/6.46.0 + HEAD @@ -76,7 +76,7 @@ - 2022-05-28T08:50:57Z + 2022-05-28T09:04:31Z 7 From c3f6be479b093c7dd2a3aa7debef6c25e9d1438c Mon Sep 17 00:00:00 2001 From: Andreas Dangel Date: Sat, 28 May 2022 11:05:56 +0200 Subject: [PATCH 146/198] Prepare next development version [skip ci] --- docs/_config.yml | 6 +- docs/pages/release_notes.md | 136 -------------------------- docs/pages/release_notes_old.md | 165 ++++++++++++++++++++++++++++++++ 3 files changed, 168 insertions(+), 139 deletions(-) diff --git a/docs/_config.yml b/docs/_config.yml index 150e6e2fd1..e642bcc872 100644 --- a/docs/_config.yml +++ b/docs/_config.yml @@ -1,9 +1,9 @@ repository: pmd/pmd pmd: - version: 6.46.0 - previous_version: 6.45.0 - date: 28-May-2022 + version: 6.47.0-SNAPSHOT + previous_version: 6.46.0 + date: 25-June-2022 release_type: minor # release types: major, minor, bugfix diff --git a/docs/pages/release_notes.md b/docs/pages/release_notes.md index 561254d8a8..b8f8783555 100644 --- a/docs/pages/release_notes.md +++ b/docs/pages/release_notes.md @@ -14,147 +14,11 @@ This is a {{ site.pmd.release_type }} release. ### New and noteworthy -#### CLI improvements - -The PMD CLI now allows repeating the `--dir` (`-d`) and `--rulesets` (`-R`) options, - as well as providing several space-separated arguments to either of them. For instance: -```shell -pmd -d src/main/java src/test/java -R rset1.xml -R rset2.xml -``` -This also allows globs to be used on the CLI if your shell supports shell expansion. -For instance, the above can be written -```shell -pmd -d src/*/java -R rset*.xml -``` -Please use theses new forms instead of using comma-separated lists as argument to these options. - -#### C# Improvements - -When executing CPD on C# sources, the option `--ignore-annotations` is now supported as well. -It ignores C# attributes when detecting duplicated code. This option can also be enabled via -the CPD GUI. See [#3974](https://github.com/pmd/pmd/pull/3974) for details. - -#### New Rules - -This release ships with 2 new Java rules. - -* {% rule java/codestyle/EmptyControlStatement %} reports many instances of empty things, e.g. control statements whose - body is empty, as well as empty initializers. - - EmptyControlStatement also works for empty `for` and `do` loops, while there were previously - no corresponding rules. - - This new rule replaces the rules EmptyFinallyBlock, EmptyIfStmt, EmptyInitializer, EmptyStatementBlock, - EmptySwitchStatements, EmptySynchronizedBlock, EmptyTryBlock, and EmptyWhileStmt. - -```xml - -``` - -The rule is part of the quickstart.xml ruleset. - -* {%rule java/codestyle/UnnecessarySemicolon %} reports semicolons that are unnecessary (so called "empty statements" - and "empty declarations"). - - This new rule replaces the rule EmptyStatementNotInLoop. - -```xml - -``` - -The rule is part of the quickstart.xml ruleset. - -#### Deprecated Rules - -* The following Java rules are deprecated and removed from the quickstart ruleset, as the new rule -{% rule java/codestyle/EmptyControlStatement %} merges their functionality: - * {% rule java/errorprone/EmptyFinallyBlock %} - * {% rule java/errorprone/EmptyIfStmt %} - * {% rule java/errorprone/EmptyInitializer %} - * {% rule java/errorprone/EmptyStatementBlock %} - * {% rule java/errorprone/EmptySwitchStatements %} - * {% rule java/errorprone/EmptySynchronizedBlock %} - * {% rule java/errorprone/EmptyTryBlock %} - * {% rule java/errorprone/EmptyWhileStmt %} -* The Java rule {% rule java/errorprone/EmptyStatementNotInLoop %} is deprecated and removed from the quickstart -ruleset. Use the new rule {% rule java/codestyle/UnnecessarySemicolon %} instead. - ### Fixed Issues -* cli - * [#1445](https://github.com/pmd/pmd/issues/1445): \[core] Allow CLI to take globs as parameters -* core - * [#2352](https://github.com/pmd/pmd/issues/2352): \[core] Deprecate \-\ hyphen notation for ruleset references - * [#3787](https://github.com/pmd/pmd/issues/3787): \[core] Internalize some methods in Ant Formatter - * [#3835](https://github.com/pmd/pmd/issues/3835): \[core] Deprecate system properties of CPDCommandLineInterface - * [#3942](https://github.com/pmd/pmd/issues/3942): \[core] common-io path traversal vulnerability (CVE-2021-29425) -* cs (c#) - * [#3974](https://github.com/pmd/pmd/pull/3974): \[cs] Add option to ignore C# attributes (annotations) -* go - * [#2752](https://github.com/pmd/pmd/issues/2752): \[go] Error parsing unicode values -* html - * [#3955](https://github.com/pmd/pmd/pull/3955): \[html] Improvements for handling text and comment nodes - * [#3978](https://github.com/pmd/pmd/pull/3978): \[html] Add additional file extensions htm, xhtml, xht, shtml -* java - * [#3423](https://github.com/pmd/pmd/issues/3423): \[java] Error processing identifiers with Unicode -* java-bestpractices - * [#3954](https://github.com/pmd/pmd/issues/3954): \[java] NPE in UseCollectionIsEmptyRule when .size() is called in a record -* java-design - * [#3874](https://github.com/pmd/pmd/issues/3874): \[java] ImmutableField reports fields annotated with @Autowired (Spring) and @Mock (Mockito) -* java-errorprone - * [#3096](https://github.com/pmd/pmd/issues/3096): \[java] EmptyStatementNotInLoop FP in 6.30.0 with IfStatement -* java-performance - * [#3379](https://github.com/pmd/pmd/issues/3379): \[java] UseArraysAsList must ignore primitive arrays - * [#3965](https://github.com/pmd/pmd/issues/3965): \[java] UseArraysAsList false positive with non-trivial loops -* javascript - * [#2605](https://github.com/pmd/pmd/issues/2605): \[js] Support unicode characters - * [#3948](https://github.com/pmd/pmd/issues/3948): \[js] Invalid operator error for method property in object literal -* python - * [#2604](https://github.com/pmd/pmd/issues/2604): \[python] Support unicode identifiers - ### API Changes -#### Deprecated ruleset references - -Ruleset references with the following formats are now deprecated and will produce a warning -when used on the CLI or in a ruleset XML file: -- `-`, eg `java-basic`, which resolves to `rulesets/java/basic.xml` -- the internal release number, eg `600`, which resolves to `rulesets/releases/600.xml` - -Use the explicit forms of these references to be compatible with PMD 7. - -#### Deprecated API - -- {% jdoc core::RuleSetReferenceId#toString() %} is now deprecated. The format of this - method will remain the same until PMD 7. The deprecation is intended to steer users - away from relying on this format, as it may be changed in PMD 7. -- {% jdoc core::PMDConfiguration#getInputPaths() %} and -{% jdoc core::PMDConfiguration#setInputPaths(java.lang.String) %} are now deprecated. -A new set of methods have been added, which use lists and do not rely on comma splitting. - -#### Internal API - -Those APIs are not intended to be used by clients, and will be hidden or removed with PMD 7.0.0. -You can identify them with the `@InternalApi` annotation. You'll also get a deprecation warning. - -- {% jdoc core::cpd.CPDCommandLineInterface %} has been internalized. In order to execute CPD either -{% jdoc !!core::cpd.CPD#run(java.lang.String...) %} or {% jdoc !!core::cpd.CPD#main(java.lang.String[]) %} -should be used. -- Several members of {% jdoc test::cli.BaseCPDCLITest %} have been deprecated with replacements. -- The methods {% jdoc !!core::ant.Formatter#start(java.lang.String) %}, -{% jdoc !!core::ant.Formatter#end(net.sourceforge.pmd.Report) %}, {% jdoc !!core::ant.Formatter#getRenderer() %}, -and {% jdoc !!core::ant.Formatter#isNoOutputSupplied() %} have been internalized. - ### External Contributions -* [#3961](https://github.com/pmd/pmd/pull/3961): \[java] Fix #3954 - NPE in UseCollectionIsEmptyRule with record - [@flyhard](https://github.com/flyhard) -* [#3964](https://github.com/pmd/pmd/pull/3964): \[java] Fix #3874 - ImmutableField: fix mockito/spring false positives - [@lukelukes](https://github.com/lukelukes) -* [#3974](https://github.com/pmd/pmd/pull/3974): \[cs] Add option to ignore C# attributes (annotations) - [@maikelsteneker](https://github.com/maikelsteneker) - -### Stats -* 92 commits -* 30 closed tickets & PRs -* Days since last release: 28 - {% endtocmaker %} diff --git a/docs/pages/release_notes_old.md b/docs/pages/release_notes_old.md index 1d546c49c1..0dc2d9c9f1 100644 --- a/docs/pages/release_notes_old.md +++ b/docs/pages/release_notes_old.md @@ -5,6 +5,171 @@ permalink: pmd_release_notes_old.html Previous versions of PMD can be downloaded here: https://github.com/pmd/pmd/releases +## 28-May-2022 - 6.46.0 + +The PMD team is pleased to announce PMD 6.46.0. + +This is a minor release. + +### Table Of Contents + +* [New and noteworthy](#new-and-noteworthy) + * [CLI improvements](#cli-improvements) + * [C# Improvements](#c#-improvements) + * [New Rules](#new-rules) + * [Deprecated Rules](#deprecated-rules) +* [Fixed Issues](#fixed-issues) +* [API Changes](#api-changes) + * [Deprecated ruleset references](#deprecated-ruleset-references) + * [Deprecated API](#deprecated-api) + * [Internal API](#internal-api) +* [External Contributions](#external-contributions) +* [Stats](#stats) + +### New and noteworthy + +#### CLI improvements + +The PMD CLI now allows repeating the `--dir` (`-d`) and `--rulesets` (`-R`) options, + as well as providing several space-separated arguments to either of them. For instance: +```shell +pmd -d src/main/java src/test/java -R rset1.xml -R rset2.xml +``` +This also allows globs to be used on the CLI if your shell supports shell expansion. +For instance, the above can be written +```shell +pmd -d src/*/java -R rset*.xml +``` +Please use theses new forms instead of using comma-separated lists as argument to these options. + +#### C# Improvements + +When executing CPD on C# sources, the option `--ignore-annotations` is now supported as well. +It ignores C# attributes when detecting duplicated code. This option can also be enabled via +the CPD GUI. See [#3974](https://github.com/pmd/pmd/pull/3974) for details. + +#### New Rules + +This release ships with 2 new Java rules. + +* [`EmptyControlStatement`](https://pmd.github.io/pmd-6.46.0/pmd_rules_java_codestyle.html#emptycontrolstatement) reports many instances of empty things, e.g. control statements whose + body is empty, as well as empty initializers. + + EmptyControlStatement also works for empty `for` and `do` loops, while there were previously + no corresponding rules. + + This new rule replaces the rules EmptyFinallyBlock, EmptyIfStmt, EmptyInitializer, EmptyStatementBlock, + EmptySwitchStatements, EmptySynchronizedBlock, EmptyTryBlock, and EmptyWhileStmt. + +```xml + +``` + +The rule is part of the quickstart.xml ruleset. + +* [`UnnecessarySemicolon`](https://pmd.github.io/pmd-6.46.0/pmd_rules_java_codestyle.html#unnecessarysemicolon) reports semicolons that are unnecessary (so called "empty statements" + and "empty declarations"). + + This new rule replaces the rule EmptyStatementNotInLoop. + +```xml + +``` + +The rule is part of the quickstart.xml ruleset. + +#### Deprecated Rules + +* The following Java rules are deprecated and removed from the quickstart ruleset, as the new rule +[`EmptyControlStatement`](https://pmd.github.io/pmd-6.46.0/pmd_rules_java_codestyle.html#emptycontrolstatement) merges their functionality: + * [`EmptyFinallyBlock`](https://pmd.github.io/pmd-6.46.0/pmd_rules_java_errorprone.html#emptyfinallyblock) + * [`EmptyIfStmt`](https://pmd.github.io/pmd-6.46.0/pmd_rules_java_errorprone.html#emptyifstmt) + * [`EmptyInitializer`](https://pmd.github.io/pmd-6.46.0/pmd_rules_java_errorprone.html#emptyinitializer) + * [`EmptyStatementBlock`](https://pmd.github.io/pmd-6.46.0/pmd_rules_java_errorprone.html#emptystatementblock) + * [`EmptySwitchStatements`](https://pmd.github.io/pmd-6.46.0/pmd_rules_java_errorprone.html#emptyswitchstatements) + * [`EmptySynchronizedBlock`](https://pmd.github.io/pmd-6.46.0/pmd_rules_java_errorprone.html#emptysynchronizedblock) + * [`EmptyTryBlock`](https://pmd.github.io/pmd-6.46.0/pmd_rules_java_errorprone.html#emptytryblock) + * [`EmptyWhileStmt`](https://pmd.github.io/pmd-6.46.0/pmd_rules_java_errorprone.html#emptywhilestmt) +* The Java rule [`EmptyStatementNotInLoop`](https://pmd.github.io/pmd-6.46.0/pmd_rules_java_errorprone.html#emptystatementnotinloop) is deprecated and removed from the quickstart +ruleset. Use the new rule [`UnnecessarySemicolon`](https://pmd.github.io/pmd-6.46.0/pmd_rules_java_codestyle.html#unnecessarysemicolon) instead. + +### Fixed Issues + +* cli + * [#1445](https://github.com/pmd/pmd/issues/1445): \[core] Allow CLI to take globs as parameters +* core + * [#2352](https://github.com/pmd/pmd/issues/2352): \[core] Deprecate \-\ hyphen notation for ruleset references + * [#3787](https://github.com/pmd/pmd/issues/3787): \[core] Internalize some methods in Ant Formatter + * [#3835](https://github.com/pmd/pmd/issues/3835): \[core] Deprecate system properties of CPDCommandLineInterface + * [#3942](https://github.com/pmd/pmd/issues/3942): \[core] common-io path traversal vulnerability (CVE-2021-29425) +* cs (c#) + * [#3974](https://github.com/pmd/pmd/pull/3974): \[cs] Add option to ignore C# attributes (annotations) +* go + * [#2752](https://github.com/pmd/pmd/issues/2752): \[go] Error parsing unicode values +* html + * [#3955](https://github.com/pmd/pmd/pull/3955): \[html] Improvements for handling text and comment nodes + * [#3978](https://github.com/pmd/pmd/pull/3978): \[html] Add additional file extensions htm, xhtml, xht, shtml +* java + * [#3423](https://github.com/pmd/pmd/issues/3423): \[java] Error processing identifiers with Unicode +* java-bestpractices + * [#3954](https://github.com/pmd/pmd/issues/3954): \[java] NPE in UseCollectionIsEmptyRule when .size() is called in a record +* java-design + * [#3874](https://github.com/pmd/pmd/issues/3874): \[java] ImmutableField reports fields annotated with @Autowired (Spring) and @Mock (Mockito) +* java-errorprone + * [#3096](https://github.com/pmd/pmd/issues/3096): \[java] EmptyStatementNotInLoop FP in 6.30.0 with IfStatement +* java-performance + * [#3379](https://github.com/pmd/pmd/issues/3379): \[java] UseArraysAsList must ignore primitive arrays + * [#3965](https://github.com/pmd/pmd/issues/3965): \[java] UseArraysAsList false positive with non-trivial loops +* javascript + * [#2605](https://github.com/pmd/pmd/issues/2605): \[js] Support unicode characters + * [#3948](https://github.com/pmd/pmd/issues/3948): \[js] Invalid operator error for method property in object literal +* python + * [#2604](https://github.com/pmd/pmd/issues/2604): \[python] Support unicode identifiers + +### API Changes + +#### Deprecated ruleset references + +Ruleset references with the following formats are now deprecated and will produce a warning +when used on the CLI or in a ruleset XML file: +- `-`, eg `java-basic`, which resolves to `rulesets/java/basic.xml` +- the internal release number, eg `600`, which resolves to `rulesets/releases/600.xml` + +Use the explicit forms of these references to be compatible with PMD 7. + +#### Deprecated API + +- toString is now deprecated. The format of this + method will remain the same until PMD 7. The deprecation is intended to steer users + away from relying on this format, as it may be changed in PMD 7. +- getInputPaths and +setInputPaths are now deprecated. +A new set of methods have been added, which use lists and do not rely on comma splitting. + +#### Internal API + +Those APIs are not intended to be used by clients, and will be hidden or removed with PMD 7.0.0. +You can identify them with the `@InternalApi` annotation. You'll also get a deprecation warning. + +- CPDCommandLineInterface has been internalized. In order to execute CPD either +CPD#run or CPD#main +should be used. +- Several members of BaseCPDCLITest have been deprecated with replacements. +- The methods Formatter#start, +Formatter#end, Formatter#getRenderer, +and Formatter#isNoOutputSupplied have been internalized. + +### External Contributions + +* [#3961](https://github.com/pmd/pmd/pull/3961): \[java] Fix #3954 - NPE in UseCollectionIsEmptyRule with record - [@flyhard](https://github.com/flyhard) +* [#3964](https://github.com/pmd/pmd/pull/3964): \[java] Fix #3874 - ImmutableField: fix mockito/spring false positives - [@lukelukes](https://github.com/lukelukes) +* [#3974](https://github.com/pmd/pmd/pull/3974): \[cs] Add option to ignore C# attributes (annotations) - [@maikelsteneker](https://github.com/maikelsteneker) + +### Stats +* 92 commits +* 30 closed tickets & PRs +* Days since last release: 28 + ## 30-April-2022 - 6.45.0 The PMD team is pleased to announce PMD 6.45.0. From 44e7aec80fafe9b453b10c32ae99f11b9169c6d0 Mon Sep 17 00:00:00 2001 From: Andreas Dangel Date: Sat, 28 May 2022 11:42:52 +0200 Subject: [PATCH 147/198] Bump pmd from 6.45.0 to 6.46.0 --- pom.xml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/pom.xml b/pom.xml index f354efbd91..19569b6454 100644 --- a/pom.xml +++ b/pom.xml @@ -406,22 +406,22 @@ net.sourceforge.pmd pmd-core - 6.45.0 + 6.46.0 net.sourceforge.pmd pmd-java - 6.45.0 + 6.46.0 net.sourceforge.pmd pmd-jsp - 6.45.0 + 6.46.0 net.sourceforge.pmd pmd-javascript - 6.45.0 + 6.46.0 From 459c23a8b638d9fcab9efe31a33dca229f96eab6 Mon Sep 17 00:00:00 2001 From: Andreas Dangel Date: Sat, 28 May 2022 11:56:10 +0200 Subject: [PATCH 148/198] Bump build-tools from 17-SNAPSHOT to 18 --- .github/workflows/build.yml | 2 +- .github/workflows/git-repo-sync.yml | 2 +- .github/workflows/troubleshooting.yml | 2 +- pom.xml | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 6dadb3e2d8..1f64ba25cb 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -45,7 +45,7 @@ jobs: run: | echo "LANG=en_US.UTF-8" >> $GITHUB_ENV echo "MAVEN_OPTS=-Dmaven.wagon.httpconnectionManager.ttlSeconds=180 -Dmaven.wagon.http.retryHandler.count=3 -DautoReleaseAfterClose=true -DstagingProgressTimeoutMinutes=30" >> $GITHUB_ENV - echo "PMD_CI_SCRIPTS_URL=https://raw.githubusercontent.com/pmd/build-tools/17/scripts" >> $GITHUB_ENV + echo "PMD_CI_SCRIPTS_URL=https://raw.githubusercontent.com/pmd/build-tools/18/scripts" >> $GITHUB_ENV - name: Check Environment shell: bash run: | diff --git a/.github/workflows/git-repo-sync.yml b/.github/workflows/git-repo-sync.yml index 657e82e484..3cfb2e23e9 100644 --- a/.github/workflows/git-repo-sync.yml +++ b/.github/workflows/git-repo-sync.yml @@ -21,7 +21,7 @@ jobs: shell: bash run: | echo "LANG=en_US.UTF-8" >> $GITHUB_ENV - echo "PMD_CI_SCRIPTS_URL=https://raw.githubusercontent.com/pmd/build-tools/17/scripts" >> $GITHUB_ENV + echo "PMD_CI_SCRIPTS_URL=https://raw.githubusercontent.com/pmd/build-tools/18/scripts" >> $GITHUB_ENV - name: Sync run: .ci/git-repo-sync.sh shell: bash diff --git a/.github/workflows/troubleshooting.yml b/.github/workflows/troubleshooting.yml index 04ac1cd39c..ea4bd54fd9 100644 --- a/.github/workflows/troubleshooting.yml +++ b/.github/workflows/troubleshooting.yml @@ -36,7 +36,7 @@ jobs: run: | echo "LANG=en_US.UTF-8" >> $GITHUB_ENV echo "MAVEN_OPTS=-Dmaven.wagon.httpconnectionManager.ttlSeconds=180 -Dmaven.wagon.http.retryHandler.count=3 -DstagingProgressTimeoutMinutes=30" >> $GITHUB_ENV - echo "PMD_CI_SCRIPTS_URL=https://raw.githubusercontent.com/pmd/build-tools/17/scripts" >> $GITHUB_ENV + echo "PMD_CI_SCRIPTS_URL=https://raw.githubusercontent.com/pmd/build-tools/18/scripts" >> $GITHUB_ENV - name: Check Environment shell: bash run: | diff --git a/pom.xml b/pom.xml index 19569b6454..c5119da86e 100644 --- a/pom.xml +++ b/pom.xml @@ -105,7 +105,7 @@ -Xmx512m -Dfile.encoding=${project.build.sourceEncoding} - 18-SNAPSHOT + 18 6.37.0 From 6111951e6cdfd447fb8889c4fd6534c8e31fdab4 Mon Sep 17 00:00:00 2001 From: dalizi007 <11912017@mail.sustech.edu.cn> Date: Sat, 28 May 2022 23:55:47 +0800 Subject: [PATCH 149/198] [java] Add the method "buz" definition #3937 --- .../java/rule/errorprone/xml/AvoidDuplicateLiterals.xml | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/pmd-java/src/test/resources/net/sourceforge/pmd/lang/java/rule/errorprone/xml/AvoidDuplicateLiterals.xml b/pmd-java/src/test/resources/net/sourceforge/pmd/lang/java/rule/errorprone/xml/AvoidDuplicateLiterals.xml index e86665b847..619eb56c84 100644 --- a/pmd-java/src/test/resources/net/sourceforge/pmd/lang/java/rule/errorprone/xml/AvoidDuplicateLiterals.xml +++ b/pmd-java/src/test/resources/net/sourceforge/pmd/lang/java/rule/errorprone/xml/AvoidDuplicateLiterals.xml @@ -15,6 +15,7 @@ public class Foo { buz("Howdy"); buz("Howdy"); } + private void buz(String x) {} } ]]> @@ -27,6 +28,7 @@ public class Foo { private void bar() { buz(2); } + private void buz(int x) {} } ]]> @@ -86,6 +88,7 @@ public class Foo { buz("Howdy"); buz("Howdy"); } + private void buz(String x) {} } ]]> @@ -100,6 +103,7 @@ public class Foo { buz("Howdy"); buz("Howdy"); buz("Howdy"); buz("Howdy"); buz("foo"); buz("foo"); buz("foo"); buz("foo"); } + private void buz(String x) {} } ]]> @@ -115,6 +119,7 @@ public class Foo { buz("Howdy"); buz("Howdy"); buz("Howdy"); buz("Howdy"); buz("foo"); buz("foo"); buz("foo"); buz("foo"); } + private void buz(String x) {} } ]]> @@ -128,6 +133,7 @@ public class Foo { private void bar() { buz("Howdy"); buz("Howdy"); buz("Howdy"); buz("Howdy"); } + private void buz(String x) {} } ]]> @@ -141,6 +147,7 @@ public class Foo { private void bar() { buz("foo"); buz("foo"); buz("foo"); buz("foo"); } + private void buz(String x) {} } ]]> @@ -154,6 +161,7 @@ public class Foo { buz("foo"); buz("foo"); buz("foo"); buz("foo"); buz("fo"); buz("fo"); buz("fo"); buz("fo"); } + private void buz(String x) {} } ]]> From 25e59bc2eedced36081c3beef321d308440d4396 Mon Sep 17 00:00:00 2001 From: Andreas Dangel Date: Thu, 2 Jun 2022 11:35:19 +0200 Subject: [PATCH 150/198] [doc] Update release notes (#3937, #3993) --- docs/pages/release_notes.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/docs/pages/release_notes.md b/docs/pages/release_notes.md index b8f8783555..1eb0bab3e3 100644 --- a/docs/pages/release_notes.md +++ b/docs/pages/release_notes.md @@ -15,10 +15,13 @@ This is a {{ site.pmd.release_type }} release. ### New and noteworthy ### Fixed Issues +* java-errorprone + * [#3937](https://github.com/pmd/pmd/issues/3937): \[java] AvoidDuplicateLiterals - uncompilable test cases ### API Changes ### External Contributions +* [#3993](https://github.com/pmd/pmd/pull/3993): \[java] AvoidDuplicateLiterals - Add the method "buz" definition to test cases - [@dalizi007](https://github.com/dalizi007) {% endtocmaker %} From 74c9ebb15afe015ec4d610a9dac21eab4a60b3bd Mon Sep 17 00:00:00 2001 From: Andreas Dangel Date: Thu, 2 Jun 2022 11:35:42 +0200 Subject: [PATCH 151/198] Add @dalizi007 as a contributor --- .all-contributorsrc | 9 ++++++ docs/pages/pmd/projectdocs/credits.md | 41 ++++++++++++++------------- 2 files changed, 30 insertions(+), 20 deletions(-) diff --git a/.all-contributorsrc b/.all-contributorsrc index 85095b18fe..5357d8fad6 100644 --- a/.all-contributorsrc +++ b/.all-contributorsrc @@ -6684,6 +6684,15 @@ "contributions": [ "bug" ] + }, + { + "login": "dalizi007", + "name": "dalizi007", + "avatar_url": "https://avatars.githubusercontent.com/u/90743616?v=4", + "profile": "https://github.com/dalizi007", + "contributions": [ + "code" + ] } ], "contributorsPerLine": 7, diff --git a/docs/pages/pmd/projectdocs/credits.md b/docs/pages/pmd/projectdocs/credits.md index 48913f3d00..c01402c827 100644 --- a/docs/pages/pmd/projectdocs/credits.md +++ b/docs/pages/pmd/projectdocs/credits.md @@ -770,186 +770,187 @@ Thanks goes to these wonderful people ([emoji key](https://allcontributors.org/d
d1ss0nanz

🐛 +
dalizi007

💻
danbrycefairsailcom

🐛
dariansanity

🐛
darrenmiliband

🐛
davidburstrom

🐛
dbirkman-paloalto

🐛
deepak-patra

🐛 -
dependabot[bot]

💻 🐛 +
dependabot[bot]

💻 🐛
dinesh150

🐛
diziaq

🐛
dreaminpast123

🐛
duanyanan

🐛
dutt-sanjay

🐛
dylanleung

🐛 -
dzeigler

🐛 +
dzeigler

🐛
ekkirala

🐛
emersonmoura

🐛
fairy

🐛
filiprafalowicz

💻
foxmason

🐛
frankegabor

🐛 -
frankl

🐛 +
frankl

🐛
freafrea

🐛
fsapatin

🐛
gracia19

🐛
guo fei

🐛
gurmsc5

🐛
gwilymatgearset

💻 🐛 -
haigsn

🐛 +
haigsn

🐛
hemanshu070

🐛
henrik242

🐛
hongpuwu

🐛
hvbtup

💻 🐛
igniti GmbH

🐛
ilovezfs

🐛 -
itaigilo

🐛 +
itaigilo

🐛
jakivey32

🐛
jbennett2091

🐛
jcamerin

🐛
jkeener1

🐛
jmetertea

🐛
johnra2

💻 -
josemanuelrolon

💻 🐛 +
josemanuelrolon

💻 🐛
kabroxiko

💻 🐛
karwer

🐛
kaulonline

🐛
kdaemonv

🐛
kenji21

💻 🐛
kfranic

🐛 -
khalidkh

🐛 +
khalidkh

🐛
krzyk

🐛
lasselindqvist

🐛
lihuaib

🐛
lonelyma1021

🐛
lpeddy

🐛
lujiefsi

💻 -
lukelukes

💻 +
lukelukes

💻
lyriccoder

🐛
marcelmore

🐛
matchbox

🐛
matthiaskraaz

🐛
meandonlyme

🐛
mikesive

🐛 -
milossesic

🐛 +
milossesic

🐛
mriddell95

🐛
mrlzh

🐛
msloan

🐛
mucharlaravalika

🐛
mvenneman

🐛
nareshl119

🐛 -
nicolas-harraudeau-sonarsource

🐛 +
nicolas-harraudeau-sonarsource

🐛
noerremark

🐛
novsirion

🐛
oggboy

🐛
oinume

🐛
orimarko

💻 🐛
pallavi agarwal

🐛 -
parksungrin

🐛 +
parksungrin

🐛
patpatpat123

🐛
patriksevallius

🐛
pbrajesh1

🐛
phoenix384

🐛
piotrszymanski-sc

💻
plan3d

🐛 -
poojasix

🐛 +
poojasix

🐛
prabhushrikant

🐛
pujitha8783

🐛
r-r-a-j

🐛
raghujayjunk

🐛
rajeshveera

🐛
rajeswarreddy88

🐛 -
recdevs

🐛 +
recdevs

🐛
reudismam

💻 🐛
rijkt

🐛
rillig-tk

🐛
rmohan20

💻 🐛
rxmicro

🐛
ryan-gustafson

💻 🐛 -
sabi0

🐛 +
sabi0

🐛
scais

🐛
sebbASF

🐛
sergeygorbaty

💻
shilko2013

🐛
simeonKondr

🐛
snajberk

🐛 -
sniperrifle2004

🐛 +
sniperrifle2004

🐛
snuyanzin

🐛 💻
sratz

🐛
stonio

🐛
sturton

💻 🐛
sudharmohan

🐛
suruchidawar

🐛 -
svenfinitiv

🐛 +
svenfinitiv

🐛
tashiscool

🐛
test-git-hook

🐛
testation21

💻 🐛
thanosa

🐛
tiandiyixian

🐛
tobwoerk

🐛 -
tprouvot

🐛 +
tprouvot

🐛
trentchilders

🐛
triandicAnt

🐛
trishul14

🐛
tsui

🐛
winhkey

🐛
witherspore

🐛 -
wjljack

🐛 +
wjljack

🐛
wuchiuwong

🐛
xingsong

🐛
xioayuge

🐛
xnYi9wRezm

💻 🐛
xuanuy

🐛
xyf0921

🐛 -
yalechen-cyw3

🐛 +
yalechen-cyw3

🐛
yasuharu-sato

🐛
zenglian

🐛
zgrzyt93

💻 🐛
zh3ng

🐛
zt_soft

🐛
ztt79

🐛 -
zzzzfeng

🐛 +
zzzzfeng

🐛
Árpád Magosányi

🐛
任贵杰

🐛 From 051951e852f4f7753ffc51f0f3cc005b0ba9a2da Mon Sep 17 00:00:00 2001 From: Scrsloota <1912125562@qq.com> Date: Thu, 2 Jun 2022 23:43:31 +0800 Subject: [PATCH 152/198] change to avoid instanceof checks --- .../AvoidFieldNameMatchingMethodNameRule.java | 56 ++++++++++--------- .../xml/AvoidFieldNameMatchingMethodName.xml | 6 +- 2 files changed, 32 insertions(+), 30 deletions(-) diff --git a/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/rule/errorprone/AvoidFieldNameMatchingMethodNameRule.java b/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/rule/errorprone/AvoidFieldNameMatchingMethodNameRule.java index 9fd52b984a..5e5dd5de17 100644 --- a/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/rule/errorprone/AvoidFieldNameMatchingMethodNameRule.java +++ b/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/rule/errorprone/AvoidFieldNameMatchingMethodNameRule.java @@ -14,7 +14,6 @@ import net.sourceforge.pmd.lang.ast.Node; import net.sourceforge.pmd.lang.java.ast.ASTClassOrInterfaceBody; import net.sourceforge.pmd.lang.java.ast.ASTClassOrInterfaceDeclaration; import net.sourceforge.pmd.lang.java.ast.ASTEnumBody; -import net.sourceforge.pmd.lang.java.ast.ASTEnumDeclaration; import net.sourceforge.pmd.lang.java.ast.ASTFieldDeclaration; import net.sourceforge.pmd.lang.java.ast.ASTMethodDeclaration; import net.sourceforge.pmd.lang.java.ast.JavaNode; @@ -31,36 +30,39 @@ public class AvoidFieldNameMatchingMethodNameRule extends AbstractJavaRule { } @Override - public Object visit(ASTEnumDeclaration node, Object data) { + public Object visit(ASTClassOrInterfaceBody node, Object data) { + handleClassOrEnum(node, data); return super.visit(node, data); } @Override - public Object visit(JavaNode node, Object data) { - if (node instanceof ASTClassOrInterfaceBody || node instanceof ASTEnumBody) { - int n = node.getNumChildren(); - List fields = new ArrayList<>(); - Set methodNames = new HashSet<>(); - for (int i = 0; i < n; i++) { - Node child = node.getChild(i); - if (child.getNumChildren() == 0) { - continue; - } - child = child.getChild(child.getNumChildren() - 1); - if (child instanceof ASTFieldDeclaration) { - fields.add((ASTFieldDeclaration) child); - } else if (child instanceof ASTMethodDeclaration) { - methodNames.add(((ASTMethodDeclaration) child).getName().toLowerCase(Locale.ROOT)); - } - } - for (ASTFieldDeclaration field : fields) { - String varName = field.getVariableName().toLowerCase(Locale.ROOT); - if (methodNames.contains(varName)) { - addViolation(data, field, field.getVariableName()); - } - } - return super.visit(node, data); - } + public Object visit(ASTEnumBody node, Object data) { + handleClassOrEnum(node, data); return super.visit(node, data); } + + private void handleClassOrEnum(JavaNode node, Object data) { + int n = node.getNumChildren(); + List fields = new ArrayList<>(); + Set methodNames = new HashSet<>(); + for (int i = 0; i < n; i++) { + Node child = node.getChild(i); + if (child.getNumChildren() == 0) { + continue; + } + child = child.getChild(child.getNumChildren() - 1); + if (child instanceof ASTFieldDeclaration) { + fields.add((ASTFieldDeclaration) child); + } else if (child instanceof ASTMethodDeclaration) { + methodNames.add(((ASTMethodDeclaration) child).getName().toLowerCase(Locale.ROOT)); + } + } + for (ASTFieldDeclaration field : fields) { + String varName = field.getVariableName().toLowerCase(Locale.ROOT); + if (methodNames.contains(varName)) { + addViolation(data, field, field.getVariableName()); + } + } + } + } diff --git a/pmd-java/src/test/resources/net/sourceforge/pmd/lang/java/rule/errorprone/xml/AvoidFieldNameMatchingMethodName.xml b/pmd-java/src/test/resources/net/sourceforge/pmd/lang/java/rule/errorprone/xml/AvoidFieldNameMatchingMethodName.xml index ad0170102a..4cab17b54a 100644 --- a/pmd-java/src/test/resources/net/sourceforge/pmd/lang/java/rule/errorprone/xml/AvoidFieldNameMatchingMethodName.xml +++ b/pmd-java/src/test/resources/net/sourceforge/pmd/lang/java/rule/errorprone/xml/AvoidFieldNameMatchingMethodName.xml @@ -65,7 +65,7 @@ public interface Bar { - Test1 in Enum + Test1 in Enum #3936 1 - Test2 in Enum + Test2 in Enum #3936 0 - Test3 in Enum + Test3 in Enum #3936 0 Date: Sat, 4 Jun 2022 10:27:57 +0200 Subject: [PATCH 153/198] [core] Fix cli when only --file-list is used Fixes #3999 --- docs/pages/release_notes.md | 2 ++ .../java/net/sourceforge/pmd/cli/PMDParameters.java | 2 +- .../pmd/cli/PMDCommandLineInterfaceTest.java | 13 +++++++++++++ 3 files changed, 16 insertions(+), 1 deletion(-) diff --git a/docs/pages/release_notes.md b/docs/pages/release_notes.md index 1eb0bab3e3..4ba7666866 100644 --- a/docs/pages/release_notes.md +++ b/docs/pages/release_notes.md @@ -15,6 +15,8 @@ This is a {{ site.pmd.release_type }} release. ### New and noteworthy ### Fixed Issues +* core + * [#3999](https://github.com/pmd/pmd/issues/3999): \[cli] All files are analyzed despite parameter `--file-list` * java-errorprone * [#3937](https://github.com/pmd/pmd/issues/3937): \[java] AvoidDuplicateLiterals - uncompilable test cases diff --git a/pmd-core/src/main/java/net/sourceforge/pmd/cli/PMDParameters.java b/pmd-core/src/main/java/net/sourceforge/pmd/cli/PMDParameters.java index 18c1da8a28..6b1888db54 100644 --- a/pmd-core/src/main/java/net/sourceforge/pmd/cli/PMDParameters.java +++ b/pmd-core/src/main/java/net/sourceforge/pmd/cli/PMDParameters.java @@ -224,7 +224,7 @@ public class PMDParameters { */ public PMDConfiguration toConfiguration() { PMDConfiguration configuration = new PMDConfiguration(); - configuration.setInputPaths(this.getSourceDir()); + configuration.setInputPaths(this.getInputPaths()); configuration.setInputFilePath(this.getFileListPath()); configuration.setIgnoreFilePath(this.getIgnoreListPath()); configuration.setInputUri(this.getUri()); diff --git a/pmd-core/src/test/java/net/sourceforge/pmd/cli/PMDCommandLineInterfaceTest.java b/pmd-core/src/test/java/net/sourceforge/pmd/cli/PMDCommandLineInterfaceTest.java index 5923717395..897884da7a 100644 --- a/pmd-core/src/test/java/net/sourceforge/pmd/cli/PMDCommandLineInterfaceTest.java +++ b/pmd-core/src/test/java/net/sourceforge/pmd/cli/PMDCommandLineInterfaceTest.java @@ -4,6 +4,8 @@ package net.sourceforge.pmd.cli; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNull; import static org.junit.Assert.assertTrue; import org.junit.Assert; @@ -100,4 +102,15 @@ public class PMDCommandLineInterfaceTest { Assert.assertNotNull(PMDCommandLineInterface.buildUsageText()); } + @Test + public void testOnlyFileListOption() { + PMDParameters params = new PMDParameters(); + String[] args = {"--file-list", "pmd.filelist", "-f", "text", "-R", "rulesets/java/quickstart.xml", "--no-cache", }; + PMDCommandLineInterface.extractParameters(params, args, "PMD"); + + PMDConfiguration config = params.toConfiguration(); + assertEquals("pmd.filelist", config.getInputFilePath()); + assertTrue(config.getAllInputPaths().isEmpty()); // no additional input paths + assertNull(config.getInputPaths()); + } } From 066b510eef1b5c650fdcd4b4056d11430d52daba Mon Sep 17 00:00:00 2001 From: Andreas Dangel Date: Sat, 4 Jun 2022 11:00:30 +0200 Subject: [PATCH 154/198] chore: Fix project.parent.relativePath in pom.xml It must point to a file, pointing to a directory is not valid. --- pmd-apex-jorje/pom.xml | 2 +- pmd-apex/pom.xml | 2 +- pmd-core/pom.xml | 2 +- pmd-cpp/pom.xml | 2 +- pmd-cs/pom.xml | 2 +- pmd-dart/pom.xml | 2 +- pmd-dist/pom.xml | 2 +- pmd-doc/pom.xml | 2 +- pmd-fortran/pom.xml | 2 +- pmd-go/pom.xml | 2 +- pmd-groovy/pom.xml | 2 +- pmd-html/pom.xml | 2 +- pmd-java/pom.xml | 2 +- pmd-java8/pom.xml | 2 +- pmd-javascript/pom.xml | 2 +- pmd-jsp/pom.xml | 2 +- pmd-kotlin/pom.xml | 2 +- pmd-lang-test/pom.xml | 2 +- pmd-lua/pom.xml | 2 +- pmd-matlab/pom.xml | 2 +- pmd-modelica/pom.xml | 2 +- pmd-objectivec/pom.xml | 2 +- pmd-perl/pom.xml | 2 +- pmd-php/pom.xml | 2 +- pmd-plsql/pom.xml | 2 +- pmd-python/pom.xml | 2 +- pmd-ruby/pom.xml | 2 +- pmd-scala-modules/pmd-scala-common/pom.xml | 2 +- pmd-scala-modules/pmd-scala_2.12/pom.xml | 2 +- pmd-scala-modules/pmd-scala_2.13/pom.xml | 2 +- pmd-scala/pom.xml | 2 +- pmd-swift/pom.xml | 2 +- pmd-test/pom.xml | 2 +- pmd-visualforce/pom.xml | 2 +- pmd-vm/pom.xml | 2 +- pmd-xml/pom.xml | 2 +- 36 files changed, 36 insertions(+), 36 deletions(-) diff --git a/pmd-apex-jorje/pom.xml b/pmd-apex-jorje/pom.xml index 3666d840ce..b5a177525f 100644 --- a/pmd-apex-jorje/pom.xml +++ b/pmd-apex-jorje/pom.xml @@ -9,7 +9,7 @@ net.sourceforge.pmd pmd 6.47.0-SNAPSHOT - ../ + ../pom.xml diff --git a/pmd-apex/pom.xml b/pmd-apex/pom.xml index 9eebf20f95..9cbd113a4e 100644 --- a/pmd-apex/pom.xml +++ b/pmd-apex/pom.xml @@ -8,7 +8,7 @@ net.sourceforge.pmd pmd 6.47.0-SNAPSHOT - ../ + ../pom.xml diff --git a/pmd-core/pom.xml b/pmd-core/pom.xml index 09da20cebe..f86c7c1c49 100644 --- a/pmd-core/pom.xml +++ b/pmd-core/pom.xml @@ -8,7 +8,7 @@ net.sourceforge.pmd pmd 6.47.0-SNAPSHOT - ../ + ../pom.xml diff --git a/pmd-cpp/pom.xml b/pmd-cpp/pom.xml index 4a7287fcbf..36487444eb 100644 --- a/pmd-cpp/pom.xml +++ b/pmd-cpp/pom.xml @@ -8,7 +8,7 @@ net.sourceforge.pmd pmd 6.47.0-SNAPSHOT - ../ + ../pom.xml diff --git a/pmd-cs/pom.xml b/pmd-cs/pom.xml index 2de4e3d6b7..96e8cb895a 100644 --- a/pmd-cs/pom.xml +++ b/pmd-cs/pom.xml @@ -8,7 +8,7 @@ net.sourceforge.pmd pmd 6.47.0-SNAPSHOT - ../ + ../pom.xml diff --git a/pmd-dart/pom.xml b/pmd-dart/pom.xml index 35c30a87c3..f1196e2faa 100644 --- a/pmd-dart/pom.xml +++ b/pmd-dart/pom.xml @@ -8,7 +8,7 @@ net.sourceforge.pmd pmd 6.47.0-SNAPSHOT - ../ + ../pom.xml diff --git a/pmd-dist/pom.xml b/pmd-dist/pom.xml index edaf2e9a89..1181aecfaf 100644 --- a/pmd-dist/pom.xml +++ b/pmd-dist/pom.xml @@ -9,7 +9,7 @@ net.sourceforge.pmd pmd 6.47.0-SNAPSHOT - ../ + ../pom.xml diff --git a/pmd-doc/pom.xml b/pmd-doc/pom.xml index 5721c1a635..684f809c62 100644 --- a/pmd-doc/pom.xml +++ b/pmd-doc/pom.xml @@ -9,7 +9,7 @@ net.sourceforge.pmd pmd 6.47.0-SNAPSHOT - ../ + ../pom.xml diff --git a/pmd-fortran/pom.xml b/pmd-fortran/pom.xml index 5e5c483a30..4a31b11c06 100644 --- a/pmd-fortran/pom.xml +++ b/pmd-fortran/pom.xml @@ -8,7 +8,7 @@ net.sourceforge.pmd pmd 6.47.0-SNAPSHOT - ../ + ../pom.xml diff --git a/pmd-go/pom.xml b/pmd-go/pom.xml index 9ec6b42466..9389feafff 100644 --- a/pmd-go/pom.xml +++ b/pmd-go/pom.xml @@ -8,7 +8,7 @@ net.sourceforge.pmd pmd 6.47.0-SNAPSHOT - ../ + ../pom.xml diff --git a/pmd-groovy/pom.xml b/pmd-groovy/pom.xml index 2ccd52164f..4608e3662f 100644 --- a/pmd-groovy/pom.xml +++ b/pmd-groovy/pom.xml @@ -8,7 +8,7 @@ net.sourceforge.pmd pmd 6.47.0-SNAPSHOT - ../ + ../pom.xml diff --git a/pmd-html/pom.xml b/pmd-html/pom.xml index b77f7d296d..f536a558ee 100644 --- a/pmd-html/pom.xml +++ b/pmd-html/pom.xml @@ -8,7 +8,7 @@ net.sourceforge.pmd pmd 6.47.0-SNAPSHOT - ../ + ../pom.xml diff --git a/pmd-java/pom.xml b/pmd-java/pom.xml index ecb14302c2..c94e568db0 100644 --- a/pmd-java/pom.xml +++ b/pmd-java/pom.xml @@ -8,7 +8,7 @@ net.sourceforge.pmd pmd 6.47.0-SNAPSHOT - ../ + ../pom.xml diff --git a/pmd-java8/pom.xml b/pmd-java8/pom.xml index c367c8064a..7f75518ed4 100644 --- a/pmd-java8/pom.xml +++ b/pmd-java8/pom.xml @@ -8,7 +8,7 @@ net.sourceforge.pmd pmd 6.47.0-SNAPSHOT - ../ + ../pom.xml diff --git a/pmd-javascript/pom.xml b/pmd-javascript/pom.xml index 09725d447e..0d2edc5e3a 100644 --- a/pmd-javascript/pom.xml +++ b/pmd-javascript/pom.xml @@ -8,7 +8,7 @@ net.sourceforge.pmd pmd 6.47.0-SNAPSHOT - ../ + ../pom.xml diff --git a/pmd-jsp/pom.xml b/pmd-jsp/pom.xml index 1fd17a18c2..79342c8ff1 100644 --- a/pmd-jsp/pom.xml +++ b/pmd-jsp/pom.xml @@ -8,7 +8,7 @@ net.sourceforge.pmd pmd 6.47.0-SNAPSHOT - ../ + ../pom.xml diff --git a/pmd-kotlin/pom.xml b/pmd-kotlin/pom.xml index 939c94f0e3..6234df66e7 100644 --- a/pmd-kotlin/pom.xml +++ b/pmd-kotlin/pom.xml @@ -8,7 +8,7 @@ net.sourceforge.pmd pmd 6.47.0-SNAPSHOT - ../ + ../pom.xml diff --git a/pmd-lang-test/pom.xml b/pmd-lang-test/pom.xml index ce1bc5067e..99a590c89b 100644 --- a/pmd-lang-test/pom.xml +++ b/pmd-lang-test/pom.xml @@ -13,7 +13,7 @@ net.sourceforge.pmd pmd 6.47.0-SNAPSHOT - ../ + ../pom.xml diff --git a/pmd-lua/pom.xml b/pmd-lua/pom.xml index b7f3fbe731..ef459787d3 100644 --- a/pmd-lua/pom.xml +++ b/pmd-lua/pom.xml @@ -8,7 +8,7 @@ net.sourceforge.pmd pmd 6.47.0-SNAPSHOT - ../ + ../pom.xml diff --git a/pmd-matlab/pom.xml b/pmd-matlab/pom.xml index 0de710099a..b6dffb8afa 100644 --- a/pmd-matlab/pom.xml +++ b/pmd-matlab/pom.xml @@ -8,7 +8,7 @@ net.sourceforge.pmd pmd 6.47.0-SNAPSHOT - ../ + ../pom.xml diff --git a/pmd-modelica/pom.xml b/pmd-modelica/pom.xml index 341803ec4e..bee6eb4ece 100644 --- a/pmd-modelica/pom.xml +++ b/pmd-modelica/pom.xml @@ -8,7 +8,7 @@ net.sourceforge.pmd pmd 6.47.0-SNAPSHOT - ../ + ../pom.xml diff --git a/pmd-objectivec/pom.xml b/pmd-objectivec/pom.xml index cedfce8126..2b1bede214 100644 --- a/pmd-objectivec/pom.xml +++ b/pmd-objectivec/pom.xml @@ -8,7 +8,7 @@ net.sourceforge.pmd pmd 6.47.0-SNAPSHOT - ../ + ../pom.xml diff --git a/pmd-perl/pom.xml b/pmd-perl/pom.xml index 558fa427c8..83f957ad73 100644 --- a/pmd-perl/pom.xml +++ b/pmd-perl/pom.xml @@ -8,7 +8,7 @@ net.sourceforge.pmd pmd 6.47.0-SNAPSHOT - ../ + ../pom.xml diff --git a/pmd-php/pom.xml b/pmd-php/pom.xml index 782f861703..c4a2e6e040 100644 --- a/pmd-php/pom.xml +++ b/pmd-php/pom.xml @@ -8,7 +8,7 @@ net.sourceforge.pmd pmd 6.47.0-SNAPSHOT - ../ + ../pom.xml diff --git a/pmd-plsql/pom.xml b/pmd-plsql/pom.xml index c0a1762555..2242099ad1 100644 --- a/pmd-plsql/pom.xml +++ b/pmd-plsql/pom.xml @@ -8,7 +8,7 @@ net.sourceforge.pmd pmd 6.47.0-SNAPSHOT - ../ + ../pom.xml diff --git a/pmd-python/pom.xml b/pmd-python/pom.xml index 1161024852..6406fb7bc5 100644 --- a/pmd-python/pom.xml +++ b/pmd-python/pom.xml @@ -8,7 +8,7 @@ net.sourceforge.pmd pmd 6.47.0-SNAPSHOT - ../ + ../pom.xml diff --git a/pmd-ruby/pom.xml b/pmd-ruby/pom.xml index 5bc68ba973..e0385b000c 100644 --- a/pmd-ruby/pom.xml +++ b/pmd-ruby/pom.xml @@ -8,7 +8,7 @@ net.sourceforge.pmd pmd 6.47.0-SNAPSHOT - ../ + ../pom.xml diff --git a/pmd-scala-modules/pmd-scala-common/pom.xml b/pmd-scala-modules/pmd-scala-common/pom.xml index 20ace8b9c8..c5327d8381 100644 --- a/pmd-scala-modules/pmd-scala-common/pom.xml +++ b/pmd-scala-modules/pmd-scala-common/pom.xml @@ -9,7 +9,7 @@ net.sourceforge.pmd pmd 6.47.0-SNAPSHOT - ../.. + ../../pom.xml diff --git a/pmd-scala-modules/pmd-scala_2.12/pom.xml b/pmd-scala-modules/pmd-scala_2.12/pom.xml index 4765990084..b6a62cd14c 100644 --- a/pmd-scala-modules/pmd-scala_2.12/pom.xml +++ b/pmd-scala-modules/pmd-scala_2.12/pom.xml @@ -8,7 +8,7 @@ net.sourceforge.pmd pmd-scala-common 6.47.0-SNAPSHOT - ../pmd-scala-common + ../pmd-scala-common/pom.xml diff --git a/pmd-scala-modules/pmd-scala_2.13/pom.xml b/pmd-scala-modules/pmd-scala_2.13/pom.xml index 9b5c50f976..43ed00eb17 100644 --- a/pmd-scala-modules/pmd-scala_2.13/pom.xml +++ b/pmd-scala-modules/pmd-scala_2.13/pom.xml @@ -8,7 +8,7 @@ net.sourceforge.pmd pmd-scala-common 6.47.0-SNAPSHOT - ../pmd-scala-common + ../pmd-scala-common/pom.xml diff --git a/pmd-scala/pom.xml b/pmd-scala/pom.xml index bc1c3e9ccd..9a0020aa0f 100644 --- a/pmd-scala/pom.xml +++ b/pmd-scala/pom.xml @@ -10,7 +10,7 @@ net.sourceforge.pmd pmd 6.47.0-SNAPSHOT - ../ + ../pom.xml diff --git a/pmd-swift/pom.xml b/pmd-swift/pom.xml index 10032db400..82a44caa83 100644 --- a/pmd-swift/pom.xml +++ b/pmd-swift/pom.xml @@ -8,7 +8,7 @@ net.sourceforge.pmd pmd 6.47.0-SNAPSHOT - ../ + ../pom.xml diff --git a/pmd-test/pom.xml b/pmd-test/pom.xml index b8757a44a0..c2540c1888 100644 --- a/pmd-test/pom.xml +++ b/pmd-test/pom.xml @@ -9,7 +9,7 @@ net.sourceforge.pmd pmd 6.47.0-SNAPSHOT - ../ + ../pom.xml diff --git a/pmd-visualforce/pom.xml b/pmd-visualforce/pom.xml index 4e2ef9d4ba..acdf585467 100644 --- a/pmd-visualforce/pom.xml +++ b/pmd-visualforce/pom.xml @@ -8,7 +8,7 @@ net.sourceforge.pmd pmd 6.47.0-SNAPSHOT - ../ + ../pom.xml diff --git a/pmd-vm/pom.xml b/pmd-vm/pom.xml index bfbb62269f..3c69ab2437 100644 --- a/pmd-vm/pom.xml +++ b/pmd-vm/pom.xml @@ -8,7 +8,7 @@ net.sourceforge.pmd pmd 6.47.0-SNAPSHOT - ../ + ../pom.xml diff --git a/pmd-xml/pom.xml b/pmd-xml/pom.xml index 26c8a9faf8..7fe4f69fe5 100644 --- a/pmd-xml/pom.xml +++ b/pmd-xml/pom.xml @@ -8,7 +8,7 @@ net.sourceforge.pmd pmd 6.47.0-SNAPSHOT - ../ + ../pom.xml From 62d27c07b40985ecc1ed8ab3b87647ac9d39f1a5 Mon Sep 17 00:00:00 2001 From: Andreas Dangel Date: Sat, 4 Jun 2022 15:14:35 +0200 Subject: [PATCH 155/198] [doc] Update release notes (#3936, #3985) --- docs/pages/release_notes.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/docs/pages/release_notes.md b/docs/pages/release_notes.md index 1eb0bab3e3..fe77034c8c 100644 --- a/docs/pages/release_notes.md +++ b/docs/pages/release_notes.md @@ -16,11 +16,13 @@ This is a {{ site.pmd.release_type }} release. ### Fixed Issues * java-errorprone + * [#3936](https://github.com/pmd/pmd/issues/3936): \[java] AvoidFieldNameMatchingMethodName should consider enum class * [#3937](https://github.com/pmd/pmd/issues/3937): \[java] AvoidDuplicateLiterals - uncompilable test cases ### API Changes ### External Contributions +* [#3985](https://github.com/pmd/pmd/pull/3985): \[java] Fix false negative problem about Enum in AvoidFieldNameMatchingMethodName #3936 - [@Scrsloota](https://github.com/Scrsloota) * [#3993](https://github.com/pmd/pmd/pull/3993): \[java] AvoidDuplicateLiterals - Add the method "buz" definition to test cases - [@dalizi007](https://github.com/dalizi007) {% endtocmaker %} From 021c5a25e8fda96f760f005686328f3f487e146e Mon Sep 17 00:00:00 2001 From: Andreas Dangel Date: Sat, 4 Jun 2022 15:49:01 +0200 Subject: [PATCH 156/198] chore: Check for SNAPSHOT build tools and other SNAPSHOTs --- do-release.sh | 8 ++++++++ pom.xml | 34 +++++++++++++++++++++++++++++++++- 2 files changed, 41 insertions(+), 1 deletion(-) diff --git a/do-release.sh b/do-release.sh index 5cd900bf32..3ddb331bbd 100755 --- a/do-release.sh +++ b/do-release.sh @@ -72,6 +72,14 @@ export RELEASE_VERSION export DEVELOPMENT_VERSION export CURRENT_BRANCH +# check for SNAPSHOT version of pmd.build-tools.version +BUILD_TOOLS_VERSION=$(./mvnw org.apache.maven.plugins:maven-help-plugin:3.2.0:evaluate -Dexpression=pmd.build-tools.version -q -DforceStdout) +BUILD_TOOLS_VERSION_RELEASE=${BUILD_TOOLS_VERSION%-SNAPSHOT} +if [ "${BUILD_TOOLS_VERSION}" != "${BUILD_TOOLS_VERSION_RELEASE}" ]; then + echo "Error: version pmd.build-tools.version is ${BUILD_TOOLS_VERSION} - snapshot is not allowed" + exit 1 +fi + RELEASE_RULESET="pmd-core/src/main/resources/rulesets/releases/${RELEASE_VERSION//\./}.xml" echo "* Update date info in **docs/_config.yml**." diff --git a/pom.xml b/pom.xml index c5119da86e..f9a643d105 100644 --- a/pom.xml +++ b/pom.xml @@ -364,7 +364,7 @@ org.apache.maven.plugins maven-enforcer-plugin - 3.0.0-M2 + 3.0.0 org.apache.maven.plugins @@ -431,6 +431,11 @@
+ + org.apache.maven.plugins + maven-site-plugin + 4.0.0-M1 + org.codehaus.mojo versions-maven-plugin @@ -495,6 +500,33 @@ + + enforce-no-snapshots + + enforce + + + + + No Snapshots Allowed! + true + + + + + + enforce-plugin-versions + + enforce + + + + + Best Practice is to always define plugin versions! + + + + From e29a5899703bfec2f2aebeee5f0f1c7fe9f58a96 Mon Sep 17 00:00:00 2001 From: James Harrison Date: Tue, 7 Jun 2022 09:58:45 +0100 Subject: [PATCH 157/198] [java] ImmutableField: Ignore @Value (Spring) and @Captor (Mockito) --- .all-contributorsrc | 3 ++- docs/pages/pmd/projectdocs/credits.md | 2 +- docs/pages/release_notes.md | 4 ++++ .../java/rule/design/ImmutableFieldRule.java | 4 +++- .../java/rule/design/xml/ImmutableField.xml | 18 ++++++++++++++++++ 5 files changed, 28 insertions(+), 3 deletions(-) diff --git a/.all-contributorsrc b/.all-contributorsrc index 5357d8fad6..2fc583bca3 100644 --- a/.all-contributorsrc +++ b/.all-contributorsrc @@ -3384,7 +3384,8 @@ "avatar_url": "https://avatars.githubusercontent.com/u/242337?v=4", "profile": "https://github.com/jjlharrison", "contributions": [ - "bug" + "bug", + "code" ] }, { diff --git a/docs/pages/pmd/projectdocs/credits.md b/docs/pages/pmd/projectdocs/credits.md index c01402c827..838629d195 100644 --- a/docs/pages/pmd/projectdocs/credits.md +++ b/docs/pages/pmd/projectdocs/credits.md @@ -307,7 +307,7 @@ Thanks goes to these wonderful people ([emoji key](https://allcontributors.org/d
Ivo Šmíd

🐛
JJengility

🐛
Jake Hemmerle

🐛 -
James Harrison

🐛 +
James Harrison

💻 🐛
Jan

🐛 diff --git a/docs/pages/release_notes.md b/docs/pages/release_notes.md index fe77034c8c..aab61eb788 100644 --- a/docs/pages/release_notes.md +++ b/docs/pages/release_notes.md @@ -15,6 +15,9 @@ This is a {{ site.pmd.release_type }} release. ### New and noteworthy ### Fixed Issues +* java-design + * [#3981](https://github.com/pmd/pmd/issues/3981): \[java] ImmutableField reports fields annotated with @Value (Spring) + * [#3998](https://github.com/pmd/pmd/issues/3998): \[java] ImmutableField reports fields annotated with @Captor (Mockito) * java-errorprone * [#3936](https://github.com/pmd/pmd/issues/3936): \[java] AvoidFieldNameMatchingMethodName should consider enum class * [#3937](https://github.com/pmd/pmd/issues/3937): \[java] AvoidDuplicateLiterals - uncompilable test cases @@ -24,6 +27,7 @@ This is a {{ site.pmd.release_type }} release. ### External Contributions * [#3985](https://github.com/pmd/pmd/pull/3985): \[java] Fix false negative problem about Enum in AvoidFieldNameMatchingMethodName #3936 - [@Scrsloota](https://github.com/Scrsloota) * [#3993](https://github.com/pmd/pmd/pull/3993): \[java] AvoidDuplicateLiterals - Add the method "buz" definition to test cases - [@dalizi007](https://github.com/dalizi007) +* [#4002](https://github.com/pmd/pmd/pull/4002): \[java] ImmutableField - Ignore fields annotated with @Value (Spring) or @Captor (Mockito) - [@jjlharrison](https://github.com/jjlharrison) {% endtocmaker %} diff --git a/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/rule/design/ImmutableFieldRule.java b/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/rule/design/ImmutableFieldRule.java index 69baff8219..4bbc274bdb 100644 --- a/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/rule/design/ImmutableFieldRule.java +++ b/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/rule/design/ImmutableFieldRule.java @@ -46,9 +46,11 @@ public class ImmutableFieldRule extends AbstractLombokAwareRule { @Override protected Collection defaultSuppressionAnnotations() { Collection defaultValues = new ArrayList<>(super.defaultSuppressionAnnotations()); - defaultValues.add("org.mockito.Mock"); + defaultValues.add("org.mockito.Captor"); defaultValues.add("org.mockito.InjectMocks"); + defaultValues.add("org.mockito.Mock"); defaultValues.add("org.springframework.beans.factory.annotation.Autowired"); + defaultValues.add("org.springframework.beans.factory.annotation.Value"); defaultValues.add("org.springframework.boot.test.mock.mockito.MockBean"); return defaultValues; diff --git a/pmd-java/src/test/resources/net/sourceforge/pmd/lang/java/rule/design/xml/ImmutableField.xml b/pmd-java/src/test/resources/net/sourceforge/pmd/lang/java/rule/design/xml/ImmutableField.xml index b6f6bfb687..722ffc8377 100644 --- a/pmd-java/src/test/resources/net/sourceforge/pmd/lang/java/rule/design/xml/ImmutableField.xml +++ b/pmd-java/src/test/resources/net/sourceforge/pmd/lang/java/rule/design/xml/ImmutableField.xml @@ -603,4 +603,22 @@ class Baz {} class Foo2 {} ]]>
+ + #3981 #3998 [java] ImmutableField reports fields annotated with @Value (Spring) and @Captor (Mockito) + 0 + baz2; +} + ]]> + From 6ecaa64beb794e413b94da6eec167cc0d55b0b34 Mon Sep 17 00:00:00 2001 From: Andreas Dangel Date: Tue, 7 Jun 2022 19:41:37 +0200 Subject: [PATCH 158/198] Bump maven-pmd-plugin from 3.16.0 to 3.17.0 --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index f9a643d105..22f0a9d611 100644 --- a/pom.xml +++ b/pom.xml @@ -94,7 +94,7 @@ 3.0.0-M5 9.3 3.1.2 - 3.16.0 + 3.17.0 1.10.12 3.2.0 4.7.2 From b90c5f3ae3d30ad3efdbb1be8c1a68fa8910fab8 Mon Sep 17 00:00:00 2001 From: Andreas Dangel Date: Wed, 8 Jun 2022 18:58:18 +0200 Subject: [PATCH 159/198] chore: Regenerate credits.md --- docs/pages/pmd/projectdocs/credits.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/pages/pmd/projectdocs/credits.md b/docs/pages/pmd/projectdocs/credits.md index 838629d195..54f1f79b03 100644 --- a/docs/pages/pmd/projectdocs/credits.md +++ b/docs/pages/pmd/projectdocs/credits.md @@ -307,7 +307,7 @@ Thanks goes to these wonderful people ([emoji key](https://allcontributors.org/d
Ivo Šmíd

🐛
JJengility

🐛
Jake Hemmerle

🐛 -
James Harrison

💻 🐛 +
James Harrison

🐛 💻
Jan

🐛 From b4916d6a4b931b090749e41099c3274e2c838b88 Mon Sep 17 00:00:00 2001 From: James Harrison Date: Thu, 9 Jun 2022 07:41:22 +0100 Subject: [PATCH 160/198] UnusedPrivateField: Ignore fields annotated with @Id, @EmbeddedId, @Version, @Mock, @Spy, or @MockBean --- docs/pages/release_notes.md | 3 + .../bestpractices/UnusedPrivateFieldRule.java | 9 +++ .../bestpractices/xml/UnusedPrivateField.xml | 59 +++++++++++++++++++ 3 files changed, 71 insertions(+) diff --git a/docs/pages/release_notes.md b/docs/pages/release_notes.md index aab61eb788..2fd6e0bf93 100644 --- a/docs/pages/release_notes.md +++ b/docs/pages/release_notes.md @@ -18,6 +18,8 @@ This is a {{ site.pmd.release_type }} release. * java-design * [#3981](https://github.com/pmd/pmd/issues/3981): \[java] ImmutableField reports fields annotated with @Value (Spring) * [#3998](https://github.com/pmd/pmd/issues/3998): \[java] ImmutableField reports fields annotated with @Captor (Mockito) + * [#3824](https://github.com/pmd/pmd/issues/3824): \[java] UnusedPrivateField: Do not flag fields annotated with @Version + * [#3825](https://github.com/pmd/pmd/issues/3825): \[java] UnusedPrivateField: Do not flag fields annotated with @Id or @EmbeddedId * java-errorprone * [#3936](https://github.com/pmd/pmd/issues/3936): \[java] AvoidFieldNameMatchingMethodName should consider enum class * [#3937](https://github.com/pmd/pmd/issues/3937): \[java] AvoidDuplicateLiterals - uncompilable test cases @@ -28,6 +30,7 @@ This is a {{ site.pmd.release_type }} release. * [#3985](https://github.com/pmd/pmd/pull/3985): \[java] Fix false negative problem about Enum in AvoidFieldNameMatchingMethodName #3936 - [@Scrsloota](https://github.com/Scrsloota) * [#3993](https://github.com/pmd/pmd/pull/3993): \[java] AvoidDuplicateLiterals - Add the method "buz" definition to test cases - [@dalizi007](https://github.com/dalizi007) * [#4002](https://github.com/pmd/pmd/pull/4002): \[java] ImmutableField - Ignore fields annotated with @Value (Spring) or @Captor (Mockito) - [@jjlharrison](https://github.com/jjlharrison) +* [#4003](https://github.com/pmd/pmd/pull/4003): \[java] UnusedPrivateField - Ignore fields annotated with @Id/@EmbeddedId/@Version (JPA) or @Mock/@Spy/@MockBean (Mockito/Spring) - [@jjlharrison](https://github.com/jjlharrison) {% endtocmaker %} diff --git a/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/rule/bestpractices/UnusedPrivateFieldRule.java b/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/rule/bestpractices/UnusedPrivateFieldRule.java index 6eb43383d0..06133f4bf4 100644 --- a/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/rule/bestpractices/UnusedPrivateFieldRule.java +++ b/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/rule/bestpractices/UnusedPrivateFieldRule.java @@ -49,6 +49,15 @@ public class UnusedPrivateFieldRule extends AbstractLombokAwareRule { defaultValues.add("javafx.fxml.FXML"); defaultValues.add("lombok.experimental.Delegate"); defaultValues.add("lombok.EqualsAndHashCode"); + defaultValues.add("javax.persistence.Id"); + defaultValues.add("javax.persistence.EmbeddedId"); + defaultValues.add("javax.persistence.Version"); + defaultValues.add("jakarta.persistence.Id"); + defaultValues.add("jakarta.persistence.EmbeddedId"); + defaultValues.add("jakarta.persistence.Version"); + defaultValues.add("org.mockito.Mock"); + defaultValues.add("org.mockito.Spy"); + defaultValues.add("org.springframework.boot.test.mock.mockito.MockBean"); return defaultValues; } diff --git a/pmd-java/src/test/resources/net/sourceforge/pmd/lang/java/rule/bestpractices/xml/UnusedPrivateField.xml b/pmd-java/src/test/resources/net/sourceforge/pmd/lang/java/rule/bestpractices/xml/UnusedPrivateField.xml index edccd7fd30..3574634255 100644 --- a/pmd-java/src/test/resources/net/sourceforge/pmd/lang/java/rule/bestpractices/xml/UnusedPrivateField.xml +++ b/pmd-java/src/test/resources/net/sourceforge/pmd/lang/java/rule/bestpractices/xml/UnusedPrivateField.xml @@ -683,6 +683,65 @@ public class Foo { } } } +} + ]]>
+ + + + #3824 #3825 Do not flag fields annotated with @Id, @EmbeddedId, or @Version + 0 + + + + + Do not flag Mockito fields that are injected into test target + 0 + From 872111f2a1f22f035a312e5bbe5fa01151011e90 Mon Sep 17 00:00:00 2001 From: Andreas Dangel Date: Thu, 9 Jun 2022 14:59:07 +0200 Subject: [PATCH 161/198] chore: retry git push sync During the release it can happen, that two pushes are executed fast one after another. This could lead to gh action jobs overlapping while trying to push to sourceforge leading to errors like "remote: error: cannot lock ref 'refs/heads/master': is at XXX but expected YYY". --- .ci/git-repo-sync.sh | 39 ++++++++++++++++++++++++++++++++++++++- 1 file changed, 38 insertions(+), 1 deletion(-) diff --git a/.ci/git-repo-sync.sh b/.ci/git-repo-sync.sh index a32d6c9b03..af0635d9ba 100755 --- a/.ci/git-repo-sync.sh +++ b/.ci/git-repo-sync.sh @@ -27,7 +27,7 @@ function git_repo_sync() { pmd_ci_log_group_start "Git Sync" git remote add pmd-sf "${PMD_SF_USER}@git.code.sf.net:/p/pmd/code" if [ -n "${PMD_CI_BRANCH}" ]; then - git push pmd-sf "${PMD_CI_BRANCH}:${PMD_CI_BRANCH}" + retry 5 git push pmd-sf "${PMD_CI_BRANCH}:${PMD_CI_BRANCH}" pmd_ci_log_success "Successfully pushed ${PMD_CI_BRANCH} to sourceforge" elif [ -n "${PMD_CI_TAG}" ]; then git push pmd-sf tag "${PMD_CI_TAG}" @@ -39,6 +39,43 @@ function git_repo_sync() { pmd_ci_log_group_end } + +# +# From: https://gist.github.com/sj26/88e1c6584397bb7c13bd11108a579746 +# +# Retry a command up to a specific number of times until it exits successfully, +# with exponential back off. +# +# $ retry 5 echo Hello +# Hello +# +# $ retry 5 false +# Retry 1/5 exited 1, retrying in 1 seconds... +# Retry 2/5 exited 1, retrying in 2 seconds... +# Retry 3/5 exited 1, retrying in 4 seconds... +# Retry 4/5 exited 1, retrying in 8 seconds... +# Retry 5/5 exited 1, no more retries left. +# +function retry { + local retries=$1 + shift + + local count=0 + until "$@"; do + exit=$? + wait=$((2 ** $count)) + count=$(($count + 1)) + if [ $count -lt $retries ]; then + echo "Retry $count/$retries exited $exit, retrying in $wait seconds..." + sleep $wait + else + echo "Retry $count/$retries exited $exit, no more retries left." + return $exit + fi + done + return 0 +} + git_repo_sync exit 0 From 4b2c3fa1a426890e30648c5f53193b05483ef709 Mon Sep 17 00:00:00 2001 From: Andreas Dangel Date: Thu, 9 Jun 2022 16:15:19 +0200 Subject: [PATCH 162/198] Exclude commons-io (CVE-2021-29425) Refactor last test usages to use PMD's IOUtil instead. --- .../java/net/sourceforge/pmd/cpd/ApexCpdTest.java | 4 ++-- .../sourceforge/pmd/lang/apex/ast/ApexParserTest.java | 11 +++++------ .../java/net/sourceforge/pmd/ant/PMDTaskTest.java | 6 ++++-- .../net/sourceforge/pmd/coverage/PMDCoverageTest.java | 4 ++-- pom.xml | 9 +++++++++ 5 files changed, 22 insertions(+), 12 deletions(-) diff --git a/pmd-apex/src/test/java/net/sourceforge/pmd/cpd/ApexCpdTest.java b/pmd-apex/src/test/java/net/sourceforge/pmd/cpd/ApexCpdTest.java index 51ad07f5c8..412c4ea024 100644 --- a/pmd-apex/src/test/java/net/sourceforge/pmd/cpd/ApexCpdTest.java +++ b/pmd-apex/src/test/java/net/sourceforge/pmd/cpd/ApexCpdTest.java @@ -11,18 +11,18 @@ import java.io.File; import java.io.IOException; import java.util.Iterator; -import org.apache.commons.io.FilenameUtils; import org.junit.Before; import org.junit.Test; import net.sourceforge.pmd.lang.apex.ApexLanguageModule; +import net.sourceforge.pmd.util.IOUtil; public class ApexCpdTest { private File testdir; @Before public void setUp() { - String path = FilenameUtils.normalize("src/test/resources/net/sourceforge/pmd/cpd/issue427"); + String path = IOUtil.normalizePath("src/test/resources/net/sourceforge/pmd/cpd/issue427"); testdir = new File(path); } diff --git a/pmd-apex/src/test/java/net/sourceforge/pmd/lang/apex/ast/ApexParserTest.java b/pmd-apex/src/test/java/net/sourceforge/pmd/lang/apex/ast/ApexParserTest.java index 8e8edd9926..be3f11d57e 100644 --- a/pmd-apex/src/test/java/net/sourceforge/pmd/lang/apex/ast/ApexParserTest.java +++ b/pmd-apex/src/test/java/net/sourceforge/pmd/lang/apex/ast/ApexParserTest.java @@ -14,13 +14,12 @@ import java.io.IOException; import java.nio.charset.StandardCharsets; import java.util.List; -import org.apache.commons.io.FileUtils; -import org.apache.commons.io.IOUtils; import org.junit.Assert; import org.junit.Test; import net.sourceforge.pmd.lang.ast.Node; import net.sourceforge.pmd.lang.ast.xpath.internal.FileNameXPathFunction; +import net.sourceforge.pmd.util.IOUtil; import apex.jorje.semantic.ast.compilation.Compilation; @@ -154,7 +153,7 @@ public class ApexParserTest extends ApexParserTestBase { for (File file : fList) { if (file.isFile() && file.getName().endsWith(".cls")) { - String sourceCode = FileUtils.readFileToString(file, StandardCharsets.UTF_8); + String sourceCode = IOUtil.readFileToString(file, StandardCharsets.UTF_8); ApexNode rootNode = parse(sourceCode); Assert.assertNotNull(rootNode); } @@ -167,7 +166,7 @@ public class ApexParserTest extends ApexParserTestBase { */ @Test public void parseInheritedSharingClass() throws IOException { - String source = IOUtils.toString(ApexParserTest.class.getResourceAsStream("InheritedSharing.cls"), + String source = IOUtil.readToString(ApexParserTest.class.getResourceAsStream("InheritedSharing.cls"), StandardCharsets.UTF_8); ApexNode rootNode = parse(source); Assert.assertNotNull(rootNode); @@ -180,7 +179,7 @@ public class ApexParserTest extends ApexParserTestBase { */ @Test public void stackOverflowDuringClassParsing() throws Exception { - String source = IOUtils.toString(ApexParserTest.class.getResourceAsStream("StackOverflowClass.cls"), + String source = IOUtil.readToString(ApexParserTest.class.getResourceAsStream("StackOverflowClass.cls"), StandardCharsets.UTF_8); ApexNode rootNode = parse(source); Assert.assertNotNull(rootNode); @@ -191,7 +190,7 @@ public class ApexParserTest extends ApexParserTestBase { @Test public void verifyLineColumnNumbersInnerClasses() throws Exception { - String source = IOUtils.toString(ApexParserTest.class.getResourceAsStream("InnerClassLocations.cls"), + String source = IOUtil.readToString(ApexParserTest.class.getResourceAsStream("InnerClassLocations.cls"), StandardCharsets.UTF_8); source = source.replaceAll("\r\n", "\n"); ApexNode rootNode = parse(source); diff --git a/pmd-java/src/test/java/net/sourceforge/pmd/ant/PMDTaskTest.java b/pmd-java/src/test/java/net/sourceforge/pmd/ant/PMDTaskTest.java index 2ae2b31129..dcff84e7e9 100644 --- a/pmd-java/src/test/java/net/sourceforge/pmd/ant/PMDTaskTest.java +++ b/pmd-java/src/test/java/net/sourceforge/pmd/ant/PMDTaskTest.java @@ -9,15 +9,17 @@ import static org.junit.Assert.assertTrue; import java.io.UnsupportedEncodingException; import java.nio.charset.Charset; +import java.nio.charset.StandardCharsets; import java.util.Locale; -import org.apache.commons.io.FileUtils; import org.junit.Rule; import org.junit.Test; import org.junit.contrib.java.lang.system.RestoreSystemProperties; import org.junit.rules.ExternalResource; import org.junit.rules.TestRule; +import net.sourceforge.pmd.util.IOUtil; + public class PMDTaskTest extends AbstractAntTestHelper { public PMDTaskTest() { @@ -132,7 +134,7 @@ public class PMDTaskTest extends AbstractAntTestHelper { setDefaultCharset("cp1252"); executeTarget("testFormatterEncodingWithXML"); - String report = FileUtils.readFileToString(currentTempFile(), "UTF-8"); + String report = IOUtil.readFileToString(currentTempFile(), StandardCharsets.UTF_8); assertTrue(report.contains("someVariableWithÜmlaut")); } diff --git a/pmd-java/src/test/java/net/sourceforge/pmd/coverage/PMDCoverageTest.java b/pmd-java/src/test/java/net/sourceforge/pmd/coverage/PMDCoverageTest.java index 99f534b543..c7cab54408 100644 --- a/pmd-java/src/test/java/net/sourceforge/pmd/coverage/PMDCoverageTest.java +++ b/pmd-java/src/test/java/net/sourceforge/pmd/coverage/PMDCoverageTest.java @@ -14,7 +14,6 @@ import java.nio.charset.StandardCharsets; import java.util.Arrays; import java.util.List; -import org.apache.commons.io.FileUtils; import org.apache.commons.lang3.ArrayUtils; import org.apache.commons.lang3.StringUtils; import org.junit.Rule; @@ -27,6 +26,7 @@ import net.sourceforge.pmd.PMD; import net.sourceforge.pmd.lang.LanguageRegistry; import net.sourceforge.pmd.lang.LanguageVersion; import net.sourceforge.pmd.lang.java.JavaLanguageModule; +import net.sourceforge.pmd.util.IOUtil; public class PMDCoverageTest { @@ -80,7 +80,7 @@ public class PMDCoverageTest { System.err.println("Running PMD with: " + Arrays.toString(args)); PMD.runPmd(args); - report = FileUtils.readFileToString(f, StandardCharsets.UTF_8); + report = IOUtil.readFileToString(f, StandardCharsets.UTF_8); assertEquals("Nothing should be output to stdout", 0, output.getLog().length()); diff --git a/pom.xml b/pom.xml index 22f0a9d611..5aeded6f08 100644 --- a/pom.xml +++ b/pom.xml @@ -893,6 +893,15 @@ kotest-runner-junit5-jvm ${kotest.version} test + + + + commons-io + commons-io + + io.kotest From a8a61f2c440504d266f23b4f4f11a233448e0d1d Mon Sep 17 00:00:00 2001 From: Andreas Dangel Date: Thu, 9 Jun 2022 16:19:28 +0200 Subject: [PATCH 163/198] Upgrade io.github.classgraph:classgraph from 4.8.102 to 4.8.112 Fixes [sonatype-2021-1074] CWE-611: Improper Restriction of XML External Entity Reference ('XXE') --- pom.xml | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/pom.xml b/pom.xml index 5aeded6f08..7e9aa680a8 100644 --- a/pom.xml +++ b/pom.xml @@ -922,6 +922,16 @@ 13.0 test + + + + io.github.classgraph + classgraph + 4.8.112 + From 9537629e58f5e4349c6f6d1e6714a0f45f205ea8 Mon Sep 17 00:00:00 2001 From: Andreas Dangel Date: Thu, 9 Jun 2022 16:22:29 +0200 Subject: [PATCH 164/198] Upgrade com.google.protobuf:protobuf-java from 3.7.1 to 3.16.1 Fixes CVE-2021-22569 A potential Denial of Service issue in protobuf-java https://github.com/protocolbuffers/protobuf/security/advisories/GHSA-wrvw-hg22-4m67 --- pom.xml | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/pom.xml b/pom.xml index 7e9aa680a8..0a0877f766 100644 --- a/pom.xml +++ b/pom.xml @@ -932,6 +932,16 @@ classgraph 4.8.112 + + + + com.google.protobuf + protobuf-java + 3.16.1 + From 8fbedb3a0fb2380f618895ab0c8ff7155040a429 Mon Sep 17 00:00:00 2001 From: shiomiyan <35842766+shiomiyan@users.noreply.github.com> Date: Fri, 10 Jun 2022 13:08:09 +0900 Subject: [PATCH 165/198] fix documentation link --- docs/pages/pmd/userdocs/tools/tools.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/pages/pmd/userdocs/tools/tools.md b/docs/pages/pmd/userdocs/tools/tools.md index 78d7b7d316..033cac07ad 100644 --- a/docs/pages/pmd/userdocs/tools/tools.md +++ b/docs/pages/pmd/userdocs/tools/tools.md @@ -197,7 +197,7 @@ To install the PMD plugin for Eclipse: * Start Eclipse and open a project * Select "Help"->"Software Updates"->"Find and Install" * Click "Next", then click "New remote site" -* Enter "PMD" into the Name field and into the URL field +* Enter "PMD" into the Name field and select the URL of the version you need from [here](https://pmd.github.io/pmd-eclipse-plugin-p2-site/) and into the URL field * Click through the rest of the dialog boxes to install the plugin Alternatively, you can download the latest zip file and follow the above procedures From a9b8991700b5c505e46f4e4b7f8e1422e8acae7c Mon Sep 17 00:00:00 2001 From: shiomiyan <35842766+shiomiyan@users.noreply.github.com> Date: Sat, 11 Jun 2022 01:25:02 +0900 Subject: [PATCH 166/198] Update docs/pages/pmd/userdocs/tools/tools.md Co-authored-by: Andreas Dangel --- docs/pages/pmd/userdocs/tools/tools.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/pages/pmd/userdocs/tools/tools.md b/docs/pages/pmd/userdocs/tools/tools.md index 033cac07ad..c889ef0091 100644 --- a/docs/pages/pmd/userdocs/tools/tools.md +++ b/docs/pages/pmd/userdocs/tools/tools.md @@ -197,7 +197,7 @@ To install the PMD plugin for Eclipse: * Start Eclipse and open a project * Select "Help"->"Software Updates"->"Find and Install" * Click "Next", then click "New remote site" -* Enter "PMD" into the Name field and select the URL of the version you need from [here](https://pmd.github.io/pmd-eclipse-plugin-p2-site/) and into the URL field +* Enter "PMD" into the Name field and into the URL field * Click through the rest of the dialog boxes to install the plugin Alternatively, you can download the latest zip file and follow the above procedures From 179578dffb3619f523ba19ea06787074f95f2f4e Mon Sep 17 00:00:00 2001 From: Maikel Steneker Date: Mon, 13 Jun 2022 11:43:04 +0200 Subject: [PATCH 167/198] Bump kotlin from 1.4.32 to 1.7.0 --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 22f0a9d611..1c4837281f 100644 --- a/pom.xml +++ b/pom.xml @@ -85,7 +85,7 @@ ${maven.compiler.test.target} - 1.4.32 + 1.7.0 4.4.3 1.4.32 From f2d1c95102e0935cc9d6f413e80bb16c64414501 Mon Sep 17 00:00:00 2001 From: Maikel Steneker Date: Mon, 13 Jun 2022 11:44:32 +0200 Subject: [PATCH 168/198] Bump dokka maven plugin from 1.4.32 to 1.6.21 --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 1c4837281f..582b954ff3 100644 --- a/pom.xml +++ b/pom.xml @@ -87,7 +87,7 @@ ${maven.compiler.test.target} 1.7.0 4.4.3 - 1.4.32 + 1.6.21 5.0 From 02a7d4e0dd8c05675d1cd63c0a43046942fc4c72 Mon Sep 17 00:00:00 2001 From: Andreas Dangel Date: Fri, 10 Jun 2022 12:12:41 +0200 Subject: [PATCH 169/198] Use maven-pmd-plugin 3.18.0-pmd7-SNAPSHOT for pmd7 --- .ci/build.sh | 3 +++ pom.xml | 11 +++++++++++ 2 files changed, 14 insertions(+) diff --git a/.ci/build.sh b/.ci/build.sh index b40190edda..92f7f6472a 100755 --- a/.ci/build.sh +++ b/.ci/build.sh @@ -244,12 +244,15 @@ ${rendered_release_notes}" # Runs the dogfood ruleset with the currently built pmd against itself # function pmd_ci_dogfood() { + local mpmdVersion=() ./mvnw versions:set -DnewVersion="${PMD_CI_MAVEN_PROJECT_VERSION}-dogfood" -DgenerateBackupPoms=false sed -i 's/[0-9]\{1,\}\.[0-9]\{1,\}\.[0-9]\{1,\}.*<\/version>\( *\)/'"${PMD_CI_MAVEN_PROJECT_VERSION}"'<\/version>\1/' pom.xml if [ "${PMD_CI_MAVEN_PROJECT_VERSION}" = "7.0.0-SNAPSHOT" ]; then sed -i 's/pmd-dogfood-config\.xml/pmd-dogfood-config7.xml/' pom.xml + mpmdVersion=(-Denforcer.skip=true -Dpmd.plugin.version=3.18.0-pmd7-SNAPSHOT) fi ./mvnw verify --show-version --errors --batch-mode --no-transfer-progress "${PMD_MAVEN_EXTRA_OPTS[@]}" \ + "${mpmdVersion[@]}" \ -DskipTests \ -Dmaven.javadoc.skip=true \ -Dmaven.source.skip=true \ diff --git a/pom.xml b/pom.xml index 22f0a9d611..4480c8bdb3 100644 --- a/pom.xml +++ b/pom.xml @@ -965,6 +965,17 @@ true + + apache.snapshots + Apache Snapshot Repository + https://repository.apache.org/snapshots + + false + + + true + + From 0c647f5365ce1aeb578d40b341d664b0d330e38a Mon Sep 17 00:00:00 2001 From: Andreas Dangel Date: Mon, 13 Jun 2022 18:24:35 +0200 Subject: [PATCH 170/198] [doc] Update release notes (#4006) --- docs/pages/release_notes.md | 1 + 1 file changed, 1 insertion(+) diff --git a/docs/pages/release_notes.md b/docs/pages/release_notes.md index aab61eb788..6726bc0659 100644 --- a/docs/pages/release_notes.md +++ b/docs/pages/release_notes.md @@ -28,6 +28,7 @@ This is a {{ site.pmd.release_type }} release. * [#3985](https://github.com/pmd/pmd/pull/3985): \[java] Fix false negative problem about Enum in AvoidFieldNameMatchingMethodName #3936 - [@Scrsloota](https://github.com/Scrsloota) * [#3993](https://github.com/pmd/pmd/pull/3993): \[java] AvoidDuplicateLiterals - Add the method "buz" definition to test cases - [@dalizi007](https://github.com/dalizi007) * [#4002](https://github.com/pmd/pmd/pull/4002): \[java] ImmutableField - Ignore fields annotated with @Value (Spring) or @Captor (Mockito) - [@jjlharrison](https://github.com/jjlharrison) +* [#4006](https://github.com/pmd/pmd/pull/4006): \[doc] Fix eclipse plugin update site URL - [@shiomiyan](https://github.com/shiomiyan) {% endtocmaker %} From c1d3324abe4a5130d69c9e1d5354fb210fe19319 Mon Sep 17 00:00:00 2001 From: Andreas Dangel Date: Mon, 13 Jun 2022 18:24:55 +0200 Subject: [PATCH 171/198] Add @shiomiyan as a contributor --- .all-contributorsrc | 9 +++++++++ docs/pages/pmd/projectdocs/credits.md | 13 +++++++------ 2 files changed, 16 insertions(+), 6 deletions(-) diff --git a/.all-contributorsrc b/.all-contributorsrc index 2fc583bca3..f2a96ed2dd 100644 --- a/.all-contributorsrc +++ b/.all-contributorsrc @@ -6694,6 +6694,15 @@ "contributions": [ "code" ] + }, + { + "login": "shiomiyan", + "name": "shiomiyan", + "avatar_url": "https://avatars.githubusercontent.com/u/35842766?v=4", + "profile": "https://github.com/shiomiyan", + "contributions": [ + "doc" + ] } ], "contributorsPerLine": 7, diff --git a/docs/pages/pmd/projectdocs/credits.md b/docs/pages/pmd/projectdocs/credits.md index 54f1f79b03..caa59049f9 100644 --- a/docs/pages/pmd/projectdocs/credits.md +++ b/docs/pages/pmd/projectdocs/credits.md @@ -901,55 +901,56 @@ Thanks goes to these wonderful people ([emoji key](https://allcontributors.org/d
sebbASF

🐛
sergeygorbaty

💻
shilko2013

🐛 +
shiomiyan

📖
simeonKondr

🐛 -
snajberk

🐛 +
snajberk

🐛
sniperrifle2004

🐛
snuyanzin

🐛 💻
sratz

🐛
stonio

🐛
sturton

💻 🐛
sudharmohan

🐛 -
suruchidawar

🐛 +
suruchidawar

🐛
svenfinitiv

🐛
tashiscool

🐛
test-git-hook

🐛
testation21

💻 🐛
thanosa

🐛
tiandiyixian

🐛 -
tobwoerk

🐛 +
tobwoerk

🐛
tprouvot

🐛
trentchilders

🐛
triandicAnt

🐛
trishul14

🐛
tsui

🐛
winhkey

🐛 -
witherspore

🐛 +
witherspore

🐛
wjljack

🐛
wuchiuwong

🐛
xingsong

🐛
xioayuge

🐛
xnYi9wRezm

💻 🐛
xuanuy

🐛 -
xyf0921

🐛 +
xyf0921

🐛
yalechen-cyw3

🐛
yasuharu-sato

🐛
zenglian

🐛
zgrzyt93

💻 🐛
zh3ng

🐛
zt_soft

🐛 -
ztt79

🐛 +
ztt79

🐛
zzzzfeng

🐛
Árpád Magosányi

🐛
任贵杰

🐛 From d5e9cde2d1111fb51bc4f122d0d9a447f6cc8282 Mon Sep 17 00:00:00 2001 From: Andreas Dangel Date: Mon, 13 Jun 2022 18:32:42 +0200 Subject: [PATCH 172/198] [doc] Update release notes (#4009, #4010) --- docs/pages/release_notes.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/docs/pages/release_notes.md b/docs/pages/release_notes.md index aab61eb788..6740acd9a3 100644 --- a/docs/pages/release_notes.md +++ b/docs/pages/release_notes.md @@ -15,6 +15,8 @@ This is a {{ site.pmd.release_type }} release. ### New and noteworthy ### Fixed Issues +* core + * [#4009](https://github.com/pmd/pmd/issues/4009): \[core] Cannot build PMD with Temurin 17 * java-design * [#3981](https://github.com/pmd/pmd/issues/3981): \[java] ImmutableField reports fields annotated with @Value (Spring) * [#3998](https://github.com/pmd/pmd/issues/3998): \[java] ImmutableField reports fields annotated with @Captor (Mockito) @@ -28,6 +30,7 @@ This is a {{ site.pmd.release_type }} release. * [#3985](https://github.com/pmd/pmd/pull/3985): \[java] Fix false negative problem about Enum in AvoidFieldNameMatchingMethodName #3936 - [@Scrsloota](https://github.com/Scrsloota) * [#3993](https://github.com/pmd/pmd/pull/3993): \[java] AvoidDuplicateLiterals - Add the method "buz" definition to test cases - [@dalizi007](https://github.com/dalizi007) * [#4002](https://github.com/pmd/pmd/pull/4002): \[java] ImmutableField - Ignore fields annotated with @Value (Spring) or @Captor (Mockito) - [@jjlharrison](https://github.com/jjlharrison) +* [#4010](https://github.com/pmd/pmd/pull/4010): \[core] Bump kotlin to version 1.7.0 - [@maikelsteneker](https://github.com/maikelsteneker) {% endtocmaker %} From d787604c52f3a5fc06eb75ddc1ad60e1dfd7afa3 Mon Sep 17 00:00:00 2001 From: Andreas Dangel Date: Tue, 14 Jun 2022 18:53:27 +0200 Subject: [PATCH 173/198] Bump maven from 3.8.5 to 3.8.6 --- .mvn/wrapper/maven-wrapper.properties | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.mvn/wrapper/maven-wrapper.properties b/.mvn/wrapper/maven-wrapper.properties index db95c131dd..25a1876bb8 100644 --- a/.mvn/wrapper/maven-wrapper.properties +++ b/.mvn/wrapper/maven-wrapper.properties @@ -14,5 +14,5 @@ # KIND, either express or implied. See the License for the # specific language governing permissions and limitations # under the License. -distributionUrl=https://repo.maven.apache.org/maven2/org/apache/maven/apache-maven/3.8.5/apache-maven-3.8.5-bin.zip -wrapperUrl=https://repo.maven.apache.org/maven2/org/apache/maven/wrapper/maven-wrapper/3.1.0/maven-wrapper-3.1.0.jar +distributionUrl=https://repo.maven.apache.org/maven2/org/apache/maven/apache-maven/3.8.6/apache-maven-3.8.6-bin.zip +wrapperUrl=https://repo.maven.apache.org/maven2/org/apache/maven/wrapper/maven-wrapper/3.1.1/maven-wrapper-3.1.1.jar From efd0c9ed13c5124b724a01219e8a32fb9bf8653e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9ment=20Fournier?= Date: Fri, 17 Jun 2022 06:40:17 +0200 Subject: [PATCH 174/198] Fix #4008 --- .../java/rule/design/ImmutableFieldRule.java | 50 ++++++------------- .../java/rule/design/xml/ImmutableField.xml | 28 +++++++++++ 2 files changed, 43 insertions(+), 35 deletions(-) diff --git a/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/rule/design/ImmutableFieldRule.java b/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/rule/design/ImmutableFieldRule.java index 4bbc274bdb..e06a73cc79 100644 --- a/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/rule/design/ImmutableFieldRule.java +++ b/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/rule/design/ImmutableFieldRule.java @@ -6,6 +6,7 @@ package net.sourceforge.pmd.lang.java.rule.design; import java.util.ArrayList; import java.util.Collection; +import java.util.Collections; import java.util.HashSet; import java.util.List; import java.util.Map; @@ -34,15 +35,6 @@ import net.sourceforge.pmd.lang.symboltable.NameOccurrence; */ public class ImmutableFieldRule extends AbstractLombokAwareRule { - private enum FieldImmutabilityType { - /** Variable is changed in methods and/or in lambdas */ - MUTABLE, - /** Variable is not changed outside the constructor. */ - IMMUTABLE, - /** Variable is only written during declaration, if at all. */ - CHECKDECL - } - @Override protected Collection defaultSuppressionAnnotations() { Collection defaultValues = new ArrayList<>(super.defaultSuppressionAnnotations()); @@ -62,7 +54,7 @@ public class ImmutableFieldRule extends AbstractLombokAwareRule { Map> vars = node.getScope() .getDeclarations(VariableNameDeclaration.class); - List constructors = findAllConstructors(node); + Set constructors = Collections.unmodifiableSet(new HashSet<>(findAllConstructors(node))); for (Map.Entry> entry : vars.entrySet()) { VariableNameDeclaration field = entry.getKey(); AccessNode accessNodeParent = field.getAccessNodeParent(); @@ -74,14 +66,7 @@ public class ImmutableFieldRule extends AbstractLombokAwareRule { } List usages = entry.getValue(); - FieldImmutabilityType type = initializedInConstructor(field, usages, new HashSet<>(constructors)); - if (type == FieldImmutabilityType.MUTABLE) { - continue; - } - if (initializedWhenDeclared(field) && usages.isEmpty()) { - addViolation(data, field.getNode(), field.getImage()); - } - if (type == FieldImmutabilityType.IMMUTABLE || type == FieldImmutabilityType.CHECKDECL && !initializedWhenDeclared(field)) { + if (isImmutableField(field, usages, constructors)) { addViolation(data, field.getNode(), field.getImage()); } } @@ -92,10 +77,9 @@ public class ImmutableFieldRule extends AbstractLombokAwareRule { return field.getAccessNodeParent().hasDescendantOfType(ASTVariableInitializer.class); } - private FieldImmutabilityType initializedInConstructor(VariableNameDeclaration field, List usages, Set allConstructors) { - FieldImmutabilityType result = FieldImmutabilityType.MUTABLE; - int methodInitCount = 0; - int lambdaUsage = 0; + private boolean isImmutableField(VariableNameDeclaration field, List usages, Set allConstructors) { + boolean assignedInMethod = false; + boolean assignedInLambda = false; Set consSet = new HashSet<>(); // set of constructors accessing the field for (NameOccurrence occ : usages) { JavaNameOccurrence jocc = (JavaNameOccurrence) occ; @@ -104,35 +88,31 @@ public class ImmutableFieldRule extends AbstractLombokAwareRule { ASTConstructorDeclaration constructor = node.getFirstParentOfType(ASTConstructorDeclaration.class); if (constructor != null && isSameClass(field, constructor)) { if (inLoopOrTry(node)) { - methodInitCount++; + assignedInMethod = true; continue; } if (inAnonymousInnerClass(node)) { - methodInitCount++; + assignedInMethod = true; } else if (node.getFirstParentOfType(ASTLambdaExpression.class) != null) { - lambdaUsage++; + assignedInLambda = true; } else { consSet.add(constructor); } } else { if (node.getFirstParentOfType(ASTLambdaExpression.class) != null) { - lambdaUsage++; + assignedInLambda = true; } else { - methodInitCount++; + assignedInMethod = true; } } } } - if (usages.isEmpty() || methodInitCount == 0 && lambdaUsage == 0 && allConstructors.equals(consSet)) { - result = FieldImmutabilityType.CHECKDECL; - } else { - allConstructors.removeAll(consSet); - if (allConstructors.isEmpty() && methodInitCount == 0 && lambdaUsage == 0) { - result = FieldImmutabilityType.IMMUTABLE; - } + if (assignedInLambda || assignedInMethod) { + return false; } - return result; + return (allConstructors.equals(consSet) && !allConstructors.isEmpty()) + ^ initializedWhenDeclared(field); } /** diff --git a/pmd-java/src/test/resources/net/sourceforge/pmd/lang/java/rule/design/xml/ImmutableField.xml b/pmd-java/src/test/resources/net/sourceforge/pmd/lang/java/rule/design/xml/ImmutableField.xml index 722ffc8377..725ac4515c 100644 --- a/pmd-java/src/test/resources/net/sourceforge/pmd/lang/java/rule/design/xml/ImmutableField.xml +++ b/pmd-java/src/test/resources/net/sourceforge/pmd/lang/java/rule/design/xml/ImmutableField.xml @@ -621,4 +621,32 @@ public class ExampleImmutableField { } ]]>
+ + #4008 FN with field assigned only in initializer + 1 + + + #4008 FN with field assigned only in initializer (no ctor) + 1 + + From 5d8b210e6ddd8d7653d359fc78cc4602aa3f6904 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9ment=20Fournier?= Date: Fri, 17 Jun 2022 06:51:17 +0200 Subject: [PATCH 175/198] Simplify --- .../java/rule/design/ImmutableFieldRule.java | 26 +++++++------------ 1 file changed, 9 insertions(+), 17 deletions(-) diff --git a/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/rule/design/ImmutableFieldRule.java b/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/rule/design/ImmutableFieldRule.java index e06a73cc79..c375259d0f 100644 --- a/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/rule/design/ImmutableFieldRule.java +++ b/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/rule/design/ImmutableFieldRule.java @@ -78,8 +78,6 @@ public class ImmutableFieldRule extends AbstractLombokAwareRule { } private boolean isImmutableField(VariableNameDeclaration field, List usages, Set allConstructors) { - boolean assignedInMethod = false; - boolean assignedInLambda = false; Set consSet = new HashSet<>(); // set of constructors accessing the field for (NameOccurrence occ : usages) { JavaNameOccurrence jocc = (JavaNameOccurrence) occ; @@ -88,33 +86,27 @@ public class ImmutableFieldRule extends AbstractLombokAwareRule { ASTConstructorDeclaration constructor = node.getFirstParentOfType(ASTConstructorDeclaration.class); if (constructor != null && isSameClass(field, constructor)) { if (inLoopOrTry(node)) { - assignedInMethod = true; - continue; + return false; } - if (inAnonymousInnerClass(node)) { - assignedInMethod = true; - } else if (node.getFirstParentOfType(ASTLambdaExpression.class) != null) { - assignedInLambda = true; + if (inAnonymousInnerClass(node) || isInLambda(node)) { + return false; // leaks } else { consSet.add(constructor); } - } else { - if (node.getFirstParentOfType(ASTLambdaExpression.class) != null) { - assignedInLambda = true; - } else { - assignedInMethod = true; - } + } else if (inAnonymousInnerClass(node) || isInLambda(node)) { + return false; // leaks } } } - if (assignedInLambda || assignedInMethod) { - return false; - } return (allConstructors.equals(consSet) && !allConstructors.isEmpty()) ^ initializedWhenDeclared(field); } + private boolean isInLambda(Node node) { + return node.getFirstParentOfType(ASTLambdaExpression.class) != null; + } + /** * Checks whether the given constructor belongs to the class, in which the field is declared. * This might not be the case for inner classes, which accesses the fields of the outer class. From 5c05c105b78a351234d86970695ca6c3185becf7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9ment=20Fournier?= Date: Sat, 18 Jun 2022 19:16:16 +0200 Subject: [PATCH 176/198] Fix tests --- .../pmd/lang/java/rule/design/ImmutableFieldRule.java | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/rule/design/ImmutableFieldRule.java b/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/rule/design/ImmutableFieldRule.java index c375259d0f..a59d4868f0 100644 --- a/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/rule/design/ImmutableFieldRule.java +++ b/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/rule/design/ImmutableFieldRule.java @@ -94,11 +94,13 @@ public class ImmutableFieldRule extends AbstractLombokAwareRule { } else { consSet.add(constructor); } - } else if (inAnonymousInnerClass(node) || isInLambda(node)) { - return false; // leaks + } else { + // assigned outside of ctors. + return false; } } } + return (allConstructors.equals(consSet) && !allConstructors.isEmpty()) ^ initializedWhenDeclared(field); } From f16532f0e0ea4b05c2b1693b0e4a1fa090128981 Mon Sep 17 00:00:00 2001 From: Andreas Dangel Date: Thu, 23 Jun 2022 15:47:23 +0200 Subject: [PATCH 177/198] [java] ImmutableField - add test case for @Inject (#4011) --- .../lang/java/rule/design/xml/ImmutableField.xml | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/pmd-java/src/test/resources/net/sourceforge/pmd/lang/java/rule/design/xml/ImmutableField.xml b/pmd-java/src/test/resources/net/sourceforge/pmd/lang/java/rule/design/xml/ImmutableField.xml index 725ac4515c..86fe5e4243 100644 --- a/pmd-java/src/test/resources/net/sourceforge/pmd/lang/java/rule/design/xml/ImmutableField.xml +++ b/pmd-java/src/test/resources/net/sourceforge/pmd/lang/java/rule/design/xml/ImmutableField.xml @@ -636,7 +636,8 @@ public class ExampleImmutableField { } } ]]> - + + #4008 FN with field assigned only in initializer (no ctor) 1 + + [java] ImmutableField: Do not flag fields annotated with @Inject #4011 + 0 + + From b68b7b6a876bd7a463a6762cd54655eac8f13bde Mon Sep 17 00:00:00 2001 From: Andreas Dangel Date: Thu, 23 Jun 2022 15:49:03 +0200 Subject: [PATCH 178/198] [java] ImmutableField - add test case for Selenium (#4020) --- .../lang/java/rule/design/xml/ImmutableField.xml | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/pmd-java/src/test/resources/net/sourceforge/pmd/lang/java/rule/design/xml/ImmutableField.xml b/pmd-java/src/test/resources/net/sourceforge/pmd/lang/java/rule/design/xml/ImmutableField.xml index 86fe5e4243..a8f5e2d826 100644 --- a/pmd-java/src/test/resources/net/sourceforge/pmd/lang/java/rule/design/xml/ImmutableField.xml +++ b/pmd-java/src/test/resources/net/sourceforge/pmd/lang/java/rule/design/xml/ImmutableField.xml @@ -661,6 +661,20 @@ public class Foo { } interface MyService {} +]]> + + + [java] ImmutableField reports fields annotated with @FindBy and @FindBys (Selenium) #4020 + 0 + From 770e416de18411fe453fe6bb9a454fc6da376a8f Mon Sep 17 00:00:00 2001 From: Andreas Dangel Date: Thu, 23 Jun 2022 15:51:11 +0200 Subject: [PATCH 179/198] [java] ImmutableField - add test case for GwtMockito and Spy (Mockito) (#4004) --- .../lang/java/rule/design/xml/ImmutableField.xml | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/pmd-java/src/test/resources/net/sourceforge/pmd/lang/java/rule/design/xml/ImmutableField.xml b/pmd-java/src/test/resources/net/sourceforge/pmd/lang/java/rule/design/xml/ImmutableField.xml index a8f5e2d826..a79e65de43 100644 --- a/pmd-java/src/test/resources/net/sourceforge/pmd/lang/java/rule/design/xml/ImmutableField.xml +++ b/pmd-java/src/test/resources/net/sourceforge/pmd/lang/java/rule/design/xml/ImmutableField.xml @@ -675,6 +675,19 @@ public class SomePage { @org.openqa.selenium.support.FindBy(xpath = "//div/table")}) private WebElement table; } +]]> + + + [java] ImmutableField reports fields annotated with @GwtMock (GwtMockito) and @Spy (Mockito) #4004 + 0 + From 7f4ed46a6ab5a901fa98388fa2b889e54652395d Mon Sep 17 00:00:00 2001 From: Andreas Dangel Date: Thu, 23 Jun 2022 15:55:25 +0200 Subject: [PATCH 180/198] [java] ImmutableField - add test case for JPA Entity (#3823) --- .../java/rule/design/xml/ImmutableField.xml | 35 +++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/pmd-java/src/test/resources/net/sourceforge/pmd/lang/java/rule/design/xml/ImmutableField.xml b/pmd-java/src/test/resources/net/sourceforge/pmd/lang/java/rule/design/xml/ImmutableField.xml index a79e65de43..65d8bf8097 100644 --- a/pmd-java/src/test/resources/net/sourceforge/pmd/lang/java/rule/design/xml/ImmutableField.xml +++ b/pmd-java/src/test/resources/net/sourceforge/pmd/lang/java/rule/design/xml/ImmutableField.xml @@ -688,6 +688,41 @@ public class SomeTest { @org.mockito.Spy private String someSpy; } +]]> + + + [java] ImmutableField: Do not flag fields in @Entity #3823 + 0 + From c1b6f7cc274c00db4c9f4102d0a982e23969bc10 Mon Sep 17 00:00:00 2001 From: Andreas Dangel Date: Thu, 23 Jun 2022 16:01:12 +0200 Subject: [PATCH 181/198] [java] ImmutableField - remove now unneeded default suppression annotations --- .../pmd/lang/java/rule/design/ImmutableFieldRule.java | 7 ------- 1 file changed, 7 deletions(-) diff --git a/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/rule/design/ImmutableFieldRule.java b/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/rule/design/ImmutableFieldRule.java index a59d4868f0..516ae15cb9 100644 --- a/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/rule/design/ImmutableFieldRule.java +++ b/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/rule/design/ImmutableFieldRule.java @@ -38,13 +38,6 @@ public class ImmutableFieldRule extends AbstractLombokAwareRule { @Override protected Collection defaultSuppressionAnnotations() { Collection defaultValues = new ArrayList<>(super.defaultSuppressionAnnotations()); - defaultValues.add("org.mockito.Captor"); - defaultValues.add("org.mockito.InjectMocks"); - defaultValues.add("org.mockito.Mock"); - defaultValues.add("org.springframework.beans.factory.annotation.Autowired"); - defaultValues.add("org.springframework.beans.factory.annotation.Value"); - defaultValues.add("org.springframework.boot.test.mock.mockito.MockBean"); - return defaultValues; } From 520ca80cc5da169c16dfab84230945a5cc9c7e3c Mon Sep 17 00:00:00 2001 From: Andreas Dangel Date: Thu, 23 Jun 2022 16:13:11 +0200 Subject: [PATCH 182/198] [doc] Update release notes for PR #4018 Fixes #3823 Fixes #4004 Fixes #4008 Fixes #4011 Fixes #4020 --- docs/pages/release_notes.md | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/docs/pages/release_notes.md b/docs/pages/release_notes.md index 300f41e5bf..417aaec88c 100644 --- a/docs/pages/release_notes.md +++ b/docs/pages/release_notes.md @@ -19,8 +19,13 @@ This is a {{ site.pmd.release_type }} release. * [#3999](https://github.com/pmd/pmd/issues/3999): \[cli] All files are analyzed despite parameter `--file-list` * [#4009](https://github.com/pmd/pmd/issues/4009): \[core] Cannot build PMD with Temurin 17 * java-design + * [#3823](https://github.com/pmd/pmd/issues/3823): \[java] ImmutableField: Do not flag fields in @Entity * [#3981](https://github.com/pmd/pmd/issues/3981): \[java] ImmutableField reports fields annotated with @Value (Spring) * [#3998](https://github.com/pmd/pmd/issues/3998): \[java] ImmutableField reports fields annotated with @Captor (Mockito) + * [#4004](https://github.com/pmd/pmd/issues/4004): \[java] ImmutableField reports fields annotated with @GwtMock (GwtMockito) and @Spy (Mockito) + * [#4008](https://github.com/pmd/pmd/issues/4008): \[java] ImmutableField not reporting fields that are only initialized in the declaration + * [#4011](https://github.com/pmd/pmd/issues/4011): \[java] ImmutableField: Do not flag fields annotated with @Inject + * [#4020](https://github.com/pmd/pmd/issues/4020): \[java] ImmutableField reports fields annotated with @FindBy and @FindBys (Selenium) * java-errorprone * [#3936](https://github.com/pmd/pmd/issues/3936): \[java] AvoidFieldNameMatchingMethodName should consider enum class * [#3937](https://github.com/pmd/pmd/issues/3937): \[java] AvoidDuplicateLiterals - uncompilable test cases From 1694fb714fb8682fed23fa4d292536f0a1607d88 Mon Sep 17 00:00:00 2001 From: Andreas Dangel Date: Thu, 23 Jun 2022 16:14:02 +0200 Subject: [PATCH 183/198] Add @lgemeinhardt as a contributor --- .all-contributorsrc | 9 +++++++++ docs/pages/pmd/projectdocs/credits.md | 27 ++++++++++++++------------- 2 files changed, 23 insertions(+), 13 deletions(-) diff --git a/.all-contributorsrc b/.all-contributorsrc index f2a96ed2dd..ad7c585dca 100644 --- a/.all-contributorsrc +++ b/.all-contributorsrc @@ -6703,6 +6703,15 @@ "contributions": [ "doc" ] + }, + { + "login": "lgemeinhardt", + "name": "lgemeinhardt", + "avatar_url": "https://avatars.githubusercontent.com/u/1395165?v=4", + "profile": "https://github.com/lgemeinhardt", + "contributions": [ + "bug" + ] } ], "contributorsPerLine": 7, diff --git a/docs/pages/pmd/projectdocs/credits.md b/docs/pages/pmd/projectdocs/credits.md index caa59049f9..faedc0bbd2 100644 --- a/docs/pages/pmd/projectdocs/credits.md +++ b/docs/pages/pmd/projectdocs/credits.md @@ -836,120 +836,121 @@ Thanks goes to these wonderful people ([emoji key](https://allcontributors.org/d
khalidkh

🐛
krzyk

🐛
lasselindqvist

🐛 +
lgemeinhardt

🐛
lihuaib

🐛
lonelyma1021

🐛
lpeddy

🐛 -
lujiefsi

💻 +
lujiefsi

💻
lukelukes

💻
lyriccoder

🐛
marcelmore

🐛
matchbox

🐛
matthiaskraaz

🐛
meandonlyme

🐛 -
mikesive

🐛 +
mikesive

🐛
milossesic

🐛
mriddell95

🐛
mrlzh

🐛
msloan

🐛
mucharlaravalika

🐛
mvenneman

🐛 -
nareshl119

🐛 +
nareshl119

🐛
nicolas-harraudeau-sonarsource

🐛
noerremark

🐛
novsirion

🐛
oggboy

🐛
oinume

🐛
orimarko

💻 🐛 -
pallavi agarwal

🐛 +
pallavi agarwal

🐛
parksungrin

🐛
patpatpat123

🐛
patriksevallius

🐛
pbrajesh1

🐛
phoenix384

🐛
piotrszymanski-sc

💻 -
plan3d

🐛 +
plan3d

🐛
poojasix

🐛
prabhushrikant

🐛
pujitha8783

🐛
r-r-a-j

🐛
raghujayjunk

🐛
rajeshveera

🐛 -
rajeswarreddy88

🐛 +
rajeswarreddy88

🐛
recdevs

🐛
reudismam

💻 🐛
rijkt

🐛
rillig-tk

🐛
rmohan20

💻 🐛
rxmicro

🐛 -
ryan-gustafson

💻 🐛 +
ryan-gustafson

💻 🐛
sabi0

🐛
scais

🐛
sebbASF

🐛
sergeygorbaty

💻
shilko2013

🐛
shiomiyan

📖 -
simeonKondr

🐛 +
simeonKondr

🐛
snajberk

🐛
sniperrifle2004

🐛
snuyanzin

🐛 💻
sratz

🐛
stonio

🐛
sturton

💻 🐛 -
sudharmohan

🐛 +
sudharmohan

🐛
suruchidawar

🐛
svenfinitiv

🐛
tashiscool

🐛
test-git-hook

🐛
testation21

💻 🐛
thanosa

🐛 -
tiandiyixian

🐛 +
tiandiyixian

🐛
tobwoerk

🐛
tprouvot

🐛
trentchilders

🐛
triandicAnt

🐛
trishul14

🐛
tsui

🐛 -
winhkey

🐛 +
winhkey

🐛
witherspore

🐛
wjljack

🐛
wuchiuwong

🐛
xingsong

🐛
xioayuge

🐛
xnYi9wRezm

💻 🐛 -
xuanuy

🐛 +
xuanuy

🐛
xyf0921

🐛
yalechen-cyw3

🐛
yasuharu-sato

🐛
zenglian

🐛
zgrzyt93

💻 🐛
zh3ng

🐛 -
zt_soft

🐛 +
zt_soft

🐛
ztt79

🐛
zzzzfeng

🐛
Árpád Magosányi

🐛 From de3f377c62779e61766e1873684c6e2226ed6fc7 Mon Sep 17 00:00:00 2001 From: Andreas Dangel Date: Thu, 23 Jun 2022 16:14:23 +0200 Subject: [PATCH 184/198] Add @HaelC as a contributor --- .all-contributorsrc | 9 ++ docs/pages/pmd/projectdocs/credits.md | 151 +++++++++++++------------- 2 files changed, 85 insertions(+), 75 deletions(-) diff --git a/.all-contributorsrc b/.all-contributorsrc index ad7c585dca..f9f0563c44 100644 --- a/.all-contributorsrc +++ b/.all-contributorsrc @@ -6712,6 +6712,15 @@ "contributions": [ "bug" ] + }, + { + "login": "HaelC", + "name": "Haoliang Chen", + "avatar_url": "https://avatars.githubusercontent.com/u/16898273?v=4", + "profile": "https://haelchan.me/", + "contributions": [ + "bug" + ] } ], "contributorsPerLine": 7, diff --git a/docs/pages/pmd/projectdocs/credits.md b/docs/pages/pmd/projectdocs/credits.md index faedc0bbd2..abf76da116 100644 --- a/docs/pages/pmd/projectdocs/credits.md +++ b/docs/pages/pmd/projectdocs/credits.md @@ -279,677 +279,678 @@ Thanks goes to these wonderful people ([emoji key](https://allcontributors.org/d
Guy Elsmore-Paddock

🐛
Görkem Mülayim

🐛
Hanzel Godinez

🐛 +
Haoliang Chen

🐛
Harsh Kukreja

🐛
Heber

🐛 -
Henning Schmiedehausen

💻 🐛 +
Henning Schmiedehausen

💻 🐛
Henning von Bargen

💻
Hervé Boutemy

🐛
Himanshu Pandey

🐛
Hokwang Lee

🐛
Hooperbloob

💻
Hung PHAN

🐛 -
IDoCodingStuffs

💻 🐛 +
IDoCodingStuffs

💻 🐛
Iccen Gan

🐛
Ignacio Mariano Tirabasso

🐛
Igor Melnichenko

🐛
Igor Moreno

🐛
Intelesis-MS

🐛
Iroha_

🐛 -
Ishan Srivastava

🐛 +
Ishan Srivastava

🐛
Ivano Guerini

🐛
Ivar Andreas Bonsaksen

🐛
Ivo Šmíd

🐛
JJengility

🐛
Jake Hemmerle

🐛
James Harrison

🐛 💻 -
Jan

🐛 +
Jan

🐛
Jan Aertgeerts

💻 🐛
Jan Brümmer

🐛
Jan Tříska

🐛
Jan-Lukas Else

🐛
Jason Qiu

💻 📖
Jason Williams

🐛 -
Jean-Paul Mayer

🐛 +
Jean-Paul Mayer

🐛
Jean-Simon Larochelle

🐛
Jeff Bartolotta

💻 🐛
Jeff Hube

💻 🐛
Jeff Jensen

🐛
Jeff May

🐛
Jens Gerdes

🐛 -
Jeroen Borgers

🐛 +
Jeroen Borgers

🐛
Jerome Russ

🐛
JerritEic

💻 📖
Jiri Pejchal

🐛
Jithin Sunny

🐛
Jiří Škorpil

🐛
Joao Machado

🐛 -
Jochen Krauss

🐛 +
Jochen Krauss

🐛
Johan Hammar

🐛
John Karp

🐛
John Zhang

🐛
John-Teng

💻 🐛
Jon Moroney

💻 🐛
Jonas Geiregat

🐛 -
Jonathan Wiesel

💻 🐛 +
Jonathan Wiesel

💻 🐛
Jordan

🐛
Jordi Llach

🐛
Jorge Solórzano

🐛
JorneVL

🐛
Jose Palafox

🐛
Jose Stovall

🐛 -
Joseph

💻 +
Joseph

💻
Joseph Heenan

🐛
Josh Feingold

💻 🐛
Josh Holthaus

🐛
Joshua S Arquilevich

🐛
João Ferreira

💻 🐛
João Pedro Schmitt

🐛 -
Juan Martín Sotuyo Dodero

💻 📖 🐛 🚧 +
Juan Martín Sotuyo Dodero

💻 📖 🐛 🚧
Juan Pablo Civile

🐛
Julian Voronetsky

🐛
Julien

🐛
Julius

🐛
JustPRV

🐛
Jörn Huxhorn

🐛 -
KThompso

🐛 +
KThompso

🐛
Kai Amundsen

🐛
Karel Vervaeke

🐛
Karl-Andero Mere

🐛
Karl-Philipp Richter

🐛
Karsten Silz

🐛
Kazuma Watanabe

🐛 -
Kev

🐛 +
Kev

🐛
Keve Müller

🐛
Kevin Guerra

💻
Kevin Jones

🐛
Kevin Wayne

🐛
Kieran Black

🐛
Kirill Zubov

🐛 -
Kirk Clemens

💻 🐛 +
Kirk Clemens

💻 🐛
Klaus Hartl

🐛
Koen Van Looveren

🐛
Kris Scheibe

💻 🐛
Kunal Thanki

🐛
LaLucid

💻
Larry Diamond

💻 🐛 -
Lars Knickrehm

🐛 +
Lars Knickrehm

🐛
Leo Gutierrez

🐛
LiGaOg

💻
Lintsi

🐛
Linus Fernandes

🐛
Lixon Lookose

🐛
Logesh

🐛 -
Lorenzo Gabriele

🐛 +
Lorenzo Gabriele

🐛
Loïc Ledoyen

🐛
Lucas Silva

🐛
Lucas Soncini

💻 🐛
Lukasz Slonina

🐛
Lukebray

🐛
Lyor Goldstein

🐛 -
MCMicS

🐛 +
MCMicS

🐛
Macarse

🐛
Machine account for PMD

💻
Maciek Siemczyk

🐛
Maikel Steneker

💻 🐛
Maksim Moiseikin

🐛
Manfred Koch

🐛 -
Manuel Moya Ferrer

💻 🐛 +
Manuel Moya Ferrer

💻 🐛
Manuel Ryan

🐛
Marat Vyshegorodtsev

🐛
Marcel Härle

🐛
Marcello Fialho

🐛
Marcin Rataj

🐛
Mark Adamcin

🐛 -
Mark Hall

💻 🐛 +
Mark Hall

💻 🐛
Mark Kolich

🐛
Mark Pritchard

🐛
Markus Rathgeb

🐛
Marquis Wang

🐛
Martin Feldsztejn

🐛
Martin Lehmann

🐛 -
Martin Spamer

🐛 +
Martin Spamer

🐛
Martin Tarjányi

🐛
MatFl

🐛
Mateusz Stefanski

🐛
Mathieu Gouin

🐛
MatiasComercio

💻 🐛
Matt Benson

🐛 -
Matt De Poorter

🐛 +
Matt De Poorter

🐛
Matt Harrah

🐛
Matt Nelson

🐛
Matthew Amos

🐛
Matthew Duggan

🐛
Matthew Hall

🐛
Matías Fraga

💻 🐛 -
Maxime Robert

💻 🐛 +
Maxime Robert

💻 🐛
MetaBF

🐛
Michael

🐛
Michael Bell

🐛
Michael Bernstein

🐛
Michael Clay

🐛
Michael Dombrowski

🐛 -
Michael Hausegger

🐛 +
Michael Hausegger

🐛
Michael Hoefer

🐛
Michael Möbius

🐛
Michael N. Lipp

🐛
Michael Pellegrini

🐛
Michal Kordas

🐛
Michał Borek

🐛 -
Michał Kuliński

🐛 +
Michał Kuliński

🐛
Miguel Núñez Díaz-Montes

🐛
Mihai Ionut

🐛
Mirek Hankus

🐛
Mladjan Gadzic

🐛
MrAngry52

🐛
Muminur Choudhury

🐛 -
Mykhailo Palahuta

💻 🐛 +
Mykhailo Palahuta

💻 🐛
Nagendra Kumar Singh

🐛
Nahuel Barrios

🐛
Nathan Braun

🐛
Nathan Reynolds

🐛
Nathan Reynolds

🐛
Nathanaël

🐛 -
Naveen

💻 +
Naveen

💻
Nazdravi

🐛
Neha-Dhonde

🐛
Nicholas Doyle

🐛
Nick Butcher

🐛
Nico Gallinal

🐛
Nicola Dal Maso

🐛 -
Nicolas Filotto

💻 +
Nicolas Filotto

💻
Nikita Chursin

🐛
Niklas Baudy

🐛
Nikolas Havrikov

🐛
Nilesh Virkar

🐛
Nimit Patel

🐛
Niranjan Harpale

🐛 -
Noah Sussman

🐛 +
Noah Sussman

🐛
Noah0120

🐛
Noam Tamim

🐛
Noel Grandin

🐛
Olaf Haalstra

🐛
Oleg Pavlenko

🐛
Oleksii Dykov

💻 -
Oliver Eikemeier

🐛 +
Oliver Eikemeier

🐛
Olivier Parent

💻 🐛
Ollie Abbey

💻 🐛
OverDrone

🐛
Ozan Gulle

💻 🐛
PUNEET JAIN

🐛
Parbati Bose

🐛 -
Paul Berg

🐛 +
Paul Berg

🐛
Pavel Bludov

🐛
Pavel Mička

🐛
Pedro Nuno Santos

🐛
Pedro Rijo

🐛
Pelisse Romain

💻 📖 🐛
Per Abich

💻 -
Pete Davids

🐛 +
Pete Davids

🐛
Peter Bruin

🐛
Peter Chittum

💻 🐛
Peter Cudmore

🐛
Peter Kasson

🐛
Peter Kofler

🐛
Pham Hai Trung

🐛 -
Philip Graf

💻 🐛 +
Philip Graf

💻 🐛
Philip Hachey

🐛
Philippe Ozil

🐛
Phinehas Artemix

🐛
Phokham Nonava

🐛
Piotr Szymański

🐛
Piotrek Żygieło

💻 🐛 -
Pranay Jaiswal

🐛 +
Pranay Jaiswal

🐛
Prasad Kamath

🐛
Prasanna

🐛
Presh-AR

🐛
Puneet1726

🐛
Rafael Cortês

🐛
RaheemShaik999

🐛 -
RajeshR

💻 🐛 +
RajeshR

💻 🐛
Ramachandra Mohan

🐛
Ramel0921

🐛
Raquel Pau

🐛
Ravikiran Janardhana

🐛
Reda Benhemmouche

🐛
Renato Oliveira

💻 🐛 -
Rich DiCroce

🐛 +
Rich DiCroce

🐛
Riot R1cket

🐛
Rishabh Jain

🐛
RishabhDeep Singh

🐛
Robbie Martinus

💻 🐛
Robert Henry

🐛
Robert Painsi

🐛 -
Robert Russell

🐛 +
Robert Russell

🐛
Robert Sösemann

💻 📖 📢 🐛
Robert Whitebit

🐛
Robin Richtsfeld

🐛
Robin Stocker

💻 🐛
Robin Wils

🐛
RochusOest

🐛 -
Rodolfo Noviski

🐛 +
Rodolfo Noviski

🐛
Rodrigo Casara

🐛
Rodrigo Fernandes

🐛
Roman Salvador

💻 🐛
Ronald Blaschke

🐛
Róbert Papp

🐛
Saikat Sengupta

🐛 -
Saksham Handu

🐛 +
Saksham Handu

🐛
Saladoc

🐛
Salesforce Bob Lightning

🐛
Sam Carlberg

🐛
Satoshi Kubo

🐛
Scott Kennedy

🐛
Scott Wells

🐛 💻 -
Scrsloota

💻 +
Scrsloota

💻
Sebastian Bögl

🐛
Sebastian Schuberth

🐛
Sebastian Schwarz

🐛
Sergey Gorbaty

🐛
Sergey Kozlov

🐛
Sergey Yanzin

💻 🐛 -
Seth Wilcox

💻 +
Seth Wilcox

💻
Shubham

💻 🐛
Simon Xiao

🐛
Srinivasan Venkatachalam

🐛
Stanislav Gromov

🐛
Stanislav Myachenkov

💻
Stefan Birkner

🐛 -
Stefan Bohn

🐛 +
Stefan Bohn

🐛
Stefan Endrullis

🐛
Stefan Klöss-Schuster

🐛
Stefan Wolf

🐛
Stephan H. Wissel

🐛
Stephen

🐛
Stephen Friedrich

🐛 -
Steve Babula

💻 +
Steve Babula

💻
Stexxe

🐛
Stian Lågstad

🐛
StuartClayton5

🐛
Supun Arunoda

🐛
Suren Abrahamyan

🐛
SwatiBGupta1110

🐛 -
SyedThoufich

🐛 +
SyedThoufich

🐛
Szymon Sasin

🐛
T-chuangxin

🐛
TERAI Atsuhiro

🐛
TIOBE Software

💻 🐛
Taylor Smock

🐛
Techeira Damián

💻 🐛 -
Ted Husted

🐛 +
Ted Husted

🐛
TehBakker

🐛
The Gitter Badger

🐛
Theodoor

🐛
Thiago Henrique Hüpner

🐛
Thibault Meyer

🐛
Thomas Güttler

🐛 -
Thomas Jones-Low

🐛 +
Thomas Jones-Low

🐛
Thomas Smith

💻 🐛
ThrawnCA

🐛
Thunderforge

💻 🐛
Tim van der Lippe

🐛
Tobias Weimer

💻 🐛
Tom Daly

🐛 -
Tomer Figenblat

🐛 +
Tomer Figenblat

🐛
Tomi De Lucca

💻 🐛
Torsten Kleiber

🐛
TrackerSB

🐛
Ullrich Hafner

🐛
Utku Cuhadaroglu

💻 🐛
Valentin Brandl

🐛 -
Valeria

🐛 +
Valeria

🐛
Vasily Anisimov

🐛
Vibhor Goyal

🐛
Vickenty Fesunov

🐛
Victor Noël

🐛
Vincent Galloy

💻
Vincent HUYNH

🐛 -
Vincent Maurin

🐛 +
Vincent Maurin

🐛
Vincent Privat

🐛
Vishhwas

🐛
Vitaly

🐛
Vitaly Polonetsky

🐛
Vojtech Polivka

🐛
Vsevolod Zholobov

🐛 -
Vyom Yadav

💻 +
Vyom Yadav

💻
Wang Shidong

🐛
Waqas Ahmed

🐛
Wayne J. Earl

🐛
Wchenghui

🐛
Will Winder

🐛
William Brockhus

💻 🐛 -
Wilson Kurniawan

🐛 +
Wilson Kurniawan

🐛
Wim Deblauwe

🐛
Woongsik Choi

🐛
XenoAmess

💻 🐛
Yang

💻
YaroslavTER

🐛
Young Chan

💻 🐛 -
YuJin Kim

🐛 +
YuJin Kim

🐛
Yuri Dolzhenko

🐛
Yurii Dubinka

🐛
Zoltan Farkas

🐛
Zustin

🐛
aaronhurst-google

🐛
alexmodis

🐛 -
andreoss

🐛 +
andreoss

🐛
andrey81inmd

💻 🐛
anicoara

🐛
arunprasathav

🐛
asiercamara

🐛
astillich-igniti

💻
avesolovksyy

🐛 -
avishvat

🐛 +
avishvat

🐛
avivmu

🐛
axelbarfod1

🐛
b-3-n

🐛
balbhadra9

🐛
base23de

🐛
bergander

🐛 -
berkam

💻 🐛 +
berkam

💻 🐛
breizh31

🐛
caesarkim

🐛
carolyujing

🐛
cesares-basilico

🐛
chrite

🐛
cobratbq

🐛 -
coladict

🐛 +
coladict

🐛
cosmoJFH

🐛
cristalp

🐛
crunsk

🐛
cwholmes

🐛
cyberjj999

🐛
cyw3

🐛 -
d1ss0nanz

🐛 +
d1ss0nanz

🐛
dalizi007

💻
danbrycefairsailcom

🐛
dariansanity

🐛
darrenmiliband

🐛
davidburstrom

🐛
dbirkman-paloalto

🐛 -
deepak-patra

🐛 +
deepak-patra

🐛
dependabot[bot]

💻 🐛
dinesh150

🐛
diziaq

🐛
dreaminpast123

🐛
duanyanan

🐛
dutt-sanjay

🐛 -
dylanleung

🐛 +
dylanleung

🐛
dzeigler

🐛
ekkirala

🐛
emersonmoura

🐛
fairy

🐛
filiprafalowicz

💻
foxmason

🐛 -
frankegabor

🐛 +
frankegabor

🐛
frankl

🐛
freafrea

🐛
fsapatin

🐛
gracia19

🐛
guo fei

🐛
gurmsc5

🐛 -
gwilymatgearset

💻 🐛 +
gwilymatgearset

💻 🐛
haigsn

🐛
hemanshu070

🐛
henrik242

🐛
hongpuwu

🐛
hvbtup

💻 🐛
igniti GmbH

🐛 -
ilovezfs

🐛 +
ilovezfs

🐛
itaigilo

🐛
jakivey32

🐛
jbennett2091

🐛
jcamerin

🐛
jkeener1

🐛
jmetertea

🐛 -
johnra2

💻 +
johnra2

💻
josemanuelrolon

💻 🐛
kabroxiko

💻 🐛
karwer

🐛
kaulonline

🐛
kdaemonv

🐛
kenji21

💻 🐛 -
kfranic

🐛 +
kfranic

🐛
khalidkh

🐛
krzyk

🐛
lasselindqvist

🐛
lgemeinhardt

🐛
lihuaib

🐛
lonelyma1021

🐛 -
lpeddy

🐛 +
lpeddy

🐛
lujiefsi

💻
lukelukes

💻
lyriccoder

🐛
marcelmore

🐛
matchbox

🐛
matthiaskraaz

🐛 -
meandonlyme

🐛 +
meandonlyme

🐛
mikesive

🐛
milossesic

🐛
mriddell95

🐛
mrlzh

🐛
msloan

🐛
mucharlaravalika

🐛 -
mvenneman

🐛 +
mvenneman

🐛
nareshl119

🐛
nicolas-harraudeau-sonarsource

🐛
noerremark

🐛
novsirion

🐛
oggboy

🐛
oinume

🐛 -
orimarko

💻 🐛 +
orimarko

💻 🐛
pallavi agarwal

🐛
parksungrin

🐛
patpatpat123

🐛
patriksevallius

🐛
pbrajesh1

🐛
phoenix384

🐛 -
piotrszymanski-sc

💻 +
piotrszymanski-sc

💻
plan3d

🐛
poojasix

🐛
prabhushrikant

🐛
pujitha8783

🐛
r-r-a-j

🐛
raghujayjunk

🐛 -
rajeshveera

🐛 +
rajeshveera

🐛
rajeswarreddy88

🐛
recdevs

🐛
reudismam

💻 🐛
rijkt

🐛
rillig-tk

🐛
rmohan20

💻 🐛 -
rxmicro

🐛 +
rxmicro

🐛
ryan-gustafson

💻 🐛
sabi0

🐛
scais

🐛
sebbASF

🐛
sergeygorbaty

💻
shilko2013

🐛 -
shiomiyan

📖 +
shiomiyan

📖
simeonKondr

🐛
snajberk

🐛
sniperrifle2004

🐛
snuyanzin

🐛 💻
sratz

🐛
stonio

🐛 -
sturton

💻 🐛 +
sturton

💻 🐛
sudharmohan

🐛
suruchidawar

🐛
svenfinitiv

🐛
tashiscool

🐛
test-git-hook

🐛
testation21

💻 🐛 -
thanosa

🐛 +
thanosa

🐛
tiandiyixian

🐛
tobwoerk

🐛
tprouvot

🐛
trentchilders

🐛
triandicAnt

🐛
trishul14

🐛 -
tsui

🐛 +
tsui

🐛
winhkey

🐛
witherspore

🐛
wjljack

🐛
wuchiuwong

🐛
xingsong

🐛
xioayuge

🐛 -
xnYi9wRezm

💻 🐛 +
xnYi9wRezm

💻 🐛
xuanuy

🐛
xyf0921

🐛
yalechen-cyw3

🐛
yasuharu-sato

🐛
zenglian

🐛
zgrzyt93

💻 🐛 -
zh3ng

🐛 +
zh3ng

🐛
zt_soft

🐛
ztt79

🐛
zzzzfeng

🐛 From 5b210a7239e47f2abbd6a2c7ec7fe056f821ba94 Mon Sep 17 00:00:00 2001 From: Andreas Dangel Date: Thu, 23 Jun 2022 16:15:14 +0200 Subject: [PATCH 185/198] Add @FSchliephacke as a contributor --- .all-contributorsrc | 9 ++ docs/pages/pmd/projectdocs/credits.md | 159 +++++++++++++------------- 2 files changed, 89 insertions(+), 79 deletions(-) diff --git a/.all-contributorsrc b/.all-contributorsrc index f9f0563c44..77965bd302 100644 --- a/.all-contributorsrc +++ b/.all-contributorsrc @@ -6721,6 +6721,15 @@ "contributions": [ "bug" ] + }, + { + "login": "FSchliephacke", + "name": "FSchliephacke", + "avatar_url": "https://avatars.githubusercontent.com/u/10260493?v=4", + "profile": "https://github.com/FSchliephacke", + "contributions": [ + "bug" + ] } ], "contributorsPerLine": 7, diff --git a/docs/pages/pmd/projectdocs/credits.md b/docs/pages/pmd/projectdocs/credits.md index abf76da116..af2199ce28 100644 --- a/docs/pages/pmd/projectdocs/credits.md +++ b/docs/pages/pmd/projectdocs/credits.md @@ -244,712 +244,713 @@ Thanks goes to these wonderful people ([emoji key](https://allcontributors.org/d
Erik Bleske

🐛
Ernst Reissner

🐛
F.W. Dekker

🐛 +
FSchliephacke

🐛
Facundo

🐛 -
Federico Giust

🐛 +
Federico Giust

🐛
Fedor Sherstobitov

🐛
Felix Lampe

🐛
Filip Golonka

🐛
Filipe Esperandio

💻 🐛
Filippo Nova

🐛
Francesco la Torre

🐛 -
Francisco Duarte

🐛 +
Francisco Duarte

🐛
Frieder Bluemle

🐛
Frits Jalvingh

💻 🐛
G. Bazior

🐛
Gabe Henkes

🐛
Genoud Magloire

🐛
Geoffrey555

🐛 -
Georg Romstorfer

🐛 +
Georg Romstorfer

🐛
Gio

🐛
Gol

🐛
Gonzalo Exequiel Ibars Ingman

💻 🐛
GooDer

🐛
Gregor Riegler

🐛
Grzegorz Olszewski

🐛 -
Gunther Schrijvers

💻 🐛 +
Gunther Schrijvers

💻 🐛
Gustavo Krieger

🐛
Guy Elsmore-Paddock

🐛
Görkem Mülayim

🐛
Hanzel Godinez

🐛
Haoliang Chen

🐛
Harsh Kukreja

🐛 -
Heber

🐛 +
Heber

🐛
Henning Schmiedehausen

💻 🐛
Henning von Bargen

💻
Hervé Boutemy

🐛
Himanshu Pandey

🐛
Hokwang Lee

🐛
Hooperbloob

💻 -
Hung PHAN

🐛 +
Hung PHAN

🐛
IDoCodingStuffs

💻 🐛
Iccen Gan

🐛
Ignacio Mariano Tirabasso

🐛
Igor Melnichenko

🐛
Igor Moreno

🐛
Intelesis-MS

🐛 -
Iroha_

🐛 +
Iroha_

🐛
Ishan Srivastava

🐛
Ivano Guerini

🐛
Ivar Andreas Bonsaksen

🐛
Ivo Šmíd

🐛
JJengility

🐛
Jake Hemmerle

🐛 -
James Harrison

🐛 💻 +
James Harrison

🐛 💻
Jan

🐛
Jan Aertgeerts

💻 🐛
Jan Brümmer

🐛
Jan Tříska

🐛
Jan-Lukas Else

🐛
Jason Qiu

💻 📖 -
Jason Williams

🐛 +
Jason Williams

🐛
Jean-Paul Mayer

🐛
Jean-Simon Larochelle

🐛
Jeff Bartolotta

💻 🐛
Jeff Hube

💻 🐛
Jeff Jensen

🐛
Jeff May

🐛 -
Jens Gerdes

🐛 +
Jens Gerdes

🐛
Jeroen Borgers

🐛
Jerome Russ

🐛
JerritEic

💻 📖
Jiri Pejchal

🐛
Jithin Sunny

🐛
Jiří Škorpil

🐛 -
Joao Machado

🐛 +
Joao Machado

🐛
Jochen Krauss

🐛
Johan Hammar

🐛
John Karp

🐛
John Zhang

🐛
John-Teng

💻 🐛
Jon Moroney

💻 🐛 -
Jonas Geiregat

🐛 +
Jonas Geiregat

🐛
Jonathan Wiesel

💻 🐛
Jordan

🐛
Jordi Llach

🐛
Jorge Solórzano

🐛
JorneVL

🐛
Jose Palafox

🐛 -
Jose Stovall

🐛 +
Jose Stovall

🐛
Joseph

💻
Joseph Heenan

🐛
Josh Feingold

💻 🐛
Josh Holthaus

🐛
Joshua S Arquilevich

🐛
João Ferreira

💻 🐛 -
João Pedro Schmitt

🐛 +
João Pedro Schmitt

🐛
Juan Martín Sotuyo Dodero

💻 📖 🐛 🚧
Juan Pablo Civile

🐛
Julian Voronetsky

🐛
Julien

🐛
Julius

🐛
JustPRV

🐛 -
Jörn Huxhorn

🐛 +
Jörn Huxhorn

🐛
KThompso

🐛
Kai Amundsen

🐛
Karel Vervaeke

🐛
Karl-Andero Mere

🐛
Karl-Philipp Richter

🐛
Karsten Silz

🐛 -
Kazuma Watanabe

🐛 +
Kazuma Watanabe

🐛
Kev

🐛
Keve Müller

🐛
Kevin Guerra

💻
Kevin Jones

🐛
Kevin Wayne

🐛
Kieran Black

🐛 -
Kirill Zubov

🐛 +
Kirill Zubov

🐛
Kirk Clemens

💻 🐛
Klaus Hartl

🐛
Koen Van Looveren

🐛
Kris Scheibe

💻 🐛
Kunal Thanki

🐛
LaLucid

💻 -
Larry Diamond

💻 🐛 +
Larry Diamond

💻 🐛
Lars Knickrehm

🐛
Leo Gutierrez

🐛
LiGaOg

💻
Lintsi

🐛
Linus Fernandes

🐛
Lixon Lookose

🐛 -
Logesh

🐛 +
Logesh

🐛
Lorenzo Gabriele

🐛
Loïc Ledoyen

🐛
Lucas Silva

🐛
Lucas Soncini

💻 🐛
Lukasz Slonina

🐛
Lukebray

🐛 -
Lyor Goldstein

🐛 +
Lyor Goldstein

🐛
MCMicS

🐛
Macarse

🐛
Machine account for PMD

💻
Maciek Siemczyk

🐛
Maikel Steneker

💻 🐛
Maksim Moiseikin

🐛 -
Manfred Koch

🐛 +
Manfred Koch

🐛
Manuel Moya Ferrer

💻 🐛
Manuel Ryan

🐛
Marat Vyshegorodtsev

🐛
Marcel Härle

🐛
Marcello Fialho

🐛
Marcin Rataj

🐛 -
Mark Adamcin

🐛 +
Mark Adamcin

🐛
Mark Hall

💻 🐛
Mark Kolich

🐛
Mark Pritchard

🐛
Markus Rathgeb

🐛
Marquis Wang

🐛
Martin Feldsztejn

🐛 -
Martin Lehmann

🐛 +
Martin Lehmann

🐛
Martin Spamer

🐛
Martin Tarjányi

🐛
MatFl

🐛
Mateusz Stefanski

🐛
Mathieu Gouin

🐛
MatiasComercio

💻 🐛 -
Matt Benson

🐛 +
Matt Benson

🐛
Matt De Poorter

🐛
Matt Harrah

🐛
Matt Nelson

🐛
Matthew Amos

🐛
Matthew Duggan

🐛
Matthew Hall

🐛 -
Matías Fraga

💻 🐛 +
Matías Fraga

💻 🐛
Maxime Robert

💻 🐛
MetaBF

🐛
Michael

🐛
Michael Bell

🐛
Michael Bernstein

🐛
Michael Clay

🐛 -
Michael Dombrowski

🐛 +
Michael Dombrowski

🐛
Michael Hausegger

🐛
Michael Hoefer

🐛
Michael Möbius

🐛
Michael N. Lipp

🐛
Michael Pellegrini

🐛
Michal Kordas

🐛 -
Michał Borek

🐛 +
Michał Borek

🐛
Michał Kuliński

🐛
Miguel Núñez Díaz-Montes

🐛
Mihai Ionut

🐛
Mirek Hankus

🐛
Mladjan Gadzic

🐛
MrAngry52

🐛 -
Muminur Choudhury

🐛 +
Muminur Choudhury

🐛
Mykhailo Palahuta

💻 🐛
Nagendra Kumar Singh

🐛
Nahuel Barrios

🐛
Nathan Braun

🐛
Nathan Reynolds

🐛
Nathan Reynolds

🐛 -
Nathanaël

🐛 +
Nathanaël

🐛
Naveen

💻
Nazdravi

🐛
Neha-Dhonde

🐛
Nicholas Doyle

🐛
Nick Butcher

🐛
Nico Gallinal

🐛 -
Nicola Dal Maso

🐛 +
Nicola Dal Maso

🐛
Nicolas Filotto

💻
Nikita Chursin

🐛
Niklas Baudy

🐛
Nikolas Havrikov

🐛
Nilesh Virkar

🐛
Nimit Patel

🐛 -
Niranjan Harpale

🐛 +
Niranjan Harpale

🐛
Noah Sussman

🐛
Noah0120

🐛
Noam Tamim

🐛
Noel Grandin

🐛
Olaf Haalstra

🐛
Oleg Pavlenko

🐛 -
Oleksii Dykov

💻 +
Oleksii Dykov

💻
Oliver Eikemeier

🐛
Olivier Parent

💻 🐛
Ollie Abbey

💻 🐛
OverDrone

🐛
Ozan Gulle

💻 🐛
PUNEET JAIN

🐛 -
Parbati Bose

🐛 +
Parbati Bose

🐛
Paul Berg

🐛
Pavel Bludov

🐛
Pavel Mička

🐛
Pedro Nuno Santos

🐛
Pedro Rijo

🐛
Pelisse Romain

💻 📖 🐛 -
Per Abich

💻 +
Per Abich

💻
Pete Davids

🐛
Peter Bruin

🐛
Peter Chittum

💻 🐛
Peter Cudmore

🐛
Peter Kasson

🐛
Peter Kofler

🐛 -
Pham Hai Trung

🐛 +
Pham Hai Trung

🐛
Philip Graf

💻 🐛
Philip Hachey

🐛
Philippe Ozil

🐛
Phinehas Artemix

🐛
Phokham Nonava

🐛
Piotr Szymański

🐛 -
Piotrek Żygieło

💻 🐛 +
Piotrek Żygieło

💻 🐛
Pranay Jaiswal

🐛
Prasad Kamath

🐛
Prasanna

🐛
Presh-AR

🐛
Puneet1726

🐛
Rafael Cortês

🐛 -
RaheemShaik999

🐛 +
RaheemShaik999

🐛
RajeshR

💻 🐛
Ramachandra Mohan

🐛
Ramel0921

🐛
Raquel Pau

🐛
Ravikiran Janardhana

🐛
Reda Benhemmouche

🐛 -
Renato Oliveira

💻 🐛 +
Renato Oliveira

💻 🐛
Rich DiCroce

🐛
Riot R1cket

🐛
Rishabh Jain

🐛
RishabhDeep Singh

🐛
Robbie Martinus

💻 🐛
Robert Henry

🐛 -
Robert Painsi

🐛 +
Robert Painsi

🐛
Robert Russell

🐛
Robert Sösemann

💻 📖 📢 🐛
Robert Whitebit

🐛
Robin Richtsfeld

🐛
Robin Stocker

💻 🐛
Robin Wils

🐛 -
RochusOest

🐛 +
RochusOest

🐛
Rodolfo Noviski

🐛
Rodrigo Casara

🐛
Rodrigo Fernandes

🐛
Roman Salvador

💻 🐛
Ronald Blaschke

🐛
Róbert Papp

🐛 -
Saikat Sengupta

🐛 +
Saikat Sengupta

🐛
Saksham Handu

🐛
Saladoc

🐛
Salesforce Bob Lightning

🐛
Sam Carlberg

🐛
Satoshi Kubo

🐛
Scott Kennedy

🐛 -
Scott Wells

🐛 💻 +
Scott Wells

🐛 💻
Scrsloota

💻
Sebastian Bögl

🐛
Sebastian Schuberth

🐛
Sebastian Schwarz

🐛
Sergey Gorbaty

🐛
Sergey Kozlov

🐛 -
Sergey Yanzin

💻 🐛 +
Sergey Yanzin

💻 🐛
Seth Wilcox

💻
Shubham

💻 🐛
Simon Xiao

🐛
Srinivasan Venkatachalam

🐛
Stanislav Gromov

🐛
Stanislav Myachenkov

💻 -
Stefan Birkner

🐛 +
Stefan Birkner

🐛
Stefan Bohn

🐛
Stefan Endrullis

🐛
Stefan Klöss-Schuster

🐛
Stefan Wolf

🐛
Stephan H. Wissel

🐛
Stephen

🐛 -
Stephen Friedrich

🐛 +
Stephen Friedrich

🐛
Steve Babula

💻
Stexxe

🐛
Stian Lågstad

🐛
StuartClayton5

🐛
Supun Arunoda

🐛
Suren Abrahamyan

🐛 -
SwatiBGupta1110

🐛 +
SwatiBGupta1110

🐛
SyedThoufich

🐛
Szymon Sasin

🐛
T-chuangxin

🐛
TERAI Atsuhiro

🐛
TIOBE Software

💻 🐛
Taylor Smock

🐛 -
Techeira Damián

💻 🐛 +
Techeira Damián

💻 🐛
Ted Husted

🐛
TehBakker

🐛
The Gitter Badger

🐛
Theodoor

🐛
Thiago Henrique Hüpner

🐛
Thibault Meyer

🐛 -
Thomas Güttler

🐛 +
Thomas Güttler

🐛
Thomas Jones-Low

🐛
Thomas Smith

💻 🐛
ThrawnCA

🐛
Thunderforge

💻 🐛
Tim van der Lippe

🐛
Tobias Weimer

💻 🐛 -
Tom Daly

🐛 +
Tom Daly

🐛
Tomer Figenblat

🐛
Tomi De Lucca

💻 🐛
Torsten Kleiber

🐛
TrackerSB

🐛
Ullrich Hafner

🐛
Utku Cuhadaroglu

💻 🐛 -
Valentin Brandl

🐛 +
Valentin Brandl

🐛
Valeria

🐛
Vasily Anisimov

🐛
Vibhor Goyal

🐛
Vickenty Fesunov

🐛
Victor Noël

🐛
Vincent Galloy

💻 -
Vincent HUYNH

🐛 +
Vincent HUYNH

🐛
Vincent Maurin

🐛
Vincent Privat

🐛
Vishhwas

🐛
Vitaly

🐛
Vitaly Polonetsky

🐛
Vojtech Polivka

🐛 -
Vsevolod Zholobov

🐛 +
Vsevolod Zholobov

🐛
Vyom Yadav

💻
Wang Shidong

🐛
Waqas Ahmed

🐛
Wayne J. Earl

🐛
Wchenghui

🐛
Will Winder

🐛 -
William Brockhus

💻 🐛 +
William Brockhus

💻 🐛
Wilson Kurniawan

🐛
Wim Deblauwe

🐛
Woongsik Choi

🐛
XenoAmess

💻 🐛
Yang

💻
YaroslavTER

🐛 -
Young Chan

💻 🐛 +
Young Chan

💻 🐛
YuJin Kim

🐛
Yuri Dolzhenko

🐛
Yurii Dubinka

🐛
Zoltan Farkas

🐛
Zustin

🐛
aaronhurst-google

🐛 -
alexmodis

🐛 +
alexmodis

🐛
andreoss

🐛
andrey81inmd

💻 🐛
anicoara

🐛
arunprasathav

🐛
asiercamara

🐛
astillich-igniti

💻 -
avesolovksyy

🐛 +
avesolovksyy

🐛
avishvat

🐛
avivmu

🐛
axelbarfod1

🐛
b-3-n

🐛
balbhadra9

🐛
base23de

🐛 -
bergander

🐛 +
bergander

🐛
berkam

💻 🐛
breizh31

🐛
caesarkim

🐛
carolyujing

🐛
cesares-basilico

🐛
chrite

🐛 -
cobratbq

🐛 +
cobratbq

🐛
coladict

🐛
cosmoJFH

🐛
cristalp

🐛
crunsk

🐛
cwholmes

🐛
cyberjj999

🐛 -
cyw3

🐛 +
cyw3

🐛
d1ss0nanz

🐛
dalizi007

💻
danbrycefairsailcom

🐛
dariansanity

🐛
darrenmiliband

🐛
davidburstrom

🐛 -
dbirkman-paloalto

🐛 +
dbirkman-paloalto

🐛
deepak-patra

🐛
dependabot[bot]

💻 🐛
dinesh150

🐛
diziaq

🐛
dreaminpast123

🐛
duanyanan

🐛 -
dutt-sanjay

🐛 +
dutt-sanjay

🐛
dylanleung

🐛
dzeigler

🐛
ekkirala

🐛
emersonmoura

🐛
fairy

🐛
filiprafalowicz

💻 -
foxmason

🐛 +
foxmason

🐛
frankegabor

🐛
frankl

🐛
freafrea

🐛
fsapatin

🐛
gracia19

🐛
guo fei

🐛 -
gurmsc5

🐛 +
gurmsc5

🐛
gwilymatgearset

💻 🐛
haigsn

🐛
hemanshu070

🐛
henrik242

🐛
hongpuwu

🐛
hvbtup

💻 🐛 -
igniti GmbH

🐛 +
igniti GmbH

🐛
ilovezfs

🐛
itaigilo

🐛
jakivey32

🐛
jbennett2091

🐛
jcamerin

🐛
jkeener1

🐛 -
jmetertea

🐛 +
jmetertea

🐛
johnra2

💻
josemanuelrolon

💻 🐛
kabroxiko

💻 🐛
karwer

🐛
kaulonline

🐛
kdaemonv

🐛 -
kenji21

💻 🐛 +
kenji21

💻 🐛
kfranic

🐛
khalidkh

🐛
krzyk

🐛
lasselindqvist

🐛
lgemeinhardt

🐛
lihuaib

🐛 -
lonelyma1021

🐛 +
lonelyma1021

🐛
lpeddy

🐛
lujiefsi

💻
lukelukes

💻
lyriccoder

🐛
marcelmore

🐛
matchbox

🐛 -
matthiaskraaz

🐛 +
matthiaskraaz

🐛
meandonlyme

🐛
mikesive

🐛
milossesic

🐛
mriddell95

🐛
mrlzh

🐛
msloan

🐛 -
mucharlaravalika

🐛 +
mucharlaravalika

🐛
mvenneman

🐛
nareshl119

🐛
nicolas-harraudeau-sonarsource

🐛
noerremark

🐛
novsirion

🐛
oggboy

🐛 -
oinume

🐛 +
oinume

🐛
orimarko

💻 🐛
pallavi agarwal

🐛
parksungrin

🐛
patpatpat123

🐛
patriksevallius

🐛
pbrajesh1

🐛 -
phoenix384

🐛 +
phoenix384

🐛
piotrszymanski-sc

💻
plan3d

🐛
poojasix

🐛
prabhushrikant

🐛
pujitha8783

🐛
r-r-a-j

🐛 -
raghujayjunk

🐛 +
raghujayjunk

🐛
rajeshveera

🐛
rajeswarreddy88

🐛
recdevs

🐛
reudismam

💻 🐛
rijkt

🐛
rillig-tk

🐛 -
rmohan20

💻 🐛 +
rmohan20

💻 🐛
rxmicro

🐛
ryan-gustafson

💻 🐛
sabi0

🐛
scais

🐛
sebbASF

🐛
sergeygorbaty

💻 -
shilko2013

🐛 +
shilko2013

🐛
shiomiyan

📖
simeonKondr

🐛
snajberk

🐛
sniperrifle2004

🐛
snuyanzin

🐛 💻
sratz

🐛 -
stonio

🐛 +
stonio

🐛
sturton

💻 🐛
sudharmohan

🐛
suruchidawar

🐛
svenfinitiv

🐛
tashiscool

🐛
test-git-hook

🐛 -
testation21

💻 🐛 +
testation21

💻 🐛
thanosa

🐛
tiandiyixian

🐛
tobwoerk

🐛
tprouvot

🐛
trentchilders

🐛
triandicAnt

🐛 -
trishul14

🐛 +
trishul14

🐛
tsui

🐛
winhkey

🐛
witherspore

🐛
wjljack

🐛
wuchiuwong

🐛
xingsong

🐛 -
xioayuge

🐛 +
xioayuge

🐛
xnYi9wRezm

💻 🐛
xuanuy

🐛
xyf0921

🐛
yalechen-cyw3

🐛
yasuharu-sato

🐛
zenglian

🐛 -
zgrzyt93

💻 🐛 +
zgrzyt93

💻 🐛
zh3ng

🐛
zt_soft

🐛
ztt79

🐛 From c5e4b716464eab3522cb171823ca58aa97d1db04 Mon Sep 17 00:00:00 2001 From: Andreas Dangel Date: Thu, 23 Jun 2022 16:23:45 +0200 Subject: [PATCH 186/198] [java] ImmutableField - remove now unnecessary defaultSuppressionAnnotations --- .../pmd/lang/java/rule/design/ImmutableFieldRule.java | 8 -------- 1 file changed, 8 deletions(-) diff --git a/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/rule/design/ImmutableFieldRule.java b/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/rule/design/ImmutableFieldRule.java index 516ae15cb9..8df6023062 100644 --- a/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/rule/design/ImmutableFieldRule.java +++ b/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/rule/design/ImmutableFieldRule.java @@ -4,8 +4,6 @@ package net.sourceforge.pmd.lang.java.rule.design; -import java.util.ArrayList; -import java.util.Collection; import java.util.Collections; import java.util.HashSet; import java.util.List; @@ -35,12 +33,6 @@ import net.sourceforge.pmd.lang.symboltable.NameOccurrence; */ public class ImmutableFieldRule extends AbstractLombokAwareRule { - @Override - protected Collection defaultSuppressionAnnotations() { - Collection defaultValues = new ArrayList<>(super.defaultSuppressionAnnotations()); - return defaultValues; - } - @Override public Object visit(ASTClassOrInterfaceDeclaration node, Object data) { Object result = super.visit(node, data); From ed6cd9ae39f3bc3a8bf68251aeed3128d01b5311 Mon Sep 17 00:00:00 2001 From: Andreas Dangel Date: Fri, 24 Jun 2022 15:50:11 +0200 Subject: [PATCH 187/198] [doc] Update release notes - escape `@` to not mention people on github --- docs/pages/release_notes.md | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/docs/pages/release_notes.md b/docs/pages/release_notes.md index c493ec7552..9426e54be0 100644 --- a/docs/pages/release_notes.md +++ b/docs/pages/release_notes.md @@ -19,16 +19,16 @@ This is a {{ site.pmd.release_type }} release. * [#3999](https://github.com/pmd/pmd/issues/3999): \[cli] All files are analyzed despite parameter `--file-list` * [#4009](https://github.com/pmd/pmd/issues/4009): \[core] Cannot build PMD with Temurin 17 * java-bestpractices - * [#3824](https://github.com/pmd/pmd/issues/3824): \[java] UnusedPrivateField: Do not flag fields annotated with @Version - * [#3825](https://github.com/pmd/pmd/issues/3825): \[java] UnusedPrivateField: Do not flag fields annotated with @Id or @EmbeddedId + * [#3824](https://github.com/pmd/pmd/issues/3824): \[java] UnusedPrivateField: Do not flag fields annotated with @Version + * [#3825](https://github.com/pmd/pmd/issues/3825): \[java] UnusedPrivateField: Do not flag fields annotated with @Id or @EmbeddedId * java-design - * [#3823](https://github.com/pmd/pmd/issues/3823): \[java] ImmutableField: Do not flag fields in @Entity - * [#3981](https://github.com/pmd/pmd/issues/3981): \[java] ImmutableField reports fields annotated with @Value (Spring) - * [#3998](https://github.com/pmd/pmd/issues/3998): \[java] ImmutableField reports fields annotated with @Captor (Mockito) - * [#4004](https://github.com/pmd/pmd/issues/4004): \[java] ImmutableField reports fields annotated with @GwtMock (GwtMockito) and @Spy (Mockito) + * [#3823](https://github.com/pmd/pmd/issues/3823): \[java] ImmutableField: Do not flag fields in @Entity + * [#3981](https://github.com/pmd/pmd/issues/3981): \[java] ImmutableField reports fields annotated with @Value (Spring) + * [#3998](https://github.com/pmd/pmd/issues/3998): \[java] ImmutableField reports fields annotated with @Captor (Mockito) + * [#4004](https://github.com/pmd/pmd/issues/4004): \[java] ImmutableField reports fields annotated with @GwtMock (GwtMockito) and @Spy (Mockito) * [#4008](https://github.com/pmd/pmd/issues/4008): \[java] ImmutableField not reporting fields that are only initialized in the declaration - * [#4011](https://github.com/pmd/pmd/issues/4011): \[java] ImmutableField: Do not flag fields annotated with @Inject - * [#4020](https://github.com/pmd/pmd/issues/4020): \[java] ImmutableField reports fields annotated with @FindBy and @FindBys (Selenium) + * [#4011](https://github.com/pmd/pmd/issues/4011): \[java] ImmutableField: Do not flag fields annotated with @Inject + * [#4020](https://github.com/pmd/pmd/issues/4020): \[java] ImmutableField reports fields annotated with @FindBy and @FindBys (Selenium) * java-errorprone * [#3936](https://github.com/pmd/pmd/issues/3936): \[java] AvoidFieldNameMatchingMethodName should consider enum class * [#3937](https://github.com/pmd/pmd/issues/3937): \[java] AvoidDuplicateLiterals - uncompilable test cases @@ -38,8 +38,8 @@ This is a {{ site.pmd.release_type }} release. ### External Contributions * [#3985](https://github.com/pmd/pmd/pull/3985): \[java] Fix false negative problem about Enum in AvoidFieldNameMatchingMethodName #3936 - [@Scrsloota](https://github.com/Scrsloota) * [#3993](https://github.com/pmd/pmd/pull/3993): \[java] AvoidDuplicateLiterals - Add the method "buz" definition to test cases - [@dalizi007](https://github.com/dalizi007) -* [#4002](https://github.com/pmd/pmd/pull/4002): \[java] ImmutableField - Ignore fields annotated with @Value (Spring) or @Captor (Mockito) - [@jjlharrison](https://github.com/jjlharrison) -* [#4003](https://github.com/pmd/pmd/pull/4003): \[java] UnusedPrivateField - Ignore fields annotated with @Id/@EmbeddedId/@Version (JPA) or @Mock/@Spy/@MockBean (Mockito/Spring) - [@jjlharrison](https://github.com/jjlharrison) +* [#4002](https://github.com/pmd/pmd/pull/4002): \[java] ImmutableField - Ignore fields annotated with @Value (Spring) or @Captor (Mockito) - [@jjlharrison](https://github.com/jjlharrison) +* [#4003](https://github.com/pmd/pmd/pull/4003): \[java] UnusedPrivateField - Ignore fields annotated with @Id/@EmbeddedId/@Version (JPA) or @Mock/@Spy/@MockBean (Mockito/Spring) - [@jjlharrison](https://github.com/jjlharrison) * [#4006](https://github.com/pmd/pmd/pull/4006): \[doc] Fix eclipse plugin update site URL - [@shiomiyan](https://github.com/shiomiyan) * [#4010](https://github.com/pmd/pmd/pull/4010): \[core] Bump kotlin to version 1.7.0 - [@maikelsteneker](https://github.com/maikelsteneker) From 4f1e95dae35e3de67375d9594f1c30b70374f4cf Mon Sep 17 00:00:00 2001 From: Andreas Dangel Date: Fri, 24 Jun 2022 16:07:26 +0200 Subject: [PATCH 188/198] Fix compile error --- .../pmd/lang/apex/multifile/ApexMultifileAnalysisTest.java | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/pmd-apex/src/test/java/net/sourceforge/pmd/lang/apex/multifile/ApexMultifileAnalysisTest.java b/pmd-apex/src/test/java/net/sourceforge/pmd/lang/apex/multifile/ApexMultifileAnalysisTest.java index 319f265ecf..7f3effa2b7 100644 --- a/pmd-apex/src/test/java/net/sourceforge/pmd/lang/apex/multifile/ApexMultifileAnalysisTest.java +++ b/pmd-apex/src/test/java/net/sourceforge/pmd/lang/apex/multifile/ApexMultifileAnalysisTest.java @@ -15,13 +15,14 @@ import java.nio.charset.StandardCharsets; import java.nio.file.Files; import java.util.Arrays; -import org.apache.commons.io.IOUtils; import org.checkerframework.checker.nullness.qual.NonNull; import org.junit.Rule; import org.junit.Test; import org.junit.contrib.java.lang.system.SystemErrRule; import org.junit.rules.TemporaryFolder; +import net.sourceforge.pmd.util.IOUtil; + public class ApexMultifileAnalysisTest { @Rule @@ -67,7 +68,7 @@ public class ApexMultifileAnalysisTest { private void copyResource(String resourcePath, String relativePathInTempDir) throws IOException { File file = tempFolder.newFile(relativePathInTempDir); - String fileContents = IOUtils.toString(getClass().getResourceAsStream(resourcePath), StandardCharsets.UTF_8); + String fileContents = IOUtil.readToString(getClass().getResourceAsStream(resourcePath), StandardCharsets.UTF_8); Files.write(file.toPath(), Arrays.asList(fileContents.split("\\R").clone())); } From 0f58afcc0122faef593fe0ef699a8d55315dc7eb Mon Sep 17 00:00:00 2001 From: Andreas Dangel Date: Fri, 24 Jun 2022 16:19:43 +0200 Subject: [PATCH 189/198] [java] ImmutableField - remove now unnecessary field annotations --- .../lang/java/rule/design/ImmutableFieldRule.java | 12 ------------ 1 file changed, 12 deletions(-) diff --git a/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/rule/design/ImmutableFieldRule.java b/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/rule/design/ImmutableFieldRule.java index 438bbcaaba..ecd65ef8b6 100644 --- a/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/rule/design/ImmutableFieldRule.java +++ b/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/rule/design/ImmutableFieldRule.java @@ -43,17 +43,6 @@ public class ImmutableFieldRule extends AbstractJavaRulechainRule { "lombok.Value" ); - private static final Set INVALIDATING_FIELD_ANNOTS = - setOf( - "lombok.Setter", - "org.mockito.Captor", - "org.mockito.InjectMocks", - "org.mockito.Mock", - "org.springframework.beans.factory.annotation.Autowired", - "org.springframework.beans.factory.annotation.Value", - "org.springframework.boot.test.mock.mockito.MockBean" - ); - public ImmutableFieldRule() { super(ASTFieldDeclaration.class); definePropertyDescriptor(IGNORED_ANNOTS); @@ -65,7 +54,6 @@ public class ImmutableFieldRule extends AbstractJavaRulechainRule { ASTAnyTypeDeclaration enclosingType = field.getEnclosingType(); if (field.getEffectiveVisibility().isAtMost(Visibility.V_PRIVATE) && !field.getModifiers().hasAny(JModifier.VOLATILE, JModifier.STATIC, JModifier.FINAL) - && !JavaAstUtils.hasAnyAnnotation(field, INVALIDATING_FIELD_ANNOTS) && !JavaAstUtils.hasAnyAnnotation(enclosingType, INVALIDATING_CLASS_ANNOT) && !JavaAstUtils.hasAnyAnnotation(field, getProperty(IGNORED_ANNOTS))) { From cf90c2141f07ff0400fc413ed1f4db60391b6cd1 Mon Sep 17 00:00:00 2001 From: Andreas Dangel Date: Sat, 25 Jun 2022 09:15:59 +0200 Subject: [PATCH 190/198] Prepare pmd release 6.47.0 --- docs/_config.yml | 2 +- docs/pages/next_major_development.md | 4 ++++ docs/pages/release_notes.md | 9 +++++++-- 3 files changed, 12 insertions(+), 3 deletions(-) diff --git a/docs/_config.yml b/docs/_config.yml index e642bcc872..c4367fc735 100644 --- a/docs/_config.yml +++ b/docs/_config.yml @@ -1,7 +1,7 @@ repository: pmd/pmd pmd: - version: 6.47.0-SNAPSHOT + version: 6.47.0 previous_version: 6.46.0 date: 25-June-2022 release_type: minor diff --git a/docs/pages/next_major_development.md b/docs/pages/next_major_development.md index 0c952b2741..6c53ffc407 100644 --- a/docs/pages/next_major_development.md +++ b/docs/pages/next_major_development.md @@ -125,6 +125,10 @@ the breaking API changes will be performed in 7.0.0. an API is tagged as `@Deprecated` or not in the latest minor release. During the development of 7.0.0, we may decide to remove some APIs that were not tagged as deprecated, though we'll try to avoid it." %} +#### 6.47.0 + +No changes. + #### 6.46.0 ##### Deprecated ruleset references diff --git a/docs/pages/release_notes.md b/docs/pages/release_notes.md index 9426e54be0..a716be02e8 100644 --- a/docs/pages/release_notes.md +++ b/docs/pages/release_notes.md @@ -12,8 +12,6 @@ This is a {{ site.pmd.release_type }} release. {% tocmaker is_release_notes_processor %} -### New and noteworthy - ### Fixed Issues * core * [#3999](https://github.com/pmd/pmd/issues/3999): \[cli] All files are analyzed despite parameter `--file-list` @@ -35,6 +33,8 @@ This is a {{ site.pmd.release_type }} release. ### API Changes +No changes. + ### External Contributions * [#3985](https://github.com/pmd/pmd/pull/3985): \[java] Fix false negative problem about Enum in AvoidFieldNameMatchingMethodName #3936 - [@Scrsloota](https://github.com/Scrsloota) * [#3993](https://github.com/pmd/pmd/pull/3993): \[java] AvoidDuplicateLiterals - Add the method "buz" definition to test cases - [@dalizi007](https://github.com/dalizi007) @@ -43,5 +43,10 @@ This is a {{ site.pmd.release_type }} release. * [#4006](https://github.com/pmd/pmd/pull/4006): \[doc] Fix eclipse plugin update site URL - [@shiomiyan](https://github.com/shiomiyan) * [#4010](https://github.com/pmd/pmd/pull/4010): \[core] Bump kotlin to version 1.7.0 - [@maikelsteneker](https://github.com/maikelsteneker) +### Stats +* 45 commits +* 23 closed tickets & PRs +* Days since last release: 27 + {% endtocmaker %} From 07eb3d2d8081d787c60abdfe74c46af24772a3ce Mon Sep 17 00:00:00 2001 From: Andreas Dangel Date: Sat, 25 Jun 2022 09:30:37 +0200 Subject: [PATCH 191/198] [maven-release-plugin] prepare release pmd_releases/6.47.0 --- pmd-apex-jorje/pom.xml | 2 +- pmd-apex/pom.xml | 2 +- pmd-core/pom.xml | 2 +- pmd-cpp/pom.xml | 2 +- pmd-cs/pom.xml | 2 +- pmd-dart/pom.xml | 2 +- pmd-dist/pom.xml | 2 +- pmd-doc/pom.xml | 2 +- pmd-fortran/pom.xml | 2 +- pmd-go/pom.xml | 2 +- pmd-groovy/pom.xml | 2 +- pmd-html/pom.xml | 2 +- pmd-java/pom.xml | 2 +- pmd-java8/pom.xml | 2 +- pmd-javascript/pom.xml | 2 +- pmd-jsp/pom.xml | 2 +- pmd-kotlin/pom.xml | 2 +- pmd-lang-test/pom.xml | 2 +- pmd-lua/pom.xml | 2 +- pmd-matlab/pom.xml | 2 +- pmd-modelica/pom.xml | 2 +- pmd-objectivec/pom.xml | 2 +- pmd-perl/pom.xml | 2 +- pmd-php/pom.xml | 2 +- pmd-plsql/pom.xml | 2 +- pmd-python/pom.xml | 2 +- pmd-ruby/pom.xml | 2 +- pmd-scala-modules/pmd-scala-common/pom.xml | 2 +- pmd-scala-modules/pmd-scala_2.12/pom.xml | 2 +- pmd-scala-modules/pmd-scala_2.13/pom.xml | 2 +- pmd-scala/pom.xml | 2 +- pmd-swift/pom.xml | 2 +- pmd-test/pom.xml | 2 +- pmd-visualforce/pom.xml | 2 +- pmd-vm/pom.xml | 2 +- pmd-xml/pom.xml | 2 +- pom.xml | 6 +++--- 37 files changed, 39 insertions(+), 39 deletions(-) diff --git a/pmd-apex-jorje/pom.xml b/pmd-apex-jorje/pom.xml index b5a177525f..c8d686cf07 100644 --- a/pmd-apex-jorje/pom.xml +++ b/pmd-apex-jorje/pom.xml @@ -8,7 +8,7 @@ net.sourceforge.pmd pmd - 6.47.0-SNAPSHOT + 6.47.0 ../pom.xml diff --git a/pmd-apex/pom.xml b/pmd-apex/pom.xml index 9cbd113a4e..d4cfae40d4 100644 --- a/pmd-apex/pom.xml +++ b/pmd-apex/pom.xml @@ -7,7 +7,7 @@ net.sourceforge.pmd pmd - 6.47.0-SNAPSHOT + 6.47.0 ../pom.xml diff --git a/pmd-core/pom.xml b/pmd-core/pom.xml index f86c7c1c49..dba82937a4 100644 --- a/pmd-core/pom.xml +++ b/pmd-core/pom.xml @@ -7,7 +7,7 @@ net.sourceforge.pmd pmd - 6.47.0-SNAPSHOT + 6.47.0 ../pom.xml diff --git a/pmd-cpp/pom.xml b/pmd-cpp/pom.xml index 36487444eb..0c2a975dd3 100644 --- a/pmd-cpp/pom.xml +++ b/pmd-cpp/pom.xml @@ -7,7 +7,7 @@ net.sourceforge.pmd pmd - 6.47.0-SNAPSHOT + 6.47.0 ../pom.xml diff --git a/pmd-cs/pom.xml b/pmd-cs/pom.xml index 96e8cb895a..0491ecc2f4 100644 --- a/pmd-cs/pom.xml +++ b/pmd-cs/pom.xml @@ -7,7 +7,7 @@ net.sourceforge.pmd pmd - 6.47.0-SNAPSHOT + 6.47.0 ../pom.xml diff --git a/pmd-dart/pom.xml b/pmd-dart/pom.xml index f1196e2faa..882a70552e 100644 --- a/pmd-dart/pom.xml +++ b/pmd-dart/pom.xml @@ -7,7 +7,7 @@ net.sourceforge.pmd pmd - 6.47.0-SNAPSHOT + 6.47.0 ../pom.xml diff --git a/pmd-dist/pom.xml b/pmd-dist/pom.xml index 1181aecfaf..306c765abb 100644 --- a/pmd-dist/pom.xml +++ b/pmd-dist/pom.xml @@ -8,7 +8,7 @@ net.sourceforge.pmd pmd - 6.47.0-SNAPSHOT + 6.47.0 ../pom.xml diff --git a/pmd-doc/pom.xml b/pmd-doc/pom.xml index 684f809c62..0fb47d06fc 100644 --- a/pmd-doc/pom.xml +++ b/pmd-doc/pom.xml @@ -8,7 +8,7 @@ net.sourceforge.pmd pmd - 6.47.0-SNAPSHOT + 6.47.0 ../pom.xml diff --git a/pmd-fortran/pom.xml b/pmd-fortran/pom.xml index 4a31b11c06..2311e8fb87 100644 --- a/pmd-fortran/pom.xml +++ b/pmd-fortran/pom.xml @@ -7,7 +7,7 @@ net.sourceforge.pmd pmd - 6.47.0-SNAPSHOT + 6.47.0 ../pom.xml diff --git a/pmd-go/pom.xml b/pmd-go/pom.xml index 9389feafff..8b8c43dad4 100644 --- a/pmd-go/pom.xml +++ b/pmd-go/pom.xml @@ -7,7 +7,7 @@ net.sourceforge.pmd pmd - 6.47.0-SNAPSHOT + 6.47.0 ../pom.xml diff --git a/pmd-groovy/pom.xml b/pmd-groovy/pom.xml index 4608e3662f..6f893c2fa4 100644 --- a/pmd-groovy/pom.xml +++ b/pmd-groovy/pom.xml @@ -7,7 +7,7 @@ net.sourceforge.pmd pmd - 6.47.0-SNAPSHOT + 6.47.0 ../pom.xml diff --git a/pmd-html/pom.xml b/pmd-html/pom.xml index f536a558ee..17163fbde9 100644 --- a/pmd-html/pom.xml +++ b/pmd-html/pom.xml @@ -7,7 +7,7 @@ net.sourceforge.pmd pmd - 6.47.0-SNAPSHOT + 6.47.0 ../pom.xml diff --git a/pmd-java/pom.xml b/pmd-java/pom.xml index c94e568db0..8ce840bedd 100644 --- a/pmd-java/pom.xml +++ b/pmd-java/pom.xml @@ -7,7 +7,7 @@ net.sourceforge.pmd pmd - 6.47.0-SNAPSHOT + 6.47.0 ../pom.xml diff --git a/pmd-java8/pom.xml b/pmd-java8/pom.xml index 7f75518ed4..92f8b346a9 100644 --- a/pmd-java8/pom.xml +++ b/pmd-java8/pom.xml @@ -7,7 +7,7 @@ net.sourceforge.pmd pmd - 6.47.0-SNAPSHOT + 6.47.0 ../pom.xml diff --git a/pmd-javascript/pom.xml b/pmd-javascript/pom.xml index 0d2edc5e3a..0e649dd5e1 100644 --- a/pmd-javascript/pom.xml +++ b/pmd-javascript/pom.xml @@ -7,7 +7,7 @@ net.sourceforge.pmd pmd - 6.47.0-SNAPSHOT + 6.47.0 ../pom.xml diff --git a/pmd-jsp/pom.xml b/pmd-jsp/pom.xml index 79342c8ff1..6b8aa0e9ca 100644 --- a/pmd-jsp/pom.xml +++ b/pmd-jsp/pom.xml @@ -7,7 +7,7 @@ net.sourceforge.pmd pmd - 6.47.0-SNAPSHOT + 6.47.0 ../pom.xml diff --git a/pmd-kotlin/pom.xml b/pmd-kotlin/pom.xml index 6234df66e7..66d17278e6 100644 --- a/pmd-kotlin/pom.xml +++ b/pmd-kotlin/pom.xml @@ -7,7 +7,7 @@ net.sourceforge.pmd pmd - 6.47.0-SNAPSHOT + 6.47.0 ../pom.xml diff --git a/pmd-lang-test/pom.xml b/pmd-lang-test/pom.xml index 99a590c89b..06c637e385 100644 --- a/pmd-lang-test/pom.xml +++ b/pmd-lang-test/pom.xml @@ -12,7 +12,7 @@ net.sourceforge.pmd pmd - 6.47.0-SNAPSHOT + 6.47.0 ../pom.xml diff --git a/pmd-lua/pom.xml b/pmd-lua/pom.xml index ef459787d3..dc0bb01bca 100644 --- a/pmd-lua/pom.xml +++ b/pmd-lua/pom.xml @@ -7,7 +7,7 @@ net.sourceforge.pmd pmd - 6.47.0-SNAPSHOT + 6.47.0 ../pom.xml diff --git a/pmd-matlab/pom.xml b/pmd-matlab/pom.xml index b6dffb8afa..d52f309768 100644 --- a/pmd-matlab/pom.xml +++ b/pmd-matlab/pom.xml @@ -7,7 +7,7 @@ net.sourceforge.pmd pmd - 6.47.0-SNAPSHOT + 6.47.0 ../pom.xml diff --git a/pmd-modelica/pom.xml b/pmd-modelica/pom.xml index bee6eb4ece..398b1bdd9e 100644 --- a/pmd-modelica/pom.xml +++ b/pmd-modelica/pom.xml @@ -7,7 +7,7 @@ net.sourceforge.pmd pmd - 6.47.0-SNAPSHOT + 6.47.0 ../pom.xml diff --git a/pmd-objectivec/pom.xml b/pmd-objectivec/pom.xml index 2b1bede214..0f36dcd9b9 100644 --- a/pmd-objectivec/pom.xml +++ b/pmd-objectivec/pom.xml @@ -7,7 +7,7 @@ net.sourceforge.pmd pmd - 6.47.0-SNAPSHOT + 6.47.0 ../pom.xml diff --git a/pmd-perl/pom.xml b/pmd-perl/pom.xml index 83f957ad73..f82316968a 100644 --- a/pmd-perl/pom.xml +++ b/pmd-perl/pom.xml @@ -7,7 +7,7 @@ net.sourceforge.pmd pmd - 6.47.0-SNAPSHOT + 6.47.0 ../pom.xml diff --git a/pmd-php/pom.xml b/pmd-php/pom.xml index c4a2e6e040..23554bef66 100644 --- a/pmd-php/pom.xml +++ b/pmd-php/pom.xml @@ -7,7 +7,7 @@ net.sourceforge.pmd pmd - 6.47.0-SNAPSHOT + 6.47.0 ../pom.xml diff --git a/pmd-plsql/pom.xml b/pmd-plsql/pom.xml index 2242099ad1..0ac09fbfb3 100644 --- a/pmd-plsql/pom.xml +++ b/pmd-plsql/pom.xml @@ -7,7 +7,7 @@ net.sourceforge.pmd pmd - 6.47.0-SNAPSHOT + 6.47.0 ../pom.xml diff --git a/pmd-python/pom.xml b/pmd-python/pom.xml index 6406fb7bc5..b71b214139 100644 --- a/pmd-python/pom.xml +++ b/pmd-python/pom.xml @@ -7,7 +7,7 @@ net.sourceforge.pmd pmd - 6.47.0-SNAPSHOT + 6.47.0 ../pom.xml diff --git a/pmd-ruby/pom.xml b/pmd-ruby/pom.xml index e0385b000c..b57d3dae75 100644 --- a/pmd-ruby/pom.xml +++ b/pmd-ruby/pom.xml @@ -7,7 +7,7 @@ net.sourceforge.pmd pmd - 6.47.0-SNAPSHOT + 6.47.0 ../pom.xml diff --git a/pmd-scala-modules/pmd-scala-common/pom.xml b/pmd-scala-modules/pmd-scala-common/pom.xml index c5327d8381..abd29a1944 100644 --- a/pmd-scala-modules/pmd-scala-common/pom.xml +++ b/pmd-scala-modules/pmd-scala-common/pom.xml @@ -8,7 +8,7 @@ net.sourceforge.pmd pmd - 6.47.0-SNAPSHOT + 6.47.0 ../../pom.xml diff --git a/pmd-scala-modules/pmd-scala_2.12/pom.xml b/pmd-scala-modules/pmd-scala_2.12/pom.xml index b6a62cd14c..2a15b153ae 100644 --- a/pmd-scala-modules/pmd-scala_2.12/pom.xml +++ b/pmd-scala-modules/pmd-scala_2.12/pom.xml @@ -7,7 +7,7 @@ net.sourceforge.pmd pmd-scala-common - 6.47.0-SNAPSHOT + 6.47.0 ../pmd-scala-common/pom.xml diff --git a/pmd-scala-modules/pmd-scala_2.13/pom.xml b/pmd-scala-modules/pmd-scala_2.13/pom.xml index 43ed00eb17..77448efb0a 100644 --- a/pmd-scala-modules/pmd-scala_2.13/pom.xml +++ b/pmd-scala-modules/pmd-scala_2.13/pom.xml @@ -7,7 +7,7 @@ net.sourceforge.pmd pmd-scala-common - 6.47.0-SNAPSHOT + 6.47.0 ../pmd-scala-common/pom.xml diff --git a/pmd-scala/pom.xml b/pmd-scala/pom.xml index 9a0020aa0f..f630566890 100644 --- a/pmd-scala/pom.xml +++ b/pmd-scala/pom.xml @@ -9,7 +9,7 @@ net.sourceforge.pmd pmd - 6.47.0-SNAPSHOT + 6.47.0 ../pom.xml diff --git a/pmd-swift/pom.xml b/pmd-swift/pom.xml index 82a44caa83..e35389d270 100644 --- a/pmd-swift/pom.xml +++ b/pmd-swift/pom.xml @@ -7,7 +7,7 @@ net.sourceforge.pmd pmd - 6.47.0-SNAPSHOT + 6.47.0 ../pom.xml diff --git a/pmd-test/pom.xml b/pmd-test/pom.xml index c2540c1888..8368d125ba 100644 --- a/pmd-test/pom.xml +++ b/pmd-test/pom.xml @@ -8,7 +8,7 @@ net.sourceforge.pmd pmd - 6.47.0-SNAPSHOT + 6.47.0 ../pom.xml diff --git a/pmd-visualforce/pom.xml b/pmd-visualforce/pom.xml index acdf585467..546b1063c6 100644 --- a/pmd-visualforce/pom.xml +++ b/pmd-visualforce/pom.xml @@ -7,7 +7,7 @@ net.sourceforge.pmd pmd - 6.47.0-SNAPSHOT + 6.47.0 ../pom.xml diff --git a/pmd-vm/pom.xml b/pmd-vm/pom.xml index 3c69ab2437..f0763b7207 100644 --- a/pmd-vm/pom.xml +++ b/pmd-vm/pom.xml @@ -7,7 +7,7 @@ net.sourceforge.pmd pmd - 6.47.0-SNAPSHOT + 6.47.0 ../pom.xml diff --git a/pmd-xml/pom.xml b/pmd-xml/pom.xml index 7fe4f69fe5..db64e88324 100644 --- a/pmd-xml/pom.xml +++ b/pmd-xml/pom.xml @@ -7,7 +7,7 @@ net.sourceforge.pmd pmd - 6.47.0-SNAPSHOT + 6.47.0 ../pom.xml diff --git a/pom.xml b/pom.xml index 423b08a6e7..ce61b80ca9 100644 --- a/pom.xml +++ b/pom.xml @@ -3,7 +3,7 @@ 4.0.0 net.sourceforge.pmd pmd - 6.47.0-SNAPSHOT + 6.47.0 pom PMD @@ -55,7 +55,7 @@ scm:git:git://github.com/pmd/pmd.git scm:git:ssh://git@github.com/pmd/pmd.git https://github.com/pmd/pmd - HEAD + pmd_releases/6.47.0 @@ -76,7 +76,7 @@ - 2022-05-28T09:04:31Z + 2022-06-25T07:16:23Z 7 From a5006f63839cb9e3e23cd2cd24f19f747d3d3d9d Mon Sep 17 00:00:00 2001 From: Andreas Dangel Date: Sat, 25 Jun 2022 09:30:43 +0200 Subject: [PATCH 192/198] [maven-release-plugin] prepare for next development iteration --- pmd-apex-jorje/pom.xml | 2 +- pmd-apex/pom.xml | 2 +- pmd-core/pom.xml | 2 +- pmd-cpp/pom.xml | 2 +- pmd-cs/pom.xml | 2 +- pmd-dart/pom.xml | 2 +- pmd-dist/pom.xml | 2 +- pmd-doc/pom.xml | 2 +- pmd-fortran/pom.xml | 2 +- pmd-go/pom.xml | 2 +- pmd-groovy/pom.xml | 2 +- pmd-html/pom.xml | 2 +- pmd-java/pom.xml | 2 +- pmd-java8/pom.xml | 2 +- pmd-javascript/pom.xml | 2 +- pmd-jsp/pom.xml | 2 +- pmd-kotlin/pom.xml | 2 +- pmd-lang-test/pom.xml | 2 +- pmd-lua/pom.xml | 2 +- pmd-matlab/pom.xml | 2 +- pmd-modelica/pom.xml | 2 +- pmd-objectivec/pom.xml | 2 +- pmd-perl/pom.xml | 2 +- pmd-php/pom.xml | 2 +- pmd-plsql/pom.xml | 2 +- pmd-python/pom.xml | 2 +- pmd-ruby/pom.xml | 2 +- pmd-scala-modules/pmd-scala-common/pom.xml | 2 +- pmd-scala-modules/pmd-scala_2.12/pom.xml | 2 +- pmd-scala-modules/pmd-scala_2.13/pom.xml | 2 +- pmd-scala/pom.xml | 2 +- pmd-swift/pom.xml | 2 +- pmd-test/pom.xml | 2 +- pmd-visualforce/pom.xml | 2 +- pmd-vm/pom.xml | 2 +- pmd-xml/pom.xml | 2 +- pom.xml | 6 +++--- 37 files changed, 39 insertions(+), 39 deletions(-) diff --git a/pmd-apex-jorje/pom.xml b/pmd-apex-jorje/pom.xml index c8d686cf07..c368f726dc 100644 --- a/pmd-apex-jorje/pom.xml +++ b/pmd-apex-jorje/pom.xml @@ -8,7 +8,7 @@ net.sourceforge.pmd pmd - 6.47.0 + 6.48.0-SNAPSHOT ../pom.xml diff --git a/pmd-apex/pom.xml b/pmd-apex/pom.xml index d4cfae40d4..5a5f208f72 100644 --- a/pmd-apex/pom.xml +++ b/pmd-apex/pom.xml @@ -7,7 +7,7 @@ net.sourceforge.pmd pmd - 6.47.0 + 6.48.0-SNAPSHOT ../pom.xml diff --git a/pmd-core/pom.xml b/pmd-core/pom.xml index dba82937a4..d7bf9e1b27 100644 --- a/pmd-core/pom.xml +++ b/pmd-core/pom.xml @@ -7,7 +7,7 @@ net.sourceforge.pmd pmd - 6.47.0 + 6.48.0-SNAPSHOT ../pom.xml diff --git a/pmd-cpp/pom.xml b/pmd-cpp/pom.xml index 0c2a975dd3..cfbe955501 100644 --- a/pmd-cpp/pom.xml +++ b/pmd-cpp/pom.xml @@ -7,7 +7,7 @@ net.sourceforge.pmd pmd - 6.47.0 + 6.48.0-SNAPSHOT ../pom.xml diff --git a/pmd-cs/pom.xml b/pmd-cs/pom.xml index 0491ecc2f4..36a4e08e0a 100644 --- a/pmd-cs/pom.xml +++ b/pmd-cs/pom.xml @@ -7,7 +7,7 @@ net.sourceforge.pmd pmd - 6.47.0 + 6.48.0-SNAPSHOT ../pom.xml diff --git a/pmd-dart/pom.xml b/pmd-dart/pom.xml index 882a70552e..e3c472c466 100644 --- a/pmd-dart/pom.xml +++ b/pmd-dart/pom.xml @@ -7,7 +7,7 @@ net.sourceforge.pmd pmd - 6.47.0 + 6.48.0-SNAPSHOT ../pom.xml diff --git a/pmd-dist/pom.xml b/pmd-dist/pom.xml index 306c765abb..9323e14075 100644 --- a/pmd-dist/pom.xml +++ b/pmd-dist/pom.xml @@ -8,7 +8,7 @@ net.sourceforge.pmd pmd - 6.47.0 + 6.48.0-SNAPSHOT ../pom.xml diff --git a/pmd-doc/pom.xml b/pmd-doc/pom.xml index 0fb47d06fc..f35338c8c1 100644 --- a/pmd-doc/pom.xml +++ b/pmd-doc/pom.xml @@ -8,7 +8,7 @@ net.sourceforge.pmd pmd - 6.47.0 + 6.48.0-SNAPSHOT ../pom.xml diff --git a/pmd-fortran/pom.xml b/pmd-fortran/pom.xml index 2311e8fb87..55afe0f0ca 100644 --- a/pmd-fortran/pom.xml +++ b/pmd-fortran/pom.xml @@ -7,7 +7,7 @@ net.sourceforge.pmd pmd - 6.47.0 + 6.48.0-SNAPSHOT ../pom.xml diff --git a/pmd-go/pom.xml b/pmd-go/pom.xml index 8b8c43dad4..9c7c525e53 100644 --- a/pmd-go/pom.xml +++ b/pmd-go/pom.xml @@ -7,7 +7,7 @@ net.sourceforge.pmd pmd - 6.47.0 + 6.48.0-SNAPSHOT ../pom.xml diff --git a/pmd-groovy/pom.xml b/pmd-groovy/pom.xml index 6f893c2fa4..db176baebe 100644 --- a/pmd-groovy/pom.xml +++ b/pmd-groovy/pom.xml @@ -7,7 +7,7 @@ net.sourceforge.pmd pmd - 6.47.0 + 6.48.0-SNAPSHOT ../pom.xml diff --git a/pmd-html/pom.xml b/pmd-html/pom.xml index 17163fbde9..db21698140 100644 --- a/pmd-html/pom.xml +++ b/pmd-html/pom.xml @@ -7,7 +7,7 @@ net.sourceforge.pmd pmd - 6.47.0 + 6.48.0-SNAPSHOT ../pom.xml diff --git a/pmd-java/pom.xml b/pmd-java/pom.xml index 8ce840bedd..ddd74247e6 100644 --- a/pmd-java/pom.xml +++ b/pmd-java/pom.xml @@ -7,7 +7,7 @@ net.sourceforge.pmd pmd - 6.47.0 + 6.48.0-SNAPSHOT ../pom.xml diff --git a/pmd-java8/pom.xml b/pmd-java8/pom.xml index 92f8b346a9..a122fd7a41 100644 --- a/pmd-java8/pom.xml +++ b/pmd-java8/pom.xml @@ -7,7 +7,7 @@ net.sourceforge.pmd pmd - 6.47.0 + 6.48.0-SNAPSHOT ../pom.xml diff --git a/pmd-javascript/pom.xml b/pmd-javascript/pom.xml index 0e649dd5e1..1fb34e70f5 100644 --- a/pmd-javascript/pom.xml +++ b/pmd-javascript/pom.xml @@ -7,7 +7,7 @@ net.sourceforge.pmd pmd - 6.47.0 + 6.48.0-SNAPSHOT ../pom.xml diff --git a/pmd-jsp/pom.xml b/pmd-jsp/pom.xml index 6b8aa0e9ca..2689d0b071 100644 --- a/pmd-jsp/pom.xml +++ b/pmd-jsp/pom.xml @@ -7,7 +7,7 @@ net.sourceforge.pmd pmd - 6.47.0 + 6.48.0-SNAPSHOT ../pom.xml diff --git a/pmd-kotlin/pom.xml b/pmd-kotlin/pom.xml index 66d17278e6..4e226a123d 100644 --- a/pmd-kotlin/pom.xml +++ b/pmd-kotlin/pom.xml @@ -7,7 +7,7 @@ net.sourceforge.pmd pmd - 6.47.0 + 6.48.0-SNAPSHOT ../pom.xml diff --git a/pmd-lang-test/pom.xml b/pmd-lang-test/pom.xml index 06c637e385..b8c6d65a03 100644 --- a/pmd-lang-test/pom.xml +++ b/pmd-lang-test/pom.xml @@ -12,7 +12,7 @@ net.sourceforge.pmd pmd - 6.47.0 + 6.48.0-SNAPSHOT ../pom.xml diff --git a/pmd-lua/pom.xml b/pmd-lua/pom.xml index dc0bb01bca..180aa92f43 100644 --- a/pmd-lua/pom.xml +++ b/pmd-lua/pom.xml @@ -7,7 +7,7 @@ net.sourceforge.pmd pmd - 6.47.0 + 6.48.0-SNAPSHOT ../pom.xml diff --git a/pmd-matlab/pom.xml b/pmd-matlab/pom.xml index d52f309768..af78df7ea9 100644 --- a/pmd-matlab/pom.xml +++ b/pmd-matlab/pom.xml @@ -7,7 +7,7 @@ net.sourceforge.pmd pmd - 6.47.0 + 6.48.0-SNAPSHOT ../pom.xml diff --git a/pmd-modelica/pom.xml b/pmd-modelica/pom.xml index 398b1bdd9e..72480f6f5a 100644 --- a/pmd-modelica/pom.xml +++ b/pmd-modelica/pom.xml @@ -7,7 +7,7 @@ net.sourceforge.pmd pmd - 6.47.0 + 6.48.0-SNAPSHOT ../pom.xml diff --git a/pmd-objectivec/pom.xml b/pmd-objectivec/pom.xml index 0f36dcd9b9..fca206b41e 100644 --- a/pmd-objectivec/pom.xml +++ b/pmd-objectivec/pom.xml @@ -7,7 +7,7 @@ net.sourceforge.pmd pmd - 6.47.0 + 6.48.0-SNAPSHOT ../pom.xml diff --git a/pmd-perl/pom.xml b/pmd-perl/pom.xml index f82316968a..a3a95bb798 100644 --- a/pmd-perl/pom.xml +++ b/pmd-perl/pom.xml @@ -7,7 +7,7 @@ net.sourceforge.pmd pmd - 6.47.0 + 6.48.0-SNAPSHOT ../pom.xml diff --git a/pmd-php/pom.xml b/pmd-php/pom.xml index 23554bef66..029be6c047 100644 --- a/pmd-php/pom.xml +++ b/pmd-php/pom.xml @@ -7,7 +7,7 @@ net.sourceforge.pmd pmd - 6.47.0 + 6.48.0-SNAPSHOT ../pom.xml diff --git a/pmd-plsql/pom.xml b/pmd-plsql/pom.xml index 0ac09fbfb3..c217149637 100644 --- a/pmd-plsql/pom.xml +++ b/pmd-plsql/pom.xml @@ -7,7 +7,7 @@ net.sourceforge.pmd pmd - 6.47.0 + 6.48.0-SNAPSHOT ../pom.xml diff --git a/pmd-python/pom.xml b/pmd-python/pom.xml index b71b214139..7a4c58569d 100644 --- a/pmd-python/pom.xml +++ b/pmd-python/pom.xml @@ -7,7 +7,7 @@ net.sourceforge.pmd pmd - 6.47.0 + 6.48.0-SNAPSHOT ../pom.xml diff --git a/pmd-ruby/pom.xml b/pmd-ruby/pom.xml index b57d3dae75..6631300aa5 100644 --- a/pmd-ruby/pom.xml +++ b/pmd-ruby/pom.xml @@ -7,7 +7,7 @@ net.sourceforge.pmd pmd - 6.47.0 + 6.48.0-SNAPSHOT ../pom.xml diff --git a/pmd-scala-modules/pmd-scala-common/pom.xml b/pmd-scala-modules/pmd-scala-common/pom.xml index abd29a1944..5029a7d0a3 100644 --- a/pmd-scala-modules/pmd-scala-common/pom.xml +++ b/pmd-scala-modules/pmd-scala-common/pom.xml @@ -8,7 +8,7 @@ net.sourceforge.pmd pmd - 6.47.0 + 6.48.0-SNAPSHOT ../../pom.xml diff --git a/pmd-scala-modules/pmd-scala_2.12/pom.xml b/pmd-scala-modules/pmd-scala_2.12/pom.xml index 2a15b153ae..2de4376841 100644 --- a/pmd-scala-modules/pmd-scala_2.12/pom.xml +++ b/pmd-scala-modules/pmd-scala_2.12/pom.xml @@ -7,7 +7,7 @@ net.sourceforge.pmd pmd-scala-common - 6.47.0 + 6.48.0-SNAPSHOT ../pmd-scala-common/pom.xml diff --git a/pmd-scala-modules/pmd-scala_2.13/pom.xml b/pmd-scala-modules/pmd-scala_2.13/pom.xml index 77448efb0a..a7e7e17bed 100644 --- a/pmd-scala-modules/pmd-scala_2.13/pom.xml +++ b/pmd-scala-modules/pmd-scala_2.13/pom.xml @@ -7,7 +7,7 @@ net.sourceforge.pmd pmd-scala-common - 6.47.0 + 6.48.0-SNAPSHOT ../pmd-scala-common/pom.xml diff --git a/pmd-scala/pom.xml b/pmd-scala/pom.xml index f630566890..513cbc7fda 100644 --- a/pmd-scala/pom.xml +++ b/pmd-scala/pom.xml @@ -9,7 +9,7 @@ net.sourceforge.pmd pmd - 6.47.0 + 6.48.0-SNAPSHOT ../pom.xml diff --git a/pmd-swift/pom.xml b/pmd-swift/pom.xml index e35389d270..9a600748c1 100644 --- a/pmd-swift/pom.xml +++ b/pmd-swift/pom.xml @@ -7,7 +7,7 @@ net.sourceforge.pmd pmd - 6.47.0 + 6.48.0-SNAPSHOT ../pom.xml diff --git a/pmd-test/pom.xml b/pmd-test/pom.xml index 8368d125ba..61db74f33b 100644 --- a/pmd-test/pom.xml +++ b/pmd-test/pom.xml @@ -8,7 +8,7 @@ net.sourceforge.pmd pmd - 6.47.0 + 6.48.0-SNAPSHOT ../pom.xml diff --git a/pmd-visualforce/pom.xml b/pmd-visualforce/pom.xml index 546b1063c6..6285b89b29 100644 --- a/pmd-visualforce/pom.xml +++ b/pmd-visualforce/pom.xml @@ -7,7 +7,7 @@ net.sourceforge.pmd pmd - 6.47.0 + 6.48.0-SNAPSHOT ../pom.xml diff --git a/pmd-vm/pom.xml b/pmd-vm/pom.xml index f0763b7207..238203f2f0 100644 --- a/pmd-vm/pom.xml +++ b/pmd-vm/pom.xml @@ -7,7 +7,7 @@ net.sourceforge.pmd pmd - 6.47.0 + 6.48.0-SNAPSHOT ../pom.xml diff --git a/pmd-xml/pom.xml b/pmd-xml/pom.xml index db64e88324..c3ade37bbd 100644 --- a/pmd-xml/pom.xml +++ b/pmd-xml/pom.xml @@ -7,7 +7,7 @@ net.sourceforge.pmd pmd - 6.47.0 + 6.48.0-SNAPSHOT ../pom.xml diff --git a/pom.xml b/pom.xml index ce61b80ca9..4a7d758d4d 100644 --- a/pom.xml +++ b/pom.xml @@ -3,7 +3,7 @@ 4.0.0 net.sourceforge.pmd pmd - 6.47.0 + 6.48.0-SNAPSHOT pom PMD @@ -55,7 +55,7 @@ scm:git:git://github.com/pmd/pmd.git scm:git:ssh://git@github.com/pmd/pmd.git https://github.com/pmd/pmd - pmd_releases/6.47.0 + HEAD @@ -76,7 +76,7 @@ - 2022-06-25T07:16:23Z + 2022-06-25T07:30:42Z 7 From 129674e0d5a86a2cc9ad3394239885f0a007e1c9 Mon Sep 17 00:00:00 2001 From: Andreas Dangel Date: Sat, 25 Jun 2022 09:33:00 +0200 Subject: [PATCH 193/198] Prepare next development version [skip ci] --- docs/_config.yml | 6 ++-- docs/pages/release_notes.md | 32 ++------------------- docs/pages/release_notes_old.md | 49 +++++++++++++++++++++++++++++++++ 3 files changed, 54 insertions(+), 33 deletions(-) diff --git a/docs/_config.yml b/docs/_config.yml index c4367fc735..a75b2e740a 100644 --- a/docs/_config.yml +++ b/docs/_config.yml @@ -1,9 +1,9 @@ repository: pmd/pmd pmd: - version: 6.47.0 - previous_version: 6.46.0 - date: 25-June-2022 + version: 6.48.0-SNAPSHOT + previous_version: 6.47.0 + date: 30-July-2022 release_type: minor # release types: major, minor, bugfix diff --git a/docs/pages/release_notes.md b/docs/pages/release_notes.md index a716be02e8..b8f8783555 100644 --- a/docs/pages/release_notes.md +++ b/docs/pages/release_notes.md @@ -12,41 +12,13 @@ This is a {{ site.pmd.release_type }} release. {% tocmaker is_release_notes_processor %} +### New and noteworthy + ### Fixed Issues -* core - * [#3999](https://github.com/pmd/pmd/issues/3999): \[cli] All files are analyzed despite parameter `--file-list` - * [#4009](https://github.com/pmd/pmd/issues/4009): \[core] Cannot build PMD with Temurin 17 -* java-bestpractices - * [#3824](https://github.com/pmd/pmd/issues/3824): \[java] UnusedPrivateField: Do not flag fields annotated with @Version - * [#3825](https://github.com/pmd/pmd/issues/3825): \[java] UnusedPrivateField: Do not flag fields annotated with @Id or @EmbeddedId -* java-design - * [#3823](https://github.com/pmd/pmd/issues/3823): \[java] ImmutableField: Do not flag fields in @Entity - * [#3981](https://github.com/pmd/pmd/issues/3981): \[java] ImmutableField reports fields annotated with @Value (Spring) - * [#3998](https://github.com/pmd/pmd/issues/3998): \[java] ImmutableField reports fields annotated with @Captor (Mockito) - * [#4004](https://github.com/pmd/pmd/issues/4004): \[java] ImmutableField reports fields annotated with @GwtMock (GwtMockito) and @Spy (Mockito) - * [#4008](https://github.com/pmd/pmd/issues/4008): \[java] ImmutableField not reporting fields that are only initialized in the declaration - * [#4011](https://github.com/pmd/pmd/issues/4011): \[java] ImmutableField: Do not flag fields annotated with @Inject - * [#4020](https://github.com/pmd/pmd/issues/4020): \[java] ImmutableField reports fields annotated with @FindBy and @FindBys (Selenium) -* java-errorprone - * [#3936](https://github.com/pmd/pmd/issues/3936): \[java] AvoidFieldNameMatchingMethodName should consider enum class - * [#3937](https://github.com/pmd/pmd/issues/3937): \[java] AvoidDuplicateLiterals - uncompilable test cases ### API Changes -No changes. - ### External Contributions -* [#3985](https://github.com/pmd/pmd/pull/3985): \[java] Fix false negative problem about Enum in AvoidFieldNameMatchingMethodName #3936 - [@Scrsloota](https://github.com/Scrsloota) -* [#3993](https://github.com/pmd/pmd/pull/3993): \[java] AvoidDuplicateLiterals - Add the method "buz" definition to test cases - [@dalizi007](https://github.com/dalizi007) -* [#4002](https://github.com/pmd/pmd/pull/4002): \[java] ImmutableField - Ignore fields annotated with @Value (Spring) or @Captor (Mockito) - [@jjlharrison](https://github.com/jjlharrison) -* [#4003](https://github.com/pmd/pmd/pull/4003): \[java] UnusedPrivateField - Ignore fields annotated with @Id/@EmbeddedId/@Version (JPA) or @Mock/@Spy/@MockBean (Mockito/Spring) - [@jjlharrison](https://github.com/jjlharrison) -* [#4006](https://github.com/pmd/pmd/pull/4006): \[doc] Fix eclipse plugin update site URL - [@shiomiyan](https://github.com/shiomiyan) -* [#4010](https://github.com/pmd/pmd/pull/4010): \[core] Bump kotlin to version 1.7.0 - [@maikelsteneker](https://github.com/maikelsteneker) - -### Stats -* 45 commits -* 23 closed tickets & PRs -* Days since last release: 27 {% endtocmaker %} diff --git a/docs/pages/release_notes_old.md b/docs/pages/release_notes_old.md index 0dc2d9c9f1..e5b53bc05d 100644 --- a/docs/pages/release_notes_old.md +++ b/docs/pages/release_notes_old.md @@ -5,6 +5,55 @@ permalink: pmd_release_notes_old.html Previous versions of PMD can be downloaded here: https://github.com/pmd/pmd/releases +## 25-June-2022 - 6.47.0 + +The PMD team is pleased to announce PMD 6.47.0. + +This is a minor release. + +### Table Of Contents + +* [Fixed Issues](#fixed-issues) +* [API Changes](#api-changes) +* [External Contributions](#external-contributions) +* [Stats](#stats) + +### Fixed Issues +* core + * [#3999](https://github.com/pmd/pmd/issues/3999): \[cli] All files are analyzed despite parameter `--file-list` + * [#4009](https://github.com/pmd/pmd/issues/4009): \[core] Cannot build PMD with Temurin 17 +* java-bestpractices + * [#3824](https://github.com/pmd/pmd/issues/3824): \[java] UnusedPrivateField: Do not flag fields annotated with @Version + * [#3825](https://github.com/pmd/pmd/issues/3825): \[java] UnusedPrivateField: Do not flag fields annotated with @Id or @EmbeddedId +* java-design + * [#3823](https://github.com/pmd/pmd/issues/3823): \[java] ImmutableField: Do not flag fields in @Entity + * [#3981](https://github.com/pmd/pmd/issues/3981): \[java] ImmutableField reports fields annotated with @Value (Spring) + * [#3998](https://github.com/pmd/pmd/issues/3998): \[java] ImmutableField reports fields annotated with @Captor (Mockito) + * [#4004](https://github.com/pmd/pmd/issues/4004): \[java] ImmutableField reports fields annotated with @GwtMock (GwtMockito) and @Spy (Mockito) + * [#4008](https://github.com/pmd/pmd/issues/4008): \[java] ImmutableField not reporting fields that are only initialized in the declaration + * [#4011](https://github.com/pmd/pmd/issues/4011): \[java] ImmutableField: Do not flag fields annotated with @Inject + * [#4020](https://github.com/pmd/pmd/issues/4020): \[java] ImmutableField reports fields annotated with @FindBy and @FindBys (Selenium) +* java-errorprone + * [#3936](https://github.com/pmd/pmd/issues/3936): \[java] AvoidFieldNameMatchingMethodName should consider enum class + * [#3937](https://github.com/pmd/pmd/issues/3937): \[java] AvoidDuplicateLiterals - uncompilable test cases + +### API Changes + +No changes. + +### External Contributions +* [#3985](https://github.com/pmd/pmd/pull/3985): \[java] Fix false negative problem about Enum in AvoidFieldNameMatchingMethodName #3936 - [@Scrsloota](https://github.com/Scrsloota) +* [#3993](https://github.com/pmd/pmd/pull/3993): \[java] AvoidDuplicateLiterals - Add the method "buz" definition to test cases - [@dalizi007](https://github.com/dalizi007) +* [#4002](https://github.com/pmd/pmd/pull/4002): \[java] ImmutableField - Ignore fields annotated with @Value (Spring) or @Captor (Mockito) - [@jjlharrison](https://github.com/jjlharrison) +* [#4003](https://github.com/pmd/pmd/pull/4003): \[java] UnusedPrivateField - Ignore fields annotated with @Id/@EmbeddedId/@Version (JPA) or @Mock/@Spy/@MockBean (Mockito/Spring) - [@jjlharrison](https://github.com/jjlharrison) +* [#4006](https://github.com/pmd/pmd/pull/4006): \[doc] Fix eclipse plugin update site URL - [@shiomiyan](https://github.com/shiomiyan) +* [#4010](https://github.com/pmd/pmd/pull/4010): \[core] Bump kotlin to version 1.7.0 - [@maikelsteneker](https://github.com/maikelsteneker) + +### Stats +* 45 commits +* 23 closed tickets & PRs +* Days since last release: 27 + ## 28-May-2022 - 6.46.0 The PMD team is pleased to announce PMD 6.46.0. From e98d2006df4930d2c9c5b94ac3ef91905cf9709e Mon Sep 17 00:00:00 2001 From: Andreas Dangel Date: Sat, 25 Jun 2022 11:39:17 +0200 Subject: [PATCH 194/198] Bump pmd from 6.46.0 to 6.47.0 --- pom.xml | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/pom.xml b/pom.xml index 4a7d758d4d..3291fc39d6 100644 --- a/pom.xml +++ b/pom.xml @@ -406,22 +406,22 @@ net.sourceforge.pmd pmd-core - 6.46.0 + 6.47.0 net.sourceforge.pmd pmd-java - 6.46.0 + 6.47.0 net.sourceforge.pmd pmd-jsp - 6.46.0 + 6.47.0 net.sourceforge.pmd pmd-javascript - 6.46.0 + 6.47.0 From 44cc3829a7d4428fc121dda4bc529cff9ef58d22 Mon Sep 17 00:00:00 2001 From: Andreas Dangel Date: Thu, 30 Jun 2022 14:53:31 +0200 Subject: [PATCH 195/198] [doc] Update release notes (#419, #3808) --- docs/pages/7_0_0_release_notes.md | 28 ++++++++++++++++--- .../main/resources/rulesets/releases/700.xml | 3 ++ 2 files changed, 27 insertions(+), 4 deletions(-) diff --git a/docs/pages/7_0_0_release_notes.md b/docs/pages/7_0_0_release_notes.md index cc3d9a0dc9..27b8b5a681 100644 --- a/docs/pages/7_0_0_release_notes.md +++ b/docs/pages/7_0_0_release_notes.md @@ -49,6 +49,24 @@ Given the full Antlr support, PMD now fully supports Swift. We are pleased to an * {% rule "swift/bestpractices/UnavailableFunction" %} (`swift-bestpractices`) flags any function throwing a `fatalError` not marked as `@available(*, unavailable)` to ensure no calls are actually performed in the codebase. +#### Kotlin support (experimental) + +PMD now supports Kotlin as an additional language for analyzing source code. It is based on +the official kotlin Antlr grammar. Java-based rules and XPath-based rules are supported. + +Kotlin support has **experimental** stability level, meaning no compatibility should +be expected between even incremental releases. Any functionality can be added, removed or changed without +warning. + +We are shipping the following rules: + +* {% rule kotlin/bestpractices/FunctionNameTooShort %} (`kotlin-bestpractices`) finds functions with a too short name. +* {% rule kotlin/errorprone/OverrideBothEqualsAndHashcode %} (`kotlin-errorprone`) finds classes with only either `equals` + or `hashCode` overridden, but not both. This leads to unexpected behavior once instances of such classes + are used in collections (Lists, HashMaps, ...). + +Contributors: [@jborgers](https://github.com/jborgers), [@stokpop](https://github.com/stokpop) + #### XPath 3.1 support Support for XPath versions 1.0, 1.0-compatibility was removed, support for XPath 2.0 is deprecated. The default (and only) supported XPath version is now XPath 3.1. This version of the XPath language is mostly identical to XPath 2.0. Notable changes: @@ -161,14 +179,14 @@ The following previously deprecated rules have been finally removed: ### Fixed Issues -* miscellaneous +* miscellaneous * [#896](https://github.com/pmd/pmd/issues/896): \[all] Use slf4j * [#1451](https://github.com/pmd/pmd/issues/1451): \[core] RulesetFactoryCompatibility stores the whole ruleset file in memory as a string -* cli +* cli * [#3828](https://github.com/pmd/pmd/issues/3828): \[core] Progress reporting -* apex-design +* apex-design * [#2667](https://github.com/pmd/pmd/issues/2667): \[apex] Integrate nawforce/ApexLink to build robust Unused rule -* java-bestpractices +* java-bestpractices * [#342](https://github.com/pmd/pmd/issues/342): \[java] AccessorMethodGeneration: Name clash with another public field not properly handled * [#755](https://github.com/pmd/pmd/issues/755): \[java] AccessorClassGeneration false positive for private constructors * [#770](https://github.com/pmd/pmd/issues/770): \[java] UnusedPrivateMethod yields false positive for counter-variant arguments @@ -243,6 +261,8 @@ The following previously deprecated rules have been finally removed: * java-performance * [#1224](https://github.com/pmd/pmd/issues/1224): \[java] InefficientEmptyStringCheck false negative in anonymous class * [#2712](https://github.com/pmd/pmd/issues/2712): \[java] SimplifyStartsWith false-positive with AssertJ +* kotlin + * [#419](https://github.com/pmd/pmd/issues/419): \[kotlin] Add support for Kotlin ### API Changes diff --git a/pmd-core/src/main/resources/rulesets/releases/700.xml b/pmd-core/src/main/resources/rulesets/releases/700.xml index 75821d4a05..61d49236ca 100644 --- a/pmd-core/src/main/resources/rulesets/releases/700.xml +++ b/pmd-core/src/main/resources/rulesets/releases/700.xml @@ -12,5 +12,8 @@ This ruleset contains links to rules that are new in PMD v7.0.0 + + + From bd1f7271ce7a3269b3144103626d175d070ec1ac Mon Sep 17 00:00:00 2001 From: Andreas Dangel Date: Thu, 30 Jun 2022 15:03:54 +0200 Subject: [PATCH 196/198] [doc] Update swift rules and contributors --- docs/pages/7_0_0_release_notes.md | 2 ++ pmd-core/src/main/resources/rulesets/releases/700.xml | 5 +++++ 2 files changed, 7 insertions(+) diff --git a/docs/pages/7_0_0_release_notes.md b/docs/pages/7_0_0_release_notes.md index 27b8b5a681..be94436737 100644 --- a/docs/pages/7_0_0_release_notes.md +++ b/docs/pages/7_0_0_release_notes.md @@ -49,6 +49,8 @@ Given the full Antlr support, PMD now fully supports Swift. We are pleased to an * {% rule "swift/bestpractices/UnavailableFunction" %} (`swift-bestpractices`) flags any function throwing a `fatalError` not marked as `@available(*, unavailable)` to ensure no calls are actually performed in the codebase. +Contributors: [@lsoncini](https://github.com/lsoncini), [@matifraga](https://github.com/matifraga), [@tomidelucca](https://github.com/tomidelucca) + #### Kotlin support (experimental) PMD now supports Kotlin as an additional language for analyzing source code. It is based on diff --git a/pmd-core/src/main/resources/rulesets/releases/700.xml b/pmd-core/src/main/resources/rulesets/releases/700.xml index 61d49236ca..4646553133 100644 --- a/pmd-core/src/main/resources/rulesets/releases/700.xml +++ b/pmd-core/src/main/resources/rulesets/releases/700.xml @@ -15,5 +15,10 @@ This ruleset contains links to rules that are new in PMD v7.0.0 + + + + + From b38c8969acadaa59be60025c174d01cd0d4a9b66 Mon Sep 17 00:00:00 2001 From: Andreas Dangel Date: Thu, 30 Jun 2022 15:27:09 +0200 Subject: [PATCH 197/198] [kotlin] Clarify license for grammar --- .../sourceforge/pmd/lang/kotlin/ast/Kotlin.g4 | 1 + .../pmd/lang/kotlin/ast/KotlinLexer.g4 | 1 + .../pmd/lang/kotlin/ast/KotlinLexer.tokens | 1 + .../sourceforge/pmd/lang/kotlin/ast/README.md | 29 +++++++++++++++++-- .../pmd/lang/kotlin/ast/UnicodeClasses.g4 | 1 + .../pmd/lang/kotlin/ast/UnicodeClasses.tokens | 1 + 6 files changed, 32 insertions(+), 2 deletions(-) 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 99aecafb6e..c905ec427d 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 @@ -1,3 +1,4 @@ +// SPDX-License-Identifier: Apache-2.0 /** * Kotlin syntax grammar in ANTLR4 notation */ 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 418a5e5b01..2a33305a1d 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 @@ -1,3 +1,4 @@ +// SPDX-License-Identifier: Apache-2.0 /** * Kotlin lexical grammar in ANTLR4 notation */ 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..59c6001e21 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 @@ -1,3 +1,4 @@ +// SPDX-License-Identifier: Apache-2.0 ShebangLine=1 DelimitedComment=2 LineComment=3 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 8965301371..84ef104798 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 @@ -1,8 +1,33 @@ # Kotlin Grammar -Release: -Source: +The grammar files for Kotlin are taken from , released under the +Apache License, Version 2.0: +``` +Copyright 2000-2020 JetBrains s.r.o. and Kotlin Programming Language contributors. + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. +``` + +The grammar files still use the Apache License, but are slightly modified. +All other files in this PMD module are licensed under BSD. + +## Currently used version + +* Release: +* Source: + +### Modifications Some modifications are made in KotlinParser.g4: 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 537284804c..71a0b720ae 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 @@ -1,3 +1,4 @@ +// SPDX-License-Identifier: Apache-2.0 /** * Kotlin lexical grammar in ANTLR4 notation (Unicode classes) * diff --git a/pmd-kotlin/src/main/antlr4/net/sourceforge/pmd/lang/kotlin/ast/UnicodeClasses.tokens b/pmd-kotlin/src/main/antlr4/net/sourceforge/pmd/lang/kotlin/ast/UnicodeClasses.tokens index bd91da7e6b..e5c386828a 100644 --- a/pmd-kotlin/src/main/antlr4/net/sourceforge/pmd/lang/kotlin/ast/UnicodeClasses.tokens +++ b/pmd-kotlin/src/main/antlr4/net/sourceforge/pmd/lang/kotlin/ast/UnicodeClasses.tokens @@ -1,3 +1,4 @@ +// SPDX-License-Identifier: Apache-2.0 UNICODE_CLASS_LL=1 UNICODE_CLASS_LM=2 UNICODE_CLASS_LO=3 From 9d1782d9f4cc7de4fb89962e77a57874f7dde7f9 Mon Sep 17 00:00:00 2001 From: Andreas Dangel Date: Thu, 30 Jun 2022 15:44:24 +0200 Subject: [PATCH 198/198] [kotlin] remove spdx-ids from tokens files --- .../net/sourceforge/pmd/lang/kotlin/ast/KotlinLexer.tokens | 1 - .../net/sourceforge/pmd/lang/kotlin/ast/UnicodeClasses.tokens | 1 - 2 files changed, 2 deletions(-) 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 59c6001e21..a207d69c19 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 @@ -1,4 +1,3 @@ -// SPDX-License-Identifier: Apache-2.0 ShebangLine=1 DelimitedComment=2 LineComment=3 diff --git a/pmd-kotlin/src/main/antlr4/net/sourceforge/pmd/lang/kotlin/ast/UnicodeClasses.tokens b/pmd-kotlin/src/main/antlr4/net/sourceforge/pmd/lang/kotlin/ast/UnicodeClasses.tokens index e5c386828a..bd91da7e6b 100644 --- a/pmd-kotlin/src/main/antlr4/net/sourceforge/pmd/lang/kotlin/ast/UnicodeClasses.tokens +++ b/pmd-kotlin/src/main/antlr4/net/sourceforge/pmd/lang/kotlin/ast/UnicodeClasses.tokens @@ -1,4 +1,3 @@ -// SPDX-License-Identifier: Apache-2.0 UNICODE_CLASS_LL=1 UNICODE_CLASS_LM=2 UNICODE_CLASS_LO=3