[java] Rename ASTVariableDeclaratorId to ASTVariableId

This commit is contained in:
Andreas Dangel 2023-12-13 10:30:39 +01:00
parent 8198218ad7
commit ba0611534d
No known key found for this signature in database
GPG Key ID: 93450DF2DF9A3FA3
165 changed files with 1371 additions and 1375 deletions

View File

@ -129,7 +129,7 @@ langs:
examples:
- code: '//FormalParameter[pmd-java:typeIs("java.lang.String[]")]'
outcome: "Matches formal parameters of type `String[]` (including vararg parameters)"
- code: '//VariableDeclaratorId[pmd-java:typeIs("java.lang.List")]'
- code: '//VariableId[pmd-java:typeIs("java.lang.List")]'
outcome: "Matches variable declarators of type `List` or any of its subtypes (including e.g. `ArrayList`)"
- name: typeIsExactly
@ -142,7 +142,7 @@ langs:
parameters:
- *qname_param
examples:
- code: '//VariableDeclaratorId[pmd-java:typeIsExactly("java.lang.List")]'
- code: '//VariableId[pmd-java:typeIsExactly("java.lang.List")]'
outcome: "Matches variable declarators of type `List` (but not e.g. `ArrayList`)"

View File

@ -76,7 +76,7 @@ $ cat Foo.xml
<PrimitiveType Array='false' ArrayDepth='0' Boolean='false' Image='int' />
</Type>
<VariableDeclarator Image='' Initializer='false' Name='a'>
<VariableDeclaratorId Array='false' ArrayDepth='0' ArrayType='false' ExceptionBlockParameter='false' ExplicitReceiverParameter='false' Field='true' Final='false' FormalParameter='false' Image='a' LambdaParameter='false' LocalVariable='false' ResourceDeclaration='false' TypeInferred='false' VariableName='a' />
<VariableId Array='false' ArrayDepth='0' ArrayType='false' ExceptionBlockParameter='false' ExplicitReceiverParameter='false' Field='true' Final='false' FormalParameter='false' Image='a' LambdaParameter='false' LocalVariable='false' ResourceDeclaration='false' TypeInferred='false' VariableName='a' />
</VariableDeclarator>
</FieldDeclaration>
</ClassOrInterfaceBodyDeclaration>
@ -85,8 +85,8 @@ $ cat Foo.xml
</TypeDeclaration>
</CompilationUnit>
$ xmlstarlet select -t -c "//VariableDeclaratorId[@VariableName='a']" Foo.xml
<VariableDeclaratorId Array="false" ArrayDepth="0" ArrayType="false" ExceptionBlockParameter="false" ExplicitReceiverParameter="false" Field="true" Final="false" FormalParameter="false" Image="a" LambdaParameter="false" LocalVariable="false" ResourceDeclaration="false" TypeInferred="false" VariableName="a"/>
$ xmlstarlet select -t -c "//VariableId[@VariableName='a']" Foo.xml
<VariableId Array="false" ArrayDepth="0" ArrayType="false" ExceptionBlockParameter="false" ExplicitReceiverParameter="false" Field="true" Final="false" FormalParameter="false" Image="a" LambdaParameter="false" LocalVariable="false" ResourceDeclaration="false" TypeInferred="false" VariableName="a"/>
```
This example uses [xmlstarlet](http://xmlstar.sourceforge.net/) to query the xml document for any variables/fields

View File

@ -158,7 +158,7 @@ with a backslash when needed.
description="A StringMultiProperty." />
<property name="xpath">
<![CDATA[
//VariableDeclaratorId[@Image = $reportedIdentifiers]
//VariableId[@Image = $reportedIdentifiers]
]]></property>
</properties>
</rule>

View File

@ -61,8 +61,8 @@ public class MyRule extends AbstractJavaRule {
Generally, a rule wants to check for only some node types. In our XPath example
in [Your First Rule](pmd_userdocs_extending_your_first_rule.html),
we wanted to check for some `VariableDeclaratorId` nodes. That's the XPath name,
but in Java, you'll get access to the {% jdoc jast::ASTVariableDeclaratorId %}
we wanted to check for some `VariableId` nodes. That's the XPath name,
but in Java, you'll get access to the {% jdoc jast::ASTVariableId %}
full API.
If you want to check for some specific node types, you can override the
@ -72,8 +72,8 @@ corresponding `visit` method:
public class MyRule extends AbstractJavaRule {
@Override
public Object visit(ASTVariableDeclaratorId node, Object data) {
// This method is called on each node of type ASTVariableDeclaratorId
public Object visit(ASTVariableId node, Object data) {
// This method is called on each node of type ASTVariableId
// in the AST
if (node.getType() == short.class) {

View File

@ -83,11 +83,11 @@ public class KeepingItSerious {
```
Examining the AST, you find out that the LocalVariableDeclaration has a VariableDeclaratorId
descendant, whose `Image` XPath attribute is exactly `bill`. You thus write your first attempt
Examining the AST, you find out that the LocalVariableDeclaration has a VariableId
descendant, whose `Name` XPath attribute is exactly `bill`. You thus write your first attempt
in the XPath editor:
```xpath
//VariableDeclaratorId[@Image = "bill"]
//VariableId[@Name = "bill"]
```
You can see the XPath result list is updated with the variable declarator.
@ -112,7 +112,7 @@ based on your examination of the Type node of the field and local variable
declaration nodes.
```xpath
//VariableDeclaratorId[@Image = "bill" and ../../Type[@TypeImage = "short"]]
//VariableId[@Name = "bill" and ../../Type[@TypeImage = "short"]]
```
### Exporting to XML
@ -135,7 +135,7 @@ TODO
<property name="xpath">
<value>
<![CDATA[
//VariableDeclaratorId[../../Type[@TypeImage="short"] and @Image = "bill"]
//VariableId[../../Type[@TypeImage="short"] and @Image = "bill"]
]]>
</value>
</property>

