Skip to content

Commit b3c8565

Browse files
authored
fix: Show 'module-info.java' at source roots (#745)
1 parent e5565db commit b3c8565

File tree

8 files changed

+53
-16
lines changed

8 files changed

+53
-16
lines changed

CHANGELOG.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,14 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
77
## 0.22.0
88
### Added
99
- Display non-Java files in Java Projects explorer. [#145](https://github.com/microsoft/vscode-java-dependency/issues/145)
10-
- Show non Java Projects in the Java Projects explorer. [#736](https://github.com/microsoft/vscode-java-dependency/issues/736)
10+
- Show non Java projects in the Java Projects explorer. [#736](https://github.com/microsoft/vscode-java-dependency/issues/736)
1111
- Support creating files and folders in Java Projects explorer. [#598](https://github.com/microsoft/vscode-java-dependency/issues/598)
1212
- Apply file decorators to project level. [#481](https://github.com/microsoft/vscode-java-dependency/issues/481)
1313
- Give more hints about the project import status. [#580](https://github.com/microsoft/vscode-java-dependency/issues/580)
1414
### Fixed
1515
- Apply `files.exclude` to Java Projects explorer. [#214](https://github.com/microsoft/vscode-java-dependency/issues/214)
16+
- Empty packages will not appear sometimes. [#600](https://github.com/microsoft/vscode-java-dependency/issues/600)
17+
- Show `module-info.java` at source roots. [698](https://github.com/microsoft/vscode-java-dependency/issues/698)
1618

1719
## 0.21.2
1820
### Fixed

jdtls.ext/com.microsoft.jdtls.ext.core/src/com/microsoft/jdtls/ext/core/PackageCommand.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -540,9 +540,10 @@ public static List<Object> getPackageFragmentRootContent(IPackageFragmentRoot ro
540540

541541
IModuleDescription moduleDescription = root.getModuleDescription();
542542
if (moduleDescription != null) {
543-
IClassFile moduleInfo = moduleDescription.getClassFile();
544-
if (moduleInfo != null) {
543+
if (moduleDescription.getClassFile() != null) {
545544
result.add(moduleDescription.getClassFile());
545+
} else if (moduleDescription.getCompilationUnit() != null) {
546+
result.add(moduleDescription.getCompilationUnit());
546547
}
547548
}
548549
return result;

jdtls.ext/com.microsoft.jdtls.ext.core/src/com/microsoft/jdtls/ext/core/parser/JavaResourceVisitor.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
import org.eclipse.core.resources.IFolder;
1919
import org.eclipse.jdt.core.IClassFile;
2020
import org.eclipse.jdt.core.IClasspathEntry;
21+
import org.eclipse.jdt.core.ICompilationUnit;
2122
import org.eclipse.jdt.core.IJarEntryResource;
2223
import org.eclipse.jdt.core.IJavaProject;
2324
import org.eclipse.jdt.core.IPackageFragment;
@@ -58,6 +59,13 @@ public void visit(IClassFile classFile) {
5859
this.nodes.add(node);
5960
}
6061

62+
@Override
63+
public void visit(ICompilationUnit compilationUnit) {
64+
PackageNode node = new PackageNode(compilationUnit.getElementName(), null, NodeKind.FILE);
65+
node.setUri(JDTUtils.toUri(compilationUnit));
66+
this.nodes.add(node);
67+
}
68+
6169
@Override
6270
public void visit(IFile file) {
6371
this.nodes.add(PackageNode.createNodeForFile(file));

jdtls.ext/com.microsoft.jdtls.ext.core/src/com/microsoft/jdtls/ext/core/parser/ResourceSet.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
import org.eclipse.core.runtime.NullProgressMonitor;
2626
import org.eclipse.jdt.core.IClassFile;
2727
import org.eclipse.jdt.core.IClasspathEntry;
28+
import org.eclipse.jdt.core.ICompilationUnit;
2829
import org.eclipse.jdt.core.IJarEntryResource;
2930
import org.eclipse.jdt.core.IJavaProject;
3031
import org.eclipse.jdt.core.IPackageFragment;
@@ -101,6 +102,8 @@ public void accept(ResourceVisitor visitor) {
101102
visitor.visit((IType) resource);
102103
} else if (resource instanceof IClassFile) {
103104
visitor.visit((IClassFile) resource);
105+
} else if (resource instanceof ICompilationUnit) {
106+
visitor.visit((ICompilationUnit) resource);
104107
} else if (resource instanceof IFile) {
105108
if (shouldVisit((IFile) resource)) {
106109
visitor.visit((IFile) resource);

jdtls.ext/com.microsoft.jdtls.ext.core/src/com/microsoft/jdtls/ext/core/parser/ResourceVisitor.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
import org.eclipse.core.resources.IFolder;
1818
import org.eclipse.jdt.core.IClassFile;
1919
import org.eclipse.jdt.core.IClasspathEntry;
20+
import org.eclipse.jdt.core.ICompilationUnit;
2021
import org.eclipse.jdt.core.IJarEntryResource;
2122
import org.eclipse.jdt.core.IPackageFragment;
2223
import org.eclipse.jdt.core.IPackageFragmentRoot;
@@ -40,6 +41,8 @@ public interface ResourceVisitor {
4041

4142
void visit(IClassFile classFile);
4243

44+
void visit(ICompilationUnit compilationUnit);
45+
4346
void visit(IFile file);
4447

4548
void visit(IFolder folder);

test/maven-suite/projectView.test.ts

Lines changed: 25 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -33,11 +33,14 @@ suite("Maven Project View Tests", () => {
3333
const mainPackage = projectChildren[0] as PackageRootNode;
3434
assert.equal(mainPackage.name, "src/main/java", "Package name should be \"src/main/java\"");
3535

36-
const primarySubPackages = await mainPackage.getChildren();
37-
assert.equal(primarySubPackages.length, 1, "Number of primary subpackages should be 1");
38-
const primarySubPackage = primarySubPackages[0] as PackageNode;
36+
const mainSourceSetChildren = await mainPackage.getChildren();
37+
assert.equal(mainSourceSetChildren.length, 2, "Number of primary subpackages should be 2");
38+
const primarySubPackage = mainSourceSetChildren[0] as DataNode;
3939
assert.equal(primarySubPackage.name, "com.mycompany", "Name of primary subpackage should be \"com.mycompany\"");
4040

41+
const moduleInfo = mainSourceSetChildren[1] as DataNode;
42+
assert.equal(moduleInfo.name, "module-info.java");
43+
4144
const secondarySubPackages = await primarySubPackage.getChildren();
4245
assert.equal(secondarySubPackages.length, 2, "Number of secondary subpackages should be 1");
4346
const firstSecondarySubPackage = secondarySubPackages[0] as PackageNode;
@@ -85,15 +88,23 @@ suite("Maven Project View Tests", () => {
8588
assert.equal(mavenDependency.name, "Maven Dependencies", "Container name should be \"Maven Dependencies\"");
8689

8790
// validate package nodes
88-
const mainSubPackages = await mainPackage.getChildren();
89-
const testSubPackages = await testPackage.getChildren();
90-
assert.equal(mainSubPackages.length, 2, "Number of main sub packages should be 2");
91-
assert.equal(testSubPackages.length, 1, "Number of test sub packages should be 1");
92-
const firstMainSubPackage = mainSubPackages[0] as PackageNode;
93-
const secondMainSubPackage = mainSubPackages[1] as PackageNode;
94-
const testSubPackage = testSubPackages[0] as PackageNode;
91+
const mainSourceSetChildren = await mainPackage.getChildren();
92+
assert.equal(mainSourceSetChildren.length, 3, "Number of main source set children should be 3");
93+
94+
const firstMainSubPackage = mainSourceSetChildren[0] as DataNode;
9595
assert.equal(firstMainSubPackage.name, "com.mycompany.app", "Name of first main subpackage should be \"com.mycompany.app\"");
96+
97+
const secondMainSubPackage = mainSourceSetChildren[1] as DataNode;
9698
assert.equal(secondMainSubPackage.name, "com.mycompany.app1", "Name of second main subpackage should be \"com.mycompany.app1\"");
99+
100+
const moduleInfo = mainSourceSetChildren[2] as DataNode;
101+
assert.equal(moduleInfo.name, "module-info.java");
102+
103+
const testSourceSetChildren = await testPackage.getChildren();
104+
assert.equal(testSourceSetChildren.length, 1, "Number of test sub packages should be 1");
105+
const testSubPackage = testSourceSetChildren[0] as PackageNode;
106+
107+
97108
assert.equal(testSubPackage.name, "com.mycompany.app", "Name of test subpackage should be \"com.mycompany.app\"");
98109

99110
// validate innermost layer nodes
@@ -195,9 +206,10 @@ suite("Maven Project View Tests", () => {
195206
path: mainPackage.nodeData.name,
196207
handlerIdentifier: mainPackage.nodeData.handlerIdentifier,
197208
});
198-
assert.equal(packages?.length, 2, "packages' length should be 2");
199-
assert.equal(packages![0].name, "com.mycompany.app", "package[0]'s name should be com.mycompany.app");
200-
assert.equal(packages![1].name, "com.mycompany.app1", "package[1]'s name should be com.mycompany.app1");
209+
assert.equal(packages?.length, 3, "packages' length should be 3");
210+
assert.equal(packages![0].name, "com.mycompany.app");
211+
assert.equal(packages![1].name, "com.mycompany.app1");
212+
assert.equal(packages![2].name, "module-info.java");
201213
});
202214

203215
test("Can execute command java.resolvePath correctly", async function() {

test/maven/pom.xml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@
77
<version>1.0-SNAPSHOT</version>
88
<name>my-app</name>
99
<url>http://maven.apache.org</url>
10+
<properties>
11+
<maven.compiler.target>17</maven.compiler.target>
12+
<maven.compiler.source>17</maven.compiler.source>
13+
</properties>
1014
<dependencies>
1115
<dependency>
1216
<groupId>junit</groupId>
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
module my.app {
2+
exports com.mycompany.app1;
3+
exports com.mycompany.app;
4+
}

0 commit comments

Comments
 (0)