HHH-8962 - Create a set of light reflection classes

This commit is contained in:
Steve Ebersole 2014-02-12 21:29:57 -06:00
parent c5cbf662b4
commit b2ab350866
12 changed files with 796 additions and 113 deletions

View File

@ -0,0 +1,71 @@
/*
* Hibernate, Relational Persistence for Idiomatic Java
*
* Copyright (c) 2014, Red Hat Inc. or third-party contributors as
* indicated by the @author tags or express copyright attribution
* statements applied by the authors. All third-party contributions are
* distributed under license by Red Hat Inc.
*
* This copyrighted material is made available to anyone wishing to use, modify,
* copy, or redistribute it subject to the terms and conditions of the GNU
* Lesser General Public License, as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
* for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this distribution; if not, write to:
* Free Software Foundation, Inc.
* 51 Franklin Street, Fifth Floor
* Boston, MA 02110-1301 USA
*/
package org.hibernate.metamodel.reflite.internal;
import org.hibernate.metamodel.reflite.spi.ArrayTypeDescriptor;
import org.hibernate.metamodel.reflite.spi.Name;
import org.hibernate.metamodel.reflite.spi.TypeDescriptor;
/**
* @author Steve Ebersole
*/
public class ArrayTypeDescriptorImpl implements ArrayTypeDescriptor {
private final Name name;
private TypeDescriptor componentType;
public ArrayTypeDescriptorImpl(Name name, TypeDescriptor componentType) {
this.name = name;
this.componentType = componentType;
}
@Override
public Name getName() {
return name;
}
@Override
public TypeDescriptor getComponentTypeDescriptor() {
return componentType;
}
@Override
public boolean isInterface() {
return false;
}
@Override
public boolean isVoid() {
return false;
}
@Override
public boolean isArray() {
return true;
}
@Override
public boolean isPrimitive() {
return false;
}
}

View File

