Skip to content

Commit

Permalink
Merge branch 'main' into cs/on-project-delete
Browse files Browse the repository at this point in the history
  • Loading branch information
jdneo authored Nov 29, 2023
2 parents 67ade2c + a0dcf41 commit eba9f11
Show file tree
Hide file tree
Showing 16 changed files with 455 additions and 53 deletions.
13 changes: 13 additions & 0 deletions ThirdPartyNotices.txt
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ This project incorporates components from the projects listed below. The origina
6. jprichardson/node-fs-extra (https://github.com/jprichardson/node-fs-extra)
7. lodash/lodash (https://github.com/lodash/lodash)
8. sindresorhus/globby (https://github.com/sindresorhus/globby)
9. tcort/fmtr (https://github.com/tcort/fmtr)

%% Apache Commons Lang NOTICES AND INFORMATION BEGIN HERE
=========================================
Expand Down Expand Up @@ -571,3 +572,15 @@ The above copyright notice and this permission notice shall be included in all c
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
=========================================
END OF sindresorhus/globby NOTICES AND INFORMATION

%% tcort/fmtr NOTICES AND INFORMATION BEGIN HERE
=========================================
ISC License

Copyright (c) 2015-2021 Thomas Cort [email protected]

Permission to use, copy, modify, and distribute this software for any purpose with or without fee is hereby granted, provided that the above copyright notice and this permission notice appear in all copies.

THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
=========================================
END OF tcort/fmtr NOTICES AND INFORMATION
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.

84 changes: 80 additions & 4 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 @@ -641,21 +691,46 @@
"javaProject.new": [
{
"command": "java.view.package.newJavaClass",
"group": "new@10",
"group": "new1@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": "new1@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": "new1@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": "new1@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": "new1@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": "new1@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",
"group": "new1@20",
"when": "view == javaProjectExplorer && (viewItem =~ /java:(package|packageRoot)(?=.*?\\b\\+source\\b)/ || viewItem =~ /java:project(?=.*?\\b\\+java\\b)/ || viewItem =~ /java:type/)"
},
{
"command": "java.view.package.newFile",
"group": "new@30"
"group": "new2@30"
},
{
"command": "java.view.package.newFolder",
"group": "new@40",
"group": "new2@40",
"when": "view == javaProjectExplorer && (viewItem =~ /java:(file|folder|project)/ || viewItem =~ /java:(packageRoot)(?=.*?\\b\\+resource\\b)/)"
}
]
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
Loading

0 comments on commit eba9f11

Please sign in to comment.