Example usage for org.eclipse.jdt.internal.codeassist InternalCompletionContext InternalCompletionContext

List of usage examples for org.eclipse.jdt.internal.codeassist InternalCompletionContext InternalCompletionContext

Introduction

In this page you can find the example usage for org.eclipse.jdt.internal.codeassist InternalCompletionContext InternalCompletionContext.

Prototype

InternalCompletionContext

Source Link

Usage

From source file:org.grails.ide.eclipse.editor.gsp.adapter.CodeCompletionDelegate.java

License:Open Source License

public void codeComplete(ICompilationUnit unit, ICompilationUnit unitToSkip, int position,
        CompletionRequestor requestor, WorkingCopyOwner owner, ITypeRoot typeRoot, IProgressMonitor monitor)
        throws JavaModelException {

    InternalCompletionContext completionContext = new InternalCompletionContext();
    requestor.acceptContext(completionContext);

    GroovyCompletionProposalComputer computer = new GroovyCompletionProposalComputer();
    JavaContentAssistInvocationContext context = createContext((GroovyCompilationUnit) typeRoot, position);
    try {//from w  w  w.j  a v  a 2s  .  c o m
        if (GrailsCoreActivator.testMode) {
            // on build server, GSPContentAssistTests are failing because
            // monitor is being canceled. Avoid that problem here
            monitor = new NullProgressMonitor() {
                @Override
                public void setCanceled(boolean cancelled) {
                    // no-op
                }
            };
        }
        if (monitor == null) {
            monitor = new NullProgressMonitor();
        }
        monitor.beginTask("Content assist", 1);
        List<ICompletionProposal> proposals = computer.computeCompletionProposals(context, monitor);
        for (ICompletionProposal proposal : proposals) {
            CompletionProposal cp = null;
            if (proposal instanceof LazyJavaCompletionProposal) {
                cp = (CompletionProposal) ReflectionUtils.getPrivateField(LazyJavaCompletionProposal.class,
                        "fProposal", proposal); //$NON-NLS-1$
            } else if (proposal instanceof GroovyJavaFieldCompletionProposal) {
                cp = ((GroovyJavaFieldCompletionProposal) proposal).getProposal();
            } else if (proposal instanceof JavaCompletionProposal) {
                cp = createMockProposal((JavaCompletionProposal) proposal);
            }
            if (cp != null) {
                requestor.accept(cp);
            }
        }
    } catch (Exception e) {
        GroovyCore.logException("Exception with code completion", e); //$NON-NLS-1$
    }
}