use of eu.esdihumboldt.hale.ui.util.groovy.GroovyCompletionProposals in project hale by halestudio.
the class GroovyASTCompletionProcessor method computeCompletionProposals.
@Override
public ICompletionProposal[] computeCompletionProposals(final ITextViewer viewer, final int offset) {
if (proposals == null || proposals.isEmpty()) {
return null;
}
if (viewer instanceof CompilingSourceViewer<?>) {
CompilingSourceViewer<?> csv = (CompilingSourceViewer<?>) viewer;
try {
Object compiled = csv.getCompiled().get();
if (compiled instanceof GroovyAST) {
// the Groovy AST
GroovyAST ast = (GroovyAST) compiled;
// the line (0-based)
int line = csv.getDocument().getLineOfOffset(offset);
// the line column (0-based)
int column = offset - csv.getDocument().getLineOffset(line);
// locations in Groovy AST are 1-based
line++;
column++;
List<ICompletionProposal> list = new ArrayList<>();
// add proposals of individual computers
for (GroovyCompletionProposals proposal : proposals) {
Iterable<? extends ICompletionProposal> computed = proposal.computeProposals(viewer, ast, line, column, offset);
if (computed != null) {
Iterables.addAll(list, computed);
}
}
return list.toArray(new ICompletionProposal[list.size()]);
}
} catch (Exception e) {
log.warn("Failed to get AST to compute completion proposals", e);
}
}
return null;
}
Aggregations