@Override public Object invoke( Object o, final Method method, Object[] objects ) throws Throwable { if( method.equals( Property.class.getMethod( "get" ) ) ) { Type propertyType = GenericPropertyInfo.propertyTypeOf( property.accessor() ); if( propertyType.getClass().equals( Class.class ) ) { return Proxy.newProxyInstance( method.getDeclaringClass().getClassLoader(), array( (Class<?>) propertyType, PropertyReference.class ), new TemplateHandler<T>( property, null, null, null ) ); } } return null; } }
public static Type propertyTypeOf( AccessibleObject accessor ) { return toPropertyType( typeOf( accessor ) ); }
propertyMethod.setAccessible( true ); Object value = objectObjectEntry.getValue(); Type propertyType = GenericPropertyInfo.propertyTypeOf( propertyMethod );
public static Type toPropertyType( Type methodReturnType ) { if( methodReturnType instanceof ParameterizedType ) { ParameterizedType parameterizedType = (ParameterizedType) methodReturnType; if( Property.class.isAssignableFrom( (Class<?>) parameterizedType.getRawType() ) ) { return parameterizedType.getActualTypeArguments()[ 0 ]; } } if( methodReturnType instanceof Class<?> ) { Type[] interfaces = ( (Class<?>) methodReturnType ).getGenericInterfaces(); for( Type anInterface : interfaces ) { Type propertyType = toPropertyType( anInterface ); if( propertyType != null ) { return propertyType; } } } return null; } }
/** * Verify that the provided accessor method has not been marked with a Queryable(false). * * @param accessor accessor method * * @throws NotQueryableException - If accessor method has been marked as not queryable */ public static void throwIfNotQueryable( final AccessibleObject accessor ) { Queryable queryable = accessor.getAnnotation( Queryable.class ); if( queryable != null && !queryable.value() ) { throw new NotQueryableException( String.format( "%1$s \"%2$s\" (%3$s) is not queryable as has been marked with @Queryable(false)", Classes.RAW_CLASS.map( GenericPropertyInfo.propertyTypeOf( accessor ) ).getSimpleName(), ( (Member) accessor ).getName(), ( (Member) accessor ).getDeclaringClass().getName() ) ); } }
Type propertyTypeAsType = GenericPropertyInfo.toPropertyType( returnType ); if( propertyTypeAsType instanceof ParameterizedType )
Type t = GenericPropertyInfo.propertyTypeOf( method ); if( t instanceof Class )