Skip to content

Commit 3ab0189

Browse files
authored
Merge branch 'main' into bug-fix-182
2 parents cfbe34a + 60a20d0 commit 3ab0189

File tree

5 files changed

+138
-1
lines changed

5 files changed

+138
-1
lines changed

README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,10 @@ If the system does not detect any JDK, the extension will offer a downloader and
7979
Alternatively, you can manually specify the path to JDK binaries by utilizing the JDK downloader.
8080
You can also access the JDK downloader through the "Download, install, and Use JDK" option in the command palette.
8181
![JDK Downloader](vscode/images/jdk_downloader.png)
82+
## Enabling Java Preview Features
83+
When using preview features use the quick fix action option to easily enable them.
8284

85+
![Enable Preview](vscode/images/enable_preview.gif)
8386
## Supported Refactorings
8487

8588
Class level refactorings as well as variable refactorings are supported in VSCode via Oracle Java Platform extension. See following screenshots:

build.xml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,8 @@
4343
patches/7491-preliminary.diff
4444
patches/7548_source-1.8.diff
4545
patches/7583_source-1.8.diff
46-
patches/7621.diff
46+
patches/7610.diff
47+
patches/7621.diff
4748
patches/7654.diff
4849
patches/mvn-sh.diff
4950
patches/generate-dependencies.diff

patches/7610.diff

