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 committed by Christian Beikov
parent 0ef361ae0c
commit ef934fb09f
3 changed files with 35 additions and 15 deletions

View File

@ -101,6 +101,14 @@ public final class ClassWriter {
pw.println();
final List<MetaAttribute> members = entity.getMembers();
for ( MetaAttribute metaMember : members ) {
if ( metaMember.hasStringAttribute() ) {
pw.println( '\t' + metaMember.getAttributeNameDeclarationString() );
}
}
pw.println();
for ( MetaAttribute metaMember : members ) {
if ( metaMember.hasTypedAttribute() ) {
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("}");
@ -130,7 +132,11 @@ public final class ClassWriter {
}
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) );
String superClassName = entity.getSupertypeName();

View File

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

View File

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