Navigation Menu

Skip to content
This repository has been archived by the owner on Sep 19, 2023. It is now read-only.

Commit

Permalink
8275784: Bogus warning generated for record with compact constructor
Browse files Browse the repository at this point in the history
Reviewed-by: prappo
  • Loading branch information
jonathan-gibbons committed Jun 28, 2022
1 parent 6f9717b commit a814293
Show file tree
Hide file tree
Showing 2 changed files with 73 additions and 2 deletions.
Expand Up @@ -33,6 +33,7 @@
import java.util.EnumSet;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
Expand All @@ -47,6 +48,7 @@
import javax.lang.model.element.ExecutableElement;
import javax.lang.model.element.Name;
import javax.lang.model.element.NestingKind;
import javax.lang.model.element.RecordComponentElement;
import javax.lang.model.element.TypeElement;
import javax.lang.model.element.VariableElement;
import javax.lang.model.type.TypeKind;
Expand Down Expand Up @@ -244,8 +246,10 @@ public Void scan(DocCommentTree tree, TreePath p) {
} else if (isExecutable()) {
if (!isOverridingMethod) {
ExecutableElement ee = (ExecutableElement) env.currElement;
checkParamsDocumented(ee.getTypeParameters());
checkParamsDocumented(ee.getParameters());
if (!isCanonicalRecordConstructor(ee)) {
checkParamsDocumented(ee.getTypeParameters());
checkParamsDocumented(ee.getParameters());
}
switch (ee.getReturnType().getKind()) {
case VOID, NONE -> { }
default -> {
Expand All @@ -263,6 +267,31 @@ public Void scan(DocCommentTree tree, TreePath p) {
return null;
}

private boolean isCanonicalRecordConstructor(ExecutableElement ee) {
TypeElement te = (TypeElement) ee.getEnclosingElement();
if (te.getKind() != ElementKind.RECORD) {
return false;
}
List<? extends RecordComponentElement> stateComps = te.getRecordComponents();
List<? extends VariableElement> params = ee.getParameters();
if (stateComps.size() != params.size()) {
return false;
}

Iterator<? extends RecordComponentElement> stateIter = stateComps.iterator();
Iterator<? extends VariableElement> paramIter = params.iterator();
while (paramIter.hasNext() && stateIter.hasNext()) {
VariableElement param = paramIter.next();
RecordComponentElement comp = stateIter.next();
if (!Objects.equals(param.getSimpleName(), comp.getSimpleName())
|| !env.types.isSameType(param.asType(), comp.asType())) {
return false;
}
}

return true;
}

private void reportMissing(String code, Object... args) {
env.messages.report(MISSING, Kind.WARNING, env.currPath.getLeaf(), code, args);
}
Expand Down
42 changes: 42 additions & 0 deletions test/langtools/tools/doclint/RecordCompactConstructorTest.java
@@ -0,0 +1,42 @@
/*
* Copyright (c) 2022, 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
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
* or visit www.oracle.com if you need additional information or have any
* questions.
*/

/*
* @test /nodynamiccopyright/
* @bug 8275784
* @summary Bogus warning generated for record with compact constructor
* @modules jdk.javadoc/jdk.javadoc.internal.doclint
* @build DocLintTester
* @run main DocLintTester -Xmsgs:all RecordCompactConstructorTest.java
*/

/**
* Comment.
* @param a aaa
* @param b bbb
* @param c ccc
*/
public record RecordCompactConstructorTest(int a, int b, int c) {
/** Compact constructor. */
public RecordCompactConstructorTest { }
}

1 comment on commit a814293

@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.