-
Notifications
You must be signed in to change notification settings - Fork 77
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Remove the duplication nodes with the outline explorer #235
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -22,7 +22,7 @@ public enum NodeKind { | |
|
||
PACKAGE(5), | ||
|
||
TYPEROOT(6), | ||
PRIMARYTYPE(6), | ||
|
||
FOLDER(7), | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,22 +12,23 @@ | |
package com.microsoft.jdtls.ext.core.model; | ||
|
||
import java.net.URI; | ||
import java.util.HashMap; | ||
import java.util.List; | ||
import java.util.Map; | ||
|
||
import org.eclipse.core.resources.IFile; | ||
import org.eclipse.core.resources.IFolder; | ||
import org.eclipse.core.resources.IProject; | ||
import org.eclipse.core.resources.IResource; | ||
import org.eclipse.core.runtime.CoreException; | ||
import org.eclipse.core.runtime.IPath; | ||
import org.eclipse.jdt.core.IClassFile; | ||
import org.eclipse.jdt.core.IClasspathContainer; | ||
import org.eclipse.jdt.core.IClasspathEntry; | ||
import org.eclipse.jdt.core.ICompilationUnit; | ||
import org.eclipse.jdt.core.IJavaElement; | ||
import org.eclipse.jdt.core.IJavaProject; | ||
import org.eclipse.jdt.core.IPackageFragment; | ||
import org.eclipse.jdt.core.IPackageFragmentRoot; | ||
import org.eclipse.jdt.core.IType; | ||
import org.eclipse.jdt.core.JavaCore; | ||
import org.eclipse.jdt.core.JavaModelException; | ||
import org.eclipse.jdt.ls.core.internal.JDTUtils; | ||
|
@@ -39,15 +40,33 @@ | |
* Represent a PackageNode in the project view. | ||
*/ | ||
public class PackageNode { | ||
|
||
public final static String K_TYPE_KIND = "TypeKind"; | ||
|
||
/** | ||
* Kind constant for a class. | ||
*/ | ||
public final static int K_CLASS = 1; | ||
|
||
/** | ||
* Kind constant for an interface. | ||
*/ | ||
public final static int K_INTERFACE = 2; | ||
|
||
/** | ||
* Kind constant for an enum. | ||
*/ | ||
public final static int K_ENUM = 3; | ||
|
||
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 String DEFAULT_PACKAGE_DISPLAYNAME = "(default package)"; | ||
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); | ||
public static final ContainerNode IMMUTABLE_REFERENCED_LIBRARIES_CONTAINER = new ContainerNode(IMMUTABLE_REFERENCED_LIBRARIES_CONTAINER_NAME, | ||
REFERENCED_LIBRARIES_PATH, NodeKind.CONTAINER, IClasspathEntry.CPE_CONTAINER); | ||
|
||
/** | ||
* The name of the PackageNode | ||
|
@@ -74,6 +93,11 @@ public class PackageNode { | |
*/ | ||
private NodeKind kind; | ||
|
||
/** | ||
* PackageNode metaData | ||
*/ | ||
private Map<String, Object> metaData; | ||
|
||
/** | ||
* PackageNode children list | ||
*/ | ||
|
@@ -83,6 +107,17 @@ public PackageNode() { | |
|
||
} | ||
|
||
public Map<String, Object> getMetaData() { | ||
return metaData; | ||
} | ||
|
||
public void setMetaDataValue(String key, Object value) { | ||
if (this.metaData == null) { | ||
this.metaData = new HashMap<>(); | ||
} | ||
this.metaData.put(key, value); | ||
} | ||
|
||
public PackageNode(String name, String path, NodeKind kind) { | ||
this.name = name; | ||
this.path = path; | ||
|
@@ -187,15 +222,23 @@ public static PackageNode createNodeForClasspathEntry(IClasspathEntry classpathE | |
return null; | ||
} | ||
|
||
public static PackageNode createNodeForTypeRoot(IJavaElement typeRoot) { | ||
PackageNode typeRootNode = new TypeRootNode(typeRoot.getElementName(), typeRoot.getPath().toPortableString(), NodeKind.TYPEROOT, | ||
typeRoot instanceof IClassFile ? TypeRootNode.K_BINARY : TypeRootNode.K_SOURCE); | ||
if (typeRoot instanceof ICompilationUnit) { | ||
typeRootNode.setUri(JDTUtils.toURI((ICompilationUnit) typeRoot)); | ||
} else if (typeRoot instanceof IClassFile) { | ||
typeRootNode.setUri(JDTUtils.toUri((IClassFile) typeRoot)); | ||
public static PackageNode createNodeForPrimaryType(IType type) { | ||
PackageNode primaryTypeNode = new PackageNode(type.getElementName(), type.getPath().toPortableString(), NodeKind.PRIMARYTYPE); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. why create packageNode for IType? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. That's some unknown historical reason. The Java side code only has the following kinds of nodes:
I'm also confused about the naming. But the fact is that different kind of nodes are all named as |
||
|
||
try { | ||
if (type.isEnum()) { | ||
primaryTypeNode.setMetaDataValue(K_TYPE_KIND, K_ENUM); | ||
} else if (type.isInterface()) { | ||
primaryTypeNode.setMetaDataValue(K_TYPE_KIND, K_INTERFACE); | ||
} else { | ||
primaryTypeNode.setMetaDataValue(K_TYPE_KIND, K_CLASS); | ||
} | ||
} catch (JavaModelException e) { | ||
primaryTypeNode.setMetaDataValue(K_TYPE_KIND, K_CLASS); | ||
} | ||
return typeRootNode; | ||
|
||
primaryTypeNode.setUri(JDTUtils.toUri(type.getTypeRoot())); | ||
return primaryTypeNode; | ||
} | ||
|
||
/** | ||
|
This file was deleted.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
packageFragment.getChildren() returns the immediate children of this package. Will it contain inner class?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, the Inner class will become:
XXX$Inner.class
after compilation.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Theoretically the java class name itself can use $, but i didn't find a good way to judge whether it's inner class. let's keep the current judge, if there is someone reporting the issue, then fix it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ok