44 */
55package org .hibernate .processor .annotation ;
66
7+ import org .checkerframework .checker .nullness .qual .Nullable ;
78import org .hibernate .processor .model .Metamodel ;
89
910import static org .hibernate .processor .util .StringUtil .nameToMethodName ;
1011
1112/**
13+ * Represents a named query or named entity graph.
14+ *
1215 * @author Gavin King
1316 */
1417class TypedMetaAttribute extends NameMetaAttribute {
1518 private final String prefix ;
1619 private final String resultType ;
1720 private final String referenceType ;
21+ private final @ Nullable String query ;
1822
1923 public TypedMetaAttribute (
2024 Metamodel annotationMetaEntity ,
2125 String name ,
2226 String prefix ,
2327 String resultType ,
24- String referenceType ) {
28+ String referenceType ,
29+ @ Nullable String query ) {
2530 super ( annotationMetaEntity , name , prefix );
2631 this .prefix = prefix ;
2732 this .resultType = resultType ;
2833 this .referenceType = referenceType ;
34+ this .query = query ;
2935 }
3036
3137 @ Override
@@ -35,14 +41,25 @@ public boolean hasTypedAttribute() {
3541
3642 @ Override
3743 public String getAttributeDeclarationString () {
44+ final boolean isQuery = "QUERY_" .equals (prefix ); //UGLY!
3845 final Metamodel entity = getHostingEntity ();
3946 final StringBuilder declaration = new StringBuilder ();
4047 declaration
4148 .append ("\n /**" )
42- .append ("\n * The query named {@value " )
49+ .append ("\n * The " )
50+ .append (isQuery ? "query" : "entity graph" )
51+ .append (" named {@value " )
4352 .append (prefix )
4453 .append (fieldName ())
45- .append ("}\n *\n * @see " )
54+ .append ("}\n " );
55+ if ( query != null ) {
56+ declaration .append (" * <pre>" );
57+ query .lines ()
58+ .forEach ( line -> declaration .append ("\n * " ).append ( line ) );
59+ declaration .append ("\n * </pre>\n " );
60+ }
61+ declaration
62+ .append (" *\n * @see " )
4663 .append (entity .getQualifiedName ())
4764 .append ("\n **/\n " )
4865 .append ("public static volatile " )
@@ -53,7 +70,7 @@ public String getAttributeDeclarationString() {
5370 .append (' ' )
5471 .append ('_' )
5572 .append (nameToMethodName (getPropertyName ()));
56- if ( "QUERY_" . equals ( prefix ) ) { //UGLY!
73+ if ( isQuery ) {
5774 declaration .append ('_' );
5875 }
5976 declaration .append (';' );
0 commit comments