Skip to content

Commit

Permalink
8301618: Compare elements and type mirrors properly
Browse files Browse the repository at this point in the history
Reviewed-by: jjg
  • Loading branch information
pavelrappo committed Feb 1, 2023
1 parent d683212 commit 8d6e8a4
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 31 deletions.
Expand Up @@ -36,6 +36,7 @@
import java.util.ListIterator;
import java.util.Locale;
import java.util.Map;
import java.util.Objects;
import java.util.Optional;
import java.util.Set;
import java.util.regex.Matcher;
Expand Down Expand Up @@ -1543,7 +1544,8 @@ private boolean inSamePackage(Element element) {
Element currentPageElement = (this instanceof PackageWriterImpl packageWriter)
? packageWriter.packageElement : getCurrentPageElement();
return currentPageElement != null && !utils.isModule(element)
&& utils.containingPackage(currentPageElement) == utils.containingPackage(element);
&& Objects.equals(utils.containingPackage(currentPageElement),
utils.containingPackage(element));
}

/**
Expand Down
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2003, 2022, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2003, 2023, 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 @@ -295,15 +295,15 @@ private void buildInheritedSummary(MemberSummaryWriter writer,
if (!(utils.isPublic(inheritedClass) || utils.isLinkable(inheritedClass))) {
continue;
}
if (inheritedClass == typeElement) {
if (Objects.equals(inheritedClass, typeElement)) {
continue;
}
if (utils.hasHiddenTag(inheritedClass)) {
continue;
}

List<? extends Element> members = inheritedMembersFromMap.stream()
.filter(e -> utils.getEnclosingTypeElement(e) == inheritedClass)
.filter(e -> Objects.equals(utils.getEnclosingTypeElement(e), inheritedClass))
.toList();

if (!members.isEmpty()) {
Expand All @@ -318,13 +318,15 @@ private void buildInheritedSummary(MemberSummaryWriter writer,
}
}

private void addSummaryFootNote(TypeElement inheritedClass, SortedSet<Element> inheritedMembers,
private void addSummaryFootNote(TypeElement inheritedClass, Iterable<Element> inheritedMembers,
Content links, MemberSummaryWriter writer) {
for (Element member : inheritedMembers) {
boolean isFirst = true;
for (var iterator = inheritedMembers.iterator(); iterator.hasNext(); ) {
var member = iterator.next();
TypeElement t = utils.isUndocumentedEnclosure(inheritedClass)
? typeElement : inheritedClass;
writer.addInheritedMemberSummary(t, member, inheritedMembers.first() == member,
inheritedMembers.last() == member, links);
writer.addInheritedMemberSummary(t, member, isFirst, !iterator.hasNext(), links);
isFirst = false;
}
}

Expand Down
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2003, 2022, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2003, 2023, 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 All @@ -26,6 +26,8 @@
package jdk.javadoc.internal.doclets.toolkit.builders;


import java.util.Collection;
import java.util.Iterator;
import java.util.List;
import java.util.SortedSet;
import java.util.TreeSet;
Expand Down Expand Up @@ -263,19 +265,15 @@ protected void buildClassContent(Content target) throws DocletException {
*/
protected void buildSerializableMethods(Content target) throws DocletException {
Content serializableMethodsHeader = methodWriter.getSerializableMethodsHeader();
SortedSet<ExecutableElement> members = utils.serializationMethods(currentTypeElement);
if (!members.isEmpty()) {
for (ExecutableElement member : members) {
currentMember = member;
Content methodsContent = methodWriter.getMethodsContentHeader(
currentMember == members.last());
for (var i = utils.serializationMethods(currentTypeElement).iterator(); i.hasNext(); ) {
currentMember = i.next();
Content methodsContent = methodWriter.getMethodsContentHeader(!i.hasNext());

buildMethodSubHeader(methodsContent);
buildDeprecatedMethodInfo(methodsContent);
buildMethodInfo(methodsContent);
buildMethodSubHeader(methodsContent);
buildDeprecatedMethodInfo(methodsContent);
buildMethodInfo(methodsContent);

serializableMethodsHeader.add(methodsContent);
}
serializableMethodsHeader.add(methodsContent);
}
if (!utils.serializationMethods(currentTypeElement).isEmpty()) {
target.add(methodWriter.getSerializableMethods(
Expand Down Expand Up @@ -400,14 +398,13 @@ public void buildFieldSerializationOverview(TypeElement typeElement, Content cla
*/
protected void buildSerializableFields(Content target)
throws DocletException {
SortedSet<VariableElement> members = utils.serializableFields(currentTypeElement);
Collection<VariableElement> members = utils.serializableFields(currentTypeElement);
if (!members.isEmpty()) {
Content serializableFieldsHeader = fieldWriter.getSerializableFieldsHeader();
for (VariableElement ve : members) {
currentMember = ve;
for (var i = members.iterator(); i.hasNext();) {
currentMember = i.next();
if (!utils.definesSerializableFields(currentTypeElement)) {
Content fieldsContent = fieldWriter.getFieldsContentHeader(
currentMember == members.last());
Content fieldsContent = fieldWriter.getFieldsContentHeader(!i.hasNext());

buildFieldSubHeader(fieldsContent);
buildFieldDeprecationInfo(fieldsContent);
Expand Down
@@ -1,5 +1,5 @@
/*
* Copyright (c) 1999, 2022, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 1999, 2023, 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 @@ -418,7 +418,7 @@ public boolean definesSerializableFields(TypeElement aclass) {
}

public boolean isFunctionalInterface(AnnotationMirror amirror) {
return amirror.getAnnotationType().equals(getFunctionalInterface()) &&
return typeUtils.isSameType(amirror.getAnnotationType(), getFunctionalInterface()) &&
configuration.docEnv.getSourceVersion()
.compareTo(SourceVersion.RELEASE_8) >= 0;
}
Expand Down
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2018, 2022, Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 2018, 2023, 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 @@ -53,6 +53,7 @@
import java.util.LinkedHashSet;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.Set;
import java.util.function.Predicate;
import java.util.stream.Stream;
Expand Down Expand Up @@ -242,7 +243,7 @@ public List<Element> getVisibleMembers(Kind kind, Predicate<Element> p) {
public List<Element> getVisibleMembers(Kind kind) {
Predicate<Element> declaredAndLeafMembers = e -> {
TypeElement encl = utils.getEnclosingTypeElement(e);
return encl == te || utils.isUndocumentedEnclosure(encl);
return Objects.equals(encl, te) || utils.isUndocumentedEnclosure(encl);
};
return getVisibleMembers(kind, declaredAndLeafMembers);
}
Expand All @@ -255,7 +256,7 @@ public List<Element> getVisibleMembers(Kind kind) {
* @return a list of visible enclosed members in this type
*/
public List<Element> getMembers(Kind kind) {
Predicate<Element> onlyLocallyDeclaredMembers = e -> utils.getEnclosingTypeElement(e) == te;
Predicate<Element> onlyLocallyDeclaredMembers = e -> Objects.equals(utils.getEnclosingTypeElement(e), te);
return getVisibleMembers(kind, onlyLocallyDeclaredMembers);
}

Expand Down Expand Up @@ -904,7 +905,7 @@ private void computeVisibleProperties(LocalMemberTable lmt) {

List<ExecutableElement> propertyMethods = list.stream()
.map(e -> (ExecutableElement) e)
.filter(e -> utils.getEnclosingTypeElement(e) == te)
.filter(e -> Objects.equals(utils.getEnclosingTypeElement(e), te))
.toList();

// Compute additional properties related sundries.
Expand Down

1 comment on commit 8d6e8a4

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