3939public class SymbolTable {
4040
4141 private static JavaSymbolSolver javaSymbolSolver ;
42+ private static Set <String > unresolvedTypes = new HashSet <>();
43+ private static Set <String > unresolvedExpressions = new HashSet <>();
4244
4345 /**
4446 * Processes the given compilation unit to extract information about classes and
@@ -408,6 +410,7 @@ private static List<String> getAccessedFields(Optional<BlockStmt> callableBody,
408410 // process field access expressions in the callable
409411 callableBody .ifPresent (cb -> cb .findAll (FieldAccessExpr .class )
410412 .stream ()
413+ .filter (faExpr -> faExpr .getParentNode ().isPresent () && !(faExpr .getParentNode ().get () instanceof FieldAccessExpr ))
411414 .map (faExpr -> {
412415 String fieldDeclaringType = resolveExpression (faExpr .getScope ());
413416 if (!fieldDeclaringType .isEmpty ()) {
@@ -474,12 +477,8 @@ private static List<CallSite> getCallSites(Optional<BlockStmt> callableBody) {
474477
475478 for (ObjectCreationExpr objectCreationExpr : callableBody .get ().findAll (ObjectCreationExpr .class )) {
476479 // resolve declaring type for called method
477- String instantiatedType = objectCreationExpr .getTypeAsString ();
478- try {
479- instantiatedType = objectCreationExpr .getType ().resolve ().describe ();
480- } catch (UnsolvedSymbolException | IllegalStateException e ) {
481- Log .warn ("Could not resolve " +instantiatedType +": " +e .getMessage ());
482- }
480+ String instantiatedType = resolveType (objectCreationExpr .getType ());
481+
483482 // resolve arguments of the constructor call to types
484483 List <String > arguments = objectCreationExpr .getArguments ().stream ()
485484 .map (arg -> resolveExpression (arg )).collect (Collectors .toList ());
@@ -538,13 +537,17 @@ private static CallSite createCallSite(Expression callExpr, String calleeName, S
538537 * @return Resolved type name or empty string if type resolution fails
539538 */
540539 private static String resolveExpression (Expression expression ) {
541- try {
542- ResolvedType resolvedType = javaSymbolSolver .calculateType (expression );
543- if (resolvedType .isReferenceType () || resolvedType .isUnionType ()) {
544- return resolvedType .describe ();
540+ // perform expression resolution if resolution of this expression did not fail previously
541+ if (!unresolvedExpressions .contains (expression .toString ())) {
542+ try {
543+ ResolvedType resolvedType = javaSymbolSolver .calculateType (expression );
544+ if (resolvedType .isReferenceType () || resolvedType .isUnionType ()) {
545+ return resolvedType .describe ();
546+ }
547+ } catch (RuntimeException exception ) {
548+ Log .debug ("Could not resolve expression: " + expression + ": " + exception .getMessage ());
549+ unresolvedExpressions .add (expression .toString ());
545550 }
546- } catch (RuntimeException exception ) {
547- Log .warn ("Could not resolve expression: " +expression +"\n " +exception .getMessage ());
548551 }
549552 return "" ;
550553 }
@@ -556,12 +559,16 @@ private static String resolveExpression(Expression expression) {
556559 * @return Resolved (qualified) type name
557560 */
558561 private static String resolveType (Type type ) {
559- try {
560- return type .resolve ().describe ();
561- } catch (UnsolvedSymbolException | IllegalStateException | MethodAmbiguityException e ) {
562- Log .warn ("Could not resolve " +type .asString ()+": " +e .getMessage ());
563- return type .asString ();
562+ // perform type resolution if resolution of this type did not fail previously
563+ if (!unresolvedTypes .contains (type .asString ())) {
564+ try {
565+ return type .resolve ().describe ();
566+ } catch (RuntimeException e ) {
567+ Log .warn ("Could not resolve type: " + type .asString () + ": " + e .getMessage ());
568+ unresolvedTypes .add (type .asString ());
569+ }
564570 }
571+ return type .asString ();
565572 }
566573
567574 /**
0 commit comments