use of org.spoofax.terms.visitor.AStrategoTermVisitor in project spoofax by metaborg.
the class JSGLRCompletionService method findPlaceholderTerms.
private Collection<IStrategoTerm> findPlaceholderTerms(IStrategoTerm ast) {
final Collection<IStrategoTerm> placeholderTerms = Lists.newLinkedList();
final IStrategoTermVisitor visitor = new AStrategoTermVisitor() {
@Override
public boolean visit(IStrategoTerm term) {
if (term instanceof IStrategoAppl) {
IStrategoAppl appl = (IStrategoAppl) term;
if (appl.getConstructor().getName().contains("-Plhdr") && appl.getSubtermCount() > 0) {
placeholderTerms.add(appl);
return false;
}
}
return true;
}
};
StrategoTermVisitee.topdown(visitor, ast);
return placeholderTerms;
}
use of org.spoofax.terms.visitor.AStrategoTermVisitor in project spoofax by metaborg.
the class JSGLRCompletionService method findNestedCompletionTerm.
private Collection<IStrategoTerm> findNestedCompletionTerm(final StrategoTerm ast, final boolean excludeIdTerm) {
final Collection<IStrategoTerm> completionTerms = Lists.newLinkedList();
final IStrategoTermVisitor visitor = new AStrategoTermVisitor() {
@Override
public boolean visit(IStrategoTerm term) {
ImploderAttachment ia = term.getAttachment(ImploderAttachment.TYPE);
if (excludeIdTerm && term.equals(ast)) {
return true;
}
if (ia.isNestedCompletion()) {
completionTerms.add(term);
return false;
}
return true;
}
};
StrategoTermVisitee.topdown(visitor, ast);
return completionTerms;
}
use of org.spoofax.terms.visitor.AStrategoTermVisitor in project spoofax by metaborg.
the class JSGLRCompletionService method findCompletionTerm.
private Collection<IStrategoTerm> findCompletionTerm(StrategoTerm ast) {
final Collection<IStrategoTerm> completionTerms = Lists.newLinkedList();
final IStrategoTermVisitor visitor = new AStrategoTermVisitor() {
@Override
public boolean visit(IStrategoTerm term) {
ImploderAttachment ia = term.getAttachment(ImploderAttachment.TYPE);
if (ia.isNestedCompletion()) {
return false;
}
if (ia.isCompletion()) {
completionTerms.add(term);
return false;
}
return true;
}
};
StrategoTermVisitee.topdown(visitor, ast);
return completionTerms;
}
use of org.spoofax.terms.visitor.AStrategoTermVisitor in project spoofax by metaborg.
the class JSGLRCompletionService method tracingTermsCompletions.
private Iterable<IStrategoTerm> tracingTermsCompletions(final int position, Object result, final ISourceRegion region, final HybridInterpreter runtime, final ITermFactory termFactory, final String languageName, final Map<IStrategoTerm, Boolean> leftRecursiveTerms, final Map<IStrategoTerm, Boolean> rightRecursiveTerms) {
if (result == null || region == null) {
return Iterables2.empty();
}
final Collection<IStrategoTerm> parsed = Lists.newLinkedList();
final IStrategoTermVisitor visitor = new AStrategoTermVisitor() {
@Override
public boolean visit(IStrategoTerm term) {
final ISourceLocation location = fromTokens(term, runtime, termFactory, position, languageName, leftRecursiveTerms, rightRecursiveTerms);
if (location != null && location.region().contains(region)) {
parsed.add(term);
return false;
}
return true;
}
};
StrategoTermVisitee.bottomup(visitor, (IStrategoTerm) result);
return parsed;
}
use of org.spoofax.terms.visitor.AStrategoTermVisitor in project spoofax by metaborg.
the class JSGLRCompletionService method findCompletionTermInsideNested.
private Collection<IStrategoTerm> findCompletionTermInsideNested(final StrategoTerm ast) {
final Collection<IStrategoTerm> completionTerms = Lists.newLinkedList();
final IStrategoTermVisitor visitor = new AStrategoTermVisitor() {
@Override
public boolean visit(IStrategoTerm term) {
ImploderAttachment ia = term.getAttachment(ImploderAttachment.TYPE);
if (ia.isNestedCompletion() && !term.equals(ast)) {
return false;
}
if (ia.isCompletion()) {
completionTerms.add(term);
return false;
}
return true;
}
};
StrategoTermVisitee.topdown(visitor, ast);
return completionTerms;
}
Aggregations