make Jakarta Data static metamodel into interfaces

Signed-off-by: Gavin King <gavin@hibernate.org>
This commit is contained in:
Gavin King 2024-04-05 22:51:01 +02:00
parent 66838ef44b
commit b0368e7135
3 changed files with 35 additions and 15 deletions

View File

@ -101,6 +101,14 @@ public final class ClassWriter {
pw.println(); pw.println();
final List<MetaAttribute> members = entity.getMembers(); final List<MetaAttribute> members = entity.getMembers();
for ( MetaAttribute metaMember : members ) {
if ( metaMember.hasStringAttribute() ) {
pw.println( '\t' + metaMember.getAttributeNameDeclarationString() );
}
}
pw.println();
for ( MetaAttribute metaMember : members ) { for ( MetaAttribute metaMember : members ) {
if ( metaMember.hasTypedAttribute() ) { if ( metaMember.hasTypedAttribute() ) {
metaMember.getAttributeDeclarationString().lines() metaMember.getAttributeDeclarationString().lines()
@ -116,12 +124,6 @@ public final class ClassWriter {
}); });
} }
} }
pw.println();
for ( MetaAttribute metaMember : members ) {
if ( metaMember.hasStringAttribute() ) {
pw.println( '\t' + metaMember.getAttributeNameDeclarationString() );
}
}
pw.println(); pw.println();
pw.println("}"); pw.println("}");
@ -130,7 +132,11 @@ public final class ClassWriter {
} }
private static void printClassDeclaration(Metamodel entity, PrintWriter pw) { private static void printClassDeclaration(Metamodel entity, PrintWriter pw) {
pw.print( entity.isImplementation() ? "public class " : "public abstract class " ); pw.print( "public " );
if ( !entity.isImplementation() && !entity.isJakartaDataStyle() ) {
pw.print( "abstract " );
}
pw.print( entity.isJakartaDataStyle() ? "interface " : "class " );
pw.print( getGeneratedClassName(entity) ); pw.print( getGeneratedClassName(entity) );
String superClassName = entity.getSupertypeName(); String superClassName = entity.getSupertypeName();

View File

@ -63,7 +63,7 @@ public class DataAnnotationMetaAttribute implements MetaAttribute {
.append( "#") .append( "#")
.append(memberName) .append(memberName)
.append( "\n **/\n" ) .append( "\n **/\n" )
.append( "public static final " ) // .append( "public static final " )
.append( parent.importType( getMetaType() ) ) .append( parent.importType( getMetaType() ) )
.append( "<" ) .append( "<" )
.append( className ) .append( className )
@ -71,21 +71,19 @@ public class DataAnnotationMetaAttribute implements MetaAttribute {
.append( getPropertyName().replace('.','_') ) .append( getPropertyName().replace('.','_') )
.append(" = new ") .append(" = new ")
.append( impl ) .append( impl )
.append( "<>(\"" ) .append( "<>(" )
.append( getPropertyName() ) .append( fieldName() )
.append( "\");" ) .append( ");" )
.toString(); .toString();
} }
@Override @Override
public String getAttributeNameDeclarationString(){ public String getAttributeNameDeclarationString(){
final String fieldName =
getUpperUnderscoreCaseFromLowerCamelCase(getPropertyName().replace('.', '_'));
return new StringBuilder() return new StringBuilder()
.append("public static final ") // .append("public static final ")
.append(parent.importType(String.class.getName())) .append(parent.importType(String.class.getName()))
.append(" ") .append(" ")
.append(fieldName) .append(fieldName())
.append(" = ") .append(" = ")
.append("\"") .append("\"")
.append(getPropertyName()) .append(getPropertyName())
@ -94,6 +92,10 @@ public class DataAnnotationMetaAttribute implements MetaAttribute {
.toString(); .toString();
} }
private String fieldName() {
return getUpperUnderscoreCaseFromLowerCamelCase(getPropertyName().replace('.', '_'));
}
@Override @Override
public String getPropertyName() { public String getPropertyName() {
final String propertyName = propertyName(parent, element); final String propertyName = propertyName(parent, element);

View File

@ -39,12 +39,24 @@ public interface Metamodel extends ImportContext {
Context getContext(); Context getContext();
/**
* Is this an implementation of a repository interface?
*/
boolean isImplementation(); boolean isImplementation();
/**
* Can this be injected into things?
*/
boolean isInjectable(); boolean isInjectable();
/**
* What is its CDI scope for injection?
*/
String scope(); String scope();
/**
* Is it a Jakarta Data style metamodel interface?
*/
boolean isJakartaDataStyle(); boolean isJakartaDataStyle();
List<AnnotationMirror> inheritedAnnotations(); List<AnnotationMirror> inheritedAnnotations();