Skip to content

Commit e64497a

Browse files
committed
Log warnings instead of throwing disambiguation failures
1 parent bb28773 commit e64497a

File tree

1 file changed

+9
-12
lines changed
  • delphi-frontend/src/main/java/au/com/integradev/delphi/symbol/resolve

1 file changed

+9
-12
lines changed

delphi-frontend/src/main/java/au/com/integradev/delphi/symbol/resolve/NameResolver.java

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,8 @@
5454
import java.util.function.Supplier;
5555
import java.util.stream.Collectors;
5656
import javax.annotation.Nullable;
57-
import org.apache.commons.lang3.StringUtils;
57+
import org.slf4j.Logger;
58+
import org.slf4j.LoggerFactory;
5859
import org.sonar.plugins.communitydelphi.api.ast.ArgumentListNode;
5960
import org.sonar.plugins.communitydelphi.api.ast.ArrayAccessorNode;
6061
import org.sonar.plugins.communitydelphi.api.ast.AttributeNode;
@@ -105,6 +106,7 @@
105106
import org.sonar.plugins.communitydelphi.api.type.Typed;
106107

107108
public class NameResolver {
109+
private static final Logger LOG = LoggerFactory.getLogger(NameResolver.class);
108110
private final TypeFactory typeFactory;
109111
private final List<NameOccurrenceImpl> names = new ArrayList<>();
110112
private final List<NameDeclaration> resolvedDeclarations = new ArrayList<>();
@@ -196,7 +198,12 @@ NameDeclaration addResolvedDeclaration() {
196198

197199
public void checkAmbiguity() {
198200
if (declarations.size() > 1) {
199-
throw new DisambiguationException(declarations, Iterables.getLast(names));
201+
LOG.warn(
202+
"Ambiguous declarations could not be resolved\n[Occurrence] {}{}",
203+
Iterables.getLast(names),
204+
declarations.stream().map(declaration -> "\n[Declaration] " + declaration));
205+
206+
declarations.clear();
200207
}
201208
}
202209

@@ -1389,14 +1396,4 @@ private static void registerOccurrence(NameOccurrenceImpl occurrence) {
13891396
FileScope scope = occurrence.getLocation().getScope().getEnclosingScope(FileScope.class);
13901397
((FileScopeImpl) scope).registerOccurrence(occurrence.getLocation(), occurrence);
13911398
}
1392-
1393-
private static class DisambiguationException extends RuntimeException {
1394-
DisambiguationException(Set<NameDeclaration> declarations, NameOccurrence occurrence) {
1395-
super(
1396-
"Ambiguous declarations could not be resolved\n[Occurrence] "
1397-
+ occurrence
1398-
+ "\n[Declaration] "
1399-
+ StringUtils.join(declarations, "\n[Declaration] "));
1400-
}
1401-
}
14021399
}

0 commit comments

Comments
 (0)