View File

@ -38,7 +38,7 @@ There are a couple of deprecated things in PMD 6, you might encounter:
* If you have written custom XPath rule, look out for warnings about deprecated XPath attributes. These warnings
might look like
```
WARNING: Use of deprecated attribute 'VariableDeclaratorId/@Image' by XPath rule 'VariableNaming' (in ruleset 'VariableNamingRule'), please use @Name instead
WARNING: Use of deprecated attribute 'VariableId/@Image' by XPath rule 'VariableNaming' (in ruleset 'VariableNamingRule'), please use @Name instead
```
and often already suggest an alternative.
@ -101,7 +101,7 @@ override the method {% jdoc core::lang.rule.AbstractRule#buildTargetSelector %}:
```java
protected RuleTargetSelector buildTargetSelector() {
return RuleTargetSelector.forTypes(ASTVariableDeclaratorId.class);
return RuleTargetSelector.forTypes(ASTVariableId.class);
}
```
@ -318,7 +318,7 @@ Example:
```java
NodeStream.of(someNode) // the stream here is empty if the node is null
.filterIs(ASTVariableDeclaratorId.class)// the stream here is empty if the node was not a variable declarator id
.filterIs(ASTVariableId.class) // the stream here is empty if the node was not a variable id
.followingSiblings() // the stream here contains only the siblings, not the original node
.children(ASTNumericLiteral.class)
.filter(ASTNumericLiteral::isIntLiteral)
@ -397,6 +397,7 @@ which can also display the AST.
* ClassOrInterfaceDeclaration ➡️ ClassDeclaration ({% jdoc jast::ASTClassDeclaration %})
* AnyTypeDeclaration ➡️ TypeDeclaration ({% jdoc jast::ASTTypeDeclaration %})
* MethodOrConstructorDeclaration ➡️ ExecutableDeclaration ({% jdoc jast::ASTExecutableDeclaration %})
* VariableDeclaratorId ➡️ VariableId ({% jdoc jast::ASTVariableId %})
#### Annotations
@ -786,7 +787,7 @@ Array type
│ └─ Annotation "B"
│ └─ ClassType "B"
└─ VariableDeclarator
└─ VariableDeclaratorId "x"
└─ VariableId "x"
{% endhighlight %}
</td></tr>
@ -866,12 +867,12 @@ enum E {
│ ├─ ModifierList
│ │ └─ Annotation "A"
│ │ └─ ClassType "A"
│ └─ VariableDeclaratorId "E1"
│ └─ VariableId "E1"
└─ EnumConstant "E2"
├─ ModifierList
│ └─ Annotation "B"
│ └─ ClassType "B"
└─ VariableDeclaratorId "E2"
└─ VariableId "E2"
{% endhighlight %}
<ul>
@ -906,7 +907,7 @@ enum E {
* `Type/ReferenceType[@ArrayDepth > 1]/ClassOrInterfaceType` ➡️ `ArrayType/ClassType`.
* `Type/ReferenceType/PrimitiveType` ➡️ `ArrayType/PrimitiveType`.
* Note that in most cases you should check the type of a variable with e.g.
`VariableDeclaratorId[pmd-java:typeIs("java.lang.String[]")]` because it
`VariableId[pmd-java:typeIs("java.lang.String[]")]` because it
considers the additional dimensions on declarations like `String foo[];`.
The Java equivalent is `TypeHelper.isA(id, String[].class);`
@ -1352,10 +1353,10 @@ public void set(final int x, int y) { }
└─ FormalParameters
├─ FormalParameter[ pmd-java:modifiers() = 'final' ]
│ ├─ ModifierList
│ └─ VariableDeclaratorId "x"
│ └─ VariableId "x"
└─ FormalParameter[ pmd-java:modifiers() = () ]
├─ ModifierList
└─ VariableDeclaratorId "y"
└─ VariableId "y"
{% endhighlight %}
</td></tr>
@ -1432,7 +1433,7 @@ public class Flat {
├─ ModifierList
├─ PrimitiveType "int"
└─ VariableDeclarator
└─ VariableDeclaratorId "f"
└─ VariableId "f"
{% endhighlight %}
</td></tr>
@ -1594,7 +1595,7 @@ Object anonymous = new Object() { };
├─ ModifierList
├─ ClassType[ @SimpleName = 'Object' ]
└─ VariableDeclarator
├─ VariableDeclaratorId[ @Name = 'anonymous' ]
├─ VariableId[ @Name = 'anonymous' ]
└─ ConstructorCall
├─ ClassType[ @SimpleName = 'Object' ]
├─ ArgumentList
@ -1779,7 +1780,7 @@ try {
│ ├─ UnionType
│ │ ├─ ClassType[ @SimpleName = 'IOException' ]
│ │ └─ ClassType[ @SimpleName = 'IllegalArgumentException' ]
│ └─ VariableDeclaratorId[ @Name = 'e' ]
│ └─ VariableId[ @Name = 'e' ]
└─ Block
{% endhighlight %}
</td></tr>
@ -1841,10 +1842,10 @@ c -> {};
├─ LambdaParameterList
│ ├─ LambdaParameter
│ │ ├─ ModifierList
│ │ └─ VariableDeclaratorId[ @Name = 'a' ]
│ │ └─ VariableId[ @Name = 'a' ]
│ └─ LambdaParameter
│ ├─ ModifierList
│ └─ VariableDeclaratorId[ @Name = 'b' ]
│ └─ VariableId[ @Name = 'b' ]
└─ Block
└─ ExpressionStatement
@ -1852,7 +1853,7 @@ c -> {};
├─ LambdaParameterList
│ └─ LambdaParameter
│ ├─ ModifierList
│ └─ VariableDeclaratorId[ @Name = 'c' ]
│ └─ VariableId[ @Name = 'c' ]
└─ Block
└─ ExpressionStatement
@ -1862,7 +1863,7 @@ c -> {};
│ ├─ ModifierList
│ │ └─ Annotation[ @SimpleName = 'A' ]
│ │ └─ ClassType[ @SimpleName = 'A' ]
│ └─ VariableDeclaratorId[ @Name = 'd' ]
│ └─ VariableId[ @Name = 'd' ]
└─ Block
└─ ExpressionStatement
@ -1873,7 +1874,7 @@ c -> {};
│ │ └─ Annotation[ @SimpleName = 'A' ]
│ │ └─ ClassType[ @SimpleName = 'A' ]
│ ├─ PrimitiveType[ @Kind = 'int' ]
│ └─ VariableDeclaratorId[ @Name = 'e' ]
│ └─ VariableId[ @Name = 'e' ]
└─ Block
{% endhighlight %}
</td></tr>
@ -1887,7 +1888,7 @@ c -> {};
* Why: A receiver parameter is not a formal parameter, even though it looks like one: it doesn't declare a variable,
and doesn't affect the arity of the method or constructor. It's so rarely used that giving it its own node avoids
matching it by mistake and simplifies the API and grammar of the ubiquitous {% jdoc jast::ASTFormalParameter %}
and {% jdoc jast::ASTVariableDeclaratorId %}.
and {% jdoc jast::ASTVariableId %}.
* Related issue: [[java] Separate receiver parameter from formal parameter (#1980)](https://github.com/pmd/pmd/pull/1980)
<details>
@ -1926,7 +1927,7 @@ void myMethod(@A Foo this, Foo other) {}
└─ FormalParameter
├─ ModifierList
├─ ClassType "Foo"
└─ VariableDeclaratorId "other"
└─ VariableId "other"
{% endhighlight %}
</td></tr>
</table>
@ -1963,7 +1964,7 @@ void myMethod(int... is) {}
│ ├─ PrimitiveType "int"
│ └─ ArrayDimensions
│ └─ ArrayTypeDim[ @Varargs = true() ]
└─ VariableDeclaratorId "is"
└─ VariableId "is"
{% endhighlight %}
</td></tr>
@ -1992,7 +1993,7 @@ void myMethod(int @A ... is) {}
│ └─ ArrayTypeDim[ @Varargs = true() ]
│ └─ Annotation "A"
│ └─ ClassType "A"
└─ VariableDeclaratorId "is"
└─ VariableId "is"
{% endhighlight %}
</td></tr>
@ -2018,7 +2019,7 @@ void myMethod(int[]... is) {}
│ └─ ArrayDimensions (2)
│ ├─ ArrayTypeDim
│ └─ ArrayTypeDim[ @Varargs = true() ]
└─ VariableDeclaratorId "is"
└─ VariableId "is"
{% endhighlight %}
</td></tr>
</table>
@ -2132,7 +2133,7 @@ i = 1;
│ ├─ ModifierList
│ ├─ PrimitiveType "int"
│ └─ VariableDeclarator
│ └─ VariableDeclaratorId "i"
│ └─ VariableId "i"
└─ ExpressionStatement
└─ AssignmentExpression "="
├─ VariableAccess "i"
@ -2197,7 +2198,7 @@ for (String s : List.of("a", "b")) { }
│ ├─ ModifierList
│ ├─ ClassType "String"
│ └─ VariableDeclarator "s"
│ └─ VariableDeclaratorId "s"
│ └─ VariableId "s"
├─ MethodCall "of"
│ ├─ TypeExpression
│ │ └─ ClassType "List"
@ -2308,7 +2309,7 @@ try (InputStream in = new FileInputStream(); OutputStream out = new FileOutputSt
│ ├─ ModifierList
│ ├─ ClassType "InputStream"
│ └─ VariableDeclarator
│ ├─ VariableDeclaratorId "in"
│ ├─ VariableId "in"
│ └─ ConstructorCall
│ ├─ ClassType "FileInputStream"
│ └─ ArgumentList (0)
@ -2317,7 +2318,7 @@ try (InputStream in = new FileInputStream(); OutputStream out = new FileOutputSt
├─ ModifierList
├─ ClassType "OutputStream"
└─ VariableDeclarator
├─ VariableDeclaratorId "out"
├─ VariableId "out"
└─ ConstructorCall
├─ ClassType "FileOutputStream"
└─ ArgumentList (0)
@ -2892,7 +2893,7 @@ var x = Foo::method;
└─ LocalVariableDeclaration
├─ ModifierList
└─ VariableDeclarator
├─ VariableDeclaratorId "x"
├─ VariableId "x"
└─ MethodReference "method"
└─ TypeExpression
└─ ClassType "Foo"

View File

@ -177,6 +177,8 @@ The following previously deprecated classes have been removed:
* The interface `ASTMethodOrConstructorDeclaration` has been renamed to
{% jdoc java::lang.ast.ASTExecutableDeclaration %}. This is only relevant for Java rules, which sue that type
directly, e.g. through downcasting. Or when using the XPath function `pmd-java:nodeIs()`.
* The node `ASTVariableDeclaratorId` has been renamed to {% jdoc java::lang.ast.ASTVariableId %}. XPath rules
need to be adjusted.
**Deprecated classes and methods**

View File

@ -54,10 +54,10 @@ import net.sourceforge.pmd.lang.ast.internal.StreamImpl;
* the emptiness of a node stream. E.g. the following tests if the node
* is a variable declarator id initialized to the value {@code 0}:
* <pre>
* {@linkplain #of(Node) NodeStream.of}(someNode) <i>// the stream here is empty if the node is null</i>
* {@linkplain #filterIs(Class) .filterIs}(ASTVariableDeclaratorId.class)<i>// the stream here is empty if the node was not a variable declarator id</i>
* {@linkplain #followingSiblings() .followingSiblings}() <i>// the stream here contains only the siblings, not the original node</i>
* {@linkplain #take(int) .take}(1) <i>// the stream here contains only the first sibling, if it exists</i>
* {@linkplain #of(Node) NodeStream.of}(someNode) <i>// the stream here is empty if the node is null</i>
* {@linkplain #filterIs(Class) .filterIs}(ASTVariableId.class) <i>// the stream here is empty if the node was not a variable declarator id</i>
* {@linkplain #followingSiblings() .followingSiblings}() <i>// the stream here contains only the siblings, not the original node</i>
* {@linkplain #take(int) .take}(1) <i>// the stream here contains only the first sibling, if it exists</i>
* {@linkplain #filterIs(Class) .filterIs}(ASTNumericLiteral.class)
* {@linkplain #filter(Predicate) .filter}(it -&gt; !it.isFloatingPoint() &amp;&amp; it.getValueAsInt() == 0)
* {@linkplain #nonEmpty() .nonEmpty}(); <i>// If the stream is non empty here, then all the pipeline matched</i>

View File

@ -22,7 +22,7 @@ import net.sourceforge.pmd.properties.PropertySource;
* +- Type
* | +- PrimitiveType
* +- VariableDeclarator
* +- VariableDeclaratorId
* +- VariableId
* +- VariableInitializer
* +- 1 child not shown
*
@ -36,7 +36,7 @@ import net.sourceforge.pmd.properties.PropertySource;
* Type
* PrimitiveType
* VariableDeclarator
* VariableDeclaratorId
* VariableId
* VariableInitializer
* 1 child not shown
*

View File

@ -1410,13 +1410,13 @@ void VariableDeclarator() :
VariableIdWithDims() [ "=" VariableInitializer() ]
}
void VariableDeclaratorId() :
void VariableDeclaratorId() #VariableId:
{}
{
<IDENTIFIER> { setLastTokenImage(jjtThis); }
}
void VariableIdWithDims() #VariableDeclaratorId :
void VariableIdWithDims() #VariableId :
{}
{
<IDENTIFIER> { setLastTokenImage(jjtThis); }

View File

@ -15,7 +15,7 @@ import net.sourceforge.pmd.lang.java.ast.ASTList.ASTNonEmptyList;
* after the formal parameter list. For example:
* <pre>public int newIntArray(int length) [];</pre>
* </li>
* <li>As the {@linkplain ASTVariableDeclaratorId#getExtraDimensions() extra dimensions of a variable declarator id},
* <li>As the {@linkplain ASTVariableId#getExtraDimensions() extra dimensions of a variable declarator id},
* in a {@linkplain ASTVariableDeclarator variable declarator}. For example:
* <pre>public int a[], b[][];</pre>
* </li>

View File

@ -19,7 +19,7 @@ import net.sourceforge.pmd.lang.java.types.TypeSystem;
*
* <pre class="grammar">
*
* CatchParameter ::= {@link ASTModifierList LocalVarModifierList} {@link ASTType Type} {@link ASTVariableDeclaratorId VariableDeclaratorId}
* CatchParameter ::= {@link ASTModifierList LocalVarModifierList} {@link ASTType Type} {@link ASTVariableId VariableId}
*
* </pre>
*/
@ -50,8 +50,8 @@ public final class ASTCatchParameter extends AbstractJavaNode
@Override
@NonNull
public ASTVariableDeclaratorId getVarId() {
return (ASTVariableDeclaratorId) getLastChild();
public ASTVariableId getVarId() {
return (ASTVariableId) getLastChild();
}
/** Returns the name of this parameter. */

View File

@ -14,7 +14,7 @@ import net.sourceforge.pmd.lang.java.types.OverloadSelectionResult;
*
* <pre class="grammar">
*
* EnumConstant ::= {@link ASTModifierList AnnotationList} {@link ASTVariableDeclaratorId VariableDeclaratorId} {@linkplain ASTArgumentList ArgumentList}? {@linkplain ASTAnonymousClassDeclaration AnonymousClassDeclaration}?
* EnumConstant ::= {@link ASTModifierList AnnotationList} {@link ASTVariableId VariableId} {@linkplain ASTArgumentList ArgumentList}? {@linkplain ASTAnonymousClassDeclaration AnonymousClassDeclaration}?
*
* </pre>
*/
@ -45,8 +45,8 @@ public final class ASTEnumConstant extends AbstractJavaTypeNode
@Override
public ASTVariableDeclaratorId getVarId() {
return getFirstChildOfType(ASTVariableDeclaratorId.class);
public ASTVariableId getVarId() {
return getFirstChildOfType(ASTVariableId.class);
}
@Override

View File

@ -22,7 +22,7 @@ import net.sourceforge.pmd.lang.rule.xpath.DeprecatedAttribute;
* </pre>
*/
public final class ASTFieldDeclaration extends AbstractJavaNode
implements Iterable<ASTVariableDeclaratorId>,
implements Iterable<ASTVariableId>,
LeftRecursiveNode,
ModifierOwner,
ASTBodyDeclaration,
@ -48,16 +48,16 @@ public final class ASTFieldDeclaration extends AbstractJavaNode
/**
* Gets the variable name of this field. This method searches the first
* VariableDeclaratorId node and returns its image or <code>null</code> if
* VariableId node and returns its image or <code>null</code> if
* the child node is not found.
*
* @return a String representing the name of the variable
*
* @deprecated FieldDeclaration may declare several variables, so this is not exhaustive
* Iterate on the {@linkplain ASTVariableDeclaratorId VariableDeclaratorIds} instead
* Iterate on the {@linkplain ASTVariableId VariableIds} instead
*/
@Deprecated
@DeprecatedAttribute(replaceWith = "VariableDeclaratorId/@Name")
@DeprecatedAttribute(replaceWith = "VariableId/@Name")
public String getVariableName() {
return getVarIds().firstOrThrow().getName();
}
@ -66,7 +66,7 @@ public final class ASTFieldDeclaration extends AbstractJavaNode
/**
* Returns the type node at the beginning of this field declaration.
* The type of this node is not necessarily the type of the variables,
* see {@link ASTVariableDeclaratorId#getType()}.
* see {@link ASTVariableId#getType()}.
*/
@Override
public ASTType getTypeNode() {

View File

@ -34,9 +34,9 @@ public final class ASTForeachStatement extends AbstractStatement implements Inte
@Override
@NonNull
public ASTVariableDeclaratorId getVarId() {
public ASTVariableId getVarId() {
// in case of destructuring record patterns, there might be multiple vars
return getFirstChild().descendants(ASTVariableDeclaratorId.class).first();
return getFirstChild().descendants(ASTVariableId.class).first();
}
/**

View File

@ -20,7 +20,7 @@ import net.sourceforge.pmd.lang.java.types.TypingContext;
*
* <pre class="grammar">
*
* FormalParameter ::= {@link ASTModifierList LocalVarModifierList} {@link ASTType Type} {@link ASTVariableDeclaratorId VariableDeclaratorId}
* FormalParameter ::= {@link ASTModifierList LocalVarModifierList} {@link ASTType Type} {@link ASTVariableId VariableId}
*
* </pre>
*/
@ -69,8 +69,8 @@ public final class ASTFormalParameter extends AbstractJavaNode
* Returns the declarator ID of this formal parameter.
*/
@Override
public @NonNull ASTVariableDeclaratorId getVarId() {
return firstChild(ASTVariableDeclaratorId.class);
public @NonNull ASTVariableId getVarId() {
return firstChild(ASTVariableId.class);
}

View File

@ -13,8 +13,8 @@ import org.checkerframework.checker.nullness.qual.Nullable;
*
* <pre class="grammar">
*
* LambdaParameter ::= {@link ASTModifierList LocalVarModifierList} ( "var" | {@link ASTType Type} ) {@link ASTVariableDeclaratorId VariableDeclaratorId}
* | {@link ASTModifierList EmptyModifierList} {@link ASTVariableDeclaratorId VariableDeclaratorId}
* LambdaParameter ::= {@link ASTModifierList LocalVarModifierList} ( "var" | {@link ASTType Type} ) {@link ASTVariableId VariableId}
* | {@link ASTModifierList EmptyModifierList} {@link ASTVariableId VariableId}
*
* </pre>
*/
@ -29,7 +29,7 @@ public final class ASTLambdaParameter extends AbstractJavaTypeNode
* If true, this formal parameter represents one without explicit types.
* This can appear as part of a lambda expression with java11 using "var".
*
* @see ASTVariableDeclaratorId#isTypeInferred()
* @see ASTVariableId#isTypeInferred()
*/
public boolean isTypeInferred() {
return getTypeNode() == null;
@ -52,8 +52,8 @@ public final class ASTLambdaParameter extends AbstractJavaTypeNode
*/
@Override
@NonNull
public ASTVariableDeclaratorId getVarId() {
return getFirstChildOfType(ASTVariableDeclaratorId.class);
public ASTVariableId getVarId() {
return getFirstChildOfType(ASTVariableId.class);
}
/** Returns the type node of this formal parameter. */

View File

@ -14,7 +14,7 @@ import net.sourceforge.pmd.lang.document.FileLocation;
* {@linkplain ASTForStatement foreach statements}.
*
* <p>This statement may define several variables, possibly of different types
* (see {@link ASTVariableDeclaratorId#getType()}). The nodes corresponding to
* (see {@link ASTVariableId#getType()}). The nodes corresponding to
* the declared variables are accessible through {@link #getVarIds()}.
*
* <pre class="grammar">
@ -25,7 +25,7 @@ import net.sourceforge.pmd.lang.document.FileLocation;
*/
// TODO extend AbstractStatement
public final class ASTLocalVariableDeclaration extends AbstractJavaNode
implements Iterable<ASTVariableDeclaratorId>,
implements Iterable<ASTVariableId>,
ASTStatement,
ModifierOwner,
LeftRecursiveNode, // ModifierList is parsed separately in BlockStatement
@ -56,7 +56,7 @@ public final class ASTLocalVariableDeclaration extends AbstractJavaNode
* which makes use of local variable type inference, e.g. java10 "var".
* You can receive the inferred type via {@link ASTVariableDeclarator#getType()}.
*
* @see ASTVariableDeclaratorId#isTypeInferred()
* @see ASTVariableId#isTypeInferred()
*/
public boolean isTypeInferred() {
return getTypeNode() == null;

View File

@ -20,7 +20,7 @@ import net.sourceforge.pmd.lang.java.symbols.JConstructorSymbol;
* scope in the body of a {@linkplain ASTRecordConstructorDeclaration compact record constructor}).
* They also may imply the declaration of an accessor method.
* <ul>
* <li>The symbol exposed by the {@link ASTVariableDeclaratorId} is the field
* <li>The symbol exposed by the {@link ASTVariableId} is the field
* symbol.
* <li> The formal parameter symbol is accessible in the formal parameter
* list of the {@link JConstructorSymbol} for the {@linkplain ASTRecordComponentList#getSymbol() canonical constructor}.
@ -30,7 +30,7 @@ import net.sourceforge.pmd.lang.java.symbols.JConstructorSymbol;
*
* <pre class="grammar">
*
* RecordComponent ::= {@linkplain ASTAnnotation Annotation}* {@linkplain ASTType Type} {@linkplain ASTVariableDeclaratorId VariableDeclaratorId}
* RecordComponent ::= {@linkplain ASTAnnotation Annotation}* {@linkplain ASTType Type} {@linkplain ASTVariableId VariableId}
*
* </pre>
*/
@ -60,7 +60,7 @@ public final class ASTRecordComponent extends AbstractJavaNode implements Modifi
}
@Override
public ASTVariableDeclaratorId getVarId() {
return getFirstChildOfType(ASTVariableDeclaratorId.class);
public ASTVariableId getVarId() {
return getFirstChildOfType(ASTVariableId.class);
}
}

View File

@ -42,8 +42,8 @@ public final class ASTRecordPattern extends AbstractJavaNode implements ASTPatte
}
/** Returns the declared variable. */
public ASTVariableDeclaratorId getVarId() {
return getFirstChildOfType(ASTVariableDeclaratorId.class);
public ASTVariableId getVarId() {
return getFirstChildOfType(ASTVariableId.class);
}
void bumpParenDepth() {

View File

@ -17,7 +17,7 @@ import net.sourceforge.pmd.annotation.Experimental;
*
* <pre class="grammar">
*
* TypePattern ::= ( "final" | {@linkplain ASTAnnotation Annotation} )* {@linkplain ASTType Type} {@link ASTVariableDeclaratorId VariableDeclaratorId}
* TypePattern ::= ( "final" | {@linkplain ASTAnnotation Annotation} )* {@linkplain ASTType Type} {@link ASTVariableId VariableId}
*
* </pre>
*
@ -44,8 +44,8 @@ public final class ASTTypePattern extends AbstractJavaNode implements ASTPattern
}
/** Returns the declared variable. */
public @NonNull ASTVariableDeclaratorId getVarId() {
return Objects.requireNonNull(firstChild(ASTVariableDeclaratorId.class));
public @NonNull ASTVariableId getVarId() {
return Objects.requireNonNull(firstChild(ASTVariableId.class));
}
void bumpParenDepth() {

View File

@ -18,7 +18,7 @@ import org.checkerframework.checker.nullness.qual.Nullable;
*
* <pre class="grammar">
*
* VariableDeclarator ::= {@linkplain ASTVariableDeclaratorId VariableDeclaratorId} ( "=" {@linkplain ASTExpression Expression} )?
* VariableDeclarator ::= {@linkplain ASTVariableId VariableId} ( "=" {@linkplain ASTExpression Expression} )?
*
* </pre>
*/
@ -48,8 +48,8 @@ public class ASTVariableDeclarator extends AbstractJavaNode implements InternalI
*/
@Override
@NonNull
public ASTVariableDeclaratorId getVarId() {
return (ASTVariableDeclaratorId) getChild(0);
public ASTVariableId getVarId() {
return (ASTVariableId) getChild(0);
}

View File

@ -36,17 +36,18 @@ import net.sourceforge.pmd.lang.rule.xpath.DeprecatedAttribute;
*
* <pre class="grammar">
*
* VariableDeclaratorId ::= &lt;IDENTIFIER&gt; {@link ASTArrayDimensions ArrayDimensions}?
* VariableId ::= &lt;IDENTIFIER&gt; {@link ASTArrayDimensions ArrayDimensions}?
*
* </pre>
*
* <p>Note: This node has been called ASTVariableDeclaratorId in PMD 6.
*/
// @formatter:on
public final class ASTVariableDeclaratorId extends AbstractTypedSymbolDeclarator<JVariableSymbol> implements ModifierOwner, SymbolDeclaratorNode {
public final class ASTVariableId extends AbstractTypedSymbolDeclarator<JVariableSymbol> implements ModifierOwner, SymbolDeclaratorNode {
private List<ASTNamedReferenceExpr> usages = Collections.emptyList();
ASTVariableDeclaratorId(int id) {
ASTVariableId(int id) {
super(id);
}

View File

@ -53,8 +53,8 @@ public final class InternalApiBridge {
}
@Deprecated
public static ASTVariableDeclaratorId newVarId(String image) {
ASTVariableDeclaratorId varid = new ASTVariableDeclaratorId(JavaParserImplTreeConstants.JJTVARIABLEDECLARATORID);
public static ASTVariableId newVarId(String image) {
ASTVariableId varid = new ASTVariableId(JavaParserImplTreeConstants.JJTVARIABLEID);
varid.setImage(image);
return varid;
}
@ -66,8 +66,8 @@ public final class InternalApiBridge {
((ASTConstructorDeclaration) node).setSymbol((JConstructorSymbol) symbol);
} else if (node instanceof ASTTypeDeclaration) {
((AbstractTypeDeclaration) node).setSymbol((JClassSymbol) symbol);
} else if (node instanceof ASTVariableDeclaratorId) {
((ASTVariableDeclaratorId) node).setSymbol((JVariableSymbol) symbol);
} else if (node instanceof ASTVariableId) {
((ASTVariableId) node).setSymbol((JVariableSymbol) symbol);
} else if (node instanceof ASTTypeParameter) {
((ASTTypeParameter) node).setSymbol((JTypeParameterSymbol) symbol);
} else if (node instanceof ASTRecordComponentList) {
@ -104,7 +104,7 @@ public final class InternalApiBridge {
.forEach(node -> {
JVariableSymbol sym = node.getReferencedSym();
if (sym != null) {
ASTVariableDeclaratorId reffed = sym.tryGetNode();
ASTVariableId reffed = sym.tryGetNode();
if (reffed != null) { // declared in this file
reffed.addUsage(node);
}

View File

@ -131,22 +131,22 @@ final class InternalInterfaces {
interface VariableIdOwner extends JavaNode {
/** Returns the id of the declared variable. */
ASTVariableDeclaratorId getVarId();
ASTVariableId getVarId();
}
interface MultiVariableIdOwner extends JavaNode, Iterable<ASTVariableDeclaratorId>, ModifierOwner {
interface MultiVariableIdOwner extends JavaNode, Iterable<ASTVariableId>, ModifierOwner {
/**
* Returns a stream of the variable ids declared
* by this node.
*/
default NodeStream<ASTVariableDeclaratorId> getVarIds() {
return children(ASTVariableDeclarator.class).children(ASTVariableDeclaratorId.class);
default NodeStream<ASTVariableId> getVarIds() {
return children(ASTVariableDeclarator.class).children(ASTVariableId.class);
}
@Override
default Iterator<ASTVariableDeclaratorId> iterator() {
default Iterator<ASTVariableId> iterator() {
return getVarIds().iterator();
}

View File

@ -63,7 +63,7 @@ import net.sourceforge.pmd.lang.java.ast.ASTThrowStatement;
import net.sourceforge.pmd.lang.java.ast.ASTTypeDeclaration;
import net.sourceforge.pmd.lang.java.ast.ASTUnaryExpression;
import net.sourceforge.pmd.lang.java.ast.ASTVariableAccess;
import net.sourceforge.pmd.lang.java.ast.ASTVariableDeclaratorId;
import net.sourceforge.pmd.lang.java.ast.ASTVariableId;
import net.sourceforge.pmd.lang.java.ast.Annotatable;
import net.sourceforge.pmd.lang.java.ast.BinaryOp;
import net.sourceforge.pmd.lang.java.ast.JavaNode;
@ -223,7 +223,7 @@ public final class JavaAstUtils {
* the variable must be less than {@link Visibility#V_PRIVATE} for
* us to be sure of it.
*/
public static boolean isNeverUsed(ASTVariableDeclaratorId varId) {
public static boolean isNeverUsed(ASTVariableId varId) {
return CollectionUtil.none(varId.getLocalUsages(), JavaAstUtils::isReadUsage);
}
@ -288,7 +288,7 @@ public final class JavaAstUtils {
* Returns the variable IDS corresponding to variables declared in
* the init clause of the loop.
*/
public static NodeStream<ASTVariableDeclaratorId> getLoopVariables(ASTForStatement loop) {
public static NodeStream<ASTVariableId> getLoopVariables(ASTForStatement loop) {
return NodeStream.of(loop.getInit())
.filterIs(ASTLocalVariableDeclaration.class)
.flatMap(ASTLocalVariableDeclaration::getVarIds);

View File

@ -47,7 +47,7 @@ import net.sourceforge.pmd.lang.java.ast.ASTTypeDeclaration;
import net.sourceforge.pmd.lang.java.ast.ASTTypeParameters;
import net.sourceforge.pmd.lang.java.ast.ASTTypePattern;
import net.sourceforge.pmd.lang.java.ast.ASTUnnamedPattern;
import net.sourceforge.pmd.lang.java.ast.ASTVariableDeclaratorId;
import net.sourceforge.pmd.lang.java.ast.ASTVariableId;
import net.sourceforge.pmd.lang.java.ast.ASTYieldStatement;
import net.sourceforge.pmd.lang.java.ast.JModifier;
import net.sourceforge.pmd.lang.java.ast.JavaNode;
@ -651,7 +651,7 @@ public class LanguageLevelChecker<T> {
}
@Override
public Void visit(ASTVariableDeclaratorId node, T data) {
public Void visit(ASTVariableId node, T data) {
checkIdent(node, node.getName(), data);
return null;
}

View File

@ -43,7 +43,7 @@ import net.sourceforge.pmd.lang.java.ast.ASTTypeDeclaration;
import net.sourceforge.pmd.lang.java.ast.ASTTypeExpression;
import net.sourceforge.pmd.lang.java.ast.ASTUnionType;
import net.sourceforge.pmd.lang.java.ast.ASTVariableAccess;
import net.sourceforge.pmd.lang.java.ast.ASTVariableDeclaratorId;
import net.sourceforge.pmd.lang.java.ast.ASTVariableId;
import net.sourceforge.pmd.lang.java.ast.ASTVoidType;
import net.sourceforge.pmd.lang.java.ast.ASTWildcardType;
import net.sourceforge.pmd.lang.java.ast.JavaNode;
@ -179,8 +179,8 @@ public final class PrettyPrintingUtil {
return ((ASTResource) node).getStableName();
} else if (node instanceof ASTTypeDeclaration) {
return ((ASTTypeDeclaration) node).getSimpleName();
} else if (node instanceof ASTVariableDeclaratorId) {
return ((ASTVariableDeclaratorId) node).getName();
} else if (node instanceof ASTVariableId) {
return ((ASTVariableId) node).getName();
} else {
return node.getImage(); // todo get rid of this
}

View File

@ -31,7 +31,7 @@ import net.sourceforge.pmd.lang.java.ast.ASTPrimitiveType;
import net.sourceforge.pmd.lang.java.ast.ASTTypeDeclaration;
import net.sourceforge.pmd.lang.java.ast.ASTUnaryExpression;
import net.sourceforge.pmd.lang.java.ast.ASTVariableAccess;
import net.sourceforge.pmd.lang.java.ast.ASTVariableDeclaratorId;
import net.sourceforge.pmd.lang.java.ast.ASTVariableId;
import net.sourceforge.pmd.lang.java.ast.InvocationNode;
import net.sourceforge.pmd.lang.java.ast.JModifier;
import net.sourceforge.pmd.lang.java.ast.JavaNode;
@ -75,7 +75,7 @@ public final class JavaDesignerBindings extends DefaultDesignerBindings {
} else if (node instanceof ASTConstructorDeclaration
|| node instanceof ASTCompactConstructorDeclaration) {
return TreeIconId.CONSTRUCTOR;
} else if (node instanceof ASTVariableDeclaratorId) {
} else if (node instanceof ASTVariableId) {
return TreeIconId.VARIABLE;
}
return super.getIcon(node);
@ -194,7 +194,7 @@ public final class JavaDesignerBindings extends DefaultDesignerBindings {
}
@Override
public Attribute visit(ASTVariableDeclaratorId node, Void data) {
public Attribute visit(ASTVariableId node, Void data) {
return new Attribute(node, "Name", node.getName());
}

View File

@ -22,7 +22,7 @@ import net.sourceforge.pmd.lang.java.ast.ASTInitializer;
import net.sourceforge.pmd.lang.java.ast.ASTLocalVariableDeclaration;
import net.sourceforge.pmd.lang.java.ast.ASTTypeDeclaration;
import net.sourceforge.pmd.lang.java.ast.ASTVariableDeclarator;
import net.sourceforge.pmd.lang.java.ast.ASTVariableDeclaratorId;
import net.sourceforge.pmd.lang.java.ast.ASTVariableId;
import net.sourceforge.pmd.lang.java.ast.JavaNode;
import net.sourceforge.pmd.lang.java.ast.ModifierOwner;
import net.sourceforge.pmd.reporting.ViolationDecorator;
@ -82,9 +82,9 @@ final class JavaViolationDecorator implements ViolationDecorator {
return null;
}
private static String getVariableNames(Iterable<ASTVariableDeclaratorId> iterable) {
private static String getVariableNames(Iterable<ASTVariableId> iterable) {
return IteratorUtil.toStream(iterable.iterator())
.map(ASTVariableDeclaratorId::getName)
.map(ASTVariableId::getName)
.collect(Collectors.joining(", "));
}
@ -95,10 +95,10 @@ final class JavaViolationDecorator implements ViolationDecorator {
return getVariableNames((ASTLocalVariableDeclaration) node);
} else if (node instanceof ASTVariableDeclarator) {
return ((ASTVariableDeclarator) node).getVarId().getName();
} else if (node instanceof ASTVariableDeclaratorId) {
return ((ASTVariableDeclaratorId) node).getName();
} else if (node instanceof ASTVariableId) {
return ((ASTVariableId) node).getName();
} else if (node instanceof ASTFormalParameter) {
return getVariableNameIfExists(node.firstChild(ASTVariableDeclaratorId.class));
return getVariableNameIfExists(node.firstChild(ASTVariableId.class));
} else if (node instanceof ASTExpression) {
return getVariableNameIfExists(node.getParent());
}

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