@@ -357,6 +357,23 @@ private static List<String> getReferencedTypes(Optional<BlockStmt> blockStmt) {
357357            .filter (vd  -> vd .getType ().isClassOrInterfaceType ())
358358            .map (vd  -> resolveType (vd .getType ()))
359359            .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+ 
360377        return  new  ArrayList <>(referencedTypes );
361378    }
362379
@@ -465,8 +482,15 @@ private static List<CallSite> getCallSites(Optional<BlockStmt> callableBody) {
465482                if  (declaringTypeName .equals (scopeExpr .toString ())) {
466483                    isStaticCall  = true ;
467484                }
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  {
468491                returnType  = resolveExpression (methodCallExpr );
469492            }
493+ 
470494            // resolve arguments of the method call to types 
471495            List <String > arguments  = methodCallExpr .getArguments ().stream ()
472496                .map (arg  -> resolveExpression (arg )).collect (Collectors .toList ());
0 commit comments