Search in sources :

Example 1 with CompletionEngine

use of org.eclipse.jdt.internal.codeassist.CompletionEngine in project eclipse.jdt.ls by eclipse.

the class ModelBasedCompletionEngine method codeComplete.

public static void codeComplete(ICompilationUnit cu, int position, CompletionRequestor requestor, WorkingCopyOwner owner, IProgressMonitor monitor) throws JavaModelException {
    if (!(cu instanceof CompilationUnit)) {
        return;
    }
    if (requestor == null) {
        // $NON-NLS-1$
        throw new IllegalArgumentException("Completion requestor cannot be null");
    }
    IBuffer buffer = cu.getBuffer();
    if (buffer == null) {
        return;
    }
    if (position < -1 || position > buffer.getLength()) {
        throw new JavaModelException(new JavaModelStatus(IJavaModelStatusConstants.INDEX_OUT_OF_BOUNDS));
    }
    JavaProject project = (JavaProject) cu.getJavaProject();
    ModelBasedSearchableEnvironment environment = new ModelBasedSearchableEnvironment(project, owner, requestor.isTestCodeExcluded());
    environment.setUnitToSkip((CompilationUnit) cu);
    // code complete
    CompletionEngine engine = new CompletionEngine(environment, requestor, project.getOptions(true), project, owner, monitor);
    engine.complete((CompilationUnit) cu, position, 0, cu);
}
Also used : ICompilationUnit(org.eclipse.jdt.core.ICompilationUnit) CompilationUnit(org.eclipse.jdt.internal.core.CompilationUnit) JavaModelException(org.eclipse.jdt.core.JavaModelException) JavaProject(org.eclipse.jdt.internal.core.JavaProject) JavaModelStatus(org.eclipse.jdt.internal.core.JavaModelStatus) CompletionEngine(org.eclipse.jdt.internal.codeassist.CompletionEngine) IBuffer(org.eclipse.jdt.core.IBuffer)

Aggregations

IBuffer (org.eclipse.jdt.core.IBuffer)1 ICompilationUnit (org.eclipse.jdt.core.ICompilationUnit)1 JavaModelException (org.eclipse.jdt.core.JavaModelException)1 CompletionEngine (org.eclipse.jdt.internal.codeassist.CompletionEngine)1 CompilationUnit (org.eclipse.jdt.internal.core.CompilationUnit)1 JavaModelStatus (org.eclipse.jdt.internal.core.JavaModelStatus)1 JavaProject (org.eclipse.jdt.internal.core.JavaProject)1