@@ -46,7 +46,7 @@ private class ExprOrStmt extends Element {
4646 }
4747}
4848
49- /** Holds if the given element does not need to be rendered in the AST, due to being compiler-generated. */
49+ /** Holds if the given element does not need to be rendered in the AST, due to being compiler-generated. */
5050private predicate isNotNeeded ( Element el ) {
5151 exists ( InitializerMethod im |
5252 el = im
@@ -58,17 +58,33 @@ private predicate isNotNeeded(Element el) {
5858 )
5959 )
6060 or
61- exists ( Constructor c | c .isDefaultConstructor ( ) |
61+ exists ( Constructor c | c .isDefaultConstructor ( ) |
6262 el = c
6363 or
6464 el .( ExprOrStmt ) .getEnclosingCallable ( ) = c
6565 )
6666 or
67+ exists ( Constructor c , int sline , int eline , int scol , int ecol |
68+ el .( ExprOrStmt ) .getEnclosingCallable ( ) = c
69+ |
70+ el .getLocation ( ) .hasLocationInfo ( _, sline , eline , scol , ecol ) and
71+ c .getLocation ( ) .hasLocationInfo ( _, sline , eline , scol , ecol )
72+ // simply comparing their getLocation() doesn't work as they have distinct but equivalent locations
73+ )
74+ or
6775 isNotNeeded ( el .( Expr ) .getParent * ( ) .( Annotation ) .getAnnotatedElement ( ) )
6876 or
6977 isNotNeeded ( el .( Parameter ) .getCallable ( ) )
7078}
7179
80+ /** Holds if the given field would have the same javadoc and annotations as another field declared in the same declaration */
81+ private predicate duplicateMetadata ( Field f ) {
82+ exists ( FieldDeclaration fd |
83+ f = fd .getAField ( ) and
84+ not f = fd .getField ( 0 )
85+ )
86+ }
87+
7288/**
7389 * Retrieves the canonical QL class(es) for entity `el`
7490 */
@@ -97,14 +113,18 @@ private predicate locationSortKeys(Element ast, string file, int line, int colum
97113 */
98114private newtype TPrintAstNode =
99115 TElementNode ( Element el ) { shouldPrint ( el , _) } or
100- TAnnotationsNode ( Annotatable ann ) { shouldPrint ( ann , _) and ann .hasAnnotation ( ) and not partOfAnnotation ( ann ) } or
116+ TAnnotationsNode ( Annotatable ann ) {
117+ shouldPrint ( ann , _) and ann .hasAnnotation ( ) and not partOfAnnotation ( ann )
118+ } or
101119 TParametersNode ( Callable c ) { shouldPrint ( c , _) and not c .hasNoParameters ( ) } or
102120 TBaseTypesNode ( ClassOrInterface ty ) { shouldPrint ( ty , _) } or
103- TGenericTypeNode ( GenericType ty ) { shouldPrint ( ty , _) } or
121+ TGenericTypeNode ( GenericType ty ) { shouldPrint ( ty , _) } or
104122 TGenericCallableNode ( GenericCallable c ) { shouldPrint ( c , _) } or
105123 TDocumentableNode ( Documentable d ) { shouldPrint ( d , _) and exists ( d .getJavadoc ( ) ) } or
106124 TJavadocNode ( Javadoc jd ) { exists ( Documentable d | d .getJavadoc ( ) = jd | shouldPrint ( d , _) ) } or
107- TJavadocElementNode ( JavadocElement jd ) { exists ( Documentable d | d .getJavadoc ( ) = jd .getParent * ( ) | shouldPrint ( d , _) ) }
125+ TJavadocElementNode ( JavadocElement jd ) {
126+ exists ( Documentable d | d .getJavadoc ( ) = jd .getParent * ( ) | shouldPrint ( d , _) )
127+ }
108128
109129/**
110130 * A node in the output tree.
@@ -201,7 +221,7 @@ abstract class ElementNode extends PrintAstNode, TElementNode {
201221private predicate partOfAnnotation ( Expr e ) {
202222 e instanceof Annotation
203223 or
204- e instanceof ArrayInit and
224+ e instanceof ArrayInit and
205225 partOfAnnotation ( e .getParent ( ) )
206226}
207227
@@ -236,11 +256,12 @@ final class ExprStmtNode extends ElementNode {
236256 el = element .( LocalClassDeclStmt ) .getLocalClass ( )
237257 or
238258 partOfAnnotation ( element ) and
239- el = rank [ childIndex ] ( Element ch , string file , int line , int column |
240- ch = getAnAnnotationChild ( element ) and locationSortKeys ( ch , file , line , column )
241- |
242- ch order by file , line , column
243- )
259+ el =
260+ rank [ childIndex ] ( Element ch , string file , int line , int column |
261+ ch = getAnAnnotationChild ( element ) and locationSortKeys ( ch , file , line , column )
262+ |
263+ ch order by file , line , column
264+ )
244265 )
245266 or
246267 exists ( Element el | result .( AnnotationsNode ) .getAnnotated ( ) = el |
@@ -292,7 +313,7 @@ final class ParameterNode extends ElementNode {
292313 result .( AnnotationsNode ) .getAnnotated ( ) = p
293314 or
294315 childIndex = 0 and
295- result .( ElementNode ) .getElement ( ) .( Expr ) .getParent ( ) = p
316+ result .( ElementNode ) .getElement ( ) .( Expr ) .isNthChildOf ( p , - 1 ) // type
296317 }
297318}
298319
@@ -353,10 +374,10 @@ final class FieldDeclNode extends ElementNode {
353374
354375 override PrintAstNode getChild ( int childIndex ) {
355376 childIndex = - 3 and
356- result .( DocumentableNode ) .getDocumentable ( ) = decl .getAField ( )
377+ result .( DocumentableNode ) .getDocumentable ( ) = decl .getField ( 0 )
357378 or
358379 childIndex = - 2 and
359- result .( AnnotationsNode ) .getAnnotated ( ) = decl .getAField ( )
380+ result .( AnnotationsNode ) .getAnnotated ( ) = decl .getField ( 0 )
360381 or
361382 childIndex = - 1 and
362383 result .( ElementNode ) .getElement ( ) = decl .getTypeAccess ( )
@@ -398,7 +419,7 @@ final class ImportNode extends ElementNode {
398419 ImportNode ( ) { element instanceof Import }
399420}
400421
401- /**
422+ /**
402423 * A node representing a `TypeVariable`.
403424 */
404425final class TypeVariableNode extends ElementNode {
@@ -416,7 +437,9 @@ final class TypeVariableNode extends ElementNode {
416437final class AnnotationsNode extends PrintAstNode , TAnnotationsNode {
417438 Annotatable ann ;
418439
419- AnnotationsNode ( ) { this = TAnnotationsNode ( ann ) and not isNotNeeded ( ann ) }
440+ AnnotationsNode ( ) {
441+ this = TAnnotationsNode ( ann ) and not isNotNeeded ( ann ) and not duplicateMetadata ( ann )
442+ }
420443
421444 override string toString ( ) { result = "(Annotations)" }
422445
@@ -526,13 +549,13 @@ final class GenericCallableNode extends PrintAstNode, TGenericCallableNode {
526549}
527550
528551/**
529- * A node representing the documentation of a `Documentable`.
552+ * A node representing the documentation of a `Documentable`.
530553 * Only rendered if there is at least one `Javadoc` attatched to it.
531554 */
532555final class DocumentableNode extends PrintAstNode , TDocumentableNode {
533556 Documentable d ;
534557
535- DocumentableNode ( ) { this = TDocumentableNode ( d ) }
558+ DocumentableNode ( ) { this = TDocumentableNode ( d ) and not duplicateMetadata ( d ) }
536559
537560 override string toString ( ) { result = "(Javadoc)" }
538561
@@ -542,7 +565,7 @@ final class DocumentableNode extends PrintAstNode, TDocumentableNode {
542565 result .getJavadoc ( ) =
543566 rank [ childIndex ] ( Javadoc jd , string file , int line , int column |
544567 jd .getCommentedElement ( ) = d and jd .getLocation ( ) .hasLocationInfo ( file , line , column , _, _)
545- |
568+ |
546569 jd order by file , line , column
547570 )
548571 }
@@ -554,7 +577,7 @@ final class DocumentableNode extends PrintAstNode, TDocumentableNode {
554577}
555578
556579/**
557- * A node representing a `Javadoc`.
580+ * A node representing a `Javadoc`.
558581 * Only rendered if it is the javadoc of some `Documentable`.
559582 */
560583final class JavadocNode extends PrintAstNode , TJavadocNode {
@@ -576,7 +599,8 @@ final class JavadocNode extends PrintAstNode, TJavadocNode {
576599 Javadoc getJavadoc ( ) { result = jd }
577600}
578601
579- /** A node representing a `JavadocElement`.
602+ /**
603+ * A node representing a `JavadocElement`.
580604 * Only rendered if it is part of the javadoc of some `Documentable`.
581605 */
582606final class JavadocElementNode extends PrintAstNode , TJavadocElementNode {
0 commit comments