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
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2017 Microsoft Corporation and others.
* Copyright (c) 2018 Microsoft Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
Expand All @@ -8,6 +8,7 @@
* Contributors:
* Microsoft Corporation - initial API and implementation
*******************************************************************************/

package com.microsoft.jdtls.ext.core;

import java.util.List;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2017 Microsoft Corporation and others.
* Copyright (c) 2018 Microsoft Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
Expand All @@ -14,6 +14,7 @@
import java.net.URI;
import java.net.URISyntaxException;

import org.eclipse.core.runtime.IPath;
import org.eclipse.jdt.core.IPackageFragmentRoot;
import org.eclipse.jdt.internal.core.JarEntryFile;
import org.eclipse.jdt.ls.core.internal.JavaLanguageServerPlugin;
Expand All @@ -34,4 +35,10 @@ public static String toUri(JarEntryFile jarEntryFile) {
}
}

public static IPath removeProjectSegment(String projectElementName, IPath path) {
if (projectElementName.equals(path.segment(0))) {
return path.removeFirstSegments(1).makeRelative();
}
return path;
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2017 Microsoft Corporation and others.
* Copyright (c) 2018 Microsoft Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2017 Microsoft Corporation and others.
* Copyright (c) 2018 Microsoft Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2017 Microsoft Corporation and others.
* Copyright (c) 2018 Microsoft Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2017 Microsoft Corporation and others.
* Copyright (c) 2018 Microsoft Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
Expand Down Expand Up @@ -61,7 +61,7 @@ public class PackageCommand {
static {
commands = new HashMap<>();
commands.put(NodeKind.PROJECT, PackageCommand::getContainers);
commands.put(NodeKind.CONTAINER, PackageCommand::getJars);
commands.put(NodeKind.CONTAINER, PackageCommand::getPackageFragmentRoots);
commands.put(NodeKind.JAR, PackageCommand::getPackages);
commands.put(NodeKind.PACKAGE, PackageCommand::getClassfiles);
commands.put(NodeKind.Folder, PackageCommand::getFolderChildren);
Expand All @@ -73,8 +73,8 @@ public class PackageCommand {
* @param arguments
* List of the arguments which contain two entries to get class path
* children: the first entry is the query target node type
* {@link NodeKind} and the second one is the query instance
* of type {@link PackageParams}
* {@link NodeKind} and the second one is the query instance of type
* {@link PackageParams}
* @return the found ClasspathNode list
* @throws CoreException
*/
Expand All @@ -86,8 +86,7 @@ public static List<PackageNode> getChildren(List<Object> arguments, IProgressMon

BiFunction<PackageParams, IProgressMonitor, List<PackageNode>> loader = commands.get(params.getKind());
if (loader == null) {
throw new CoreException(new Status(IStatus.ERROR, JavaLanguageServerPlugin.PLUGIN_ID,
String.format("Unknown classpath item type: %s", params.getKind())));
throw new CoreException(new Status(IStatus.ERROR, JavaLanguageServerPlugin.PLUGIN_ID, String.format("Unknown classpath item type: %s", params.getKind())));
}
List<PackageNode> result = loader.apply(params, pm);
return result;
Expand All @@ -102,30 +101,34 @@ private static List<PackageNode> getContainers(PackageParams query, IProgressMon
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);
if (container != null) {
PackageNode containerNode = new PackageNode(container.getDescription(),
container.getPath().toPortableString(), NodeKind.CONTAINER);
return containerNode;
return Arrays.stream(references).map(entry -> {
try {
entry = JavaCore.getResolvedClasspathEntry(entry);
IClasspathContainer container = JavaCore.getClasspathContainer(entry.getPath(), javaProject);
if (container != null) {
if (entry.getEntryKind() == IClasspathEntry.CPE_SOURCE) {
IPackageFragmentRoot[] packageFragmentRoots = javaProject.findPackageFragmentRoots(entry);
for (IPackageFragmentRoot fragmentRoot : packageFragmentRoots) {
String rootName = ExtUtils.removeProjectSegment(javaProject.getElementName(), fragmentRoot.getPath()).toPortableString();
return new PackageNode(rootName, fragmentRoot.getPath().toPortableString(), NodeKind.JAR);
}
} catch (CoreException e) {
// Ignore it
} else {
return new PackageNode(container.getDescription(), container.getPath().toPortableString(), NodeKind.CONTAINER);
}
return null;
}).filter(containerNode -> containerNode != null).collect(Collectors.toList());
}
} catch (CoreException e) {
// Ignore it
}
return null;
}).filter(containerNode -> containerNode != null).collect(Collectors.toList());
} catch (CoreException e) {
JavaLanguageServerPlugin.logException("Problem load project library ", e);
}
}
return Collections.emptyList();
}

private static List<PackageNode> getJars(PackageParams query, IProgressMonitor pm) {
private static List<PackageNode> getPackageFragmentRoots(PackageParams query, IProgressMonitor pm) {
IJavaProject javaProject = getJavaProject(query.getProjectUri());

if (javaProject != null) {
Expand All @@ -142,8 +145,7 @@ private static List<PackageNode> getJars(PackageParams query, IProgressMonitor p
ArrayList<PackageNode> children = new ArrayList<>();
IPackageFragmentRoot[] packageFragmentRoots = javaProject.findPackageFragmentRoots(containerEntry);
for (IPackageFragmentRoot fragmentRoot : packageFragmentRoots) {
PackageNode node = new PackageNode(fragmentRoot.getElementName(),
fragmentRoot.getPath().toPortableString(), NodeKind.JAR);
PackageNode node = new PackageNode(fragmentRoot.getElementName(), fragmentRoot.getPath().toPortableString(), NodeKind.JAR);
children.add(node);
if (fragmentRoot instanceof JrtPackageFragmentRoot) {
node.setModuleName(fragmentRoot.getModuleDescription().getElementName());
Expand All @@ -165,11 +167,9 @@ private static List<PackageNode> getPackages(PackageParams query, IProgressMonit
if (javaProject != null) {

try {
IPackageFragmentRoot packageRoot = javaProject
.findPackageFragmentRoot(Path.fromPortableString(query.getRootPath()));
IPackageFragmentRoot packageRoot = javaProject.findPackageFragmentRoot(Path.fromPortableString(query.getRootPath()));
if (packageRoot == null) {
throw new CoreException(new Status(IStatus.ERROR, JavaLanguageServerPlugin.PLUGIN_ID,
String.format("No package root found for %s", query.getPath())));
throw new CoreException(new Status(IStatus.ERROR, JavaLanguageServerPlugin.PLUGIN_ID, String.format("No package root found for %s", query.getPath())));
}
Object[] result = getPackageFragmentRootContent(packageRoot, pm);
return convertToClasspathNode(result);
Expand All @@ -184,21 +184,17 @@ private static List<PackageNode> getClassfiles(PackageParams query, IProgressMon
IJavaProject javaProject = getJavaProject(query.getProjectUri());
if (javaProject != null) {
try {
IPackageFragmentRoot packageRoot = javaProject
.findPackageFragmentRoot(Path.fromPortableString(query.getRootPath()));
IPackageFragmentRoot packageRoot = javaProject.findPackageFragmentRoot(Path.fromPortableString(query.getRootPath()));
if (packageRoot == null) {
throw new CoreException(new Status(IStatus.ERROR, JavaLanguageServerPlugin.PLUGIN_ID,
String.format("No package root found for %s", query.getPath())));
throw new CoreException(new Status(IStatus.ERROR, JavaLanguageServerPlugin.PLUGIN_ID, String.format("No package root found for %s", query.getPath())));
}
IPackageFragment packageFragment = packageRoot.getPackageFragment(query.getPath());
if (packageFragment != null) {
IJavaElement[] classFiles = packageFragment.getChildren();
return Arrays.stream(classFiles).filter(classFile -> !classFile.getElementName().contains("$"))
.map(classFile -> {
PackageNode item = new PackageNode(classFile.getElementName(),
classFile.getPath().toPortableString(), NodeKind.CLASSFILE);
return item;
}).collect(Collectors.toList());
return Arrays.stream(classFiles).filter(classFile -> !classFile.getElementName().contains("$")).map(classFile -> {
PackageNode item = new PackageNode(classFile.getElementName(), classFile.getPath().toPortableString(), NodeKind.CLASSFILE);
return item;
}).collect(Collectors.toList());

}
} catch (CoreException e) {
Expand All @@ -212,11 +208,9 @@ private static List<PackageNode> getFolderChildren(PackageParams query, IProgres
IJavaProject javaProject = getJavaProject(query.getProjectUri());
if (javaProject != null) {
try {
IPackageFragmentRoot packageRoot = javaProject
.findPackageFragmentRoot(Path.fromPortableString(query.getRootPath()));
IPackageFragmentRoot packageRoot = javaProject.findPackageFragmentRoot(Path.fromPortableString(query.getRootPath()));
if (packageRoot == null) {
throw new CoreException(new Status(IStatus.ERROR, JavaLanguageServerPlugin.PLUGIN_ID,
String.format("No package root found for %s", query.getPath())));
throw new CoreException(new Status(IStatus.ERROR, JavaLanguageServerPlugin.PLUGIN_ID, String.format("No package root found for %s", query.getPath())));
}
// jar file and folders
Object[] resources = packageRoot.getNonJavaResources();
Expand All @@ -240,8 +234,7 @@ private static List<PackageNode> getFolderChildren(PackageParams query, IProgres
return Collections.emptyList();
}

private static Object[] getPackageFragmentRootContent(IPackageFragmentRoot root, IProgressMonitor pm)
throws CoreException {
private static Object[] getPackageFragmentRootContent(IPackageFragmentRoot root, IProgressMonitor pm) throws CoreException {
ArrayList<Object> result = new ArrayList<>();
for (IJavaElement child : root.getChildren()) {
IPackageFragment fragment = (IPackageFragment) child;
Expand All @@ -263,8 +256,7 @@ private static List<PackageNode> convertToClasspathNode(Object[] rootContent) th
for (Object root : rootContent) {
if (root instanceof IPackageFragment) {
IPackageFragment packageFragment = (IPackageFragment) root;
PackageNode entry = new PackageNode(((IPackageFragment) root).getElementName(),
packageFragment.getPath().toPortableString(), NodeKind.PACKAGE);
PackageNode entry = new PackageNode(((IPackageFragment) root).getElementName(), packageFragment.getPath().toPortableString(), NodeKind.PACKAGE);
result.add(entry);
} else if (root instanceof IClassFile) {
IClassFile classFile = (IClassFile) root;
Expand All @@ -284,11 +276,9 @@ private static List<PackageNode> convertToClasspathNode(Object[] rootContent) th

private static PackageNode getJarEntryResource(JarEntryResource resource) {
if (resource instanceof JarEntryDirectory) {
return new PackageNode(resource.getName(), resource.getFullPath().toPortableString(),
NodeKind.Folder);
return new PackageNode(resource.getName(), resource.getFullPath().toPortableString(), NodeKind.Folder);
} else if (resource instanceof JarEntryFile) {
PackageNode entry = new PackageNode(resource.getName(), resource.getFullPath().toPortableString(),
NodeKind.FILE);
PackageNode entry = new PackageNode(resource.getName(), resource.getFullPath().toPortableString(), NodeKind.FILE);
entry.setUri(ExtUtils.toUri((JarEntryFile) resource));
return entry;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2017 Microsoft Corporation and others.
* Copyright (c) 2018 Microsoft Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2017 Microsoft Corporation and others.
* Copyright (c) 2018 Microsoft Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
Expand Down
22 changes: 22 additions & 0 deletions jdtls.ext/target.target
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<?pde version="3.8"?><target name="JDTLS.EXT" sequenceNumber="38">
<locations>
<location includeAllPlatforms="false" includeConfigurePhase="true" includeMode="planner" includeSource="true" type="InstallableUnit">
<unit id="org.eclipse.libra.framework.feature.feature.group" version="0.3.1.201609011955"/>
<repository location="http://download.eclipse.org/releases/oxygen"/>
</location>
<location includeAllPlatforms="false" includeConfigurePhase="true" includeMode="planner" includeSource="true" type="InstallableUnit">
<unit id="org.eclipse.xtend.sdk.feature.group" version="2.13.0.v20171020-0920"/>
<unit id="org.eclipse.xtext.sdk.feature.group" version="2.13.0.v20171020-0920"/>
<repository location="http://download.eclipse.org/releases/photon/"/>
</location>
<location includeAllPlatforms="false" includeConfigurePhase="true" includeMode="planner" includeSource="true" type="InstallableUnit">
<unit id="org.eclipse.lsp4j.sdk.feature.group" version="0.4.0.v20180301-0956"/>
<repository location="http://download.eclipse.org/lsp4j/updates/milestones"/>
</location>
<location includeAllPlatforms="false" includeConfigurePhase="true" includeMode="planner" includeSource="true" type="InstallableUnit">
<unit id="org.eclipse.jdt.ls.core" version="0.16.0.201804042215"/>
<repository location="http://download.eclipse.org/jdtls/snapshots/repository/0.16.0.201804042215/"/>
</location>
</locations>
</target>
Binary file removed vscode/images/statusMarker.png
Binary file not shown.
Binary file removed vscode/images/vscode-java.0.0.1.gif
Binary file not shown.
2 changes: 2 additions & 0 deletions vscode/src/extension.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@

import { PackageExplorer } from "./views/packageExplorer";
import { ExtensionContext, window } from "vscode";
import { Services } from "./services";

export function activate(context: ExtensionContext) {
Services.initialize(context);
context.subscriptions.push(window.registerTreeDataProvider('javaProjectExplorer', new PackageExplorer(context)));
}
13 changes: 13 additions & 0 deletions vscode/src/services.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import { ExtensionContext } from "vscode";

export class Services {
static initialize(context: ExtensionContext) {
this._context = context;
}

private static _context: ExtensionContext;

static get context() {
return this._context;
}
}
15 changes: 15 additions & 0 deletions vscode/src/views/classfileNode.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,32 @@
import { INodeData } from "../java/nodeData";
import { ExplorerNode } from "./explorerNode";
import { DataNode } from "./dataNode";
import { TreeItem, TreeItemCollapsibleState } from "vscode";
import { Services } from "../services";

export class ClassfileNode extends DataNode {
constructor(nodeData: INodeData) {
super(nodeData);
}


public getTreeItem(): TreeItem | Promise<TreeItem> {
if (this.nodeData) {
const item = new TreeItem(this.nodeData.name, TreeItemCollapsibleState.None);
item.iconPath = Services.context.asAbsolutePath(this.iconPath);
return item;
}
}

protected loadData(): Thenable<INodeData[]> {
return null;
}

protected createChildNodeList(): ExplorerNode[] {
return null;
}

protected get iconPath(): string {
return "./images/classfile.png";
}
}
4 changes: 4 additions & 0 deletions vscode/src/views/containerNode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,8 @@ export class ContainerNode extends DataNode {
}
return result;
}

protected get iconPath() : string {
return "./images/library.png";
}
}
7 changes: 5 additions & 2 deletions vscode/src/views/dataNode.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@

import { ExplorerNode } from "./explorerNode";
import { INodeData } from "../java/nodeData";
import { ProviderResult, TreeItem, TreeItemCollapsibleState } from "vscode";
import { ProviderResult, TreeItem, TreeItemCollapsibleState, Uri } from "vscode";
import { Services } from "../services";

export abstract class DataNode extends ExplorerNode {
constructor(private _nodeData: INodeData) {
Expand All @@ -11,7 +12,7 @@ export abstract class DataNode extends ExplorerNode {
public getTreeItem(): TreeItem | Promise<TreeItem> {
if (this._nodeData) {
const item = new TreeItem(this._nodeData.name, TreeItemCollapsibleState.Collapsed);
item.iconPath = {};
item.iconPath = Services.context.asAbsolutePath(this.iconPath);
return item;
}
}
Expand All @@ -38,6 +39,8 @@ export abstract class DataNode extends ExplorerNode {
return this.createChildNodeList();
}

protected abstract get iconPath(): string;

protected abstract loadData(): Thenable<INodeData[]>;

protected abstract createChildNodeList(): ExplorerNode[];
Expand Down
4 changes: 4 additions & 0 deletions vscode/src/views/fileNode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,8 @@ export class FileNode extends DataNode {
protected createChildNodeList(): ExplorerNode[] {
return null;
}

protected get iconPath() : string {
return "./images/file.png";
}
}
Loading