public ICompletionProposal[] computeCompletionProposals( final ITextViewer viewer, final int offset) { final List proposals = new ArrayList(); final ICompletionProposal[] hippieProposals = hippie.computeCompletionProposals(viewer, offset); for (int i = 0; i < hippieProposals.length; i++) proposals.add(hippieProposals[i]); return (ICompletionProposal[]) proposals.toArray(new ICompletionProposal[0]); }
/** * Invoke content assist on the given viewer at the given offset, for the given number of pages * and return the results of each page * * @param viewer * @param offset * @param pageCount * @return * @throws Exception */ private static ICompletionProposal[][] getProposals( StructuredTextViewer viewer, int offset, int pageCount) throws Exception { // setup the viewer StructuredTextViewerConfigurationHTML configuration = new StructuredTextViewerConfigurationHTML(); ContentAssistant contentAssistant = (ContentAssistant) configuration.getContentAssistant(viewer); viewer.configure(configuration); viewer.setSelectedRange(offset, 0); // get the processor String partitionTypeID = viewer.getDocument().getPartition(offset).getType(); IContentAssistProcessor processor = contentAssistant.getContentAssistProcessor(partitionTypeID); // fire content assist session about to start Method privateFireSessionBeginEventMethod = ContentAssistant.class.getDeclaredMethod( "fireSessionBeginEvent", new Class[] {boolean.class}); privateFireSessionBeginEventMethod.setAccessible(true); privateFireSessionBeginEventMethod.invoke(contentAssistant, new Object[] {Boolean.TRUE}); // get content assist suggestions ICompletionProposal[][] pages = new ICompletionProposal[pageCount][]; for (int p = 0; p < pageCount; ++p) { pages[p] = processor.computeCompletionProposals(viewer, offset); } // fire content assist session ending Method privateFireSessionEndEventMethod = ContentAssistant.class.getDeclaredMethod("fireSessionEndEvent", null); privateFireSessionEndEventMethod.setAccessible(true); privateFireSessionEndEventMethod.invoke(contentAssistant, null); return pages; }