@ -23,6 +23,7 @@
*/ */
package org.hibernate.metamodel.reflite.internal; package org.hibernate.metamodel.reflite.internal;
import org.hibernate.metamodel.reflite.spi.ClassDescriptor;
import org.hibernate.metamodel.reflite.spi.FieldDescriptor; import org.hibernate.metamodel.reflite.spi.FieldDescriptor;
import org.hibernate.metamodel.reflite.spi.MethodDescriptor; import org.hibernate.metamodel.reflite.spi.MethodDescriptor;
import org.hibernate.metamodel.reflite.spi.Name; import org.hibernate.metamodel.reflite.spi.Name;
@ -33,21 +34,19 @@
* *
* @author Steve Ebersole * @author Steve Ebersole
*/ */
public class TypeDescriptorImpl implements TypeDescriptor { public class ClassDescriptorImpl implements ClassDescriptor {
private final Name name; private final Name name;
private final boolean isInterface;
private final boolean hasDefaultConstructor;
private TypeDescriptor superType; private TypeDescriptor superType;
private TypeDescriptor[] interfaces; private TypeDescriptor[] interfaces;
private final boolean hasDefaultConstructor;
private FieldDescriptor[] fieldDescriptors; private FieldDescriptor[] fieldDescriptors;
private MethodDescriptor[] methodDescriptors; private MethodDescriptor[] methodDescriptors;
public TypeDescriptorImpl(Name name, boolean isInterface, boolean hasDefaultConstructor) { public ClassDescriptorImpl(Name name, boolean hasDefaultConstructor) {
this.name = name; this.name = name;
this.isInterface = isInterface;
this.hasDefaultConstructor = hasDefaultConstructor; this.hasDefaultConstructor = hasDefaultConstructor;
} }
@ -58,12 +57,22 @@ public Name getName() {
@Override @Override
public boolean isInterface() { public boolean isInterface() {
return isInterface; return false;
} }
@Override @Override
public boolean hasDefaultConstructor() { public boolean isVoid() {
return hasDefaultConstructor; return false;
}
@Override
public boolean isPrimitive() {
return false;
}
@Override
public boolean isArray() {
return false;
} }
@Override @Override
@ -76,6 +85,11 @@ public TypeDescriptor[] getInterfaceTypes() {
return interfaces; return interfaces;
} }
@Override
public boolean hasDefaultConstructor() {
return hasDefaultConstructor;
}
@Override @Override
public FieldDescriptor[] getDeclaredFields() { public FieldDescriptor[] getDeclaredFields() {
return fieldDescriptors; return fieldDescriptors;

View File

@ -32,10 +32,10 @@
* *
* @author Steve Ebersole * @author Steve Ebersole
*/ */
public class DotNameAdapter implements Name { class DotNameAdapter implements Name {
private final DotName dotName; private final DotName dotName;
public DotNameAdapter(String name) { DotNameAdapter(String name) {
final int loc = name.lastIndexOf( '.' ); final int loc = name.lastIndexOf( '.' );
if ( loc < 0 ) { if ( loc < 0 ) {
this.dotName = DotName.createSimple( name ); this.dotName = DotName.createSimple( name );

View File

@ -0,0 +1,97 @@
/*
* Hibernate, Relational Persistence for Idiomatic Java
*
* Copyright (c) 2014, Red Hat Inc. or third-party contributors as
* indicated by the @author tags or express copyright attribution
* statements applied by the authors. All third-party contributions are
* distributed under license by Red Hat Inc.
*
* This copyrighted material is made available to anyone wishing to use, modify,
* copy, or redistribute it subject to the terms and conditions of the GNU
* Lesser General Public License, as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
* for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this distribution; if not, write to:
* Free Software Foundation, Inc.
* 51 Franklin Street, Fifth Floor
* Boston, MA 02110-1301 USA
*/
package org.hibernate.metamodel.reflite.internal;
import org.hibernate.metamodel.reflite.spi.FieldDescriptor;
import org.hibernate.metamodel.reflite.spi.InterfaceDescriptor;
import org.hibernate.metamodel.reflite.spi.MethodDescriptor;
import org.hibernate.metamodel.reflite.spi.Name;
import org.hibernate.metamodel.reflite.spi.TypeDescriptor;
/**
* @author Steve Ebersole
*/
public class InterfaceDescriptorImpl implements InterfaceDescriptor {
private final Name name;
private TypeDescriptor[] extendedInterfaceTypes;
private FieldDescriptor[] declaredFields;
private MethodDescriptor[] declaredMethods;
public InterfaceDescriptorImpl(Name name) {
this.name = name;
}
@Override
public Name getName() {
return name;
}
@Override
public boolean isInterface() {
return true;
}
@Override
public boolean isVoid() {
return false;
}
@Override
public boolean isArray() {
return false;
}
@Override
public boolean isPrimitive() {
return false;
}
@Override
public TypeDescriptor[] getExtendedInterfaceTypes() {
return extendedInterfaceTypes;
}
@Override
public FieldDescriptor[] getDeclaredFields() {
return declaredFields;
}
@Override
public MethodDescriptor[] getDeclaredMethods() {
return declaredMethods;
}
void setExtendedInterfaceTypes(TypeDescriptor[] extendedInterfaceTypes) {
this.extendedInterfaceTypes = extendedInterfaceTypes;
}
void setDeclaredFields(FieldDescriptor[] declaredFields) {
this.declaredFields = declaredFields;
}
void setDeclaredMethods(MethodDescriptor[] declaredMethods) {
this.declaredMethods = declaredMethods;
}
}

View File

@ -0,0 +1,217 @@
/*
* Hibernate, Relational Persistence for Idiomatic Java
*
* Copyright (c) 2014, Red Hat Inc. or third-party contributors as
* indicated by the @author tags or express copyright attribution
* statements applied by the authors. All third-party contributions are
* distributed under license by Red Hat Inc.
*
* This copyrighted material is made available to anyone wishing to use, modify,
* copy, or redistribute it subject to the terms and conditions of the GNU
* Lesser General Public License, as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
* for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this distribution; if not, write to:
* Free Software Foundation, Inc.
* 51 Franklin Street, Fifth Floor
* Boston, MA 02110-1301 USA
*/
package org.hibernate.metamodel.reflite.internal;
import org.hibernate.metamodel.reflite.spi.ArrayTypeDescriptor;
import org.hibernate.metamodel.reflite.spi.Name;
import org.hibernate.metamodel.reflite.spi.PrimitiveTypeDescriptor;
import org.hibernate.metamodel.reflite.spi.PrimitiveWrapperTypeDescriptor;
import org.hibernate.metamodel.reflite.spi.TypeDescriptor;
/**
* @author Steve Ebersole
*/
public class Primitives {
public static class PrimitiveGroup {
private final PrimitiveTypeDescriptor primitiveType;
private final PrimitiveWrapperTypeDescriptor primitiveWrapperType;
private final ArrayTypeDescriptor primitiveArrayType;
private final ArrayTypeDescriptor primitiveWrapperArrayType;
public PrimitiveGroup(Class primitiveClass, Class wrapperClass) {
assert primitiveClass.isPrimitive();
assert !wrapperClass.isPrimitive();
this.primitiveType = new PrimitiveDescriptorImpl( primitiveClass.getName(), this );
this.primitiveWrapperType = new WrapperDescriptorImpl( wrapperClass.getName(), this );
this.primitiveArrayType = new ArrayTypeDescriptorImpl( null, this.primitiveType );
this.primitiveWrapperArrayType = new ArrayTypeDescriptorImpl( null, this.primitiveWrapperType );
}
public PrimitiveTypeDescriptor getPrimitiveType() {
return primitiveType;
}
public PrimitiveWrapperTypeDescriptor getPrimitiveWrapperType() {
return primitiveWrapperType;
}
public ArrayTypeDescriptor getPrimitiveArrayType() {
return primitiveArrayType;
}
public ArrayTypeDescriptor getPrimitiveWrapperArrayType() {
return primitiveWrapperArrayType;
}
}
public static final PrimitiveGroup CHAR = new PrimitiveGroup( char.class, Character.class );
public static final PrimitiveGroup BOOLEAN = new PrimitiveGroup( boolean.class, Boolean.class );
public static final PrimitiveGroup BYTE = new PrimitiveGroup( byte.class, Byte.class );
public static final PrimitiveGroup SHORT = new PrimitiveGroup( short.class, Short.class );
public static final PrimitiveGroup INTEGER = new PrimitiveGroup( int.class, Integer.class );
public static final PrimitiveGroup LONG = new PrimitiveGroup( long.class, Long.class );
public static final PrimitiveGroup FLOAT = new PrimitiveGroup( float.class, Float.class );
public static final PrimitiveGroup DOUBLE = new PrimitiveGroup( double.class, Double.class );
public static TypeDescriptor resolveByName(Name name) {
assert name != null;
final String typeNameString = name.toString();
if ( char.class.getName().equals( typeNameString ) ) {
return CHAR.primitiveType;
}
else if ( Character.class.getName().equals( name ) ) {
return CHAR.primitiveWrapperType;
}
else if ( boolean.class.getName().equals( typeNameString ) ) {
return BOOLEAN.primitiveType;
}
else if ( Boolean.class.getName().equals( typeNameString ) ) {
return BOOLEAN.primitiveWrapperType;
}
else if ( byte.class.getName().equals( typeNameString ) ) {
return BYTE.primitiveType;
}
else if ( Byte.class.getName().equals( typeNameString ) ) {
return BYTE.primitiveWrapperType;
}
else if ( short.class.getName().equals( typeNameString ) ) {
return SHORT.primitiveType;
}
else if ( Short.class.getName().equals( typeNameString ) ) {
return SHORT.primitiveArrayType;
}
else if ( int.class.getName().equals( typeNameString ) ) {
return INTEGER.primitiveType;
}
else if ( Integer.class.getName().equals( typeNameString ) ) {
return INTEGER.primitiveWrapperType;
}
else if ( long.class.getName().equals( typeNameString ) ) {
return LONG.primitiveType;
}
else if ( Long.class.getName().equals( typeNameString ) ) {
return LONG.primitiveWrapperType;
}
else if ( float.class.getName().equals( typeNameString ) ) {
return FLOAT.primitiveType;
}
else if ( Float.class.getName().equals( typeNameString ) ) {
return FLOAT.primitiveWrapperType;
}
else if ( double.class.getName().equals( typeNameString ) ) {
return DOUBLE.primitiveType;
}
else if ( double.class.getName().equals( typeNameString ) ) {
return DOUBLE.primitiveWrapperType;
}
return null;
}
private static class PrimitiveDescriptorImpl implements PrimitiveTypeDescriptor {
private final Name name;
private final PrimitiveGroup group;
protected PrimitiveDescriptorImpl(String simpleName, PrimitiveGroup group) {
this.name = new DotNameAdapter( simpleName );
this.group = group;
}
@Override
public Name getName() {
return name;
}
@Override
public PrimitiveWrapperTypeDescriptor getWrapperTypeDescriptor() {
return group.primitiveWrapperType;
}
@Override
public boolean isVoid() {
return false;
}
@Override
public boolean isInterface() {
return false;
}
@Override
public boolean isPrimitive() {
return true;
}
@Override
public boolean isArray() {
return false;
}
}
private static class WrapperDescriptorImpl implements PrimitiveWrapperTypeDescriptor {
private final Name name;
private final PrimitiveGroup group;
private WrapperDescriptorImpl(String simpleName, PrimitiveGroup group) {
this.name = new DotNameAdapter( simpleName );
this.group = group;
}
@Override
public Name getName() {
return name;
}
@Override
public PrimitiveTypeDescriptor getPrimitiveTypeDescriptor() {
return group.primitiveType;
}
@Override
public boolean isInterface() {
return false;
}
@Override
public boolean isVoid() {
return false;
}
@Override
public boolean isArray() {
return false;
}
@Override
public boolean isPrimitive() {
return false;
}
}
}

View File

@ -28,6 +28,7 @@
import java.util.HashMap; import java.util.HashMap;
import java.util.Map; import java.util.Map;
import org.hibernate.boot.registry.BootstrapServiceRegistryBuilder;
import org.hibernate.boot.registry.classloading.spi.ClassLoaderService; import org.hibernate.boot.registry.classloading.spi.ClassLoaderService;
import org.hibernate.boot.registry.classloading.spi.ClassLoadingException; import org.hibernate.boot.registry.classloading.spi.ClassLoadingException;
import org.hibernate.metamodel.reflite.spi.FieldDescriptor; import org.hibernate.metamodel.reflite.spi.FieldDescriptor;
@ -64,12 +65,41 @@ public Name buildName(String name) {
return new DotNameAdapter( name ); return new DotNameAdapter( name );
} }
@Override private TypeDescriptor arrayOfType(Class type) {
public TypeDescriptor getType(Name className) { if ( type.isArray() ) {
TypeDescriptor descriptor = typeDescriptorMap.get( className ); return new ArrayTypeDescriptorImpl(
if ( descriptor == null ) { buildName( "[" + type.getName() ),
descriptor = makeTypeDescriptor( className ); arrayOfType( type.getComponentType() )
);
} }
return new ArrayTypeDescriptorImpl(
buildName( "[" + type.getName() ),
getType( buildName( type.getName() ) )
);
}
@Override
public TypeDescriptor getType(Name typeName) {
if ( typeName == null ) {
return null;
}
final String typeNameString = typeName.toString();
if ( "void".equals( typeNameString ) ) {
return VoidTypeDescriptor.INSTANCE;
}
TypeDescriptor descriptor = typeDescriptorMap.get( typeName );
if ( descriptor == null ) {
descriptor = Primitives.resolveByName( typeName );
}
if ( descriptor == null ) {
descriptor = makeTypeDescriptor( typeName );
typeDescriptorMap.put( typeName, descriptor );
}
return descriptor; return descriptor;
} }
@ -117,90 +147,116 @@ private boolean isSafeClass(Name className) {
} }
private static TypeDescriptor[] NO_TYPES = new TypeDescriptor[0];
private static FieldDescriptor[] NO_FIELDS = new FieldDescriptor[0];
private static MethodDescriptor[] NO_METHODS = new MethodDescriptor[0];
// todo : this is not circular reference safe in terms of fields/methods referring back to this type
private TypeDescriptor makeTypeDescriptor(Name typeName, Class clazz) { private TypeDescriptor makeTypeDescriptor(Name typeName, Class clazz) {
// we build and register it now to protect against circular references if ( clazz.isInterface() ) {
final TypeDescriptorImpl typeDescriptor = new TypeDescriptorImpl( final InterfaceDescriptorImpl typeDescriptor = new InterfaceDescriptorImpl( typeName );
typeName, typeDescriptorMap.put( typeName, typeDescriptor );
clazz.isInterface(),
hasDefaultCtor( clazz )
);
typeDescriptorMap.put( typeName, typeDescriptor );
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ typeDescriptor.setExtendedInterfaceTypes( fromInterfaces( clazz ) );
// super type typeDescriptor.setDeclaredFields( fromFields( clazz, typeDescriptor ) );
TypeDescriptor superType = null; typeDescriptor.setDeclaredMethods( fromMethods( clazz, typeDescriptor ) );
if ( !clazz.isInterface() ) {
final Class superclass = clazz.getSuperclass(); return typeDescriptor;
if ( superclass != null ) {
superType = getType( buildName( superclass.getName() ) );
}
} }
typeDescriptor.setSuperType( superType ); else {
final ClassDescriptorImpl typeDescriptor = new ClassDescriptorImpl( typeName, hasDefaultCtor( clazz ) );
typeDescriptorMap.put( typeName, typeDescriptor );
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ typeDescriptor.setSuperType( fromSuper( clazz ) );
// interfaces typeDescriptor.setInterfaces( fromInterfaces( clazz ) );
TypeDescriptor[] interfaceTypes = null; typeDescriptor.setFields( fromFields( clazz, typeDescriptor ) );
typeDescriptor.setMethods( fromMethods( clazz, typeDescriptor ) );
return typeDescriptor;
}
}
private TypeDescriptor fromSuper(Class clazz) {
final Class superclass = clazz.getSuperclass();
if ( superclass == null ) {
return null;
}
return getType( buildName( superclass.getName() ) );
}
private static TypeDescriptor[] NO_TYPES = new TypeDescriptor[0];
private TypeDescriptor[] fromInterfaces(Class clazz) {
final Class[] interfaces = clazz.getInterfaces(); final Class[] interfaces = clazz.getInterfaces();
if ( interfaces != null && interfaces.length > 0 ) { if ( interfaces == null || interfaces.length <= 0 ) {
interfaceTypes = new TypeDescriptor[ interfaces.length ]; return NO_TYPES;
for ( int i = 0; i < interfaces.length; i++ ) {
interfaceTypes[i] = getType( buildName( interfaces[i].getName() ) );
}
} }
typeDescriptor.setInterfaces( interfaceTypes == null ? NO_TYPES : interfaceTypes );
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ final TypeDescriptor[] interfaceTypes = new TypeDescriptor[ interfaces.length ];
// fields for ( int i = 0; i < interfaces.length; i++ ) {
FieldDescriptor[] fieldDescriptors = null; interfaceTypes[i] = getType( buildName( interfaces[i].getName() ) );
}
return interfaceTypes;
}
private static FieldDescriptor[] NO_FIELDS = new FieldDescriptor[0];
private FieldDescriptor[] fromFields(Class clazz, TypeDescriptor declaringType) {
final Field[] fields = clazz.getDeclaredFields(); final Field[] fields = clazz.getDeclaredFields();
if ( fields != null && fields.length > 0 ) { if ( fields == null || fields.length <= 0 ) {
fieldDescriptors = new FieldDescriptor[ fields.length ]; return NO_FIELDS;
for ( int i = 0; i < fields.length; i++ ) {
fieldDescriptors[i] = new FieldDescriptorImpl(
fields[i].getName(),
getType( buildName( fields[i].getType().getName() ) ),
typeDescriptor
);
}
} }
typeDescriptor.setFields( fieldDescriptors == null ? NO_FIELDS : fieldDescriptors );
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ FieldDescriptor[] fieldDescriptors = new FieldDescriptor[ fields.length ];
// methods for ( int i = 0; i < fields.length; i++ ) {
MethodDescriptor[] methodDescriptors = null; final Class fieldType = fields[i].getType();
fieldDescriptors[i] = new FieldDescriptorImpl(
fields[i].getName(),
toTypeDescriptor( fieldType ),
declaringType
);
}
return fieldDescriptors;
}
private TypeDescriptor toTypeDescriptor(Class clazz) {
final TypeDescriptor fieldTypeDescriptor;
if ( clazz.isArray() ) {
fieldTypeDescriptor = arrayOfType( clazz.getComponentType() );
}
else {
fieldTypeDescriptor = getType( buildName( clazz.getName() ) );
}
return fieldTypeDescriptor;
}
private static MethodDescriptor[] NO_METHODS = new MethodDescriptor[0];
private MethodDescriptor[] fromMethods(Class clazz, TypeDescriptor declaringType) {
final Method[] methods = clazz.getDeclaredMethods(); final Method[] methods = clazz.getDeclaredMethods();
if ( methods != null && methods.length > 0 ) { if ( methods == null || methods.length <= 0 ) {
methodDescriptors = new MethodDescriptor[ methods.length ]; return NO_METHODS;
for ( int i = 0; i < methods.length; i++ ) {
final Class[] parameterTypes = methods[i].getParameterTypes();
final TypeDescriptor[] argumentTypes;
if ( parameterTypes.length == 0 ) {
argumentTypes = NO_TYPES;
}
else {
argumentTypes = new TypeDescriptor[ parameterTypes.length ];
for ( int x = 0; x < parameterTypes.length; x++ ) {
argumentTypes[x] = getType( buildName( parameterTypes[x].getName() ) );
}
}
methodDescriptors[i] = new MethodDescriptorImpl(
methods[i].getName(),
typeDescriptor,
getType( buildName( methods[i].getReturnType().getName() ) ),
argumentTypes
);
}
} }
typeDescriptor.setMethods( methodDescriptors == null ? NO_METHODS : methodDescriptors );
return typeDescriptor; MethodDescriptor[] methodDescriptors = new MethodDescriptor[ methods.length ];
for ( int i = 0; i < methods.length; i++ ) {
final Class[] parameterTypes = methods[i].getParameterTypes();
final TypeDescriptor[] argumentTypes;
if ( parameterTypes.length == 0 ) {
argumentTypes = NO_TYPES;
}
else {
argumentTypes = new TypeDescriptor[ parameterTypes.length ];
for ( int x = 0; x < parameterTypes.length; x++ ) {
argumentTypes[x] = toTypeDescriptor( parameterTypes[x] );
}
}
methodDescriptors[i] = new MethodDescriptorImpl(
methods[i].getName(),
declaringType,
toTypeDescriptor( methods[i].getReturnType() ),
argumentTypes
);
}
return methodDescriptors;
} }
@ -214,4 +270,48 @@ private static boolean hasDefaultCtor(Class clazz) {
} }
} }
public static void main(String... args) {
RepositoryImpl repo = new RepositoryImpl(
RepositoryImpl.class.getClassLoader(),
new BootstrapServiceRegistryBuilder().build()
);
TypeDescriptor td = repo.getType( repo.buildName( RepositoryImpl.class.getName() ) );
assert !td.isInterface();
}
private static class VoidTypeDescriptor implements TypeDescriptor {
/**
* Singleton access
*/
public static final VoidTypeDescriptor INSTANCE = new VoidTypeDescriptor();
private final Name name = new DotNameAdapter( "void" );
@Override
public Name getName() {
return name;
}
@Override
public boolean isInterface() {
return false;
}
@Override
public boolean isVoid() {
return true;
}
@Override
public boolean isArray() {
return false;
}
@Override
public boolean isPrimitive() {
return false;
}
}
} }

