Skip to content

Commit

Permalink
8256755: Update build.tools.depend.Depend to handle record components…
Browse files Browse the repository at this point in the history
… in API signatures

Reviewed-by: jlahoda
  • Loading branch information
ChrisHegarty committed Nov 25, 2020
1 parent 9aeadbb commit b0bd0c2
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 2 deletions.
10 changes: 9 additions & 1 deletion 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
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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());
Expand Down
33 changes: 32 additions & 1 deletion 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
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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;
Expand Down

1 comment on commit b0bd0c2

@openjdk-notifier
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.