-
Notifications
You must be signed in to change notification settings - Fork 101
Add referenced libraries as reference container #113
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
Merged
Merged
Changes from 1 commit
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
c728c6f
Add referenced libraries as reference container
Flanker32 1656e5e
Merge branch 'master' into hanxiao_referlibs
andxu 1946e30
Add support for Referenced Variable
Flanker32 749e4d3
Merge branch 'hanxiao_referlibs' of https://github.com/Microsoft/vsco…
Flanker32 db123a3
Resolve comments
Flanker32 b13f924
Resolve comments
Flanker32 2f72289
Set entry kind to BINARY for referenced variable which refers to folder
Flanker32 35efcfd
Resolve comments
Flanker32 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -67,6 +67,8 @@ public class PackageCommand { | |
|
|
||
| private static final String DEFAULT_PACKAGE_DISPLAYNAME = "(default package)"; | ||
|
|
||
| private static final String REFERENCED_LIBRARIES_PATH = "REFERENCED_LIBRARIES_PATH"; | ||
|
|
||
| private static final Gson gson = new GsonBuilder().registerTypeAdapterFactory(new CollectionTypeAdapterFactory()) | ||
| .registerTypeAdapterFactory(new EnumTypeAdapterFactory()).create(); | ||
|
|
||
|
|
@@ -154,8 +156,13 @@ public static List<PackageNode> resolvePath(List<Object> arguments, IProgressMon | |
| if (typeRoot instanceof IClassFile) { | ||
| IClasspathEntry entry = pkgRoot.getRawClasspathEntry(); | ||
| IClasspathContainer container = JavaCore.getClasspathContainer(entry.getPath(), typeRoot.getJavaProject()); | ||
| PackageNode containerNode = new ContainerNode(container.getDescription(), container.getPath().toPortableString(), NodeKind.CONTAINER, | ||
| entry.getEntryKind()); | ||
| PackageNode containerNode = null; | ||
| if (entry.getEntryKind() == IClasspathEntry.CPE_LIBRARY) { | ||
| containerNode = new ContainerNode("ReferencedLibraries", REFERENCED_LIBRARIES_PATH, NodeKind.CONTAINER, IClasspathEntry.CPE_CONTAINER); | ||
| } else { | ||
| containerNode = new ContainerNode(container.getDescription(), container.getPath().toPortableString(), NodeKind.CONTAINER, | ||
| entry.getEntryKind()); | ||
| } | ||
| result.add(containerNode); | ||
| } | ||
| result.add(rootNode); | ||
|
|
@@ -174,36 +181,66 @@ public static List<PackageNode> resolvePath(List<Object> arguments, IProgressMon | |
| */ | ||
| private static List<PackageNode> getContainers(PackageParams query, IProgressMonitor pm) { | ||
| IJavaProject javaProject = getJavaProject(query.getProjectUri()); | ||
|
|
||
| if (javaProject != null) { | ||
| try { | ||
| IClasspathEntry[] references = javaProject.getRawClasspath(); | ||
| return Arrays.stream(references).map(entry -> { | ||
| try { | ||
| entry = JavaCore.getResolvedClasspathEntry(entry); | ||
| IClasspathContainer container = JavaCore.getClasspathContainer(entry.getPath(), javaProject); | ||
| // HACK: There is an initialization issue for the first container. | ||
| if (container == null) { | ||
| container = JavaCore.getClasspathContainer(entry.getPath(), javaProject); | ||
| } | ||
|
|
||
| if (container != null) { | ||
| return new ContainerNode(container.getDescription(), container.getPath().toPortableString(), NodeKind.CONTAINER, | ||
| entry.getEntryKind()); | ||
| } | ||
| } catch (CoreException e) { | ||
| // Ignore it | ||
| } | ||
| return null; | ||
| }).filter(containerNode -> containerNode != null).collect(Collectors.toList()); | ||
| List<PackageNode> result = Arrays.stream(references).filter(entry -> entry.getEntryKind() != IClasspathEntry.CPE_LIBRARY) | ||
| .map(entry -> getNodeFromClasspathEntry(entry, javaProject, NodeKind.CONTAINER)).filter(containerNode -> containerNode != null) | ||
| .collect(Collectors.toList()); | ||
|
|
||
| List<IClasspathEntry> referenceLibraries = Arrays.stream(references).filter(entry -> entry.getEntryKind() == IClasspathEntry.CPE_LIBRARY) | ||
| .collect(Collectors.toList()); | ||
| if (referenceLibraries.size() > 0) { | ||
| result.add(new ContainerNode("ReferencedLibraries", REFERENCED_LIBRARIES_PATH, NodeKind.CONTAINER, IClasspathEntry.CPE_CONTAINER)); | ||
|
Contributor
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. ContainerNode("ReferencedLibraries", REFERENCED_LIBRARIES_PATH, NodeKind.CONTAINER, IClasspathEntry.CPE_CONTAINER) should be a constant |
||
| } | ||
| return result; | ||
| } catch (CoreException e) { | ||
| JdtlsExtActivator.logException("Problem load project library ", e); | ||
| } | ||
| } | ||
| return Collections.emptyList(); | ||
| } | ||
|
|
||
| /** | ||
| * Get the correspond node of classpath, it may be container or a package root | ||
| * | ||
| * @param classpathEntry | ||
| * classpath | ||
| * @param javaProject | ||
| * correspond java project | ||
| * @param nodeKind | ||
| * could be CONTAINER or PACKAGEROOT(for referenced libraries) | ||
| * @return | ||
|
Flanker32 marked this conversation as resolved.
Outdated
|
||
| */ | ||
| private static PackageNode getNodeFromClasspathEntry(IClasspathEntry classpathEntry, IJavaProject javaProject, NodeKind nodeKind) { | ||
| try { | ||
| IClasspathEntry entry = JavaCore.getResolvedClasspathEntry(classpathEntry); | ||
| IClasspathContainer container = JavaCore.getClasspathContainer(entry.getPath(), javaProject); | ||
| // HACK: There is an initialization issue for the first container. | ||
| if (container == null) { | ||
| container = JavaCore.getClasspathContainer(entry.getPath(), javaProject); | ||
| } | ||
| if (container != null) { | ||
| switch (nodeKind) { | ||
| case CONTAINER: | ||
| return new ContainerNode(container.getDescription(), container.getPath().toPortableString(), nodeKind, entry.getEntryKind()); | ||
| case PACKAGEROOT: | ||
| // Use package name as package root name | ||
| String[] pathSegments = container.getPath().segments(); | ||
| return new PackageRootNode(pathSegments[pathSegments.length - 1], container.getPath().toPortableString(), nodeKind, | ||
| IClasspathEntry.CPE_PROJECT); | ||
| default: | ||
| return null; | ||
| } | ||
| } | ||
| } catch (CoreException e) { | ||
| // Ignore it | ||
| } | ||
| return null; | ||
| } | ||
|
|
||
| private static List<PackageNode> getPackageFragmentRoots(PackageParams query, IProgressMonitor pm) { | ||
| ArrayList<PackageNode> children = new ArrayList<>(); | ||
| IJavaProject javaProject = getJavaProject(query.getProjectUri()); | ||
|
|
||
| if (javaProject != null) { | ||
|
|
@@ -217,7 +254,6 @@ private static List<PackageNode> getPackageFragmentRoots(PackageParams query, IP | |
| } | ||
| } | ||
| if (containerEntry != null) { | ||
| ArrayList<PackageNode> children = new ArrayList<>(); | ||
| IPackageFragmentRoot[] packageFragmentRoots = javaProject.findPackageFragmentRoots(containerEntry); | ||
| for (IPackageFragmentRoot fragmentRoot : packageFragmentRoots) { | ||
| String displayName = fragmentRoot.getElementName(); | ||
|
|
@@ -232,6 +268,13 @@ private static List<PackageNode> getPackageFragmentRoots(PackageParams query, IP | |
| } | ||
| } | ||
| return children; | ||
| } else if (query.getPath().equals(REFERENCED_LIBRARIES_PATH)) { | ||
| // Process referenced libraries | ||
| List<PackageNode> classpaths = Arrays.stream(references).filter(entry -> entry.getEntryKind() == IClasspathEntry.CPE_LIBRARY) | ||
| .map(classpath -> getNodeFromClasspathEntry(classpath, javaProject, NodeKind.PACKAGEROOT)).filter(entry -> entry != null) | ||
| .collect(Collectors.toList()); | ||
| children.addAll(classpaths); | ||
| return children; | ||
| } | ||
| } catch (CoreException e) { | ||
| JdtlsExtActivator.logException("Problem load project JAR entries ", e); | ||
|
|
@@ -274,7 +317,7 @@ private static List<PackageNode> getRootTypes(PackageParams query, IProgressMoni | |
| if (packageFragment != null) { | ||
| IJavaElement[] types = packageFragment.getChildren(); | ||
| Object[] nonJavaResources = packageFragment.getNonJavaResources(); | ||
| List<PackageNode> rootTypeNodes = Arrays.stream(types).filter(typeRoot -> !typeRoot.getElementName().contains("$")).map(typeRoot -> { | ||
| List<PackageNode> rootTypeNodes = Arrays.stream(types).filter(typeRoot -> !typeRoot.getElementName().contains("$")).map(typeRoot -> { | ||
| PackageNode item = new TypeRootNode(typeRoot.getElementName(), typeRoot.getPath().toPortableString(), NodeKind.TYPEROOT, | ||
| typeRoot instanceof IClassFile ? TypeRootNode.K_BINARY : TypeRootNode.K_SOURCE); | ||
| if (typeRoot instanceof ICompilationUnit) { | ||
|
|
@@ -289,20 +332,20 @@ private static List<PackageNode> getRootTypes(PackageParams query, IProgressMoni | |
| } | ||
| // when .java files and other .properties files are mixed up | ||
| rootTypeNodes.addAll( | ||
| Arrays.stream(nonJavaResources).filter(resource -> resource instanceof IFile || resource instanceof JarEntryFile).map(resource -> { | ||
| if (resource instanceof IFile) { | ||
| IFile file = (IFile) resource; | ||
| PackageNode item = new PackageNode(file.getName(), file.getFullPath().toPortableString(), NodeKind.FILE); | ||
| item.setUri(JDTUtils.getFileURI(file)); | ||
| return item; | ||
| } else { | ||
| JarEntryFile file = (JarEntryFile) resource; | ||
| PackageNode entry = new PackageNode(file.getName(), file.getFullPath().toPortableString(), NodeKind.FILE); | ||
| entry.setUri(ExtUtils.toUri((JarEntryFile) resource)); | ||
| return entry; | ||
| } | ||
|
|
||
| }).collect(Collectors.toList())); | ||
| Arrays.stream(nonJavaResources).filter(resource -> resource instanceof IFile || resource instanceof JarEntryFile).map(resource -> { | ||
| if (resource instanceof IFile) { | ||
| IFile file = (IFile) resource; | ||
| PackageNode item = new PackageNode(file.getName(), file.getFullPath().toPortableString(), NodeKind.FILE); | ||
| item.setUri(JDTUtils.getFileURI(file)); | ||
| return item; | ||
| } else { | ||
| JarEntryFile file = (JarEntryFile) resource; | ||
| PackageNode entry = new PackageNode(file.getName(), file.getFullPath().toPortableString(), NodeKind.FILE); | ||
| entry.setUri(ExtUtils.toUri((JarEntryFile) resource)); | ||
| return entry; | ||
| } | ||
|
|
||
| }).collect(Collectors.toList())); | ||
| return rootTypeNodes; | ||
| } | ||
| } catch (CoreException e) { | ||
|
|
||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.