Skip to content

Commit b0bd0c2

Browse files
committed
8256755: Update build.tools.depend.Depend to handle record components in API signatures
Reviewed-by: jlahoda
1 parent 9aeadbb commit b0bd0c2

File tree

2 files changed

+41
-2
lines changed

2 files changed

+41
-2
lines changed

make/jdk/src/classes/build/tools/depend/Depend.java

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2017, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2017, 2020, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -59,6 +59,7 @@
5959
import javax.lang.model.element.ModuleElement.UsesDirective;
6060
import javax.lang.model.element.PackageElement;
6161
import javax.lang.model.element.QualifiedNameable;
62+
import javax.lang.model.element.RecordComponentElement;
6263
import javax.lang.model.element.TypeElement;
6364
import javax.lang.model.element.TypeParameterElement;
6465
import javax.lang.model.element.VariableElement;
@@ -258,6 +259,13 @@ public Void visitType(TypeElement e, Void p) {
258259
return null;
259260
}
260261

262+
@Override
263+
public Void visitRecordComponent(@SuppressWarnings("preview")RecordComponentElement e, Void p) {
264+
update(e.getSimpleName());
265+
visit(e.asType());
266+
return null;
267+
}
268+
261269
@Override
262270
public Void visitVariable(VariableElement e, Void p) {
263271
visit(e.asType());

make/jdk/src/classes/build/tools/depend/DependTest.java

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2017, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2017, 2020, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* 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 {
5151
test.testFields();
5252
test.testModules();
5353
test.testAnnotations();
54+
test.testRecords();
5455
}
5556

5657
public void testMethods() throws Exception {
@@ -191,6 +192,36 @@ public void testModules() throws Exception {
191192
true);
192193
}
193194

195+
public void testRecords() throws Exception {
196+
doOrdinaryTest("package test; public record Test (int x, int y) { }",
197+
"package test; public record Test (int x, int y) { }", // identical
198+
false);
199+
doOrdinaryTest("package test; public record Test (int x, int y) { }",
200+
"package test; public record Test (int x, int y) {" +
201+
"public Test { } }", // compact ctr
202+
false);
203+
doOrdinaryTest("package test; public record Test (int x, int y) { }",
204+
"package test; public record Test (int x, int y) {" +
205+
"public Test (int x, int y) { this.x=x; this.y=y;} }", // canonical ctr
206+
false);
207+
doOrdinaryTest("package test; public record Test (int x, int y) { }",
208+
"package test; public record Test (int y, int x) { }", // reverse
209+
true);
210+
doOrdinaryTest("package test; public record Test (int x, int y) { }",
211+
"package test; public record Test (int x, int y, int z) { }", // additional
212+
true);
213+
doOrdinaryTest("package test; public record Test (int x, int y) { }",
214+
"package test; public record Test () { }", // empty
215+
true);
216+
doOrdinaryTest("package test; public record Test (int x, int y) { }",
217+
"package test; /*package*/ record Test (int x, int y) { }", // package
218+
true);
219+
doOrdinaryTest("package test; public record Test (int x, int y) { }",
220+
"package test; public record Test (int x, int y) {" +
221+
"public Test (int x, int y, int z) { this(x, y); } }", // additional ctr
222+
true);
223+
}
224+
194225
private final JavaCompiler compiler = ToolProvider.getSystemJavaCompiler();
195226
private Path depend;
196227
private Path scratchServices;

0 commit comments

Comments
 (0)