Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ public static List<MainClassInfo> getMainClasses(List<Object> arguments, IProgre
}
}
}
IJavaSearchScope scope = SearchEngine.createJavaSearchScope(searchRoots.toArray(IJavaElement[]::new));
IJavaSearchScope scope = SearchEngine.createJavaSearchScope(searchRoots.toArray(new IJavaElement[0]));
SearchPattern pattern = SearchPattern.createPattern("main(String[]) void", IJavaSearchConstants.METHOD,
IJavaSearchConstants.DECLARATIONS, SearchPattern.R_EXACT_MATCH | SearchPattern.R_CASE_SENSITIVE);
SearchRequestor requestor = new SearchRequestor() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
package com.microsoft.jdtls.ext.core.model;

import java.net.URI;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
Expand Down Expand Up @@ -43,13 +45,6 @@
*/
public class PackageNode {

/**
* Nature Id for the IProject.
*/
private static final String NATURE_ID = "NatureId";

private static final String UNMANAGED_FOLDER_INNER_PATH = "UnmanagedFolderInnerPath";

public static final String K_TYPE_KIND = "TypeKind";

/**
Expand All @@ -67,15 +62,26 @@ public class PackageNode {
*/
public static final int K_ENUM = 3;

public static final String REFERENCED_LIBRARIES_PATH = "REFERENCED_LIBRARIES_PATH";
private static final String REFERENCED_LIBRARIES_CONTAINER_NAME = "Referenced Libraries";
private static final String IMMUTABLE_REFERENCED_LIBRARIES_CONTAINER_NAME = "Referenced Libraries (Read-only)";

public static final String REFERENCED_LIBRARIES_PATH = "REFERENCED_LIBRARIES_PATH";
public static final ContainerNode REFERENCED_LIBRARIES_CONTAINER = new ContainerNode(REFERENCED_LIBRARIES_CONTAINER_NAME, REFERENCED_LIBRARIES_PATH,
NodeKind.CONTAINER, IClasspathEntry.CPE_CONTAINER);
public static final ContainerNode IMMUTABLE_REFERENCED_LIBRARIES_CONTAINER = new ContainerNode(IMMUTABLE_REFERENCED_LIBRARIES_CONTAINER_NAME,
REFERENCED_LIBRARIES_PATH, NodeKind.CONTAINER, IClasspathEntry.CPE_CONTAINER);

/**
* Nature Id for the IProject.
*/
private static final String NATURE_ID = "NatureId";

private static final String UNMANAGED_FOLDER_INNER_PATH = "UnmanagedFolderInnerPath";

/**
* Nature Id for the unmanaged folder.
*/
private static final String UNMANAGED_FOLDER_NATURE_ID = "org.eclipse.jdt.ls.core.unmanagedFolder";

/**
* The name of the PackageNode.
*/
Expand Down Expand Up @@ -158,10 +164,12 @@ public static PackageNode createNodeForProject(IJavaElement javaElement) {
PackageNode projectNode = new PackageNode(proj.getName(), proj.getFullPath().toPortableString(), NodeKind.PROJECT);
projectNode.setUri(ProjectUtils.getProjectRealFolder(proj).toFile().toURI().toString());
try {
projectNode.setMetaDataValue(NATURE_ID, proj.getDescription().getNatureIds());
List<String> natureIds = new ArrayList<>(Arrays.asList(proj.getDescription().getNatureIds()));
if (!ProjectUtils.isVisibleProject(proj)) {
natureIds.add(UNMANAGED_FOLDER_NATURE_ID);
projectNode.setMetaDataValue(UNMANAGED_FOLDER_INNER_PATH, proj.getLocationURI().toString());
}
projectNode.setMetaDataValue(NATURE_ID, natureIds);
} catch (CoreException e) {
// do nothing
}
Expand Down
4 changes: 4 additions & 0 deletions src/views/projectNode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,8 @@ function getProjectType(natureId: string): string {
return ReadableNature.Maven;
case NatureId.Gradle:
return ReadableNature.Gradle;
case NatureId.UnmanagedFolder:
return ReadableNature.UnmanagedFolder;
default:
return "";
}
Expand All @@ -160,12 +162,14 @@ function getProjectType(natureId: string): string {
enum NatureId {
Maven = "org.eclipse.m2e.core.maven2Nature",
Gradle = "org.eclipse.buildship.core.gradleprojectnature",
UnmanagedFolder = "org.eclipse.jdt.ls.core.unmanagedFolder",
Java = "org.eclipse.jdt.core.javanature",
}

enum ReadableNature {
Maven = "maven",
Gradle = "gradle",
UnmanagedFolder = "unmanagedFolder",
Java = "java",
}

Expand Down
16 changes: 15 additions & 1 deletion test/suite/contextValue.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,11 @@ suite("Context Value Tests", () => {
assert.ok(/java:project(?=.*?\b\+java\b)(?=.*?\b\+gradle\b)(?=.*?\b\+uri\b)/.test((await gradleProject.getTreeItem()).contextValue || ""));
});

test("test unmanaged folder node", async function() {
assert.ok(/java:project(?=.*?\b\+java\b)(?=.*?\b\+unmanagedFolder\b)(?=.*?\b\+uri\b)/
.test((await unmanagedFolder.getTreeItem()).contextValue || ""));
});

test("test JRE container node", async function() {
assert.ok(/java:container(?=.*?\b\+jre\b)(?=.*?\b\+uri\b)/.test((await jreContainer.getTreeItem()).contextValue || ""));
});
Expand Down Expand Up @@ -70,7 +75,7 @@ suite("Context Value Tests", () => {
assert.ok(/java:package(?=.*?\b\+source\b)(?=.*?\b\+uri\b)/.test((await sourcePackage.getTreeItem()).contextValue || ""));
});

test("test source package node", async function() {
test("test source(test) package node", async function() {
assert.ok(/java:package(?=.*?\b\+source\b)(?=.*?\b\+test\b)(?=.*?\b\+uri\b)/
.test((await testSourcePackage.getTreeItem()).contextValue || ""));
});
Expand Down Expand Up @@ -129,6 +134,15 @@ const gradleProject: ProjectNode = new ProjectNode({
},
}, workspace);

const unmanagedFolder: ProjectNode = new ProjectNode({
name: "unmanagedFolder",
uri: Uri.file(__dirname).toString(),
kind: NodeKind.Project,
metaData: {
NatureId: ["org.eclipse.jdt.core.javanature", "org.eclipse.jdt.ls.core.unmanagedFolder"],
},
}, workspace);

const jreContainer: ContainerNode = new ContainerNode({
name: "jreContainer",
uri: Uri.file(__dirname).toString(),
Expand Down