View File

@ -0,0 +1,31 @@
/*
* Hibernate, Relational Persistence for Idiomatic Java
*
* Copyright (c) 2014, Red Hat Inc. or third-party contributors as
* indicated by the @author tags or express copyright attribution
* statements applied by the authors. All third-party contributions are
* distributed under license by Red Hat Inc.
*
* This copyrighted material is made available to anyone wishing to use, modify,
* copy, or redistribute it subject to the terms and conditions of the GNU
* Lesser General Public License, as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
* for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this distribution; if not, write to:
* Free Software Foundation, Inc.
* 51 Franklin Street, Fifth Floor
* Boston, MA 02110-1301 USA
*/
package org.hibernate.metamodel.reflite.spi;
/**
* @author Steve Ebersole
*/
public interface ArrayTypeDescriptor extends TypeDescriptor {
public TypeDescriptor getComponentTypeDescriptor();
}

View File

@ -0,0 +1,64 @@
/*
* Hibernate, Relational Persistence for Idiomatic Java
*
* Copyright (c) 2014, Red Hat Inc. or third-party contributors as
* indicated by the @author tags or express copyright attribution
* statements applied by the authors. All third-party contributions are
* distributed under license by Red Hat Inc.
*
* This copyrighted material is made available to anyone wishing to use, modify,
* copy, or redistribute it subject to the terms and conditions of the GNU
* Lesser General Public License, as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
* for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this distribution; if not, write to:
* Free Software Foundation, Inc.
* 51 Franklin Street, Fifth Floor
* Boston, MA 02110-1301 USA
*/
package org.hibernate.metamodel.reflite.spi;
/**
* @author Steve Ebersole
*/
public interface ClassDescriptor extends TypeDescriptor {
/**
* Did the class define a default (no-arg) constructor?
*
* @return {@code true} indicates the class did have a default (no arg) constructor.
*/
public boolean hasDefaultConstructor();
/**
* The super type for this type (if it is a class)
*
* @return The super type
*/
public TypeDescriptor getSuperType();
/**
* Get the interfaces implemented by this type
*
* @return The implemented interfaces
*/
public TypeDescriptor[] getInterfaceTypes();
/**
* Get all the fields declared by this type.
*
* @return All fields declared by this type
*/
public FieldDescriptor[] getDeclaredFields();
/**
* Get all the methods declared by this type.
*
* @return All fields declared by this type
*/
public MethodDescriptor[] getDeclaredMethods();
}

