clean up some minor formatting / code style issues
This commit is contained in:
parent
23109af6e4
commit
fdae11f791
|
@ -30,6 +30,7 @@ import javax.lang.model.element.TypeElement;
|
||||||
import javax.lang.model.type.DeclaredType;
|
import javax.lang.model.type.DeclaredType;
|
||||||
import javax.lang.model.type.TypeKind;
|
import javax.lang.model.type.TypeKind;
|
||||||
import javax.lang.model.type.TypeMirror;
|
import javax.lang.model.type.TypeMirror;
|
||||||
|
import javax.lang.model.util.Elements;
|
||||||
import javax.tools.Diagnostic;
|
import javax.tools.Diagnostic;
|
||||||
import javax.tools.StandardLocation;
|
import javax.tools.StandardLocation;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
@ -41,6 +42,7 @@ import java.util.HashSet;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
import java.util.function.Function;
|
||||||
|
|
||||||
import static java.lang.Boolean.parseBoolean;
|
import static java.lang.Boolean.parseBoolean;
|
||||||
import static javax.lang.model.util.ElementFilter.fieldsIn;
|
import static javax.lang.model.util.ElementFilter.fieldsIn;
|
||||||
|
@ -374,7 +376,8 @@ public class HibernateProcessor extends AbstractProcessor {
|
||||||
// skip it completely
|
// skip it completely
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
else if ( isEntityOrEmbeddable( element ) && !element.getModifiers().contains( Modifier.PRIVATE )) {
|
else if ( isEntityOrEmbeddable( element )
|
||||||
|
&& !element.getModifiers().contains( Modifier.PRIVATE ) ) {
|
||||||
context.logMessage( Diagnostic.Kind.OTHER, "Processing annotated entity class '" + element + "'" );
|
context.logMessage( Diagnostic.Kind.OTHER, "Processing annotated entity class '" + element + "'" );
|
||||||
handleRootElementAnnotationMirrors( element, parent );
|
handleRootElementAnnotationMirrors( element, parent );
|
||||||
}
|
}
|
||||||
|
@ -409,30 +412,14 @@ public class HibernateProcessor extends AbstractProcessor {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if ( enclosesEntityOrEmbeddable( element ) ) {
|
if ( enclosesEntityOrEmbeddable( element ) ) {
|
||||||
AnnotationMetaEntity parentMeta = null;
|
final NonManagedMetamodel metaEntity =
|
||||||
if ( parent instanceof TypeElement parentElement ) {
|
NonManagedMetamodel.create( typeElement, context, false,
|
||||||
final String key = parentElement.getQualifiedName().toString();
|
parentMetadata( parent, context::getMetamodel ) );
|
||||||
if ( context.getMetamodel( key ) instanceof AnnotationMetaEntity parentMetaEntity ) {
|
|
||||||
parentMeta = parentMetaEntity;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
final NonManagedMetamodel metaEntity =
|
|
||||||
NonManagedMetamodel .create(
|
|
||||||
typeElement, context,
|
|
||||||
false, parentMeta );
|
|
||||||
context.addMetaEntity( metaEntity.getQualifiedName(), metaEntity );
|
context.addMetaEntity( metaEntity.getQualifiedName(), metaEntity );
|
||||||
if ( context.generateJakartaDataStaticMetamodel()) {
|
if ( context.generateJakartaDataStaticMetamodel() ) {
|
||||||
AnnotationMetaEntity parentDataMeta = null;
|
final NonManagedMetamodel dataMetaEntity =
|
||||||
if ( parent instanceof TypeElement parentElement ) {
|
NonManagedMetamodel.create( typeElement, context, true,
|
||||||
final String key = parentElement.getQualifiedName().toString();
|
parentMetadata( parent, context::getDataMetaEntity ) );
|
||||||
if ( context.getDataMetaEntity( key ) instanceof AnnotationMetaEntity parentMetaEntity ) {
|
|
||||||
parentDataMeta = parentMetaEntity;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
final NonManagedMetamodel dataMetaEntity =
|
|
||||||
NonManagedMetamodel .create(
|
|
||||||
typeElement, context,
|
|
||||||
true, parentDataMeta );
|
|
||||||
context.addDataMetaEntity( dataMetaEntity.getQualifiedName(), dataMetaEntity );
|
context.addDataMetaEntity( dataMetaEntity.getQualifiedName(), dataMetaEntity );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -448,16 +435,28 @@ public class HibernateProcessor extends AbstractProcessor {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch ( ProcessLaterException processLaterException ) {
|
catch ( ProcessLaterException processLaterException ) {
|
||||||
if ( element instanceof TypeElement ) {
|
if ( element instanceof TypeElement typeElement ) {
|
||||||
context.logMessage(
|
context.logMessage(
|
||||||
Diagnostic.Kind.OTHER,
|
Diagnostic.Kind.OTHER,
|
||||||
"Could not process '" + element + "' (will redo in next round)"
|
"Could not process '" + element + "' (will redo in next round)"
|
||||||
);
|
);
|
||||||
context.addElementToRedo( ( (TypeElement) element ).getQualifiedName() );
|
context.addElementToRedo( typeElement.getQualifiedName() );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private @Nullable AnnotationMetaEntity parentMetadata(
|
||||||
|
@Nullable Element parent, Function<String, @Nullable Object> metamodel) {
|
||||||
|
if ( parent instanceof TypeElement parentElement
|
||||||
|
&& metamodel.apply( parentElement.getQualifiedName().toString() )
|
||||||
|
instanceof AnnotationMetaEntity parentMetaEntity ) {
|
||||||
|
return parentMetaEntity;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private boolean hasPackageAnnotation(Element element, String annotation) {
|
private boolean hasPackageAnnotation(Element element, String annotation) {
|
||||||
final PackageElement pack = context.getElementUtils().getPackageOf( element ); // null for module descriptor
|
final PackageElement pack = context.getElementUtils().getPackageOf( element ); // null for module descriptor
|
||||||
return pack != null && hasAnnotation( pack, annotation );
|
return pack != null && hasAnnotation( pack, annotation );
|
||||||
|
@ -562,15 +561,18 @@ public class HibernateProcessor extends AbstractProcessor {
|
||||||
}
|
}
|
||||||
|
|
||||||
private static boolean enclosesEntityOrEmbeddable(Element element) {
|
private static boolean enclosesEntityOrEmbeddable(Element element) {
|
||||||
if ( !(element instanceof TypeElement typeElement) ) {
|
if ( element instanceof TypeElement typeElement ) {
|
||||||
|
for ( final Element enclosedElement : typeElement.getEnclosedElements() ) {
|
||||||
|
if ( isEntityOrEmbeddable( enclosedElement )
|
||||||
|
|| enclosesEntityOrEmbeddable( enclosedElement ) ) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
for ( final Element enclosedElement : typeElement.getEnclosedElements() ) {
|
else {
|
||||||
if ( isEntityOrEmbeddable( enclosedElement ) || enclosesEntityOrEmbeddable( enclosedElement ) ) {
|
return false;
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private static boolean isEntityOrEmbeddable(Element element) {
|
private static boolean isEntityOrEmbeddable(Element element) {
|
||||||
|
@ -621,14 +623,8 @@ public class HibernateProcessor extends AbstractProcessor {
|
||||||
+ "' since XML configuration is metadata complete.");
|
+ "' since XML configuration is metadata complete.");
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
AnnotationMetaEntity parentMetaEntity = null;
|
final AnnotationMetaEntity parentMetaEntity =
|
||||||
if ( parent instanceof TypeElement parentTypeElement ) {
|
parentMetadata( parent, context::getMetamodel );
|
||||||
if ( context.getMetamodel(
|
|
||||||
parentTypeElement.getQualifiedName().toString() )
|
|
||||||
instanceof AnnotationMetaEntity pme ) {
|
|
||||||
parentMetaEntity = pme;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
final boolean requiresLazyMemberInitialization
|
final boolean requiresLazyMemberInitialization
|
||||||
= hasAnnotation( element, EMBEDDABLE, MAPPED_SUPERCLASS );
|
= hasAnnotation( element, EMBEDDABLE, MAPPED_SUPERCLASS );
|
||||||
final AnnotationMetaEntity metaEntity =
|
final AnnotationMetaEntity metaEntity =
|
||||||
|
@ -648,13 +644,8 @@ public class HibernateProcessor extends AbstractProcessor {
|
||||||
// let a handwritten metamodel "override" the generated one
|
// let a handwritten metamodel "override" the generated one
|
||||||
// (this is used in the Jakarta Data TCK)
|
// (this is used in the Jakarta Data TCK)
|
||||||
&& !hasHandwrittenMetamodel(element) ) {
|
&& !hasHandwrittenMetamodel(element) ) {
|
||||||
AnnotationMetaEntity parentDataEntity = null;
|
final AnnotationMetaEntity parentDataEntity =
|
||||||
if ( parent instanceof TypeElement parentTypeElement ) {
|
parentMetadata( parent, context::getDataMetaEntity );
|
||||||
if ( context.getDataMetaEntity( parentTypeElement.getQualifiedName().toString() )
|
|
||||||
instanceof AnnotationMetaEntity pme ) {
|
|
||||||
parentDataEntity = pme;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
final AnnotationMetaEntity dataMetaEntity =
|
final AnnotationMetaEntity dataMetaEntity =
|
||||||
AnnotationMetaEntity.create( typeElement, context,
|
AnnotationMetaEntity.create( typeElement, context,
|
||||||
requiresLazyMemberInitialization,
|
requiresLazyMemberInitialization,
|
||||||
|
@ -783,13 +774,14 @@ public class HibernateProcessor extends AbstractProcessor {
|
||||||
|
|
||||||
private void writeIndex() {
|
private void writeIndex() {
|
||||||
final ProcessingEnvironment processingEnvironment = context.getProcessingEnvironment();
|
final ProcessingEnvironment processingEnvironment = context.getProcessingEnvironment();
|
||||||
|
final Elements elementUtils = processingEnvironment.getElementUtils();
|
||||||
context.getEntityNameMappings().forEach((entityName, className) -> {
|
context.getEntityNameMappings().forEach((entityName, className) -> {
|
||||||
try (Writer writer = processingEnvironment.getFiler()
|
try (Writer writer = processingEnvironment.getFiler()
|
||||||
.createResource(
|
.createResource(
|
||||||
StandardLocation.SOURCE_OUTPUT,
|
StandardLocation.SOURCE_OUTPUT,
|
||||||
ENTITY_INDEX,
|
ENTITY_INDEX,
|
||||||
entityName,
|
entityName,
|
||||||
processingEnvironment.getElementUtils().getTypeElement( className )
|
elementUtils.getTypeElement( className )
|
||||||
)
|
)
|
||||||
.openWriter()) {
|
.openWriter()) {
|
||||||
writer.append(className);
|
writer.append(className);
|
||||||
|
@ -801,11 +793,12 @@ public class HibernateProcessor extends AbstractProcessor {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
context.getEnumTypesByValue().forEach((valueName, enumTypeNames) -> {
|
context.getEnumTypesByValue().forEach((valueName, enumTypeNames) -> {
|
||||||
try (Writer writer = processingEnvironment.getFiler().createResource(
|
try (Writer writer = processingEnvironment.getFiler()
|
||||||
|
.createResource(
|
||||||
StandardLocation.SOURCE_OUTPUT,
|
StandardLocation.SOURCE_OUTPUT,
|
||||||
ENTITY_INDEX,
|
ENTITY_INDEX,
|
||||||
'.' + valueName,
|
'.' + valueName,
|
||||||
processingEnvironment.getElementUtils().getTypeElement( enumTypeNames.iterator().next() )
|
elementUtils.getTypeElement( enumTypeNames.iterator().next() )
|
||||||
)
|
)
|
||||||
.openWriter()) {
|
.openWriter()) {
|
||||||
for (String enumTypeName : enumTypeNames) {
|
for (String enumTypeName : enumTypeNames) {
|
||||||
|
|
Loading…
Reference in New Issue