@Test public void testParameterIndex_WhenDefined() throws Exception { class ImplicitBoolField { @Parameters(index = "2..3") boolean boolSingleValue; } Range arity = Range.parameterIndex(ImplicitBoolField.class.getDeclaredField("boolSingleValue")); assertEquals(3, arity.max); assertEquals(2, arity.min); assertEquals(false, arity.isVariable); assertEquals("2..3", arity.toString()); }
@Test public void testParameterIndex_WhenUndefined() throws Exception { class ImplicitBoolField { @Parameters boolean boolSingleValue; } Range arity = Range.parameterIndex(ImplicitBoolField.class.getDeclaredField("boolSingleValue")); assertEquals(Integer.MAX_VALUE, arity.max); assertEquals(0, arity.min); assertEquals(true, arity.isVariable); assertEquals("0..*", arity.toString()); }
@Test public void testParameterIndex_WhenUndefined() throws Exception { class ImplicitBoolField { @Parameters boolean boolSingleValue; } Range arity = Range.parameterIndex(ImplicitBoolField.class.getDeclaredField("boolSingleValue")); assertEquals(Integer.MAX_VALUE, arity.max); assertEquals(0, arity.min); assertEquals(true, arity.isVariable); assertEquals("0..*", arity.toString()); }
@Test public void testParameterIndex_WhenDefined() throws Exception { class ImplicitBoolField { @Parameters(index = "2..3") boolean boolSingleValue; } Range arity = Range.parameterIndex(ImplicitBoolField.class.getDeclaredField("boolSingleValue")); assertEquals(3, arity.max); assertEquals(2, arity.min); assertEquals(false, arity.isVariable); assertEquals("2..3", arity.toString()); }
/** Returns a new {@code Range} based on the {@link Parameters#index()} annotation on the specified field. * @param field the field whose Parameters annotation to inspect * @return a new {@code Range} based on the Parameters index annotation on the specified field */ public static Range parameterIndex(Field field) { return parameterIndex(new TypedMember(field)); } private static Range parameterIndex(TypedMember member) {
static Range parameterCapacity(TypedMember member) { Range arity = parameterArity(member); if (!member.isMultiValue()) { return arity; } Range index = parameterIndex(member); return parameterCapacity(arity, index); } private static Range parameterCapacity(Range arity, Range index) {
static Range parameterCapacity(IAnnotatedElement member) { Range arity = parameterArity(member); if (!member.isMultiValue()) { return arity; } Range index = parameterIndex(member); return parameterCapacity(arity, index); } private static Range parameterCapacity(Range arity, Range index) {
/** Returns a new {@code Range} based on the {@link Parameters#index()} annotation on the specified field. * @param field the field whose Parameters annotation to inspect * @return a new {@code Range} based on the Parameters index annotation on the specified field */ public static Range parameterIndex(Field field) { return parameterIndex(new TypedMember(field)); } private static Range parameterIndex(IAnnotatedElement member) {