View File

@ -0,0 +1,50 @@
/*
* Hibernate, Relational Persistence for Idiomatic Java
*
* Copyright (c) 2014, Red Hat Inc. or third-party contributors as
* indicated by the @author tags or express copyright attribution
* statements applied by the authors. All third-party contributions are
* distributed under license by Red Hat Inc.
*
* This copyrighted material is made available to anyone wishing to use, modify,
* copy, or redistribute it subject to the terms and conditions of the GNU
* Lesser General Public License, as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
* for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this distribution; if not, write to:
* Free Software Foundation, Inc.
* 51 Franklin Street, Fifth Floor
* Boston, MA 02110-1301 USA
*/
package org.hibernate.metamodel.reflite.spi;
/**
* @author Steve Ebersole
*/
public interface InterfaceDescriptor extends TypeDescriptor {
/**
* Get the interfaces extended by this interface
*
* @return The implemented interfaces
*/
public TypeDescriptor[] getExtendedInterfaceTypes();
/**
* Get all the fields declared by this type.
*
* @return All fields declared by this type
*/
public FieldDescriptor[] getDeclaredFields();
/**
* Get all the methods declared by this type.
*
* @return All fields declared by this type
*/
public MethodDescriptor[] getDeclaredMethods();
}

View File

@ -0,0 +1,31 @@
/*
* Hibernate, Relational Persistence for Idiomatic Java
*
* Copyright (c) 2014, Red Hat Inc. or third-party contributors as
* indicated by the @author tags or express copyright attribution
* statements applied by the authors. All third-party contributions are
* distributed under license by Red Hat Inc.
*
* This copyrighted material is made available to anyone wishing to use, modify,
* copy, or redistribute it subject to the terms and conditions of the GNU
* Lesser General Public License, as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
* for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this distribution; if not, write to:
* Free Software Foundation, Inc.
* 51 Franklin Street, Fifth Floor
* Boston, MA 02110-1301 USA
*/
package org.hibernate.metamodel.reflite.spi;
/**
* @author Steve Ebersole
*/
public interface PrimitiveTypeDescriptor extends TypeDescriptor {
public PrimitiveWrapperTypeDescriptor getWrapperTypeDescriptor();
}

