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 @@ -101,6 +101,7 @@
import static org.hibernate.processor.util.TypeUtils.getInheritedAnnotationMirror;
import static org.hibernate.processor.util.TypeUtils.hasAnnotation;
import static org.hibernate.processor.util.TypeUtils.implementsInterface;
import static org.hibernate.processor.util.TypeUtils.isPluralAttribute;
import static org.hibernate.processor.util.TypeUtils.primitiveClassMatchesKind;
import static org.hibernate.processor.util.TypeUtils.propertyName;
import static org.hibernate.processor.util.TypeUtils.resolveTypeMirror;
Expand Down Expand Up @@ -2548,7 +2549,7 @@ enum FieldType {
final boolean idClassRef = isIdRef( path ) && hasAnnotation( entityType, ID_CLASS );
final Element member = idClassRef ? null : memberMatchingPath( entityType, path );
if ( member != null ) {
if ( containsAnnotation( member, MANY_TO_MANY, ONE_TO_MANY, ELEMENT_COLLECTION ) ) {
if ( isPluralAttribute( member ) ) {
message( param,
"matching field is a collection",
Diagnostic.Kind.ERROR );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@

import org.checkerframework.checker.nullness.qual.Nullable;
import org.hibernate.processor.Context;
import org.hibernate.processor.util.Constants;

import javax.lang.model.element.Element;
import javax.lang.model.element.TypeElement;
Expand All @@ -18,9 +17,8 @@
import javax.lang.model.util.SimpleTypeVisitor8;
import javax.lang.model.util.Types;

import static org.hibernate.processor.util.NullnessUtil.castNonNull;
import static org.hibernate.processor.util.TypeUtils.getTargetEntity;
import static org.hibernate.processor.util.TypeUtils.isBasicAttribute;
import static org.hibernate.processor.util.TypeUtils.isPluralAttribute;
import static org.hibernate.processor.util.TypeUtils.isPropertyGetter;
import static org.hibernate.processor.util.TypeUtils.toArrayTypeString;
import static org.hibernate.processor.util.TypeUtils.toTypeString;
Expand Down Expand Up @@ -70,20 +68,20 @@ private Types typeUtils() {
@Override
public @Nullable DataAnnotationMetaAttribute visitDeclared(DeclaredType declaredType, Element element) {
final TypeElement returnedElement = (TypeElement) typeUtils().asElement( declaredType );
if ( returnedElement == null ) {
return null;
}
// WARNING: .toString() is necessary here since Name equals does not compare to String
final String returnTypeName = castNonNull( returnedElement ).getQualifiedName().toString();
final String collection = Constants.COLLECTIONS.get( returnTypeName );
final String targetEntity = getTargetEntity( element.getAnnotationMirrors() );
if ( collection != null ) {
if ( isPluralAttribute( element ) ) {
// final String returnTypeName = returnedElement.getQualifiedName().toString();
// final String collection = Constants.COLLECTIONS.get( returnTypeName );
return null;
}
else if ( isBasicAttribute( element, returnedElement, context ) ) {
else {
final String type = targetEntity != null ? targetEntity : returnedElement.getQualifiedName().toString();
return new DataAnnotationMetaAttribute( entity, element, type, path );
}
else {
return null;
}
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
import static org.hibernate.processor.util.TypeUtils.getKeyType;
import static org.hibernate.processor.util.TypeUtils.getTargetEntity;
import static org.hibernate.processor.util.TypeUtils.hasAnnotation;
import static org.hibernate.processor.util.TypeUtils.isBasicAttribute;
import static org.hibernate.processor.util.TypeUtils.isPluralAttribute;
import static org.hibernate.processor.util.TypeUtils.isPropertyGetter;
import static org.hibernate.processor.util.TypeUtils.toArrayTypeString;
import static org.hibernate.processor.util.TypeUtils.toTypeString;
Expand Down Expand Up @@ -70,7 +70,7 @@ private Types typeUtils() {

@Override
public @Nullable AnnotationMetaAttribute visitArray(ArrayType arrayType, Element element) {
if ( hasAnnotation( element, MANY_TO_MANY, ONE_TO_MANY, ELEMENT_COLLECTION ) ) {
if ( isPluralAttribute( element ) ) {
return new AnnotationMetaCollection( entity, element, LIST_ATTRIBUTE,
toTypeString(arrayType.getComponentType()) );
}
Expand All @@ -89,21 +89,25 @@ private Types typeUtils() {
@Override
public @Nullable AnnotationMetaAttribute visitDeclared(DeclaredType declaredType, Element element) {
final TypeElement returnedElement = (TypeElement) typeUtils().asElement( declaredType );
assert returnedElement != null;
if ( returnedElement == null ) {
return null;
}
// WARNING: .toString() is necessary here since Name equals does not compare to String
final String returnTypeName = castNonNull( returnedElement ).getQualifiedName().toString();
final String collection = Constants.COLLECTIONS.get( returnTypeName );
final String targetEntity = getTargetEntity( element.getAnnotationMirrors() );
if ( collection != null ) {
return createMetaCollectionAttribute( declaredType, element, returnTypeName, collection, targetEntity );
if ( isPluralAttribute( element ) ) {
final String returnTypeName = returnedElement.getQualifiedName().toString();
final String collection = Constants.COLLECTIONS.get( returnTypeName );
if ( collection != null ) {
return createMetaCollectionAttribute( declaredType, element, returnTypeName, collection, targetEntity );
}
else {
return null;
}
}
else if ( isBasicAttribute( element, returnedElement, context ) ) {
else {
final String type = targetEntity != null ? targetEntity : returnedElement.getQualifiedName().toString();
return new AnnotationMetaSingleAttribute( entity, element, type );
}
else {
return null;
}
}

private AnnotationMetaAttribute createMetaCollectionAttribute(
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@
*/
package org.hibernate.processor.util;

import java.math.BigDecimal;
import java.math.BigInteger;
import java.util.List;
import java.util.Map;
import java.util.Set;
Expand All @@ -21,6 +19,8 @@ public final class Constants {
public static final String MAPPED_SUPERCLASS = "jakarta.persistence.MappedSuperclass";
public static final String EMBEDDABLE = "jakarta.persistence.Embeddable";
public static final String EMBEDDED = "jakarta.persistence.Embedded";
public static final String ENUMERATED = "jakarta.persistence.Enumerated";
public static final String LOB = "jakarta.persistence.Lob";
public static final String ID = "jakarta.persistence.Id";
public static final String ID_CLASS = "jakarta.persistence.IdClass";
public static final String EMBEDDED_ID = "jakarta.persistence.EmbeddedId";
Expand Down Expand Up @@ -191,28 +191,6 @@ public final class Constants {
SPRING_STATELESS_SESSION_PROVIDER
);

//TODO: this is not even an exhaustive list of built-in basic types
// so any logic that relies on incomplete this list is broken!
public static final Set<String> BASIC_TYPES = Set.of(
String.class.getName(),
Boolean.class.getName(),
Byte.class.getName(),
Character.class.getName(),
Short.class.getName(),
Integer.class.getName(),
Long.class.getName(),
Float.class.getName(),
Double.class.getName(),
BigInteger.class.getName(),
BigDecimal.class.getName(),
java.util.Date.class.getName(),
java.util.Calendar.class.getName(),
java.sql.Date.class.getName(),
java.sql.Time.class.getName(),
java.sql.Timestamp.class.getName(),
java.sql.Blob.class.getName()
);

public static final List<String> BASIC_ARRAY_TYPES = List.of(
Character.class.getName(),
Byte.class.getName()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,8 @@
import static org.hibernate.internal.util.StringHelper.split;
import static org.hibernate.processor.util.AccessTypeInformation.DEFAULT_ACCESS_TYPE;
import static org.hibernate.processor.util.Constants.ACCESS;
import static org.hibernate.processor.util.Constants.BASIC;
import static org.hibernate.processor.util.Constants.ELEMENT_COLLECTION;
import static org.hibernate.processor.util.Constants.EMBEDDABLE;
import static org.hibernate.processor.util.Constants.EMBEDDED;
import static org.hibernate.processor.util.Constants.EMBEDDED_ID;
import static org.hibernate.processor.util.Constants.ENTITY;
import static org.hibernate.processor.util.Constants.ID;
Expand Down Expand Up @@ -573,10 +571,9 @@ && isProperty( element.getSimpleName().toString(),
toTypeString( executable.getReturnType() ) );
}

public static boolean isBasicAttribute(Element element, Element returnedElement, Context context) {
return hasAnnotation( element, BASIC, ONE_TO_ONE, MANY_TO_ONE, EMBEDDED, EMBEDDED_ID, ID )
|| hasAnnotation( element, "org.hibernate.annotations.Type") // METAGEN-28
|| returnedElement.asType().accept( new BasicAttributeVisitor( context ), returnedElement );
public static boolean isPluralAttribute(Element element) {
// TODO: should MANY_TO_ANY be on this list?
return hasAnnotation( element, MANY_TO_MANY, ONE_TO_MANY, ELEMENT_COLLECTION );
}

public static @Nullable String getFullyQualifiedClassNameOfTargetEntity(
Expand Down