@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 ) ); }
@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 ) ); }
/** * 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.apply( GenericPropertyInfo.propertyTypeOf( accessor ) ).getSimpleName(), ( (Member) accessor ).getName(), ( (Member) accessor ).getDeclaringClass().getName() ) ); } }
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; } }
Method propertyMethod = composite.getClass().getInterfaces()[ 0 ].getMethod( methodName ); 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.apply( GenericPropertyInfo.propertyTypeOf( accessor ) ).getSimpleName(), ( (Member) accessor ).getName(), ( (Member) accessor ).getDeclaringClass().getName() ) ); } }
Type propertyTypeAsType = GenericPropertyInfo.toPropertyType( returnType ); if( propertyTypeAsType instanceof ParameterizedType )
Method propertyMethod = composite.getClass().getInterfaces()[ 0 ].getMethod( methodName ); Object value = objectObjectEntry.getValue(); Type propertyType = GenericPropertyInfo.propertyTypeOf( propertyMethod );
Type propertyTypeAsType = GenericPropertyInfo.toPropertyType( returnType ); if( propertyTypeAsType instanceof ParameterizedType )
public PropertyModel( AccessibleObject accessor, boolean immutable, boolean useDefaults, ValueConstraintsInstance constraints, MetaInfo metaInfo, Object initialValue ) { if( accessor instanceof Method ) { Method m = (Method) accessor; if( !m.getReturnType().equals( Property.class ) ) { throw new InvalidPropertyTypeException( accessor ); } } this.immutable = immutable; this.metaInfo = metaInfo; this.accessor = accessor; type = GenericPropertyInfo.propertyTypeOf( accessor ); checkTypeValidity( type ); qualifiedName = QualifiedName.fromAccessor( accessor ); initialValueProvider = new DefaultInitialValueProvider( useDefaults, initialValue ); this.constraints = constraints; final Queryable queryable = accessor.getAnnotation( Queryable.class ); this.queryable = queryable == null || queryable.value(); }
ValueConstraintsModel valueConstraintsModel = constraintsFor( annotations.stream(), GenericPropertyInfo.propertyTypeOf( accessor ), ( (Member) accessor ).getName(), optional,