Commit 8c6d09fca6dd99c07902a90b635c23a5645e677b
Exists in
master
Merge branch 'fix-reflections-multiple-children' of https://github.com/vfcosta/f…
…ramework into vfcosta-fix-reflections-multiple-children
Showing
2 changed files
with
15 additions
and
1 deletions
Show diff stats
impl/core/src/main/java/br/gov/frameworkdemoiselle/util/Reflections.java
| ... | ... | @@ -68,7 +68,7 @@ public final class Reflections { |
| 68 | 68 | try { |
| 69 | 69 | paramType = (ParameterizedType) type; |
| 70 | 70 | } catch (ClassCastException cause) { |
| 71 | - paramType = (ParameterizedType) ((Class<T>) type).getGenericSuperclass(); | |
| 71 | + return getGenericTypeArgument((Class<T>) type, idx); | |
| 72 | 72 | } |
| 73 | 73 | |
| 74 | 74 | return (Class<T>) paramType.getActualTypeArguments()[idx]; | ... | ... |
impl/core/src/test/java/util/reflection/ReflectionsTest.java
| ... | ... | @@ -58,6 +58,12 @@ public class ReflectionsTest { |
| 58 | 58 | assertEquals(Long.class, Reflections.getGenericTypeArgument(members[0], 0)); |
| 59 | 59 | assertEquals(String.class, Reflections.getGenericTypeArgument(members[1], 0)); |
| 60 | 60 | } |
| 61 | + | |
| 62 | + @Test | |
| 63 | + public void testGetGenericTypeArgumentClassMultipleChildren() { | |
| 64 | + assertEquals(Long.class, Reflections.getGenericTypeArgument(OtherClass3.class, 0)); | |
| 65 | + assertEquals(String.class, Reflections.getGenericTypeArgument(OtherClass3.class, 1)); | |
| 66 | + } | |
| 61 | 67 | } |
| 62 | 68 | |
| 63 | 69 | class SomeClass<T, I> { |
| ... | ... | @@ -73,3 +79,11 @@ class OtherClass extends SomeClass<Long, String> { |
| 73 | 79 | |
| 74 | 80 | public Class<String> text; |
| 75 | 81 | } |
| 82 | + | |
| 83 | +class OtherClass2 extends OtherClass { | |
| 84 | + | |
| 85 | +} | |
| 86 | + | |
| 87 | +class OtherClass3 extends OtherClass2 { | |
| 88 | + | |
| 89 | +} | ... | ... |