@@ -357,6 +357,23 @@ private static List<String> getReferencedTypes(Optional<BlockStmt> blockStmt) {
357
357
.filter (vd -> vd .getType ().isClassOrInterfaceType ())
358
358
.map (vd -> resolveType (vd .getType ()))
359
359
.forEach (referencedTypes ::add ));
360
+
361
+ // add types of accessed fields to the set of referenced types
362
+ blockStmt .ifPresent (bs -> bs .findAll (FieldAccessExpr .class )
363
+ .stream ()
364
+ .filter (faExpr -> faExpr .getParentNode ().isPresent () && !(faExpr .getParentNode ().get () instanceof FieldAccessExpr ))
365
+ .map (faExpr -> {
366
+ if (faExpr .getParentNode ().isPresent () && faExpr .getParentNode ().get () instanceof CastExpr ) {
367
+ return resolveType (((CastExpr )faExpr .getParentNode ().get ()).getType ());
368
+ } else {
369
+ return resolveExpression (faExpr );
370
+ }
371
+ })
372
+ .filter (type -> !type .isEmpty ())
373
+ .forEach (referencedTypes ::add ));
374
+
375
+ // TODO: add resolved method access expressions
376
+
360
377
return new ArrayList <>(referencedTypes );
361
378
}
362
379
@@ -465,8 +482,15 @@ private static List<CallSite> getCallSites(Optional<BlockStmt> callableBody) {
465
482
if (declaringTypeName .equals (scopeExpr .toString ())) {
466
483
isStaticCall = true ;
467
484
}
485
+ }
486
+
487
+ // compute return type for method call taking into account typecast of return value
488
+ if (methodCallExpr .getParentNode ().isPresent () && methodCallExpr .getParentNode ().get () instanceof CastExpr ) {
489
+ returnType = resolveType (((CastExpr )methodCallExpr .getParentNode ().get ()).getType ());
490
+ } else {
468
491
returnType = resolveExpression (methodCallExpr );
469
492
}
493
+
470
494
// resolve arguments of the method call to types
471
495
List <String > arguments = methodCallExpr .getArguments ().stream ()
472
496
.map (arg -> resolveExpression (arg )).collect (Collectors .toList ());
0 commit comments