Skip to content

Commit

Permalink
tidy: fix linter warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
acke committed Jan 30, 2025
1 parent 716313d commit fff3029
Show file tree
Hide file tree
Showing 7 changed files with 27 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import java.util.ArrayList;
import java.util.List;
import java.util.Queue;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ConcurrentLinkedQueue;
import java.util.function.Consumer;
Expand All @@ -17,7 +18,7 @@
*/
public class TaskProcessor {
// left = taskToExecute, right = callback function
private final ConcurrentLinkedQueue<Pair<Consumer<SnykExtendedLanguageClient>, Consumer<Void>>> taskQueue = new ConcurrentLinkedQueue<>();
private final Queue<Pair<Consumer<SnykExtendedLanguageClient>, Consumer<Void>>> taskQueue = new ConcurrentLinkedQueue<>();

private TaskProcessor() {
CompletableFuture.runAsync(() -> {
Expand All @@ -39,6 +40,8 @@ public static TaskProcessor getInstance() {
}

private void start() {
final List<Pair<Consumer<SnykExtendedLanguageClient>, Consumer<Void>>> copyForSending = new ArrayList<>();

while (true) {
String authToken = Preferences.getInstance().getAuthToken();
SnykExtendedLanguageClient lc = SnykExtendedLanguageClient.getInstance();
Expand All @@ -50,8 +53,9 @@ private void start() {
}
continue;
}
List<Pair<Consumer<SnykExtendedLanguageClient>, Consumer<Void>>> copyForSending = new ArrayList<>(
taskQueue);

copyForSending.clear(); // Clear the list before reuse
copyForSending.addAll(taskQueue); // Add all elements from taskQueue

for (Pair<Consumer<SnykExtendedLanguageClient>, Consumer<Void>> event : copyForSending) {
try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -161,14 +161,16 @@ public String getSummaryInitHtml() {
if (logger == null) {
logger = Platform.getLog(getClass());
}
StringBuilder content = new StringBuilder();

StringBuilder content = new StringBuilder();
try (InputStream inputStream = getClass().getResourceAsStream("/ui/html/ScanSummaryInit.html");
BufferedReader reader = new BufferedReader(new InputStreamReader(inputStream))) {

String line;
while ((line = reader.readLine()) != null) {
content.append(line).append("\n");
String line = reader.readLine();
while (line != null) {
// Process the line here
content.append(line).append(System.lineSeparator());
line = reader.readLine();
}
} catch (IOException e) {
SnykLogger.logError(e);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public class BaseBranchDialog {
public BaseBranchDialog() {
}

public void open(Display display, Path projectPath, String[] localBranches) {
public void open(Display display, Path projectPath, String... localBranches) {
Shell shell = new Shell(display, SWT.APPLICATION_MODAL | SWT.DIALOG_TRIM);
shell.setText("Choose base branch for net-new issues scanning");
shell.setLayout(new GridLayout(1, false));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@

@SuppressWarnings("restriction")
public class BrowserHandler {
private static final int validNumberOfArguments = 5;
private Browser browser;
private String initScript = "";

Expand All @@ -45,7 +46,7 @@ public void initialize() {
new BrowserFunction(browser, "openInEditor") {
@Override
public Object function(Object[] arguments) {
if (arguments.length != 5) {
if (arguments.length != validNumberOfArguments) {
return null;
}
String filePath = (String) arguments[0];
Expand Down Expand Up @@ -165,7 +166,7 @@ public CompletableFuture<Void> updateBrowserContent(TreeNode node) {
}

private BaseHtmlProvider getHtmlProvider(TreeNode node) {
var product = "";
String product;
if (node instanceof IssueTreeNode) {
product = ((ProductTreeNode) node.getParent().getParent()).getProduct();
} else if (node instanceof ProductTreeNode) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,15 @@ public Object execute(ExecutionEvent event) throws ExecutionException {

String commandId = event.getCommand().getId();

switch (commandId) {
case "io.snyk.eclipse.plugin.commands.TreeCollapse":
String treeCollapse = "io.snyk.eclipse.plugin.commands.TreeCollapse";
String treeExpand = "io.snyk.eclipse.plugin.commands.TreeExpand";

if (commandId.equals(treeCollapse)) {
SnykStartup.getView().getTreeViewer().collapseAll();
break;
case "io.snyk.eclipse.plugin.commands.TreeExpand":
} else if (commandId.equals(treeExpand)) {
SnykStartup.getView().getTreeViewer().expandAll();
break;
}

return null;
}
}
}
3 changes: 2 additions & 1 deletion plugin/src/main/java/io/snyk/languageserver/ScanState.java
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
package io.snyk.languageserver;

import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

public class ScanState {
private ScanState() {

}

private final ConcurrentHashMap<ScanInProgressKey, Boolean> scanInProgress = new ConcurrentHashMap<>();
private final Map<ScanInProgressKey, Boolean> scanInProgress = new ConcurrentHashMap<>();

private static ScanState instance = new ScanState();
public static ScanState getInstance() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -367,7 +367,7 @@ public void snykScan(SnykScanParam param) {
for (ProductTreeNode productTreeNode : affectedProductTreeNodes) {
this.toolView.resetNode(productTreeNode);
addInfoNodes(productTreeNode, param.getFolderPath(), issueCache);
populateFileAndIssueNodes(productTreeNode, param.getFolderPath(), issueCache);
populateFileAndIssueNodes(productTreeNode, issueCache);
}
break;
case SCAN_STATE_ERROR:
Expand Down Expand Up @@ -535,7 +535,7 @@ public void publishDiagnostics316(PublishDiagnostics316Param param) {
populateIssueCache(param, filePath);
}

private void populateFileAndIssueNodes(ProductTreeNode productTreeNode, String folderPath,
private void populateFileAndIssueNodes(ProductTreeNode productTreeNode,
SnykIssueCache issueCache) {
var cacheHashMap = issueCache.getCacheByDisplayProduct(productTreeNode.getProduct());
for (var kv : cacheHashMap.entrySet()) {
Expand Down

0 comments on commit fff3029

Please sign in to comment.