From b0bd0c24aa4a3a7b0029b5f44d2076d0decdaf6c Mon Sep 17 00:00:00 2001 From: Chris Hegarty Date: Wed, 25 Nov 2020 11:37:19 +0000 Subject: [PATCH] 8256755: Update build.tools.depend.Depend to handle record components in API signatures Reviewed-by: jlahoda --- .../classes/build/tools/depend/Depend.java | 10 +++++- .../build/tools/depend/DependTest.java | 33 ++++++++++++++++++- 2 files changed, 41 insertions(+), 2 deletions(-) diff --git a/make/jdk/src/classes/build/tools/depend/Depend.java b/make/jdk/src/classes/build/tools/depend/Depend.java index ba7e882dbe465..2a2a568ef368f 100644 --- a/make/jdk/src/classes/build/tools/depend/Depend.java +++ b/make/jdk/src/classes/build/tools/depend/Depend.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2017, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2017, 2020, 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 @@ -59,6 +59,7 @@ import javax.lang.model.element.ModuleElement.UsesDirective; import javax.lang.model.element.PackageElement; import javax.lang.model.element.QualifiedNameable; +import javax.lang.model.element.RecordComponentElement; import javax.lang.model.element.TypeElement; import javax.lang.model.element.TypeParameterElement; import javax.lang.model.element.VariableElement; @@ -258,6 +259,13 @@ public Void visitType(TypeElement e, Void p) { return null; } + @Override + public Void visitRecordComponent(@SuppressWarnings("preview")RecordComponentElement e, Void p) { + update(e.getSimpleName()); + visit(e.asType()); + return null; + } + @Override public Void visitVariable(VariableElement e, Void p) { visit(e.asType()); diff --git a/make/jdk/src/classes/build/tools/depend/DependTest.java b/make/jdk/src/classes/build/tools/depend/DependTest.java index 1cc53bf48f056..4d23c5f27ccfe 100644 --- a/make/jdk/src/classes/build/tools/depend/DependTest.java +++ b/make/jdk/src/classes/build/tools/depend/DependTest.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2017, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2017, 2020, 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 @@ -51,6 +51,7 @@ public static void main(String... args) throws Exception { test.testFields(); test.testModules(); test.testAnnotations(); + test.testRecords(); } public void testMethods() throws Exception { @@ -191,6 +192,36 @@ public void testModules() throws Exception { true); } + public void testRecords() throws Exception { + doOrdinaryTest("package test; public record Test (int x, int y) { }", + "package test; public record Test (int x, int y) { }", // identical + false); + doOrdinaryTest("package test; public record Test (int x, int y) { }", + "package test; public record Test (int x, int y) {" + + "public Test { } }", // compact ctr + false); + doOrdinaryTest("package test; public record Test (int x, int y) { }", + "package test; public record Test (int x, int y) {" + + "public Test (int x, int y) { this.x=x; this.y=y;} }", // canonical ctr + false); + doOrdinaryTest("package test; public record Test (int x, int y) { }", + "package test; public record Test (int y, int x) { }", // reverse + true); + doOrdinaryTest("package test; public record Test (int x, int y) { }", + "package test; public record Test (int x, int y, int z) { }", // additional + true); + doOrdinaryTest("package test; public record Test (int x, int y) { }", + "package test; public record Test () { }", // empty + true); + doOrdinaryTest("package test; public record Test (int x, int y) { }", + "package test; /*package*/ record Test (int x, int y) { }", // package + true); + doOrdinaryTest("package test; public record Test (int x, int y) { }", + "package test; public record Test (int x, int y) {" + + "public Test (int x, int y, int z) { this(x, y); } }", // additional ctr + true); + } + private final JavaCompiler compiler = ToolProvider.getSystemJavaCompiler(); private Path depend; private Path scratchServices;