Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -412,15 +412,15 @@ public boolean checkNamedQuery(String name) {
public void setUsesQuarkusOrm(boolean b) {
usesQuarkusOrm = b;
}

public boolean usesQuarkusOrm() {
return usesQuarkusOrm;
}

public void setUsesQuarkusReactive(boolean b) {
usesQuarkusReactive = b;
}

public boolean usesQuarkusReactive() {
return usesQuarkusReactive;
}
Expand Down Expand Up @@ -504,7 +504,21 @@ public Map<String,Set<String>> getEnumTypesByValue() {
return enumTypesByValue;
}

public void addEnumValue(String type, String value) {
enumTypesByValue.computeIfAbsent( value, s -> new TreeSet<>() ).add( type );
public void addEnumValue(
String qualifiedTypeName, String shortTypeName,
@Nullable String outerTypeQualifiedName, @Nullable String outerShortTypeName,
String value) {
addEnumValue( qualifiedTypeName, value );
addEnumValue( qualifiedTypeName, qualifiedTypeName + '.' + value );
addEnumValue( qualifiedTypeName, shortTypeName + '.' + value );
if ( outerShortTypeName != null ) {
addEnumValue( qualifiedTypeName, outerShortTypeName + '.' + shortTypeName + '.' + value );
addEnumValue( qualifiedTypeName, outerShortTypeName + '$' + shortTypeName + '.' + value );
addEnumValue( qualifiedTypeName, outerTypeQualifiedName + '$' + shortTypeName + '.' + value );
}
}

private void addEnumValue(String qualifiedTypeName, String value) {
enumTypesByValue.computeIfAbsent( value, s -> new TreeSet<>() ).add( qualifiedTypeName );
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -646,9 +646,15 @@ private void indexEnumValues(TypeMirror type) {
final DeclaredType declaredType = (DeclaredType) type;
final TypeElement fieldType = (TypeElement) declaredType.asElement();
if ( fieldType.getKind() == ElementKind.ENUM ) {
for (Element enumMember : fieldType.getEnclosedElements() ) {
for ( Element enumMember : fieldType.getEnclosedElements() ) {
if ( enumMember.getKind() == ElementKind.ENUM_CONSTANT ) {
final Element enclosingElement = fieldType.getEnclosingElement();
final boolean hasOuterType =
enclosingElement.getKind().isClass() || enclosingElement.getKind().isInterface();
context.addEnumValue( fieldType.getQualifiedName().toString(),
fieldType.getSimpleName().toString(),
hasOuterType ? ((TypeElement) enclosingElement).getQualifiedName().toString() : null,
hasOuterType ? enclosingElement.getSimpleName().toString() : null,
enumMember.getSimpleName().toString() );
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@
import org.hibernate.query.sqm.tree.expression.SqmParameter;
import org.hibernate.query.sqm.tree.select.SqmSelectStatement;

import javax.annotation.processing.ProcessingEnvironment;
import javax.lang.model.element.AnnotationMirror;
import javax.lang.model.element.AnnotationValue;
import javax.lang.model.element.Element;
Expand All @@ -51,7 +50,6 @@
import javax.lang.model.type.TypeMirror;
import javax.lang.model.type.TypeVariable;
import javax.lang.model.type.WildcardType;
import javax.lang.model.util.Elements;
import javax.lang.model.util.Types;
import javax.tools.Diagnostic;
import java.util.ArrayList;
Expand Down Expand Up @@ -86,10 +84,12 @@
import static org.hibernate.processor.util.TypeUtils.containsAnnotation;
import static org.hibernate.processor.util.TypeUtils.determineAccessTypeForHierarchy;
import static org.hibernate.processor.util.TypeUtils.determineAnnotationSpecifiedAccessType;
import static org.hibernate.processor.util.TypeUtils.extendsClass;
import static org.hibernate.processor.util.TypeUtils.findMappedSuperClass;
import static org.hibernate.processor.util.TypeUtils.getAnnotationMirror;
import static org.hibernate.processor.util.TypeUtils.getAnnotationValue;
import static org.hibernate.processor.util.TypeUtils.hasAnnotation;
import static org.hibernate.processor.util.TypeUtils.implementsInterface;
import static org.hibernate.processor.util.TypeUtils.primitiveClassMatchesKind;
import static org.hibernate.processor.util.TypeUtils.propertyName;

Expand Down Expand Up @@ -660,41 +660,18 @@ boolean needsDefaultConstructor() {
}

private boolean isPanacheType(TypeElement type) {
return isOrmPanacheType( type )
|| isReactivePanacheType( type );
return context.usesQuarkusOrm() && isOrmPanacheType( type )
|| context.usesQuarkusReactive() && isReactivePanacheType( type );
}

private boolean isOrmPanacheType(TypeElement type) {
final ProcessingEnvironment processingEnvironment = context.getProcessingEnvironment();
final Elements elements = processingEnvironment.getElementUtils();
final TypeElement panacheRepositorySuperType = elements.getTypeElement( PANACHE_ORM_REPOSITORY_BASE );
final TypeElement panacheEntitySuperType = elements.getTypeElement( PANACHE_ORM_ENTITY_BASE );
if ( panacheRepositorySuperType == null || panacheEntitySuperType == null ) {
return false;
}
else {
final Types types = processingEnvironment.getTypeUtils();
// check against a raw supertype of PanacheRepositoryBase, which .asType() is not
return types.isSubtype( type.asType(), types.getDeclaredType( panacheRepositorySuperType ) )
|| types.isSubtype( type.asType(), panacheEntitySuperType.asType() );
}
return implementsInterface( type, PANACHE_ORM_REPOSITORY_BASE )
|| extendsClass( type, PANACHE_ORM_ENTITY_BASE );
}

private boolean isReactivePanacheType(TypeElement type) {
final ProcessingEnvironment processingEnvironment = context.getProcessingEnvironment();
final Elements elements = processingEnvironment.getElementUtils();
final TypeElement panacheRepositorySuperType = elements.getTypeElement( PANACHE_REACTIVE_REPOSITORY_BASE );
final TypeElement panacheEntitySuperType = elements.getTypeElement( PANACHE_REACTIVE_ENTITY_BASE );

if ( panacheRepositorySuperType == null || panacheEntitySuperType == null ) {
return false;
}
else {
final Types types = processingEnvironment.getTypeUtils();
// check against a raw supertype of PanacheRepositoryBase, which .asType() is not
return types.isSubtype( type.asType(), types.getDeclaredType( panacheRepositorySuperType ) )
|| types.isSubtype( type.asType(), panacheEntitySuperType.asType() );
}
return implementsInterface( type, PANACHE_REACTIVE_REPOSITORY_BASE )
|| extendsClass( type, PANACHE_REACTIVE_ENTITY_BASE );
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -129,12 +129,11 @@ protected TypeMirror defaultAction(TypeMirror e, Void aVoid) {
}

public static @Nullable TypeElement getSuperclassTypeElement(TypeElement element) {
final TypeMirror superClass = element.getSuperclass();
final TypeMirror superclass = element.getSuperclass();
//superclass of Object is of NoType which returns some other kind
if ( superClass.getKind() == TypeKind.DECLARED ) {
//F..king Ch...t Have those people used their horrible APIs even once?
final Element superClassElement = ( (DeclaredType) superClass ).asElement();
return (TypeElement) superClassElement;
if ( superclass.getKind() == TypeKind.DECLARED ) {
final DeclaredType declaredType = (DeclaredType) superclass;
return (TypeElement) declaredType.asElement();
}
else {
return null;
Expand Down Expand Up @@ -602,7 +601,7 @@ else if ( element.getKind() == ElementKind.METHOD ) {
return elementsUtil.getName(decapitalize(name.substring(3))).toString();
}
else if ( name.startsWith( "is" ) ) {
return (elementsUtil.getName(decapitalize(name.substring(2)))).toString();
return elementsUtil.getName(decapitalize(name.substring(2))).toString();
}
return elementsUtil.getName(decapitalize(name)).toString();
}
Expand Down Expand Up @@ -654,6 +653,33 @@ private static boolean extendsSuperMetaModel(Element superClassElement, boolean
|| !entityMetaComplete && containsAnnotation( superClassElement, ENTITY, MAPPED_SUPERCLASS );
}

public static boolean implementsInterface(TypeElement type, String interfaceName) {
for ( TypeMirror iface : type.getInterfaces() ) {
if ( iface.getKind() == TypeKind.DECLARED ) {
final DeclaredType declaredType = (DeclaredType) iface;
final TypeElement typeElement = (TypeElement) declaredType.asElement();
if ( typeElement.getQualifiedName().contentEquals( interfaceName )
|| implementsInterface( typeElement, interfaceName ) ) {
return true;
}
}
}
return false;
}

public static boolean extendsClass(TypeElement type, String className) {
TypeMirror superclass = type.getSuperclass();
while ( superclass != null && superclass.getKind() == TypeKind.DECLARED ) {
final DeclaredType declaredType = (DeclaredType) superclass;
final TypeElement typeElement = (TypeElement) declaredType.asElement();
if ( typeElement.getQualifiedName().contentEquals( className ) ) {
return true;
}
superclass = typeElement.getSuperclass();
}
return false;
}

static class EmbeddedAttributeVisitor extends SimpleTypeVisitor8<@Nullable TypeElement, Element> {
private final Context context;

Expand All @@ -665,7 +691,7 @@ static class EmbeddedAttributeVisitor extends SimpleTypeVisitor8<@Nullable TypeE
public @Nullable TypeElement visitDeclared(DeclaredType declaredType, Element element) {
final TypeElement returnedElement = (TypeElement)
context.getTypeUtils().asElement( declaredType );
return containsAnnotation( NullnessUtil.castNonNull( returnedElement ), EMBEDDABLE ) ? returnedElement : null;
return containsAnnotation( castNonNull( returnedElement ), EMBEDDABLE ) ? returnedElement : null;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,6 @@
import static org.hibernate.internal.util.StringHelper.root;
import static org.hibernate.internal.util.StringHelper.split;
import static org.hibernate.internal.util.StringHelper.unroot;
import static org.hibernate.metamodel.model.domain.internal.JpaMetamodelImpl.addAllowedEnumLiteralsToEnumTypesMap;
import static org.hibernate.processor.util.Constants.JAVA_OBJECT;

/**
Expand Down Expand Up @@ -92,7 +91,7 @@ public static MockSessionFactory create(
private final Types typeUtil;
private final Filer filer;
private final Map<String, String> entityNameMappings;
private final Map<String, Set<String>> allowedEnumLiteralsToEnumTypeNames;
private final Map<String, Set<String>> enumTypesByValue;

public ProcessorSessionFactory(
ProcessingEnvironment processingEnvironment,
Expand All @@ -102,23 +101,7 @@ public ProcessorSessionFactory(
typeUtil = processingEnvironment.getTypeUtils();
filer = processingEnvironment.getFiler();
this.entityNameMappings = entityNameMappings;
final Map<String, Set<String>> allowedEnumLiteralsToEnumTypeNames = new HashMap<>( enumTypesByValue.size() << 2 );
for ( Map.Entry<String, Set<String>> entry : enumTypesByValue.entrySet() ) {
final String enumConstantName = entry.getKey();
for ( String enumClassName : entry.getValue() ) {
final TypeElement enumTypeElement = elementUtil.getTypeElement( enumClassName );
if ( enumTypeElement != null ) {
addAllowedEnumLiteralsToEnumTypesMap(
allowedEnumLiteralsToEnumTypeNames,
enumConstantName,
enumTypeElement.getSimpleName().toString(),
elementUtil.getBinaryName( enumTypeElement ).toString(),
enumClassName
);
}
}
}
this.allowedEnumLiteralsToEnumTypeNames = allowedEnumLiteralsToEnumTypeNames;
this.enumTypesByValue = enumTypesByValue;
}

@Override
Expand Down Expand Up @@ -236,7 +219,7 @@ private static JdbcType enumJdbcType(Element member) {

@Override @Nullable
Set<String> getEnumTypesForValue(String value) {
Set<String> result = allowedEnumLiteralsToEnumTypeNames.get( value);
Set<String> result = enumTypesByValue.get(value);
if ( result != null ) {
return result;
}
Expand Down
Loading