use of org.spoofax.terms.TermVisitor in project spoofax by metaborg.
the class AnalysisCommon method ambiguityMessages.
public Collection<IMessage> ambiguityMessages(final FileObject resource, IStrategoTerm ast) {
final Collection<IMessage> messages = Lists.newLinkedList();
final TermVisitor termVisitor = new TermVisitor() {
private IStrategoTerm ambStart;
@Override
public void preVisit(IStrategoTerm term) {
if (ambStart == null && "amb".equals(Term.tryGetName(term))) {
final String text = "Fragment is ambiguous: " + ambToString(term);
final ISourceLocation location = tracingService.location(term);
if (location != null) {
final ISourceRegion region = location.region();
messages.add(message(resource, region, text, MessageSeverity.WARNING));
} else {
messages.add(message(resource, text, MessageSeverity.WARNING));
}
ambStart = term;
}
}
@Override
public void postVisit(IStrategoTerm term) {
if (term == ambStart) {
ambStart = null;
}
}
private String ambToString(IStrategoTerm amb) {
final String result = amb.toString();
return result.length() > 5000 ? result.substring(0, 5000) + "..." : result;
}
};
termVisitor.visit(ast);
return messages;
}
Aggregations