Commit 15ad54404bfccf150d77e1ec3c79edf7057b9fd5
1 parent
466843a6
Exists in
master
-Classe agora não é mais "final"
-Editadas documentações que faltavam
Showing
1 changed file
with
23 additions
and
11 deletions
Show diff stats
impl/core/src/main/java/br/gov/frameworkdemoiselle/util/Reflections.java
... | ... | @@ -52,9 +52,11 @@ import java.util.List; |
52 | 52 | * |
53 | 53 | * @author SERPRO |
54 | 54 | */ |
55 | -public final class Reflections { | |
55 | +public class Reflections { | |
56 | 56 | |
57 | - private Reflections() { | |
57 | + protected Reflections() { | |
58 | + //Impede instanciar subclasses desse tipo. | |
59 | + throw new UnsupportedOperationException(); | |
58 | 60 | } |
59 | 61 | |
60 | 62 | /** |
... | ... | @@ -109,7 +111,10 @@ public final class Reflections { |
109 | 111 | } |
110 | 112 | |
111 | 113 | /** |
112 | - * TODO | |
114 | + * <p>Return the parametized type passed to members (fields or methods) that accepts Generics.</p> | |
115 | + * | |
116 | + * @see #getGenericTypeArgument(Field field, int idx) | |
117 | + * | |
113 | 118 | */ |
114 | 119 | public static <T> Class<T> getGenericTypeArgument(final Member member, final int idx) { |
115 | 120 | Class<T> result = null; |
... | ... | @@ -124,7 +129,10 @@ public final class Reflections { |
124 | 129 | } |
125 | 130 | |
126 | 131 | /** |
127 | - * TODO | |
132 | + * <p>Return the parametized type passed to methods that accepts Generics.</p> | |
133 | + * | |
134 | + * @see #getGenericTypeArgument(Field field, int idx) | |
135 | + * | |
128 | 136 | */ |
129 | 137 | @SuppressWarnings("unchecked") |
130 | 138 | public static <T> Class<T> getGenericTypeArgument(final Method method, final int pos) { |
... | ... | @@ -180,7 +188,8 @@ public final class Reflections { |
180 | 188 | } |
181 | 189 | |
182 | 190 | /** |
183 | - * TODO | |
191 | + * @return All non static fields from a certain type. Inherited fields are not returned, so if you | |
192 | + * need to get inherited fields you must iterate over this type's hierarchy. | |
184 | 193 | */ |
185 | 194 | public static Field[] getNonStaticDeclaredFields(Class<?> type) { |
186 | 195 | List<Field> fields = new ArrayList<Field>(); |
... | ... | @@ -197,21 +206,24 @@ public final class Reflections { |
197 | 206 | } |
198 | 207 | |
199 | 208 | /** |
200 | - * TODO | |
209 | + * @return All non static fields from a certain type, including fields declared in superclasses of this type. | |
201 | 210 | */ |
202 | 211 | public static List<Field> getNonStaticFields(Class<?> type) { |
203 | 212 | List<Field> fields = new ArrayList<Field>(); |
204 | 213 | |
205 | 214 | if (type != null) { |
206 | - fields.addAll(Arrays.asList(getNonStaticDeclaredFields(type))); | |
207 | - fields.addAll(getNonStaticFields(type.getSuperclass())); | |
215 | + Class<?> currentType = type; | |
216 | + while(currentType!=null && !"java.lang.Object".equals(currentType.getCanonicalName())){ | |
217 | + fields.addAll(Arrays.asList(getNonStaticDeclaredFields(currentType))); | |
218 | + currentType = currentType.getSuperclass(); | |
219 | + } | |
208 | 220 | } |
209 | 221 | |
210 | 222 | return fields; |
211 | 223 | } |
212 | 224 | |
213 | 225 | /** |
214 | - * TODO | |
226 | + * Instantiate an object of the given type. The default constructor with no parameters is used. | |
215 | 227 | */ |
216 | 228 | public static <T> T instantiate(Class<T> clazz) { |
217 | 229 | T object = null; |
... | ... | @@ -282,7 +294,7 @@ public final class Reflections { |
282 | 294 | } |
283 | 295 | |
284 | 296 | /** |
285 | - * TODO | |
297 | + * Return an URL to access a resource available to the active classloader for the calling thread. | |
286 | 298 | */ |
287 | 299 | public static URL getResourceAsURL(final String resource) { |
288 | 300 | ClassLoader classLoader = getClassLoaderForResource(resource); |
... | ... | @@ -290,7 +302,7 @@ public final class Reflections { |
290 | 302 | } |
291 | 303 | |
292 | 304 | /** |
293 | - * TODO | |
305 | + * Loads a class with the given name using the active classloader for the current thread. | |
294 | 306 | */ |
295 | 307 | @SuppressWarnings("unchecked") |
296 | 308 | public static <T> Class<T> forName(final String className) throws ClassNotFoundException { | ... | ... |