Search in sources :

Example 1 with DocumentAdapter

use of org.eclipse.jdt.ls.core.internal.DocumentAdapter in project eclipse.jdt.ls by eclipse.

the class AbstractProjectsManagerBasedTest method initProjectManager.

@Before
public void initProjectManager() throws CoreException {
    clientRequests.clear();
    logListener = new SimpleLogListener();
    Platform.addLogListener(logListener);
    preferences = new Preferences();
    if (preferenceManager != null) {
        when(preferenceManager.getPreferences()).thenReturn(preferences);
        ClientPreferences clientPreferences = mock(ClientPreferences.class);
        when(clientPreferences.isProgressReportSupported()).thenReturn(true);
        when(preferenceManager.getClientPreferences()).thenReturn(clientPreferences);
    }
    projectsManager = new ProjectsManager(preferenceManager);
    ProgressReporterManager progressManager = new ProgressReporterManager(this.client, preferenceManager);
    // disable throttling to ensure we capture all events
    progressManager.setReportThrottle(0);
    Job.getJobManager().setProgressProvider(progressManager);
    monitor = progressManager.getDefaultMonitor();
    WorkingCopyOwner.setPrimaryBufferProvider(new WorkingCopyOwner() {

        @Override
        public IBuffer createBuffer(ICompilationUnit workingCopy) {
            ICompilationUnit original = workingCopy.getPrimary();
            IResource resource = original.getResource();
            if (resource instanceof IFile) {
                return new DocumentAdapter(workingCopy, (IFile) resource);
            }
            return DocumentAdapter.Null;
        }
    });
}
Also used : ICompilationUnit(org.eclipse.jdt.core.ICompilationUnit) SimpleLogListener(org.eclipse.jdt.ls.core.internal.SimpleLogListener) ClientPreferences(org.eclipse.jdt.ls.core.internal.preferences.ClientPreferences) IFile(org.eclipse.core.resources.IFile) WorkingCopyOwner(org.eclipse.jdt.core.WorkingCopyOwner) ProgressReporterManager(org.eclipse.jdt.ls.core.internal.handlers.ProgressReporterManager) DocumentAdapter(org.eclipse.jdt.ls.core.internal.DocumentAdapter) ClientPreferences(org.eclipse.jdt.ls.core.internal.preferences.ClientPreferences) Preferences(org.eclipse.jdt.ls.core.internal.preferences.Preferences) IBuffer(org.eclipse.jdt.core.IBuffer) IResource(org.eclipse.core.resources.IResource) Before(org.junit.Before)

Example 2 with DocumentAdapter

use of org.eclipse.jdt.ls.core.internal.DocumentAdapter in project eclipse.jdt.ls by eclipse.

the class DocumentLifeCycleHandler method performValidation.

private IStatus performValidation(IProgressMonitor monitor) throws JavaModelException {
    long start = System.currentTimeMillis();
    List<ICompilationUnit> cusToReconcile = new ArrayList<>();
    synchronized (toReconcile) {
        cusToReconcile.addAll(toReconcile);
        toReconcile.clear();
    }
    if (cusToReconcile.isEmpty()) {
        return Status.OK_STATUS;
    }
    // first reconcile all units with content changes
    SubMonitor progress = SubMonitor.convert(monitor, cusToReconcile.size() + 1);
    for (ICompilationUnit cu : cusToReconcile) {
        cu.reconcile(ICompilationUnit.NO_AST, true, null, progress.newChild(1));
    }
    this.sharedASTProvider.disposeAST();
    List<ICompilationUnit> toValidate = Arrays.asList(JavaCore.getWorkingCopies(null));
    List<CompilationUnit> astRoots = new ArrayList<>();
    for (ICompilationUnit rootToValidate : toValidate) {
        CompilationUnit astRoot = this.sharedASTProvider.getAST(rootToValidate, CoreASTProvider.WAIT_YES, monitor);
        astRoots.add(astRoot);
    }
    for (CompilationUnit astRoot : astRoots) {
        // report errors, even if there are no problems in the file: The client need to know that they got fixed.
        ICompilationUnit unit = (ICompilationUnit) astRoot.getTypeRoot();
        final DiagnosticsHandler handler = new DiagnosticsHandler(connection, unit);
        WorkingCopyOwner wcOwner = new WorkingCopyOwner() {

            /* (non-Javadoc)
				 * @see org.eclipse.jdt.core.WorkingCopyOwner#createBuffer(org.eclipse.jdt.core.ICompilationUnit)
				 */
            @Override
            public IBuffer createBuffer(ICompilationUnit workingCopy) {
                ICompilationUnit original = workingCopy.getPrimary();
                IResource resource = original.getResource();
                if (resource instanceof IFile) {
                    return new DocumentAdapter(workingCopy, (IFile) resource);
                }
                return DocumentAdapter.Null;
            }

            /* (non-Javadoc)
				 * @see org.eclipse.jdt.core.WorkingCopyOwner#getProblemRequestor(org.eclipse.jdt.core.ICompilationUnit)
				 */
            @Override
            public IProblemRequestor getProblemRequestor(ICompilationUnit workingCopy) {
                return handler;
            }
        };
        unit.reconcile(ICompilationUnit.NO_AST, true, wcOwner, progress.newChild(1));
    }
    JavaLanguageServerPlugin.logInfo("Reconciled " + toReconcile.size() + ", validated: " + toValidate.size() + ". Took " + (System.currentTimeMillis() - start) + " ms");
    return Status.OK_STATUS;
}
Also used : ICompilationUnit(org.eclipse.jdt.core.ICompilationUnit) CompilationUnit(org.eclipse.jdt.core.dom.CompilationUnit) ICompilationUnit(org.eclipse.jdt.core.ICompilationUnit) IFile(org.eclipse.core.resources.IFile) WorkingCopyOwner(org.eclipse.jdt.core.WorkingCopyOwner) ArrayList(java.util.ArrayList) SubMonitor(org.eclipse.core.runtime.SubMonitor) DocumentAdapter(org.eclipse.jdt.ls.core.internal.DocumentAdapter) IResource(org.eclipse.core.resources.IResource)

Aggregations

IFile (org.eclipse.core.resources.IFile)2 IResource (org.eclipse.core.resources.IResource)2 ICompilationUnit (org.eclipse.jdt.core.ICompilationUnit)2 WorkingCopyOwner (org.eclipse.jdt.core.WorkingCopyOwner)2 DocumentAdapter (org.eclipse.jdt.ls.core.internal.DocumentAdapter)2 ArrayList (java.util.ArrayList)1 SubMonitor (org.eclipse.core.runtime.SubMonitor)1 IBuffer (org.eclipse.jdt.core.IBuffer)1 CompilationUnit (org.eclipse.jdt.core.dom.CompilationUnit)1 SimpleLogListener (org.eclipse.jdt.ls.core.internal.SimpleLogListener)1 ProgressReporterManager (org.eclipse.jdt.ls.core.internal.handlers.ProgressReporterManager)1 ClientPreferences (org.eclipse.jdt.ls.core.internal.preferences.ClientPreferences)1 Preferences (org.eclipse.jdt.ls.core.internal.preferences.Preferences)1 Before (org.junit.Before)1