8153268: javac accepts enums being referenced by 'uses' statement
Reviewed-by: jjg
This commit is contained in:
parent
8c11293294
commit
9f41228dab
@ -102,6 +102,7 @@ import com.sun.tools.javac.tree.JCTree.JCDirective;
|
||||
import com.sun.tools.javac.tree.JCTree.Tag;
|
||||
|
||||
import static com.sun.tools.javac.code.Flags.ABSTRACT;
|
||||
import static com.sun.tools.javac.code.Flags.ENUM;
|
||||
import static com.sun.tools.javac.code.Flags.PUBLIC;
|
||||
import static com.sun.tools.javac.tree.JCTree.Tag.MODULEDEF;
|
||||
|
||||
@ -753,7 +754,10 @@ public class Modules extends JCTree.Visitor {
|
||||
@Override
|
||||
public void visitUses(JCUses tree) {
|
||||
Type st = attr.attribType(tree.qualid, env, syms.objectType);
|
||||
if (st.hasTag(CLASS)) {
|
||||
Symbol sym = TreeInfo.symbol(tree.qualid);
|
||||
if ((sym.flags() & ENUM) != 0) {
|
||||
log.error(tree.qualid.pos(), Errors.ServiceDefinitionIsEnum(st.tsym));
|
||||
} else if (st.hasTag(CLASS)) {
|
||||
ClassSymbol service = (ClassSymbol) st.tsym;
|
||||
Directive.UsesDirective d = new Directive.UsesDirective(service);
|
||||
if (!allUses.add(d)) {
|
||||
|
@ -2718,6 +2718,10 @@ compiler.err.service.implementation.is.inner=\
|
||||
compiler.err.service.definition.is.inner=\
|
||||
the service definition is an inner class: {0}
|
||||
|
||||
# 0: symbol
|
||||
compiler.err.service.definition.is.enum=\
|
||||
the service definition is an enum: {0}
|
||||
|
||||
# 0: symbol
|
||||
compiler.err.service.implementation.doesnt.have.a.no.args.constructor=\
|
||||
the service implementation does not have a default constructor: {0}
|
||||
|
@ -146,6 +146,7 @@ compiler.err.package.empty.or.not.found
|
||||
compiler.err.package.in.other.module
|
||||
compiler.err.processorpath.no.processormodulepath
|
||||
compiler.err.service.definition.is.inner
|
||||
compiler.err.service.definition.is.enum
|
||||
compiler.err.service.implementation.doesnt.have.a.no.args.constructor
|
||||
compiler.err.service.implementation.is.abstract
|
||||
compiler.err.service.implementation.is.inner
|
||||
|
@ -81,6 +81,29 @@ public class UsesTest extends ModuleTestBase {
|
||||
.writeAll();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testEnumAsAService(Path base) throws Exception {
|
||||
Path src = base.resolve("src");
|
||||
tb.writeJavaFiles(src,
|
||||
"module m { uses pkg.EnumST; }",
|
||||
"package pkg; public enum EnumST {A, B}");
|
||||
Path classes = base.resolve("classes");
|
||||
Files.createDirectories(classes);
|
||||
|
||||
List<String> output = new JavacTask(tb)
|
||||
.options("-XDrawDiagnostics")
|
||||
.outdir(classes)
|
||||
.files(tb.findJavaFiles(src))
|
||||
.run(Task.Expect.FAIL)
|
||||
.writeAll()
|
||||
.getOutputLines(Task.OutputKind.DIRECT);
|
||||
List<String> expected = Arrays.asList("module-info.java:1:20: compiler.err.service.definition.is.enum: pkg.EnumST",
|
||||
"1 error");
|
||||
if (!output.containsAll(expected)) {
|
||||
throw new Exception("Expected output not found");
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSimpleAnnotation(Path base) throws Exception {
|
||||
Path src = base.resolve("src");
|
||||
|
Loading…
Reference in New Issue
Block a user