/** * Create a {@code SimpleEvaluationContext} for read-write access to * public properties via {@link DataBindingPropertyAccessor}. * @see DataBindingPropertyAccessor#forReadWriteAccess() * @see #forPropertyAccessors */ public static Builder forReadWriteDataBinding() { return new Builder(DataBindingPropertyAccessor.forReadWriteAccess()); }
/** * Create a {@code SimpleEvaluationContext} for read-only access to * public properties via {@link DataBindingPropertyAccessor}. * @see DataBindingPropertyAccessor#forReadOnlyAccess() * @see #forPropertyAccessors */ public static Builder forReadOnlyDataBinding() { return new Builder(DataBindingPropertyAccessor.forReadOnlyAccess()); }
@Override public TypeLocator getTypeLocator() { if (this.typeLocator == null) { this.typeLocator = new StandardTypeLocator(); } return this.typeLocator; }
@Test public void testStandardEvaluationContext() { StandardEvaluationContext context = new StandardEvaluationContext(); assertNotNull(context.getTypeComparator()); TypeComparator tc = new StandardTypeComparator(); context.setTypeComparator(tc); assertEquals(tc, context.getTypeComparator()); TypeLocator tl = new StandardTypeLocator(); context.setTypeLocator(tl); assertEquals(tl, context.getTypeLocator()); }
/** * Return the default evaluation context that will be used if none is supplied on an evaluation call. * @return the default evaluation context */ public EvaluationContext getEvaluationContext() { if (this.evaluationContext == null) { this.evaluationContext = new StandardEvaluationContext(); } return this.evaluationContext; }
/** * Register some variables that can be referenced from the tests * @param testContext the test evaluation context */ private static void populateVariables(StandardEvaluationContext testContext) { testContext.setVariable("answer", 42); }
@Test public void testReflectionHelperCompareArguments_CloseMatching() { StandardTypeConverter tc = new StandardTypeConverter(); // Calling foo(List) with (ArrayList) is close match (no conversion required) checkMatch(new Class<?>[] {ArrayList.class}, new Class<?>[] {List.class}, tc, ArgumentsMatchKind.CLOSE); // Passing (Sub,String) on call to foo(Super,String) is close match checkMatch(new Class<?>[] {Sub.class, String.class}, new Class<?>[] {Super.class, String.class}, tc, ArgumentsMatchKind.CLOSE); // Passing (String,Sub) on call to foo(String,Super) is close match checkMatch(new Class<?>[] {String.class, Sub.class}, new Class<?>[] {String.class, Super.class}, tc, ArgumentsMatchKind.CLOSE); }
/** * Register a custom {@link ConversionService}. * <p>By default a {@link StandardTypeConverter} backed by a * {@link org.springframework.core.convert.support.DefaultConversionService} is used. * @see #withTypeConverter * @see StandardTypeConverter#StandardTypeConverter(ConversionService) */ public Builder withConversionService(ConversionService conversionService) { this.typeConverter = new StandardTypeConverter(conversionService); return this; } /**
/** * Create a new data-binding property accessor for read-write operations. */ public static DataBindingPropertyAccessor forReadWriteAccess() { return new DataBindingPropertyAccessor(true); }
public BooleanLiteral(String payload, int startPos, int endPos, boolean value) { super(payload, startPos, endPos); this.value = BooleanTypedValue.forValue(value); this.exitTypeDescriptor = "Z"; }
/** * Create a new data-binding method resolver for instance method resolution. */ public static DataBindingMethodResolver forInstanceMethodInvocation() { return new DataBindingMethodResolver(); }
@Override public List<MethodResolver> getMethodResolvers() { return initMethodResolvers(); }
@Override public List<ConstructorResolver> getConstructorResolvers() { return initConstructorResolvers(); }
public SimpleEvaluationContext build() { return new SimpleEvaluationContext(this.accessors, this.resolvers, this.typeConverter, this.rootObject); } }
@Override public List<PropertyAccessor> getPropertyAccessors() { return initPropertyAccessors(); }
@Test public void testReflectionHelperCompareArguments_RequiresConversionMatching() { StandardTypeConverter tc = new StandardTypeConverter(); // Calling foo(String,int) with (String,Integer) requires boxing conversion of argument one checkMatch(new Class<?>[] {String.class, Integer.TYPE}, new Class<?>[] {String.class,Integer.class},tc, ArgumentsMatchKind.CLOSE); // Passing (int,String) on call to foo(Integer,String) requires boxing conversion of argument zero checkMatch(new Class<?>[] {Integer.TYPE, String.class}, new Class<?>[] {Integer.class, String.class},tc, ArgumentsMatchKind.CLOSE); // Passing (int,Sub) on call to foo(Integer,Super) requires boxing conversion of argument zero checkMatch(new Class<?>[] {Integer.TYPE, Sub.class}, new Class<?>[] {Integer.class, Super.class}, tc, ArgumentsMatchKind.CLOSE); // Passing (int,Sub,boolean) on call to foo(Integer,Super,Boolean) requires boxing conversion of arguments zero and two // TODO checkMatch(new Class<?>[] {Integer.TYPE, Sub.class, Boolean.TYPE}, new Class<?>[] {Integer.class, Super.class, Boolean.class}, tc, ArgsMatchKind.REQUIRES_CONVERSION); }
@Override public TypeConverter getTypeConverter() { if (this.typeConverter == null) { this.typeConverter = new StandardTypeConverter(); } return this.typeConverter; }
/** * Create a new data-binding property accessor for read-only operations. */ public static DataBindingPropertyAccessor forReadOnlyAccess() { return new DataBindingPropertyAccessor(false); }
@Test public void testReflectionHelperCompareArguments_ExactMatching() { StandardTypeConverter tc = new StandardTypeConverter(); // Calling foo(String) with (String) is exact match checkMatch(new Class<?>[] {String.class}, new Class<?>[] {String.class}, tc, ReflectionHelper.ArgumentsMatchKind.EXACT); // Calling foo(String,Integer) with (String,Integer) is exact match checkMatch(new Class<?>[] {String.class, Integer.class}, new Class<?>[] {String.class, Integer.class}, tc, ArgumentsMatchKind.EXACT); }
@Test public void testReflectionHelperCompareArguments_NotAMatch() { StandardTypeConverter typeConverter = new StandardTypeConverter(); // Passing (Super,String) on call to foo(Sub,String) is not a match checkMatch(new Class<?>[] {Super.class,String.class}, new Class<?>[] {Sub.class,String.class}, typeConverter, null); }