diff --git a/.all-contributorsrc b/.all-contributorsrc index d90beb1366..2542025f73 100644 --- a/.all-contributorsrc +++ b/.all-contributorsrc @@ -7847,6 +7847,15 @@ "contributions": [ "code" ] + }, + { + "login": "jdupak", + "name": "Jakub Dupak", + "avatar_url": "https://avatars.githubusercontent.com/u/22683640?v=4", + "profile": "https://github.com/jdupak", + "contributions": [ + "code" + ] } ], "contributorsPerLine": 7, diff --git a/docs/pages/pmd/userdocs/cpd/cpd.md b/docs/pages/pmd/userdocs/cpd/cpd.md index 1bf2954c18..0580732bb4 100644 --- a/docs/pages/pmd/userdocs/cpd/cpd.md +++ b/docs/pages/pmd/userdocs/cpd/cpd.md @@ -163,7 +163,7 @@ exactly identical. {% include custom/cli_option_row.html options="--ignore-literals" description="Ignore literal values such as numbers and strings when comparing text. By default, literals are not ignored." - languages="Java" + languages="Java, C++" %} {% include custom/cli_option_row.html options="--ignore-literal-sequences" description="Ignore sequences of literals such as list initializers. @@ -173,7 +173,7 @@ exactly identical. {% include custom/cli_option_row.html options="--ignore-identifiers" description="Ignore names of classes, methods, variables, constants, etc. when comparing text. By default, identifier names are not ignored." - languages="Java" + languages="Java, C++" %} {% include custom/cli_option_row.html options="--ignore-annotations" description="Ignore language annotations (Java) or attributes (C#) when comparing text. diff --git a/docs/pages/release_notes.md b/docs/pages/release_notes.md index e3abda244a..8adaca9a57 100644 --- a/docs/pages/release_notes.md +++ b/docs/pages/release_notes.md @@ -14,8 +14,19 @@ This is a {{ site.pmd.release_type }} release. ### 🚀 New and noteworthy +#### CPD can now ignore literals and identifiers in C++ code + +When searching for duplicated code in C++ differences in literals or identifiers can be +ignored now (like in Java). This can be enabled via the command line options `--ignore-literal` +and `--ignore-identifiers`. +See [PR #5040](https://github.com/pmd/pmd/pull/5040) for details. + ### 🌟 Rule Changes +#### Changed Rules +* {% rule java/bestpractices/UnitTestShouldUseAfterAnnotation %} (Java Best Practices) now also considers JUnit 5 and TestNG tests. +* {% rule java/bestpractices/UnitTestShouldUseBeforeAnnotation %} (Java Best Practices) now also considers JUnit 5 and TestNG tests. + #### Renamed Rules * Several rules for unit testing have been renamed to better reflect their actual scope. Lots of them were called after JUnit / JUnit 4, even when they applied to JUnit 5 and / or TestNG. @@ -36,7 +47,10 @@ The old rule names still work but are deprecated. * [#4813](https://github.com/pmd/pmd/issues/4813): \[java] SwitchStmtsShouldHaveDefault false positive with pattern matching * java-codestyle * [#5253](https://github.com/pmd/pmd/issues/5253): \[java] BooleanGetMethodName: False-negatives with `Boolean` wrapper +* java-design + * [#5030](https://github.com/pmd/pmd/issues/5030): \[java] SwitchDensity false positive with pattern matching * java-errorprone + * [#3362](https://github.com/pmd/pmd/issues/3362): \[java] ImplicitSwitchFallThrough should consider switch expressions * [#5067](https://github.com/pmd/pmd/issues/5067): \[java] CloseResource: False positive for FileSystems.getDefault() ### 🚨 API Changes @@ -51,8 +65,12 @@ The old rule names still work but are deprecated. ### ✨ Merged pull requests * [#4965](https://github.com/pmd/pmd/pull/4965): Fix #4532: \[java] Rename JUnit rules with overly restrictive names - [Juan Martín Sotuyo Dodero](https://github.com/jsotuyod) (@jsotuyod) +* [#5040](https://github.com/pmd/pmd/pull/5040): \[cpp] Ignore literals and ignore identifiers capability to C++ CPD - [Jakub Dupak](https://github.com/jdupak) (@jdupak) * [#5225](https://github.com/pmd/pmd/pull/5225): Fix #5067: \[java] CloseResource: False positive for FileSystems.getDefault() - [Lukas Gräf](https://github.com/lukasgraef) (@lukasgraef) * [#5241](https://github.com/pmd/pmd/pull/5241): Ignore javacc code in coverage report - [Juan Martín Sotuyo Dodero](https://github.com/jsotuyod) (@jsotuyod) +* [#5245](https://github.com/pmd/pmd/pull/5245): \[java] Improve UnitTestShouldUse{After,Before}Annotation rules to support JUnit5 and TestNG - [Andreas Dangel](https://github.com/adangel) (@adangel) +* [#5247](https://github.com/pmd/pmd/pull/5247): Fix #5030: \[java] SwitchDensity false positive with pattern matching - [Andreas Dangel](https://github.com/adangel) (@adangel) +* [#5248](https://github.com/pmd/pmd/pull/5248): Fix #3362: \[java] ImplicitSwitchFallThrough should consider switch expressions - [Andreas Dangel](https://github.com/adangel) (@adangel) * [#5252](https://github.com/pmd/pmd/pull/5252): Fix #4813: \[java] SwitchStmtsShouldHaveDefault false positive with pattern matching - [Andreas Dangel](https://github.com/adangel) (@adangel) * [#5258](https://github.com/pmd/pmd/pull/5258): Ignore generated antlr classes in coverage reports - [Juan Martín Sotuyo Dodero](https://github.com/jsotuyod) (@jsotuyod) * [#5264](https://github.com/pmd/pmd/pull/5264): Fix #5261: \[java] Fix NPE with empty pattern list - [Clément Fournier](https://github.com/oowekyala) (@oowekyala) diff --git a/pmd-cpp/src/main/java/net/sourceforge/pmd/lang/cpp/CppLanguageModule.java b/pmd-cpp/src/main/java/net/sourceforge/pmd/lang/cpp/CppLanguageModule.java index 520fc7327c..5312f8abaf 100644 --- a/pmd-cpp/src/main/java/net/sourceforge/pmd/lang/cpp/CppLanguageModule.java +++ b/pmd-cpp/src/main/java/net/sourceforge/pmd/lang/cpp/CppLanguageModule.java @@ -47,6 +47,8 @@ public class CppLanguageModule extends CpdOnlyLanguageModuleBase { LanguagePropertyBundle bundle = super.newPropertyBundle(); bundle.definePropertyDescriptor(CpdLanguageProperties.CPD_IGNORE_LITERAL_SEQUENCES); bundle.definePropertyDescriptor(CpdLanguageProperties.CPD_IGNORE_LITERAL_AND_IDENTIFIER_SEQUENCES); + bundle.definePropertyDescriptor(CpdLanguageProperties.CPD_ANONYMIZE_IDENTIFIERS); + bundle.definePropertyDescriptor(CpdLanguageProperties.CPD_ANONYMIZE_LITERALS); bundle.definePropertyDescriptor(CPD_SKIP_BLOCKS); return bundle; } diff --git a/pmd-cpp/src/main/java/net/sourceforge/pmd/lang/cpp/cpd/CppCpdLexer.java b/pmd-cpp/src/main/java/net/sourceforge/pmd/lang/cpp/cpd/CppCpdLexer.java index 5d0e423a51..69287747ba 100644 --- a/pmd-cpp/src/main/java/net/sourceforge/pmd/lang/cpp/cpd/CppCpdLexer.java +++ b/pmd-cpp/src/main/java/net/sourceforge/pmd/lang/cpp/cpd/CppCpdLexer.java @@ -9,8 +9,9 @@ import java.util.regex.Pattern; import org.apache.commons.lang3.StringUtils; import net.sourceforge.pmd.cpd.CpdLanguageProperties; -import net.sourceforge.pmd.cpd.impl.CpdLexerBase; +import net.sourceforge.pmd.cpd.TokenFactory; import net.sourceforge.pmd.cpd.impl.JavaCCTokenFilter; +import net.sourceforge.pmd.cpd.impl.JavaccCpdLexer; import net.sourceforge.pmd.lang.LanguagePropertyBundle; import net.sourceforge.pmd.lang.TokenManager; import net.sourceforge.pmd.lang.ast.impl.javacc.CharStream; @@ -26,17 +27,21 @@ import net.sourceforge.pmd.lang.document.TextDocument; * *

Note: This class has been called CPPTokenizer in PMD 6

. */ -public class CppCpdLexer extends CpdLexerBase { +public class CppCpdLexer extends JavaccCpdLexer { private boolean skipBlocks; private Pattern skipBlocksStart; private Pattern skipBlocksEnd; private final boolean ignoreIdentifierAndLiteralSeqences; private final boolean ignoreLiteralSequences; + private final boolean ignoreLiterals; + private final boolean ignoreIdentifiers; public CppCpdLexer(LanguagePropertyBundle cppProperties) { ignoreLiteralSequences = cppProperties.getProperty(CpdLanguageProperties.CPD_IGNORE_LITERAL_SEQUENCES); ignoreIdentifierAndLiteralSeqences = cppProperties.getProperty(CpdLanguageProperties.CPD_IGNORE_LITERAL_AND_IDENTIFIER_SEQUENCES); + ignoreLiterals = cppProperties.getProperty(CpdLanguageProperties.CPD_ANONYMIZE_LITERALS); + ignoreIdentifiers = cppProperties.getProperty(CpdLanguageProperties.CPD_ANONYMIZE_IDENTIFIERS); String skipBlocksPattern = cppProperties.getProperty(CppLanguageModule.CPD_SKIP_BLOCKS); if (StringUtils.isNotBlank(skipBlocksPattern)) { skipBlocks = true; @@ -73,6 +78,23 @@ public class CppCpdLexer extends CpdLexerBase { return new CppTokenFilter(tokenManager, ignoreLiteralSequences, ignoreIdentifierAndLiteralSeqences); } + @Override + protected void processToken(TokenFactory tokenEntries, JavaccToken currentToken) { + int kind = currentToken.getKind(); + String image = currentToken.getImage(); + + boolean isLiteral = kind == CppTokenKinds.STRING || kind == CppTokenKinds.RSTRING || kind == CppTokenKinds.CHARACTER || kind == CppTokenKinds.DECIMAL_INT_LITERAL || kind == CppTokenKinds.HEXADECIMAL_INT_LITERAL || kind == CppTokenKinds.OCTAL_INT_LITERAL || kind == CppTokenKinds.FLOAT_LITERAL || kind == CppTokenKinds.BINARY_INT_LITERAL || kind == CppTokenKinds.ZERO; + if (ignoreLiterals && isLiteral) { + image = CppTokenKinds.describe(kind); + } + + if (ignoreIdentifiers && (kind == CppTokenKinds.ID)) { + image = CppTokenKinds.describe(kind); + } + + tokenEntries.recordToken(image, currentToken.getReportLocation()); + } + private static class CppTokenFilter extends JavaCCTokenFilter { private final boolean ignoreLiteralSequences; diff --git a/pmd-cpp/src/test/java/net/sourceforge/pmd/lang/cpp/cpd/CppCpdLexerTest.java b/pmd-cpp/src/test/java/net/sourceforge/pmd/lang/cpp/cpd/CppCpdLexerTest.java index 805bb9a86d..90bfe90a32 100644 --- a/pmd-cpp/src/test/java/net/sourceforge/pmd/lang/cpp/cpd/CppCpdLexerTest.java +++ b/pmd-cpp/src/test/java/net/sourceforge/pmd/lang/cpp/cpd/CppCpdLexerTest.java @@ -59,6 +59,16 @@ class CppCpdLexerTest extends CpdTextComparisonTest { doTest("specialComments"); } + @Test + void testIgnoreLiterals() { + doTest("ignoreLiterals", "", ignoreLiterals()); + } + + @Test + void testIgnoreIdents() { + doTest("ignoreIdents", "", ignoreIdents()); + } + @Test void testMultiLineMacros() { doTest("multilineMacros"); @@ -142,7 +152,7 @@ class CppCpdLexerTest extends CpdTextComparisonTest { } private static LanguagePropertyConfig skipBlocks(String skipPattern) { - return properties(true, skipPattern, false, false); + return properties(true, skipPattern, false, false, false, false); } private static LanguagePropertyConfig skipBlocks() { @@ -150,22 +160,31 @@ class CppCpdLexerTest extends CpdTextComparisonTest { } private static LanguagePropertyConfig dontSkipBlocks() { - return properties(false, null, false, false); + return properties(false, null, false, false, false, false); } private static LanguagePropertyConfig skipLiteralSequences() { - return properties(false, null, true, false); + return properties(false, null, true, false, false, false); } private static LanguagePropertyConfig skipIdentifierAndLiteralsSequences() { - return properties(false, null, true, true); + return properties(false, null, true, true, false, false); } private static LanguagePropertyConfig skipIdentifierSequences() { - return properties(false, null, false, true); + return properties(false, null, false, true, false, false); } - private static LanguagePropertyConfig properties(boolean skipBlocks, String skipPattern, boolean skipLiteralSequences, boolean skipSequences) { + private static LanguagePropertyConfig ignoreIdents() { + return properties(false, null, false, false, false, true); + } + + private static LanguagePropertyConfig ignoreLiterals() { + return properties(false, null, false, false, true, false); + } + + + private static LanguagePropertyConfig properties(boolean skipBlocks, String skipPattern, boolean skipLiteralSequences, boolean skipSequences, boolean ignoreLiterals, boolean ignoreIdents) { return properties -> { if (!skipBlocks) { properties.setProperty(CppLanguageModule.CPD_SKIP_BLOCKS, ""); @@ -174,6 +193,8 @@ class CppCpdLexerTest extends CpdTextComparisonTest { } properties.setProperty(CpdLanguageProperties.CPD_IGNORE_LITERAL_SEQUENCES, skipLiteralSequences); properties.setProperty(CpdLanguageProperties.CPD_IGNORE_LITERAL_AND_IDENTIFIER_SEQUENCES, skipSequences); + properties.setProperty(CpdLanguageProperties.CPD_ANONYMIZE_LITERALS, ignoreLiterals); + properties.setProperty(CpdLanguageProperties.CPD_ANONYMIZE_IDENTIFIERS, ignoreIdents); }; } } diff --git a/pmd-cpp/src/test/resources/net/sourceforge/pmd/lang/cpp/cpd/testdata/ignoreIdents.cpp b/pmd-cpp/src/test/resources/net/sourceforge/pmd/lang/cpp/cpd/testdata/ignoreIdents.cpp new file mode 100644 index 0000000000..91473e3e67 --- /dev/null +++ b/pmd-cpp/src/test/resources/net/sourceforge/pmd/lang/cpp/cpd/testdata/ignoreIdents.cpp @@ -0,0 +1,6 @@ +class Test { + void f(int a, float b) { + auto c = a + b; + int d = 6; + } +} \ No newline at end of file diff --git a/pmd-cpp/src/test/resources/net/sourceforge/pmd/lang/cpp/cpd/testdata/ignoreIdents.txt b/pmd-cpp/src/test/resources/net/sourceforge/pmd/lang/cpp/cpd/testdata/ignoreIdents.txt new file mode 100644 index 0000000000..b564fde247 --- /dev/null +++ b/pmd-cpp/src/test/resources/net/sourceforge/pmd/lang/cpp/cpd/testdata/ignoreIdents.txt @@ -0,0 +1,35 @@ + [Image] or [Truncated image[ Bcol Ecol +L1 + [class] 1 6 + [] 7 11 + [{] 12 13 +L2 + [void] 2 6 + [] 7 8 + [(] 8 9 + [int] 9 12 + [] 13 14 + [,] 14 15 + [float] 16 21 + [] 22 23 + [)] 23 24 + [{] 25 26 +L3 + [auto] 3 7 + [] 8 9 + [=] 10 11 + [] 12 13 + [+] 14 15 + [] 16 17 + [;] 17 18 +L4 + [int] 3 6 + [] 7 8 + [=] 9 10 + [6] 11 12 + [;] 12 13 +L5 + [}] 2 3 +L6 + [}] 1 2 +EOF diff --git a/pmd-cpp/src/test/resources/net/sourceforge/pmd/lang/cpp/cpd/testdata/ignoreLiterals.cpp b/pmd-cpp/src/test/resources/net/sourceforge/pmd/lang/cpp/cpd/testdata/ignoreLiterals.cpp new file mode 100644 index 0000000000..cbae7336ba --- /dev/null +++ b/pmd-cpp/src/test/resources/net/sourceforge/pmd/lang/cpp/cpd/testdata/ignoreLiterals.cpp @@ -0,0 +1,43 @@ + void main() { + char x = L'a'; // wide chars + x = '\0x05'; // hex + // x = L''; // empty character is an error + + print("\ oMedia"); // whitespace escape + + + // char prefixes + char16_t c = u'\u00F6'; + wchar_t b = L'\xFFEF'; + char a = '\x30'; + char32_t d = U'\U0010FFFF'; + + // string prefixes + char A[] = "Hello\x0A"; + wchar_t B[] = L"Hell\xF6\x0A"; + char16_t C[] = u"Hell\u00F6"; + char32_t D[] = U"Hell\U000000F6\U0010FFFF"; + auto E[] = u8"\u00F6\U0010FFFF"; + + + + char* rawString = R"( + [Sinks.1] + Destination=Console + AutoFlush=true + Format="[%TimeStamp%] %ThreadId% %QueryIdHigh% %QueryIdLow% %LoggerFile%:%Line% (%Severity%) - %Message%" + Filter="%Severity% >= WRN" + )"; + + + + // digit separators + auto integer_literal = 1'000''000; + auto floating_point_literal = 0.000'015'3; + auto hex_literal = 0x0F00'abcd'6f3d; + auto silly_example = 1'0'0'000'00; + + // boolean literals + int b1 = 0B001101; // C++ 14 binary literal + int b2 = 0b000001; // C++ 14 binary literal +} \ No newline at end of file diff --git a/pmd-cpp/src/test/resources/net/sourceforge/pmd/lang/cpp/cpd/testdata/ignoreLiterals.txt b/pmd-cpp/src/test/resources/net/sourceforge/pmd/lang/cpp/cpd/testdata/ignoreLiterals.txt new file mode 100644 index 0000000000..ef31240e44 --- /dev/null +++ b/pmd-cpp/src/test/resources/net/sourceforge/pmd/lang/cpp/cpd/testdata/ignoreLiterals.txt @@ -0,0 +1,135 @@ + [Image] or [Truncated image[ Bcol Ecol +L1 + [void] 2 6 + [main] 7 11 + [(] 11 12 + [)] 12 13 + [{] 14 15 +L2 + [char] 5 9 + [x] 10 11 + [=] 12 13 + [] 14 18 + [;] 18 19 +L3 + [x] 5 6 + [=] 7 8 + [] 9 16 + [;] 16 17 +L6 + [print] 5 10 + [(] 10 11 + [] 11 24 + [)] 24 25 + [;] 25 26 +L10 + [char16_t] 5 13 + [c] 14 15 + [=] 16 17 + [] 18 27 + [;] 27 28 +L11 + [wchar_t] 5 12 + [b] 13 14 + [=] 15 16 + [] 17 26 + [;] 26 27 +L12 + [char] 5 9 + [a] 10 11 + [=] 12 13 + [] 15 21 + [;] 21 22 +L13 + [char32_t] 5 13 + [d] 14 15 + [=] 16 17 + [] 18 31 + [;] 31 32 +L16 + [char] 5 9 + [A] 10 11 + [\[] 11 12 + [\]] 12 13 + [=] 14 15 + [] 16 27 + [;] 27 28 +L17 + [wchar_t] 5 12 + [B] 13 14 + [\[] 14 15 + [\]] 15 16 + [=] 17 18 + [] 19 34 + [;] 34 35 +L18 + [char16_t] 5 13 + [C] 14 15 + [\[] 15 16 + [\]] 16 17 + [=] 18 19 + [] 20 33 + [;] 33 34 +L19 + [char32_t] 5 13 + [D] 14 15 + [\[] 15 16 + [\]] 16 17 + [=] 18 19 + [] 20 47 + [;] 47 48 +L20 + [auto] 5 9 + [E] 10 11 + [\[] 11 12 + [\]] 12 13 + [=] 14 15 + [] 16 36 + [;] 36 37 +L24 + [char] 5 9 + [*] 9 10 + [rawString] 11 20 + [=] 21 22 + [] 23 7 +L30 + [;] 7 8 +L35 + [auto] 5 9 + [integer_literal] 10 25 + [=] 26 27 + [] 28 38 + [;] 38 39 +L36 + [auto] 5 9 + [floating_point_literal] 10 32 + [=] 33 34 + [] 35 46 + [;] 46 47 +L37 + [auto] 5 9 + [hex_literal] 10 21 + [=] 22 23 + [] 24 40 + [;] 40 41 +L38 + [auto] 5 9 + [silly_example] 10 23 + [=] 24 25 + [] 26 38 + [;] 38 39 +L41 + [int] 5 8 + [b1] 9 11 + [=] 12 13 + [] 14 22 + [;] 22 23 +L42 + [int] 5 8 + [b2] 9 11 + [=] 12 13 + [] 14 22 + [;] 22 23 +L43 + [}] 1 2 +EOF diff --git a/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/ast/ASTSwitchLabel.java b/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/ast/ASTSwitchLabel.java index 8391284ec8..2b489d4fde 100644 --- a/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/ast/ASTSwitchLabel.java +++ b/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/ast/ASTSwitchLabel.java @@ -50,8 +50,9 @@ public final class ASTSwitchLabel extends AbstractJavaNode implements Iterable getExprList() { return children(ASTExpression.class); @@ -66,4 +67,12 @@ public final class ASTSwitchLabel extends AbstractJavaNode implements Iterable iterator() { return children(ASTExpression.class).iterator(); } + + /** + * Checks whether this label tests a {@link ASTTypePattern} or a {@link ASTRecordPattern}. + * @since 7.7.0 + */ + public boolean isPatternLabel() { + return children(ASTPattern.class).nonEmpty(); + } } diff --git a/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/rule/design/SwitchDensityRule.java b/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/rule/design/SwitchDensityRule.java index 1360d29458..a8a6fe6fbe 100644 --- a/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/rule/design/SwitchDensityRule.java +++ b/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/rule/design/SwitchDensityRule.java @@ -55,7 +55,7 @@ public class SwitchDensityRule extends AbstractJavaRulechainRule { int stmtCount = node.descendants(ASTStatement.class).count(); int labelCount = node.getBranches() .map(ASTSwitchBranch::getLabel) - .sumBy(label -> label.isDefault() ? 1 : label.getExprList().count()); + .sumBy(label -> label.isDefault() || label.isPatternLabel() ? 1 : label.getExprList().count()); // note: if labelCount is zero, double division will produce +Infinity or NaN, not ArithmeticException double density = stmtCount / (double) labelCount; diff --git a/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/rule/errorprone/ImplicitSwitchFallThroughRule.java b/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/rule/errorprone/ImplicitSwitchFallThroughRule.java index 29d91c111c..fb0a9298f5 100644 --- a/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/rule/errorprone/ImplicitSwitchFallThroughRule.java +++ b/pmd-java/src/main/java/net/sourceforge/pmd/lang/java/rule/errorprone/ImplicitSwitchFallThroughRule.java @@ -9,28 +9,40 @@ import java.util.regex.Pattern; import net.sourceforge.pmd.lang.ast.GenericToken; import net.sourceforge.pmd.lang.ast.impl.javacc.JavaccToken; import net.sourceforge.pmd.lang.java.ast.ASTSwitchBranch; +import net.sourceforge.pmd.lang.java.ast.ASTSwitchExpression; import net.sourceforge.pmd.lang.java.ast.ASTSwitchFallthroughBranch; +import net.sourceforge.pmd.lang.java.ast.ASTSwitchLike; import net.sourceforge.pmd.lang.java.ast.ASTSwitchStatement; import net.sourceforge.pmd.lang.java.ast.JavaNode; import net.sourceforge.pmd.lang.java.ast.internal.JavaAstUtils; import net.sourceforge.pmd.lang.java.rule.AbstractJavaRulechainRule; import net.sourceforge.pmd.lang.java.rule.internal.DataflowPass; import net.sourceforge.pmd.lang.java.rule.internal.DataflowPass.DataflowResult; +import net.sourceforge.pmd.reporting.RuleContext; import net.sourceforge.pmd.util.OptionalBool; public class ImplicitSwitchFallThroughRule extends AbstractJavaRulechainRule { - //todo should consider switch exprs - private static final Pattern IGNORED_COMMENT = Pattern.compile("/[/*].*\\bfalls?[ -]?thr(ough|u)\\b.*", Pattern.DOTALL | Pattern.CASE_INSENSITIVE); public ImplicitSwitchFallThroughRule() { - super(ASTSwitchStatement.class); + super(ASTSwitchStatement.class, ASTSwitchExpression.class); } @Override public Object visit(ASTSwitchStatement node, Object data) { + checkSwitchLike(node, asCtx(data)); + return null; + } + + @Override + public Object visit(ASTSwitchExpression node, Object data) { + checkSwitchLike(node, asCtx(data)); + return null; + } + + private void checkSwitchLike(ASTSwitchLike node, RuleContext ruleContext) { DataflowResult dataflow = DataflowPass.getDataflowResult(node.getRoot()); for (ASTSwitchBranch branch : node.getBranches()) { @@ -38,15 +50,14 @@ public class ImplicitSwitchFallThroughRule extends AbstractJavaRulechainRule { ASTSwitchFallthroughBranch fallthrough = (ASTSwitchFallthroughBranch) branch; OptionalBool bool = dataflow.switchBranchFallsThrough(branch); if (bool != OptionalBool.NO - && fallthrough.getStatements().nonEmpty() - && !nextBranchHasComment(branch)) { - asCtx(data).addViolation(branch.getNextBranch().getLabel()); + && fallthrough.getStatements().nonEmpty() + && !nextBranchHasComment(branch)) { + ruleContext.addViolation(branch.getNextBranch().getLabel()); } } else { - return null; + return; } } - return null; } boolean nextBranchHasComment(ASTSwitchBranch branch) { @@ -62,5 +73,4 @@ public class ImplicitSwitchFallThroughRule extends AbstractJavaRulechainRule { } return false; } - } diff --git a/pmd-java/src/main/resources/category/java/bestpractices.xml b/pmd-java/src/main/resources/category/java/bestpractices.xml index 58fea8b30b..32fff7716f 100644 --- a/pmd-java/src/main/resources/category/java/bestpractices.xml +++ b/pmd-java/src/main/resources/category/java/bestpractices.xml @@ -1335,38 +1335,48 @@ public class Foo { - This rule detects methods called `tearDown()` that are not properly annotated as a cleanup method. - This is primarily intended to assist in upgrading from JUnit 3, where tear down methods were required to be called `tearDown()`. - To a lesser extent, this may help detect omissions under newer JUnit versions, as long as you are following this convention to name the methods. +This rule detects methods called `tearDown()` that are not properly annotated as a cleanup method. +This is primarily intended to assist in upgrading from JUnit 3, where tear down methods were required to be called `tearDown()`. +To a lesser extent, this may help detect omissions even under newer JUnit versions or under TestNG, +as long as you are following this convention to name the methods. - JUnit 4 will only execute methods annotated with `@After` after running each test. - JUnit 5 introduced `@AfterEach` and `@AfterAll` annotations to execute methods after each test or after all tests in the class, respectively. +* JUnit 4 will only execute methods annotated with `@After` after running each test. +* JUnit 5 introduced `@AfterEach` and `@AfterAll` annotations to execute methods after each test or after + all tests in the class, respectively. +* TestNG provides the annotations `@AfterMethod` and `@AfterClass` to execute methods after each test or after + tests in the class, respectively. - Note: This rule was named JUnit4TestShouldUseAfterAnnotation before PMD 7.7.0. +Note: This rule was named JUnit4TestShouldUseAfterAnnotation before PMD 7.7.0. 3 - - - This rule detects methods called `setUp()` that are not properly annotated as a setup method. - This is primarily intended to assist in upgrading from JUnit 3, where setup methods were required to be called `setUp()`. - To a lesser extent, this may help detect omissions even under newer JUnit versions, as long as you are following this convention to name the methods. +This rule detects methods called `setUp()` that are not properly annotated as a setup method. +This is primarily intended to assist in upgrading from JUnit 3, where setup methods were required to be called `setUp()`. +To a lesser extent, this may help detect omissions even under newer JUnit versions or under TestNG, +as long as you are following this convention to name the methods. - JUnit 4 will only execute methods annotated with `@Before` before all tests. - JUnit 5 introduced `@BeforeEach` and `@BeforeAll` annotations to execute methods before each test or before all tests in the class, respectively. +* JUnit 4 will only execute methods annotated with `@Before` before all tests. +* JUnit 5 introduced `@BeforeEach` and `@BeforeAll` annotations to execute methods before each test or before all + tests in the class, respectively. +* TestNG provides the annotations `@BeforeMethod` and `@BeforeClass` to execute methods before each test or before + tests in the class, respectively. - Note: This rule was named JUnit4TestShouldUseBeforeAnnotation before PMD 7.7.0. +Note: This rule was named JUnit4TestShouldUseBeforeAnnotation before PMD 7.7.0. 3 @@ -1407,9 +1421,15 @@ public class MyTest2 { pmd-java:typeIs('org.junit.Before') or pmd-java:typeIs('org.junit.jupiter.api.BeforeEach') or pmd-java:typeIs('org.junit.jupiter.api.BeforeAll') - or pmd-java:typeIs('org.testng.annotations.BeforeMethod')])] - (: Make sure this is a junit 4 class :) - [../MethodDeclaration[pmd-java:hasAnnotation('org.junit.Test')]] + or pmd-java:typeIs('org.testng.annotations.BeforeMethod') + or pmd-java:typeIs('org.testng.annotations.BeforeClass') + ])] + (: Make sure this is a JUnit 4/5 or TestNG class :) + [../MethodDeclaration[ + pmd-java:hasAnnotation('org.junit.Test') + or pmd-java:hasAnnotation('org.junit.jupiter.api.Test') + or pmd-java:hasAnnotation('org.testng.annotations.Test') + ]] ]]> diff --git a/pmd-java/src/test/resources/net/sourceforge/pmd/lang/java/ast/ParserCornerCases17.txt b/pmd-java/src/test/resources/net/sourceforge/pmd/lang/java/ast/ParserCornerCases17.txt index 553f930c10..bea2307a18 100644 --- a/pmd-java/src/test/resources/net/sourceforge/pmd/lang/java/ast/ParserCornerCases17.txt +++ b/pmd-java/src/test/resources/net/sourceforge/pmd/lang/java/ast/ParserCornerCases17.txt @@ -107,39 +107,39 @@ | | +- VariableAccess[@AccessType = AccessType.READ, @CompileTimeConstant = false, @Image = "instruction", @Name = "instruction", @ParenthesisDepth = 0, @Parenthesized = false] | | +- NumericLiteral[@Base = 2, @CompileTimeConstant = true, @DoubleLiteral = false, @FloatLiteral = false, @Image = "0b11110000", @IntLiteral = true, @Integral = true, @LiteralText = "0b11110000", @LongLiteral = false, @ParenthesisDepth = 0, @Parenthesized = false, @ValueAsDouble = 240.0, @ValueAsFloat = 240.0, @ValueAsInt = 240, @ValueAsLong = 240] | +- SwitchFallthroughBranch[@Default = false] - | | +- SwitchLabel[@Default = false] + | | +- SwitchLabel[@Default = false, @PatternLabel = false] | | | +- NumericLiteral[@Base = 2, @CompileTimeConstant = true, @DoubleLiteral = false, @FloatLiteral = false, @Image = "0b00000000", @IntLiteral = true, @Integral = true, @LiteralText = "0b00000000", @LongLiteral = false, @ParenthesisDepth = 0, @Parenthesized = false, @ValueAsDouble = 0.0, @ValueAsFloat = 0.0, @ValueAsInt = 0, @ValueAsLong = 0] | | +- BreakStatement[@Label = null] | +- SwitchFallthroughBranch[@Default = false] - | | +- SwitchLabel[@Default = false] + | | +- SwitchLabel[@Default = false, @PatternLabel = false] | | | +- NumericLiteral[@Base = 2, @CompileTimeConstant = true, @DoubleLiteral = false, @FloatLiteral = false, @Image = "0b00010000", @IntLiteral = true, @Integral = true, @LiteralText = "0b00010000", @LongLiteral = false, @ParenthesisDepth = 0, @Parenthesized = false, @ValueAsDouble = 16.0, @ValueAsFloat = 16.0, @ValueAsInt = 16, @ValueAsLong = 16] | | +- BreakStatement[@Label = null] | +- SwitchFallthroughBranch[@Default = false] - | | +- SwitchLabel[@Default = false] + | | +- SwitchLabel[@Default = false, @PatternLabel = false] | | | +- NumericLiteral[@Base = 2, @CompileTimeConstant = true, @DoubleLiteral = false, @FloatLiteral = false, @Image = "0b00100000", @IntLiteral = true, @Integral = true, @LiteralText = "0b00100000", @LongLiteral = false, @ParenthesisDepth = 0, @Parenthesized = false, @ValueAsDouble = 32.0, @ValueAsFloat = 32.0, @ValueAsInt = 32, @ValueAsLong = 32] | | +- BreakStatement[@Label = null] | +- SwitchFallthroughBranch[@Default = false] - | | +- SwitchLabel[@Default = false] + | | +- SwitchLabel[@Default = false, @PatternLabel = false] | | | +- NumericLiteral[@Base = 2, @CompileTimeConstant = true, @DoubleLiteral = false, @FloatLiteral = false, @Image = "0b00110000", @IntLiteral = true, @Integral = true, @LiteralText = "0b00110000", @LongLiteral = false, @ParenthesisDepth = 0, @Parenthesized = false, @ValueAsDouble = 48.0, @ValueAsFloat = 48.0, @ValueAsInt = 48, @ValueAsLong = 48] | | +- BreakStatement[@Label = null] | +- SwitchFallthroughBranch[@Default = false] - | | +- SwitchLabel[@Default = false] + | | +- SwitchLabel[@Default = false, @PatternLabel = false] | | | +- NumericLiteral[@Base = 2, @CompileTimeConstant = true, @DoubleLiteral = false, @FloatLiteral = false, @Image = "0b01000000", @IntLiteral = true, @Integral = true, @LiteralText = "0b01000000", @LongLiteral = false, @ParenthesisDepth = 0, @Parenthesized = false, @ValueAsDouble = 64.0, @ValueAsFloat = 64.0, @ValueAsInt = 64, @ValueAsLong = 64] | | +- BreakStatement[@Label = null] | +- SwitchFallthroughBranch[@Default = false] - | | +- SwitchLabel[@Default = false] + | | +- SwitchLabel[@Default = false, @PatternLabel = false] | | | +- NumericLiteral[@Base = 2, @CompileTimeConstant = true, @DoubleLiteral = false, @FloatLiteral = false, @Image = "0b01010000", @IntLiteral = true, @Integral = true, @LiteralText = "0b01010000", @LongLiteral = false, @ParenthesisDepth = 0, @Parenthesized = false, @ValueAsDouble = 80.0, @ValueAsFloat = 80.0, @ValueAsInt = 80, @ValueAsLong = 80] | | +- BreakStatement[@Label = null] | +- SwitchFallthroughBranch[@Default = false] - | | +- SwitchLabel[@Default = false] + | | +- SwitchLabel[@Default = false, @PatternLabel = false] | | | +- NumericLiteral[@Base = 2, @CompileTimeConstant = true, @DoubleLiteral = false, @FloatLiteral = false, @Image = "0b01100000", @IntLiteral = true, @Integral = true, @LiteralText = "0b01100000", @LongLiteral = false, @ParenthesisDepth = 0, @Parenthesized = false, @ValueAsDouble = 96.0, @ValueAsFloat = 96.0, @ValueAsInt = 96, @ValueAsLong = 96] | | +- BreakStatement[@Label = null] | +- SwitchFallthroughBranch[@Default = false] - | | +- SwitchLabel[@Default = false] + | | +- SwitchLabel[@Default = false, @PatternLabel = false] | | | +- NumericLiteral[@Base = 2, @CompileTimeConstant = true, @DoubleLiteral = false, @FloatLiteral = false, @Image = "0b01110000", @IntLiteral = true, @Integral = true, @LiteralText = "0b01110000", @LongLiteral = false, @ParenthesisDepth = 0, @Parenthesized = false, @ValueAsDouble = 112.0, @ValueAsFloat = 112.0, @ValueAsInt = 112, @ValueAsLong = 112] | | +- BreakStatement[@Label = null] | +- SwitchFallthroughBranch[@Default = true] - | +- SwitchLabel[@Default = true] + | +- SwitchLabel[@Default = true, @PatternLabel = false] | +- ThrowStatement[] | +- ConstructorCall[@AnonymousClass = false, @CompileTimeConstant = false, @DiamondTypeArgs = false, @MethodName = "new", @ParenthesisDepth = 0, @Parenthesized = false, @QualifiedInstanceCreation = false] | +- ClassType[@FullyQualified = false, @PackageQualifier = null, @SimpleName = "IllegalArgumentException"] @@ -258,7 +258,7 @@ | +- SwitchStatement[@DefaultCase = true, @EnumSwitch = false, @ExhaustiveEnumSwitch = false, @FallthroughSwitch = true] | | +- VariableAccess[@AccessType = AccessType.READ, @CompileTimeConstant = false, @Image = "dayOfWeekArg", @Name = "dayOfWeekArg", @ParenthesisDepth = 0, @Parenthesized = false] | | +- SwitchFallthroughBranch[@Default = false] - | | | +- SwitchLabel[@Default = false] + | | | +- SwitchLabel[@Default = false, @PatternLabel = false] | | | | +- StringLiteral[@CompileTimeConstant = true, @ConstValue = "Monday", @Empty = false, @Image = "\"Monday\"", @Length = 6, @LiteralText = "\"Monday\"", @ParenthesisDepth = 0, @Parenthesized = false, @TextBlock = false] | | | +- ExpressionStatement[] | | | | +- AssignmentExpression[@CompileTimeConstant = false, @Compound = false, @Operator = AssignmentOp.ASSIGN, @ParenthesisDepth = 0, @Parenthesized = false] @@ -266,13 +266,13 @@ | | | | +- StringLiteral[@CompileTimeConstant = true, @ConstValue = "Start of work week", @Empty = false, @Image = "\"Start of work week\"", @Length = 18, @LiteralText = "\"Start of work week\"", @ParenthesisDepth = 0, @Parenthesized = false, @TextBlock = false] | | | +- BreakStatement[@Label = null] | | +- SwitchFallthroughBranch[@Default = false] - | | | +- SwitchLabel[@Default = false] + | | | +- SwitchLabel[@Default = false, @PatternLabel = false] | | | +- StringLiteral[@CompileTimeConstant = true, @ConstValue = "Tuesday", @Empty = false, @Image = "\"Tuesday\"", @Length = 7, @LiteralText = "\"Tuesday\"", @ParenthesisDepth = 0, @Parenthesized = false, @TextBlock = false] | | +- SwitchFallthroughBranch[@Default = false] - | | | +- SwitchLabel[@Default = false] + | | | +- SwitchLabel[@Default = false, @PatternLabel = false] | | | +- StringLiteral[@CompileTimeConstant = true, @ConstValue = "Wednesday", @Empty = false, @Image = "\"Wednesday\"", @Length = 9, @LiteralText = "\"Wednesday\"", @ParenthesisDepth = 0, @Parenthesized = false, @TextBlock = false] | | +- SwitchFallthroughBranch[@Default = false] - | | | +- SwitchLabel[@Default = false] + | | | +- SwitchLabel[@Default = false, @PatternLabel = false] | | | | +- StringLiteral[@CompileTimeConstant = true, @ConstValue = "Thursday", @Empty = false, @Image = "\"Thursday\"", @Length = 8, @LiteralText = "\"Thursday\"", @ParenthesisDepth = 0, @Parenthesized = false, @TextBlock = false] | | | +- ExpressionStatement[] | | | | +- AssignmentExpression[@CompileTimeConstant = false, @Compound = false, @Operator = AssignmentOp.ASSIGN, @ParenthesisDepth = 0, @Parenthesized = false] @@ -280,7 +280,7 @@ | | | | +- StringLiteral[@CompileTimeConstant = true, @ConstValue = "Midweek", @Empty = false, @Image = "\"Midweek\"", @Length = 7, @LiteralText = "\"Midweek\"", @ParenthesisDepth = 0, @Parenthesized = false, @TextBlock = false] | | | +- BreakStatement[@Label = null] | | +- SwitchFallthroughBranch[@Default = false] - | | | +- SwitchLabel[@Default = false] + | | | +- SwitchLabel[@Default = false, @PatternLabel = false] | | | | +- StringLiteral[@CompileTimeConstant = true, @ConstValue = "Friday", @Empty = false, @Image = "\"Friday\"", @Length = 6, @LiteralText = "\"Friday\"", @ParenthesisDepth = 0, @Parenthesized = false, @TextBlock = false] | | | +- ExpressionStatement[] | | | | +- AssignmentExpression[@CompileTimeConstant = false, @Compound = false, @Operator = AssignmentOp.ASSIGN, @ParenthesisDepth = 0, @Parenthesized = false] @@ -288,10 +288,10 @@ | | | | +- StringLiteral[@CompileTimeConstant = true, @ConstValue = "End of work week", @Empty = false, @Image = "\"End of work week\"", @Length = 16, @LiteralText = "\"End of work week\"", @ParenthesisDepth = 0, @Parenthesized = false, @TextBlock = false] | | | +- BreakStatement[@Label = null] | | +- SwitchFallthroughBranch[@Default = false] - | | | +- SwitchLabel[@Default = false] + | | | +- SwitchLabel[@Default = false, @PatternLabel = false] | | | +- StringLiteral[@CompileTimeConstant = true, @ConstValue = "Saturday", @Empty = false, @Image = "\"Saturday\"", @Length = 8, @LiteralText = "\"Saturday\"", @ParenthesisDepth = 0, @Parenthesized = false, @TextBlock = false] | | +- SwitchFallthroughBranch[@Default = false] - | | | +- SwitchLabel[@Default = false] + | | | +- SwitchLabel[@Default = false, @PatternLabel = false] | | | | +- StringLiteral[@CompileTimeConstant = true, @ConstValue = "Sunday", @Empty = false, @Image = "\"Sunday\"", @Length = 6, @LiteralText = "\"Sunday\"", @ParenthesisDepth = 0, @Parenthesized = false, @TextBlock = false] | | | +- ExpressionStatement[] | | | | +- AssignmentExpression[@CompileTimeConstant = false, @Compound = false, @Operator = AssignmentOp.ASSIGN, @ParenthesisDepth = 0, @Parenthesized = false] @@ -299,7 +299,7 @@ | | | | +- StringLiteral[@CompileTimeConstant = true, @ConstValue = "Weekend", @Empty = false, @Image = "\"Weekend\"", @Length = 7, @LiteralText = "\"Weekend\"", @ParenthesisDepth = 0, @Parenthesized = false, @TextBlock = false] | | | +- BreakStatement[@Label = null] | | +- SwitchFallthroughBranch[@Default = true] - | | +- SwitchLabel[@Default = true] + | | +- SwitchLabel[@Default = true, @PatternLabel = false] | | +- ThrowStatement[] | | +- ConstructorCall[@AnonymousClass = false, @CompileTimeConstant = false, @DiamondTypeArgs = false, @MethodName = "new", @ParenthesisDepth = 0, @Parenthesized = false, @QualifiedInstanceCreation = false] | | +- ClassType[@FullyQualified = false, @PackageQualifier = null, @SimpleName = "IllegalArgumentException"] diff --git a/pmd-java/src/test/resources/net/sourceforge/pmd/lang/java/ast/SwitchStatements.txt b/pmd-java/src/test/resources/net/sourceforge/pmd/lang/java/ast/SwitchStatements.txt index 70874b1031..dbfa7a4509 100644 --- a/pmd-java/src/test/resources/net/sourceforge/pmd/lang/java/ast/SwitchStatements.txt +++ b/pmd-java/src/test/resources/net/sourceforge/pmd/lang/java/ast/SwitchStatements.txt @@ -16,16 +16,16 @@ +- SwitchStatement[@DefaultCase = true, @EnumSwitch = false, @ExhaustiveEnumSwitch = false, @FallthroughSwitch = true] | +- VariableAccess[@AccessType = AccessType.READ, @CompileTimeConstant = false, @Image = "a", @Name = "a", @ParenthesisDepth = 0, @Parenthesized = false] | +- SwitchFallthroughBranch[@Default = false] - | | +- SwitchLabel[@Default = false] + | | +- SwitchLabel[@Default = false, @PatternLabel = false] | | +- NumericLiteral[@Base = 10, @CompileTimeConstant = true, @DoubleLiteral = false, @FloatLiteral = false, @Image = "1", @IntLiteral = true, @Integral = true, @LiteralText = "1", @LongLiteral = false, @ParenthesisDepth = 0, @Parenthesized = false, @ValueAsDouble = 1.0, @ValueAsFloat = 1.0, @ValueAsInt = 1, @ValueAsLong = 1] | +- SwitchFallthroughBranch[@Default = true] - | +- SwitchLabel[@Default = true] + | +- SwitchLabel[@Default = true, @PatternLabel = false] +- SwitchStatement[@DefaultCase = false, @EnumSwitch = false, @ExhaustiveEnumSwitch = false, @FallthroughSwitch = false] | +- VariableAccess[@AccessType = AccessType.READ, @CompileTimeConstant = false, @Image = "a", @Name = "a", @ParenthesisDepth = 0, @Parenthesized = false] +- SwitchStatement[@DefaultCase = true, @EnumSwitch = false, @ExhaustiveEnumSwitch = false, @FallthroughSwitch = true] +- VariableAccess[@AccessType = AccessType.READ, @CompileTimeConstant = false, @Image = "a", @Name = "a", @ParenthesisDepth = 0, @Parenthesized = false] +- SwitchFallthroughBranch[@Default = false] - | +- SwitchLabel[@Default = false] + | +- SwitchLabel[@Default = false, @PatternLabel = false] | | +- NumericLiteral[@Base = 10, @CompileTimeConstant = true, @DoubleLiteral = false, @FloatLiteral = false, @Image = "1", @IntLiteral = true, @Integral = true, @LiteralText = "1", @LongLiteral = false, @ParenthesisDepth = 0, @Parenthesized = false, @ValueAsDouble = 1.0, @ValueAsFloat = 1.0, @ValueAsInt = 1, @ValueAsLong = 1] | +- ExpressionStatement[] | | +- MethodCall[@CompileTimeConstant = false, @Image = "println", @MethodName = "println", @ParenthesisDepth = 0, @Parenthesized = false] @@ -36,4 +36,4 @@ | | +- StringLiteral[@CompileTimeConstant = true, @ConstValue = "1", @Empty = false, @Image = "\"1\"", @Length = 1, @LiteralText = "\"1\"", @ParenthesisDepth = 0, @Parenthesized = false, @TextBlock = false] | +- BreakStatement[@Label = null] +- SwitchFallthroughBranch[@Default = true] - +- SwitchLabel[@Default = true] + +- SwitchLabel[@Default = true, @PatternLabel = false] diff --git a/pmd-java/src/test/resources/net/sourceforge/pmd/lang/java/ast/SwitchWithFallthrough.txt b/pmd-java/src/test/resources/net/sourceforge/pmd/lang/java/ast/SwitchWithFallthrough.txt index 49574ca1a0..5f16e3c6a7 100644 --- a/pmd-java/src/test/resources/net/sourceforge/pmd/lang/java/ast/SwitchWithFallthrough.txt +++ b/pmd-java/src/test/resources/net/sourceforge/pmd/lang/java/ast/SwitchWithFallthrough.txt @@ -16,7 +16,7 @@ +- SwitchStatement[@DefaultCase = true, @EnumSwitch = false, @ExhaustiveEnumSwitch = false, @FallthroughSwitch = true] +- VariableAccess[@AccessType = AccessType.READ, @CompileTimeConstant = false, @Image = "a", @Name = "a", @ParenthesisDepth = 0, @Parenthesized = false] +- SwitchFallthroughBranch[@Default = false] - | +- SwitchLabel[@Default = false] + | +- SwitchLabel[@Default = false, @PatternLabel = false] | +- NumericLiteral[@Base = 10, @CompileTimeConstant = true, @DoubleLiteral = false, @FloatLiteral = false, @Image = "1", @IntLiteral = true, @Integral = true, @LiteralText = "1", @LongLiteral = false, @ParenthesisDepth = 0, @Parenthesized = false, @ValueAsDouble = 1.0, @ValueAsFloat = 1.0, @ValueAsInt = 1, @ValueAsLong = 1] +- SwitchFallthroughBranch[@Default = true] - +- SwitchLabel[@Default = true] + +- SwitchLabel[@Default = true, @PatternLabel = false] diff --git a/pmd-java/src/test/resources/net/sourceforge/pmd/lang/java/ast/jdkversiontests/java14/MultipleCaseLabels.txt b/pmd-java/src/test/resources/net/sourceforge/pmd/lang/java/ast/jdkversiontests/java14/MultipleCaseLabels.txt index 5600a4c3d8..a9007b4787 100644 --- a/pmd-java/src/test/resources/net/sourceforge/pmd/lang/java/ast/jdkversiontests/java14/MultipleCaseLabels.txt +++ b/pmd-java/src/test/resources/net/sourceforge/pmd/lang/java/ast/jdkversiontests/java14/MultipleCaseLabels.txt @@ -65,7 +65,7 @@ +- SwitchStatement[@DefaultCase = false, @EnumSwitch = false, @ExhaustiveEnumSwitch = false, @FallthroughSwitch = true] +- VariableAccess[@AccessType = AccessType.READ, @CompileTimeConstant = false, @Image = "day", @Name = "day", @ParenthesisDepth = 0, @Parenthesized = false] +- SwitchFallthroughBranch[@Default = false] - | +- SwitchLabel[@Default = false] + | +- SwitchLabel[@Default = false, @PatternLabel = false] | | +- VariableAccess[@AccessType = AccessType.READ, @CompileTimeConstant = true, @Image = "MONDAY", @Name = "MONDAY", @ParenthesisDepth = 0, @Parenthesized = false] | | +- VariableAccess[@AccessType = AccessType.READ, @CompileTimeConstant = true, @Image = "FRIDAY", @Name = "FRIDAY", @ParenthesisDepth = 0, @Parenthesized = false] | | +- VariableAccess[@AccessType = AccessType.READ, @CompileTimeConstant = true, @Image = "SUNDAY", @Name = "SUNDAY", @ParenthesisDepth = 0, @Parenthesized = false] @@ -78,7 +78,7 @@ | | +- StringLiteral[@CompileTimeConstant = true, @ConstValue = " 6", @Empty = false, @Image = "\" 6\"", @Length = 3, @LiteralText = "\" 6\"", @ParenthesisDepth = 0, @Parenthesized = false, @TextBlock = false] | +- BreakStatement[@Label = null] +- SwitchFallthroughBranch[@Default = false] - | +- SwitchLabel[@Default = false] + | +- SwitchLabel[@Default = false, @PatternLabel = false] | | +- VariableAccess[@AccessType = AccessType.READ, @CompileTimeConstant = true, @Image = "TUESDAY", @Name = "TUESDAY", @ParenthesisDepth = 0, @Parenthesized = false] | +- ExpressionStatement[] | | +- MethodCall[@CompileTimeConstant = false, @Image = "println", @MethodName = "println", @ParenthesisDepth = 0, @Parenthesized = false] @@ -89,7 +89,7 @@ | | +- StringLiteral[@CompileTimeConstant = true, @ConstValue = " 7", @Empty = false, @Image = "\" 7\"", @Length = 3, @LiteralText = "\" 7\"", @ParenthesisDepth = 0, @Parenthesized = false, @TextBlock = false] | +- BreakStatement[@Label = null] +- SwitchFallthroughBranch[@Default = false] - | +- SwitchLabel[@Default = false] + | +- SwitchLabel[@Default = false, @PatternLabel = false] | | +- VariableAccess[@AccessType = AccessType.READ, @CompileTimeConstant = true, @Image = "THURSDAY", @Name = "THURSDAY", @ParenthesisDepth = 0, @Parenthesized = false] | | +- VariableAccess[@AccessType = AccessType.READ, @CompileTimeConstant = true, @Image = "SATURDAY", @Name = "SATURDAY", @ParenthesisDepth = 0, @Parenthesized = false] | +- ExpressionStatement[] @@ -101,7 +101,7 @@ | | +- StringLiteral[@CompileTimeConstant = true, @ConstValue = " 8", @Empty = false, @Image = "\" 8\"", @Length = 3, @LiteralText = "\" 8\"", @ParenthesisDepth = 0, @Parenthesized = false, @TextBlock = false] | +- BreakStatement[@Label = null] +- SwitchFallthroughBranch[@Default = false] - +- SwitchLabel[@Default = false] + +- SwitchLabel[@Default = false, @PatternLabel = false] | +- VariableAccess[@AccessType = AccessType.READ, @CompileTimeConstant = true, @Image = "WEDNESDAY", @Name = "WEDNESDAY", @ParenthesisDepth = 0, @Parenthesized = false] +- ExpressionStatement[] | +- MethodCall[@CompileTimeConstant = false, @Image = "println", @MethodName = "println", @ParenthesisDepth = 0, @Parenthesized = false] diff --git a/pmd-java/src/test/resources/net/sourceforge/pmd/lang/java/ast/jdkversiontests/java14/SimpleSwitchExpressions.txt b/pmd-java/src/test/resources/net/sourceforge/pmd/lang/java/ast/jdkversiontests/java14/SimpleSwitchExpressions.txt index 7eb7d249f3..63cbacf6b4 100644 --- a/pmd-java/src/test/resources/net/sourceforge/pmd/lang/java/ast/jdkversiontests/java14/SimpleSwitchExpressions.txt +++ b/pmd-java/src/test/resources/net/sourceforge/pmd/lang/java/ast/jdkversiontests/java14/SimpleSwitchExpressions.txt @@ -69,26 +69,26 @@ | | +- SwitchExpression[@CompileTimeConstant = false, @DefaultCase = true, @EnumSwitch = false, @ExhaustiveEnumSwitch = false, @FallthroughSwitch = false, @ParenthesisDepth = 0, @Parenthesized = false] | | +- VariableAccess[@AccessType = AccessType.READ, @CompileTimeConstant = false, @Image = "day", @Name = "day", @ParenthesisDepth = 0, @Parenthesized = false] | | +- SwitchArrowBranch[@Default = false] - | | | +- SwitchLabel[@Default = false] + | | | +- SwitchLabel[@Default = false, @PatternLabel = false] | | | | +- VariableAccess[@AccessType = AccessType.READ, @CompileTimeConstant = true, @Image = "MONDAY", @Name = "MONDAY", @ParenthesisDepth = 0, @Parenthesized = false] | | | | +- VariableAccess[@AccessType = AccessType.READ, @CompileTimeConstant = true, @Image = "FRIDAY", @Name = "FRIDAY", @ParenthesisDepth = 0, @Parenthesized = false] | | | | +- VariableAccess[@AccessType = AccessType.READ, @CompileTimeConstant = true, @Image = "SUNDAY", @Name = "SUNDAY", @ParenthesisDepth = 0, @Parenthesized = false] | | | +- NumericLiteral[@Base = 10, @CompileTimeConstant = true, @DoubleLiteral = false, @FloatLiteral = false, @Image = "6", @IntLiteral = true, @Integral = true, @LiteralText = "6", @LongLiteral = false, @ParenthesisDepth = 0, @Parenthesized = false, @ValueAsDouble = 6.0, @ValueAsFloat = 6.0, @ValueAsInt = 6, @ValueAsLong = 6] | | +- SwitchArrowBranch[@Default = false] - | | | +- SwitchLabel[@Default = false] + | | | +- SwitchLabel[@Default = false, @PatternLabel = false] | | | | +- VariableAccess[@AccessType = AccessType.READ, @CompileTimeConstant = true, @Image = "TUESDAY", @Name = "TUESDAY", @ParenthesisDepth = 0, @Parenthesized = false] | | | +- NumericLiteral[@Base = 10, @CompileTimeConstant = true, @DoubleLiteral = false, @FloatLiteral = false, @Image = "7", @IntLiteral = true, @Integral = true, @LiteralText = "7", @LongLiteral = false, @ParenthesisDepth = 0, @Parenthesized = false, @ValueAsDouble = 7.0, @ValueAsFloat = 7.0, @ValueAsInt = 7, @ValueAsLong = 7] | | +- SwitchArrowBranch[@Default = false] - | | | +- SwitchLabel[@Default = false] + | | | +- SwitchLabel[@Default = false, @PatternLabel = false] | | | | +- VariableAccess[@AccessType = AccessType.READ, @CompileTimeConstant = true, @Image = "THURSDAY", @Name = "THURSDAY", @ParenthesisDepth = 0, @Parenthesized = false] | | | | +- VariableAccess[@AccessType = AccessType.READ, @CompileTimeConstant = true, @Image = "SATURDAY", @Name = "SATURDAY", @ParenthesisDepth = 0, @Parenthesized = false] | | | +- NumericLiteral[@Base = 10, @CompileTimeConstant = true, @DoubleLiteral = false, @FloatLiteral = false, @Image = "8", @IntLiteral = true, @Integral = true, @LiteralText = "8", @LongLiteral = false, @ParenthesisDepth = 0, @Parenthesized = false, @ValueAsDouble = 8.0, @ValueAsFloat = 8.0, @ValueAsInt = 8, @ValueAsLong = 8] | | +- SwitchArrowBranch[@Default = false] - | | | +- SwitchLabel[@Default = false] + | | | +- SwitchLabel[@Default = false, @PatternLabel = false] | | | | +- VariableAccess[@AccessType = AccessType.READ, @CompileTimeConstant = true, @Image = "WEDNESDAY", @Name = "WEDNESDAY", @ParenthesisDepth = 0, @Parenthesized = false] | | | +- NumericLiteral[@Base = 10, @CompileTimeConstant = true, @DoubleLiteral = false, @FloatLiteral = false, @Image = "9", @IntLiteral = true, @Integral = true, @LiteralText = "9", @LongLiteral = false, @ParenthesisDepth = 0, @Parenthesized = false, @ValueAsDouble = 9.0, @ValueAsFloat = 9.0, @ValueAsInt = 9, @ValueAsLong = 9] | | +- SwitchArrowBranch[@Default = true] - | | +- SwitchLabel[@Default = true] + | | +- SwitchLabel[@Default = true, @PatternLabel = false] | | +- Block[@Empty = false, @Size = 3, @containsComment = false] | | +- LocalVariableDeclaration[@EffectiveVisibility = Visibility.V_LOCAL, @Final = false, @TypeInferred = false, @Visibility = Visibility.V_LOCAL] | | | +- ModifierList[@EffectiveModifiers = (), @ExplicitModifiers = ()] diff --git a/pmd-java/src/test/resources/net/sourceforge/pmd/lang/java/ast/jdkversiontests/java14/SwitchExpressions.txt b/pmd-java/src/test/resources/net/sourceforge/pmd/lang/java/ast/jdkversiontests/java14/SwitchExpressions.txt index 029dca3fd9..72c512b849 100644 --- a/pmd-java/src/test/resources/net/sourceforge/pmd/lang/java/ast/jdkversiontests/java14/SwitchExpressions.txt +++ b/pmd-java/src/test/resources/net/sourceforge/pmd/lang/java/ast/jdkversiontests/java14/SwitchExpressions.txt @@ -55,7 +55,7 @@ | +- SwitchStatement[@DefaultCase = false, @EnumSwitch = true, @ExhaustiveEnumSwitch = true, @FallthroughSwitch = false] | | +- VariableAccess[@AccessType = AccessType.READ, @CompileTimeConstant = false, @Image = "day", @Name = "day", @ParenthesisDepth = 0, @Parenthesized = false] | | +- SwitchArrowBranch[@Default = false] - | | | +- SwitchLabel[@Default = false] + | | | +- SwitchLabel[@Default = false, @PatternLabel = false] | | | | +- VariableAccess[@AccessType = AccessType.READ, @CompileTimeConstant = false, @Image = "MONDAY", @Name = "MONDAY", @ParenthesisDepth = 0, @Parenthesized = false] | | | | +- VariableAccess[@AccessType = AccessType.READ, @CompileTimeConstant = false, @Image = "FRIDAY", @Name = "FRIDAY", @ParenthesisDepth = 0, @Parenthesized = false] | | | | +- VariableAccess[@AccessType = AccessType.READ, @CompileTimeConstant = false, @Image = "SUNDAY", @Name = "SUNDAY", @ParenthesisDepth = 0, @Parenthesized = false] @@ -66,7 +66,7 @@ | | | +- ArgumentList[@Empty = false, @Size = 1] | | | +- NumericLiteral[@Base = 10, @CompileTimeConstant = true, @DoubleLiteral = false, @FloatLiteral = false, @Image = "6", @IntLiteral = true, @Integral = true, @LiteralText = "6", @LongLiteral = false, @ParenthesisDepth = 0, @Parenthesized = false, @ValueAsDouble = 6.0, @ValueAsFloat = 6.0, @ValueAsInt = 6, @ValueAsLong = 6] | | +- SwitchArrowBranch[@Default = false] - | | | +- SwitchLabel[@Default = false] + | | | +- SwitchLabel[@Default = false, @PatternLabel = false] | | | | +- VariableAccess[@AccessType = AccessType.READ, @CompileTimeConstant = false, @Image = "TUESDAY", @Name = "TUESDAY", @ParenthesisDepth = 0, @Parenthesized = false] | | | +- MethodCall[@CompileTimeConstant = false, @Image = "println", @MethodName = "println", @ParenthesisDepth = 0, @Parenthesized = false] | | | +- FieldAccess[@AccessType = AccessType.READ, @CompileTimeConstant = false, @Image = "out", @Name = "out", @ParenthesisDepth = 0, @Parenthesized = false] @@ -75,7 +75,7 @@ | | | +- ArgumentList[@Empty = false, @Size = 1] | | | +- NumericLiteral[@Base = 10, @CompileTimeConstant = true, @DoubleLiteral = false, @FloatLiteral = false, @Image = "7", @IntLiteral = true, @Integral = true, @LiteralText = "7", @LongLiteral = false, @ParenthesisDepth = 0, @Parenthesized = false, @ValueAsDouble = 7.0, @ValueAsFloat = 7.0, @ValueAsInt = 7, @ValueAsLong = 7] | | +- SwitchArrowBranch[@Default = false] - | | | +- SwitchLabel[@Default = false] + | | | +- SwitchLabel[@Default = false, @PatternLabel = false] | | | | +- VariableAccess[@AccessType = AccessType.READ, @CompileTimeConstant = false, @Image = "THURSDAY", @Name = "THURSDAY", @ParenthesisDepth = 0, @Parenthesized = false] | | | | +- VariableAccess[@AccessType = AccessType.READ, @CompileTimeConstant = false, @Image = "SATURDAY", @Name = "SATURDAY", @ParenthesisDepth = 0, @Parenthesized = false] | | | +- MethodCall[@CompileTimeConstant = false, @Image = "println", @MethodName = "println", @ParenthesisDepth = 0, @Parenthesized = false] @@ -85,7 +85,7 @@ | | | +- ArgumentList[@Empty = false, @Size = 1] | | | +- NumericLiteral[@Base = 10, @CompileTimeConstant = true, @DoubleLiteral = false, @FloatLiteral = false, @Image = "8", @IntLiteral = true, @Integral = true, @LiteralText = "8", @LongLiteral = false, @ParenthesisDepth = 0, @Parenthesized = false, @ValueAsDouble = 8.0, @ValueAsFloat = 8.0, @ValueAsInt = 8, @ValueAsLong = 8] | | +- SwitchArrowBranch[@Default = false] - | | +- SwitchLabel[@Default = false] + | | +- SwitchLabel[@Default = false, @PatternLabel = false] | | | +- VariableAccess[@AccessType = AccessType.READ, @CompileTimeConstant = false, @Image = "WEDNESDAY", @Name = "WEDNESDAY", @ParenthesisDepth = 0, @Parenthesized = false] | | +- MethodCall[@CompileTimeConstant = false, @Image = "println", @MethodName = "println", @ParenthesisDepth = 0, @Parenthesized = false] | | +- FieldAccess[@AccessType = AccessType.READ, @CompileTimeConstant = false, @Image = "out", @Name = "out", @ParenthesisDepth = 0, @Parenthesized = false] @@ -101,22 +101,22 @@ | | +- SwitchExpression[@CompileTimeConstant = false, @DefaultCase = false, @EnumSwitch = true, @ExhaustiveEnumSwitch = true, @FallthroughSwitch = false, @ParenthesisDepth = 0, @Parenthesized = false] | | +- VariableAccess[@AccessType = AccessType.READ, @CompileTimeConstant = false, @Image = "day", @Name = "day", @ParenthesisDepth = 0, @Parenthesized = false] | | +- SwitchArrowBranch[@Default = false] - | | | +- SwitchLabel[@Default = false] + | | | +- SwitchLabel[@Default = false, @PatternLabel = false] | | | | +- VariableAccess[@AccessType = AccessType.READ, @CompileTimeConstant = false, @Image = "MONDAY", @Name = "MONDAY", @ParenthesisDepth = 0, @Parenthesized = false] | | | | +- VariableAccess[@AccessType = AccessType.READ, @CompileTimeConstant = false, @Image = "FRIDAY", @Name = "FRIDAY", @ParenthesisDepth = 0, @Parenthesized = false] | | | | +- VariableAccess[@AccessType = AccessType.READ, @CompileTimeConstant = false, @Image = "SUNDAY", @Name = "SUNDAY", @ParenthesisDepth = 0, @Parenthesized = false] | | | +- NumericLiteral[@Base = 10, @CompileTimeConstant = true, @DoubleLiteral = false, @FloatLiteral = false, @Image = "6", @IntLiteral = true, @Integral = true, @LiteralText = "6", @LongLiteral = false, @ParenthesisDepth = 0, @Parenthesized = false, @ValueAsDouble = 6.0, @ValueAsFloat = 6.0, @ValueAsInt = 6, @ValueAsLong = 6] | | +- SwitchArrowBranch[@Default = false] - | | | +- SwitchLabel[@Default = false] + | | | +- SwitchLabel[@Default = false, @PatternLabel = false] | | | | +- VariableAccess[@AccessType = AccessType.READ, @CompileTimeConstant = false, @Image = "TUESDAY", @Name = "TUESDAY", @ParenthesisDepth = 0, @Parenthesized = false] | | | +- NumericLiteral[@Base = 10, @CompileTimeConstant = true, @DoubleLiteral = false, @FloatLiteral = false, @Image = "7", @IntLiteral = true, @Integral = true, @LiteralText = "7", @LongLiteral = false, @ParenthesisDepth = 0, @Parenthesized = false, @ValueAsDouble = 7.0, @ValueAsFloat = 7.0, @ValueAsInt = 7, @ValueAsLong = 7] | | +- SwitchArrowBranch[@Default = false] - | | | +- SwitchLabel[@Default = false] + | | | +- SwitchLabel[@Default = false, @PatternLabel = false] | | | | +- VariableAccess[@AccessType = AccessType.READ, @CompileTimeConstant = false, @Image = "THURSDAY", @Name = "THURSDAY", @ParenthesisDepth = 0, @Parenthesized = false] | | | | +- VariableAccess[@AccessType = AccessType.READ, @CompileTimeConstant = false, @Image = "SATURDAY", @Name = "SATURDAY", @ParenthesisDepth = 0, @Parenthesized = false] | | | +- NumericLiteral[@Base = 10, @CompileTimeConstant = true, @DoubleLiteral = false, @FloatLiteral = false, @Image = "8", @IntLiteral = true, @Integral = true, @LiteralText = "8", @LongLiteral = false, @ParenthesisDepth = 0, @Parenthesized = false, @ValueAsDouble = 8.0, @ValueAsFloat = 8.0, @ValueAsInt = 8, @ValueAsLong = 8] | | +- SwitchArrowBranch[@Default = false] - | | +- SwitchLabel[@Default = false] + | | +- SwitchLabel[@Default = false, @PatternLabel = false] | | | +- VariableAccess[@AccessType = AccessType.READ, @CompileTimeConstant = false, @Image = "WEDNESDAY", @Name = "WEDNESDAY", @ParenthesisDepth = 0, @Parenthesized = false] | | +- NumericLiteral[@Base = 10, @CompileTimeConstant = true, @DoubleLiteral = false, @FloatLiteral = false, @Image = "9", @IntLiteral = true, @Integral = true, @LiteralText = "9", @LongLiteral = false, @ParenthesisDepth = 0, @Parenthesized = false, @ValueAsDouble = 9.0, @ValueAsFloat = 9.0, @ValueAsInt = 9, @ValueAsLong = 9] | +- ExpressionStatement[] @@ -159,15 +159,15 @@ | | +- SwitchExpression[@CompileTimeConstant = false, @DefaultCase = true, @EnumSwitch = true, @ExhaustiveEnumSwitch = false, @FallthroughSwitch = false, @ParenthesisDepth = 0, @Parenthesized = false] | | +- VariableAccess[@AccessType = AccessType.READ, @CompileTimeConstant = false, @Image = "day", @Name = "day", @ParenthesisDepth = 0, @Parenthesized = false] | | +- SwitchArrowBranch[@Default = false] - | | | +- SwitchLabel[@Default = false] + | | | +- SwitchLabel[@Default = false, @PatternLabel = false] | | | | +- VariableAccess[@AccessType = AccessType.READ, @CompileTimeConstant = false, @Image = "MONDAY", @Name = "MONDAY", @ParenthesisDepth = 0, @Parenthesized = false] | | | +- NumericLiteral[@Base = 10, @CompileTimeConstant = true, @DoubleLiteral = false, @FloatLiteral = false, @Image = "0", @IntLiteral = true, @Integral = true, @LiteralText = "0", @LongLiteral = false, @ParenthesisDepth = 0, @Parenthesized = false, @ValueAsDouble = 0.0, @ValueAsFloat = 0.0, @ValueAsInt = 0, @ValueAsLong = 0] | | +- SwitchArrowBranch[@Default = false] - | | | +- SwitchLabel[@Default = false] + | | | +- SwitchLabel[@Default = false, @PatternLabel = false] | | | | +- VariableAccess[@AccessType = AccessType.READ, @CompileTimeConstant = false, @Image = "TUESDAY", @Name = "TUESDAY", @ParenthesisDepth = 0, @Parenthesized = false] | | | +- NumericLiteral[@Base = 10, @CompileTimeConstant = true, @DoubleLiteral = false, @FloatLiteral = false, @Image = "1", @IntLiteral = true, @Integral = true, @LiteralText = "1", @LongLiteral = false, @ParenthesisDepth = 0, @Parenthesized = false, @ValueAsDouble = 1.0, @ValueAsFloat = 1.0, @ValueAsInt = 1, @ValueAsLong = 1] | | +- SwitchArrowBranch[@Default = true] - | | +- SwitchLabel[@Default = true] + | | +- SwitchLabel[@Default = true, @PatternLabel = false] | | +- Block[@Empty = false, @Size = 3, @containsComment = false] | | +- LocalVariableDeclaration[@EffectiveVisibility = Visibility.V_LOCAL, @Final = false, @TypeInferred = false, @Visibility = Visibility.V_LOCAL] | | | +- ModifierList[@EffectiveModifiers = (), @ExplicitModifiers = ()] @@ -211,24 +211,24 @@ | | +- SwitchExpression[@CompileTimeConstant = false, @DefaultCase = true, @EnumSwitch = false, @ExhaustiveEnumSwitch = false, @FallthroughSwitch = true, @ParenthesisDepth = 0, @Parenthesized = false] | | +- VariableAccess[@AccessType = AccessType.READ, @CompileTimeConstant = false, @Image = "s", @Name = "s", @ParenthesisDepth = 0, @Parenthesized = false] | | +- SwitchFallthroughBranch[@Default = false] - | | | +- SwitchLabel[@Default = false] + | | | +- SwitchLabel[@Default = false, @PatternLabel = false] | | | | +- StringLiteral[@CompileTimeConstant = true, @ConstValue = "Foo", @Empty = false, @Image = "\"Foo\"", @Length = 3, @LiteralText = "\"Foo\"", @ParenthesisDepth = 0, @Parenthesized = false, @TextBlock = false] | | | +- YieldStatement[] | | | +- NumericLiteral[@Base = 10, @CompileTimeConstant = true, @DoubleLiteral = false, @FloatLiteral = false, @Image = "1", @IntLiteral = true, @Integral = true, @LiteralText = "1", @LongLiteral = false, @ParenthesisDepth = 0, @Parenthesized = false, @ValueAsDouble = 1.0, @ValueAsFloat = 1.0, @ValueAsInt = 1, @ValueAsLong = 1] | | +- SwitchFallthroughBranch[@Default = false] - | | | +- SwitchLabel[@Default = false] + | | | +- SwitchLabel[@Default = false, @PatternLabel = false] | | | | +- StringLiteral[@CompileTimeConstant = true, @ConstValue = "Bar", @Empty = false, @Image = "\"Bar\"", @Length = 3, @LiteralText = "\"Bar\"", @ParenthesisDepth = 0, @Parenthesized = false, @TextBlock = false] | | | +- YieldStatement[] | | | +- NumericLiteral[@Base = 10, @CompileTimeConstant = true, @DoubleLiteral = false, @FloatLiteral = false, @Image = "2", @IntLiteral = true, @Integral = true, @LiteralText = "2", @LongLiteral = false, @ParenthesisDepth = 0, @Parenthesized = false, @ValueAsDouble = 2.0, @ValueAsFloat = 2.0, @ValueAsInt = 2, @ValueAsLong = 2] | | +- SwitchFallthroughBranch[@Default = false] - | | | +- SwitchLabel[@Default = false] + | | | +- SwitchLabel[@Default = false, @PatternLabel = false] | | | | +- StringLiteral[@CompileTimeConstant = true, @ConstValue = "Baz", @Empty = false, @Image = "\"Baz\"", @Length = 3, @LiteralText = "\"Baz\"", @ParenthesisDepth = 0, @Parenthesized = false, @TextBlock = false] | | | +- YieldStatement[] | | | +- FieldAccess[@AccessType = AccessType.READ, @CompileTimeConstant = true, @Image = "BAZ", @Name = "BAZ", @ParenthesisDepth = 0, @Parenthesized = false] | | | +- TypeExpression[@CompileTimeConstant = false, @ParenthesisDepth = 0, @Parenthesized = false] | | | +- ClassType[@FullyQualified = false, @PackageQualifier = null, @SimpleName = "SwitchExpressions"] | | +- SwitchFallthroughBranch[@Default = true] - | | +- SwitchLabel[@Default = true] + | | +- SwitchLabel[@Default = true, @PatternLabel = false] | | +- ExpressionStatement[] | | | +- MethodCall[@CompileTimeConstant = false, @Image = "println", @MethodName = "println", @ParenthesisDepth = 0, @Parenthesized = false] | | | +- FieldAccess[@AccessType = AccessType.READ, @CompileTimeConstant = false, @Image = "out", @Name = "out", @ParenthesisDepth = 0, @Parenthesized = false] @@ -258,7 +258,7 @@ | +- SwitchStatement[@DefaultCase = true, @EnumSwitch = false, @ExhaustiveEnumSwitch = false, @FallthroughSwitch = false] | +- VariableAccess[@AccessType = AccessType.READ, @CompileTimeConstant = false, @Image = "k", @Name = "k", @ParenthesisDepth = 0, @Parenthesized = false] | +- SwitchArrowBranch[@Default = false] - | | +- SwitchLabel[@Default = false] + | | +- SwitchLabel[@Default = false, @PatternLabel = false] | | | +- NumericLiteral[@Base = 10, @CompileTimeConstant = true, @DoubleLiteral = false, @FloatLiteral = false, @Image = "1", @IntLiteral = true, @Integral = true, @LiteralText = "1", @LongLiteral = false, @ParenthesisDepth = 0, @Parenthesized = false, @ValueAsDouble = 1.0, @ValueAsFloat = 1.0, @ValueAsInt = 1, @ValueAsLong = 1] | | +- MethodCall[@CompileTimeConstant = false, @Image = "println", @MethodName = "println", @ParenthesisDepth = 0, @Parenthesized = false] | | +- FieldAccess[@AccessType = AccessType.READ, @CompileTimeConstant = false, @Image = "out", @Name = "out", @ParenthesisDepth = 0, @Parenthesized = false] @@ -267,7 +267,7 @@ | | +- ArgumentList[@Empty = false, @Size = 1] | | +- StringLiteral[@CompileTimeConstant = true, @ConstValue = "one", @Empty = false, @Image = "\"one\"", @Length = 3, @LiteralText = "\"one\"", @ParenthesisDepth = 0, @Parenthesized = false, @TextBlock = false] | +- SwitchArrowBranch[@Default = false] - | | +- SwitchLabel[@Default = false] + | | +- SwitchLabel[@Default = false, @PatternLabel = false] | | | +- NumericLiteral[@Base = 10, @CompileTimeConstant = true, @DoubleLiteral = false, @FloatLiteral = false, @Image = "2", @IntLiteral = true, @Integral = true, @LiteralText = "2", @LongLiteral = false, @ParenthesisDepth = 0, @Parenthesized = false, @ValueAsDouble = 2.0, @ValueAsFloat = 2.0, @ValueAsInt = 2, @ValueAsLong = 2] | | +- MethodCall[@CompileTimeConstant = false, @Image = "println", @MethodName = "println", @ParenthesisDepth = 0, @Parenthesized = false] | | +- FieldAccess[@AccessType = AccessType.READ, @CompileTimeConstant = false, @Image = "out", @Name = "out", @ParenthesisDepth = 0, @Parenthesized = false] @@ -276,7 +276,7 @@ | | +- ArgumentList[@Empty = false, @Size = 1] | | +- StringLiteral[@CompileTimeConstant = true, @ConstValue = "two", @Empty = false, @Image = "\"two\"", @Length = 3, @LiteralText = "\"two\"", @ParenthesisDepth = 0, @Parenthesized = false, @TextBlock = false] | +- SwitchArrowBranch[@Default = true] - | +- SwitchLabel[@Default = true] + | +- SwitchLabel[@Default = true, @PatternLabel = false] | +- MethodCall[@CompileTimeConstant = false, @Image = "println", @MethodName = "println", @ParenthesisDepth = 0, @Parenthesized = false] | +- FieldAccess[@AccessType = AccessType.READ, @CompileTimeConstant = false, @Image = "out", @Name = "out", @ParenthesisDepth = 0, @Parenthesized = false] | | +- TypeExpression[@CompileTimeConstant = false, @ParenthesisDepth = 0, @Parenthesized = false] @@ -301,15 +301,15 @@ | +- SwitchExpression[@CompileTimeConstant = false, @DefaultCase = true, @EnumSwitch = false, @ExhaustiveEnumSwitch = false, @FallthroughSwitch = false, @ParenthesisDepth = 0, @Parenthesized = false] | +- VariableAccess[@AccessType = AccessType.READ, @CompileTimeConstant = false, @Image = "k", @Name = "k", @ParenthesisDepth = 0, @Parenthesized = false] | +- SwitchArrowBranch[@Default = false] - | | +- SwitchLabel[@Default = false] + | | +- SwitchLabel[@Default = false, @PatternLabel = false] | | | +- NumericLiteral[@Base = 10, @CompileTimeConstant = true, @DoubleLiteral = false, @FloatLiteral = false, @Image = "1", @IntLiteral = true, @Integral = true, @LiteralText = "1", @LongLiteral = false, @ParenthesisDepth = 0, @Parenthesized = false, @ValueAsDouble = 1.0, @ValueAsFloat = 1.0, @ValueAsInt = 1, @ValueAsLong = 1] | | +- StringLiteral[@CompileTimeConstant = true, @ConstValue = "one", @Empty = false, @Image = "\"one\"", @Length = 3, @LiteralText = "\"one\"", @ParenthesisDepth = 0, @Parenthesized = false, @TextBlock = false] | +- SwitchArrowBranch[@Default = false] - | | +- SwitchLabel[@Default = false] + | | +- SwitchLabel[@Default = false, @PatternLabel = false] | | | +- NumericLiteral[@Base = 10, @CompileTimeConstant = true, @DoubleLiteral = false, @FloatLiteral = false, @Image = "2", @IntLiteral = true, @Integral = true, @LiteralText = "2", @LongLiteral = false, @ParenthesisDepth = 0, @Parenthesized = false, @ValueAsDouble = 2.0, @ValueAsFloat = 2.0, @ValueAsInt = 2, @ValueAsLong = 2] | | +- StringLiteral[@CompileTimeConstant = true, @ConstValue = "two", @Empty = false, @Image = "\"two\"", @Length = 3, @LiteralText = "\"two\"", @ParenthesisDepth = 0, @Parenthesized = false, @TextBlock = false] | +- SwitchArrowBranch[@Default = true] - | +- SwitchLabel[@Default = true] + | +- SwitchLabel[@Default = true, @PatternLabel = false] | +- StringLiteral[@CompileTimeConstant = true, @ConstValue = "many", @Empty = false, @Image = "\"many\"", @Length = 4, @LiteralText = "\"many\"", @ParenthesisDepth = 0, @Parenthesized = false, @TextBlock = false] +- MethodDeclaration[@Abstract = false, @Arity = 1, @EffectiveVisibility = Visibility.V_PRIVATE, @Final = false, @Name = "f", @Overridden = false, @Static = true, @Varargs = false, @Visibility = Visibility.V_PRIVATE, @Void = false] +- ModifierList[@EffectiveModifiers = (JModifier.PRIVATE, JModifier.STATIC), @ExplicitModifiers = (JModifier.PRIVATE, JModifier.STATIC)] diff --git a/pmd-java/src/test/resources/net/sourceforge/pmd/lang/java/ast/jdkversiontests/java14/SwitchRules.txt b/pmd-java/src/test/resources/net/sourceforge/pmd/lang/java/ast/jdkversiontests/java14/SwitchRules.txt index 812fecf840..4eb465db71 100644 --- a/pmd-java/src/test/resources/net/sourceforge/pmd/lang/java/ast/jdkversiontests/java14/SwitchRules.txt +++ b/pmd-java/src/test/resources/net/sourceforge/pmd/lang/java/ast/jdkversiontests/java14/SwitchRules.txt @@ -65,7 +65,7 @@ +- SwitchStatement[@DefaultCase = true, @EnumSwitch = false, @ExhaustiveEnumSwitch = false, @FallthroughSwitch = false] +- VariableAccess[@AccessType = AccessType.READ, @CompileTimeConstant = false, @Image = "day", @Name = "day", @ParenthesisDepth = 0, @Parenthesized = false] +- SwitchArrowBranch[@Default = false] - | +- SwitchLabel[@Default = false] + | +- SwitchLabel[@Default = false, @PatternLabel = false] | | +- VariableAccess[@AccessType = AccessType.READ, @CompileTimeConstant = true, @Image = "MONDAY", @Name = "MONDAY", @ParenthesisDepth = 0, @Parenthesized = false] | | +- VariableAccess[@AccessType = AccessType.READ, @CompileTimeConstant = true, @Image = "FRIDAY", @Name = "FRIDAY", @ParenthesisDepth = 0, @Parenthesized = false] | | +- VariableAccess[@AccessType = AccessType.READ, @CompileTimeConstant = true, @Image = "SUNDAY", @Name = "SUNDAY", @ParenthesisDepth = 0, @Parenthesized = false] @@ -76,7 +76,7 @@ | +- ArgumentList[@Empty = false, @Size = 1] | +- StringLiteral[@CompileTimeConstant = true, @ConstValue = " 6", @Empty = false, @Image = "\" 6\"", @Length = 3, @LiteralText = "\" 6\"", @ParenthesisDepth = 0, @Parenthesized = false, @TextBlock = false] +- SwitchArrowBranch[@Default = false] - | +- SwitchLabel[@Default = false] + | +- SwitchLabel[@Default = false, @PatternLabel = false] | | +- VariableAccess[@AccessType = AccessType.READ, @CompileTimeConstant = true, @Image = "TUESDAY", @Name = "TUESDAY", @ParenthesisDepth = 0, @Parenthesized = false] | +- MethodCall[@CompileTimeConstant = false, @Image = "println", @MethodName = "println", @ParenthesisDepth = 0, @Parenthesized = false] | +- FieldAccess[@AccessType = AccessType.READ, @CompileTimeConstant = false, @Image = "out", @Name = "out", @ParenthesisDepth = 0, @Parenthesized = false] @@ -85,7 +85,7 @@ | +- ArgumentList[@Empty = false, @Size = 1] | +- StringLiteral[@CompileTimeConstant = true, @ConstValue = " 7", @Empty = false, @Image = "\" 7\"", @Length = 3, @LiteralText = "\" 7\"", @ParenthesisDepth = 0, @Parenthesized = false, @TextBlock = false] +- SwitchArrowBranch[@Default = false] - | +- SwitchLabel[@Default = false] + | +- SwitchLabel[@Default = false, @PatternLabel = false] | | +- VariableAccess[@AccessType = AccessType.READ, @CompileTimeConstant = true, @Image = "THURSDAY", @Name = "THURSDAY", @ParenthesisDepth = 0, @Parenthesized = false] | | +- VariableAccess[@AccessType = AccessType.READ, @CompileTimeConstant = true, @Image = "SATURDAY", @Name = "SATURDAY", @ParenthesisDepth = 0, @Parenthesized = false] | +- MethodCall[@CompileTimeConstant = false, @Image = "println", @MethodName = "println", @ParenthesisDepth = 0, @Parenthesized = false] @@ -95,7 +95,7 @@ | +- ArgumentList[@Empty = false, @Size = 1] | +- StringLiteral[@CompileTimeConstant = true, @ConstValue = " 8", @Empty = false, @Image = "\" 8\"", @Length = 3, @LiteralText = "\" 8\"", @ParenthesisDepth = 0, @Parenthesized = false, @TextBlock = false] +- SwitchArrowBranch[@Default = false] - | +- SwitchLabel[@Default = false] + | +- SwitchLabel[@Default = false, @PatternLabel = false] | | +- VariableAccess[@AccessType = AccessType.READ, @CompileTimeConstant = true, @Image = "WEDNESDAY", @Name = "WEDNESDAY", @ParenthesisDepth = 0, @Parenthesized = false] | +- Block[@Empty = false, @Size = 1, @containsComment = false] | +- ExpressionStatement[] @@ -106,7 +106,7 @@ | +- ArgumentList[@Empty = false, @Size = 1] | +- StringLiteral[@CompileTimeConstant = true, @ConstValue = " 9", @Empty = false, @Image = "\" 9\"", @Length = 3, @LiteralText = "\" 9\"", @ParenthesisDepth = 0, @Parenthesized = false, @TextBlock = false] +- SwitchArrowBranch[@Default = true] - +- SwitchLabel[@Default = true] + +- SwitchLabel[@Default = true, @PatternLabel = false] +- ThrowStatement[] +- ConstructorCall[@AnonymousClass = false, @CompileTimeConstant = false, @DiamondTypeArgs = false, @MethodName = "new", @ParenthesisDepth = 0, @Parenthesized = false, @QualifiedInstanceCreation = false] +- ClassType[@FullyQualified = false, @PackageQualifier = null, @SimpleName = "IllegalArgumentException"] diff --git a/pmd-java/src/test/resources/net/sourceforge/pmd/lang/java/ast/jdkversiontests/java14/YieldStatements.txt b/pmd-java/src/test/resources/net/sourceforge/pmd/lang/java/ast/jdkversiontests/java14/YieldStatements.txt index bbab68e109..766c74cde2 100644 --- a/pmd-java/src/test/resources/net/sourceforge/pmd/lang/java/ast/jdkversiontests/java14/YieldStatements.txt +++ b/pmd-java/src/test/resources/net/sourceforge/pmd/lang/java/ast/jdkversiontests/java14/YieldStatements.txt @@ -29,7 +29,7 @@ +- SwitchExpression[@CompileTimeConstant = false, @DefaultCase = false, @EnumSwitch = false, @ExhaustiveEnumSwitch = false, @FallthroughSwitch = false, @ParenthesisDepth = 0, @Parenthesized = false] +- VariableAccess[@AccessType = AccessType.READ, @CompileTimeConstant = false, @Image = "e", @Name = "e", @ParenthesisDepth = 0, @Parenthesized = false] +- SwitchArrowBranch[@Default = false] - +- SwitchLabel[@Default = false] + +- SwitchLabel[@Default = false, @PatternLabel = false] | +- NumericLiteral[@Base = 10, @CompileTimeConstant = true, @DoubleLiteral = false, @FloatLiteral = false, @Image = "1", @IntLiteral = true, @Integral = true, @LiteralText = "1", @LongLiteral = false, @ParenthesisDepth = 0, @Parenthesized = false, @ValueAsDouble = 1.0, @ValueAsFloat = 1.0, @ValueAsInt = 1, @ValueAsLong = 1] +- Block[@Empty = false, @Size = 12, @containsComment = true] +- ExpressionStatement[] @@ -67,7 +67,7 @@ | +- SwitchExpression[@CompileTimeConstant = false, @DefaultCase = false, @EnumSwitch = false, @ExhaustiveEnumSwitch = false, @FallthroughSwitch = false, @ParenthesisDepth = 0, @Parenthesized = false] | +- VariableAccess[@AccessType = AccessType.READ, @CompileTimeConstant = false, @Image = "foo", @Name = "foo", @ParenthesisDepth = 0, @Parenthesized = false] | +- SwitchArrowBranch[@Default = false] - | +- SwitchLabel[@Default = false] + | +- SwitchLabel[@Default = false, @PatternLabel = false] | | +- NumericLiteral[@Base = 10, @CompileTimeConstant = true, @DoubleLiteral = false, @FloatLiteral = false, @Image = "4", @IntLiteral = true, @Integral = true, @LiteralText = "4", @LongLiteral = false, @ParenthesisDepth = 0, @Parenthesized = false, @ValueAsDouble = 4.0, @ValueAsFloat = 4.0, @ValueAsInt = 4, @ValueAsLong = 4] | +- Block[@Empty = false, @Size = 1, @containsComment = false] | +- YieldStatement[] diff --git a/pmd-java/src/test/resources/net/sourceforge/pmd/lang/java/ast/jdkversiontests/java21/DealingWithNull.txt b/pmd-java/src/test/resources/net/sourceforge/pmd/lang/java/ast/jdkversiontests/java21/DealingWithNull.txt index fe8144121b..1eb5bde018 100644 --- a/pmd-java/src/test/resources/net/sourceforge/pmd/lang/java/ast/jdkversiontests/java21/DealingWithNull.txt +++ b/pmd-java/src/test/resources/net/sourceforge/pmd/lang/java/ast/jdkversiontests/java21/DealingWithNull.txt @@ -14,7 +14,7 @@ | +- SwitchStatement[@DefaultCase = true, @EnumSwitch = false, @ExhaustiveEnumSwitch = false, @FallthroughSwitch = false] | +- VariableAccess[@AccessType = AccessType.READ, @CompileTimeConstant = false, @Image = "s", @Name = "s", @ParenthesisDepth = 0, @Parenthesized = false] | +- SwitchArrowBranch[@Default = false] - | | +- SwitchLabel[@Default = false] + | | +- SwitchLabel[@Default = false, @PatternLabel = false] | | | +- NullLiteral[@CompileTimeConstant = false, @LiteralText = "null", @ParenthesisDepth = 0, @Parenthesized = false] | | +- MethodCall[@CompileTimeConstant = false, @Image = "println", @MethodName = "println", @ParenthesisDepth = 0, @Parenthesized = false] | | +- FieldAccess[@AccessType = AccessType.READ, @CompileTimeConstant = false, @Image = "out", @Name = "out", @ParenthesisDepth = 0, @Parenthesized = false] @@ -23,7 +23,7 @@ | | +- ArgumentList[@Empty = false, @Size = 1] | | +- StringLiteral[@CompileTimeConstant = true, @ConstValue = "Oops", @Empty = false, @Image = "\"Oops\"", @Length = 4, @LiteralText = "\"Oops\"", @ParenthesisDepth = 0, @Parenthesized = false, @TextBlock = false] | +- SwitchArrowBranch[@Default = false] - | | +- SwitchLabel[@Default = false] + | | +- SwitchLabel[@Default = false, @PatternLabel = false] | | | +- StringLiteral[@CompileTimeConstant = true, @ConstValue = "Foo", @Empty = false, @Image = "\"Foo\"", @Length = 3, @LiteralText = "\"Foo\"", @ParenthesisDepth = 0, @Parenthesized = false, @TextBlock = false] | | | +- StringLiteral[@CompileTimeConstant = true, @ConstValue = "Bar", @Empty = false, @Image = "\"Bar\"", @Length = 3, @LiteralText = "\"Bar\"", @ParenthesisDepth = 0, @Parenthesized = false, @TextBlock = false] | | +- MethodCall[@CompileTimeConstant = false, @Image = "println", @MethodName = "println", @ParenthesisDepth = 0, @Parenthesized = false] @@ -33,7 +33,7 @@ | | +- ArgumentList[@Empty = false, @Size = 1] | | +- StringLiteral[@CompileTimeConstant = true, @ConstValue = "Great", @Empty = false, @Image = "\"Great\"", @Length = 5, @LiteralText = "\"Great\"", @ParenthesisDepth = 0, @Parenthesized = false, @TextBlock = false] | +- SwitchArrowBranch[@Default = true] - | +- SwitchLabel[@Default = true] + | +- SwitchLabel[@Default = true, @PatternLabel = false] | +- MethodCall[@CompileTimeConstant = false, @Image = "println", @MethodName = "println", @ParenthesisDepth = 0, @Parenthesized = false] | +- FieldAccess[@AccessType = AccessType.READ, @CompileTimeConstant = false, @Image = "out", @Name = "out", @ParenthesisDepth = 0, @Parenthesized = false] | | +- TypeExpression[@CompileTimeConstant = false, @ParenthesisDepth = 0, @Parenthesized = false] @@ -52,7 +52,7 @@ | +- SwitchStatement[@DefaultCase = true, @EnumSwitch = false, @ExhaustiveEnumSwitch = false, @FallthroughSwitch = false] | +- VariableAccess[@AccessType = AccessType.READ, @CompileTimeConstant = false, @Image = "o", @Name = "o", @ParenthesisDepth = 0, @Parenthesized = false] | +- SwitchArrowBranch[@Default = false] - | | +- SwitchLabel[@Default = false] + | | +- SwitchLabel[@Default = false, @PatternLabel = true] | | | +- TypePattern[@EffectiveVisibility = Visibility.V_PACKAGE, @Visibility = Visibility.V_PACKAGE] | | | +- ModifierList[@EffectiveModifiers = (), @ExplicitModifiers = ()] | | | +- ClassType[@FullyQualified = false, @PackageQualifier = null, @SimpleName = "String"] @@ -66,7 +66,7 @@ | | +- StringLiteral[@CompileTimeConstant = true, @ConstValue = "String: ", @Empty = false, @Image = "\"String: \"", @Length = 8, @LiteralText = "\"String: \"", @ParenthesisDepth = 0, @Parenthesized = false, @TextBlock = false] | | +- VariableAccess[@AccessType = AccessType.READ, @CompileTimeConstant = false, @Image = "s", @Name = "s", @ParenthesisDepth = 0, @Parenthesized = false] | +- SwitchArrowBranch[@Default = false] - | | +- SwitchLabel[@Default = false] + | | +- SwitchLabel[@Default = false, @PatternLabel = false] | | | +- NullLiteral[@CompileTimeConstant = false, @LiteralText = "null", @ParenthesisDepth = 0, @Parenthesized = false] | | +- MethodCall[@CompileTimeConstant = false, @Image = "println", @MethodName = "println", @ParenthesisDepth = 0, @Parenthesized = false] | | +- FieldAccess[@AccessType = AccessType.READ, @CompileTimeConstant = false, @Image = "out", @Name = "out", @ParenthesisDepth = 0, @Parenthesized = false] @@ -75,7 +75,7 @@ | | +- ArgumentList[@Empty = false, @Size = 1] | | +- StringLiteral[@CompileTimeConstant = true, @ConstValue = "null", @Empty = false, @Image = "\"null\"", @Length = 4, @LiteralText = "\"null\"", @ParenthesisDepth = 0, @Parenthesized = false, @TextBlock = false] | +- SwitchArrowBranch[@Default = true] - | +- SwitchLabel[@Default = true] + | +- SwitchLabel[@Default = true, @PatternLabel = false] | +- MethodCall[@CompileTimeConstant = false, @Image = "println", @MethodName = "println", @ParenthesisDepth = 0, @Parenthesized = false] | +- FieldAccess[@AccessType = AccessType.READ, @CompileTimeConstant = false, @Image = "out", @Name = "out", @ParenthesisDepth = 0, @Parenthesized = false] | | +- TypeExpression[@CompileTimeConstant = false, @ParenthesisDepth = 0, @Parenthesized = false] @@ -94,7 +94,7 @@ | +- SwitchStatement[@DefaultCase = true, @EnumSwitch = false, @ExhaustiveEnumSwitch = false, @FallthroughSwitch = false] | +- VariableAccess[@AccessType = AccessType.READ, @CompileTimeConstant = false, @Image = "o", @Name = "o", @ParenthesisDepth = 0, @Parenthesized = false] | +- SwitchArrowBranch[@Default = false] - | | +- SwitchLabel[@Default = false] + | | +- SwitchLabel[@Default = false, @PatternLabel = true] | | | +- TypePattern[@EffectiveVisibility = Visibility.V_PACKAGE, @Visibility = Visibility.V_PACKAGE] | | | +- ModifierList[@EffectiveModifiers = (), @ExplicitModifiers = ()] | | | +- ClassType[@FullyQualified = false, @PackageQualifier = null, @SimpleName = "String"] @@ -108,7 +108,7 @@ | | +- StringLiteral[@CompileTimeConstant = true, @ConstValue = "String: ", @Empty = false, @Image = "\"String: \"", @Length = 8, @LiteralText = "\"String: \"", @ParenthesisDepth = 0, @Parenthesized = false, @TextBlock = false] | | +- VariableAccess[@AccessType = AccessType.READ, @CompileTimeConstant = false, @Image = "s", @Name = "s", @ParenthesisDepth = 0, @Parenthesized = false] | +- SwitchArrowBranch[@Default = true] - | +- SwitchLabel[@Default = true] + | +- SwitchLabel[@Default = true, @PatternLabel = false] | | +- NullLiteral[@CompileTimeConstant = false, @LiteralText = "null", @ParenthesisDepth = 0, @Parenthesized = false] | +- MethodCall[@CompileTimeConstant = false, @Image = "println", @MethodName = "println", @ParenthesisDepth = 0, @Parenthesized = false] | +- FieldAccess[@AccessType = AccessType.READ, @CompileTimeConstant = false, @Image = "out", @Name = "out", @ParenthesisDepth = 0, @Parenthesized = false] @@ -128,14 +128,14 @@ | +- SwitchStatement[@DefaultCase = true, @EnumSwitch = false, @ExhaustiveEnumSwitch = false, @FallthroughSwitch = false] | +- VariableAccess[@AccessType = AccessType.READ, @CompileTimeConstant = false, @Image = "o", @Name = "o", @ParenthesisDepth = 0, @Parenthesized = false] | +- SwitchArrowBranch[@Default = false] - | | +- SwitchLabel[@Default = false] + | | +- SwitchLabel[@Default = false, @PatternLabel = false] | | | +- NullLiteral[@CompileTimeConstant = false, @LiteralText = "null", @ParenthesisDepth = 0, @Parenthesized = false] | | +- ThrowStatement[] | | +- ConstructorCall[@AnonymousClass = false, @CompileTimeConstant = false, @DiamondTypeArgs = false, @MethodName = "new", @ParenthesisDepth = 0, @Parenthesized = false, @QualifiedInstanceCreation = false] | | +- ClassType[@FullyQualified = false, @PackageQualifier = null, @SimpleName = "NullPointerException"] | | +- ArgumentList[@Empty = true, @Size = 0] | +- SwitchArrowBranch[@Default = false] - | | +- SwitchLabel[@Default = false] + | | +- SwitchLabel[@Default = false, @PatternLabel = true] | | | +- TypePattern[@EffectiveVisibility = Visibility.V_PACKAGE, @Visibility = Visibility.V_PACKAGE] | | | +- ModifierList[@EffectiveModifiers = (), @ExplicitModifiers = ()] | | | +- ClassType[@FullyQualified = false, @PackageQualifier = null, @SimpleName = "String"] @@ -149,7 +149,7 @@ | | +- StringLiteral[@CompileTimeConstant = true, @ConstValue = "String: ", @Empty = false, @Image = "\"String: \"", @Length = 8, @LiteralText = "\"String: \"", @ParenthesisDepth = 0, @Parenthesized = false, @TextBlock = false] | | +- VariableAccess[@AccessType = AccessType.READ, @CompileTimeConstant = false, @Image = "s", @Name = "s", @ParenthesisDepth = 0, @Parenthesized = false] | +- SwitchArrowBranch[@Default = false] - | | +- SwitchLabel[@Default = false] + | | +- SwitchLabel[@Default = false, @PatternLabel = true] | | | +- TypePattern[@EffectiveVisibility = Visibility.V_PACKAGE, @Visibility = Visibility.V_PACKAGE] | | | +- ModifierList[@EffectiveModifiers = (), @ExplicitModifiers = ()] | | | +- ClassType[@FullyQualified = false, @PackageQualifier = null, @SimpleName = "Integer"] @@ -161,7 +161,7 @@ | | +- ArgumentList[@Empty = false, @Size = 1] | | +- StringLiteral[@CompileTimeConstant = true, @ConstValue = "Integer", @Empty = false, @Image = "\"Integer\"", @Length = 7, @LiteralText = "\"Integer\"", @ParenthesisDepth = 0, @Parenthesized = false, @TextBlock = false] | +- SwitchArrowBranch[@Default = true] - | +- SwitchLabel[@Default = true] + | +- SwitchLabel[@Default = true, @PatternLabel = false] | +- MethodCall[@CompileTimeConstant = false, @Image = "println", @MethodName = "println", @ParenthesisDepth = 0, @Parenthesized = false] | +- FieldAccess[@AccessType = AccessType.READ, @CompileTimeConstant = false, @Image = "out", @Name = "out", @ParenthesisDepth = 0, @Parenthesized = false] | | +- TypeExpression[@CompileTimeConstant = false, @ParenthesisDepth = 0, @Parenthesized = false] @@ -180,7 +180,7 @@ | +- SwitchStatement[@DefaultCase = true, @EnumSwitch = false, @ExhaustiveEnumSwitch = false, @FallthroughSwitch = true] | | +- VariableAccess[@AccessType = AccessType.READ, @CompileTimeConstant = false, @Image = "o", @Name = "o", @ParenthesisDepth = 0, @Parenthesized = false] | | +- SwitchFallthroughBranch[@Default = false] - | | | +- SwitchLabel[@Default = false] + | | | +- SwitchLabel[@Default = false, @PatternLabel = false] | | | | +- NullLiteral[@CompileTimeConstant = false, @LiteralText = "null", @ParenthesisDepth = 0, @Parenthesized = false] | | | +- ExpressionStatement[] | | | | +- MethodCall[@CompileTimeConstant = false, @Image = "println", @MethodName = "println", @ParenthesisDepth = 0, @Parenthesized = false] @@ -191,7 +191,7 @@ | | | | +- StringLiteral[@CompileTimeConstant = true, @ConstValue = "null", @Empty = false, @Image = "\"null\"", @Length = 4, @LiteralText = "\"null\"", @ParenthesisDepth = 0, @Parenthesized = false, @TextBlock = false] | | | +- BreakStatement[@Label = null] | | +- SwitchFallthroughBranch[@Default = false] - | | | +- SwitchLabel[@Default = false] + | | | +- SwitchLabel[@Default = false, @PatternLabel = true] | | | | +- TypePattern[@EffectiveVisibility = Visibility.V_PACKAGE, @Visibility = Visibility.V_PACKAGE] | | | | +- ModifierList[@EffectiveModifiers = (), @ExplicitModifiers = ()] | | | | +- ClassType[@FullyQualified = false, @PackageQualifier = null, @SimpleName = "String"] @@ -205,7 +205,7 @@ | | | | +- StringLiteral[@CompileTimeConstant = true, @ConstValue = "String", @Empty = false, @Image = "\"String\"", @Length = 6, @LiteralText = "\"String\"", @ParenthesisDepth = 0, @Parenthesized = false, @TextBlock = false] | | | +- BreakStatement[@Label = null] | | +- SwitchFallthroughBranch[@Default = true] - | | +- SwitchLabel[@Default = true] + | | +- SwitchLabel[@Default = true, @PatternLabel = false] | | +- ExpressionStatement[] | | | +- MethodCall[@CompileTimeConstant = false, @Image = "println", @MethodName = "println", @ParenthesisDepth = 0, @Parenthesized = false] | | | +- FieldAccess[@AccessType = AccessType.READ, @CompileTimeConstant = false, @Image = "out", @Name = "out", @ParenthesisDepth = 0, @Parenthesized = false] @@ -217,7 +217,7 @@ | +- SwitchStatement[@DefaultCase = true, @EnumSwitch = false, @ExhaustiveEnumSwitch = false, @FallthroughSwitch = false] | | +- VariableAccess[@AccessType = AccessType.READ, @CompileTimeConstant = false, @Image = "o", @Name = "o", @ParenthesisDepth = 0, @Parenthesized = false] | | +- SwitchArrowBranch[@Default = false] - | | | +- SwitchLabel[@Default = false] + | | | +- SwitchLabel[@Default = false, @PatternLabel = false] | | | | +- NullLiteral[@CompileTimeConstant = false, @LiteralText = "null", @ParenthesisDepth = 0, @Parenthesized = false] | | | +- MethodCall[@CompileTimeConstant = false, @Image = "println", @MethodName = "println", @ParenthesisDepth = 0, @Parenthesized = false] | | | +- FieldAccess[@AccessType = AccessType.READ, @CompileTimeConstant = false, @Image = "out", @Name = "out", @ParenthesisDepth = 0, @Parenthesized = false] @@ -226,7 +226,7 @@ | | | +- ArgumentList[@Empty = false, @Size = 1] | | | +- StringLiteral[@CompileTimeConstant = true, @ConstValue = "null", @Empty = false, @Image = "\"null\"", @Length = 4, @LiteralText = "\"null\"", @ParenthesisDepth = 0, @Parenthesized = false, @TextBlock = false] | | +- SwitchArrowBranch[@Default = false] - | | | +- SwitchLabel[@Default = false] + | | | +- SwitchLabel[@Default = false, @PatternLabel = true] | | | | +- TypePattern[@EffectiveVisibility = Visibility.V_PACKAGE, @Visibility = Visibility.V_PACKAGE] | | | | +- ModifierList[@EffectiveModifiers = (), @ExplicitModifiers = ()] | | | | +- ClassType[@FullyQualified = false, @PackageQualifier = null, @SimpleName = "String"] @@ -238,7 +238,7 @@ | | | +- ArgumentList[@Empty = false, @Size = 1] | | | +- StringLiteral[@CompileTimeConstant = true, @ConstValue = "String", @Empty = false, @Image = "\"String\"", @Length = 6, @LiteralText = "\"String\"", @ParenthesisDepth = 0, @Parenthesized = false, @TextBlock = false] | | +- SwitchArrowBranch[@Default = true] - | | +- SwitchLabel[@Default = true] + | | +- SwitchLabel[@Default = true, @PatternLabel = false] | | +- MethodCall[@CompileTimeConstant = false, @Image = "println", @MethodName = "println", @ParenthesisDepth = 0, @Parenthesized = false] | | +- FieldAccess[@AccessType = AccessType.READ, @CompileTimeConstant = false, @Image = "out", @Name = "out", @ParenthesisDepth = 0, @Parenthesized = false] | | | +- TypeExpression[@CompileTimeConstant = false, @ParenthesisDepth = 0, @Parenthesized = false] @@ -248,10 +248,10 @@ | +- SwitchStatement[@DefaultCase = true, @EnumSwitch = false, @ExhaustiveEnumSwitch = false, @FallthroughSwitch = true] | | +- VariableAccess[@AccessType = AccessType.READ, @CompileTimeConstant = false, @Image = "o", @Name = "o", @ParenthesisDepth = 0, @Parenthesized = false] | | +- SwitchFallthroughBranch[@Default = false] - | | | +- SwitchLabel[@Default = false] + | | | +- SwitchLabel[@Default = false, @PatternLabel = false] | | | +- NullLiteral[@CompileTimeConstant = false, @LiteralText = "null", @ParenthesisDepth = 0, @Parenthesized = false] | | +- SwitchFallthroughBranch[@Default = true] - | | +- SwitchLabel[@Default = true] + | | +- SwitchLabel[@Default = true, @PatternLabel = false] | | +- ExpressionStatement[] | | +- MethodCall[@CompileTimeConstant = false, @Image = "println", @MethodName = "println", @ParenthesisDepth = 0, @Parenthesized = false] | | +- FieldAccess[@AccessType = AccessType.READ, @CompileTimeConstant = false, @Image = "out", @Name = "out", @ParenthesisDepth = 0, @Parenthesized = false] @@ -262,7 +262,7 @@ | +- SwitchStatement[@DefaultCase = true, @EnumSwitch = false, @ExhaustiveEnumSwitch = false, @FallthroughSwitch = false] | +- VariableAccess[@AccessType = AccessType.READ, @CompileTimeConstant = false, @Image = "o", @Name = "o", @ParenthesisDepth = 0, @Parenthesized = false] | +- SwitchArrowBranch[@Default = true] - | +- SwitchLabel[@Default = true] + | +- SwitchLabel[@Default = true, @PatternLabel = false] | | +- NullLiteral[@CompileTimeConstant = false, @LiteralText = "null", @ParenthesisDepth = 0, @Parenthesized = false] | +- MethodCall[@CompileTimeConstant = false, @Image = "println", @MethodName = "println", @ParenthesisDepth = 0, @Parenthesized = false] | +- FieldAccess[@AccessType = AccessType.READ, @CompileTimeConstant = false, @Image = "out", @Name = "out", @ParenthesisDepth = 0, @Parenthesized = false] diff --git a/pmd-java/src/test/resources/net/sourceforge/pmd/lang/java/ast/jdkversiontests/java21/EnhancedTypeCheckingSwitch.txt b/pmd-java/src/test/resources/net/sourceforge/pmd/lang/java/ast/jdkversiontests/java21/EnhancedTypeCheckingSwitch.txt index 71d642290e..aec1b52224 100644 --- a/pmd-java/src/test/resources/net/sourceforge/pmd/lang/java/ast/jdkversiontests/java21/EnhancedTypeCheckingSwitch.txt +++ b/pmd-java/src/test/resources/net/sourceforge/pmd/lang/java/ast/jdkversiontests/java21/EnhancedTypeCheckingSwitch.txt @@ -38,7 +38,7 @@ | +- SwitchStatement[@DefaultCase = true, @EnumSwitch = false, @ExhaustiveEnumSwitch = false, @FallthroughSwitch = false] | +- VariableAccess[@AccessType = AccessType.READ, @CompileTimeConstant = false, @Image = "obj", @Name = "obj", @ParenthesisDepth = 0, @Parenthesized = false] | +- SwitchArrowBranch[@Default = false] - | | +- SwitchLabel[@Default = false] + | | +- SwitchLabel[@Default = false, @PatternLabel = false] | | | +- NullLiteral[@CompileTimeConstant = false, @LiteralText = "null", @ParenthesisDepth = 0, @Parenthesized = false] | | +- MethodCall[@CompileTimeConstant = false, @Image = "println", @MethodName = "println", @ParenthesisDepth = 0, @Parenthesized = false] | | +- FieldAccess[@AccessType = AccessType.READ, @CompileTimeConstant = false, @Image = "out", @Name = "out", @ParenthesisDepth = 0, @Parenthesized = false] @@ -47,7 +47,7 @@ | | +- ArgumentList[@Empty = false, @Size = 1] | | +- StringLiteral[@CompileTimeConstant = true, @ConstValue = "null", @Empty = false, @Image = "\"null\"", @Length = 4, @LiteralText = "\"null\"", @ParenthesisDepth = 0, @Parenthesized = false, @TextBlock = false] | +- SwitchArrowBranch[@Default = false] - | | +- SwitchLabel[@Default = false] + | | +- SwitchLabel[@Default = false, @PatternLabel = true] | | | +- TypePattern[@EffectiveVisibility = Visibility.V_PACKAGE, @Visibility = Visibility.V_PACKAGE] | | | +- ModifierList[@EffectiveModifiers = (), @ExplicitModifiers = ()] | | | +- ClassType[@FullyQualified = false, @PackageQualifier = null, @SimpleName = "String"] @@ -59,7 +59,7 @@ | | +- ArgumentList[@Empty = false, @Size = 1] | | +- StringLiteral[@CompileTimeConstant = true, @ConstValue = "String", @Empty = false, @Image = "\"String\"", @Length = 6, @LiteralText = "\"String\"", @ParenthesisDepth = 0, @Parenthesized = false, @TextBlock = false] | +- SwitchArrowBranch[@Default = false] - | | +- SwitchLabel[@Default = false] + | | +- SwitchLabel[@Default = false, @PatternLabel = true] | | | +- TypePattern[@EffectiveVisibility = Visibility.V_PACKAGE, @Visibility = Visibility.V_PACKAGE] | | | +- ModifierList[@EffectiveModifiers = (), @ExplicitModifiers = ()] | | | +- ClassType[@FullyQualified = false, @PackageQualifier = null, @SimpleName = "Color"] @@ -75,7 +75,7 @@ | | +- VariableAccess[@AccessType = AccessType.READ, @CompileTimeConstant = false, @Image = "c", @Name = "c", @ParenthesisDepth = 0, @Parenthesized = false] | | +- ArgumentList[@Empty = true, @Size = 0] | +- SwitchArrowBranch[@Default = false] - | | +- SwitchLabel[@Default = false] + | | +- SwitchLabel[@Default = false, @PatternLabel = true] | | | +- TypePattern[@EffectiveVisibility = Visibility.V_PACKAGE, @Visibility = Visibility.V_PACKAGE] | | | +- ModifierList[@EffectiveModifiers = (), @ExplicitModifiers = ()] | | | +- ClassType[@FullyQualified = false, @PackageQualifier = null, @SimpleName = "Point"] @@ -91,7 +91,7 @@ | | +- VariableAccess[@AccessType = AccessType.READ, @CompileTimeConstant = false, @Image = "p", @Name = "p", @ParenthesisDepth = 0, @Parenthesized = false] | | +- ArgumentList[@Empty = true, @Size = 0] | +- SwitchArrowBranch[@Default = false] - | | +- SwitchLabel[@Default = false] + | | +- SwitchLabel[@Default = false, @PatternLabel = true] | | | +- TypePattern[@EffectiveVisibility = Visibility.V_PACKAGE, @Visibility = Visibility.V_PACKAGE] | | | +- ModifierList[@EffectiveModifiers = (), @ExplicitModifiers = ()] | | | +- ArrayType[@ArrayDepth = 1] @@ -109,7 +109,7 @@ | | +- FieldAccess[@AccessType = AccessType.READ, @CompileTimeConstant = false, @Image = "length", @Name = "length", @ParenthesisDepth = 0, @Parenthesized = false] | | +- VariableAccess[@AccessType = AccessType.READ, @CompileTimeConstant = false, @Image = "ia", @Name = "ia", @ParenthesisDepth = 0, @Parenthesized = false] | +- SwitchArrowBranch[@Default = true] - | +- SwitchLabel[@Default = true] + | +- SwitchLabel[@Default = true, @PatternLabel = false] | +- MethodCall[@CompileTimeConstant = false, @Image = "println", @MethodName = "println", @ParenthesisDepth = 0, @Parenthesized = false] | +- FieldAccess[@AccessType = AccessType.READ, @CompileTimeConstant = false, @Image = "out", @Name = "out", @ParenthesisDepth = 0, @Parenthesized = false] | | +- TypeExpression[@CompileTimeConstant = false, @ParenthesisDepth = 0, @Parenthesized = false] diff --git a/pmd-java/src/test/resources/net/sourceforge/pmd/lang/java/ast/jdkversiontests/java21/ExhaustiveSwitch.txt b/pmd-java/src/test/resources/net/sourceforge/pmd/lang/java/ast/jdkversiontests/java21/ExhaustiveSwitch.txt index b43f4f1caf..0690ebc5ba 100644 --- a/pmd-java/src/test/resources/net/sourceforge/pmd/lang/java/ast/jdkversiontests/java21/ExhaustiveSwitch.txt +++ b/pmd-java/src/test/resources/net/sourceforge/pmd/lang/java/ast/jdkversiontests/java21/ExhaustiveSwitch.txt @@ -15,7 +15,7 @@ | +- SwitchExpression[@CompileTimeConstant = false, @DefaultCase = true, @EnumSwitch = false, @ExhaustiveEnumSwitch = false, @FallthroughSwitch = false, @ParenthesisDepth = 0, @Parenthesized = false] | +- VariableAccess[@AccessType = AccessType.READ, @CompileTimeConstant = false, @Image = "obj", @Name = "obj", @ParenthesisDepth = 0, @Parenthesized = false] | +- SwitchArrowBranch[@Default = false] - | | +- SwitchLabel[@Default = false] + | | +- SwitchLabel[@Default = false, @PatternLabel = true] | | | +- TypePattern[@EffectiveVisibility = Visibility.V_PACKAGE, @Visibility = Visibility.V_PACKAGE] | | | +- ModifierList[@EffectiveModifiers = (), @ExplicitModifiers = ()] | | | +- ClassType[@FullyQualified = false, @PackageQualifier = null, @SimpleName = "String"] @@ -24,14 +24,14 @@ | | +- VariableAccess[@AccessType = AccessType.READ, @CompileTimeConstant = false, @Image = "s", @Name = "s", @ParenthesisDepth = 0, @Parenthesized = false] | | +- ArgumentList[@Empty = true, @Size = 0] | +- SwitchArrowBranch[@Default = false] - | | +- SwitchLabel[@Default = false] + | | +- SwitchLabel[@Default = false, @PatternLabel = true] | | | +- TypePattern[@EffectiveVisibility = Visibility.V_PACKAGE, @Visibility = Visibility.V_PACKAGE] | | | +- ModifierList[@EffectiveModifiers = (), @ExplicitModifiers = ()] | | | +- ClassType[@FullyQualified = false, @PackageQualifier = null, @SimpleName = "Integer"] | | | +- VariableId[@ArrayType = false, @EffectiveVisibility = Visibility.V_LOCAL, @EnumConstant = false, @ExceptionBlockParameter = false, @Field = false, @Final = false, @ForLoopVariable = false, @ForeachVariable = false, @FormalParameter = false, @LambdaParameter = false, @LocalVariable = false, @Name = "i", @PatternBinding = true, @RecordComponent = false, @ResourceDeclaration = false, @Static = false, @TypeInferred = false, @Unnamed = false, @Visibility = Visibility.V_LOCAL] | | +- VariableAccess[@AccessType = AccessType.READ, @CompileTimeConstant = false, @Image = "i", @Name = "i", @ParenthesisDepth = 0, @Parenthesized = false] | +- SwitchArrowBranch[@Default = true] - | +- SwitchLabel[@Default = true] + | +- SwitchLabel[@Default = true, @PatternLabel = false] | +- NumericLiteral[@Base = 10, @CompileTimeConstant = true, @DoubleLiteral = false, @FloatLiteral = false, @Image = "0", @IntLiteral = true, @Integral = true, @LiteralText = "0", @LongLiteral = false, @ParenthesisDepth = 0, @Parenthesized = false, @ValueAsDouble = 0.0, @ValueAsFloat = 0.0, @ValueAsInt = 0, @ValueAsLong = 0] +- MethodDeclaration[@Abstract = false, @Arity = 1, @EffectiveVisibility = Visibility.V_PACKAGE, @Final = false, @Name = "coverageStatement", @Overridden = false, @Static = true, @Varargs = false, @Visibility = Visibility.V_PACKAGE, @Void = true] | +- ModifierList[@EffectiveModifiers = (JModifier.STATIC), @ExplicitModifiers = (JModifier.STATIC)] @@ -45,7 +45,7 @@ | +- SwitchStatement[@DefaultCase = true, @EnumSwitch = false, @ExhaustiveEnumSwitch = false, @FallthroughSwitch = true] | +- VariableAccess[@AccessType = AccessType.READ, @CompileTimeConstant = false, @Image = "o", @Name = "o", @ParenthesisDepth = 0, @Parenthesized = false] | +- SwitchFallthroughBranch[@Default = false] - | | +- SwitchLabel[@Default = false] + | | +- SwitchLabel[@Default = false, @PatternLabel = true] | | | +- TypePattern[@EffectiveVisibility = Visibility.V_PACKAGE, @Visibility = Visibility.V_PACKAGE] | | | +- ModifierList[@EffectiveModifiers = (), @ExplicitModifiers = ()] | | | +- ClassType[@FullyQualified = false, @PackageQualifier = null, @SimpleName = "String"] @@ -59,7 +59,7 @@ | | | +- VariableAccess[@AccessType = AccessType.READ, @CompileTimeConstant = false, @Image = "s", @Name = "s", @ParenthesisDepth = 0, @Parenthesized = false] | | +- BreakStatement[@Label = null] | +- SwitchFallthroughBranch[@Default = false] - | | +- SwitchLabel[@Default = false] + | | +- SwitchLabel[@Default = false, @PatternLabel = true] | | | +- TypePattern[@EffectiveVisibility = Visibility.V_PACKAGE, @Visibility = Visibility.V_PACKAGE] | | | +- ModifierList[@EffectiveModifiers = (), @ExplicitModifiers = ()] | | | +- ClassType[@FullyQualified = false, @PackageQualifier = null, @SimpleName = "Integer"] @@ -73,7 +73,7 @@ | | | +- StringLiteral[@CompileTimeConstant = true, @ConstValue = "Integer", @Empty = false, @Image = "\"Integer\"", @Length = 7, @LiteralText = "\"Integer\"", @ParenthesisDepth = 0, @Parenthesized = false, @TextBlock = false] | | +- BreakStatement[@Label = null] | +- SwitchFallthroughBranch[@Default = true] - | +- SwitchLabel[@Default = true] + | +- SwitchLabel[@Default = true, @PatternLabel = false] | +- BreakStatement[@Label = null] +- ClassDeclaration[@Abstract = true, @Annotation = false, @Anonymous = false, @BinaryName = "ExhaustiveSwitch$S", @CanonicalName = "ExhaustiveSwitch.S", @EffectiveVisibility = Visibility.V_PACKAGE, @Enum = false, @Final = false, @Interface = true, @Local = false, @Nested = true, @PackageName = "", @Record = false, @RegularClass = false, @RegularInterface = true, @SimpleName = "S", @Static = true, @TopLevel = false, @UnnamedToplevelClass = false, @Visibility = Visibility.V_PACKAGE] | +- ModifierList[@EffectiveModifiers = (JModifier.SEALED, JModifier.ABSTRACT, JModifier.STATIC), @ExplicitModifiers = (JModifier.SEALED)] @@ -115,21 +115,21 @@ | +- SwitchExpression[@CompileTimeConstant = false, @DefaultCase = false, @EnumSwitch = false, @ExhaustiveEnumSwitch = false, @FallthroughSwitch = false, @ParenthesisDepth = 0, @Parenthesized = false] | +- VariableAccess[@AccessType = AccessType.READ, @CompileTimeConstant = false, @Image = "s", @Name = "s", @ParenthesisDepth = 0, @Parenthesized = false] | +- SwitchArrowBranch[@Default = false] - | | +- SwitchLabel[@Default = false] + | | +- SwitchLabel[@Default = false, @PatternLabel = true] | | | +- TypePattern[@EffectiveVisibility = Visibility.V_PACKAGE, @Visibility = Visibility.V_PACKAGE] | | | +- ModifierList[@EffectiveModifiers = (), @ExplicitModifiers = ()] | | | +- ClassType[@FullyQualified = false, @PackageQualifier = null, @SimpleName = "A"] | | | +- VariableId[@ArrayType = false, @EffectiveVisibility = Visibility.V_LOCAL, @EnumConstant = false, @ExceptionBlockParameter = false, @Field = false, @Final = false, @ForLoopVariable = false, @ForeachVariable = false, @FormalParameter = false, @LambdaParameter = false, @LocalVariable = false, @Name = "a", @PatternBinding = true, @RecordComponent = false, @ResourceDeclaration = false, @Static = false, @TypeInferred = false, @Unnamed = false, @Visibility = Visibility.V_LOCAL] | | +- NumericLiteral[@Base = 10, @CompileTimeConstant = true, @DoubleLiteral = false, @FloatLiteral = false, @Image = "1", @IntLiteral = true, @Integral = true, @LiteralText = "1", @LongLiteral = false, @ParenthesisDepth = 0, @Parenthesized = false, @ValueAsDouble = 1.0, @ValueAsFloat = 1.0, @ValueAsInt = 1, @ValueAsLong = 1] | +- SwitchArrowBranch[@Default = false] - | | +- SwitchLabel[@Default = false] + | | +- SwitchLabel[@Default = false, @PatternLabel = true] | | | +- TypePattern[@EffectiveVisibility = Visibility.V_PACKAGE, @Visibility = Visibility.V_PACKAGE] | | | +- ModifierList[@EffectiveModifiers = (), @ExplicitModifiers = ()] | | | +- ClassType[@FullyQualified = false, @PackageQualifier = null, @SimpleName = "B"] | | | +- VariableId[@ArrayType = false, @EffectiveVisibility = Visibility.V_LOCAL, @EnumConstant = false, @ExceptionBlockParameter = false, @Field = false, @Final = false, @ForLoopVariable = false, @ForeachVariable = false, @FormalParameter = false, @LambdaParameter = false, @LocalVariable = false, @Name = "b", @PatternBinding = true, @RecordComponent = false, @ResourceDeclaration = false, @Static = false, @TypeInferred = false, @Unnamed = false, @Visibility = Visibility.V_LOCAL] | | +- NumericLiteral[@Base = 10, @CompileTimeConstant = true, @DoubleLiteral = false, @FloatLiteral = false, @Image = "2", @IntLiteral = true, @Integral = true, @LiteralText = "2", @LongLiteral = false, @ParenthesisDepth = 0, @Parenthesized = false, @ValueAsDouble = 2.0, @ValueAsFloat = 2.0, @ValueAsInt = 2, @ValueAsLong = 2] | +- SwitchArrowBranch[@Default = false] - | +- SwitchLabel[@Default = false] + | +- SwitchLabel[@Default = false, @PatternLabel = true] | | +- TypePattern[@EffectiveVisibility = Visibility.V_PACKAGE, @Visibility = Visibility.V_PACKAGE] | | +- ModifierList[@EffectiveModifiers = (), @ExplicitModifiers = ()] | | +- ClassType[@FullyQualified = false, @PackageQualifier = null, @SimpleName = "C"] @@ -147,7 +147,7 @@ | +- SwitchStatement[@DefaultCase = true, @EnumSwitch = false, @ExhaustiveEnumSwitch = false, @FallthroughSwitch = true] | | +- VariableAccess[@AccessType = AccessType.READ, @CompileTimeConstant = false, @Image = "s", @Name = "s", @ParenthesisDepth = 0, @Parenthesized = false] | | +- SwitchFallthroughBranch[@Default = false] - | | | +- SwitchLabel[@Default = false] + | | | +- SwitchLabel[@Default = false, @PatternLabel = true] | | | | +- TypePattern[@EffectiveVisibility = Visibility.V_PACKAGE, @Visibility = Visibility.V_PACKAGE] | | | | +- ModifierList[@EffectiveModifiers = (), @ExplicitModifiers = ()] | | | | +- ClassType[@FullyQualified = false, @PackageQualifier = null, @SimpleName = "A"] @@ -161,7 +161,7 @@ | | | | +- StringLiteral[@CompileTimeConstant = true, @ConstValue = "A", @Empty = false, @Image = "\"A\"", @Length = 1, @LiteralText = "\"A\"", @ParenthesisDepth = 0, @Parenthesized = false, @TextBlock = false] | | | +- BreakStatement[@Label = null] | | +- SwitchFallthroughBranch[@Default = false] - | | | +- SwitchLabel[@Default = false] + | | | +- SwitchLabel[@Default = false, @PatternLabel = true] | | | | +- TypePattern[@EffectiveVisibility = Visibility.V_PACKAGE, @Visibility = Visibility.V_PACKAGE] | | | | +- ModifierList[@EffectiveModifiers = (), @ExplicitModifiers = ()] | | | | +- ClassType[@FullyQualified = false, @PackageQualifier = null, @SimpleName = "C"] @@ -175,7 +175,7 @@ | | | | +- StringLiteral[@CompileTimeConstant = true, @ConstValue = "C", @Empty = false, @Image = "\"C\"", @Length = 1, @LiteralText = "\"C\"", @ParenthesisDepth = 0, @Parenthesized = false, @TextBlock = false] | | | +- BreakStatement[@Label = null] | | +- SwitchFallthroughBranch[@Default = true] - | | +- SwitchLabel[@Default = true] + | | +- SwitchLabel[@Default = true, @PatternLabel = false] | | +- ExpressionStatement[] | | | +- MethodCall[@CompileTimeConstant = false, @Image = "println", @MethodName = "println", @ParenthesisDepth = 0, @Parenthesized = false] | | | +- FieldAccess[@AccessType = AccessType.READ, @CompileTimeConstant = false, @Image = "out", @Name = "out", @ParenthesisDepth = 0, @Parenthesized = false] @@ -226,7 +226,7 @@ | +- SwitchExpression[@CompileTimeConstant = false, @DefaultCase = false, @EnumSwitch = false, @ExhaustiveEnumSwitch = false, @FallthroughSwitch = false, @ParenthesisDepth = 0, @Parenthesized = false] | +- VariableAccess[@AccessType = AccessType.READ, @CompileTimeConstant = false, @Image = "i", @Name = "i", @ParenthesisDepth = 0, @Parenthesized = false] | +- SwitchArrowBranch[@Default = false] - | +- SwitchLabel[@Default = false] + | +- SwitchLabel[@Default = false, @PatternLabel = true] | | +- TypePattern[@EffectiveVisibility = Visibility.V_PACKAGE, @Visibility = Visibility.V_PACKAGE] | | +- ModifierList[@EffectiveModifiers = (), @ExplicitModifiers = ()] | | +- ClassType[@FullyQualified = false, @PackageQualifier = null, @SimpleName = "F"] diff --git a/pmd-java/src/test/resources/net/sourceforge/pmd/lang/java/ast/jdkversiontests/java21/GuardedPatterns.txt b/pmd-java/src/test/resources/net/sourceforge/pmd/lang/java/ast/jdkversiontests/java21/GuardedPatterns.txt index 6e33db0bd7..e9ec43cda3 100644 --- a/pmd-java/src/test/resources/net/sourceforge/pmd/lang/java/ast/jdkversiontests/java21/GuardedPatterns.txt +++ b/pmd-java/src/test/resources/net/sourceforge/pmd/lang/java/ast/jdkversiontests/java21/GuardedPatterns.txt @@ -14,7 +14,7 @@ | +- SwitchStatement[@DefaultCase = true, @EnumSwitch = false, @ExhaustiveEnumSwitch = false, @FallthroughSwitch = false] | +- VariableAccess[@AccessType = AccessType.READ, @CompileTimeConstant = false, @Image = "o", @Name = "o", @ParenthesisDepth = 0, @Parenthesized = false] | +- SwitchArrowBranch[@Default = false] - | | +- SwitchLabel[@Default = false] + | | +- SwitchLabel[@Default = false, @PatternLabel = true] | | | +- TypePattern[@EffectiveVisibility = Visibility.V_PACKAGE, @Visibility = Visibility.V_PACKAGE] | | | | +- ModifierList[@EffectiveModifiers = (), @ExplicitModifiers = ()] | | | | +- ClassType[@FullyQualified = false, @PackageQualifier = null, @SimpleName = "String"] @@ -32,7 +32,7 @@ | | +- ArgumentList[@Empty = false, @Size = 1] | | +- StringLiteral[@CompileTimeConstant = true, @ConstValue = "single char string", @Empty = false, @Image = "\"single char string\"", @Length = 18, @LiteralText = "\"single char string\"", @ParenthesisDepth = 0, @Parenthesized = false, @TextBlock = false] | +- SwitchArrowBranch[@Default = false] - | | +- SwitchLabel[@Default = false] + | | +- SwitchLabel[@Default = false, @PatternLabel = true] | | | +- TypePattern[@EffectiveVisibility = Visibility.V_PACKAGE, @Visibility = Visibility.V_PACKAGE] | | | +- ModifierList[@EffectiveModifiers = (), @ExplicitModifiers = ()] | | | +- ClassType[@FullyQualified = false, @PackageQualifier = null, @SimpleName = "String"] @@ -44,7 +44,7 @@ | | +- ArgumentList[@Empty = false, @Size = 1] | | +- StringLiteral[@CompileTimeConstant = true, @ConstValue = "string", @Empty = false, @Image = "\"string\"", @Length = 6, @LiteralText = "\"string\"", @ParenthesisDepth = 0, @Parenthesized = false, @TextBlock = false] | +- SwitchArrowBranch[@Default = false] - | | +- SwitchLabel[@Default = false] + | | +- SwitchLabel[@Default = false, @PatternLabel = true] | | | +- TypePattern[@EffectiveVisibility = Visibility.V_PACKAGE, @Visibility = Visibility.V_PACKAGE] | | | | +- ModifierList[@EffectiveModifiers = (), @ExplicitModifiers = ()] | | | | +- ClassType[@FullyQualified = false, @PackageQualifier = null, @SimpleName = "Integer"] @@ -62,7 +62,7 @@ | | +- ArgumentList[@Empty = false, @Size = 1] | | +- StringLiteral[@CompileTimeConstant = true, @ConstValue = "integer 1", @Empty = false, @Image = "\"integer 1\"", @Length = 9, @LiteralText = "\"integer 1\"", @ParenthesisDepth = 0, @Parenthesized = false, @TextBlock = false] | +- SwitchArrowBranch[@Default = true] - | +- SwitchLabel[@Default = true] + | +- SwitchLabel[@Default = true, @PatternLabel = false] | +- MethodCall[@CompileTimeConstant = false, @Image = "println", @MethodName = "println", @ParenthesisDepth = 0, @Parenthesized = false] | +- FieldAccess[@AccessType = AccessType.READ, @CompileTimeConstant = false, @Image = "out", @Name = "out", @ParenthesisDepth = 0, @Parenthesized = false] | | +- TypeExpression[@CompileTimeConstant = false, @ParenthesisDepth = 0, @Parenthesized = false] @@ -118,7 +118,7 @@ | +- SwitchStatement[@DefaultCase = true, @EnumSwitch = false, @ExhaustiveEnumSwitch = false, @FallthroughSwitch = false] | +- VariableAccess[@AccessType = AccessType.READ, @CompileTimeConstant = false, @Image = "o", @Name = "o", @ParenthesisDepth = 0, @Parenthesized = false] | +- SwitchArrowBranch[@Default = false] - | | +- SwitchLabel[@Default = false] + | | +- SwitchLabel[@Default = false, @PatternLabel = true] | | | +- TypePattern[@EffectiveVisibility = Visibility.V_PACKAGE, @Visibility = Visibility.V_PACKAGE] | | | | +- ModifierList[@EffectiveModifiers = (), @ExplicitModifiers = ()] | | | | +- ClassType[@FullyQualified = false, @PackageQualifier = null, @SimpleName = "String"] @@ -136,7 +136,7 @@ | | +- ArgumentList[@Empty = false, @Size = 1] | | +- StringLiteral[@CompileTimeConstant = true, @ConstValue = "single char string", @Empty = false, @Image = "\"single char string\"", @Length = 18, @LiteralText = "\"single char string\"", @ParenthesisDepth = 0, @Parenthesized = false, @TextBlock = false] | +- SwitchArrowBranch[@Default = false] - | | +- SwitchLabel[@Default = false] + | | +- SwitchLabel[@Default = false, @PatternLabel = true] | | | +- TypePattern[@EffectiveVisibility = Visibility.V_PACKAGE, @Visibility = Visibility.V_PACKAGE] | | | +- ModifierList[@EffectiveModifiers = (), @ExplicitModifiers = ()] | | | +- ClassType[@FullyQualified = false, @PackageQualifier = null, @SimpleName = "String"] @@ -148,7 +148,7 @@ | | +- ArgumentList[@Empty = false, @Size = 1] | | +- StringLiteral[@CompileTimeConstant = true, @ConstValue = "string", @Empty = false, @Image = "\"string\"", @Length = 6, @LiteralText = "\"string\"", @ParenthesisDepth = 0, @Parenthesized = false, @TextBlock = false] | +- SwitchArrowBranch[@Default = false] - | | +- SwitchLabel[@Default = false] + | | +- SwitchLabel[@Default = false, @PatternLabel = true] | | | +- TypePattern[@EffectiveVisibility = Visibility.V_PACKAGE, @Visibility = Visibility.V_PACKAGE] | | | | +- ModifierList[@EffectiveModifiers = (), @ExplicitModifiers = ()] | | | | +- ClassType[@FullyQualified = false, @PackageQualifier = null, @SimpleName = "Integer"] @@ -166,7 +166,7 @@ | | +- ArgumentList[@Empty = false, @Size = 1] | | +- StringLiteral[@CompileTimeConstant = true, @ConstValue = "integer 1", @Empty = false, @Image = "\"integer 1\"", @Length = 9, @LiteralText = "\"integer 1\"", @ParenthesisDepth = 0, @Parenthesized = false, @TextBlock = false] | +- SwitchArrowBranch[@Default = false] - | | +- SwitchLabel[@Default = false] + | | +- SwitchLabel[@Default = false, @PatternLabel = false] | | | +- NullLiteral[@CompileTimeConstant = false, @LiteralText = "null", @ParenthesisDepth = 0, @Parenthesized = false] | | +- MethodCall[@CompileTimeConstant = false, @Image = "println", @MethodName = "println", @ParenthesisDepth = 0, @Parenthesized = false] | | +- FieldAccess[@AccessType = AccessType.READ, @CompileTimeConstant = false, @Image = "out", @Name = "out", @ParenthesisDepth = 0, @Parenthesized = false] @@ -175,7 +175,7 @@ | | +- ArgumentList[@Empty = false, @Size = 1] | | +- StringLiteral[@CompileTimeConstant = true, @ConstValue = "null!", @Empty = false, @Image = "\"null!\"", @Length = 5, @LiteralText = "\"null!\"", @ParenthesisDepth = 0, @Parenthesized = false, @TextBlock = false] | +- SwitchArrowBranch[@Default = true] - | +- SwitchLabel[@Default = true] + | +- SwitchLabel[@Default = true, @PatternLabel = false] | +- MethodCall[@CompileTimeConstant = false, @Image = "println", @MethodName = "println", @ParenthesisDepth = 0, @Parenthesized = false] | +- FieldAccess[@AccessType = AccessType.READ, @CompileTimeConstant = false, @Image = "out", @Name = "out", @ParenthesisDepth = 0, @Parenthesized = false] | | +- TypeExpression[@CompileTimeConstant = false, @ParenthesisDepth = 0, @Parenthesized = false] diff --git a/pmd-java/src/test/resources/net/sourceforge/pmd/lang/java/ast/jdkversiontests/java21/Jep440_RecordPatterns.txt b/pmd-java/src/test/resources/net/sourceforge/pmd/lang/java/ast/jdkversiontests/java21/Jep440_RecordPatterns.txt index 84f45093b7..8756417a53 100644 --- a/pmd-java/src/test/resources/net/sourceforge/pmd/lang/java/ast/jdkversiontests/java21/Jep440_RecordPatterns.txt +++ b/pmd-java/src/test/resources/net/sourceforge/pmd/lang/java/ast/jdkversiontests/java21/Jep440_RecordPatterns.txt @@ -260,7 +260,7 @@ | +- SwitchStatement[@DefaultCase = false, @EnumSwitch = false, @ExhaustiveEnumSwitch = false, @FallthroughSwitch = false] | +- VariableAccess[@AccessType = AccessType.READ, @CompileTimeConstant = false, @Image = "pair", @Name = "pair", @ParenthesisDepth = 0, @Parenthesized = false] | +- SwitchArrowBranch[@Default = false] - | +- SwitchLabel[@Default = false] + | +- SwitchLabel[@Default = false, @PatternLabel = true] | | +- RecordPattern[] | | +- ClassType[@FullyQualified = false, @PackageQualifier = null, @SimpleName = "MyPair"] | | +- PatternList[@Empty = false, @Size = 2] diff --git a/pmd-java/src/test/resources/net/sourceforge/pmd/lang/java/ast/jdkversiontests/java21/Jep441_PatternMatchingForSwitch.txt b/pmd-java/src/test/resources/net/sourceforge/pmd/lang/java/ast/jdkversiontests/java21/Jep441_PatternMatchingForSwitch.txt index 97893e90d3..fce6b81fdf 100644 --- a/pmd-java/src/test/resources/net/sourceforge/pmd/lang/java/ast/jdkversiontests/java21/Jep441_PatternMatchingForSwitch.txt +++ b/pmd-java/src/test/resources/net/sourceforge/pmd/lang/java/ast/jdkversiontests/java21/Jep441_PatternMatchingForSwitch.txt @@ -15,7 +15,7 @@ | +- SwitchExpression[@CompileTimeConstant = false, @DefaultCase = true, @EnumSwitch = false, @ExhaustiveEnumSwitch = false, @FallthroughSwitch = false, @ParenthesisDepth = 0, @Parenthesized = false] | +- VariableAccess[@AccessType = AccessType.READ, @CompileTimeConstant = false, @Image = "obj", @Name = "obj", @ParenthesisDepth = 0, @Parenthesized = false] | +- SwitchArrowBranch[@Default = false] - | | +- SwitchLabel[@Default = false] + | | +- SwitchLabel[@Default = false, @PatternLabel = true] | | | +- TypePattern[@EffectiveVisibility = Visibility.V_PACKAGE, @Visibility = Visibility.V_PACKAGE] | | | +- ModifierList[@EffectiveModifiers = (), @ExplicitModifiers = ()] | | | +- ClassType[@FullyQualified = false, @PackageQualifier = null, @SimpleName = "Integer"] @@ -27,7 +27,7 @@ | | +- StringLiteral[@CompileTimeConstant = true, @ConstValue = "int %d", @Empty = false, @Image = "\"int %d\"", @Length = 6, @LiteralText = "\"int %d\"", @ParenthesisDepth = 0, @Parenthesized = false, @TextBlock = false] | | +- VariableAccess[@AccessType = AccessType.READ, @CompileTimeConstant = false, @Image = "i", @Name = "i", @ParenthesisDepth = 0, @Parenthesized = false] | +- SwitchArrowBranch[@Default = false] - | | +- SwitchLabel[@Default = false] + | | +- SwitchLabel[@Default = false, @PatternLabel = true] | | | +- TypePattern[@EffectiveVisibility = Visibility.V_PACKAGE, @Visibility = Visibility.V_PACKAGE] | | | +- ModifierList[@EffectiveModifiers = (), @ExplicitModifiers = ()] | | | +- ClassType[@FullyQualified = false, @PackageQualifier = null, @SimpleName = "Long"] @@ -39,7 +39,7 @@ | | +- StringLiteral[@CompileTimeConstant = true, @ConstValue = "long %d", @Empty = false, @Image = "\"long %d\"", @Length = 7, @LiteralText = "\"long %d\"", @ParenthesisDepth = 0, @Parenthesized = false, @TextBlock = false] | | +- VariableAccess[@AccessType = AccessType.READ, @CompileTimeConstant = false, @Image = "l", @Name = "l", @ParenthesisDepth = 0, @Parenthesized = false] | +- SwitchArrowBranch[@Default = false] - | | +- SwitchLabel[@Default = false] + | | +- SwitchLabel[@Default = false, @PatternLabel = true] | | | +- TypePattern[@EffectiveVisibility = Visibility.V_PACKAGE, @Visibility = Visibility.V_PACKAGE] | | | +- ModifierList[@EffectiveModifiers = (), @ExplicitModifiers = ()] | | | +- ClassType[@FullyQualified = false, @PackageQualifier = null, @SimpleName = "Double"] @@ -51,7 +51,7 @@ | | +- StringLiteral[@CompileTimeConstant = true, @ConstValue = "double %f", @Empty = false, @Image = "\"double %f\"", @Length = 9, @LiteralText = "\"double %f\"", @ParenthesisDepth = 0, @Parenthesized = false, @TextBlock = false] | | +- VariableAccess[@AccessType = AccessType.READ, @CompileTimeConstant = false, @Image = "d", @Name = "d", @ParenthesisDepth = 0, @Parenthesized = false] | +- SwitchArrowBranch[@Default = false] - | | +- SwitchLabel[@Default = false] + | | +- SwitchLabel[@Default = false, @PatternLabel = true] | | | +- TypePattern[@EffectiveVisibility = Visibility.V_PACKAGE, @Visibility = Visibility.V_PACKAGE] | | | +- ModifierList[@EffectiveModifiers = (), @ExplicitModifiers = ()] | | | +- ClassType[@FullyQualified = false, @PackageQualifier = null, @SimpleName = "String"] @@ -63,7 +63,7 @@ | | +- StringLiteral[@CompileTimeConstant = true, @ConstValue = "String %s", @Empty = false, @Image = "\"String %s\"", @Length = 9, @LiteralText = "\"String %s\"", @ParenthesisDepth = 0, @Parenthesized = false, @TextBlock = false] | | +- VariableAccess[@AccessType = AccessType.READ, @CompileTimeConstant = false, @Image = "s", @Name = "s", @ParenthesisDepth = 0, @Parenthesized = false] | +- SwitchArrowBranch[@Default = true] - | +- SwitchLabel[@Default = true] + | +- SwitchLabel[@Default = true, @PatternLabel = false] | +- MethodCall[@CompileTimeConstant = false, @Image = "toString", @MethodName = "toString", @ParenthesisDepth = 0, @Parenthesized = false] | +- VariableAccess[@AccessType = AccessType.READ, @CompileTimeConstant = false, @Image = "obj", @Name = "obj", @ParenthesisDepth = 0, @Parenthesized = false] | +- ArgumentList[@Empty = true, @Size = 0] @@ -79,7 +79,7 @@ | +- SwitchStatement[@DefaultCase = true, @EnumSwitch = false, @ExhaustiveEnumSwitch = false, @FallthroughSwitch = false] | +- VariableAccess[@AccessType = AccessType.READ, @CompileTimeConstant = false, @Image = "s", @Name = "s", @ParenthesisDepth = 0, @Parenthesized = false] | +- SwitchArrowBranch[@Default = false] - | | +- SwitchLabel[@Default = false] + | | +- SwitchLabel[@Default = false, @PatternLabel = false] | | | +- NullLiteral[@CompileTimeConstant = false, @LiteralText = "null", @ParenthesisDepth = 0, @Parenthesized = false] | | +- MethodCall[@CompileTimeConstant = false, @Image = "println", @MethodName = "println", @ParenthesisDepth = 0, @Parenthesized = false] | | +- FieldAccess[@AccessType = AccessType.READ, @CompileTimeConstant = false, @Image = "out", @Name = "out", @ParenthesisDepth = 0, @Parenthesized = false] @@ -88,7 +88,7 @@ | | +- ArgumentList[@Empty = false, @Size = 1] | | +- StringLiteral[@CompileTimeConstant = true, @ConstValue = "Oops", @Empty = false, @Image = "\"Oops\"", @Length = 4, @LiteralText = "\"Oops\"", @ParenthesisDepth = 0, @Parenthesized = false, @TextBlock = false] | +- SwitchArrowBranch[@Default = false] - | | +- SwitchLabel[@Default = false] + | | +- SwitchLabel[@Default = false, @PatternLabel = false] | | | +- StringLiteral[@CompileTimeConstant = true, @ConstValue = "Foo", @Empty = false, @Image = "\"Foo\"", @Length = 3, @LiteralText = "\"Foo\"", @ParenthesisDepth = 0, @Parenthesized = false, @TextBlock = false] | | | +- StringLiteral[@CompileTimeConstant = true, @ConstValue = "Bar", @Empty = false, @Image = "\"Bar\"", @Length = 3, @LiteralText = "\"Bar\"", @ParenthesisDepth = 0, @Parenthesized = false, @TextBlock = false] | | +- MethodCall[@CompileTimeConstant = false, @Image = "println", @MethodName = "println", @ParenthesisDepth = 0, @Parenthesized = false] @@ -98,7 +98,7 @@ | | +- ArgumentList[@Empty = false, @Size = 1] | | +- StringLiteral[@CompileTimeConstant = true, @ConstValue = "Great", @Empty = false, @Image = "\"Great\"", @Length = 5, @LiteralText = "\"Great\"", @ParenthesisDepth = 0, @Parenthesized = false, @TextBlock = false] | +- SwitchArrowBranch[@Default = true] - | +- SwitchLabel[@Default = true] + | +- SwitchLabel[@Default = true, @PatternLabel = false] | +- MethodCall[@CompileTimeConstant = false, @Image = "println", @MethodName = "println", @ParenthesisDepth = 0, @Parenthesized = false] | +- FieldAccess[@AccessType = AccessType.READ, @CompileTimeConstant = false, @Image = "out", @Name = "out", @ParenthesisDepth = 0, @Parenthesized = false] | | +- TypeExpression[@CompileTimeConstant = false, @ParenthesisDepth = 0, @Parenthesized = false] @@ -117,11 +117,11 @@ | +- SwitchStatement[@DefaultCase = false, @EnumSwitch = false, @ExhaustiveEnumSwitch = false, @FallthroughSwitch = false] | +- VariableAccess[@AccessType = AccessType.READ, @CompileTimeConstant = false, @Image = "response", @Name = "response", @ParenthesisDepth = 0, @Parenthesized = false] | +- SwitchArrowBranch[@Default = false] - | | +- SwitchLabel[@Default = false] + | | +- SwitchLabel[@Default = false, @PatternLabel = false] | | | +- NullLiteral[@CompileTimeConstant = false, @LiteralText = "null", @ParenthesisDepth = 0, @Parenthesized = false] | | +- Block[@Empty = true, @Size = 0, @containsComment = false] | +- SwitchArrowBranch[@Default = false] - | | +- SwitchLabel[@Default = false] + | | +- SwitchLabel[@Default = false, @PatternLabel = true] | | | +- TypePattern[@EffectiveVisibility = Visibility.V_PACKAGE, @Visibility = Visibility.V_PACKAGE] | | | | +- ModifierList[@EffectiveModifiers = (), @ExplicitModifiers = ()] | | | | +- ClassType[@FullyQualified = false, @PackageQualifier = null, @SimpleName = "String"] @@ -140,7 +140,7 @@ | | +- ArgumentList[@Empty = false, @Size = 1] | | +- StringLiteral[@CompileTimeConstant = true, @ConstValue = "You got it", @Empty = false, @Image = "\"You got it\"", @Length = 10, @LiteralText = "\"You got it\"", @ParenthesisDepth = 0, @Parenthesized = false, @TextBlock = false] | +- SwitchArrowBranch[@Default = false] - | | +- SwitchLabel[@Default = false] + | | +- SwitchLabel[@Default = false, @PatternLabel = true] | | | +- TypePattern[@EffectiveVisibility = Visibility.V_PACKAGE, @Visibility = Visibility.V_PACKAGE] | | | | +- ModifierList[@EffectiveModifiers = (), @ExplicitModifiers = ()] | | | | +- ClassType[@FullyQualified = false, @PackageQualifier = null, @SimpleName = "String"] @@ -159,7 +159,7 @@ | | +- ArgumentList[@Empty = false, @Size = 1] | | +- StringLiteral[@CompileTimeConstant = true, @ConstValue = "Shame", @Empty = false, @Image = "\"Shame\"", @Length = 5, @LiteralText = "\"Shame\"", @ParenthesisDepth = 0, @Parenthesized = false, @TextBlock = false] | +- SwitchArrowBranch[@Default = false] - | +- SwitchLabel[@Default = false] + | +- SwitchLabel[@Default = false, @PatternLabel = true] | | +- TypePattern[@EffectiveVisibility = Visibility.V_PACKAGE, @Visibility = Visibility.V_PACKAGE] | | +- ModifierList[@EffectiveModifiers = (), @ExplicitModifiers = ()] | | +- ClassType[@FullyQualified = false, @PackageQualifier = null, @SimpleName = "String"] @@ -184,11 +184,11 @@ | +- SwitchStatement[@DefaultCase = false, @EnumSwitch = false, @ExhaustiveEnumSwitch = false, @FallthroughSwitch = false] | +- VariableAccess[@AccessType = AccessType.READ, @CompileTimeConstant = false, @Image = "response", @Name = "response", @ParenthesisDepth = 0, @Parenthesized = false] | +- SwitchArrowBranch[@Default = false] - | | +- SwitchLabel[@Default = false] + | | +- SwitchLabel[@Default = false, @PatternLabel = false] | | | +- NullLiteral[@CompileTimeConstant = false, @LiteralText = "null", @ParenthesisDepth = 0, @Parenthesized = false] | | +- Block[@Empty = true, @Size = 0, @containsComment = false] | +- SwitchArrowBranch[@Default = false] - | | +- SwitchLabel[@Default = false] + | | +- SwitchLabel[@Default = false, @PatternLabel = false] | | | +- StringLiteral[@CompileTimeConstant = true, @ConstValue = "y", @Empty = false, @Image = "\"y\"", @Length = 1, @LiteralText = "\"y\"", @ParenthesisDepth = 0, @Parenthesized = false, @TextBlock = false] | | | +- StringLiteral[@CompileTimeConstant = true, @ConstValue = "Y", @Empty = false, @Image = "\"Y\"", @Length = 1, @LiteralText = "\"Y\"", @ParenthesisDepth = 0, @Parenthesized = false, @TextBlock = false] | | +- Block[@Empty = false, @Size = 1, @containsComment = false] @@ -200,7 +200,7 @@ | | +- ArgumentList[@Empty = false, @Size = 1] | | +- StringLiteral[@CompileTimeConstant = true, @ConstValue = "You got it", @Empty = false, @Image = "\"You got it\"", @Length = 10, @LiteralText = "\"You got it\"", @ParenthesisDepth = 0, @Parenthesized = false, @TextBlock = false] | +- SwitchArrowBranch[@Default = false] - | | +- SwitchLabel[@Default = false] + | | +- SwitchLabel[@Default = false, @PatternLabel = false] | | | +- StringLiteral[@CompileTimeConstant = true, @ConstValue = "n", @Empty = false, @Image = "\"n\"", @Length = 1, @LiteralText = "\"n\"", @ParenthesisDepth = 0, @Parenthesized = false, @TextBlock = false] | | | +- StringLiteral[@CompileTimeConstant = true, @ConstValue = "N", @Empty = false, @Image = "\"N\"", @Length = 1, @LiteralText = "\"N\"", @ParenthesisDepth = 0, @Parenthesized = false, @TextBlock = false] | | +- Block[@Empty = false, @Size = 1, @containsComment = false] @@ -212,7 +212,7 @@ | | +- ArgumentList[@Empty = false, @Size = 1] | | +- StringLiteral[@CompileTimeConstant = true, @ConstValue = "Shame", @Empty = false, @Image = "\"Shame\"", @Length = 5, @LiteralText = "\"Shame\"", @ParenthesisDepth = 0, @Parenthesized = false, @TextBlock = false] | +- SwitchArrowBranch[@Default = false] - | | +- SwitchLabel[@Default = false] + | | +- SwitchLabel[@Default = false, @PatternLabel = true] | | | +- TypePattern[@EffectiveVisibility = Visibility.V_PACKAGE, @Visibility = Visibility.V_PACKAGE] | | | | +- ModifierList[@EffectiveModifiers = (), @ExplicitModifiers = ()] | | | | +- ClassType[@FullyQualified = false, @PackageQualifier = null, @SimpleName = "String"] @@ -231,7 +231,7 @@ | | +- ArgumentList[@Empty = false, @Size = 1] | | +- StringLiteral[@CompileTimeConstant = true, @ConstValue = "You got it", @Empty = false, @Image = "\"You got it\"", @Length = 10, @LiteralText = "\"You got it\"", @ParenthesisDepth = 0, @Parenthesized = false, @TextBlock = false] | +- SwitchArrowBranch[@Default = false] - | | +- SwitchLabel[@Default = false] + | | +- SwitchLabel[@Default = false, @PatternLabel = true] | | | +- TypePattern[@EffectiveVisibility = Visibility.V_PACKAGE, @Visibility = Visibility.V_PACKAGE] | | | | +- ModifierList[@EffectiveModifiers = (), @ExplicitModifiers = ()] | | | | +- ClassType[@FullyQualified = false, @PackageQualifier = null, @SimpleName = "String"] @@ -250,7 +250,7 @@ | | +- ArgumentList[@Empty = false, @Size = 1] | | +- StringLiteral[@CompileTimeConstant = true, @ConstValue = "Shame", @Empty = false, @Image = "\"Shame\"", @Length = 5, @LiteralText = "\"Shame\"", @ParenthesisDepth = 0, @Parenthesized = false, @TextBlock = false] | +- SwitchArrowBranch[@Default = false] - | +- SwitchLabel[@Default = false] + | +- SwitchLabel[@Default = false, @PatternLabel = true] | | +- TypePattern[@EffectiveVisibility = Visibility.V_PACKAGE, @Visibility = Visibility.V_PACKAGE] | | +- ModifierList[@EffectiveModifiers = (), @ExplicitModifiers = ()] | | +- ClassType[@FullyQualified = false, @PackageQualifier = null, @SimpleName = "String"] @@ -303,7 +303,7 @@ | +- SwitchStatement[@DefaultCase = false, @EnumSwitch = false, @ExhaustiveEnumSwitch = false, @FallthroughSwitch = false] | +- VariableAccess[@AccessType = AccessType.READ, @CompileTimeConstant = false, @Image = "c", @Name = "c", @ParenthesisDepth = 0, @Parenthesized = false] | +- SwitchArrowBranch[@Default = false] - | | +- SwitchLabel[@Default = false] + | | +- SwitchLabel[@Default = false, @PatternLabel = true] | | | +- TypePattern[@EffectiveVisibility = Visibility.V_PACKAGE, @Visibility = Visibility.V_PACKAGE] | | | | +- ModifierList[@EffectiveModifiers = (), @ExplicitModifiers = ()] | | | | +- ClassType[@FullyQualified = false, @PackageQualifier = null, @SimpleName = "Suit"] @@ -323,7 +323,7 @@ | | +- ArgumentList[@Empty = false, @Size = 1] | | +- StringLiteral[@CompileTimeConstant = true, @ConstValue = "It\'s clubs", @Empty = false, @Image = "\"It\'s clubs\"", @Length = 10, @LiteralText = "\"It\'s clubs\"", @ParenthesisDepth = 0, @Parenthesized = false, @TextBlock = false] | +- SwitchArrowBranch[@Default = false] - | | +- SwitchLabel[@Default = false] + | | +- SwitchLabel[@Default = false, @PatternLabel = true] | | | +- TypePattern[@EffectiveVisibility = Visibility.V_PACKAGE, @Visibility = Visibility.V_PACKAGE] | | | | +- ModifierList[@EffectiveModifiers = (), @ExplicitModifiers = ()] | | | | +- ClassType[@FullyQualified = false, @PackageQualifier = null, @SimpleName = "Suit"] @@ -343,7 +343,7 @@ | | +- ArgumentList[@Empty = false, @Size = 1] | | +- StringLiteral[@CompileTimeConstant = true, @ConstValue = "It\'s diamonds", @Empty = false, @Image = "\"It\'s diamonds\"", @Length = 13, @LiteralText = "\"It\'s diamonds\"", @ParenthesisDepth = 0, @Parenthesized = false, @TextBlock = false] | +- SwitchArrowBranch[@Default = false] - | | +- SwitchLabel[@Default = false] + | | +- SwitchLabel[@Default = false, @PatternLabel = true] | | | +- TypePattern[@EffectiveVisibility = Visibility.V_PACKAGE, @Visibility = Visibility.V_PACKAGE] | | | | +- ModifierList[@EffectiveModifiers = (), @ExplicitModifiers = ()] | | | | +- ClassType[@FullyQualified = false, @PackageQualifier = null, @SimpleName = "Suit"] @@ -363,7 +363,7 @@ | | +- ArgumentList[@Empty = false, @Size = 1] | | +- StringLiteral[@CompileTimeConstant = true, @ConstValue = "It\'s hearts", @Empty = false, @Image = "\"It\'s hearts\"", @Length = 11, @LiteralText = "\"It\'s hearts\"", @ParenthesisDepth = 0, @Parenthesized = false, @TextBlock = false] | +- SwitchArrowBranch[@Default = false] - | | +- SwitchLabel[@Default = false] + | | +- SwitchLabel[@Default = false, @PatternLabel = true] | | | +- TypePattern[@EffectiveVisibility = Visibility.V_PACKAGE, @Visibility = Visibility.V_PACKAGE] | | | +- ModifierList[@EffectiveModifiers = (), @ExplicitModifiers = ()] | | | +- ClassType[@FullyQualified = false, @PackageQualifier = null, @SimpleName = "Suit"] @@ -377,7 +377,7 @@ | | +- ArgumentList[@Empty = false, @Size = 1] | | +- StringLiteral[@CompileTimeConstant = true, @ConstValue = "It\'s spades", @Empty = false, @Image = "\"It\'s spades\"", @Length = 11, @LiteralText = "\"It\'s spades\"", @ParenthesisDepth = 0, @Parenthesized = false, @TextBlock = false] | +- SwitchArrowBranch[@Default = false] - | +- SwitchLabel[@Default = false] + | +- SwitchLabel[@Default = false, @PatternLabel = true] | | +- TypePattern[@EffectiveVisibility = Visibility.V_PACKAGE, @Visibility = Visibility.V_PACKAGE] | | +- ModifierList[@EffectiveModifiers = (), @ExplicitModifiers = ()] | | +- ClassType[@FullyQualified = false, @PackageQualifier = null, @SimpleName = "Tarot"] @@ -402,7 +402,7 @@ | +- SwitchStatement[@DefaultCase = false, @EnumSwitch = false, @ExhaustiveEnumSwitch = false, @FallthroughSwitch = false] | +- VariableAccess[@AccessType = AccessType.READ, @CompileTimeConstant = false, @Image = "c", @Name = "c", @ParenthesisDepth = 0, @Parenthesized = false] | +- SwitchArrowBranch[@Default = false] - | | +- SwitchLabel[@Default = false] + | | +- SwitchLabel[@Default = false, @PatternLabel = false] | | | +- FieldAccess[@AccessType = AccessType.READ, @CompileTimeConstant = false, @Image = "CLUBS", @Name = "CLUBS", @ParenthesisDepth = 0, @Parenthesized = false] | | | +- TypeExpression[@CompileTimeConstant = false, @ParenthesisDepth = 0, @Parenthesized = false] | | | +- ClassType[@FullyQualified = false, @PackageQualifier = null, @SimpleName = "Suit"] @@ -415,7 +415,7 @@ | | +- ArgumentList[@Empty = false, @Size = 1] | | +- StringLiteral[@CompileTimeConstant = true, @ConstValue = "It\'s clubs", @Empty = false, @Image = "\"It\'s clubs\"", @Length = 10, @LiteralText = "\"It\'s clubs\"", @ParenthesisDepth = 0, @Parenthesized = false, @TextBlock = false] | +- SwitchArrowBranch[@Default = false] - | | +- SwitchLabel[@Default = false] + | | +- SwitchLabel[@Default = false, @PatternLabel = false] | | | +- FieldAccess[@AccessType = AccessType.READ, @CompileTimeConstant = false, @Image = "DIAMONDS", @Name = "DIAMONDS", @ParenthesisDepth = 0, @Parenthesized = false] | | | +- TypeExpression[@CompileTimeConstant = false, @ParenthesisDepth = 0, @Parenthesized = false] | | | +- ClassType[@FullyQualified = false, @PackageQualifier = null, @SimpleName = "Suit"] @@ -428,7 +428,7 @@ | | +- ArgumentList[@Empty = false, @Size = 1] | | +- StringLiteral[@CompileTimeConstant = true, @ConstValue = "It\'s diamonds", @Empty = false, @Image = "\"It\'s diamonds\"", @Length = 13, @LiteralText = "\"It\'s diamonds\"", @ParenthesisDepth = 0, @Parenthesized = false, @TextBlock = false] | +- SwitchArrowBranch[@Default = false] - | | +- SwitchLabel[@Default = false] + | | +- SwitchLabel[@Default = false, @PatternLabel = false] | | | +- FieldAccess[@AccessType = AccessType.READ, @CompileTimeConstant = false, @Image = "HEARTS", @Name = "HEARTS", @ParenthesisDepth = 0, @Parenthesized = false] | | | +- TypeExpression[@CompileTimeConstant = false, @ParenthesisDepth = 0, @Parenthesized = false] | | | +- ClassType[@FullyQualified = false, @PackageQualifier = null, @SimpleName = "Suit"] @@ -441,7 +441,7 @@ | | +- ArgumentList[@Empty = false, @Size = 1] | | +- StringLiteral[@CompileTimeConstant = true, @ConstValue = "It\'s hearts", @Empty = false, @Image = "\"It\'s hearts\"", @Length = 11, @LiteralText = "\"It\'s hearts\"", @ParenthesisDepth = 0, @Parenthesized = false, @TextBlock = false] | +- SwitchArrowBranch[@Default = false] - | | +- SwitchLabel[@Default = false] + | | +- SwitchLabel[@Default = false, @PatternLabel = false] | | | +- FieldAccess[@AccessType = AccessType.READ, @CompileTimeConstant = false, @Image = "SPADES", @Name = "SPADES", @ParenthesisDepth = 0, @Parenthesized = false] | | | +- TypeExpression[@CompileTimeConstant = false, @ParenthesisDepth = 0, @Parenthesized = false] | | | +- ClassType[@FullyQualified = false, @PackageQualifier = null, @SimpleName = "Suit"] @@ -454,7 +454,7 @@ | | +- ArgumentList[@Empty = false, @Size = 1] | | +- StringLiteral[@CompileTimeConstant = true, @ConstValue = "It\'s spades", @Empty = false, @Image = "\"It\'s spades\"", @Length = 11, @LiteralText = "\"It\'s spades\"", @ParenthesisDepth = 0, @Parenthesized = false, @TextBlock = false] | +- SwitchArrowBranch[@Default = false] - | +- SwitchLabel[@Default = false] + | +- SwitchLabel[@Default = false, @PatternLabel = true] | | +- TypePattern[@EffectiveVisibility = Visibility.V_PACKAGE, @Visibility = Visibility.V_PACKAGE] | | +- ModifierList[@EffectiveModifiers = (), @ExplicitModifiers = ()] | | +- ClassType[@FullyQualified = false, @PackageQualifier = null, @SimpleName = "Tarot"] @@ -495,7 +495,7 @@ | +- SwitchStatement[@DefaultCase = false, @EnumSwitch = false, @ExhaustiveEnumSwitch = false, @FallthroughSwitch = false] | +- VariableAccess[@AccessType = AccessType.READ, @CompileTimeConstant = false, @Image = "c", @Name = "c", @ParenthesisDepth = 0, @Parenthesized = false] | +- SwitchArrowBranch[@Default = false] - | | +- SwitchLabel[@Default = false] + | | +- SwitchLabel[@Default = false, @PatternLabel = false] | | | +- FieldAccess[@AccessType = AccessType.READ, @CompileTimeConstant = false, @Image = "HEADS", @Name = "HEADS", @ParenthesisDepth = 0, @Parenthesized = false] | | | +- TypeExpression[@CompileTimeConstant = false, @ParenthesisDepth = 0, @Parenthesized = false] | | | +- ClassType[@FullyQualified = false, @PackageQualifier = null, @SimpleName = "Coin"] @@ -508,7 +508,7 @@ | | +- ArgumentList[@Empty = false, @Size = 1] | | +- StringLiteral[@CompileTimeConstant = true, @ConstValue = "Heads", @Empty = false, @Image = "\"Heads\"", @Length = 5, @LiteralText = "\"Heads\"", @ParenthesisDepth = 0, @Parenthesized = false, @TextBlock = false] | +- SwitchArrowBranch[@Default = false] - | +- SwitchLabel[@Default = false] + | +- SwitchLabel[@Default = false, @PatternLabel = false] | | +- FieldAccess[@AccessType = AccessType.READ, @CompileTimeConstant = false, @Image = "TAILS", @Name = "TAILS", @ParenthesisDepth = 0, @Parenthesized = false] | | +- TypeExpression[@CompileTimeConstant = false, @ParenthesisDepth = 0, @Parenthesized = false] | | +- ClassType[@FullyQualified = false, @PackageQualifier = null, @SimpleName = "Coin"] @@ -532,7 +532,7 @@ +- SwitchStatement[@DefaultCase = false, @EnumSwitch = true, @ExhaustiveEnumSwitch = true, @FallthroughSwitch = false] +- VariableAccess[@AccessType = AccessType.READ, @CompileTimeConstant = false, @Image = "c", @Name = "c", @ParenthesisDepth = 0, @Parenthesized = false] +- SwitchArrowBranch[@Default = false] - | +- SwitchLabel[@Default = false] + | +- SwitchLabel[@Default = false, @PatternLabel = false] | | +- VariableAccess[@AccessType = AccessType.READ, @CompileTimeConstant = false, @Image = "HEADS", @Name = "HEADS", @ParenthesisDepth = 0, @Parenthesized = false] | +- Block[@Empty = false, @Size = 1, @containsComment = false] | +- ExpressionStatement[] @@ -543,7 +543,7 @@ | +- ArgumentList[@Empty = false, @Size = 1] | +- StringLiteral[@CompileTimeConstant = true, @ConstValue = "Heads", @Empty = false, @Image = "\"Heads\"", @Length = 5, @LiteralText = "\"Heads\"", @ParenthesisDepth = 0, @Parenthesized = false, @TextBlock = false] +- SwitchArrowBranch[@Default = false] - +- SwitchLabel[@Default = false] + +- SwitchLabel[@Default = false, @PatternLabel = false] | +- FieldAccess[@AccessType = AccessType.READ, @CompileTimeConstant = false, @Image = "TAILS", @Name = "TAILS", @ParenthesisDepth = 0, @Parenthesized = false] | +- TypeExpression[@CompileTimeConstant = false, @ParenthesisDepth = 0, @Parenthesized = false] | +- ClassType[@FullyQualified = false, @PackageQualifier = null, @SimpleName = "Coin"] diff --git a/pmd-java/src/test/resources/net/sourceforge/pmd/lang/java/ast/jdkversiontests/java21/PatternsInSwitchLabels.txt b/pmd-java/src/test/resources/net/sourceforge/pmd/lang/java/ast/jdkversiontests/java21/PatternsInSwitchLabels.txt index c77d9dc179..c78fee3b6c 100644 --- a/pmd-java/src/test/resources/net/sourceforge/pmd/lang/java/ast/jdkversiontests/java21/PatternsInSwitchLabels.txt +++ b/pmd-java/src/test/resources/net/sourceforge/pmd/lang/java/ast/jdkversiontests/java21/PatternsInSwitchLabels.txt @@ -28,7 +28,7 @@ | +- SwitchExpression[@CompileTimeConstant = false, @DefaultCase = true, @EnumSwitch = false, @ExhaustiveEnumSwitch = false, @FallthroughSwitch = false, @ParenthesisDepth = 0, @Parenthesized = false] | +- VariableAccess[@AccessType = AccessType.READ, @CompileTimeConstant = false, @Image = "o", @Name = "o", @ParenthesisDepth = 0, @Parenthesized = false] | +- SwitchArrowBranch[@Default = false] - | | +- SwitchLabel[@Default = false] + | | +- SwitchLabel[@Default = false, @PatternLabel = true] | | | +- TypePattern[@EffectiveVisibility = Visibility.V_PACKAGE, @Visibility = Visibility.V_PACKAGE] | | | +- ModifierList[@EffectiveModifiers = (), @ExplicitModifiers = ()] | | | +- ClassType[@FullyQualified = false, @PackageQualifier = null, @SimpleName = "Integer"] @@ -40,7 +40,7 @@ | | +- StringLiteral[@CompileTimeConstant = true, @ConstValue = "int %d", @Empty = false, @Image = "\"int %d\"", @Length = 6, @LiteralText = "\"int %d\"", @ParenthesisDepth = 0, @Parenthesized = false, @TextBlock = false] | | +- VariableAccess[@AccessType = AccessType.READ, @CompileTimeConstant = false, @Image = "i", @Name = "i", @ParenthesisDepth = 0, @Parenthesized = false] | +- SwitchArrowBranch[@Default = false] - | | +- SwitchLabel[@Default = false] + | | +- SwitchLabel[@Default = false, @PatternLabel = true] | | | +- TypePattern[@EffectiveVisibility = Visibility.V_PACKAGE, @Visibility = Visibility.V_PACKAGE] | | | +- ModifierList[@EffectiveModifiers = (), @ExplicitModifiers = ()] | | | +- ClassType[@FullyQualified = false, @PackageQualifier = null, @SimpleName = "Long"] @@ -52,7 +52,7 @@ | | +- StringLiteral[@CompileTimeConstant = true, @ConstValue = "long %d", @Empty = false, @Image = "\"long %d\"", @Length = 7, @LiteralText = "\"long %d\"", @ParenthesisDepth = 0, @Parenthesized = false, @TextBlock = false] | | +- VariableAccess[@AccessType = AccessType.READ, @CompileTimeConstant = false, @Image = "l", @Name = "l", @ParenthesisDepth = 0, @Parenthesized = false] | +- SwitchArrowBranch[@Default = false] - | | +- SwitchLabel[@Default = false] + | | +- SwitchLabel[@Default = false, @PatternLabel = true] | | | +- TypePattern[@EffectiveVisibility = Visibility.V_PACKAGE, @Visibility = Visibility.V_PACKAGE] | | | +- ModifierList[@EffectiveModifiers = (), @ExplicitModifiers = ()] | | | +- ClassType[@FullyQualified = false, @PackageQualifier = null, @SimpleName = "Double"] @@ -64,7 +64,7 @@ | | +- StringLiteral[@CompileTimeConstant = true, @ConstValue = "double %f", @Empty = false, @Image = "\"double %f\"", @Length = 9, @LiteralText = "\"double %f\"", @ParenthesisDepth = 0, @Parenthesized = false, @TextBlock = false] | | +- VariableAccess[@AccessType = AccessType.READ, @CompileTimeConstant = false, @Image = "d", @Name = "d", @ParenthesisDepth = 0, @Parenthesized = false] | +- SwitchArrowBranch[@Default = false] - | | +- SwitchLabel[@Default = false] + | | +- SwitchLabel[@Default = false, @PatternLabel = true] | | | +- TypePattern[@EffectiveVisibility = Visibility.V_PACKAGE, @Visibility = Visibility.V_PACKAGE] | | | +- ModifierList[@EffectiveModifiers = (), @ExplicitModifiers = ()] | | | +- ClassType[@FullyQualified = false, @PackageQualifier = null, @SimpleName = "String"] @@ -76,7 +76,7 @@ | | +- StringLiteral[@CompileTimeConstant = true, @ConstValue = "String %s", @Empty = false, @Image = "\"String %s\"", @Length = 9, @LiteralText = "\"String %s\"", @ParenthesisDepth = 0, @Parenthesized = false, @TextBlock = false] | | +- VariableAccess[@AccessType = AccessType.READ, @CompileTimeConstant = false, @Image = "s", @Name = "s", @ParenthesisDepth = 0, @Parenthesized = false] | +- SwitchArrowBranch[@Default = true] - | +- SwitchLabel[@Default = true] + | +- SwitchLabel[@Default = true, @PatternLabel = false] | +- MethodCall[@CompileTimeConstant = false, @Image = "toString", @MethodName = "toString", @ParenthesisDepth = 0, @Parenthesized = false] | +- VariableAccess[@AccessType = AccessType.READ, @CompileTimeConstant = false, @Image = "o", @Name = "o", @ParenthesisDepth = 0, @Parenthesized = false] | +- ArgumentList[@Empty = true, @Size = 0] diff --git a/pmd-java/src/test/resources/net/sourceforge/pmd/lang/java/ast/jdkversiontests/java21/RecordPatternsExhaustiveSwitch.txt b/pmd-java/src/test/resources/net/sourceforge/pmd/lang/java/ast/jdkversiontests/java21/RecordPatternsExhaustiveSwitch.txt index ce5ef0f93d..78a8d5d495 100644 --- a/pmd-java/src/test/resources/net/sourceforge/pmd/lang/java/ast/jdkversiontests/java21/RecordPatternsExhaustiveSwitch.txt +++ b/pmd-java/src/test/resources/net/sourceforge/pmd/lang/java/ast/jdkversiontests/java21/RecordPatternsExhaustiveSwitch.txt @@ -64,7 +64,7 @@ +- SwitchStatement[@DefaultCase = false, @EnumSwitch = false, @ExhaustiveEnumSwitch = false, @FallthroughSwitch = false] | +- VariableAccess[@AccessType = AccessType.READ, @CompileTimeConstant = false, @Image = "p1", @Name = "p1", @ParenthesisDepth = 0, @Parenthesized = false] | +- SwitchArrowBranch[@Default = false] - | | +- SwitchLabel[@Default = false] + | | +- SwitchLabel[@Default = false, @PatternLabel = true] | | | +- RecordPattern[] | | | +- ClassType[@FullyQualified = false, @PackageQualifier = null, @SimpleName = "Pair"] | | | | +- TypeArguments[@Diamond = false, @Empty = false, @Size = 1] @@ -85,7 +85,7 @@ | | +- ArgumentList[@Empty = false, @Size = 1] | | +- StringLiteral[@CompileTimeConstant = true, @ConstValue = "a", @Empty = false, @Image = "\"a\"", @Length = 1, @LiteralText = "\"a\"", @ParenthesisDepth = 0, @Parenthesized = false, @TextBlock = false] | +- SwitchArrowBranch[@Default = false] - | | +- SwitchLabel[@Default = false] + | | +- SwitchLabel[@Default = false, @PatternLabel = true] | | | +- RecordPattern[] | | | +- ClassType[@FullyQualified = false, @PackageQualifier = null, @SimpleName = "Pair"] | | | | +- TypeArguments[@Diamond = false, @Empty = false, @Size = 1] @@ -106,7 +106,7 @@ | | +- ArgumentList[@Empty = false, @Size = 1] | | +- StringLiteral[@CompileTimeConstant = true, @ConstValue = "a", @Empty = false, @Image = "\"a\"", @Length = 1, @LiteralText = "\"a\"", @ParenthesisDepth = 0, @Parenthesized = false, @TextBlock = false] | +- SwitchArrowBranch[@Default = false] - | +- SwitchLabel[@Default = false] + | +- SwitchLabel[@Default = false, @PatternLabel = true] | | +- RecordPattern[] | | +- ClassType[@FullyQualified = false, @PackageQualifier = null, @SimpleName = "Pair"] | | | +- TypeArguments[@Diamond = false, @Empty = false, @Size = 1] @@ -129,7 +129,7 @@ +- SwitchStatement[@DefaultCase = false, @EnumSwitch = false, @ExhaustiveEnumSwitch = false, @FallthroughSwitch = false] | +- VariableAccess[@AccessType = AccessType.READ, @CompileTimeConstant = false, @Image = "p2", @Name = "p2", @ParenthesisDepth = 0, @Parenthesized = false] | +- SwitchArrowBranch[@Default = false] - | | +- SwitchLabel[@Default = false] + | | +- SwitchLabel[@Default = false, @PatternLabel = true] | | | +- RecordPattern[] | | | +- ClassType[@FullyQualified = false, @PackageQualifier = null, @SimpleName = "Pair"] | | | | +- TypeArguments[@Diamond = false, @Empty = false, @Size = 1] @@ -150,7 +150,7 @@ | | +- ArgumentList[@Empty = false, @Size = 1] | | +- StringLiteral[@CompileTimeConstant = true, @ConstValue = "a", @Empty = false, @Image = "\"a\"", @Length = 1, @LiteralText = "\"a\"", @ParenthesisDepth = 0, @Parenthesized = false, @TextBlock = false] | +- SwitchArrowBranch[@Default = false] - | +- SwitchLabel[@Default = false] + | +- SwitchLabel[@Default = false, @PatternLabel = true] | | +- RecordPattern[] | | +- ClassType[@FullyQualified = false, @PackageQualifier = null, @SimpleName = "Pair"] | | | +- TypeArguments[@Diamond = false, @Empty = false, @Size = 1] @@ -173,7 +173,7 @@ +- SwitchStatement[@DefaultCase = false, @EnumSwitch = false, @ExhaustiveEnumSwitch = false, @FallthroughSwitch = false] +- VariableAccess[@AccessType = AccessType.READ, @CompileTimeConstant = false, @Image = "p2", @Name = "p2", @ParenthesisDepth = 0, @Parenthesized = false] +- SwitchArrowBranch[@Default = false] - | +- SwitchLabel[@Default = false] + | +- SwitchLabel[@Default = false, @PatternLabel = true] | | +- RecordPattern[] | | +- ClassType[@FullyQualified = false, @PackageQualifier = null, @SimpleName = "Pair"] | | | +- TypeArguments[@Diamond = false, @Empty = false, @Size = 1] @@ -194,7 +194,7 @@ | +- ArgumentList[@Empty = false, @Size = 1] | +- StringLiteral[@CompileTimeConstant = true, @ConstValue = "a", @Empty = false, @Image = "\"a\"", @Length = 1, @LiteralText = "\"a\"", @ParenthesisDepth = 0, @Parenthesized = false, @TextBlock = false] +- SwitchArrowBranch[@Default = false] - | +- SwitchLabel[@Default = false] + | +- SwitchLabel[@Default = false, @PatternLabel = true] | | +- RecordPattern[] | | +- ClassType[@FullyQualified = false, @PackageQualifier = null, @SimpleName = "Pair"] | | | +- TypeArguments[@Diamond = false, @Empty = false, @Size = 1] @@ -215,7 +215,7 @@ | +- ArgumentList[@Empty = false, @Size = 1] | +- StringLiteral[@CompileTimeConstant = true, @ConstValue = "a", @Empty = false, @Image = "\"a\"", @Length = 1, @LiteralText = "\"a\"", @ParenthesisDepth = 0, @Parenthesized = false, @TextBlock = false] +- SwitchArrowBranch[@Default = false] - +- SwitchLabel[@Default = false] + +- SwitchLabel[@Default = false, @PatternLabel = true] | +- RecordPattern[] | +- ClassType[@FullyQualified = false, @PackageQualifier = null, @SimpleName = "Pair"] | | +- TypeArguments[@Diamond = false, @Empty = false, @Size = 1] diff --git a/pmd-java/src/test/resources/net/sourceforge/pmd/lang/java/ast/jdkversiontests/java21/RefiningPatternsInSwitch.txt b/pmd-java/src/test/resources/net/sourceforge/pmd/lang/java/ast/jdkversiontests/java21/RefiningPatternsInSwitch.txt index 60f0406293..8090943eaf 100644 --- a/pmd-java/src/test/resources/net/sourceforge/pmd/lang/java/ast/jdkversiontests/java21/RefiningPatternsInSwitch.txt +++ b/pmd-java/src/test/resources/net/sourceforge/pmd/lang/java/ast/jdkversiontests/java21/RefiningPatternsInSwitch.txt @@ -52,11 +52,11 @@ | +- SwitchStatement[@DefaultCase = true, @EnumSwitch = false, @ExhaustiveEnumSwitch = false, @FallthroughSwitch = true] | +- VariableAccess[@AccessType = AccessType.READ, @CompileTimeConstant = false, @Image = "s", @Name = "s", @ParenthesisDepth = 0, @Parenthesized = false] | +- SwitchFallthroughBranch[@Default = false] - | | +- SwitchLabel[@Default = false] + | | +- SwitchLabel[@Default = false, @PatternLabel = false] | | | +- NullLiteral[@CompileTimeConstant = false, @LiteralText = "null", @ParenthesisDepth = 0, @Parenthesized = false] | | +- BreakStatement[@Label = null] | +- SwitchFallthroughBranch[@Default = false] - | | +- SwitchLabel[@Default = false] + | | +- SwitchLabel[@Default = false, @PatternLabel = true] | | | +- TypePattern[@EffectiveVisibility = Visibility.V_PACKAGE, @Visibility = Visibility.V_PACKAGE] | | | +- ModifierList[@EffectiveModifiers = (), @ExplicitModifiers = ()] | | | +- ClassType[@FullyQualified = false, @PackageQualifier = null, @SimpleName = "Triangle"] @@ -77,7 +77,7 @@ | | | +- StringLiteral[@CompileTimeConstant = true, @ConstValue = "Large triangle", @Empty = false, @Image = "\"Large triangle\"", @Length = 14, @LiteralText = "\"Large triangle\"", @ParenthesisDepth = 0, @Parenthesized = false, @TextBlock = false] | | +- BreakStatement[@Label = null] | +- SwitchFallthroughBranch[@Default = true] - | +- SwitchLabel[@Default = true] + | +- SwitchLabel[@Default = true, @PatternLabel = false] | +- ExpressionStatement[] | +- MethodCall[@CompileTimeConstant = false, @Image = "println", @MethodName = "println", @ParenthesisDepth = 0, @Parenthesized = false] | +- FieldAccess[@AccessType = AccessType.READ, @CompileTimeConstant = false, @Image = "out", @Name = "out", @ParenthesisDepth = 0, @Parenthesized = false] @@ -97,12 +97,12 @@ | +- SwitchStatement[@DefaultCase = true, @EnumSwitch = false, @ExhaustiveEnumSwitch = false, @FallthroughSwitch = false] | +- VariableAccess[@AccessType = AccessType.READ, @CompileTimeConstant = false, @Image = "s", @Name = "s", @ParenthesisDepth = 0, @Parenthesized = false] | +- SwitchArrowBranch[@Default = false] - | | +- SwitchLabel[@Default = false] + | | +- SwitchLabel[@Default = false, @PatternLabel = false] | | | +- NullLiteral[@CompileTimeConstant = false, @LiteralText = "null", @ParenthesisDepth = 0, @Parenthesized = false] | | +- Block[@Empty = false, @Size = 1, @containsComment = false] | | +- BreakStatement[@Label = null] | +- SwitchArrowBranch[@Default = false] - | | +- SwitchLabel[@Default = false] + | | +- SwitchLabel[@Default = false, @PatternLabel = true] | | | +- TypePattern[@EffectiveVisibility = Visibility.V_PACKAGE, @Visibility = Visibility.V_PACKAGE] | | | | +- ModifierList[@EffectiveModifiers = (), @ExplicitModifiers = ()] | | | | +- ClassType[@FullyQualified = false, @PackageQualifier = null, @SimpleName = "Triangle"] @@ -120,7 +120,7 @@ | | +- ArgumentList[@Empty = false, @Size = 1] | | +- StringLiteral[@CompileTimeConstant = true, @ConstValue = "Large triangle", @Empty = false, @Image = "\"Large triangle\"", @Length = 14, @LiteralText = "\"Large triangle\"", @ParenthesisDepth = 0, @Parenthesized = false, @TextBlock = false] | +- SwitchArrowBranch[@Default = true] - | +- SwitchLabel[@Default = true] + | +- SwitchLabel[@Default = true, @PatternLabel = false] | +- MethodCall[@CompileTimeConstant = false, @Image = "println", @MethodName = "println", @ParenthesisDepth = 0, @Parenthesized = false] | +- FieldAccess[@AccessType = AccessType.READ, @CompileTimeConstant = false, @Image = "out", @Name = "out", @ParenthesisDepth = 0, @Parenthesized = false] | | +- TypeExpression[@CompileTimeConstant = false, @ParenthesisDepth = 0, @Parenthesized = false] @@ -139,12 +139,12 @@ | +- SwitchStatement[@DefaultCase = true, @EnumSwitch = false, @ExhaustiveEnumSwitch = false, @FallthroughSwitch = false] | +- VariableAccess[@AccessType = AccessType.READ, @CompileTimeConstant = false, @Image = "s", @Name = "s", @ParenthesisDepth = 0, @Parenthesized = false] | +- SwitchArrowBranch[@Default = false] - | | +- SwitchLabel[@Default = false] + | | +- SwitchLabel[@Default = false, @PatternLabel = false] | | | +- NullLiteral[@CompileTimeConstant = false, @LiteralText = "null", @ParenthesisDepth = 0, @Parenthesized = false] | | +- Block[@Empty = false, @Size = 1, @containsComment = false] | | +- BreakStatement[@Label = null] | +- SwitchArrowBranch[@Default = false] - | | +- SwitchLabel[@Default = false] + | | +- SwitchLabel[@Default = false, @PatternLabel = true] | | | +- TypePattern[@EffectiveVisibility = Visibility.V_PACKAGE, @Visibility = Visibility.V_PACKAGE] | | | | +- ModifierList[@EffectiveModifiers = (), @ExplicitModifiers = ()] | | | | +- ClassType[@FullyQualified = false, @PackageQualifier = null, @SimpleName = "Triangle"] @@ -162,7 +162,7 @@ | | +- ArgumentList[@Empty = false, @Size = 1] | | +- StringLiteral[@CompileTimeConstant = true, @ConstValue = "Large triangle", @Empty = false, @Image = "\"Large triangle\"", @Length = 14, @LiteralText = "\"Large triangle\"", @ParenthesisDepth = 0, @Parenthesized = false, @TextBlock = false] | +- SwitchArrowBranch[@Default = false] - | | +- SwitchLabel[@Default = false] + | | +- SwitchLabel[@Default = false, @PatternLabel = true] | | | +- TypePattern[@EffectiveVisibility = Visibility.V_PACKAGE, @Visibility = Visibility.V_PACKAGE] | | | +- ModifierList[@EffectiveModifiers = (), @ExplicitModifiers = ()] | | | +- ClassType[@FullyQualified = false, @PackageQualifier = null, @SimpleName = "Triangle"] @@ -174,7 +174,7 @@ | | +- ArgumentList[@Empty = false, @Size = 1] | | +- StringLiteral[@CompileTimeConstant = true, @ConstValue = "Small triangle", @Empty = false, @Image = "\"Small triangle\"", @Length = 14, @LiteralText = "\"Small triangle\"", @ParenthesisDepth = 0, @Parenthesized = false, @TextBlock = false] | +- SwitchArrowBranch[@Default = true] - | +- SwitchLabel[@Default = true] + | +- SwitchLabel[@Default = true, @PatternLabel = false] | +- MethodCall[@CompileTimeConstant = false, @Image = "println", @MethodName = "println", @ParenthesisDepth = 0, @Parenthesized = false] | +- FieldAccess[@AccessType = AccessType.READ, @CompileTimeConstant = false, @Image = "out", @Name = "out", @ParenthesisDepth = 0, @Parenthesized = false] | | +- TypeExpression[@CompileTimeConstant = false, @ParenthesisDepth = 0, @Parenthesized = false] diff --git a/pmd-java/src/test/resources/net/sourceforge/pmd/lang/java/ast/jdkversiontests/java21/ScopeOfPatternVariableDeclarations.txt b/pmd-java/src/test/resources/net/sourceforge/pmd/lang/java/ast/jdkversiontests/java21/ScopeOfPatternVariableDeclarations.txt index 34fed8bb67..ee01695dd4 100644 --- a/pmd-java/src/test/resources/net/sourceforge/pmd/lang/java/ast/jdkversiontests/java21/ScopeOfPatternVariableDeclarations.txt +++ b/pmd-java/src/test/resources/net/sourceforge/pmd/lang/java/ast/jdkversiontests/java21/ScopeOfPatternVariableDeclarations.txt @@ -14,7 +14,7 @@ | +- SwitchStatement[@DefaultCase = true, @EnumSwitch = false, @ExhaustiveEnumSwitch = false, @FallthroughSwitch = true] | +- VariableAccess[@AccessType = AccessType.READ, @CompileTimeConstant = false, @Image = "obj", @Name = "obj", @ParenthesisDepth = 0, @Parenthesized = false] | +- SwitchFallthroughBranch[@Default = false] - | | +- SwitchLabel[@Default = false] + | | +- SwitchLabel[@Default = false, @PatternLabel = true] | | | +- TypePattern[@EffectiveVisibility = Visibility.V_PACKAGE, @Visibility = Visibility.V_PACKAGE] | | | | +- ModifierList[@EffectiveModifiers = (), @ExplicitModifiers = ()] | | | | +- ClassType[@FullyQualified = false, @PackageQualifier = null, @SimpleName = "Character"] @@ -34,7 +34,7 @@ | | | +- StringLiteral[@CompileTimeConstant = true, @ConstValue = "Ding!", @Empty = false, @Image = "\"Ding!\"", @Length = 5, @LiteralText = "\"Ding!\"", @ParenthesisDepth = 0, @Parenthesized = false, @TextBlock = false] | | +- BreakStatement[@Label = null] | +- SwitchFallthroughBranch[@Default = true] - | +- SwitchLabel[@Default = true] + | +- SwitchLabel[@Default = true, @PatternLabel = false] | +- BreakStatement[@Label = null] +- MethodDeclaration[@Abstract = false, @Arity = 1, @EffectiveVisibility = Visibility.V_PACKAGE, @Final = false, @Name = "testSwitchRule", @Overridden = false, @Static = true, @Varargs = false, @Visibility = Visibility.V_PACKAGE, @Void = true] | +- ModifierList[@EffectiveModifiers = (JModifier.STATIC), @ExplicitModifiers = (JModifier.STATIC)] @@ -48,7 +48,7 @@ | +- SwitchStatement[@DefaultCase = true, @EnumSwitch = false, @ExhaustiveEnumSwitch = false, @FallthroughSwitch = false] | +- VariableAccess[@AccessType = AccessType.READ, @CompileTimeConstant = false, @Image = "o", @Name = "o", @ParenthesisDepth = 0, @Parenthesized = false] | +- SwitchArrowBranch[@Default = false] - | | +- SwitchLabel[@Default = false] + | | +- SwitchLabel[@Default = false, @PatternLabel = true] | | | +- TypePattern[@EffectiveVisibility = Visibility.V_PACKAGE, @Visibility = Visibility.V_PACKAGE] | | | +- ModifierList[@EffectiveModifiers = (), @ExplicitModifiers = ()] | | | +- ClassType[@FullyQualified = false, @PackageQualifier = null, @SimpleName = "Character"] @@ -76,7 +76,7 @@ | | +- ArgumentList[@Empty = false, @Size = 1] | | +- StringLiteral[@CompileTimeConstant = true, @ConstValue = "Character", @Empty = false, @Image = "\"Character\"", @Length = 9, @LiteralText = "\"Character\"", @ParenthesisDepth = 0, @Parenthesized = false, @TextBlock = false] | +- SwitchArrowBranch[@Default = false] - | | +- SwitchLabel[@Default = false] + | | +- SwitchLabel[@Default = false, @PatternLabel = true] | | | +- TypePattern[@EffectiveVisibility = Visibility.V_PACKAGE, @Visibility = Visibility.V_PACKAGE] | | | +- ModifierList[@EffectiveModifiers = (), @ExplicitModifiers = ()] | | | +- ClassType[@FullyQualified = false, @PackageQualifier = null, @SimpleName = "Integer"] @@ -91,7 +91,7 @@ | | +- VariableAccess[@AccessType = AccessType.READ, @CompileTimeConstant = false, @Image = "i", @Name = "i", @ParenthesisDepth = 0, @Parenthesized = false] | | +- ArgumentList[@Empty = true, @Size = 0] | +- SwitchArrowBranch[@Default = true] - | +- SwitchLabel[@Default = true] + | +- SwitchLabel[@Default = true, @PatternLabel = false] | +- Block[@Empty = false, @Size = 1, @containsComment = false] | +- BreakStatement[@Label = null] +- MethodDeclaration[@Abstract = false, @Arity = 1, @EffectiveVisibility = Visibility.V_PACKAGE, @Final = false, @Name = "test2", @Overridden = false, @Static = true, @Varargs = false, @Visibility = Visibility.V_PACKAGE, @Void = true] @@ -106,7 +106,7 @@ | +- SwitchStatement[@DefaultCase = true, @EnumSwitch = false, @ExhaustiveEnumSwitch = false, @FallthroughSwitch = true] | +- VariableAccess[@AccessType = AccessType.READ, @CompileTimeConstant = false, @Image = "o", @Name = "o", @ParenthesisDepth = 0, @Parenthesized = false] | +- SwitchFallthroughBranch[@Default = false] - | | +- SwitchLabel[@Default = false] + | | +- SwitchLabel[@Default = false, @PatternLabel = true] | | | +- TypePattern[@EffectiveVisibility = Visibility.V_PACKAGE, @Visibility = Visibility.V_PACKAGE] | | | +- ModifierList[@EffectiveModifiers = (), @ExplicitModifiers = ()] | | | +- ClassType[@FullyQualified = false, @PackageQualifier = null, @SimpleName = "Character"] @@ -147,7 +147,7 @@ | | +- ArgumentList[@Empty = false, @Size = 1] | | +- StringLiteral[@CompileTimeConstant = true, @ConstValue = "character", @Empty = false, @Image = "\"character\"", @Length = 9, @LiteralText = "\"character\"", @ParenthesisDepth = 0, @Parenthesized = false, @TextBlock = false] | +- SwitchFallthroughBranch[@Default = true] - | +- SwitchLabel[@Default = true] + | +- SwitchLabel[@Default = true, @PatternLabel = false] | +- ExpressionStatement[] | +- MethodCall[@CompileTimeConstant = false, @Image = "println", @MethodName = "println", @ParenthesisDepth = 0, @Parenthesized = false] | +- FieldAccess[@AccessType = AccessType.READ, @CompileTimeConstant = false, @Image = "out", @Name = "out", @ParenthesisDepth = 0, @Parenthesized = false] diff --git a/pmd-java/src/test/resources/net/sourceforge/pmd/lang/java/ast/jdkversiontests/java22/Jep456_UnnamedPatternsAndVariables.txt b/pmd-java/src/test/resources/net/sourceforge/pmd/lang/java/ast/jdkversiontests/java22/Jep456_UnnamedPatternsAndVariables.txt index e77a4d2574..06b6a2128c 100644 --- a/pmd-java/src/test/resources/net/sourceforge/pmd/lang/java/ast/jdkversiontests/java22/Jep456_UnnamedPatternsAndVariables.txt +++ b/pmd-java/src/test/resources/net/sourceforge/pmd/lang/java/ast/jdkversiontests/java22/Jep456_UnnamedPatternsAndVariables.txt @@ -181,7 +181,7 @@ | +- SwitchStatement[@DefaultCase = false, @EnumSwitch = false, @ExhaustiveEnumSwitch = false, @FallthroughSwitch = false] | | +- VariableAccess[@AccessType = AccessType.READ, @CompileTimeConstant = false, @Image = "b", @Name = "b", @ParenthesisDepth = 0, @Parenthesized = false] | | +- SwitchArrowBranch[@Default = false] - | | | +- SwitchLabel[@Default = false] + | | | +- SwitchLabel[@Default = false, @PatternLabel = true] | | | | +- RecordPattern[] | | | | +- ClassType[@FullyQualified = false, @PackageQualifier = null, @SimpleName = "Box"] | | | | +- PatternList[@Empty = false, @Size = 1] @@ -193,7 +193,7 @@ | | | +- ArgumentList[@Empty = false, @Size = 1] | | | +- VariableAccess[@AccessType = AccessType.READ, @CompileTimeConstant = false, @Image = "b", @Name = "b", @ParenthesisDepth = 0, @Parenthesized = false] | | +- SwitchArrowBranch[@Default = false] - | | | +- SwitchLabel[@Default = false] + | | | +- SwitchLabel[@Default = false, @PatternLabel = true] | | | | +- RecordPattern[] | | | | +- ClassType[@FullyQualified = false, @PackageQualifier = null, @SimpleName = "Box"] | | | | +- PatternList[@Empty = false, @Size = 1] @@ -205,7 +205,7 @@ | | | +- ArgumentList[@Empty = false, @Size = 1] | | | +- VariableAccess[@AccessType = AccessType.READ, @CompileTimeConstant = false, @Image = "b", @Name = "b", @ParenthesisDepth = 0, @Parenthesized = false] | | +- SwitchArrowBranch[@Default = false] - | | +- SwitchLabel[@Default = false] + | | +- SwitchLabel[@Default = false, @PatternLabel = true] | | | +- RecordPattern[] | | | +- ClassType[@FullyQualified = false, @PackageQualifier = null, @SimpleName = "Box"] | | | +- PatternList[@Empty = false, @Size = 1] @@ -218,7 +218,7 @@ | +- SwitchStatement[@DefaultCase = false, @EnumSwitch = false, @ExhaustiveEnumSwitch = false, @FallthroughSwitch = false] | | +- VariableAccess[@AccessType = AccessType.READ, @CompileTimeConstant = false, @Image = "b", @Name = "b", @ParenthesisDepth = 0, @Parenthesized = false] | | +- SwitchArrowBranch[@Default = false] - | | | +- SwitchLabel[@Default = false] + | | | +- SwitchLabel[@Default = false, @PatternLabel = true] | | | | +- RecordPattern[] | | | | | +- ClassType[@FullyQualified = false, @PackageQualifier = null, @SimpleName = "Box"] | | | | | +- PatternList[@Empty = false, @Size = 1] @@ -237,7 +237,7 @@ | | | +- ArgumentList[@Empty = false, @Size = 1] | | | +- VariableAccess[@AccessType = AccessType.READ, @CompileTimeConstant = false, @Image = "b", @Name = "b", @ParenthesisDepth = 0, @Parenthesized = false] | | +- SwitchArrowBranch[@Default = false] - | | | +- SwitchLabel[@Default = false] + | | | +- SwitchLabel[@Default = false, @PatternLabel = true] | | | | +- RecordPattern[] | | | | +- ClassType[@FullyQualified = false, @PackageQualifier = null, @SimpleName = "Box"] | | | | +- PatternList[@Empty = false, @Size = 1] @@ -248,7 +248,7 @@ | | | +- MethodCall[@CompileTimeConstant = false, @Image = "stopProcessing", @MethodName = "stopProcessing", @ParenthesisDepth = 0, @Parenthesized = false] | | | +- ArgumentList[@Empty = true, @Size = 0] | | +- SwitchArrowBranch[@Default = false] - | | +- SwitchLabel[@Default = false] + | | +- SwitchLabel[@Default = false, @PatternLabel = true] | | | +- RecordPattern[] | | | +- ClassType[@FullyQualified = false, @PackageQualifier = null, @SimpleName = "Box"] | | | +- PatternList[@Empty = false, @Size = 1] @@ -264,7 +264,7 @@ | +- SwitchStatement[@DefaultCase = false, @EnumSwitch = false, @ExhaustiveEnumSwitch = false, @FallthroughSwitch = false] | +- VariableAccess[@AccessType = AccessType.READ, @CompileTimeConstant = false, @Image = "b", @Name = "b", @ParenthesisDepth = 0, @Parenthesized = false] | +- SwitchArrowBranch[@Default = false] - | | +- SwitchLabel[@Default = false] + | | +- SwitchLabel[@Default = false, @PatternLabel = true] | | | +- RecordPattern[] | | | | +- ClassType[@FullyQualified = false, @PackageQualifier = null, @SimpleName = "Box"] | | | | +- PatternList[@Empty = false, @Size = 1] @@ -287,7 +287,7 @@ | | +- ArgumentList[@Empty = false, @Size = 1] | | +- VariableAccess[@AccessType = AccessType.READ, @CompileTimeConstant = false, @Image = "b", @Name = "b", @ParenthesisDepth = 0, @Parenthesized = false] | +- SwitchArrowBranch[@Default = false] - | +- SwitchLabel[@Default = false] + | +- SwitchLabel[@Default = false, @PatternLabel = true] | | +- RecordPattern[] | | +- ClassType[@FullyQualified = false, @PackageQualifier = null, @SimpleName = "Box"] | | +- PatternList[@Empty = false, @Size = 1] diff --git a/pmd-java/src/test/resources/net/sourceforge/pmd/lang/java/ast/jdkversiontests/java22p/Jep447_StatementsBeforeSuper.txt b/pmd-java/src/test/resources/net/sourceforge/pmd/lang/java/ast/jdkversiontests/java22p/Jep447_StatementsBeforeSuper.txt index 7490fc68a2..9fa3cd2810 100644 --- a/pmd-java/src/test/resources/net/sourceforge/pmd/lang/java/ast/jdkversiontests/java22p/Jep447_StatementsBeforeSuper.txt +++ b/pmd-java/src/test/resources/net/sourceforge/pmd/lang/java/ast/jdkversiontests/java22p/Jep447_StatementsBeforeSuper.txt @@ -105,7 +105,7 @@ | | +- SwitchExpression[@CompileTimeConstant = false, @DefaultCase = true, @EnumSwitch = false, @ExhaustiveEnumSwitch = false, @FallthroughSwitch = false, @ParenthesisDepth = 0, @Parenthesized = false] | | +- VariableAccess[@AccessType = AccessType.READ, @CompileTimeConstant = false, @Image = "publicKey", @Name = "publicKey", @ParenthesisDepth = 0, @Parenthesized = false] | | +- SwitchArrowBranch[@Default = false] - | | | +- SwitchLabel[@Default = false] + | | | +- SwitchLabel[@Default = false, @PatternLabel = true] | | | | +- TypePattern[@EffectiveVisibility = Visibility.V_PACKAGE, @Visibility = Visibility.V_PACKAGE] | | | | +- ModifierList[@EffectiveModifiers = (), @ExplicitModifiers = ()] | | | | +- ClassType[@FullyQualified = false, @PackageQualifier = null, @SimpleName = "RSAKey"] @@ -119,7 +119,7 @@ | | | +- TypeExpression[@CompileTimeConstant = false, @ParenthesisDepth = 0, @Parenthesized = false] | | | +- ClassType[@FullyQualified = false, @PackageQualifier = null, @SimpleName = "StandardCharsets"] | | +- SwitchArrowBranch[@Default = false] - | | | +- SwitchLabel[@Default = false] + | | | +- SwitchLabel[@Default = false, @PatternLabel = true] | | | | +- TypePattern[@EffectiveVisibility = Visibility.V_PACKAGE, @Visibility = Visibility.V_PACKAGE] | | | | +- ModifierList[@EffectiveModifiers = (), @ExplicitModifiers = ()] | | | | +- ClassType[@FullyQualified = false, @PackageQualifier = null, @SimpleName = "DSAPublicKey"] @@ -133,7 +133,7 @@ | | | +- TypeExpression[@CompileTimeConstant = false, @ParenthesisDepth = 0, @Parenthesized = false] | | | +- ClassType[@FullyQualified = false, @PackageQualifier = null, @SimpleName = "StandardCharsets"] | | +- SwitchArrowBranch[@Default = true] - | | +- SwitchLabel[@Default = true] + | | +- SwitchLabel[@Default = true, @PatternLabel = false] | | +- ArrayAllocation[@ArrayDepth = 1, @CompileTimeConstant = false, @ParenthesisDepth = 0, @Parenthesized = false] | | +- ArrayType[@ArrayDepth = 1] | | +- PrimitiveType[@Kind = PrimitiveTypeKind.BYTE] diff --git a/pmd-java/src/test/resources/net/sourceforge/pmd/lang/java/ast/jdkversiontests/java23p/Jep455_PrimitiveTypesInPatternsInstanceofAndSwitch.txt b/pmd-java/src/test/resources/net/sourceforge/pmd/lang/java/ast/jdkversiontests/java23p/Jep455_PrimitiveTypesInPatternsInstanceofAndSwitch.txt index c80a09fff6..850597a25e 100644 --- a/pmd-java/src/test/resources/net/sourceforge/pmd/lang/java/ast/jdkversiontests/java23p/Jep455_PrimitiveTypesInPatternsInstanceofAndSwitch.txt +++ b/pmd-java/src/test/resources/net/sourceforge/pmd/lang/java/ast/jdkversiontests/java23p/Jep455_PrimitiveTypesInPatternsInstanceofAndSwitch.txt @@ -347,7 +347,7 @@ | +- SwitchStatement[@DefaultCase = false, @EnumSwitch = false, @ExhaustiveEnumSwitch = false, @FallthroughSwitch = true] | +- VariableAccess[@AccessType = AccessType.READ, @CompileTimeConstant = false, @Image = "i", @Name = "i", @ParenthesisDepth = 0, @Parenthesized = false] | +- SwitchFallthroughBranch[@Default = false] - | +- SwitchLabel[@Default = false] + | +- SwitchLabel[@Default = false, @PatternLabel = true] | | +- TypePattern[@EffectiveVisibility = Visibility.V_PACKAGE, @Visibility = Visibility.V_PACKAGE] | | +- ModifierList[@EffectiveModifiers = (), @ExplicitModifiers = ()] | | +- PrimitiveType[@Kind = PrimitiveTypeKind.DOUBLE] @@ -381,11 +381,11 @@ | | +- SwitchExpression[@CompileTimeConstant = false, @DefaultCase = false, @EnumSwitch = false, @ExhaustiveEnumSwitch = false, @FallthroughSwitch = false, @ParenthesisDepth = 0, @Parenthesized = false] | | +- VariableAccess[@AccessType = AccessType.READ, @CompileTimeConstant = false, @Image = "v", @Name = "v", @ParenthesisDepth = 0, @Parenthesized = false] | | +- SwitchArrowBranch[@Default = false] - | | | +- SwitchLabel[@Default = false] + | | | +- SwitchLabel[@Default = false, @PatternLabel = false] | | | | +- NumericLiteral[@Base = 10, @CompileTimeConstant = true, @DoubleLiteral = false, @FloatLiteral = true, @Image = "0f", @IntLiteral = false, @Integral = false, @LiteralText = "0f", @LongLiteral = false, @ParenthesisDepth = 0, @Parenthesized = false, @ValueAsDouble = 0.0, @ValueAsFloat = 0.0, @ValueAsInt = 0, @ValueAsLong = 0] | | | +- NumericLiteral[@Base = 10, @CompileTimeConstant = true, @DoubleLiteral = false, @FloatLiteral = true, @Image = "5f", @IntLiteral = false, @Integral = false, @LiteralText = "5f", @LongLiteral = false, @ParenthesisDepth = 0, @Parenthesized = false, @ValueAsDouble = 5.0, @ValueAsFloat = 5.0, @ValueAsInt = 5, @ValueAsLong = 5] | | +- SwitchArrowBranch[@Default = false] - | | | +- SwitchLabel[@Default = false] + | | | +- SwitchLabel[@Default = false, @PatternLabel = true] | | | | +- TypePattern[@EffectiveVisibility = Visibility.V_PACKAGE, @Visibility = Visibility.V_PACKAGE] | | | | | +- ModifierList[@EffectiveModifiers = (), @ExplicitModifiers = ()] | | | | | +- PrimitiveType[@Kind = PrimitiveTypeKind.FLOAT] @@ -398,7 +398,7 @@ | | | +- NumericLiteral[@Base = 10, @CompileTimeConstant = true, @DoubleLiteral = false, @FloatLiteral = true, @Image = "6f", @IntLiteral = false, @Integral = false, @LiteralText = "6f", @LongLiteral = false, @ParenthesisDepth = 0, @Parenthesized = false, @ValueAsDouble = 6.0, @ValueAsFloat = 6.0, @ValueAsInt = 6, @ValueAsLong = 6] | | | +- VariableAccess[@AccessType = AccessType.READ, @CompileTimeConstant = false, @Image = "x", @Name = "x", @ParenthesisDepth = 0, @Parenthesized = false] | | +- SwitchArrowBranch[@Default = false] - | | +- SwitchLabel[@Default = false] + | | +- SwitchLabel[@Default = false, @PatternLabel = true] | | | +- TypePattern[@EffectiveVisibility = Visibility.V_PACKAGE, @Visibility = Visibility.V_PACKAGE] | | | +- ModifierList[@EffectiveModifiers = (), @ExplicitModifiers = ()] | | | +- PrimitiveType[@Kind = PrimitiveTypeKind.FLOAT] @@ -424,7 +424,7 @@ | +- SwitchStatement[@DefaultCase = false, @EnumSwitch = false, @ExhaustiveEnumSwitch = false, @FallthroughSwitch = false] | +- VariableAccess[@AccessType = AccessType.READ, @CompileTimeConstant = false, @Image = "b", @Name = "b", @ParenthesisDepth = 0, @Parenthesized = false] | +- SwitchArrowBranch[@Default = false] - | | +- SwitchLabel[@Default = false] + | | +- SwitchLabel[@Default = false, @PatternLabel = false] | | | +- BooleanLiteral[@CompileTimeConstant = true, @LiteralText = "true", @ParenthesisDepth = 0, @Parenthesized = false, @True = true] | | +- MethodCall[@CompileTimeConstant = false, @Image = "println", @MethodName = "println", @ParenthesisDepth = 0, @Parenthesized = false] | | +- FieldAccess[@AccessType = AccessType.READ, @CompileTimeConstant = false, @Image = "out", @Name = "out", @ParenthesisDepth = 0, @Parenthesized = false] @@ -433,7 +433,7 @@ | | +- ArgumentList[@Empty = false, @Size = 1] | | +- StringLiteral[@CompileTimeConstant = true, @ConstValue = "b was true", @Empty = false, @Image = "\"b was true\"", @Length = 10, @LiteralText = "\"b was true\"", @ParenthesisDepth = 0, @Parenthesized = false, @TextBlock = false] | +- SwitchArrowBranch[@Default = false] - | +- SwitchLabel[@Default = false] + | +- SwitchLabel[@Default = false, @PatternLabel = false] | | +- BooleanLiteral[@CompileTimeConstant = true, @LiteralText = "false", @ParenthesisDepth = 0, @Parenthesized = false, @True = false] | +- MethodCall[@CompileTimeConstant = false, @Image = "println", @MethodName = "println", @ParenthesisDepth = 0, @Parenthesized = false] | +- FieldAccess[@AccessType = AccessType.READ, @CompileTimeConstant = false, @Image = "out", @Name = "out", @ParenthesisDepth = 0, @Parenthesized = false] diff --git a/pmd-java/src/test/resources/net/sourceforge/pmd/lang/java/ast/jdkversiontests/java23p/Jep482_FlexibleConstructorBodies.txt b/pmd-java/src/test/resources/net/sourceforge/pmd/lang/java/ast/jdkversiontests/java23p/Jep482_FlexibleConstructorBodies.txt index 549c591ece..a796c0b585 100644 --- a/pmd-java/src/test/resources/net/sourceforge/pmd/lang/java/ast/jdkversiontests/java23p/Jep482_FlexibleConstructorBodies.txt +++ b/pmd-java/src/test/resources/net/sourceforge/pmd/lang/java/ast/jdkversiontests/java23p/Jep482_FlexibleConstructorBodies.txt @@ -105,7 +105,7 @@ | | +- SwitchExpression[@CompileTimeConstant = false, @DefaultCase = true, @EnumSwitch = false, @ExhaustiveEnumSwitch = false, @FallthroughSwitch = false, @ParenthesisDepth = 0, @Parenthesized = false] | | +- VariableAccess[@AccessType = AccessType.READ, @CompileTimeConstant = false, @Image = "publicKey", @Name = "publicKey", @ParenthesisDepth = 0, @Parenthesized = false] | | +- SwitchArrowBranch[@Default = false] - | | | +- SwitchLabel[@Default = false] + | | | +- SwitchLabel[@Default = false, @PatternLabel = true] | | | | +- TypePattern[@EffectiveVisibility = Visibility.V_PACKAGE, @Visibility = Visibility.V_PACKAGE] | | | | +- ModifierList[@EffectiveModifiers = (), @ExplicitModifiers = ()] | | | | +- ClassType[@FullyQualified = false, @PackageQualifier = null, @SimpleName = "RSAKey"] @@ -119,7 +119,7 @@ | | | +- TypeExpression[@CompileTimeConstant = false, @ParenthesisDepth = 0, @Parenthesized = false] | | | +- ClassType[@FullyQualified = false, @PackageQualifier = null, @SimpleName = "StandardCharsets"] | | +- SwitchArrowBranch[@Default = false] - | | | +- SwitchLabel[@Default = false] + | | | +- SwitchLabel[@Default = false, @PatternLabel = true] | | | | +- TypePattern[@EffectiveVisibility = Visibility.V_PACKAGE, @Visibility = Visibility.V_PACKAGE] | | | | +- ModifierList[@EffectiveModifiers = (), @ExplicitModifiers = ()] | | | | +- ClassType[@FullyQualified = false, @PackageQualifier = null, @SimpleName = "DSAPublicKey"] @@ -133,7 +133,7 @@ | | | +- TypeExpression[@CompileTimeConstant = false, @ParenthesisDepth = 0, @Parenthesized = false] | | | +- ClassType[@FullyQualified = false, @PackageQualifier = null, @SimpleName = "StandardCharsets"] | | +- SwitchArrowBranch[@Default = true] - | | +- SwitchLabel[@Default = true] + | | +- SwitchLabel[@Default = true, @PatternLabel = false] | | +- ArrayAllocation[@ArrayDepth = 1, @CompileTimeConstant = false, @ParenthesisDepth = 0, @Parenthesized = false] | | +- ArrayType[@ArrayDepth = 1] | | +- PrimitiveType[@Kind = PrimitiveTypeKind.BYTE] diff --git a/pmd-java/src/test/resources/net/sourceforge/pmd/lang/java/rule/bestpractices/xml/UnitTestShouldUseAfterAnnotation.xml b/pmd-java/src/test/resources/net/sourceforge/pmd/lang/java/rule/bestpractices/xml/UnitTestShouldUseAfterAnnotation.xml index 7a3121d8fe..8b8c06285e 100644 --- a/pmd-java/src/test/resources/net/sourceforge/pmd/lang/java/rule/bestpractices/xml/UnitTestShouldUseAfterAnnotation.xml +++ b/pmd-java/src/test/resources/net/sourceforge/pmd/lang/java/rule/bestpractices/xml/UnitTestShouldUseAfterAnnotation.xml @@ -5,129 +5,69 @@ xsi:schemaLocation="http://pmd.sourceforge.net/rule-tests http://pmd.sourceforge.net/rule-tests_1_0_0.xsd"> - Contains tearDown + JUnit4 test class contains tearDown 1 + 3 - Contains @After tearDown + JUnit4 test class contains tearDown with different signature is ok + 0 + + + + + JUnit4 test class contains @After tearDown is ok 0 - Renamed tearDown + JUnit4 test class contains renamed tearDown is ok 0 - #1446 False positive with JUnit4TestShouldUseBeforeAnnotation when TestNG is used - 0 - - - - - #940 False positive with JUnit4TestShouldUseAfterAnnotation when JUnit5's 'AfterEach' is used - 0 - - - - - #940 False positive with JUnit4TestShouldUseAfterAnnotation when JUnit5's 'AfterAll' is used - 0 - - - - Contains tearDown, not a junit 4 test + Contains tearDown, not a JUnit 4/5 or TestNG test is ok 0 - - - Contains tearDown with different signature - 0 - @@ -151,4 +91,119 @@ public class AReallyCoolFeatureTest extends BaseTest { } ]]> + + + TestNG test contains tearDown + 1 + 4 + + + + + TestNG test contains tearDown with different signature is ok (#1446) + 0 + + + + + TestNG test contains tearDown with @AfterMethod is ok + 0 + + + + + TestNG test contains tearDown with @AfterClass is ok + 0 + + + + + JUnit 5 test class contains tearDown + 1 + 4 + + + + + JUnit 5 test class contains tearDown with @AfterEach is ok (#940) + 0 + + + + + JUnit 5 test class contains tearDown with @AfterAll is ok (#940) + 0 + + diff --git a/pmd-java/src/test/resources/net/sourceforge/pmd/lang/java/rule/bestpractices/xml/UnitTestShouldUseBeforeAnnotation.xml b/pmd-java/src/test/resources/net/sourceforge/pmd/lang/java/rule/bestpractices/xml/UnitTestShouldUseBeforeAnnotation.xml index 10d6fbc524..d9ae22cfd4 100644 --- a/pmd-java/src/test/resources/net/sourceforge/pmd/lang/java/rule/bestpractices/xml/UnitTestShouldUseBeforeAnnotation.xml +++ b/pmd-java/src/test/resources/net/sourceforge/pmd/lang/java/rule/bestpractices/xml/UnitTestShouldUseBeforeAnnotation.xml @@ -5,8 +5,9 @@ xsi:schemaLocation="http://pmd.sourceforge.net/rule-tests http://pmd.sourceforge.net/rule-tests_1_0_0.xsd"> - Contains setUp + JUnit4 Test class contains setUp 1 + 3 - Contains @setUp + JUnit4 Test class with Before is ok 0 - Renamed setup + JUnit4 Test class with renamed setup using Before is ok 0 - #1446 False positive with JUnit4TestShouldUseBeforeAnnotation when TestNG is used + Contains setUp, not a JUnit 4/5/TestNG test 0 + + + + JUnit4 Test class contains setUp with different signature is ok + 0 + - - - - #940 False positive with JUnit4TestShouldUseBeforeAnnotation when JUnit5's 'BeforeEach' is used - 0 - - - - - #940 False positive with JUnit4TestShouldUseBeforeAnnotation when JUnit5's 'BeforeAll' is used - 0 - - - - Contains setUp, not a junit 4 test - 0 - - - - Contains setUp with different signature - 0 - +]]> @@ -173,4 +118,120 @@ public class AReallyCoolFeatureTest extends BaseTest { } ]]> + + + TestNG class contains setUp + 1 + 4 + + + + + TestNG class contains setUp with different signature is ok (#1446) + 0 + + + + + TestNG with @BeforeMethod is ok (#1446) + 0 + + + + + TestNG with @BeforeClass is ok + 0 + + + + + JUnit5 Test class contains setUp + 1 + 4 + + + + + JUnit5 Test class with BeforeEach is ok (#940) + 0 + + + + + JUnit5 Test class with BeforeAll is ok (#940) + 0 + + diff --git a/pmd-java/src/test/resources/net/sourceforge/pmd/lang/java/rule/design/xml/SwitchDensity.xml b/pmd-java/src/test/resources/net/sourceforge/pmd/lang/java/rule/design/xml/SwitchDensity.xml index 8af61b0af7..1c3c21bf4d 100644 --- a/pmd-java/src/test/resources/net/sourceforge/pmd/lang/java/rule/design/xml/SwitchDensity.xml +++ b/pmd-java/src/test/resources/net/sourceforge/pmd/lang/java/rule/design/xml/SwitchDensity.xml @@ -155,4 +155,104 @@ public class SwitchWithDefault } ]]> + + + [java] SwitchDensity false positive with pattern matching #5030 + 4 + 0 + 0 -> + { + System.err.println("I am a fish."); + } + case Integer i -> + { + System.err.println("I am not a fish."); + } + default -> + { + System.err.println("default"); + } + } + } +} + ]]> + + + + [java] SwitchDensity with pattern matching #5030 + 4 + 1 + 0 -> + { + System.err.println("I am a fish."); + System.err.println("I am a fish."); + System.err.println("I am a fish."); + System.err.println("I am a fish."); + System.err.println("I am a fish."); + } + case Integer i -> + { + System.err.println("I am not a fish."); + System.err.println("I am not a fish."); + System.err.println("I am not a fish."); + System.err.println("I am not a fish."); + System.err.println("I am not a fish."); + System.err.println("I am not a fish."); + } + default -> + { + System.err.println("default"); + } + } + } +} + ]]> + + + + Switch with Record Pattern, ok + 0 + System.out.println(a); + } + } +} +]]> + + + + Switch with Record Pattern, not ok + 4 + 1 + { + System.out.println(a); + System.out.println(a); + System.out.println(a); + System.out.println(a); + System.out.println(a); + } + } + } +} +]]> + diff --git a/pmd-java/src/test/resources/net/sourceforge/pmd/lang/java/rule/errorprone/xml/ImplicitSwitchFallThrough.xml b/pmd-java/src/test/resources/net/sourceforge/pmd/lang/java/rule/errorprone/xml/ImplicitSwitchFallThrough.xml index 6d86131b0d..0ddd50e522 100644 --- a/pmd-java/src/test/resources/net/sourceforge/pmd/lang/java/rule/errorprone/xml/ImplicitSwitchFallThrough.xml +++ b/pmd-java/src/test/resources/net/sourceforge/pmd/lang/java/rule/errorprone/xml/ImplicitSwitchFallThrough.xml @@ -581,4 +581,24 @@ public class Test { } ]]> + + + switch expression with one case, which is not empty + 1 + 6 + +