Skip to content
Merged
Show file tree
Hide file tree
Changes from 6 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 @@ -36,6 +36,8 @@
import org.eclipse.jdt.core.IType;
import org.eclipse.jdt.core.JavaCore;
import org.eclipse.jdt.core.JavaModelException;
import org.eclipse.jdt.internal.compiler.classfmt.ClassFileConstants;
import org.eclipse.jdt.internal.compiler.impl.CompilerOptions;
import org.eclipse.jdt.internal.core.JrtPackageFragmentRoot;
import org.eclipse.jdt.ls.core.internal.JDTUtils;
import org.eclipse.jdt.ls.core.internal.ProjectUtils;
Expand Down Expand Up @@ -68,9 +70,11 @@ public class PackageNode {
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 ContainerNode REFERENCED_LIBRARIES_CONTAINER = new ContainerNode(REFERENCED_LIBRARIES_CONTAINER_NAME, 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,
public static final ContainerNode IMMUTABLE_REFERENCED_LIBRARIES_CONTAINER = new ContainerNode(
IMMUTABLE_REFERENCED_LIBRARIES_CONTAINER_NAME,
REFERENCED_LIBRARIES_PATH, NodeKind.CONTAINER, IClasspathEntry.CPE_CONTAINER);

/**
Expand All @@ -85,6 +89,8 @@ public class PackageNode {
*/
private static final String UNMANAGED_FOLDER_NATURE_ID = "org.eclipse.jdt.ls.core.unmanagedFolder";

private static final String MAX_SOURCE_VERSION = "MaxSourceVersion";

/**
* The name of the PackageNode.
*/
Expand Down Expand Up @@ -164,7 +170,8 @@ public static PackageNode createNodeForProject(IJavaElement javaElement) {
return null;
}
IProject proj = javaElement.getJavaProject().getProject();
PackageNode projectNode = new PackageNode(proj.getName(), proj.getFullPath().toPortableString(), NodeKind.PROJECT);
PackageNode projectNode = new PackageNode(proj.getName(), proj.getFullPath().toPortableString(),
NodeKind.PROJECT);
projectNode.setUri(ProjectUtils.getProjectRealFolder(proj).toFile().toURI().toString());
try {
List<String> natureIds = new ArrayList<>(Arrays.asList(proj.getDescription().getNatureIds()));
Expand All @@ -173,6 +180,10 @@ public static PackageNode createNodeForProject(IJavaElement javaElement) {
projectNode.setMetaDataValue(UNMANAGED_FOLDER_INNER_PATH, proj.getLocationURI().toString());
}
projectNode.setMetaDataValue(NATURE_ID, natureIds);
String sourceVersion = javaElement.getJavaProject().getOption(JavaCore.COMPILER_SOURCE, true);
int jdkLevel = (int) (CompilerOptions.versionToJdkLevel(sourceVersion, true) >>> 16);
int majorVersion = Math.max(0, jdkLevel - ClassFileConstants.MAJOR_VERSION_0);
projectNode.setMetaDataValue(MAX_SOURCE_VERSION, majorVersion);
} catch (CoreException e) {
// do nothing
}
Expand Down Expand Up @@ -201,7 +212,8 @@ public static PackageNode createNodeForResource(IResource resource) {
}

public static PackageNode createNodeForPackageFragment(IPackageFragment packageFragment) {
PackageNode fragmentNode = new PackageNode(packageFragment.getElementName(), packageFragment.getPath().toPortableString(), NodeKind.PACKAGE);
PackageNode fragmentNode = new PackageNode(packageFragment.getElementName(),
packageFragment.getPath().toPortableString(), NodeKind.PACKAGE);
fragmentNode.setHandlerIdentifier(packageFragment.getHandleIdentifier());
if (packageFragment.getResource() != null) {
fragmentNode.setUri(packageFragment.getResource().getLocationURI().toString());
Expand All @@ -215,16 +227,19 @@ public static PackageNode createNodeForVirtualContainer(IPackageFragmentRoot pkg
IClasspathEntry entry = pkgRoot.getRawClasspathEntry();
IClasspathContainer container = JavaCore.getClasspathContainer(entry.getPath(), pkgRoot.getJavaProject());
PackageNode containerNode = null;
if (entry.getEntryKind() == IClasspathEntry.CPE_LIBRARY || entry.getEntryKind() == IClasspathEntry.CPE_VARIABLE) {
if (entry.getEntryKind() == IClasspathEntry.CPE_LIBRARY
|| entry.getEntryKind() == IClasspathEntry.CPE_VARIABLE) {
containerNode = REFERENCED_LIBRARIES_CONTAINER;
} else {
containerNode = new ContainerNode(container.getDescription(), container.getPath().toPortableString(), NodeKind.CONTAINER, entry.getEntryKind());
containerNode = new ContainerNode(container.getDescription(), container.getPath().toPortableString(),
NodeKind.CONTAINER, entry.getEntryKind());
}
return containerNode;

}

public static PackageRootNode createNodeForPackageFragmentRoot(IPackageFragmentRoot pkgRoot) throws JavaModelException {
public static PackageRootNode createNodeForPackageFragmentRoot(IPackageFragmentRoot pkgRoot)
throws JavaModelException {
PackageRootNode node;
String displayName = pkgRoot.getElementName();
boolean isSourcePath = pkgRoot.getKind() == IPackageFragmentRoot.K_SOURCE;
Expand Down Expand Up @@ -271,14 +286,16 @@ public static PackageRootNode createNodeForPackageFragmentRoot(IPackageFragmentR
* Get the correspond node of classpath, it may be container or a package root.
*
* @param classpathEntry
* classpath entry
* classpath entry
* @param javaProject
* correspond java project
* correspond java project
* @param nodeKind
* could be CONTAINER or PACKAGEROOT(for referenced libraries)
* could be CONTAINER or PACKAGEROOT(for referenced
* libraries)
* @return correspond PackageNode of classpath entry
*/
public static PackageNode createNodeForClasspathEntry(IClasspathEntry classpathEntry, IJavaProject javaProject, NodeKind nodeKind) {
public static PackageNode createNodeForClasspathEntry(IClasspathEntry classpathEntry, IJavaProject javaProject,
NodeKind nodeKind) {
try {
IClasspathEntry entry = JavaCore.getResolvedClasspathEntry(classpathEntry);
IClasspathContainer container = JavaCore.getClasspathContainer(entry.getPath(), javaProject);
Expand All @@ -289,17 +306,18 @@ public static PackageNode createNodeForClasspathEntry(IClasspathEntry classpathE
if (container != null) {
PackageNode node = null;
if (nodeKind == NodeKind.CONTAINER) {
node = new ContainerNode(container.getDescription(), container.getPath().toPortableString(), nodeKind, entry.getEntryKind());
node = new ContainerNode(container.getDescription(), container.getPath().toPortableString(),
nodeKind, entry.getEntryKind());
final URI containerURI = ExtUtils.getContainerURI(javaProject, container);
node.setUri(containerURI != null ? containerURI.toString() : null);
} else if (nodeKind == NodeKind.PACKAGEROOT) { // ClasspathEntry for referenced jar files
// Use package name as package root name
String[] pathSegments = container.getPath().segments();
node = new PackageRootNode(
pathSegments[pathSegments.length - 1],
container.getPath().toPortableString(),
container.getPath().toFile().toURI().toString(),
nodeKind, IPackageFragmentRoot.K_BINARY);
pathSegments[pathSegments.length - 1],
container.getPath().toPortableString(),
container.getPath().toFile().toURI().toString(),
nodeKind, IPackageFragmentRoot.K_BINARY);
}
return node;
}
Expand All @@ -310,7 +328,8 @@ public static PackageNode createNodeForClasspathEntry(IClasspathEntry classpathE
}

public static PackageNode createNodeForPrimaryType(IType type) {
PackageNode primaryTypeNode = new PackageNode(type.getElementName(), type.getPath().toPortableString(), NodeKind.PRIMARYTYPE);
PackageNode primaryTypeNode = new PackageNode(type.getElementName(), type.getPath().toPortableString(),
NodeKind.PRIMARYTYPE);

try {
if (type.isEnum()) {
Expand All @@ -332,7 +351,7 @@ public static PackageNode createNodeForPrimaryType(IType type) {
* Get correspond node of referenced variable.
*
* @param classpathEntry
* referenced variable's classpath entry
* referenced variable's classpath entry
* @return correspond package node
*/
public static PackageRootNode createNodeForClasspathVariable(IClasspathEntry classpathEntry) {
Expand Down
17 changes: 17 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

76 changes: 76 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,36 @@
"category": "Java",
"icon": "$(add)"
},
{
"command": "java.view.package.newJavaInterface",
"title": "%contributes.commands.java.view.package.newJavaInterface%",
"category": "Java",
"icon": "$(add)"
},
{
"command": "java.view.package.newJavaEnum",
"title": "%contributes.commands.java.view.package.newJavaEnum%",
"category": "Java",
"icon": "$(add)"
},
{
"command": "java.view.package.newJavaRecord",
"title": "%contributes.commands.java.view.package.newJavaRecord%",
"category": "Java",
"icon": "$(add)"
},
{
"command": "java.view.package.newJavaAnnotation",
"title": "%contributes.commands.java.view.package.newJavaAnnotation%",
"category": "Java",
"icon": "$(add)"
},
{
"command": "java.view.package.newJavaAbstractClass",
"title": "%contributes.commands.java.view.package.newJavaAbstractClass%",
"category": "Java",
"icon": "$(add)"
},
{
"command": "java.view.package.newPackage",
"title": "%contributes.commands.java.view.package.newPackage%",
Expand Down Expand Up @@ -395,6 +425,26 @@
"command": "java.view.package.newJavaClass",
"when": "false"
},
{
"command": "java.view.package.newJavaInterface",
"when": "false"
},
{
"command": "java.view.package.newJavaEnum",
"when": "false"
},
{
"command": "java.view.package.newJavaRecord",
"when": "false"
},
{
"command": "java.view.package.newJavaAnnotation",
"when": "false"
},
{
"command": "java.view.package.newJavaAbstractClass",
"when": "false"
},
{
"command": "java.view.package.newPackage",
"when": "false"
Expand Down Expand Up @@ -644,6 +694,31 @@
"group": "new@10",
"when": "view == javaProjectExplorer && (viewItem =~ /java:(package|packageRoot)(?=.*?\\b\\+source\\b)/ || viewItem =~ /java:project(?=.*?\\b\\+java\\b)/ || viewItem =~ /java:type/)"
},
{
"command": "java.view.package.newJavaInterface",
"group": "new@11",
"when": "view == javaProjectExplorer && (viewItem =~ /java:(package|packageRoot)(?=.*?\\b\\+source\\b)/ || viewItem =~ /java:project(?=.*?\\b\\+java\\b)/ || viewItem =~ /java:type/)"
},
{
"command": "java.view.package.newJavaEnum",
"group": "new@12",
"when": "view == javaProjectExplorer && (viewItem =~ /java:(package|packageRoot)(?=.*?\\b\\+source\\b)/ || viewItem =~ /java:project(?=.*?\\b\\+java\\b)/ || viewItem =~ /java:type/)"
},
{
"command": "java.view.package.newJavaRecord",
"group": "new@13",
"when": "view == javaProjectExplorer && (viewItem =~ /java:(package|packageRoot)(?=.*?\\b\\+source\\b)/ || viewItem =~ /java:project(?=.*?\\b\\+java\\b)/ || viewItem =~ /java:type/) && viewItem =~ /java:.*\\+allowRecord\\b/"
},
{
"command": "java.view.package.newJavaAnnotation",
"group": "new@14",
"when": "view == javaProjectExplorer && (viewItem =~ /java:(package|packageRoot)(?=.*?\\b\\+source\\b)/ || viewItem =~ /java:project(?=.*?\\b\\+java\\b)/ || viewItem =~ /java:type/)"
},
{
"command": "java.view.package.newJavaAbstractClass",
"group": "new@15",
"when": "view == javaProjectExplorer && (viewItem =~ /java:(package|packageRoot)(?=.*?\\b\\+source\\b)/ || viewItem =~ /java:project(?=.*?\\b\\+java\\b)/ || viewItem =~ /java:type/)"
},
{
"command": "java.view.package.newPackage",
"group": "new@20",
Expand Down Expand Up @@ -895,6 +970,7 @@
},
"dependencies": {
"await-lock": "^2.2.2",
"fmtr": "^1.1.4",
"fs-extra": "^10.1.0",
"globby": "^13.1.3",
"lodash": "^4.17.21",
Expand Down
9 changes: 7 additions & 2 deletions package.nls.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,15 @@
"contributes.commands.java.view.package.copyFilePath": "Copy Path",
"contributes.commands.java.view.package.copyRelativeFilePath": "Copy Relative Path",
"contributes.commands.java.view.package.new": "New...",
"contributes.commands.java.view.package.newJavaClass": "Java Class...",
"contributes.commands.java.view.package.newJavaClass": "Class...",
"contributes.commands.java.view.package.newJavaInterface": "Interface...",
"contributes.commands.java.view.package.newJavaEnum": "Enum...",
"contributes.commands.java.view.package.newJavaRecord": "Record...",
"contributes.commands.java.view.package.newJavaAnnotation": "Annotation...",
"contributes.commands.java.view.package.newJavaAbstractClass": "Abstract Class...",
"contributes.commands.java.view.package.newPackage": "Package...",
"contributes.commands.java.view.package.newFile": "File...",
"contributes.commands.java.view.package.newFolder": "Folder",
"contributes.commands.java.view.package.newFolder": "Folder...",
"contributes.commands.java.view.package.renameFile": "Rename",
"contributes.commands.java.view.package.moveFileToTrash": "Delete",
"contributes.commands.java.view.package.deleteFilePermanently": "Delete Permanently",
Expand Down
9 changes: 7 additions & 2 deletions package.nls.zh-cn.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,15 @@
"contributes.commands.java.view.package.copyFilePath": "复制路径",
"contributes.commands.java.view.package.copyRelativeFilePath": "复制相对路径",
"contributes.commands.java.view.package.new": "创建...",
"contributes.commands.java.view.package.newJavaClass": "Java 类...",
"contributes.commands.java.view.package.newJavaClass": "类...",
"contributes.commands.java.view.package.newJavaInterface": "接口类型...",
"contributes.commands.java.view.package.newJavaEnum": "枚举类型...",
"contributes.commands.java.view.package.newJavaRecord": "记录类型...",
"contributes.commands.java.view.package.newJavaAnnotation": "注解类型...",
"contributes.commands.java.view.package.newJavaAbstractClass": "抽象类型...",
"contributes.commands.java.view.package.newPackage": "包...",
"contributes.commands.java.view.package.newFile": "文件...",
"contributes.commands.java.view.package.newFolder": "文件夹",
"contributes.commands.java.view.package.newFolder": "文件夹...",
"contributes.commands.java.view.package.renameFile": "重命名",
"contributes.commands.java.view.package.moveFileToTrash": "删除",
"contributes.commands.java.view.package.deleteFilePermanently": "永久删除",
Expand Down
4 changes: 2 additions & 2 deletions package.nls.zh-tw.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,10 @@
"contributes.commands.java.view.package.copyFilePath": "複製路徑",
"contributes.commands.java.view.package.copyRelativeFilePath": "複製相對路徑",
"contributes.commands.java.view.package.new": "建立...",
"contributes.commands.java.view.package.newJavaClass": "Java 類別...",
"contributes.commands.java.view.package.newJavaClass": "類別...",
"contributes.commands.java.view.package.newPackage": "套件...",
"contributes.commands.java.view.package.newFile": "檔案...",
"contributes.commands.java.view.package.newFolder": "資料夾",
"contributes.commands.java.view.package.newFolder": "資料夾...",
"contributes.commands.java.view.package.renameFile": "重新命名",
"contributes.commands.java.view.package.moveFileToTrash": "刪除",
"contributes.commands.java.view.package.deleteFilePermanently": "永久刪除",
Expand Down
15 changes: 15 additions & 0 deletions src/commands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,16 @@ export namespace Commands {

export const VIEW_PACKAGE_NEW_JAVA_CLASS = "java.view.package.newJavaClass";

export const VIEW_PACKAGE_NEW_JAVA_INTERFACE = "java.view.package.newJavaInterface";

export const VIEW_PACKAGE_NEW_JAVA_ENUM = "java.view.package.newJavaEnum";

export const VIEW_PACKAGE_NEW_JAVA_RECORD = "java.view.package.newJavaRecord";

export const VIEW_PACKAGE_NEW_JAVA_ANNOTATION = "java.view.package.newJavaAnnotation";

export const VIEW_PACKAGE_NEW_JAVA_ABSTRACT_CLASS = "java.view.package.newJavaAbstractClass";

export const VIEW_PACKAGE_NEW_JAVA_PACKAGE = "java.view.package.newPackage";

export const VIEW_PACKAGE_RENAME_FILE = "java.view.package.renameFile";
Expand Down Expand Up @@ -133,6 +143,11 @@ export namespace Commands {
export const GET_ALL_PROJECTS = "java.project.getAll";

export const BUILD_PROJECT = "java.project.build";

/**
* Get the project settings
*/
export const GET_PROJECT_SETTINGS = 'java.project.getSettings';
}

export function executeJavaLanguageServerCommand(...rest: any[]) {
Expand Down
Loading