-
Notifications
You must be signed in to change notification settings - Fork 82
/
Copy pathutility.ts
49 lines (39 loc) · 1.43 KB
/
utility.ts
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
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT license.
import { isJavaIdentifier, isKeyword } from "../utility";
import { DataNode } from "../views/dataNode";
import { ExplorerNode } from "../views/explorerNode";
export function isMutable(node: DataNode): boolean {
// avoid modify dependency files
const packageExp = /java:(package|packageRoot)(?=.*?\b\+(source|resource)\b)(?=.*?\b\+uri\b)/;
const resourceOrTypeExp = /java:(file|type|folder)(?=.*?\b\+uri\b)/;
const contextValue = node.computeContextValue();
if (!contextValue) {
return false;
}
return packageExp.test(contextValue) || resourceOrTypeExp.test(contextValue);
}
export function checkJavaQualifiedName(value: string): string {
if (!value || !value.trim()) {
return "Input cannot be empty.";
}
for (const part of value.split(".")) {
if (isKeyword(part)) {
return `Keyword '${part}' cannot be used.`;
}
if (!isJavaIdentifier(part)) {
return `Invalid Java qualified name.`;
}
}
return "";
}
export function getCmdNode(selectedNodes: readonly ExplorerNode[], node?: DataNode): DataNode | undefined {
// if command not invoked by context menu, use selected node in explorer
if (node) {
return node;
}
if (selectedNodes.length > 0) {
return selectedNodes[0] as DataNode;
}
return undefined;
}