8256755: Update build.tools.depend.Depend to handle record components in API signatures

Reviewed-by: jlahoda
This commit is contained in:
Chris Hegarty 2020-11-25 11:37:19 +00:00
parent 9aeadbb020
commit b0bd0c24aa
2 changed files with 41 additions and 2 deletions

View File

@ -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.RequiresDirective;
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 class Depend implements Plugin {
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());

View File

@ -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 class DependTest {
test.testFields();
test.testModules();
test.testAnnotations();
test.testRecords();
}
public void testMethods() throws Exception {
@ -191,6 +192,36 @@ public class DependTest {
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;