Merge branch 'master' into issue-4349-cleanup-deprecations

This commit is contained in:
Andreas Dangel
2024-02-08 18:23:41 +01:00
416 changed files with 2924 additions and 4282 deletions

View File

@ -15,9 +15,6 @@ options {
PARSER_BEGIN(Ecmascript5ParserImpl)
package net.sourceforge.pmd.lang.ecmascript5.ast;
import net.sourceforge.pmd.lang.ast.impl.javacc.CharStream;
import net.sourceforge.pmd.lang.ast.TokenMgrError;
public class Ecmascript5ParserImpl {
}

View File

@ -4,11 +4,11 @@
package net.sourceforge.pmd.lang.ecmascript;
import net.sourceforge.pmd.cpd.Tokenizer;
import net.sourceforge.pmd.cpd.CpdLexer;
import net.sourceforge.pmd.lang.LanguagePropertyBundle;
import net.sourceforge.pmd.lang.LanguageRegistry;
import net.sourceforge.pmd.lang.ecmascript.ast.EcmascriptParser;
import net.sourceforge.pmd.lang.ecmascript.cpd.EcmascriptTokenizer;
import net.sourceforge.pmd.lang.ecmascript.cpd.EcmascriptCpdLexer;
import net.sourceforge.pmd.lang.impl.SimpleLanguageModuleBase;
/**
@ -34,7 +34,7 @@ public class EcmascriptLanguageModule extends SimpleLanguageModuleBase {
}
@Override
public Tokenizer createCpdTokenizer(LanguagePropertyBundle bundle) {
return new EcmascriptTokenizer();
public CpdLexer createCpdLexer(LanguagePropertyBundle bundle) {
return new EcmascriptCpdLexer();
}
}

View File

@ -12,7 +12,6 @@ public final class ASTBigIntLiteral extends AbstractEcmascriptNode<BigIntLiteral
ASTBigIntLiteral(BigIntLiteral bigIntLiteral) {
super(bigIntLiteral);
super.setImage(bigIntLiteral.getValue());
}
@Override
@ -23,4 +22,8 @@ public final class ASTBigIntLiteral extends AbstractEcmascriptNode<BigIntLiteral
public BigInteger getNumber() {
return node.getBigInt();
}
public String getValue() {
return node.getValue();
}
}

View File

@ -9,7 +9,6 @@ import org.mozilla.javascript.ast.BreakStatement;
public final class ASTBreakStatement extends AbstractEcmascriptNode<BreakStatement> {
ASTBreakStatement(BreakStatement breakStatement) {
super(breakStatement);
super.setImage(breakStatement.getBreakLabel() != null ? breakStatement.getBreakLabel().getIdentifier() : null);
}
@Override

View File

@ -9,7 +9,6 @@ import org.mozilla.javascript.ast.ContinueStatement;
public final class ASTContinueStatement extends AbstractEcmascriptNode<ContinueStatement> {
ASTContinueStatement(ContinueStatement continueStatement) {
super(continueStatement);
super.setImage(continueStatement.getLabel() != null ? continueStatement.getLabel().getIdentifier() : null);
}
@Override

View File

@ -10,7 +10,6 @@ public final class ASTErrorNode extends AbstractEcmascriptNode<ErrorNode> {
ASTErrorNode(ErrorNode errorNode) {
super(errorNode);
super.setImage(errorNode.getMessage());
}
@Override

View File

@ -9,7 +9,6 @@ import org.mozilla.javascript.ast.FunctionNode;
public final class ASTFunctionNode extends AbstractEcmascriptNode<FunctionNode> {
ASTFunctionNode(FunctionNode functionNode) {
super(functionNode);
super.setImage(functionNode.getName());
}
@Override

View File

@ -12,7 +12,6 @@ import org.mozilla.javascript.ast.KeywordLiteral;
public final class ASTKeywordLiteral extends AbstractEcmascriptNode<KeywordLiteral> {
ASTKeywordLiteral(KeywordLiteral keywordLiteral) {
super(keywordLiteral);
super.setImage(Token.typeToName(keywordLiteral.getType()).toLowerCase(Locale.ROOT));
}
@Override
@ -20,6 +19,10 @@ public final class ASTKeywordLiteral extends AbstractEcmascriptNode<KeywordLiter
return visitor.visit(this, data);
}
public String getLiteral() {
return Token.typeToName(node.getType()).toLowerCase(Locale.ROOT);
}
public boolean isBoolean() {
return node.isBooleanLiteral();
}

View File

@ -9,11 +9,14 @@ import org.mozilla.javascript.ast.Label;
public final class ASTLabel extends AbstractEcmascriptNode<Label> {
ASTLabel(Label label) {
super(label);
super.setImage(label.getName());
}
@Override
protected <P, R> R acceptJsVisitor(EcmascriptVisitor<? super P, ? extends R> visitor, P data) {
return visitor.visit(this, data);
}
public String getName() {
return node.getName();
}
}

View File

@ -9,7 +9,6 @@ import org.mozilla.javascript.ast.Name;
public final class ASTName extends AbstractEcmascriptNode<Name> {
ASTName(Name name) {
super(name);
super.setImage(name.getIdentifier());
}
@Override

View File

@ -9,7 +9,6 @@ import org.mozilla.javascript.ast.NumberLiteral;
public final class ASTNumberLiteral extends AbstractEcmascriptNode<NumberLiteral> {
ASTNumberLiteral(NumberLiteral numberLiteral) {
super(numberLiteral);
super.setImage(numberLiteral.getValue());
}
@Override
@ -18,7 +17,7 @@ public final class ASTNumberLiteral extends AbstractEcmascriptNode<NumberLiteral
}
public String getNormalizedImage() {
String image = getImage();
String image = getValue();
image = image.replaceAll("_", "");
image = normalizeHexIntegerLiteral(image);
image = normalizeBinaryLiteral(image);
@ -54,4 +53,8 @@ public final class ASTNumberLiteral extends AbstractEcmascriptNode<NumberLiteral
public double getNumber() {
return node.getNumber();
}
public String getValue() {
return node.getValue();
}
}

View File

@ -8,8 +8,7 @@ import org.mozilla.javascript.ast.PropertyGet;
public final class ASTPropertyGet extends AbstractInfixEcmascriptNode<PropertyGet> {
ASTPropertyGet(PropertyGet propertyGet) {
super(propertyGet, false);
super.setImage(".");
super(propertyGet);
}
@Override

View File

@ -9,7 +9,6 @@ import org.mozilla.javascript.ast.RegExpLiteral;
public final class ASTRegExpLiteral extends AbstractEcmascriptNode<RegExpLiteral> {
ASTRegExpLiteral(RegExpLiteral regExpLiteral) {
super(regExpLiteral);
super.setImage(regExpLiteral.getValue());
}
@Override
@ -20,4 +19,8 @@ public final class ASTRegExpLiteral extends AbstractEcmascriptNode<RegExpLiteral
public String getFlags() {
return node.getFlags();
}
public String getValue() {
return node.getValue();
}
}

View File

@ -9,7 +9,6 @@ import org.mozilla.javascript.ast.StringLiteral;
public final class ASTStringLiteral extends AbstractEcmascriptNode<StringLiteral> {
ASTStringLiteral(StringLiteral stringLiteral) {
super(stringLiteral);
super.setImage(stringLiteral.getValue());
}
@Override
@ -28,4 +27,8 @@ public final class ASTStringLiteral extends AbstractEcmascriptNode<StringLiteral
public boolean isDoubleQuoted() {
return '"' == getQuoteCharacter();
}
public String getValue() {
return node.getValue();
}
}

View File

@ -11,7 +11,6 @@ import org.mozilla.javascript.ast.UnaryExpression;
public final class ASTUnaryExpression extends AbstractEcmascriptNode<UnaryExpression> {
ASTUnaryExpression(UnaryExpression unaryExpression) {
super(unaryExpression);
super.setImage(AstRoot.operatorToString(unaryExpression.getOperator()));
}
@Override
@ -30,4 +29,8 @@ public final class ASTUnaryExpression extends AbstractEcmascriptNode<UnaryExpres
public boolean isPostfix() {
return node.getOperator() == Token.INC || node.getOperator() == Token.DEC;
}
public String getOperator() {
return AstRoot.operatorToString(node.getOperator());
}
}

View File

@ -5,14 +5,12 @@
package net.sourceforge.pmd.lang.ecmascript.ast;
import org.mozilla.javascript.ast.AstNode;
import org.mozilla.javascript.ast.AstRoot;
import org.mozilla.javascript.ast.UpdateExpression;
public final class ASTUpdateExpression extends AbstractEcmascriptNode<UpdateExpression> {
ASTUpdateExpression(UpdateExpression updateExpression) {
super(updateExpression);
super.setImage(AstRoot.operatorToString(updateExpression.getOperator()));
}
@Override

View File

@ -4,15 +4,11 @@
package net.sourceforge.pmd.lang.ecmascript.ast;
import java.util.Locale;
import org.mozilla.javascript.Token;
import org.mozilla.javascript.ast.VariableDeclaration;
public final class ASTVariableDeclaration extends AbstractEcmascriptNode<VariableDeclaration> {
ASTVariableDeclaration(VariableDeclaration variableDeclaration) {
super(variableDeclaration);
super.setImage(Token.typeToName(variableDeclaration.getType()).toLowerCase(Locale.ROOT));
}
@Override

View File

@ -4,22 +4,21 @@
package net.sourceforge.pmd.lang.ecmascript.ast;
import org.mozilla.javascript.ast.Name;
import org.mozilla.javascript.ast.XmlPropRef;
public final class ASTXmlPropRef extends AbstractEcmascriptNode<XmlPropRef> {
ASTXmlPropRef(XmlPropRef xmlPropRef) {
super(xmlPropRef);
Name propName = xmlPropRef.getPropName();
if (propName != null) {
super.setImage(propName.getIdentifier());
}
}
@Override
protected <P, R> R acceptJsVisitor(EcmascriptVisitor<? super P, ? extends R> visitor, P data) {
return visitor.visit(this, data);
}
public ASTName getPropName() {
// first ASTName would be namespace
return children(ASTName.class).last();
}
}

View File

@ -9,11 +9,14 @@ import org.mozilla.javascript.ast.XmlString;
public final class ASTXmlString extends AbstractEcmascriptNode<XmlString> {
ASTXmlString(XmlString xmlString) {
super(xmlString);
super.setImage(xmlString.getXml());
}
@Override
protected <P, R> R acceptJsVisitor(EcmascriptVisitor<? super P, ? extends R> visitor, P data) {
return visitor.visit(this, data);
}
public String getXml() {
return node.getXml();
}
}

View File

@ -13,7 +13,6 @@ import net.sourceforge.pmd.lang.document.TextRegion;
abstract class AbstractEcmascriptNode<T extends AstNode> extends AbstractNode<AbstractEcmascriptNode<?>, EcmascriptNode<?>> implements EcmascriptNode<T> {
protected final T node;
private String image;
AbstractEcmascriptNode(T node) {
this.node = node;
@ -24,15 +23,6 @@ abstract class AbstractEcmascriptNode<T extends AstNode> extends AbstractNode<Ab
super.addChild(child, index);
}
@Override
public String getImage() {
return image;
}
protected void setImage(String image) {
this.image = image;
}
@Override
public TextRegion getTextRegion() {
return TextRegion.fromOffsetLength(node.getAbsolutePosition(), node.getLength());

View File

@ -11,18 +11,17 @@ import org.mozilla.javascript.ast.InfixExpression;
abstract class AbstractInfixEcmascriptNode<T extends InfixExpression> extends AbstractEcmascriptNode<T> {
AbstractInfixEcmascriptNode(T infixExpression) {
this(infixExpression, true);
super(infixExpression);
}
AbstractInfixEcmascriptNode(T infixExpression, boolean setImage) {
super(infixExpression);
if (setImage) {
if (infixExpression.getOperator() == Token.ASSIGN_BITXOR) {
super.setImage("^=");
} else if (infixExpression.getOperator() != Token.METHOD) {
super.setImage(AstRoot.operatorToString(infixExpression.getOperator()));
}
public String getOperator() {
int operator = node.getOperator();
if (operator == Token.ASSIGN_BITXOR) {
return "^=";
} else if (operator != Token.METHOD) {
return AstRoot.operatorToString(operator);
}
return "";
}
public EcmascriptNode<?> getLeft() {

View File

@ -4,7 +4,7 @@
package net.sourceforge.pmd.lang.ecmascript.cpd;
import net.sourceforge.pmd.cpd.impl.JavaCCTokenizer;
import net.sourceforge.pmd.cpd.impl.JavaccCpdLexer;
import net.sourceforge.pmd.lang.TokenManager;
import net.sourceforge.pmd.lang.ast.impl.javacc.CharStream;
import net.sourceforge.pmd.lang.ast.impl.javacc.JavaccToken;
@ -13,8 +13,10 @@ import net.sourceforge.pmd.lang.ecmascript5.ast.Ecmascript5TokenKinds;
/**
* The Ecmascript Tokenizer
*
* <p>Note: This class has been called EcmascriptTokenizer in PMD 6</p>.
*/
public class EcmascriptTokenizer extends JavaCCTokenizer {
public class EcmascriptCpdLexer extends JavaccCpdLexer {
@Override
protected TokenManager<JavaccToken> makeLexerImpl(TextDocument doc) {

View File

@ -4,11 +4,11 @@
package net.sourceforge.pmd.lang.typescript;
import net.sourceforge.pmd.cpd.Tokenizer;
import net.sourceforge.pmd.cpd.CpdLexer;
import net.sourceforge.pmd.lang.LanguagePropertyBundle;
import net.sourceforge.pmd.lang.LanguageRegistry;
import net.sourceforge.pmd.lang.impl.CpdOnlyLanguageModuleBase;
import net.sourceforge.pmd.lang.typescript.cpd.TypeScriptTokenizer;
import net.sourceforge.pmd.lang.typescript.cpd.TypeScriptCpdLexer;
/**
* @author pguyot@kallisys.net
@ -27,7 +27,7 @@ public class TsLanguageModule extends CpdOnlyLanguageModuleBase {
}
@Override
public Tokenizer createCpdTokenizer(LanguagePropertyBundle bundle) {
return new TypeScriptTokenizer();
public CpdLexer createCpdLexer(LanguagePropertyBundle bundle) {
return new TypeScriptCpdLexer();
}
}

View File

@ -7,10 +7,10 @@ package net.sourceforge.pmd.lang.typescript.cpd;
import org.antlr.v4.runtime.CharStream;
import org.antlr.v4.runtime.Lexer;
import net.sourceforge.pmd.cpd.impl.AntlrTokenizer;
import net.sourceforge.pmd.cpd.impl.AntlrCpdLexer;
import net.sourceforge.pmd.lang.typescript.ast.TypeScriptLexer;
public class TypeScriptTokenizer extends AntlrTokenizer {
public class TypeScriptCpdLexer extends AntlrCpdLexer {
@Override
protected Lexer getLexerForSource(CharStream charStream) {
return new TypeScriptLexer(charStream);

View File

@ -176,7 +176,7 @@ See also: [parseInt()](https://developer.mozilla.org/en-US/docs/Web/JavaScript/R
<value>
<![CDATA[
//FunctionCall/Name[
@Image = 'parseInt'
@Identifier = 'parseInt'
and
count(../*) < 3
]

View File

@ -61,9 +61,9 @@ same type. The === operator avoids the casting.
<value>
<![CDATA[
//InfixExpression[
(@Image = "==" or @Image = "!=")
(@Operator = '==' or @Operator = '!=')
and
(KeywordLiteral[@Image='true' or @Image = 'false'] or NumberLiteral)
(KeywordLiteral[@Literal = 'true' or @Literal = 'false'] or NumberLiteral)
]
]]>
</value>

View File

@ -1,21 +0,0 @@
<?xml version="1.0"?>
<ruleset name="Basic Ecmascript"
xmlns="http://pmd.sourceforge.net/ruleset/2.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://pmd.sourceforge.net/ruleset/2.0.0 https://pmd.sourceforge.io/ruleset_2_0_0.xsd">
<description>Rules concerning basic ECMAScript guidelines.</description>
<rule ref="category/ecmascript/codestyle.xml/AssignmentInOperand" deprecated="true" />
<rule ref="category/ecmascript/codestyle.xml/UnreachableCode" deprecated="true" />
<rule ref="category/ecmascript/errorprone.xml/AvoidTrailingComma" deprecated="true" />"
<rule ref="category/ecmascript/errorprone.xml/EqualComparison" deprecated="true" />
<rule ref="category/ecmascript/errorprone.xml/InnaccurateNumericLiteral" deprecated="true" />
<rule ref="category/ecmascript/bestpractices.xml/ConsistentReturn" deprecated="true" />
<rule ref="category/ecmascript/bestpractices.xml/GlobalVariable" deprecated="true" />
<rule ref="category/ecmascript/bestpractices.xml/ScopeForInVariable" deprecated="true" />
<rule ref="category/ecmascript/bestpractices.xml/UseBaseWithParseInt" deprecated="true" />
</ruleset>

View File

@ -1,16 +0,0 @@
<?xml version="1.0"?>
<ruleset name="Braces"
xmlns="http://pmd.sourceforge.net/ruleset/2.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://pmd.sourceforge.net/ruleset/2.0.0 https://pmd.sourceforge.io/ruleset_2_0_0.xsd">
<description>
The Braces Ruleset contains a collection of braces rules.
</description>
<rule ref="category/ecmascript/codestyle.xml/ForLoopsMustUseBraces" deprecated="true" />
<rule ref="category/ecmascript/codestyle.xml/IfElseStmtsMustUseBraces" deprecated="true" />
<rule ref="category/ecmascript/codestyle.xml/IfStmtsMustUseBraces" deprecated="true" />
<rule ref="category/ecmascript/codestyle.xml/WhileLoopsMustUseBraces" deprecated="true" />
</ruleset>

View File

@ -1,15 +0,0 @@
<?xml version="1.0"?>
<ruleset name="Controversial Ecmascript"
xmlns="http://pmd.sourceforge.net/ruleset/2.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://pmd.sourceforge.net/ruleset/2.0.0 https://pmd.sourceforge.io/ruleset_2_0_0.xsd">
<description>
The Controversial ruleset contains rules that, for whatever reason, are considered controversial.
They are held here to allow people to include them as they see fit within their custom rulesets.
</description>
<rule ref="category/ecmascript/bestpractices.xml/AvoidWithStatement" deprecated="true" />
</ruleset>

View File

@ -1,17 +0,0 @@
#
# BSD-style license; for more info see http://pmd.sourceforge.net/license.html
#
rulesets.filenames=\
category/ecmascript/bestpractices.xml,\
category/ecmascript/codestyle.xml,\
category/ecmascript/errorprone.xml
#
#empty categories:
#
#category/ecmascript/design.xml,
#category/ecmascript/documentation.xml,
#category/ecmascript/multithreading.xml,
#category/ecmascript/performance.xml,
#category/ecmascript/security.xml,

Some files were not shown because too many files have changed in this diff Show More