Skip to content

Commit b2630c8

Browse files
committed
Merge branch 'main' of github.com:FabricMC/fabricmc.net
2 parents 539e29a + c98a76e commit b2630c8

File tree

1 file changed

+13
-1
lines changed

1 file changed

+13
-1
lines changed

scripts/src/lib/template/java.ts

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,14 @@ export function getJavaVersion(minecraftVersion: string): JavaVersion {
6060
return JAVA_21;
6161
}
6262

63-
const JAVA_PACKAGE_REGEX = /^[a-z][a-z0-9_]*(\.[a-z0-9_]+)+[0-9a-z_]$/;
63+
const JAVA_PACKAGE_REGEX = /^[a-z_][a-z0-9_]*(\.[a-z_][a-z0-9_]*)*$/;
64+
const JAVA_RESERVED_WORDS = `
65+
abstract continue for new switch assert default goto package synchronized
66+
boolean do if private this break double implements protected throw byte else
67+
import public throws case enum instanceof return transient catch extends int
68+
short try char final interface static void class finally long strictfp
69+
volatile const float native super while _ true false null
70+
`.trim().split(/\s+/);
6471
const RESERVED_PACKAGE_PREFIXES = ["net.minecraft.", "com.mojang.", "net.fabricmc.", "java."];
6572

6673
export function computePackageNameErrors(packageName: string): string[] {
@@ -70,6 +77,11 @@ export function computePackageNameErrors(packageName: string): string[] {
7077
errorList.push("Package name is not a valid Java package name!");
7178
}
7279

80+
const reservedWordsFound = packageName.split('.').filter(c => JAVA_RESERVED_WORDS.includes(c));
81+
if (reservedWordsFound.length != 0) {
82+
errorList.push(`Package name contains illegal component: '${reservedWordsFound[0]}'`);
83+
}
84+
7385
for (let prefix of RESERVED_PACKAGE_PREFIXES) {
7486
if (packageName.toLowerCase().startsWith(prefix)) {
7587
errorList.push(`Package name starts with '${prefix}', which is reserved!`);

0 commit comments

Comments
 (0)