forked from microsoft/vscode-java-pack
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmisc.ts
More file actions
65 lines (54 loc) · 1.43 KB
/
Copy pathmisc.ts
File metadata and controls
65 lines (54 loc) · 1.43 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
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT license.
import * as path from "path";
export function sourceLevelDisplayName(ver: string | number) {
if (!ver) {
return "";
}
if (ver === "1.5" || ver === 5) {
return "J2SE-1.5";
}
if (typeof ver === "number") {
return ver <= 8 ? `JavaSE-1.${ver}` : `JavaSE-${ver}`;
} else {
return `JavaSE-${ver}`;
}
}
export function sourceLevelMajorVersion(level: string): number {
if (!level) {
return 0;
}
let version = level.replace(/^.*-/, ""); // remove "JaveSE-"
// Ignore "1." prefix for legacy Java versions
if (version.startsWith("1.")) {
version = version.substring(2);
}
// look into the interesting bits now
const regexp = /\d+/g;
const match = regexp.exec(version);
let javaVersion = 0;
if (match) {
javaVersion = parseInt(match[0], 10);
}
return javaVersion;
}
export function isSamePath(a: string, b: string): boolean {
return !!(a && b) && path.relative(a, b) === "";
}
export function getMajorVersion(version: string) {
if (!version) {
return 0;
}
// Ignore "1." prefix for legacy Java versions
if (version.startsWith("1.")) {
version = version.substring(2);
}
// look into the interesting bits now
const regexp = /\d+/g;
const match = regexp.exec(version);
let javaVersion = 0;
if (match) {
javaVersion = parseInt(match[0], 10);
}
return javaVersion;
}