View File

@ -0,0 +1,31 @@
/*
* Hibernate, Relational Persistence for Idiomatic Java
*
* Copyright (c) 2014, Red Hat Inc. or third-party contributors as
* indicated by the @author tags or express copyright attribution
* statements applied by the authors. All third-party contributions are
* distributed under license by Red Hat Inc.
*
* This copyrighted material is made available to anyone wishing to use, modify,
* copy, or redistribute it subject to the terms and conditions of the GNU
* Lesser General Public License, as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
* for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this distribution; if not, write to:
* Free Software Foundation, Inc.
* 51 Franklin Street, Fifth Floor
* Boston, MA 02110-1301 USA
*/
package org.hibernate.metamodel.reflite.spi;
/**
* @author Steve Ebersole
*/
public interface PrimitiveWrapperTypeDescriptor extends TypeDescriptor {
public PrimitiveTypeDescriptor getPrimitiveTypeDescriptor();
}

View File

@ -23,8 +23,6 @@
*/ */
package org.hibernate.metamodel.reflite.spi; package org.hibernate.metamodel.reflite.spi;
import java.util.Collection;
/** /**
* Describes information about a class. * Describes information about a class.
* *
@ -40,38 +38,17 @@ public interface TypeDescriptor {
*/ */
public boolean isInterface(); public boolean isInterface();
/** public boolean isVoid();
* The super type for this type (if it is a class)
*
* @return The super type
*/
public TypeDescriptor getSuperType();
/** /**
* Get the interfaces implemented by this type
* *
* @return The implemented interfaces * @return
*/ */
public TypeDescriptor[] getInterfaceTypes(); public boolean isArray();
/** /**
* Did the class define a default (no-arg) constructor?
* *
* @return {@code true} indicates the class did have a default (no arg) constructor. * @return
*/ */
public boolean hasDefaultConstructor(); public boolean isPrimitive();
/**
* Get all the fields declared by this type.
*
* @return All fields declared by this type
*/
public FieldDescriptor[] getDeclaredFields();
/**
* Get all the methods declared by this type.
*
* @return All fields declared by this type
*/
public MethodDescriptor[] getDeclaredMethods();
} }