diff --git a/src/main/java/com/ibm/northstar/SymbolTable.java b/src/main/java/com/ibm/northstar/SymbolTable.java index bfac584..c84f09b 100644 --- a/src/main/java/com/ibm/northstar/SymbolTable.java +++ b/src/main/java/com/ibm/northstar/SymbolTable.java @@ -357,6 +357,23 @@ private static List getReferencedTypes(Optional blockStmt) { .filter(vd -> vd.getType().isClassOrInterfaceType()) .map(vd -> resolveType(vd.getType())) .forEach(referencedTypes::add)); + + // add types of accessed fields to the set of referenced types + blockStmt.ifPresent(bs -> bs.findAll(FieldAccessExpr.class) + .stream() + .filter(faExpr -> faExpr.getParentNode().isPresent() && !(faExpr.getParentNode().get() instanceof FieldAccessExpr)) + .map(faExpr -> { + if (faExpr.getParentNode().isPresent() && faExpr.getParentNode().get() instanceof CastExpr) { + return resolveType(((CastExpr)faExpr.getParentNode().get()).getType()); + } else { + return resolveExpression(faExpr); + } + }) + .filter(type -> !type.isEmpty()) + .forEach(referencedTypes::add)); + + // TODO: add resolved method access expressions + return new ArrayList<>(referencedTypes); } @@ -465,8 +482,15 @@ private static List getCallSites(Optional callableBody) { if (declaringTypeName.equals(scopeExpr.toString())) { isStaticCall = true; } + } + + // compute return type for method call taking into account typecast of return value + if (methodCallExpr.getParentNode().isPresent() && methodCallExpr.getParentNode().get() instanceof CastExpr) { + returnType = resolveType(((CastExpr)methodCallExpr.getParentNode().get()).getType()); + } else { returnType = resolveExpression(methodCallExpr); } + // resolve arguments of the method call to types List arguments = methodCallExpr.getArguments().stream() .map(arg -> resolveExpression(arg)).collect(Collectors.toList());