19
19
////////////////////////////////////////////////////////////////////////////////
20
20
package net .prominic .groovyls .compiler .util ;
21
21
22
+ import java .util .ArrayList ;
22
23
import java .util .Collections ;
23
24
import java .util .Comparator ;
24
25
import java .util .List ;
@@ -175,10 +176,38 @@ public static FieldNode getFieldFromExpression(PropertyExpression node, ASTNodeV
175
176
public static List <FieldNode > getFieldsForLeftSideOfPropertyExpression (Expression node , ASTNodeVisitor astVisitor ) {
176
177
ClassNode classNode = getTypeOfNode (node , astVisitor );
177
178
if (classNode != null ) {
179
+ List <ClassNode > classNodes = new ArrayList <>();
180
+ classNodes .add (classNode );
181
+
178
182
boolean statics = node instanceof ClassExpression ;
179
- return classNode .getFields ().stream ().filter (fieldNode -> {
180
- return statics ? fieldNode .isStatic () : !fieldNode .isStatic ();
181
- }).collect (Collectors .toList ());
183
+
184
+ List <FieldNode > result = new ArrayList <>();
185
+ int i = 0 ;
186
+ while (i < classNodes .size ()) {
187
+ ClassNode current = classNodes .get (i );
188
+
189
+ result .addAll (current .getFields ().stream ().filter (fieldNode -> {
190
+ return statics ? fieldNode .isStatic () : !fieldNode .isStatic ();
191
+ }).collect (Collectors .toList ()));
192
+
193
+ if (current .isInterface ()) {
194
+ for (ClassNode interfaceNode : current .getInterfaces ()) {
195
+ classNodes .add (interfaceNode );
196
+ }
197
+ } else {
198
+ ClassNode superClassNode = null ;
199
+ try {
200
+ superClassNode = current .getSuperClass ();
201
+ } catch (NoClassDefFoundError e ) {
202
+ // this is fine, we'll just treat it as null
203
+ }
204
+ if (superClassNode != null ) {
205
+ classNodes .add (superClassNode );
206
+ }
207
+ }
208
+ i ++;
209
+ }
210
+ return result ;
182
211
}
183
212
return Collections .emptyList ();
184
213
}
@@ -187,10 +216,37 @@ public static List<PropertyNode> getPropertiesForLeftSideOfPropertyExpression(Ex
187
216
ASTNodeVisitor astVisitor ) {
188
217
ClassNode classNode = getTypeOfNode (node , astVisitor );
189
218
if (classNode != null ) {
219
+ List <ClassNode > classNodes = new ArrayList <>();
220
+ classNodes .add (classNode );
221
+
190
222
boolean statics = node instanceof ClassExpression ;
191
- return classNode .getProperties ().stream ().filter (propNode -> {
192
- return statics ? propNode .isStatic () : !propNode .isStatic ();
193
- }).collect (Collectors .toList ());
223
+
224
+ List <PropertyNode > result = new ArrayList <>();
225
+ int i = 0 ;
226
+ while (i < classNodes .size ()) {
227
+ ClassNode current = classNodes .get (i );
228
+
229
+ result .addAll (current .getProperties ().stream ().filter (propNode -> {
230
+ return statics ? propNode .isStatic () : !propNode .isStatic ();
231
+ }).collect (Collectors .toList ()));
232
+
233
+ if (current .isInterface ()) {
234
+ for (ClassNode interfaceNode : current .getInterfaces ()) {
235
+ classNodes .add (interfaceNode );
236
+ }
237
+ } else {
238
+ ClassNode superClassNode = null ;
239
+ try {
240
+ superClassNode = current .getSuperClass ();
241
+ } catch (NoClassDefFoundError e ) {
242
+ // this is fine, we'll just treat it as null
243
+ }
244
+ if (superClassNode != null ) {
245
+ classNodes .add (superClassNode );
246
+ }
247
+ }
248
+ i ++;
249
+ }
194
250
}
195
251
return Collections .emptyList ();
196
252
}
@@ -199,10 +255,38 @@ public static List<MethodNode> getMethodsForLeftSideOfPropertyExpression(Express
199
255
ASTNodeVisitor astVisitor ) {
200
256
ClassNode classNode = getTypeOfNode (node , astVisitor );
201
257
if (classNode != null ) {
258
+ List <ClassNode > classNodes = new ArrayList <>();
259
+ classNodes .add (classNode );
260
+
202
261
boolean statics = node instanceof ClassExpression ;
203
- return classNode .getMethods ().stream ().filter (methodNode -> {
204
- return statics ? methodNode .isStatic () : !methodNode .isStatic ();
205
- }).collect (Collectors .toList ());
262
+
263
+ List <MethodNode > result = new ArrayList <>();
264
+ int i = 0 ;
265
+ while (i < classNodes .size ()) {
266
+ ClassNode current = classNodes .get (i );
267
+
268
+ result .addAll (current .getMethods ().stream ().filter (methodNode -> {
269
+ return statics ? methodNode .isStatic () : !methodNode .isStatic ();
270
+ }).collect (Collectors .toList ()));
271
+
272
+ if (current .isInterface ()) {
273
+ for (ClassNode interfaceNode : current .getInterfaces ()) {
274
+ classNodes .add (interfaceNode );
275
+ }
276
+ } else {
277
+ ClassNode superClassNode = null ;
278
+ try {
279
+ superClassNode = current .getSuperClass ();
280
+ } catch (NoClassDefFoundError e ) {
281
+ // this is fine, we'll just treat it as null
282
+ }
283
+ if (superClassNode != null ) {
284
+ classNodes .add (superClassNode );
285
+ }
286
+ }
287
+ i ++;
288
+ }
289
+ return result ;
206
290
}
207
291
return Collections .emptyList ();
208
292
}
0 commit comments