mirror of
https://github.com/openjdk/jdk.git
synced 2026-02-03 23:18:28 +00:00
8176572: Javac does not enforce module name restrictions
Reviewed-by: jlahoda
This commit is contained in:
parent
25dbddc731
commit
06143df6a2
@ -2107,10 +2107,32 @@ public class Check {
|
||||
Name moduleName = tree.sym.name;
|
||||
Assert.checkNonNull(moduleName);
|
||||
if (lint.isEnabled(LintCategory.MODULE)) {
|
||||
String moduleNameString = moduleName.toString();
|
||||
int nameLength = moduleNameString.length();
|
||||
if (nameLength > 0 && Character.isDigit(moduleNameString.charAt(nameLength - 1))) {
|
||||
log.warning(Lint.LintCategory.MODULE, tree.qualId.pos(), Warnings.PoorChoiceForModuleName(moduleName));
|
||||
JCExpression qualId = tree.qualId;
|
||||
while (qualId != null) {
|
||||
Name componentName;
|
||||
DiagnosticPosition pos;
|
||||
switch (qualId.getTag()) {
|
||||
case SELECT:
|
||||
JCFieldAccess selectNode = ((JCFieldAccess) qualId);
|
||||
componentName = selectNode.name;
|
||||
pos = selectNode.pos();
|
||||
qualId = selectNode.selected;
|
||||
break;
|
||||
case IDENT:
|
||||
componentName = ((JCIdent) qualId).name;
|
||||
pos = qualId.pos();
|
||||
qualId = null;
|
||||
break;
|
||||
default:
|
||||
throw new AssertionError("Unexpected qualified identifier: " + qualId.toString());
|
||||
}
|
||||
if (componentName != null) {
|
||||
String moduleNameComponentString = componentName.toString();
|
||||
int nameLength = moduleNameComponentString.length();
|
||||
if (nameLength > 0 && Character.isDigit(moduleNameComponentString.charAt(nameLength - 1))) {
|
||||
log.warning(Lint.LintCategory.MODULE, pos, Warnings.PoorChoiceForModuleName(componentName));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -1537,7 +1537,7 @@ compiler.warn.finally.cannot.complete=\
|
||||
|
||||
# 0: name
|
||||
compiler.warn.poor.choice.for.module.name=\
|
||||
module name {0} should avoid terminal digits
|
||||
module name component {0} should avoid terminal digits
|
||||
|
||||
# 0: string
|
||||
compiler.warn.incubating.modules=\
|
||||
|
||||
@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved.
|
||||
* Copyright (c) 2016, 2017 Oracle and/or its affiliates. All rights reserved.
|
||||
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
||||
*
|
||||
* This code is free software; you can redistribute it and/or modify it
|
||||
@ -23,7 +23,7 @@
|
||||
|
||||
/*
|
||||
* @test
|
||||
* @bug 8160181
|
||||
* @bug 8160181 8176572
|
||||
* @summary Add lint warning for digits in module names
|
||||
* @library /tools/lib
|
||||
* @modules
|
||||
@ -63,6 +63,22 @@ public class PoorChoiceForModuleNameTest extends ModuleTestBase {
|
||||
Path src_m3 = src.resolve("mango100");
|
||||
tb.writeJavaFiles(src_m3, "@SuppressWarnings(\"module\") module mango100 { }");
|
||||
|
||||
// Check that there is no warning at use site.
|
||||
Path src_m4 = src.resolve("mangouser");
|
||||
tb.writeJavaFiles(src_m4, "module mangouser { requires mango19; }");
|
||||
|
||||
// Check that we warn about component names ending in digit also
|
||||
Path src_m5 = src.resolve("mango1000.mangofruit.mangomodule");
|
||||
tb.writeJavaFiles(src_m5, "module mango1000.mangofruit.mangomodule { }");
|
||||
|
||||
// Check that we warn about component names ending in digit also
|
||||
Path src_m6 = src.resolve("mangofruit.mango1000.mangomodule");
|
||||
tb.writeJavaFiles(src_m6, "module mangofruit.mango1000.mangomodule { }");
|
||||
|
||||
// Check that we warn about component names ending in digit also
|
||||
Path src_m7 = src.resolve("mangomodule.mangofruit.mango1000");
|
||||
tb.writeJavaFiles(src_m7, "module mangomodule.mangofruit.mango1000 { }");
|
||||
|
||||
Path classes = base.resolve("classes");
|
||||
tb.createDirectories(classes);
|
||||
|
||||
@ -78,9 +94,12 @@ public class PoorChoiceForModuleNameTest extends ModuleTestBase {
|
||||
.getOutput(Task.OutputKind.DIRECT);
|
||||
|
||||
if (!log.contains("module-info.java:1:8: compiler.warn.poor.choice.for.module.name: mango19") ||
|
||||
!log.contains("module-info.java:1:8: compiler.warn.poor.choice.for.module.name: mango1000") ||
|
||||
!log.contains("module-info.java:1:18: compiler.warn.poor.choice.for.module.name: mango1000") ||
|
||||
!log.contains("module-info.java:1:30: compiler.warn.poor.choice.for.module.name: mango1000") ||
|
||||
!log.contains("- compiler.err.warnings.and.werror") ||
|
||||
!log.contains("1 error") ||
|
||||
!log.contains("1 warning"))
|
||||
!log.contains("4 warning"))
|
||||
throw new Exception("expected output not found: " + log);
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user