Skip to content

Commit

Permalink
Merge pull request #355 from NipunaRanasinghe/warnings
Browse files Browse the repository at this point in the history
Fix code warnings for java 11
  • Loading branch information
NipunaRanasinghe authored Apr 18, 2024
2 parents b21faac + fc3a5ff commit 0505245
Show file tree
Hide file tree
Showing 20 changed files with 61 additions and 49 deletions.
13 changes: 13 additions & 0 deletions spotbugs-exclude.xml
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,19 @@
<Class name="org.wso2.lsp4intellij.utils.FileUtils"/>
<Method name="findProjectsFor"/>
</And>
<And>
<Class name="org.wso2.lsp4intellij.listeners.LSPTypedHandler"/>
<Method name="charTyped"/>
</And>
<And>
<Class name="org.wso2.lsp4intellij.listeners.LSPTypedHandler"/>
<Method name="checkAutoPopup"/>
</And>
<And>
<Class name="org.wso2.lsp4intellij.statusbar.LSPServerStatusWidgetFactory"/>
<Method name="createWidget"/>
</And>

</Or>
</And>
</Match>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,11 +57,11 @@

public class IntellijLanguageClient implements ApplicationComponent, Disposable {

private static Logger LOG = Logger.getInstance(IntellijLanguageClient.class);
private static final Logger LOG = Logger.getInstance(IntellijLanguageClient.class);
private static final Map<Pair<String, String>, LanguageServerWrapper> extToLanguageWrapper = new ConcurrentHashMap<>();
private static Map<String, Set<LanguageServerWrapper>> projectToLanguageWrappers = new ConcurrentHashMap<>();
private static Map<Pair<String, String>, LanguageServerDefinition> extToServerDefinition = new ConcurrentHashMap<>();
private static Map<String, LSPExtensionManager> extToExtManager = new ConcurrentHashMap<>();
private static final Map<String, Set<LanguageServerWrapper>> projectToLanguageWrappers = new ConcurrentHashMap<>();
private static final Map<Pair<String, String>, LanguageServerDefinition> extToServerDefinition = new ConcurrentHashMap<>();
private static final Map<String, LSPExtensionManager> extToExtManager = new ConcurrentHashMap<>();
private static final Predicate<LanguageServerWrapper> RUNNING = (s) -> s.getStatus() != ServerStatus.STOPPED;

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import java.util.HashSet;
import java.util.List;
import java.util.Objects;
import java.util.stream.Collectors;

/**
* A class symbolizing a stream to a process
Expand All @@ -38,7 +39,7 @@ public class ProcessStreamConnectionProvider implements StreamConnectionProvider
private final Logger LOG = Logger.getInstance(ProcessStreamConnectionProvider.class);

@Nullable
private ProcessBuilder builder;
private final ProcessBuilder builder;
@Nullable
private Process process = null;
private List<String> commands;
Expand Down Expand Up @@ -72,7 +73,7 @@ private ProcessBuilder createProcessBuilder() {
if (builder != null) {
return builder;
} else {
commands.forEach(c -> c = c.replace("\'", ""));
commands = commands.stream().map(c -> c.replace("'", "")).collect(Collectors.toList());
ProcessBuilder builder = new ProcessBuilder(commands);
builder.directory(new File(workingDir));
builder.redirectError(ProcessBuilder.Redirect.INHERIT);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -348,7 +348,7 @@ public void didChange(DidChangeTextDocumentParams params) {
public void willSave(WillSaveTextDocumentParams params) {
if (checkStatus()) {
try {
if (Optional.ofNullable(textDocumentOptions).map(x -> x.getWillSave()).orElse(false)) {
if (Optional.ofNullable(textDocumentOptions).map(TextDocumentSyncOptions::getWillSave).orElse(false)) {
textDocumentService.willSave(params);
}
} catch (Exception e) {
Expand All @@ -361,7 +361,7 @@ public void willSave(WillSaveTextDocumentParams params) {
public CompletableFuture<List<TextEdit>> willSaveWaitUntil(WillSaveTextDocumentParams params) {
if (checkStatus()) {
try {
return Optional.ofNullable(textDocumentOptions).map(x -> x.getWillSaveWaitUntil()).orElse(false) ?
return Optional.ofNullable(textDocumentOptions).map(TextDocumentSyncOptions::getWillSaveWaitUntil).orElse(false) ?
textDocumentService.willSaveWaitUntil(params) : null;
} catch (Exception e) {
crashed(e);
Expand All @@ -375,7 +375,7 @@ public CompletableFuture<List<TextEdit>> willSaveWaitUntil(WillSaveTextDocumentP
public void didSave(DidSaveTextDocumentParams params) {
if (checkStatus()) {
try {
if (Optional.ofNullable(textDocumentOptions).map(x -> x.getSave()).isPresent()) {
if (Optional.ofNullable(textDocumentOptions).map(TextDocumentSyncOptions::getSave).isPresent()) {
textDocumentService.didSave(params);
}
} catch (Exception e) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public class LanguageServerDefinition {

public String ext;
protected Map<String, String> languageIds = Collections.emptyMap();
private Map<String, StreamConnectionProvider> streamConnectionProviders = new ConcurrentHashMap<>();
private final Map<String, StreamConnectionProvider> streamConnectionProviders = new ConcurrentHashMap<>();
public static final String SPLIT_CHAR = ",";

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@

class MessageHandler implements Function<MessageConsumer, MessageConsumer> {

private ServerListener listener;
private BooleanSupplier isRunning;
private final ServerListener listener;
private final BooleanSupplier isRunning;
private LanguageServer languageServer;

MessageHandler(@NotNull ServerListener listener, @NotNull BooleanSupplier isRunning) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

import com.intellij.openapi.editor.event.DocumentEvent;
import com.intellij.openapi.editor.event.DocumentListener;
import org.jetbrains.annotations.NotNull;

public class DocumentListenerImpl extends LSPListener implements DocumentListener {

Expand All @@ -26,7 +27,7 @@ public class DocumentListenerImpl extends LSPListener implements DocumentListene
* @param event the event containing the information about the change.
*/
@Override
public void beforeDocumentChange(DocumentEvent event) {
public void beforeDocumentChange(@NotNull DocumentEvent event) {
}

/**
Expand All @@ -35,7 +36,7 @@ public void beforeDocumentChange(DocumentEvent event) {
* @param event the event containing the information about the change.
*/
@Override
public void documentChanged(DocumentEvent event) {
public void documentChanged(@NotNull DocumentEvent event) {
if (checkEnabled()) {
manager.documentChanged(event);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,38 +17,39 @@

import com.intellij.openapi.editor.event.EditorMouseEvent;
import com.intellij.openapi.editor.event.EditorMouseListener;
import org.jetbrains.annotations.NotNull;

/**
* An EditorMouseListener implementation which listens to mouseExited, mouseEntered and mouseClicked events.
*/
public class EditorMouseListenerImpl extends LSPListener implements EditorMouseListener {
@Override
public void mousePressed(EditorMouseEvent editorMouseEvent) {
public void mousePressed(@NotNull EditorMouseEvent editorMouseEvent) {

}

@Override
public void mouseClicked(EditorMouseEvent editorMouseEvent) {
public void mouseClicked(@NotNull EditorMouseEvent editorMouseEvent) {
if (checkEnabled()) {
manager.mouseClicked(editorMouseEvent);
}

}

@Override
public void mouseReleased(EditorMouseEvent editorMouseEvent) {
public void mouseReleased(@NotNull EditorMouseEvent editorMouseEvent) {

}

@Override
public void mouseEntered(EditorMouseEvent editorMouseEvent) {
public void mouseEntered(@NotNull EditorMouseEvent editorMouseEvent) {
if (checkEnabled()) {
manager.mouseEntered();
}
}

@Override
public void mouseExited(EditorMouseEvent editorMouseEvent) {
public void mouseExited(@NotNull EditorMouseEvent editorMouseEvent) {
if (checkEnabled()) {
manager.mouseExited();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,21 +17,22 @@

import com.intellij.openapi.editor.event.EditorMouseEvent;
import com.intellij.openapi.editor.event.EditorMouseMotionListener;
import org.jetbrains.annotations.NotNull;

/**
* Class listening for mouse movement in an editor (used for hover)
*/
public class EditorMouseMotionListenerImpl extends LSPListener implements EditorMouseMotionListener {

@Override
public void mouseMoved(EditorMouseEvent e) {
public void mouseMoved(@NotNull EditorMouseEvent e) {
if (checkEnabled()) {
manager.mouseMoved(e);
}
}

@Override
public void mouseDragged(EditorMouseEvent editorMouseEvent) {
public void mouseDragged(@NotNull EditorMouseEvent editorMouseEvent) {

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import com.intellij.openapi.diagnostic.Logger;
import com.intellij.openapi.editor.event.CaretEvent;
import com.intellij.openapi.editor.event.CaretListener;
import org.jetbrains.annotations.NotNull;

import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
Expand All @@ -26,8 +27,9 @@

public class LSPCaretListenerImpl extends LSPListener implements CaretListener {

private Logger LOG = Logger.getInstance(LSPCaretListenerImpl.class);
private ScheduledExecutorService scheduler;
private final Logger LOG = Logger.getInstance(LSPCaretListenerImpl.class);

private final ScheduledExecutorService scheduler;
private ScheduledFuture<?> scheduledFuture;
private static final long DEBOUNCE_INTERVAL_MS = 500;

Expand All @@ -37,7 +39,7 @@ public LSPCaretListenerImpl() {
}

@Override
public void caretPositionChanged(CaretEvent e) {
public void caretPositionChanged(@NotNull CaretEvent e) {
try {
if (scheduledFuture != null && !scheduledFuture.isCancelled()) {
scheduledFuture.cancel(false);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public void beforeAllDocumentsSaving() {
}

@Override
public void beforeFileContentReload(VirtualFile virtualFile, @NotNull Document document) {
public void beforeFileContentReload(@NotNull VirtualFile virtualFile, @NotNull Document document) {

}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@
import org.wso2.lsp4intellij.IntellijLanguageClient;
import org.wso2.lsp4intellij.client.languageserver.ServerStatus;
import org.wso2.lsp4intellij.client.languageserver.wrapper.LanguageServerWrapper;
import org.wso2.lsp4intellij.editor.EditorEventManager;
import org.wso2.lsp4intellij.editor.EditorEventManagerBase;
import org.wso2.lsp4intellij.utils.ApplicationUtils;
import org.wso2.lsp4intellij.utils.FileUtils;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
public class LSPTypedHandler extends TypedHandlerDelegate {

@Override
public Result charTyped(char c, Project project, @NotNull Editor editor, @NotNull PsiFile file) {
public @NotNull Result charTyped(char c, @NotNull Project project, @NotNull Editor editor, @NotNull PsiFile file) {
if (!FileUtils.isFileSupported(file.getVirtualFile())) {
return Result.CONTINUE;
}
Expand All @@ -44,7 +44,7 @@ public Result charTyped(char c, Project project, @NotNull Editor editor, @NotNul
}

@Override
public Result checkAutoPopup(char charTyped, @NotNull Project project, @NotNull Editor editor, @NotNull PsiFile file) {
public @NotNull Result checkAutoPopup(char charTyped, @NotNull Project project, @NotNull Editor editor, @NotNull PsiFile file) {
if (!FileUtils.isFileSupported(file.getVirtualFile())) {
return Result.CONTINUE;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
*/
public class HoverHandler {

private Logger LOG = Logger.getInstance(HoverHandler.class);
private final Logger LOG = Logger.getInstance(HoverHandler.class);

/**
* Returns the hover string corresponding to a Hover response
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/org/wso2/lsp4intellij/requests/Timeout.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
*/
public class Timeout {

private static Map<Timeouts, Integer> timeouts = new ConcurrentHashMap<>();
private static final Map<Timeouts, Integer> timeouts = new ConcurrentHashMap<>();

static {
Arrays.stream(Timeouts.values()).forEach(t -> timeouts.put(t, t.getDefaultTimeout()));
Expand All @@ -39,6 +39,6 @@ public static Map<Timeouts, Integer> getTimeouts() {
}

public static void setTimeouts(Map<Timeouts, Integer> loaded) {
loaded.forEach((t, v) -> timeouts.replace(t, v));
loaded.forEach(timeouts::replace);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,8 @@
* An Object handling WorkspaceEdits
*/
public class WorkspaceEditHandler {
private static Logger LOG = Logger.getInstance(WorkspaceEditHandler.class);

private static final Logger LOG = Logger.getInstance(WorkspaceEditHandler.class);

public static void applyEdit(PsiElement elem, String newName, UsageInfo[] infos,
RefactoringElementListener listener, List<VirtualFile> openedEditors) {
Expand All @@ -87,7 +88,7 @@ public static void applyEdit(PsiElement elem, String newName, UsageInfo[] infos,
} catch (MalformedURLException | URISyntaxException e) {
LOG.warn(e);
}
if (edits.keySet().contains(uri)) {
if (edits.containsKey(uri)) {
edits.get(uri).add(edit);
} else {
List<TextEdit> textEdits = new ArrayList<>();
Expand Down Expand Up @@ -188,9 +189,9 @@ public static boolean applyEdit(WorkspaceEdit edit, String name, List<VirtualFil
* @param edits The text edits
* @param uri The uri of the file
* @param version The version of the file
* @param openedEditors
* @param curProject
* @param name
* @param openedEditors The list of opened editors
* @param curProject The current project
* @param name The name of the edit
* @return The runnable containing the edits
*/
private static Runnable manageUnopenedEditor(List<TextEdit> edits, String uri, int version,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,7 @@ public boolean isAvailable(@NotNull Project project) {
}

@Override
public
StatusBarWidget createWidget(@NotNull Project project) {
public @NotNull StatusBarWidget createWidget(@NotNull Project project) {
return widgetForProject.computeIfAbsent(project, (k) -> new LSPServerStatusWidget(project));
}

Expand Down
4 changes: 1 addition & 3 deletions src/main/java/org/wso2/lsp4intellij/utils/FileUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,8 @@
import org.wso2.lsp4intellij.extensions.LSPExtensionManager;

import java.io.File;
import java.net.MalformedURLException;
import java.net.URI;
import java.net.URISyntaxException;
import java.net.URL;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
Expand Down Expand Up @@ -223,7 +221,7 @@ public static String sanitizeURI(String uri) {
if (os == OS.UNIX) {
return reconstructed.append(uriCp).toString();
} else {
reconstructed.append(uriCp.substring(0, uriCp.indexOf(URI_PATH_SEP)));
reconstructed.append(uriCp, 0, uriCp.indexOf(URI_PATH_SEP));
char driveLetter = reconstructed.charAt(URI_VALID_FILE_BEGIN.length());
if (Character.isLowerCase(driveLetter)) {
reconstructed.setCharAt(URI_VALID_FILE_BEGIN.length(), Character.toUpperCase(driveLetter));
Expand Down
6 changes: 3 additions & 3 deletions src/main/java/org/wso2/lsp4intellij/utils/GUIUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -150,9 +150,9 @@ public static Hint createAndShowEditorHint(Editor editor, String string, Point p
BrowserLauncher.getInstance().browse(e.getURL().toURI());
} else {
final Project project = editor.getProject();
Optional<? extends Pair<Project, VirtualFile>> fileToOpen = Optional.ofNullable(project).map(
p -> Optional.ofNullable(VfsUtil.findFileByURL(e.getURL()))
.map(f -> new ImmutablePair<>(p, f))).orElse(Optional.empty());
Optional<? extends Pair<Project, VirtualFile>> fileToOpen = Optional.ofNullable(project)
.flatMap(p -> Optional.ofNullable(VfsUtil.findFileByURL(e.getURL()))
.map(f -> new ImmutablePair<>(p, f)));

fileToOpen.ifPresent(f -> {
final OpenFileDescriptor descriptor = new OpenFileDescriptor(f.getLeft(), f.getRight());
Expand Down
6 changes: 1 addition & 5 deletions src/main/java/org/wso2/lsp4intellij/utils/Utils.java
Original file line number Diff line number Diff line change
Expand Up @@ -86,11 +86,7 @@ public static String[] parseArgs(String[] strArr) {
wasEscaped = false;
break;
case '\\':
if (wasEscaped) {
wasEscaped = false;
} else {
wasEscaped = true;
}
wasEscaped = !wasEscaped;
curStr.append('\\');
break;
case 'c':
Expand Down

0 comments on commit 0505245

Please sign in to comment.