use of org.eclipse.jdt.ui.text.java.JavaContentAssistInvocationContext in project tdi-studio-se by Talend.
the class TalendJavaCompletionProcessor method createContext.
/*
* (non-Javadoc)
*
* @see
* org.eclipse.jdt.internal.ui.text.java.JavaCompletionProcessor#createContext(org.eclipse.jface.text.ITextViewer,
* int)
*/
@Override
protected ContentAssistInvocationContext createContext(ITextViewer viewer, int offset) {
if (viewer instanceof TalendJavaSourceViewer) {
((TalendJavaSourceViewer) viewer).updateContents();
ICompilationUnit compilationUnit = ((TalendJavaSourceViewer) viewer).getCompilationUnit();
if (compilationUnit != null) {
CompletionProposalCollector cpc = new CompletionProposalCollector(compilationUnit);
// set an empty editor Part as it's the only constructor where the viewer can be used.
JavaContentAssistInvocationContext invocContext = new JavaContentAssistInvocationContext(viewer, offset, new NullEditorPart());
cpc.setInvocationContext(invocContext);
return invocContext;
} else {
return null;
}
} else {
return null;
}
}
use of org.eclipse.jdt.ui.text.java.JavaContentAssistInvocationContext in project bndtools by bndtools.
the class BundleClassCompletionProposalComputer method computeCompletionProposals.
public List<ICompletionProposal> computeCompletionProposals(ContentAssistInvocationContext context, IProgressMonitor monitor) {
List<ICompletionProposal> result = new LinkedList<ICompletionProposal>();
if (!(context instanceof JavaContentAssistInvocationContext)) {
return Collections.emptyList();
}
try {
int offset = context.getInvocationOffset();
CharSequence prefix = context.computeIdentifierPrefix();
result.add(new CompletionProposal("foobar", offset - prefix.length(), prefix.length(), offset - prefix.length() + 6));
result.add(new CompletionProposal("fizzbuzz", offset - prefix.length(), prefix.length(), offset - prefix.length() + 8));
} catch (BadLocationException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return result;
}
Aggregations