Lines changed: 130 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,130 @@
1+
diff --git a/java/java.lsp.server/src/org/netbeans/modules/java/lsp/server/singlesourcefile/SingleFileOptionsQueryImpl.java b/java/java.lsp.server/src/org/netbeans/modules/java/lsp/server/singlesourcefile/SingleFileOptionsQueryImpl.java
2+
index da4898786f11..2e0e5a3aa4e6 100644
3+
--- a/java/java.lsp.server/src/org/netbeans/modules/java/lsp/server/singlesourcefile/SingleFileOptionsQueryImpl.java
4+
+++ b/java/java.lsp.server/src/org/netbeans/modules/java/lsp/server/singlesourcefile/SingleFileOptionsQueryImpl.java
5+
@@ -20,10 +20,11 @@
6+
7+
import java.io.File;
8+
import java.net.URI;
9+
+import java.util.ArrayList;
10+
import java.util.HashMap;
11+
+import java.util.List;
12+
import java.util.Map;
13+
import java.util.Objects;
14+
-import java.util.Set;
15+
import java.util.WeakHashMap;
16+
import javax.swing.event.ChangeEvent;
17+
import javax.swing.event.ChangeListener;
18+
@@ -54,19 +55,37 @@ public Result optionsFor(FileObject file) {
19+
if (workspaceFolder != null) {
20+
return getResult(workspace, workspaceFolder);
21+
} else {
22+
- Set<Workspace> workspaces;
23+
+ List<Workspace> workspaces;
24+
25+
synchronized (this) {
26+
- workspaces = workspace2Settings.keySet();
27+
+ workspaces = new ArrayList<>(workspace2Settings.keySet());
28+
}
29+
30+
+ int count = 0;
31+
for (Workspace w : workspaces) {
32+
+ if (w == null)
33+
+ continue; // Since a WeakHashMap is in use, it is possible to receive a null value.
34+
FileObject folder = findWorkspaceFolder(w, file);
35+
if (folder != null) {
36+
return getResult(w, folder);
37+
}
38+
+ if (count++ == 0 && workspace == null)
39+
+ workspace = w;
40+
}
41+
42+
+ if (count == 1) {
43+
+ // Since this is a single source file, associate it with the single open workspace,
44+
+ // even when it is not a descendant of one of the root folders.
45+
+ FileObject folder;
46+
+ if (file.isFolder()) {
47+
+ folder = file;
48+
+ } else {
49+
+ folder = file.getParent();
50+
+ if (folder == null)
51+
+ folder = file;
52+
+ }
53+
+ return getResult(workspace, folder);
54+
+ }
55+
return null;
56+
}
57+
}
58+
diff --git a/java/java.lsp.server/test/unit/src/org/netbeans/modules/java/lsp/server/singlesourcefile/SingleFileOptionsQueryImplTest.java b/java/java.lsp.server/test/unit/src/org/netbeans/modules/java/lsp/server/singlesourcefile/SingleFileOptionsQueryImplTest.java
59+
index 4c6d3c812f3a..a61ea98d7a24 100644
60+
--- a/java/java.lsp.server/test/unit/src/org/netbeans/modules/java/lsp/server/singlesourcefile/SingleFileOptionsQueryImplTest.java
61+
+++ b/java/java.lsp.server/test/unit/src/org/netbeans/modules/java/lsp/server/singlesourcefile/SingleFileOptionsQueryImplTest.java
62+
@@ -19,6 +19,7 @@
63+
package org.netbeans.modules.java.lsp.server.singlesourcefile;
64+
65+
import java.util.Arrays;
66+
+import java.util.Collections;
67+
import java.util.List;
68+
import java.util.concurrent.atomic.AtomicInteger;
69+
import org.netbeans.junit.NbTestCase;
70+
@@ -58,6 +59,17 @@ public void testFindWorkspaceFolder() throws Exception {
71+
assertEquals(workspace2, SingleFileOptionsQueryImpl.findWorkspaceFolder(workspace, source2));
72+
assertEquals(workspace2, SingleFileOptionsQueryImpl.findWorkspaceFolder(workspace, source2.getParent()));
73+
assertEquals(workspace2, SingleFileOptionsQueryImpl.findWorkspaceFolder(workspace, source2.getParent().getParent()));
74+
+
75+
+ FileObject singleSourceDir = FileUtil.createFolder(wd, "standalone");
76+
+ FileObject singleSourceFile = FileUtil.createData(singleSourceDir, "Test.java");
77+
+
78+
+ assertNull(SingleFileOptionsQueryImpl.findWorkspaceFolder(workspace, singleSourceFile));
79+
+ assertNull(SingleFileOptionsQueryImpl.findWorkspaceFolder(workspace, singleSourceDir));
80+
+
81+
+ Workspace emptyWorkspace = new WorkspaceImpl(Collections.emptyList());
82+
+
83+
+ assertNull(SingleFileOptionsQueryImpl.findWorkspaceFolder(emptyWorkspace, singleSourceFile));
84+
+ assertNull(SingleFileOptionsQueryImpl.findWorkspaceFolder(emptyWorkspace, singleSourceDir));
85+
}
86+
87+
public void testWorkspaceOptions() throws Exception {
88+
@@ -84,6 +96,17 @@ public void testWorkspaceOptions() throws Exception {
89+
assertEquals("-Dtest=test", query.optionsFor(source2.getParent()).getOptions());
90+
assertEquals(workspace2.toURI(), query.optionsFor(source2.getParent()).getWorkDirectory());
91+
92+
+ assertNotNull(query.optionsFor(source3));
93+
+ assertEquals("-Dtest=test", query.optionsFor(source3).getOptions());
94+
+ assertEquals(source3.getParent().toURI(), query.optionsFor(source3).getWorkDirectory());
95+
+
96+
+ assertNotNull(query.optionsFor(source3.getParent()));
97+
+ assertEquals("-Dtest=test", query.optionsFor(source3.getParent()).getOptions());
98+
+ assertEquals(source3.getParent().toURI(), query.optionsFor(source3.getParent()).getWorkDirectory());
99+
+
100+
+ assertEquals(query.optionsFor(source3), query.optionsFor(source3.getParent()));
101+
+ assertNull(query.optionsFor(wd));
102+
+
103+
AtomicInteger changeCount = new AtomicInteger();
104+
105+
query.optionsFor(source1).addChangeListener(evt -> changeCount.incrementAndGet());
106+
@@ -149,6 +172,24 @@ public void testWorkspaceOptions() throws Exception {
107+
assertEquals("-Dtest=test2", query.optionsFor(source2.getParent()).getOptions());
108+
assertEquals(workspace2.toURI(), query.optionsFor(source2.getParent()).getWorkDirectory());
109+
110+
+ assertNotNull(query.optionsFor(source3));
111+
+ assertEquals("-Dtest=test2", query.optionsFor(source3).getOptions());
112+
+ assertEquals(source3.getParent().toURI(), query.optionsFor(source3).getWorkDirectory());
113+
+ assertNotNull(query.optionsFor(source3.getParent()));
114+
+ assertEquals("-Dtest=test2", query.optionsFor(source3.getParent()).getOptions());
115+
+ assertEquals(source3.getParent().toURI(), query.optionsFor(source3.getParent()).getWorkDirectory());
116+
+ assertEquals(query.optionsFor(source3), query.optionsFor(source3.getParent()));
117+
+
118+
+ // with multiple open workspaces:
119+
+ Workspace emptyWorkspace = new WorkspaceImpl(Collections.emptyList());
120+
+ query.setConfiguration(emptyWorkspace, "-Dtest=empty", null);
121+
+
122+
+ assertEquals("-Dtest=test2", query.optionsFor(source1).getOptions());
123+
+ assertEquals(workspace1.toURI(), query.optionsFor(source1).getWorkDirectory());
124+
+
125+
+ assertEquals("-Dtest=test2", query.optionsFor(source2).getOptions());
126+
+ assertEquals(workspace2.toURI(), query.optionsFor(source2).getWorkDirectory());
127+
+
128+
assertNull(query.optionsFor(source3));
129+
assertNull(query.optionsFor(source3.getParent()));
130+
}

vscode/README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,10 @@ If the system does not detect any JDK, the extension will offer a downloader and
7474
Alternatively, you can manually specify the path to JDK binaries by utilizing the JDK downloader.
7575
You can also access the JDK downloader through the "Download, install, and Use JDK" option in the command palette.
7676
![JDK Downloader](images/jdk_downloader.png)
77+
## Enabling Java Preview Features
78+
When using preview features use the quick fix action option to easily enable them.
7779

80+
![Enable Preview](images/enable_preview.gif)
7881
## Supported Refactorings
7982

8083
Class level refactorings as well as variable refactorings are supported in VS Code via Oracle Java Platform extension. See following screenshots:

vscode/images/enable_preview.gif

61.1 KB
Loading

0 commit comments

Comments
 (0)