Skip to content

Commit f929a78

Browse files
committed
HHH-18649 nice Javadoc for static TypedQueryReferences
1 parent 975dfa1 commit f929a78

File tree

2 files changed

+24
-7
lines changed

2 files changed

+24
-7
lines changed

tooling/metamodel-generator/src/main/java/org/hibernate/processor/annotation/AnnotationMeta.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ && getAnnotationValue( mirror, "resultClass" ) == null ) {
127127
if ( resultType != null ) {
128128
putMember( "QUERY_" + name,
129129
new TypedMetaAttribute( this, name, "QUERY_", resultType,
130-
"jakarta.persistence.TypedQueryReference" ) );
130+
"jakarta.persistence.TypedQueryReference", hql ) );
131131
}
132132
}
133133
}
@@ -205,11 +205,11 @@ private NameMetaAttribute auxiliaryMember(AnnotationMirror mirror, String prefix
205205
// and then we will replace this TypedMetaAttribute
206206
return new TypedMetaAttribute( this, name, prefix,
207207
resultClass == null ? JAVA_OBJECT : resultClass.getValue().toString(),
208-
"jakarta.persistence.TypedQueryReference" );
208+
"jakarta.persistence.TypedQueryReference", null );
209209
}
210210
else if ( !isJakartaDataStyle() && "GRAPH_".equals(prefix) ) {
211211
return new TypedMetaAttribute( this, name, prefix, getQualifiedName(),
212-
"jakarta.persistence.EntityGraph" );
212+
"jakarta.persistence.EntityGraph", null );
213213
}
214214
else {
215215
return new NameMetaAttribute( this, name, prefix);

tooling/metamodel-generator/src/main/java/org/hibernate/processor/annotation/TypedMetaAttribute.java

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,28 +4,34 @@
44
*/
55
package org.hibernate.processor.annotation;
66

7+
import org.checkerframework.checker.nullness.qual.Nullable;
78
import org.hibernate.processor.model.Metamodel;
89

910
import static org.hibernate.processor.util.StringUtil.nameToMethodName;
1011

1112
/**
13+
* Represents a named query or named entity graph.
14+
*
1215
* @author Gavin King
1316
*/
1417
class 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

Comments
 (0)