diff --git a/jdtls.ext/com.microsoft.jdtls.ext.core/.checkstyle b/jdtls.ext/com.microsoft.jdtls.ext.core/.checkstyle new file mode 100644 index 00000000..5783bc0d --- /dev/null +++ b/jdtls.ext/com.microsoft.jdtls.ext.core/.checkstyle @@ -0,0 +1,7 @@ + + + + + + + diff --git a/jdtls.ext/com.microsoft.jdtls.ext.core/.settings/org.eclipse.jdt.core.prefs b/jdtls.ext/com.microsoft.jdtls.ext.core/.settings/org.eclipse.jdt.core.prefs index 044ef7ac..213c4fa9 100644 --- a/jdtls.ext/com.microsoft.jdtls.ext.core/.settings/org.eclipse.jdt.core.prefs +++ b/jdtls.ext/com.microsoft.jdtls.ext.core/.settings/org.eclipse.jdt.core.prefs @@ -22,6 +22,7 @@ org.eclipse.jdt.core.formatter.alignment_for_enum_constants=0 org.eclipse.jdt.core.formatter.alignment_for_expressions_in_array_initializer=16 org.eclipse.jdt.core.formatter.alignment_for_expressions_in_for_loop_header=0 org.eclipse.jdt.core.formatter.alignment_for_method_declaration=0 +org.eclipse.jdt.core.formatter.alignment_for_module_statements=16 org.eclipse.jdt.core.formatter.alignment_for_multiple_fields=16 org.eclipse.jdt.core.formatter.alignment_for_parameterized_type_references=0 org.eclipse.jdt.core.formatter.alignment_for_parameters_in_constructor_declaration=16 @@ -62,11 +63,11 @@ org.eclipse.jdt.core.formatter.brace_position_for_type_declaration=end_of_line org.eclipse.jdt.core.formatter.comment.clear_blank_lines_in_block_comment=false org.eclipse.jdt.core.formatter.comment.clear_blank_lines_in_javadoc_comment=false org.eclipse.jdt.core.formatter.comment.count_line_length_from_starting_position=true -org.eclipse.jdt.core.formatter.comment.format_block_comments=false +org.eclipse.jdt.core.formatter.comment.format_block_comments=true org.eclipse.jdt.core.formatter.comment.format_header=false org.eclipse.jdt.core.formatter.comment.format_html=true org.eclipse.jdt.core.formatter.comment.format_javadoc_comments=true -org.eclipse.jdt.core.formatter.comment.format_line_comments=false +org.eclipse.jdt.core.formatter.comment.format_line_comments=true org.eclipse.jdt.core.formatter.comment.format_source_code=true org.eclipse.jdt.core.formatter.comment.indent_parameter_description=true org.eclipse.jdt.core.formatter.comment.indent_root_tags=true @@ -92,7 +93,7 @@ org.eclipse.jdt.core.formatter.indent_empty_lines=false org.eclipse.jdt.core.formatter.indent_statements_compare_to_block=true org.eclipse.jdt.core.formatter.indent_statements_compare_to_body=true org.eclipse.jdt.core.formatter.indent_switchstatements_compare_to_cases=true -org.eclipse.jdt.core.formatter.indent_switchstatements_compare_to_switch=true +org.eclipse.jdt.core.formatter.indent_switchstatements_compare_to_switch=false org.eclipse.jdt.core.formatter.indentation.size=4 org.eclipse.jdt.core.formatter.insert_new_line_after_annotation_on_enum_constant=insert org.eclipse.jdt.core.formatter.insert_new_line_after_annotation_on_field=insert @@ -284,7 +285,7 @@ org.eclipse.jdt.core.formatter.keep_else_statement_on_same_line=false org.eclipse.jdt.core.formatter.keep_empty_array_initializer_on_one_line=false org.eclipse.jdt.core.formatter.keep_imple_if_on_one_line=false org.eclipse.jdt.core.formatter.keep_then_statement_on_same_line=false -org.eclipse.jdt.core.formatter.lineSplit=240 +org.eclipse.jdt.core.formatter.lineSplit=160 org.eclipse.jdt.core.formatter.never_indent_block_comments_on_first_column=false org.eclipse.jdt.core.formatter.never_indent_line_comments_on_first_column=false org.eclipse.jdt.core.formatter.number_of_blank_lines_at_beginning_of_method_body=0 @@ -302,7 +303,7 @@ org.eclipse.jdt.core.formatter.parentheses_positions_in_try_clause=common_lines org.eclipse.jdt.core.formatter.put_empty_statement_on_new_line=true org.eclipse.jdt.core.formatter.tabulation.char=tab org.eclipse.jdt.core.formatter.tabulation.size=4 -org.eclipse.jdt.core.formatter.use_on_off_tags=true +org.eclipse.jdt.core.formatter.use_on_off_tags=false org.eclipse.jdt.core.formatter.use_tabs_only_for_leading_indentations=false org.eclipse.jdt.core.formatter.wrap_before_assignment_operator=false org.eclipse.jdt.core.formatter.wrap_before_binary_operator=true diff --git a/jdtls.ext/com.microsoft.jdtls.ext.core/.settings/org.eclipse.jdt.ui.prefs b/jdtls.ext/com.microsoft.jdtls.ext.core/.settings/org.eclipse.jdt.ui.prefs index 9f4936d7..9c075644 100644 --- a/jdtls.ext/com.microsoft.jdtls.ext.core/.settings/org.eclipse.jdt.ui.prefs +++ b/jdtls.ext/com.microsoft.jdtls.ext.core/.settings/org.eclipse.jdt.ui.prefs @@ -58,7 +58,7 @@ cleanup_profile=org.eclipse.jdt.ui.default.eclipse_clean_up_profile cleanup_settings_version=2 eclipse.preferences.version=1 editor_save_participant_org.eclipse.jdt.ui.postsavelistener.cleanup=true -formatter_profile=_JDT LS +formatter_profile=_JDTLS.EXT formatter_settings_version=13 org.eclipse.jdt.ui.javadoc=true org.eclipse.jdt.ui.text.custom_code_templates= diff --git a/jdtls.ext/com.microsoft.jdtls.ext.core/src/com/microsoft/jdtls/ext/core/PackageCommand.java b/jdtls.ext/com.microsoft.jdtls.ext.core/src/com/microsoft/jdtls/ext/core/PackageCommand.java index ea0b0998..db269c4a 100644 --- a/jdtls.ext/com.microsoft.jdtls.ext.core/src/com/microsoft/jdtls/ext/core/PackageCommand.java +++ b/jdtls.ext/com.microsoft.jdtls.ext.core/src/com/microsoft/jdtls/ext/core/PackageCommand.java @@ -44,7 +44,6 @@ import org.eclipse.jdt.internal.core.JarEntryResource; import org.eclipse.jdt.internal.core.JrtPackageFragmentRoot; import org.eclipse.jdt.ls.core.internal.JDTUtils; -import org.eclipse.jdt.ls.core.internal.JavaLanguageServerPlugin; import org.eclipse.lsp4j.jsonrpc.json.adapters.CollectionTypeAdapterFactory; import org.eclipse.lsp4j.jsonrpc.json.adapters.EnumTypeAdapterFactory; @@ -54,6 +53,7 @@ import com.microsoft.jdtls.ext.core.model.NodeKind; import com.microsoft.jdtls.ext.core.model.PackageNode; import com.microsoft.jdtls.ext.core.model.PackageRootNode; +import com.microsoft.jdtls.ext.core.model.TypeRootNode; @SuppressWarnings("deprecation") public class PackageCommand { @@ -68,7 +68,7 @@ public class PackageCommand { commands.put(NodeKind.PROJECT, PackageCommand::getContainers); commands.put(NodeKind.CONTAINER, PackageCommand::getPackageFragmentRoots); commands.put(NodeKind.PACKAGEROOT, PackageCommand::getPackages); - commands.put(NodeKind.PACKAGE, PackageCommand::getClassfiles); + commands.put(NodeKind.PACKAGE, PackageCommand::getRootTypes); commands.put(NodeKind.Folder, PackageCommand::getFolderChildren); } @@ -91,8 +91,7 @@ public static List getChildren(List arguments, IProgressMon BiFunction> loader = commands.get(params.getKind()); if (loader == null) { - throw new CoreException( - new Status(IStatus.ERROR, JdtlsExtActivator.PLUGIN_ID, String.format("Unknown classpath item type: %s", params.getKind()))); + throw new CoreException(new Status(IStatus.ERROR, JdtlsExtActivator.PLUGIN_ID, String.format("Unknown classpath item type: %s", params.getKind()))); } List result = loader.apply(params, pm); return result; @@ -121,7 +120,7 @@ private static List getContainers(PackageParams query, IProgressMon return null; }).filter(containerNode -> containerNode != null).collect(Collectors.toList()); } catch (CoreException e) { - JavaLanguageServerPlugin.logException("Problem load project library ", e); + JdtlsExtActivator.logException("Problem load project library ", e); } } return Collections.emptyList(); @@ -144,7 +143,11 @@ private static List getPackageFragmentRoots(PackageParams query, IP ArrayList children = new ArrayList<>(); IPackageFragmentRoot[] packageFragmentRoots = javaProject.findPackageFragmentRoots(containerEntry); for (IPackageFragmentRoot fragmentRoot : packageFragmentRoots) { - PackageNode node = new PackageRootNode(fragmentRoot.getElementName(), fragmentRoot.getPath().toPortableString(), NodeKind.PACKAGEROOT, + String displayName = fragmentRoot.getElementName(); + if (fragmentRoot.getKind() == IPackageFragmentRoot.K_SOURCE) { + displayName = ExtUtils.removeProjectSegment(javaProject.getElementName(), fragmentRoot.getPath()).toPortableString(); + } + PackageNode node = new PackageRootNode(displayName, fragmentRoot.getPath().toPortableString(), NodeKind.PACKAGEROOT, fragmentRoot.getKind()); children.add(node); if (fragmentRoot instanceof JrtPackageFragmentRoot) { @@ -154,7 +157,7 @@ private static List getPackageFragmentRoots(PackageParams query, IP return children; } } catch (CoreException e) { - JavaLanguageServerPlugin.logException("Problem load project JAR entries ", e); + JdtlsExtActivator.logException("Problem load project JAR entries ", e); } } @@ -170,38 +173,38 @@ private static List getPackages(PackageParams query, IProgressMonit IPackageFragmentRoot packageRoot = javaProject.findPackageFragmentRoot(Path.fromPortableString(query.getRootPath())); if (packageRoot == null) { throw new CoreException( - new Status(IStatus.ERROR, JdtlsExtActivator.PLUGIN_ID, - String.format("No package root found for %s", query.getPath()))); + new Status(IStatus.ERROR, JdtlsExtActivator.PLUGIN_ID, String.format("No package root found for %s", query.getPath()))); } Object[] result = getPackageFragmentRootContent(packageRoot, pm); return convertToClasspathNode(result); } catch (CoreException e) { - JavaLanguageServerPlugin.logException("Problem load project package ", e); + JdtlsExtActivator.logException("Problem load project package ", e); } } return Collections.emptyList(); } - private static List getClassfiles(PackageParams query, IProgressMonitor pm) { + private static List getRootTypes(PackageParams query, IProgressMonitor pm) { IJavaProject javaProject = getJavaProject(query.getProjectUri()); if (javaProject != null) { try { 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()))); + new Status(IStatus.ERROR, JdtlsExtActivator.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); + IJavaElement[] types = packageFragment.getChildren(); + return 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); return item; }).collect(Collectors.toList()); } } catch (CoreException e) { - JavaLanguageServerPlugin.logException("Problem load project classfile list ", e); + JdtlsExtActivator.logException("Problem load project classfile list ", e); } } return Collections.emptyList(); @@ -232,7 +235,7 @@ private static List getFolderChildren(PackageParams query, IProgres } } catch (CoreException e) { - JavaLanguageServerPlugin.logException("Problem load project classfile list ", e); + JdtlsExtActivator.logException("Problem load project classfile list ", e); } } return Collections.emptyList(); @@ -264,7 +267,7 @@ private static List convertToClasspathNode(Object[] rootContent) th result.add(entry); } else if (root instanceof IClassFile) { IClassFile classFile = (IClassFile) root; - PackageNode entry = new PackageNode(classFile.getElementName(), null, NodeKind.CLASSFILE); + PackageNode entry = new PackageNode(classFile.getElementName(), null, NodeKind.TYPEROOT); entry.setUri(JDTUtils.toUri(classFile)); result.add(entry); } else if (root instanceof JarEntryResource) { diff --git a/jdtls.ext/com.microsoft.jdtls.ext.core/src/com/microsoft/jdtls/ext/core/model/ContainerNode.java b/jdtls.ext/com.microsoft.jdtls.ext.core/src/com/microsoft/jdtls/ext/core/model/ContainerNode.java index 1350049c..425b8012 100644 --- a/jdtls.ext/com.microsoft.jdtls.ext.core/src/com/microsoft/jdtls/ext/core/model/ContainerNode.java +++ b/jdtls.ext/com.microsoft.jdtls.ext.core/src/com/microsoft/jdtls/ext/core/model/ContainerNode.java @@ -21,10 +21,6 @@ public ContainerNode(String name, String path, NodeKind kind, int entryKind) { this.entryKind = entryKind; } - public ContainerNode() { - - } - public int getEntryType() { return this.entryKind; } diff --git a/jdtls.ext/com.microsoft.jdtls.ext.core/src/com/microsoft/jdtls/ext/core/model/NodeKind.java b/jdtls.ext/com.microsoft.jdtls.ext.core/src/com/microsoft/jdtls/ext/core/model/NodeKind.java index 29caf355..f8764595 100644 --- a/jdtls.ext/com.microsoft.jdtls.ext.core/src/com/microsoft/jdtls/ext/core/model/NodeKind.java +++ b/jdtls.ext/com.microsoft.jdtls.ext.core/src/com/microsoft/jdtls/ext/core/model/NodeKind.java @@ -22,7 +22,7 @@ public enum NodeKind { PACKAGE(5), - CLASSFILE(6), + TYPEROOT(6), Folder(7), diff --git a/jdtls.ext/com.microsoft.jdtls.ext.core/src/com/microsoft/jdtls/ext/core/model/TypeRootNode.java b/jdtls.ext/com.microsoft.jdtls.ext.core/src/com/microsoft/jdtls/ext/core/model/TypeRootNode.java new file mode 100644 index 00000000..979a8de6 --- /dev/null +++ b/jdtls.ext/com.microsoft.jdtls.ext.core/src/com/microsoft/jdtls/ext/core/model/TypeRootNode.java @@ -0,0 +1,36 @@ +/******************************************************************************* + * 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 + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Microsoft Corporation - initial API and implementation + *******************************************************************************/ + +package com.microsoft.jdtls.ext.core.model; + +public class TypeRootNode extends PackageNode { + + /** + * Kind constant for a source file. + */ + public final static int K_SOURCE = 1; + + /** + * Kind constant for a binary type. + */ + public final static int K_BINARY = 2; + + private int entryKind; + + public TypeRootNode(String name, String path, NodeKind kind, int entryKind) { + super(name, path, kind); + this.entryKind = entryKind; + } + + public int getEntryType() { + return this.entryKind; + } +} diff --git a/vscode/images/file_type_java.svg b/vscode/images/file_type_java.svg new file mode 100644 index 00000000..14121c58 --- /dev/null +++ b/vscode/images/file_type_java.svg @@ -0,0 +1 @@ +file_type_java \ No newline at end of file diff --git a/vscode/src/java/nodeData.ts b/vscode/src/java/nodeData.ts index e2a6658a..0bed3076 100644 --- a/vscode/src/java/nodeData.ts +++ b/vscode/src/java/nodeData.ts @@ -5,7 +5,7 @@ export enum NodeKind { Container = 3, PackageRoot = 4, Package = 5, - Classfile = 6, + TypeRoot = 6, Folder = 7, File = 8 } diff --git a/vscode/src/java/typeRootNodeData.ts b/vscode/src/java/typeRootNodeData.ts new file mode 100644 index 00000000..a0e9062e --- /dev/null +++ b/vscode/src/java/typeRootNodeData.ts @@ -0,0 +1,18 @@ +import { INodeData } from "./nodeData"; + +export enum TypeRootKind { + /** + * Kind constant for a source path root. Indicates this root + * only contains source files. + */ + K_SOURCE = 1, + /** + * Kind constant for a binary path root. Indicates this + * root only contains binary files. + */ + K_BINARY = 2 +} + +export interface ITypeRootNodeData extends INodeData { + entryKind: TypeRootKind; +} diff --git a/vscode/src/views/packageNode.ts b/vscode/src/views/packageNode.ts index a2f714d4..4e6b9c39 100644 --- a/vscode/src/views/packageNode.ts +++ b/vscode/src/views/packageNode.ts @@ -4,13 +4,13 @@ import { INodeData, NodeKind } from "../java/nodeData"; import { DataNode } from "./dataNode"; import { ProjectNode } from "./projectNode"; import { Jdtls } from "../java/jdtls"; -import { ClassfileNode } from "./classfileNode"; +import { TypeRootNode } from "./typeRootNode"; export class PackageNode extends DataNode { constructor(nodeData: INodeData, private _project: DataNode, private _rootNode: DataNode) { super(nodeData); } - + protected loadData(): Thenable { return Jdtls.getPackageData({ kind: NodeKind.Package, projectUri: this._project.nodeData.uri, path: this.nodeData.name, rootPath: this._rootNode.path }); } @@ -19,13 +19,13 @@ export class PackageNode extends DataNode { const result = []; if (this.nodeData.children && this.nodeData.children.length) { this.nodeData.children.forEach((nodeData) => { - result.push(new ClassfileNode(nodeData)); + result.push(new TypeRootNode(nodeData)); }); } return result; } - protected get iconPath() : string { + protected get iconPath(): string { return "./images/package.png"; } } diff --git a/vscode/src/views/packageRootNode.ts b/vscode/src/views/packageRootNode.ts index 564bf397..25111fdb 100644 --- a/vscode/src/views/packageRootNode.ts +++ b/vscode/src/views/packageRootNode.ts @@ -2,14 +2,16 @@ import { DataNode } from "./dataNode"; import { INodeData, NodeKind } from "../java/nodeData"; import { Jdtls } from "../java/jdtls"; import { ExplorerNode } from "./explorerNode"; -import { ClassfileNode } from "./classfileNode"; +import { TypeRootNode } from "./typeRootNode"; import { FolderNode } from "./folderNode"; import { FileNode } from "./fileNode"; import { PackageNode } from "./packageNode"; import { ProjectNode } from "./projectNode"; import { IPackageRootNodeData, PackageRootKind } from "../java/packageRootNodeData"; +import { IContainerNodeData } from "../java/containerNodeData"; export class PackageRootNode extends DataNode { + constructor(nodeData: INodeData, private _project: ProjectNode) { super(nodeData); } @@ -28,8 +30,8 @@ export class PackageRootNode extends DataNode { result.push(new FileNode(data)); } else if (data.kind === NodeKind.Folder) { result.push(new FolderNode(data, this._project, this)); - } else if (data.kind === NodeKind.Classfile) { - result.push(new ClassfileNode(data)); + } else if (data.kind === NodeKind.TypeRoot) { + result.push(new TypeRootNode(data)); } }); } diff --git a/vscode/src/views/projectNode.ts b/vscode/src/views/projectNode.ts index 47c41ac9..81a9c5e0 100644 --- a/vscode/src/views/projectNode.ts +++ b/vscode/src/views/projectNode.ts @@ -49,6 +49,11 @@ export class ProjectNode extends DataNode { } }); } + + result.sort((a: DataNode, b: DataNode) => { + return b.nodeData.kind - a.nodeData.kind; + }); + return result; } diff --git a/vscode/src/views/srcFileNode.ts b/vscode/src/views/srcFileNode.ts deleted file mode 100644 index e69de29b..00000000 diff --git a/vscode/src/views/classfileNode.ts b/vscode/src/views/typeRootNode.ts similarity index 67% rename from vscode/src/views/classfileNode.ts rename to vscode/src/views/typeRootNode.ts index 6f0e2cd1..a2098226 100644 --- a/vscode/src/views/classfileNode.ts +++ b/vscode/src/views/typeRootNode.ts @@ -3,8 +3,9 @@ import { ExplorerNode } from "./explorerNode"; import { DataNode } from "./dataNode"; import { TreeItem, TreeItemCollapsibleState } from "vscode"; import { Services } from "../services"; +import { ITypeRootNodeData, TypeRootKind } from "../java/typeRootNodeData"; -export class ClassfileNode extends DataNode { +export class TypeRootNode extends DataNode { constructor(nodeData: INodeData) { super(nodeData); } @@ -27,6 +28,11 @@ export class ClassfileNode extends DataNode { } protected get iconPath(): string { - return "./images/classfile.png"; + const data = this.nodeData; + if (data.entryKind === TypeRootKind.K_BINARY) { + return "./images/classfile.png"; + } else { + return "./images/file_type_java.svg"; + } } } \ No newline at end of file