Skip to content

Commit

Permalink
refact: enable NonNullByDefault for lsp4e.debug and lsp4e.jdt plugins
Browse files Browse the repository at this point in the history
  • Loading branch information
sebthom committed Aug 15, 2024
1 parent ceb1600 commit 6f4dd5a
Show file tree
Hide file tree
Showing 62 changed files with 1,077 additions and 360 deletions.
29 changes: 21 additions & 8 deletions org.eclipse.lsp4e.debug/.settings/org.eclipse.jdt.core.prefs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
eclipse.preferences.version=1
org.eclipse.jdt.core.builder.annotationPath.allLocations=enabled
org.eclipse.jdt.core.builder.cleanOutputFolder=clean
org.eclipse.jdt.core.builder.duplicateResourceTask=warning
org.eclipse.jdt.core.builder.invalidClasspath=abort
Expand All @@ -9,21 +10,30 @@ org.eclipse.jdt.core.classpath.exclusionPatterns=enabled
org.eclipse.jdt.core.classpath.mainOnlyProjectHasTestOnlyDependency=error
org.eclipse.jdt.core.classpath.multipleOutputLocations=enabled
org.eclipse.jdt.core.classpath.outputOverlappingAnotherSource=error
org.eclipse.jdt.core.compiler.annotation.inheritNullAnnotations=disabled
org.eclipse.jdt.core.compiler.annotation.missingNonNullByDefaultAnnotation=ignore
org.eclipse.jdt.core.compiler.annotation.inheritNullAnnotations=enabled
org.eclipse.jdt.core.compiler.annotation.missingNonNullByDefaultAnnotation=warning
org.eclipse.jdt.core.compiler.annotation.nonnull=org.eclipse.jdt.annotation.NonNull
org.eclipse.jdt.core.compiler.annotation.nonnull.secondary=
org.eclipse.jdt.core.compiler.annotation.nonnullbydefault=org.eclipse.jdt.annotation.NonNullByDefault
org.eclipse.jdt.core.compiler.annotation.nonnullbydefault.secondary=
org.eclipse.jdt.core.compiler.annotation.notowning=org.eclipse.jdt.annotation.NotOwning
org.eclipse.jdt.core.compiler.annotation.nullable=org.eclipse.jdt.annotation.Nullable
org.eclipse.jdt.core.compiler.annotation.nullable.secondary=
org.eclipse.jdt.core.compiler.annotation.nullanalysis=disabled
org.eclipse.jdt.core.compiler.annotation.nullanalysis=enabled
org.eclipse.jdt.core.compiler.annotation.owning=org.eclipse.jdt.annotation.Owning
org.eclipse.jdt.core.compiler.annotation.resourceanalysis=disabled
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
org.eclipse.jdt.core.compiler.codegen.methodParameters=generate
org.eclipse.jdt.core.compiler.codegen.targetPlatform=17
org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
org.eclipse.jdt.core.compiler.compliance=17
org.eclipse.jdt.core.compiler.debug.lineNumber=generate
org.eclipse.jdt.core.compiler.debug.localVariable=generate
org.eclipse.jdt.core.compiler.debug.sourceFile=generate
org.eclipse.jdt.core.compiler.doc.comment.support=enabled
org.eclipse.jdt.core.compiler.maxProblemPerUnit=100
org.eclipse.jdt.core.compiler.problem.APILeak=warning
org.eclipse.jdt.core.compiler.problem.annotatedTypeArgumentToUnannotated=info
org.eclipse.jdt.core.compiler.problem.annotationSuperInterface=warning
org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
org.eclipse.jdt.core.compiler.problem.autoboxing=ignore
Expand All @@ -44,10 +54,12 @@ org.eclipse.jdt.core.compiler.problem.finalParameterBound=warning
org.eclipse.jdt.core.compiler.problem.finallyBlockNotCompletingNormally=warning
org.eclipse.jdt.core.compiler.problem.forbiddenReference=error
org.eclipse.jdt.core.compiler.problem.hiddenCatchBlock=warning
org.eclipse.jdt.core.compiler.problem.includeNullInfoFromAsserts=disabled
org.eclipse.jdt.core.compiler.problem.includeNullInfoFromAsserts=enabled
org.eclipse.jdt.core.compiler.problem.incompatibleNonInheritedInterfaceMethod=warning
org.eclipse.jdt.core.compiler.problem.incompatibleOwningContract=warning
org.eclipse.jdt.core.compiler.problem.incompleteEnumSwitch=warning
org.eclipse.jdt.core.compiler.problem.indirectStaticAccess=ignore
org.eclipse.jdt.core.compiler.problem.insufficientResourceAnalysis=warning
org.eclipse.jdt.core.compiler.problem.invalidJavadoc=ignore
org.eclipse.jdt.core.compiler.problem.invalidJavadocTags=disabled
org.eclipse.jdt.core.compiler.problem.invalidJavadocTagsDeprecatedRef=disabled
Expand Down Expand Up @@ -77,14 +89,14 @@ org.eclipse.jdt.core.compiler.problem.nonExternalizedStringLiteral=ignore
org.eclipse.jdt.core.compiler.problem.nonnullParameterAnnotationDropped=warning
org.eclipse.jdt.core.compiler.problem.nonnullTypeVariableFromLegacyInvocation=warning
org.eclipse.jdt.core.compiler.problem.nullAnnotationInferenceConflict=error
org.eclipse.jdt.core.compiler.problem.nullReference=warning
org.eclipse.jdt.core.compiler.problem.nullReference=error
org.eclipse.jdt.core.compiler.problem.nullSpecViolation=error
org.eclipse.jdt.core.compiler.problem.nullUncheckedConversion=warning
org.eclipse.jdt.core.compiler.problem.nullUncheckedConversion=info
org.eclipse.jdt.core.compiler.problem.overridingPackageDefaultMethod=warning
org.eclipse.jdt.core.compiler.problem.parameterAssignment=ignore
org.eclipse.jdt.core.compiler.problem.pessimisticNullAnalysisForFreeTypeVariables=warning
org.eclipse.jdt.core.compiler.problem.possibleAccidentalBooleanAssignment=ignore
org.eclipse.jdt.core.compiler.problem.potentialNullReference=ignore
org.eclipse.jdt.core.compiler.problem.potentialNullReference=error
org.eclipse.jdt.core.compiler.problem.potentiallyUnclosedCloseable=ignore
org.eclipse.jdt.core.compiler.problem.rawTypeReference=warning
org.eclipse.jdt.core.compiler.problem.redundantNullAnnotation=warning
Expand All @@ -98,7 +110,8 @@ org.eclipse.jdt.core.compiler.problem.specialParameterHidingField=disabled
org.eclipse.jdt.core.compiler.problem.staticAccessReceiver=warning
org.eclipse.jdt.core.compiler.problem.suppressOptionalErrors=disabled
org.eclipse.jdt.core.compiler.problem.suppressWarnings=enabled
org.eclipse.jdt.core.compiler.problem.syntacticNullAnalysisForFields=disabled
org.eclipse.jdt.core.compiler.problem.suppressWarningsNotFullyAnalysed=info
org.eclipse.jdt.core.compiler.problem.syntacticNullAnalysisForFields=enabled
org.eclipse.jdt.core.compiler.problem.syntheticAccessEmulation=ignore
org.eclipse.jdt.core.compiler.problem.terminalDeprecation=warning
org.eclipse.jdt.core.compiler.problem.typeParameterHiding=warning
Expand Down
8 changes: 4 additions & 4 deletions org.eclipse.lsp4e.debug/META-INF/MANIFEST.MF
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,16 @@ Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-Name: Debug Adapter client for Eclipse IDE (Incubation)
Bundle-SymbolicName: org.eclipse.lsp4e.debug;singleton:=true
Bundle-Version: 0.15.10.qualifier
Bundle-Version: 0.15.11.qualifier
Bundle-Activator: org.eclipse.lsp4e.debug.DSPPlugin
Require-Bundle: org.eclipse.ui,
org.eclipse.core.runtime,
org.eclipse.debug.core,
org.eclipse.debug.ui,
org.eclipse.jface,
org.eclipse.lsp4j.jsonrpc;bundle-version="[0.23.0,0.24.0)",
org.eclipse.lsp4j.jsonrpc.debug;bundle-version="[0.23.0,0.24.0)",
org.eclipse.lsp4j.debug;bundle-version="[0.23.0,0.24.0)",
org.eclipse.lsp4j.jsonrpc;bundle-version="[0.23.1,0.24.0)",
org.eclipse.lsp4j.jsonrpc.debug;bundle-version="[0.23.1,0.24.0)",
org.eclipse.lsp4j.debug;bundle-version="[0.23.1,0.24.0)",
org.eclipse.ui.editors,
org.eclipse.core.filesystem,
org.eclipse.ui.ide;bundle-version="[3.16.0,4.0.0)",
Expand Down
6 changes: 5 additions & 1 deletion org.eclipse.lsp4e.debug/build.properties
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,9 @@ bin.includes = META-INF/,\
.,\
plugin.xml,\
EPL-2.0.html,\
.options,\
.options,\
icons/

