Search in sources :

Example 1 with MetaEntity

use of org.hibernate.jpamodelgen.model.MetaEntity in project hibernate-orm by hibernate.

the class JPAMetaModelEntityProcessor method modelGenerationNeedsToBeDeferred.

private boolean modelGenerationNeedsToBeDeferred(Collection<MetaEntity> entities, MetaEntity containedEntity) {
    ContainsAttributeTypeVisitor visitor = new ContainsAttributeTypeVisitor(containedEntity.getTypeElement(), context);
    for (MetaEntity entity : entities) {
        if (entity.equals(containedEntity)) {
            continue;
        }
        for (Element subElement : ElementFilter.fieldsIn(entity.getTypeElement().getEnclosedElements())) {
            TypeMirror mirror = subElement.asType();
            if (!TypeKind.DECLARED.equals(mirror.getKind())) {
                continue;
            }
            boolean contains = mirror.accept(visitor, subElement);
            if (contains) {
                return true;
            }
        }
        for (Element subElement : ElementFilter.methodsIn(entity.getTypeElement().getEnclosedElements())) {
            TypeMirror mirror = subElement.asType();
            if (!TypeKind.DECLARED.equals(mirror.getKind())) {
                continue;
            }
            boolean contains = mirror.accept(visitor, subElement);
            if (contains) {
                return true;
            }
        }
    }
    return false;
}
Also used : TypeMirror(javax.lang.model.type.TypeMirror) MetaEntity(org.hibernate.jpamodelgen.model.MetaEntity) AnnotationMetaEntity(org.hibernate.jpamodelgen.annotation.AnnotationMetaEntity) TypeElement(javax.lang.model.element.TypeElement) Element(javax.lang.model.element.Element)

Example 2 with MetaEntity

use of org.hibernate.jpamodelgen.model.MetaEntity in project hibernate-orm by hibernate.

the class JPAMetaModelEntityProcessor method handleRootElementAnnotationMirrors.

private void handleRootElementAnnotationMirrors(final Element element) {
    List<? extends AnnotationMirror> annotationMirrors = element.getAnnotationMirrors();
    for (AnnotationMirror mirror : annotationMirrors) {
        if (!ElementKind.CLASS.equals(element.getKind())) {
            continue;
        }
        String fqn = ((TypeElement) element).getQualifiedName().toString();
        MetaEntity alreadyExistingMetaEntity = tryGettingExistingEntityFromContext(mirror, fqn);
        if (alreadyExistingMetaEntity != null && alreadyExistingMetaEntity.isMetaComplete()) {
            String msg = "Skipping processing of annotations for " + fqn + " since xml configuration is metadata complete.";
            context.logMessage(Diagnostic.Kind.OTHER, msg);
            continue;
        }
        boolean requiresLazyMemberInitialization = false;
        AnnotationMetaEntity metaEntity;
        if (TypeUtils.containsAnnotation(element, Constants.EMBEDDABLE) || TypeUtils.containsAnnotation(element, Constants.MAPPED_SUPERCLASS)) {
            requiresLazyMemberInitialization = true;
        }
        metaEntity = new AnnotationMetaEntity((TypeElement) element, context, requiresLazyMemberInitialization);
        if (alreadyExistingMetaEntity != null) {
            metaEntity.mergeInMembers(alreadyExistingMetaEntity);
        }
        addMetaEntityToContext(mirror, metaEntity);
    }
}
Also used : AnnotationMirror(javax.lang.model.element.AnnotationMirror) AnnotationMetaEntity(org.hibernate.jpamodelgen.annotation.AnnotationMetaEntity) MetaEntity(org.hibernate.jpamodelgen.model.MetaEntity) AnnotationMetaEntity(org.hibernate.jpamodelgen.annotation.AnnotationMetaEntity) TypeElement(javax.lang.model.element.TypeElement)

Example 3 with MetaEntity

use of org.hibernate.jpamodelgen.model.MetaEntity in project hibernate-orm by hibernate.

the class JPAMetaModelEntityProcessor method createMetaModelClasses.

private void createMetaModelClasses() {
    for (MetaEntity entity : context.getMetaEntities()) {
        if (context.isAlreadyGenerated(entity.getQualifiedName())) {
            continue;
        }
        context.logMessage(Diagnostic.Kind.OTHER, "Writing meta model for entity " + entity);
        ClassWriter.writeFile(entity, context);
        context.markGenerated(entity.getQualifiedName());
    }
    // we cannot process the delayed entities in any order. There might be dependencies between them.
    // we need to process the top level entities first
    Collection<MetaEntity> toProcessEntities = context.getMetaEmbeddables();
    while (!toProcessEntities.isEmpty()) {
        Set<MetaEntity> processedEntities = new HashSet<MetaEntity>();
        int toProcessCountBeforeLoop = toProcessEntities.size();
        for (MetaEntity entity : toProcessEntities) {
            // see METAGEN-36
            if (context.isAlreadyGenerated(entity.getQualifiedName())) {
                processedEntities.add(entity);
                continue;
            }
            if (modelGenerationNeedsToBeDeferred(toProcessEntities, entity)) {
                continue;
            }
            context.logMessage(Diagnostic.Kind.OTHER, "Writing meta model for embeddable/mapped superclass" + entity);
            ClassWriter.writeFile(entity, context);
            context.markGenerated(entity.getQualifiedName());
            processedEntities.add(entity);
        }
        toProcessEntities.removeAll(processedEntities);
        if (toProcessEntities.size() >= toProcessCountBeforeLoop) {
            context.logMessage(Diagnostic.Kind.ERROR, "Potential endless loop in generation of entities.");
        }
    }
}
Also used : MetaEntity(org.hibernate.jpamodelgen.model.MetaEntity) AnnotationMetaEntity(org.hibernate.jpamodelgen.annotation.AnnotationMetaEntity) HashSet(java.util.HashSet)

Aggregations

AnnotationMetaEntity (org.hibernate.jpamodelgen.annotation.AnnotationMetaEntity)3 MetaEntity (org.hibernate.jpamodelgen.model.MetaEntity)3 TypeElement (javax.lang.model.element.TypeElement)2 HashSet (java.util.HashSet)1 AnnotationMirror (javax.lang.model.element.AnnotationMirror)1 Element (javax.lang.model.element.Element)1 TypeMirror (javax.lang.model.type.TypeMirror)1