-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[java] Add Java8TreeDumpTest for UnnamedVariable
Refs pmd#5004
- Loading branch information
Showing
4 changed files
with
70 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
29 changes: 29 additions & 0 deletions
29
pmd-java/src/test/java/net/sourceforge/pmd/lang/java/ast/Java8TreeDumpTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
/** | ||
* BSD-style license; for more info see http://pmd.sourceforge.net/license.html | ||
*/ | ||
|
||
package net.sourceforge.pmd.lang.java.ast; | ||
|
||
import org.checkerframework.checker.nullness.qual.NonNull; | ||
import org.junit.jupiter.api.Test; | ||
|
||
import net.sourceforge.pmd.lang.java.BaseJavaTreeDumpTest; | ||
import net.sourceforge.pmd.lang.java.JavaParsingHelper; | ||
import net.sourceforge.pmd.lang.test.ast.BaseParsingHelper; | ||
|
||
class Java8TreeDumpTest extends BaseJavaTreeDumpTest { | ||
|
||
private final JavaParsingHelper java8 = JavaParsingHelper.DEFAULT | ||
.withDefaultVersion("8") | ||
.withResourceContext(Java8TreeDumpTest.class, "jdkversiontests/java8"); | ||
|
||
@Test | ||
void unnamedVariablesAreAllowedWithJava8() { | ||
doTest("UnnamedVariable"); | ||
} | ||
|
||
@Override | ||
public @NonNull BaseParsingHelper<?, ?> getParser() { | ||
return java8; | ||
} | ||
} |
16 changes: 16 additions & 0 deletions
16
...st/resources/net/sourceforge/pmd/lang/java/ast/jdkversiontests/java8/UnnamedVariable.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
/* | ||
* BSD-style license; for more info see http://pmd.sourceforge.net/license.html | ||
*/ | ||
|
||
/** | ||
* See https://github.com/pmd/pmd/pull/5004: With Java 22, "_" are unnamed variables. | ||
* In Java 9-21 "_" is a restricted keyword and cannot be used as a variable name. | ||
* Before Java 9, "_" is still a valid name, but not a unnmaed variable. | ||
*/ | ||
class UnnamedVariable { | ||
void method() { | ||
int _ = 1; | ||
} | ||
|
||
void method2(int _) { } | ||
} |
24 changes: 24 additions & 0 deletions
24
...est/resources/net/sourceforge/pmd/lang/java/ast/jdkversiontests/java8/UnnamedVariable.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
+- CompilationUnit[@PackageName = ""] | ||
+- ClassDeclaration[@Abstract = false, @Annotation = false, @Anonymous = false, @BinaryName = "UnnamedVariable", @CanonicalName = "UnnamedVariable", @EffectiveVisibility = Visibility.V_PACKAGE, @Enum = false, @Final = false, @Interface = false, @Local = false, @Nested = false, @PackageName = "", @Record = false, @RegularClass = true, @RegularInterface = false, @SimpleName = "UnnamedVariable", @Static = false, @TopLevel = true, @Visibility = Visibility.V_PACKAGE] | ||
+- ModifierList[@EffectiveModifiers = (), @ExplicitModifiers = ()] | ||
+- ClassBody[@Empty = false, @Size = 2] | ||
+- MethodDeclaration[@Abstract = false, @Arity = 0, @EffectiveVisibility = Visibility.V_PACKAGE, @Final = false, @Name = "method", @Overridden = false, @Static = false, @Varargs = false, @Visibility = Visibility.V_PACKAGE, @Void = true] | ||
| +- ModifierList[@EffectiveModifiers = (), @ExplicitModifiers = ()] | ||
| +- VoidType[] | ||
| +- FormalParameters[@Empty = true, @Size = 0] | ||
| +- Block[@Empty = false, @Size = 1, @containsComment = false] | ||
| +- LocalVariableDeclaration[@EffectiveVisibility = Visibility.V_LOCAL, @Final = false, @TypeInferred = false, @Visibility = Visibility.V_LOCAL] | ||
| +- ModifierList[@EffectiveModifiers = (), @ExplicitModifiers = ()] | ||
| +- PrimitiveType[@Kind = PrimitiveTypeKind.INT] | ||
| +- VariableDeclarator[@Initializer = true, @Name = "_"] | ||
| +- VariableId[@ArrayType = false, @EffectiveVisibility = Visibility.V_LOCAL, @EnumConstant = false, @ExceptionBlockParameter = false, @Field = false, @Final = false, @ForLoopVariable = false, @ForeachVariable = false, @FormalParameter = false, @LambdaParameter = false, @LocalVariable = true, @Name = "_", @PatternBinding = false, @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] | ||
+- MethodDeclaration[@Abstract = false, @Arity = 1, @EffectiveVisibility = Visibility.V_PACKAGE, @Final = false, @Name = "method2", @Overridden = false, @Static = false, @Varargs = false, @Visibility = Visibility.V_PACKAGE, @Void = true] | ||
+- ModifierList[@EffectiveModifiers = (), @ExplicitModifiers = ()] | ||
+- VoidType[] | ||
+- FormalParameters[@Empty = false, @Size = 1] | ||
| +- FormalParameter[@EffectiveVisibility = Visibility.V_LOCAL, @Final = false, @Varargs = false, @Visibility = Visibility.V_LOCAL] | ||
| +- ModifierList[@EffectiveModifiers = (), @ExplicitModifiers = ()] | ||
| +- PrimitiveType[@Kind = PrimitiveTypeKind.INT] | ||
| +- VariableId[@ArrayType = false, @EffectiveVisibility = Visibility.V_LOCAL, @EnumConstant = false, @ExceptionBlockParameter = false, @Field = false, @Final = false, @ForLoopVariable = false, @ForeachVariable = false, @FormalParameter = true, @LambdaParameter = false, @LocalVariable = false, @Name = "_", @PatternBinding = false, @RecordComponent = false, @ResourceDeclaration = false, @Static = false, @TypeInferred = false, @Unnamed = false, @Visibility = Visibility.V_LOCAL] | ||
+- Block[@Empty = true, @Size = 0, @containsComment = false] |