Skip to content

Commit

Permalink
#9 - Add details about "index" and "element"/"component" types to Mem…
Browse files Browse the repository at this point in the history
…berDetails

#21 - Work on generics / parameterized-types
  • Loading branch information
sebersole committed Jan 24, 2024
1 parent 1003819 commit 767272e
Show file tree
Hide file tree
Showing 11 changed files with 372 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
package org.hibernate.models.internal.dynamic;

import java.lang.reflect.Member;
import java.util.Collection;
import java.util.Map;

import org.hibernate.models.internal.MutableMemberDetails;
import org.hibernate.models.spi.ClassDetails;
Expand All @@ -22,6 +24,9 @@ public class DynamicFieldDetails extends AbstractAnnotationTarget implements Fie
private final ClassDetails declaringType;
private final int modifierFlags;

private final boolean isArray;
private final boolean isPlural;

public DynamicFieldDetails(
String name,
ClassDetails type,
Expand All @@ -33,6 +38,15 @@ public DynamicFieldDetails(
this.type = type;
this.declaringType = declaringType;
this.modifierFlags = modifierFlags;

if ( type != null ) {
this.isArray = type.getName().startsWith( "[" );
this.isPlural = isArray || type.isImplementor( Collection.class ) || type.isImplementor( Map.class );
}
else {
this.isArray = false;
this.isPlural = false;
}
}

@Override
Expand All @@ -50,6 +64,16 @@ public ClassDetails getDeclaringType() {
return declaringType;
}

@Override
public boolean isPlural() {
return isPlural;
}

@Override
public boolean isArray() {
return isArray;
}

@Override
public int getModifiers() {
return modifierFlags;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,10 @@
package org.hibernate.models.internal.dynamic;

import java.lang.reflect.Member;
import java.util.Collection;
import java.util.List;
import java.util.Map;

import org.hibernate.models.internal.ModifierUtils;
import org.hibernate.models.internal.MutableMemberDetails;
import org.hibernate.models.spi.ClassDetails;
import org.hibernate.models.spi.MethodDetails;
Expand All @@ -28,6 +29,9 @@ public class DynamicMethodDetails extends AbstractAnnotationTarget implements Me
private final ClassDetails returnType;
private final List<ClassDetails> argumentTypes;

private final boolean isArray;
private final boolean isPlural;

public DynamicMethodDetails(
String name,
ClassDetails type,
Expand All @@ -45,6 +49,15 @@ public DynamicMethodDetails(
this.modifierFlags = modifierFlags;
this.returnType = returnType;
this.argumentTypes = argumentTypes;

if ( type != null ) {
this.isArray = type.getName().startsWith( "[" );
this.isPlural = isArray || type.isImplementor( Collection.class ) || type.isImplementor( Map.class );
}
else {
this.isArray = false;
this.isPlural = false;
}
}

@Override
Expand All @@ -67,6 +80,16 @@ public ClassDetails getDeclaringType() {
return declaringType;
}

@Override
public boolean isPlural() {
return isPlural;
}

@Override
public boolean isArray() {
return isArray;
}

@Override
public int getModifiers() {
return modifierFlags;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
package org.hibernate.models.internal.dynamic;

import java.lang.reflect.Member;
import java.util.Collection;
import java.util.Map;

import org.hibernate.models.internal.MutableMemberDetails;
import org.hibernate.models.spi.ClassDetails;
Expand All @@ -24,6 +26,9 @@ public class MapModeFieldDetails extends AbstractAnnotationTarget implements Fie
private final int modifierFlags;
private final ClassDetails declaringType;

private final boolean isArray;
private final boolean isPlural;

public MapModeFieldDetails(
String name,
ClassDetails type,
Expand All @@ -35,6 +40,15 @@ public MapModeFieldDetails(
this.type = type;
this.modifierFlags = modifierFlags;
this.declaringType = declaringType;

if ( type != null ) {
this.isArray = type.getName().startsWith( "[" );
this.isPlural = isArray || type.isImplementor( Collection.class ) || type.isImplementor( Map.class );
}
else {
this.isArray = false;
this.isPlural = false;
}
}

@Override
Expand All @@ -52,6 +66,16 @@ public ClassDetails getDeclaringType() {
return declaringType;
}

@Override
public boolean isPlural() {
return isPlural;
}

@Override
public boolean isArray() {
return isArray;
}

@Override
public int getModifiers() {
return modifierFlags;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@

import java.lang.reflect.Field;
import java.lang.reflect.Member;
import java.util.Collection;
import java.util.Map;

import org.hibernate.models.internal.MutableMemberDetails;
import org.hibernate.models.spi.ClassDetails;
Expand All @@ -16,6 +18,7 @@

import org.jboss.jandex.AnnotationTarget;
import org.jboss.jandex.FieldInfo;
import org.jboss.jandex.Type;

/**
* @author Steve Ebersole
Expand All @@ -25,6 +28,9 @@ public class JandexFieldDetails extends AbstractAnnotationTarget implements Fiel
private final ClassDetails type;
private final ClassDetails declaringType;

private final boolean isArray;
private final boolean isPlural;

public JandexFieldDetails(
FieldInfo fieldInfo,
ClassDetails declaringType,
Expand All @@ -33,6 +39,9 @@ public JandexFieldDetails(
this.fieldInfo = fieldInfo;
this.declaringType = declaringType;
this.type = buildingContext.getClassDetailsRegistry().resolveClassDetails( fieldInfo.type().name().toString() );

this.isArray = fieldInfo.type().kind() == Type.Kind.ARRAY;
this.isPlural = isArray || type.isImplementor( Collection.class ) || type.isImplementor( Map.class );
}

@Override
Expand All @@ -55,6 +64,16 @@ public ClassDetails getDeclaringType() {
return declaringType;
}

@Override
public boolean isPlural() {
return isPlural;
}

@Override
public boolean isArray() {
return isArray;
}

@Override
public int getModifiers() {
return fieldInfo.flags();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,10 @@

import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import java.util.Locale;
import java.util.Map;

import org.hibernate.models.internal.MutableMemberDetails;
import org.hibernate.models.spi.ClassDetails;
Expand All @@ -33,6 +35,9 @@ public class JandexMethodDetails extends AbstractAnnotationTarget implements Met
private final ClassDetails returnType;
private final List<ClassDetails> argumentTypes;

private final boolean isArray;
private final boolean isPlural;

public JandexMethodDetails(
MethodInfo methodInfo,
MethodKind methodKind,
Expand All @@ -52,6 +57,15 @@ public JandexMethodDetails(
for ( int i = 0; i < methodInfo.parametersCount(); i++ ) {
argumentTypes.add( classDetailsRegistry.resolveClassDetails( methodInfo.parameterType( i ).name().toString() ) );
}

if ( type != null ) {
this.isArray = methodInfo.returnType().kind() == Type.Kind.ARRAY;
this.isPlural = isArray || type.isImplementor( Collection.class ) || type.isImplementor( Map.class );
}
else {
this.isArray = false;
this.isPlural = false;
}
}

@Override
Expand Down Expand Up @@ -79,6 +93,16 @@ public ClassDetails getDeclaringType() {
return declaringType;
}

@Override
public boolean isPlural() {
return isPlural;
}

@Override
public boolean isArray() {
return isArray;
}

@Override
public int getModifiers() {
return methodInfo.flags();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
package org.hibernate.models.internal.jandex;

import java.lang.reflect.Member;
import java.util.Collection;
import java.util.Map;

import org.hibernate.models.internal.MutableMemberDetails;
import org.hibernate.models.spi.ClassDetails;
Expand All @@ -15,6 +17,7 @@

import org.jboss.jandex.AnnotationTarget;
import org.jboss.jandex.RecordComponentInfo;
import org.jboss.jandex.Type;

/**
* @author Steve Ebersole
Expand All @@ -24,6 +27,9 @@ public class JandexRecordComponentDetails extends AbstractAnnotationTarget imple
private final ClassDetails type;
private final ClassDetails declaringType;

private final boolean isArray;
private final boolean isPlural;

public JandexRecordComponentDetails(
RecordComponentInfo recordComponentInfo,
ClassDetails declaringType,
Expand All @@ -32,6 +38,9 @@ public JandexRecordComponentDetails(
this.recordComponentInfo = recordComponentInfo;
this.declaringType = declaringType;
this.type = buildingContext.getClassDetailsRegistry().resolveClassDetails( recordComponentInfo.type().name().toString() );

this.isArray = recordComponentInfo.type().kind() == Type.Kind.ARRAY;
this.isPlural = isArray || type.isImplementor( Collection.class ) || type.isImplementor( Map.class );
}

@Override
Expand All @@ -54,6 +63,16 @@ public ClassDetails getDeclaringType() {
return declaringType;
}

@Override
public boolean isPlural() {
return isPlural;
}

@Override
public boolean isArray() {
return isArray;
}

@Override
public int getModifiers() {
return recordComponentInfo.accessor().flags();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@
package org.hibernate.models.internal.jdk;

import java.lang.reflect.Field;
import java.lang.reflect.Member;
import java.util.Collection;
import java.util.Map;

import org.hibernate.models.internal.MutableMemberDetails;
import org.hibernate.models.spi.ClassDetails;
Expand All @@ -23,6 +24,9 @@ public class JdkFieldDetails extends AbstractAnnotationTarget implements FieldDe
private final JdkClassDetails declaringType;
private final ClassDetails type;

private final boolean isArray;
private final boolean isPlural;

public JdkFieldDetails(Field field, JdkClassDetails declaringType, SourceModelBuildingContext buildingContext) {
super( field::getAnnotations, buildingContext );
this.field = field;
Expand All @@ -31,6 +35,11 @@ public JdkFieldDetails(Field field, JdkClassDetails declaringType, SourceModelBu
field.getType().getName(),
(n) -> JdkBuilders.buildClassDetailsStatic( field.getType(), getBuildingContext() )
);

this.isArray = field.getType().isArray();
this.isPlural = isArray
|| Collection.class.isAssignableFrom( field.getType() )
|| Map.class.isAssignableFrom( field.getType() );
}

@Override
Expand All @@ -53,6 +62,16 @@ public Field toJavaMember() {
return field;
}

@Override
public boolean isPlural() {
return isPlural;
}

@Override
public boolean isArray() {
return isArray;
}

@Override
public int getModifiers() {
return field.getModifiers();
Expand Down
Loading

0 comments on commit 767272e

Please sign in to comment.