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;
}
});
}
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;
}
Aggregations