Search in sources :

Example 1 with ITextViewer

use of org.eclipse.che.jface.text.ITextViewer in project che by eclipse.

the class JavaCompletionProposalComputer method internalComputeCompletionProposals.

private List<ICompletionProposal> internalComputeCompletionProposals(int offset, JavaContentAssistInvocationContext context) {
    ICompilationUnit unit = context.getCompilationUnit();
    if (unit == null)
        return Collections.emptyList();
    ITextViewer viewer = context.getViewer();
    CompletionProposalCollector collector = createCollector(context);
    collector.setInvocationContext(context);
    // Allow completions for unresolved types - since 3.3
    collector.setAllowsRequiredProposals(CompletionProposal.FIELD_REF, CompletionProposal.TYPE_REF, true);
    collector.setAllowsRequiredProposals(CompletionProposal.FIELD_REF, CompletionProposal.TYPE_IMPORT, true);
    collector.setAllowsRequiredProposals(CompletionProposal.FIELD_REF, CompletionProposal.FIELD_IMPORT, true);
    collector.setAllowsRequiredProposals(CompletionProposal.METHOD_REF, CompletionProposal.TYPE_REF, true);
    collector.setAllowsRequiredProposals(CompletionProposal.METHOD_REF, CompletionProposal.TYPE_IMPORT, true);
    collector.setAllowsRequiredProposals(CompletionProposal.METHOD_REF, CompletionProposal.METHOD_IMPORT, true);
    collector.setAllowsRequiredProposals(CompletionProposal.CONSTRUCTOR_INVOCATION, CompletionProposal.TYPE_REF, true);
    collector.setAllowsRequiredProposals(CompletionProposal.ANONYMOUS_CLASS_CONSTRUCTOR_INVOCATION, CompletionProposal.TYPE_REF, true);
    collector.setAllowsRequiredProposals(CompletionProposal.ANONYMOUS_CLASS_DECLARATION, CompletionProposal.TYPE_REF, true);
    collector.setAllowsRequiredProposals(CompletionProposal.TYPE_REF, CompletionProposal.TYPE_REF, true);
    // Set the favorite list to propose static members - since 3.3
    collector.setFavoriteReferences(getFavoriteStaticMembers());
    try {
        Point selection = viewer.getSelectedRange();
        if (selection.y > 0)
            collector.setReplacementLength(selection.y);
        unit.codeComplete(offset, collector, fTimeoutProgressMonitor);
    } catch (OperationCanceledException x) {
        //			IBindingService bindingSvc= (IBindingService)PlatformUI.getWorkbench().getAdapter(IBindingService.class);
        //			String keyBinding= bindingSvc.getBestActiveBindingFormattedFor(IWorkbenchCommandConstants.EDIT_CONTENT_ASSIST);
        //			fErrorMessage= Messages.format(JavaTextMessages.CompletionProcessor_error_javaCompletion_took_too_long_message, keyBinding);
        JavaPlugin.log(x);
    } catch (JavaModelException x) {
        //			Shell shell= viewer.getTextWidget().getShell();
        //			if (x.isDoesNotExist() && !unit.getJavaProject().isOnClasspath(unit))
        //				MessageDialog.openInformation(shell, JavaTextMessages.CompletionProcessor_error_notOnBuildPath_title, JavaTextMessages.CompletionProcessor_error_notOnBuildPath_message);
        //			else
        //				ErrorDialog.openError(shell, JavaTextMessages.CompletionProcessor_error_accessing_title, JavaTextMessages.CompletionProcessor_error_accessing_message, x.getStatus());
        JavaPlugin.log(x);
    }
    ICompletionProposal[] javaProposals = collector.getJavaCompletionProposals();
    int contextInformationOffset = guessMethodContextInformationPosition(context);
    if (contextInformationOffset != offset) {
        for (int i = 0; i < javaProposals.length; i++) {
            if (javaProposals[i] instanceof JavaMethodCompletionProposal) {
                JavaMethodCompletionProposal jmcp = (JavaMethodCompletionProposal) javaProposals[i];
                jmcp.setContextInformationPosition(contextInformationOffset);
            }
        }
    }
    List<ICompletionProposal> proposals = new ArrayList<ICompletionProposal>(Arrays.asList(javaProposals));
    if (proposals.size() == 0) {
        String error = collector.getErrorMessage();
        if (error.length() > 0)
            fErrorMessage = error;
    }
    return proposals;
}
Also used : ICompilationUnit(org.eclipse.jdt.core.ICompilationUnit) JavaModelException(org.eclipse.jdt.core.JavaModelException) OperationCanceledException(org.eclipse.core.runtime.OperationCanceledException) ArrayList(java.util.ArrayList) Point(org.eclipse.swt.graphics.Point) Point(org.eclipse.swt.graphics.Point) ITextViewer(org.eclipse.che.jface.text.ITextViewer) CompletionProposalCollector(org.eclipse.jdt.ui.text.java.CompletionProposalCollector) ICompletionProposal(org.eclipse.che.jface.text.contentassist.ICompletionProposal)

Aggregations

ArrayList (java.util.ArrayList)1 ITextViewer (org.eclipse.che.jface.text.ITextViewer)1 ICompletionProposal (org.eclipse.che.jface.text.contentassist.ICompletionProposal)1 OperationCanceledException (org.eclipse.core.runtime.OperationCanceledException)1 ICompilationUnit (org.eclipse.jdt.core.ICompilationUnit)1 JavaModelException (org.eclipse.jdt.core.JavaModelException)1 CompletionProposalCollector (org.eclipse.jdt.ui.text.java.CompletionProposalCollector)1 Point (org.eclipse.swt.graphics.Point)1