31
31
import java .util .stream .Collectors ;
32
32
33
33
import javax .lang .model .element .Element ;
34
+ import javax .lang .model .element .ExecutableElement ;
34
35
import javax .lang .model .element .ModuleElement ;
35
36
import javax .lang .model .element .PackageElement ;
36
37
import javax .lang .model .element .TypeElement ;
@@ -87,7 +88,6 @@ public class CommentHelper {
87
88
public final TreePath path ;
88
89
public final DocCommentTree dcTree ;
89
90
public final Element element ;
90
- private Element overriddenElement ;
91
91
92
92
public static final String SPACER = " " ;
93
93
@@ -106,13 +106,6 @@ public CommentHelper(BaseConfiguration configuration, Element element, TreePath
106
106
this .dcTree = dcTree ;
107
107
}
108
108
109
- public void setOverrideElement (Element ove ) {
110
- if (this .element == ove ) {
111
- throw new AssertionError ("cannot set given element as overridden element" );
112
- }
113
- overriddenElement = ove ;
114
- }
115
-
116
109
public String getTagName (DocTree dtree ) {
117
110
switch (dtree .getKind ()) {
118
111
case AUTHOR :
@@ -679,22 +672,28 @@ public ReferenceTree getType(DocTree dtree) {
679
672
}
680
673
681
674
public DocTreePath getDocTreePath (DocTree dtree ) {
682
- if (dcTree == null && overriddenElement != null ) {
683
- // This is an inherited comment, return path from ancestor.
684
- return configuration . utils . getCommentHelper ( overriddenElement ). getDocTreePath ( dtree );
685
- } else if (path == null || dcTree == null || dtree == null ) {
675
+ if (dcTree == null && element instanceof ExecutableElement ee ) {
676
+ return getInheritedDocTreePath ( dtree , ee );
677
+ }
678
+ if (path == null || dcTree == null || dtree == null ) {
686
679
return null ;
687
680
}
688
681
DocTreePath dtPath = DocTreePath .getPath (path , dcTree , dtree );
689
- if (dtPath == null && overriddenElement != null ) {
682
+ if (dtPath == null && element instanceof ExecutableElement ee ) {
690
683
// The overriding element has a doc tree, but it doesn't contain what we're looking for.
691
- return configuration . utils . getCommentHelper ( overriddenElement ). getDocTreePath ( dtree );
684
+ return getInheritedDocTreePath ( dtree , ee );
692
685
}
693
686
return dtPath ;
694
687
}
695
688
696
- public Element getOverriddenElement () {
697
- return overriddenElement ;
689
+ private DocTreePath getInheritedDocTreePath (DocTree dtree , ExecutableElement ee ) {
690
+ Utils utils = configuration .utils ;
691
+ DocFinder .Output inheritedDoc =
692
+ DocFinder .search (configuration ,
693
+ new DocFinder .Input (utils , ee ));
694
+ return inheritedDoc == null || inheritedDoc .holder == ee
695
+ ? null
696
+ : utils .getCommentHelper (inheritedDoc .holder ).getDocTreePath (dtree );
698
697
}
699
698
700
699
/**
@@ -708,14 +707,6 @@ public String toString() {
708
707
sb .append (element .getEnclosingElement ());
709
708
sb .append ("::" );
710
709
sb .append (element );
711
- sb .append (", overriddenElement=" );
712
- if (overriddenElement != null ) {
713
- sb .append (overriddenElement .getEnclosingElement ());
714
- sb .append ("::" );
715
- sb .append (overriddenElement );
716
- } else {
717
- sb .append ("<none>" );
718
- }
719
710
sb .append ('}' );
720
711
return sb .toString ();
721
712
}
0 commit comments