Skip to content

Commit

Permalink
refact: enable NonNullByDefault for lsp4e.progress package
Browse files Browse the repository at this point in the history
  • Loading branch information
sebthom committed May 22, 2024
1 parent 141c3ab commit 122ec95
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -95,9 +95,9 @@ public abstract static class LanguageServerDefinition {
public final int lastDocumentDisconnectedTimeout;
public final @NonNull Map<IContentType, String> languageIdMappings;

LanguageServerDefinition(@NonNull String id, @NonNull String label, boolean isSingleton, int lastDocumentDisconnectedTimeout) {
LanguageServerDefinition(@NonNull String id, @Nullable String label, boolean isSingleton, int lastDocumentDisconnectedTimeout) {
this.id = id;
this.label = label;
this.label = label == null ? id : label;
this.isSingleton = isSingleton;
this.lastDocumentDisconnectedTimeout = lastDocumentDisconnectedTimeout;
this.languageIdMappings = new ConcurrentHashMap<>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
*******************************************************************************/
package org.eclipse.lsp4e.progress;

import static org.eclipse.lsp4e.internal.NullSafetyHelper.castNullable;

import java.util.Map;
import java.util.Set;
import java.util.concurrent.BlockingQueue;
Expand All @@ -27,7 +29,8 @@
import org.eclipse.core.runtime.jobs.IJobChangeEvent;
import org.eclipse.core.runtime.jobs.Job;
import org.eclipse.core.runtime.jobs.JobChangeAdapter;
import org.eclipse.jdt.annotation.NonNull;
import org.eclipse.jdt.annotation.NonNullByDefault;
import org.eclipse.jdt.annotation.Nullable;
import org.eclipse.lsp4e.LanguageServerPlugin;
import org.eclipse.lsp4e.LanguageServersRegistry.LanguageServerDefinition;
import org.eclipse.lsp4e.ui.Messages;
Expand All @@ -44,8 +47,8 @@
public class LSPProgressManager {
private final Map<String, BlockingQueue<ProgressParams>> progressMap;
private final Map<IProgressMonitor, Integer> currentPercentageMap;
private LanguageServer languageServer;
private LanguageServerDefinition languageServerDefinition;
private @Nullable LanguageServer languageServer;
private @Nullable LanguageServerDefinition languageServerDefinition;
private final Set<String> done;
private final Set<Job> jobs;

Expand All @@ -67,11 +70,11 @@ public void connect(final LanguageServer languageServer, LanguageServerDefinitio
* the {@link WorkDoneProgressCreateParams} to be used to create the progress
* @return the completable future
*/
public @NonNull CompletableFuture<Void> createProgress(final @NonNull WorkDoneProgressCreateParams params) {
public CompletableFuture<@Nullable Void> createProgress(final WorkDoneProgressCreateParams params) {
final var queue = new LinkedBlockingDeque<ProgressParams>();

String jobIdentifier = params.getToken().map(Function.identity(), Object::toString);
BlockingQueue<ProgressParams> oldQueue = progressMap.put(jobIdentifier, queue);
BlockingQueue<ProgressParams> oldQueue = castNullable(progressMap.put(jobIdentifier, queue));
if (oldQueue != null) {
LanguageServerPlugin.logInfo(
"Old progress with identifier " + jobIdentifier + " discarded due to new create progress request"); //$NON-NLS-1$//$NON-NLS-2$
Expand All @@ -85,7 +88,7 @@ private void createJob(final LinkedBlockingDeque<ProgressParams> queue, final St
final var languageServerDefinition = this.languageServerDefinition;

final var jobName = languageServerDefinition == null //
|| languageServerDefinition.label == null || languageServerDefinition.label.isBlank() //
|| languageServerDefinition.label.isBlank() //
? Messages.LSPProgressManager_BackgroundJobName
: languageServerDefinition.label;
Job job = Job.create(jobName, (ICoreRunnable) monitor -> {
Expand All @@ -101,7 +104,7 @@ private void createJob(final LinkedBlockingDeque<ProgressParams> queue, final St
}
throw new OperationCanceledException();
}
ProgressParams nextProgressNotification = queue.pollFirst(1, TimeUnit.SECONDS);
ProgressParams nextProgressNotification = castNullable(queue.pollFirst(1, TimeUnit.SECONDS));
if (nextProgressNotification != null ) {
WorkDoneProgressNotification progressNotification = nextProgressNotification.getValue().getLeft();
if (progressNotification != null) {
Expand Down Expand Up @@ -129,7 +132,7 @@ private void createJob(final LinkedBlockingDeque<ProgressParams> queue, final St
jobs.add(job);
Job.getJobManager().addJobChangeListener(new JobChangeAdapter() {
@Override
public void done(IJobChangeEvent event) {
public void done(@NonNullByDefault({}) IJobChangeEvent event) {
jobs.remove(event.getJob());
}
});
Expand Down Expand Up @@ -167,7 +170,7 @@ private void report(final WorkDoneProgressReport report, final IProgressMonitor

if (report.getPercentage() != null) {
if (currentPercentageMap.containsKey(monitor)) {
Integer percentage = currentPercentageMap.get(monitor);
Integer percentage = castNullable(currentPercentageMap.get(monitor));
int worked = percentage != null ? Math.min(percentage, report.getPercentage()) : 0;
monitor.worked(report.getPercentage().intValue() - worked);
}
Expand All @@ -182,9 +185,9 @@ private void report(final WorkDoneProgressReport report, final IProgressMonitor
* @param params
* the {@link ProgressParams} used for the progress notification
*/
public void notifyProgress(final @NonNull ProgressParams params) {
public void notifyProgress(final ProgressParams params) {
String jobIdentifier = params.getToken().map(Function.identity(), Object::toString);
BlockingQueue<ProgressParams> progress = progressMap.get(jobIdentifier);
BlockingQueue<ProgressParams> progress = castNullable(progressMap.get(jobIdentifier));
if (progress != null) { // may happen if the server does not wait on the return value of the future of createProgress
progress.add(params);
} else {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
@NonNullByDefault
package org.eclipse.lsp4e.progress;

import org.eclipse.jdt.annotation.NonNullByDefault;

0 comments on commit 122ec95

Please sign in to comment.