+76
-85
lines changedFilter options
+76
-85
lines changed Original file line number Diff line number Diff line change
@@ -1799,7 +1799,7 @@ void FormalParameter() :
1799
1799
{boolean isFinal = false;}
1800
1800
{
1801
1801
isFinal=LocalVarModifierList() {jjtThis.setFinal(isFinal);}
1802
-
FormalParamType()
1802
+
FormalParamType() ("|" FormalParamType())* // remove this stuff when #2202 is merged
1803
1803
VariableIdWithDims()
1804
1804
}
1805
1805
Original file line number Diff line number Diff line change
@@ -4,12 +4,8 @@
4
4
5
5
package net.sourceforge.pmd.lang.java.ast;
6
6
7
-
import java.util.Iterator;
8
-
9
-
import net.sourceforge.pmd.lang.ast.NodeStream;
10
7
import net.sourceforge.pmd.lang.ast.SignedNode;
11
8
import net.sourceforge.pmd.lang.java.multifile.signature.JavaFieldSignature;
12
-
import net.sourceforge.pmd.lang.java.typeresolution.typedefinition.JavaTypeDefinition;
13
9
14
10
15
11
/**
@@ -35,10 +31,11 @@
35
31
*
36
32
* </pre>
37
33
*/
38
-
public final class ASTFieldDeclaration extends AbstractJavaAccessTypeNode
34
+
public final class ASTFieldDeclaration extends AbstractJavaAccessNode
39
35
implements SignedNode<ASTFieldDeclaration>,
40
36
Iterable<ASTVariableDeclaratorId>,
41
-
LeftRecursiveNode {
37
+
LeftRecursiveNode,
38
+
InternalInterfaces.MultiVariableIdOwner {
42
39
43
40
private JavaFieldSignature signature;
44
41
@@ -171,46 +168,14 @@ public JavaFieldSignature getSignature() {
171
168
return signature;
172
169
}
173
170
174
-
public ASTType getTypeNode() {
175
-
return getFirstChildOfType(ASTType.class);
176
-
}
177
-
178
171
/**
179
-
* Returns a stream of IDs for the fields this node declares.
180
-
*/
181
-
public NodeStream<ASTVariableDeclaratorId> getVariables() {
182
-
return children(ASTVariableDeclarator.class).children(ASTVariableDeclaratorId.class);
183
-
}
184
-
185
-
/**
186
-
* Returns an iterator of IDs for the fields this node declares.
187
-
*
188
-
* @see #getVariables()
172
+
* Returns the type node at the beginning of this field declaration.
173
+
* The type of this node is not necessarily the type of the variables,
174
+
* see {@link ASTVariableDeclaratorId#getType()}.
189
175
*/
190
176
@Override
191
-
public Iterator<ASTVariableDeclaratorId> iterator() {
192
-
return getVariables().iterator();
193
-
}
194
-
195
-
196
-
/**
197
-
* @deprecated FieldDeclaration may declare several variables with a different type
198
-
* It won't implement TypeNode anymore come 7.0.0
199
-
*/
200
-
@Override
201
-
@Deprecated
202
-
public Class<?> getType() {
203
-
return super.getType();
177
+
public ASTType getTypeNode() {
178
+
return getFirstChildOfType(ASTType.class);
204
179
}
205
180
206
-
207
-
/**
208
-
* @deprecated FieldDeclaration may declare several variables with a different type
209
-
* It won't implement TypeNode anymore come 7.0.0
210
-
*/
211
-
@Override
212
-
@Deprecated
213
-
public JavaTypeDefinition getTypeDefinition() {
214
-
return super.getTypeDefinition();
215
-
}
216
181
}
Original file line number Diff line number Diff line change
@@ -94,11 +94,11 @@ public ASTType getTypeNode() {
94
94
95
95
96
96
/**
97
-
* @deprecated use {@link #getVariableDeclaratorId()}
97
+
* @deprecated use {@link #getVarId()}
98
98
*/
99
99
@Deprecated
100
100
protected ASTVariableDeclaratorId getDecl() {
101
-
return getVariableDeclaratorId();
101
+
return getVarId();
102
102
}
103
103
104
104
/**
Original file line number Diff line number Diff line change
@@ -4,11 +4,6 @@
4
4
5
5
package net.sourceforge.pmd.lang.java.ast;
6
6
7
-
import java.util.Iterator;
8
-
9
-
import net.sourceforge.pmd.lang.ast.NodeStream;
10
-
11
-
12
7
/**
13
8
* Represents a local variable declaration. This is a {@linkplain ASTStatement statement},
14
9
* but the node is also used in {@linkplain ASTForInit for-loop initialisers} and
@@ -27,7 +22,8 @@
27
22
// TODO extend AbstractStatement
28
23
public final class ASTLocalVariableDeclaration extends AbstractJavaAccessNode
29
24
implements Iterable<ASTVariableDeclaratorId>,
30
-
ASTStatement {
25
+
ASTStatement,
26
+
InternalInterfaces.MultiVariableIdOwner {
31
27
32
28
ASTLocalVariableDeclaration(int id) {
33
29
super(id);
@@ -80,24 +76,10 @@ public boolean isTypeInferred() {
80
76
*
81
77
* @see #isTypeInferred()
82
78
*/
79
+
@Override
83
80
public ASTType getTypeNode() {
84
81
return getFirstChildOfType(ASTType.class);
85
82
}
86
83
87
-
/**
88
-
* Returns a stream of IDs for the fields this node declares.
89
-
*/
90
-
public NodeStream<ASTVariableDeclaratorId> getVarIds() {
91
-
return children(ASTVariableDeclarator.class).children(ASTVariableDeclaratorId.class);
92
-
}
93
84
94
-
/**
95
-
* Returns an iterator of IDs for the fields this node declares.
96
-
*
97
-
* @see #getVarIds()
98
-
*/
99
-
@Override
100
-
public Iterator<ASTVariableDeclaratorId> iterator() {
101
-
return getVarIds().iterator();
102
-
}
103
85
}
Original file line number Diff line number Diff line change
@@ -45,7 +45,6 @@
45
45
// @formatter:on
46
46
public final class ASTVariableDeclaratorId extends AbstractJavaTypeNode {
47
47
48
-
private int arrayDepth;
49
48
private VariableNameDeclaration nameDeclaration;
50
49
51
50
@InternalApi
@@ -109,7 +108,7 @@ public boolean hasArrayType() {
109
108
* a {@code catch} statement.
110
109
*/
111
110
public boolean isExceptionBlockParameter() {
112
-
return jjtGetParent() instanceof ASTCatchParameter;
111
+
return jjtGetParent() instanceof ASTFormalParameter && jjtGetParent().jjtGetParent() instanceof ASTCatchClause;
113
112
}
114
113
115
114
@@ -179,9 +178,6 @@ public boolean isFinal() {
179
178
if (jjtGetParent() instanceof ASTFormalParameter) {
180
179
// This accounts for exception parameters too for now
181
180
return ((ASTFormalParameter) jjtGetParent()).isFinal();
182
-
} else if (jjtGetParent() instanceof ASTCatchParameter) {
183
-
return ((ASTCatchParameter) jjtGetParent()).isMulticatch()
184
-
|| ((ASTCatchParameter) jjtGetParent()).isFinal();
185
181
}
186
182
187
183
Node grandpa = getNthParent(2);
Original file line number Diff line number Diff line change
@@ -5,9 +5,13 @@
5
5
package net.sourceforge.pmd.lang.java.ast;
6
6
7
7
8
+
import java.util.Iterator;
9
+
8
10
import org.checkerframework.checker.nullness.qual.NonNull;
9
11
import org.checkerframework.checker.nullness.qual.Nullable;
10
12
13
+
import net.sourceforge.pmd.lang.ast.NodeStream;
14
+
11
15
/**
12
16
* Those are some interfaces that are not published, but are used to keep
13
17
* uniform names on related concepts. Maybe it makes sense to publish some of
@@ -92,4 +96,57 @@ default JavaNode getLastChild() {
92
96
}
93
97
}
94
98
99
+
/**
100
+
* Tags a node that has at least one child, then some methods never
101
+
* return null.
102
+
*/
103
+
interface AtLeastOneChildOfType<T extends JavaNode> extends JavaNode {
104
+
105
+
@Override
106
+
T jjtGetChild(int index);
107
+
108
+
109
+
/** Returns the first child of this node, never null. */
110
+
@Override
111
+
@NonNull
112
+
default T getFirstChild() {
113
+
assert jjtGetNumChildren() > 0;
114
+
return jjtGetChild(0);
115
+
}
116
+
117
+
118
+
/** Returns the last child of this node, never null. */
119
+
@Override
120
+
@NonNull
121
+
default T getLastChild() {
122
+
assert jjtGetNumChildren() > 0;
123
+
return jjtGetChild(jjtGetNumChildren() - 1);
124
+
}
125
+
}
126
+
127
+
interface VariableIdOwner extends JavaNode {
128
+
129
+
/** Returns the id of the declared variable. */
130
+
ASTVariableDeclaratorId getVarId();
131
+
}
132
+
133
+
interface MultiVariableIdOwner extends JavaNode, Iterable<ASTVariableDeclaratorId>, AccessNode {
134
+
135
+
/**
136
+
* Returns a stream of the variable ids declared
137
+
* by this node.
138
+
*/
139
+
default NodeStream<ASTVariableDeclaratorId> getVarIds() {
140
+
return children(ASTVariableDeclarator.class).children(ASTVariableDeclaratorId.class);
141
+
}
142
+
143
+
144
+
@Override
145
+
default Iterator<ASTVariableDeclaratorId> iterator() {
146
+
return getVarIds().iterator();
147
+
}
148
+
149
+
ASTType getTypeNode();
150
+
}
151
+
95
152
}
Original file line number Diff line number Diff line change
@@ -202,6 +202,7 @@ public Object visit(ASTFieldDeclaration decl, Object data) {
202
202
}
203
203
204
204
205
+
@SuppressWarnings("PMD.UnusedFormalParameter")
205
206
private boolean isSerialVersionUID(ASTFieldDeclaration field) {
206
207
return false; // FIXME, commented out because of incompatibility, needs typeres
207
208
// return "serialVersionUID".equals(field.getVariableName())
@@ -220,6 +221,7 @@ private boolean isSerialVersionUID(ASTFieldDeclaration field) {
220
221
* @return true if the field is a serialPersistentFields variable, otherwise false
221
222
* @see <a href="https://docs.oracle.com/javase/7/docs/platform/serialization/spec/serial-arch.html#6250">Oracle docs</a>
222
223
*/
224
+
@SuppressWarnings("PMD.UnusedFormalParameter")
223
225
private boolean isSerialPersistentFields(final ASTFieldDeclaration field) {
224
226
return false; // FIXME, commented out because of incompatibility, needs typeres
225
227
// return "serialPersistentFields".equals(field.getVariableName())
Original file line number Diff line number Diff line change
@@ -50,7 +50,6 @@
50
50
import net.sourceforge.pmd.lang.java.ast.ASTExclusiveOrExpression;
51
51
import net.sourceforge.pmd.lang.java.ast.ASTExpression;
52
52
import net.sourceforge.pmd.lang.java.ast.ASTExtendsList;
53
-
import net.sourceforge.pmd.lang.java.ast.ASTFieldDeclaration;
54
53
import net.sourceforge.pmd.lang.java.ast.ASTForStatement;
55
54
import net.sourceforge.pmd.lang.java.ast.ASTFormalParameter;
56
55
import net.sourceforge.pmd.lang.java.ast.ASTImportDeclaration;
@@ -594,13 +593,6 @@ private JavaTypeDefinition searchImportedStaticFields(String fieldName) {
594
593
}
595
594
596
595
597
-
@Override
598
-
public Object visit(ASTFieldDeclaration node, Object data) {
599
-
super.visit(node, data);
600
-
rollupTypeUnary(node);
601
-
return data;
602
-
}
603
-
604
596
@Override
605
597
public Object visit(ASTVariableDeclarator node, Object data) {
606
598
super.visit(node, data);
Original file line number Diff line number Diff line change
@@ -170,7 +170,6 @@ public void acceptanceTest() {
170
170
assertEquals(ArrayList.class, acu.getFirstDescendantOfType(ASTType.class).getType());
171
171
assertEquals(ArrayList.class, acu.getFirstDescendantOfType(ASTVariableDeclaratorId.class).getType());
172
172
assertEquals(ArrayList.class, acu.getFirstDescendantOfType(ASTVariableDeclarator.class).getType());
173
-
assertEquals(ArrayList.class, acu.getFirstDescendantOfType(ASTFieldDeclaration.class).getType());
174
173
175
174
acu = parseAndTypeResolveForClass15(DefaultJavaLangImport.class);
176
175
assertEquals(String.class, acu.getFirstDescendantOfType(ASTClassOrInterfaceType.class).getType());
Original file line number Diff line number Diff line change
@@ -100,7 +100,6 @@ void monitorTemperature() throws @Critical TemperatureException { }
100
100
Document @Readonly [][] docs2 = new Document@Readonly[2][12]; // read-only array of arrays of documents
101
101
Document[] @Readonly [] docs3 = new Document[2]@Readonly[12]; // array of read-only arrays of documents
102
102
103
-
// TODO mixed array notation, for now syntax error
104
103
Document[] docs4@Readonly[] = new Document@Readonly[2][12]; // read-only array of arrays of documents
105
104
Document @Readonly [] docs5[] = new Document[2]@Readonly[12]; // array of read-only arrays of documents
106
105
@@ -110,7 +109,6 @@ void monitorTemperature() throws @Critical TemperatureException { }
110
109
Document @Readonly [][] docs2 = new Document@Readonly[2][12]; // read-only array of arrays of documents
111
110
Document[] @Readonly [] docs3 = new Document[2]@Readonly[12]; // array of read-only arrays of documents
112
111
113
-
// TODO mixed array notation, for now syntax error
114
112
Document[] docs4@Readonly[] = new Document@Readonly[2][12]; // read-only array of arrays of documents
115
113
Document @Readonly [] docs5[] = new Document[2]@Readonly[12]; // array of read-only arrays of documents
116
114
@@ -121,8 +119,8 @@ class MyClass {
121
119
122
120
public String toString(@Readonly MyClass this) { }
123
121
124
-
public boolean equals(Object @Readonly ... other) { }
125
-
MyClass(Object @Readonly ... other) { }
122
+
public boolean equals(Object @Readonly ... other) @K[][]{ }
123
+
MyClass(Object @Readonly [] @ß... other) { }
126
124
}
127
125
128
126
You can’t perform that action at this time.
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4