forked from microsoft/vscode-java-dependency
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpackageRootNode.ts
More file actions
107 lines (97 loc) · 4.16 KB
/
Copy pathpackageRootNode.ts
File metadata and controls
107 lines (97 loc) · 4.16 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT license.
import { ThemeIcon } from "vscode";
import { Explorer } from "../constants";
import { Jdtls } from "../java/jdtls";
import { INodeData, NodeKind } from "../java/nodeData";
import { IPackageRootNodeData, PackageRootKind } from "../java/packageRootNodeData";
import { Settings } from "../settings";
import { isTest } from "../utility";
import { ContainerNode } from "./containerNode";
import { DataNode } from "./dataNode";
import { ExplorerNode } from "./explorerNode";
import { FileNode } from "./fileNode";
import { FolderNode } from "./folderNode";
import { PackageNode } from "./packageNode";
import { PrimaryTypeNode } from "./PrimaryTypeNode";
import { ProjectNode } from "./projectNode";
export class PackageRootNode extends DataNode {
constructor(nodeData: INodeData, parent: DataNode, protected _project: ProjectNode) {
super(nodeData, parent);
}
public isSourceRoot(): boolean {
return (<IPackageRootNodeData>this.nodeData).entryKind === PackageRootKind.K_SOURCE;
}
protected async loadData(): Promise<INodeData[]> {
return Jdtls.getPackageData({
kind: NodeKind.PackageRoot,
projectUri: this._project.nodeData.uri,
rootPath: this.nodeData.path,
handlerIdentifier: this.nodeData.handlerIdentifier,
isHierarchicalView: Settings.isHierarchicalView(),
});
}
protected createChildNodeList(): ExplorerNode[] {
const result: ExplorerNode[] = [];
if (this.nodeData.children && this.nodeData.children.length) {
this.sort();
this.nodeData.children.forEach((data: INodeData) => {
if (data.kind === NodeKind.Package) {
result.push(new PackageNode(data, this, this._project, this));
} else if (data.kind === NodeKind.File) {
result.push(new FileNode(data, this));
} else if (data.kind === NodeKind.Folder) {
result.push(new FolderNode(data, this, this._project, this));
} else if (data.kind === NodeKind.PrimaryType) {
if (data.metaData && data.metaData[PrimaryTypeNode.K_TYPE_KIND]) {
result.push(new PrimaryTypeNode(data, this, this));
}
}
});
}
return result;
}
protected get description(): string | boolean | undefined {
const data = <IPackageRootNodeData>this.nodeData;
if (data.entryKind === PackageRootKind.K_BINARY) {
return data.path;
} else {
return undefined;
}
}
protected get contextValue(): string {
const data = <IPackageRootNodeData>this.nodeData;
let contextValue: string;
if (data.entryKind === PackageRootKind.K_BINARY) {
contextValue = Explorer.ContextValueType.Jar;
const parent = <ContainerNode>this.getParent();
if (parent.path?.startsWith("REFERENCED_LIBRARIES_PATH")) {
contextValue += "+referencedLibrary";
}
return contextValue;
} else {
contextValue = Explorer.ContextValueType.PackageRoot;
if (isTest(data)) {
contextValue += "+test";
}
if (resourceRoots.includes(this._nodeData.name)) {
// APIs in JDT does not have a consistent result telling whether a package root
// is a source root or resource root, so we hard code some common resources root
// here as a workaround.
contextValue += "+resource";
} else {
contextValue += "+source";
}
return contextValue;
}
}
protected get iconPath(): ThemeIcon {
const data = <IPackageRootNodeData>this.nodeData;
if (data.moduleName || data.entryKind === PackageRootKind.K_SOURCE) {
return new ThemeIcon("file-submodule");
}
// K_BINARY node
return new ThemeIcon("file-zip");
}
}
export const resourceRoots: string[] = ["src/main/resources", "src/test/resources"];