[MAGNOLIA-2725] c2b: use generics to find the type to build instead of reflecting the adder method Created: 08/May/09 Updated: 11/Feb/13 Resolved: 16/Oct/12 |
|
| Status: | Closed |
| Project: | Magnolia |
| Component/s: | None |
| Affects Version/s: | None |
| Fix Version/s: | 5.0 |
| Type: | Improvement | Priority: | Major |
| Reporter: | Philipp Bärfuss | Assignee: | Jaroslav Simak |
| Resolution: | Fixed | Votes: | 0 |
| Labels: | content2bean | ||
| Remaining Estimate: | Not Specified | ||
| Time Spent: | Not Specified | ||
| Original Estimate: | Not Specified | ||
| Issue Links: |
|
||||||||
| Template: |
|
||||||||
| Acceptance criteria: |
Empty
|
||||||||
| Task DoD: |
[ ]*
Doc/release notes changes? Comment present?
[ ]*
Downstream builds green?
[ ]*
Solution information and context easily available?
[ ]*
Tests
[ ]*
FixVersion filled and not yet released
[ ] 
Architecture Decision Record (ADR)
|
||||||||
| Description |
|
If no adder method is defined we could check if generics are used and if so using it to resolve the type to build. |
| Comments |
| Comment by Philipp Bärfuss [ 15/May/09 ] |
|
A research together with Jan has lead as to the following snipped which shows that we can get the actual class from the setter. Note: it is impossible to get this information from the stingList object itself, but this is not what we try to do. public class MyClass { protected List<String> stringList = ...; pulic void setStringList(List<String> list){ this.stringList = list; } } //--------- method = Myclass.class.getMethod("setStringList", List.class); Type[] genericParameterTypes = method.getGenericParameterTypes(); for(Type genericParameterType : genericParameterTypes){ if(genericParameterType instanceof ParameterizedType){ ParameterizedType aType = (ParameterizedType) genericParameterType; Type[] parameterArgTypes = aType.getActualTypeArguments(); for(Type parameterArgType : parameterArgTypes){ Class parameterArgClass = (Class) parameterArgType; System.out.println("parameterArgClass = " + parameterArgClass); } } } |