Merge BeanWrapperImpl and DirectFieldAccessor
`BeanWrapperImpl` and `DirectFieldAccessor` are two `ConfigurablePropertyAccessor` implementations with different features set. This commit harmonizes the two implementations to use a common base class that delegates the actual property handling to the sub-classes: * `BeanWrapperImpl`: `PropertyDescriptor` and introspection utilities * `DirectFieldAccessor`: reflection on `java.lang.Field` Issues: SPR-12206 - SPR-12805
This commit is contained in:
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2014 the original author or authors.
|
||||
* Copyright 2002-2015 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -23,27 +23,29 @@ import org.springframework.tests.sample.beans.TestBean;
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
/**
|
||||
* Unit tests for {@link DirectFieldAccessor}
|
||||
* Specific {@link DirectFieldAccessor} tests.
|
||||
*
|
||||
* @author Jose Luis Martin
|
||||
* @author Chris Beams
|
||||
* @@author Stephane Nicoll
|
||||
*/
|
||||
public class DirectFieldAccessorTests extends AbstractConfigurablePropertyAccessorTests {
|
||||
|
||||
@Override
|
||||
protected ConfigurablePropertyAccessor createAccessor(Object target) {
|
||||
protected DirectFieldAccessor createAccessor(Object target) {
|
||||
return new DirectFieldAccessor(target);
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void withShadowedField() throws Exception {
|
||||
@SuppressWarnings("serial")
|
||||
TestBean tb = new TestBean() {
|
||||
TestBean target = new TestBean() {
|
||||
@SuppressWarnings("unused")
|
||||
StringBuilder name = new StringBuilder();
|
||||
};
|
||||
|
||||
DirectFieldAccessor dfa = new DirectFieldAccessor(tb);
|
||||
DirectFieldAccessor dfa = createAccessor(target);
|
||||
assertEquals(StringBuilder.class, dfa.getPropertyType("name"));
|
||||
}
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2012 the original author or authors.
|
||||
* Copyright 2002-2015 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -38,6 +38,7 @@ import org.springframework.util.ObjectUtils;
|
||||
*
|
||||
* @author Rod Johnson
|
||||
* @author Juergen Hoeller
|
||||
* @author Stephane Nicoll
|
||||
* @since 15 April 2001
|
||||
*/
|
||||
public class TestBean implements BeanNameAware, BeanFactoryAware, ITestBean, IOther, Comparable<Object> {
|
||||
@@ -58,6 +59,8 @@ public class TestBean implements BeanNameAware, BeanFactoryAware, ITestBean, IOt
|
||||
|
||||
private boolean jedi;
|
||||
|
||||
private ITestBean spouse;
|
||||
|
||||
protected ITestBean[] spouses;
|
||||
|
||||
private String touchy;
|
||||
@@ -113,7 +116,7 @@ public class TestBean implements BeanNameAware, BeanFactoryAware, ITestBean, IOt
|
||||
}
|
||||
|
||||
public TestBean(ITestBean spouse) {
|
||||
this.spouses = new ITestBean[] {spouse};
|
||||
this.spouse = spouse;
|
||||
}
|
||||
|
||||
public TestBean(String name, int age) {
|
||||
@@ -122,7 +125,7 @@ public class TestBean implements BeanNameAware, BeanFactoryAware, ITestBean, IOt
|
||||
}
|
||||
|
||||
public TestBean(ITestBean spouse, Properties someProperties) {
|
||||
this.spouses = new ITestBean[] {spouse};
|
||||
this.spouse = spouse;
|
||||
this.someProperties = someProperties;
|
||||
}
|
||||
|
||||
@@ -210,17 +213,17 @@ public class TestBean implements BeanNameAware, BeanFactoryAware, ITestBean, IOt
|
||||
|
||||
@Override
|
||||
public ITestBean getSpouse() {
|
||||
return (spouses != null ? spouses[0] : null);
|
||||
return this.spouse;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setSpouse(ITestBean spouse) {
|
||||
this.spouses = new ITestBean[] {spouse};
|
||||
this.spouse = spouse;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ITestBean[] getSpouses() {
|
||||
return spouses;
|
||||
return (spouse != null ? new ITestBean[]{spouse} : null);
|
||||
}
|
||||
|
||||
public String getTouchy() {
|
||||
|
||||
Reference in New Issue
Block a user