# JDT Null Analysis for Eclipse
additional.bundles = org.eclipse.jdt.annotation,\
com.vegardit.no-npe.eea-all
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import java.net.URL;

import org.eclipse.core.runtime.Platform;
import org.eclipse.jdt.annotation.Nullable;
import org.eclipse.jface.resource.ImageDescriptor;
import org.eclipse.jface.resource.ImageRegistry;
import org.eclipse.swt.graphics.Image;
Expand Down Expand Up @@ -65,7 +66,7 @@ public static Image get(String key) {
return imageRegistry.get(key);
}

private static URL makeIconFileURL(String prefix, String name) {
private static @Nullable URL makeIconFileURL(String prefix, String name) {
final var buffer = new StringBuilder(prefix);
buffer.append(name);
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,11 @@
*******************************************************************************/
package org.eclipse.lsp4e.debug;

import org.eclipse.core.runtime.Assert;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Platform;
import org.eclipse.core.runtime.Status;
import org.eclipse.jdt.annotation.Nullable;
import org.eclipse.lsp4j.jsonrpc.ResponseErrorException;
import org.eclipse.lsp4j.jsonrpc.messages.ResponseError;
import org.eclipse.ui.plugin.AbstractUIPlugin;
Expand Down Expand Up @@ -51,7 +53,7 @@ public class DSPPlugin extends AbstractUIPlugin {
public static final String ATTR_CUSTOM_LAUNCH_PARAMS = ID_DSP_DEBUG_MODEL + ".ATTR_CUSTOM_LAUNCH_PARAMS";

// The shared instance
private static DSPPlugin plugin;
private static volatile @Nullable DSPPlugin plugin;

public DSPPlugin() {
}
Expand All @@ -74,6 +76,7 @@ public void stop(BundleContext context) throws Exception {
* @return the shared instance
*/
public static DSPPlugin getDefault() {
Assert.isNotNull(plugin);
return plugin;
}

Expand All @@ -92,7 +95,7 @@ public static void logError(final Throwable thr) {
* @param message User comprehensible message
* @param thr The exception through which we noticed the error
*/
public static void logError(final String message, final Throwable thr) {
public static void logError(final @Nullable String message, final @Nullable Throwable thr) {
log(IStatus.ERROR, message, thr);
}

Expand All @@ -111,11 +114,11 @@ public static void logInfo(final String message) {
* @param message User comprehensible message
* @param thr The exception through which we noticed the warning
*/
public static void logWarning(final String message, final Throwable thr) {
public static void logWarning(final String message, final @Nullable Throwable thr) {
log(IStatus.WARNING, message, thr);
}

private static void log(int severity, String message, final Throwable thr) {
private static void log(final int severity, @Nullable String message, final @Nullable Throwable thr) {
ResponseError error = null;
if (thr instanceof ResponseErrorException responseErrorException) {
error = responseErrorException.getResponseError();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import org.eclipse.debug.core.model.IBreakpoint;
import org.eclipse.debug.core.model.ILineBreakpoint;
import org.eclipse.debug.ui.actions.IToggleBreakpointsTarget;
import org.eclipse.jdt.annotation.Nullable;
import org.eclipse.jface.text.ITextSelection;
import org.eclipse.jface.viewers.ISelection;
import org.eclipse.lsp4e.debug.DSPPlugin;
Expand Down Expand Up @@ -55,12 +56,12 @@ public boolean canToggleLineBreakpoints(IWorkbenchPart part, ISelection selectio
return true;
}

private ITextEditor getEditor(IWorkbenchPart part) {
private @Nullable ITextEditor getEditor(IWorkbenchPart part) {
if (part instanceof ITextEditor textEditor) {
return textEditor;
}
if (part instanceof MultiPageEditorPart multiPageEditorPart
&& ((MultiPageEditorPart) part).getSelectedPage() instanceof ITextEditor textEditor) {
&& multiPageEditorPart.getSelectedPage() instanceof ITextEditor textEditor) {
return textEditor;
}
return null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,61 +13,59 @@
import java.net.URISyntaxException;

import org.eclipse.core.filebuffers.FileBuffers;
import org.eclipse.core.filebuffers.IFileBuffer;
import org.eclipse.core.filebuffers.ITextFileBuffer;
import org.eclipse.core.filebuffers.ITextFileBufferManager;
import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IResource;
import org.eclipse.core.resources.ResourcesPlugin;
import org.eclipse.core.runtime.Adapters;
import org.eclipse.core.runtime.IPath;
import org.eclipse.jdt.annotation.Nullable;
import org.eclipse.jface.text.IDocument;
import org.eclipse.lsp4e.debug.DSPPlugin;

/*
* All this is mostly copied from LSPEclipseUtils.
/**
* The code is copied from LSPEclipseUtils.
*/
final class DocumentUtils {

private static ITextFileBuffer toBuffer(IDocument document) {
private static @Nullable ITextFileBuffer toBuffer(@Nullable IDocument document) {
if (document == null) {
return null;
}
ITextFileBufferManager bufferManager = FileBuffers.getTextFileBufferManager();
if (bufferManager == null)
return null;
return bufferManager.getTextFileBuffer(document);
}

public static URI toUri(IDocument document) {
IFile file = getFile(document);
public static @Nullable URI toUri(IDocument document) {
ITextFileBuffer buffer = toBuffer(document);
IPath path = toPath(buffer);
IFile file = getFile(path);
if (file != null) {
return toUri(file);
} else {
ITextFileBuffer buffer = toBuffer(document);
if (buffer != null) {
IPath path = toPath(buffer);
if (path != null) {
return toUri(path.toFile());
} else {
return buffer.getFileStore().toURI();
}
}
} else if (path != null) {
return toUri(path.toFile());
} else if (buffer != null && buffer.getFileStore() != null) {
return buffer.getFileStore().toURI();
}
return null;
}

private static IPath toPath(ITextFileBuffer buffer) {
private static @Nullable IPath toPath(@Nullable IFileBuffer buffer) {
if (buffer != null) {
return buffer.getLocation();
}
return null;
}

private static IPath toPath(IDocument document) {
return toPath(toBuffer(document));
}

private static URI toUri(IPath absolutePath) {
return toUri(absolutePath.toFile());
}

private static URI toUri(IResource resource) {
private static @Nullable URI toUri(IResource resource) {
URI adaptedURI = Adapters.adapt(resource, URI.class, true);
if (adaptedURI != null) {
return adaptedURI;
Expand All @@ -84,25 +82,27 @@ private static URI toUri(File file) {
try {
return new URI("file", "", file.getAbsoluteFile().toURI().getPath(), null); //$NON-NLS-1$ //$NON-NLS-2$
} catch (URISyntaxException e) {
DSPPlugin.logError(e);
return file.getAbsoluteFile().toURI();
}
}

private static IFile getFile(IDocument document) {
IPath path = toPath(document);
return getFile(path);
}

private static IFile getFile(IPath path) {
/**
* @return null if no file exists at the given path or the given path points to
* a file outside the workspace
*/
private static @Nullable IFile getFile(@Nullable IPath path) {
if (path == null) {
return null;
}
IFile res = ResourcesPlugin.getWorkspace().getRoot().getFile(path);

final IFile res = path.segmentCount() == 1 //
? ResourcesPlugin.getWorkspace().getRoot().getFileForLocation(path)
: ResourcesPlugin.getWorkspace().getRoot().getFile(path);
if (res != null && res.exists()) {
return res;
} else {
return null;
}
return null;
}

private DocumentUtils() {
Expand Down
Loading

0 comments on commit 6f4dd5a

Please sign in to comment.