From 15ad54404bfccf150d77e1ec3c79edf7057b9fd5 Mon Sep 17 00:00:00 2001 From: Dancovich Date: Mon, 21 Oct 2013 17:00:21 -0300 Subject: [PATCH] -Classe agora não é mais "final" -Editadas documentações que faltavam --- impl/core/src/main/java/br/gov/frameworkdemoiselle/util/Reflections.java | 34 +++++++++++++++++++++++----------- 1 file changed, 23 insertions(+), 11 deletions(-) diff --git a/impl/core/src/main/java/br/gov/frameworkdemoiselle/util/Reflections.java b/impl/core/src/main/java/br/gov/frameworkdemoiselle/util/Reflections.java index 25f1be6..658b687 100644 --- a/impl/core/src/main/java/br/gov/frameworkdemoiselle/util/Reflections.java +++ b/impl/core/src/main/java/br/gov/frameworkdemoiselle/util/Reflections.java @@ -52,9 +52,11 @@ import java.util.List; * * @author SERPRO */ -public final class Reflections { +public class Reflections { - private Reflections() { + protected Reflections() { + //Impede instanciar subclasses desse tipo. + throw new UnsupportedOperationException(); } /** @@ -109,7 +111,10 @@ public final class Reflections { } /** - * TODO + *

Return the parametized type passed to members (fields or methods) that accepts Generics.

+ * + * @see #getGenericTypeArgument(Field field, int idx) + * */ public static Class getGenericTypeArgument(final Member member, final int idx) { Class result = null; @@ -124,7 +129,10 @@ public final class Reflections { } /** - * TODO + *

Return the parametized type passed to methods that accepts Generics.

+ * + * @see #getGenericTypeArgument(Field field, int idx) + * */ @SuppressWarnings("unchecked") public static Class getGenericTypeArgument(final Method method, final int pos) { @@ -180,7 +188,8 @@ public final class Reflections { } /** - * TODO + * @return All non static fields from a certain type. Inherited fields are not returned, so if you + * need to get inherited fields you must iterate over this type's hierarchy. */ public static Field[] getNonStaticDeclaredFields(Class type) { List fields = new ArrayList(); @@ -197,21 +206,24 @@ public final class Reflections { } /** - * TODO + * @return All non static fields from a certain type, including fields declared in superclasses of this type. */ public static List getNonStaticFields(Class type) { List fields = new ArrayList(); if (type != null) { - fields.addAll(Arrays.asList(getNonStaticDeclaredFields(type))); - fields.addAll(getNonStaticFields(type.getSuperclass())); + Class currentType = type; + while(currentType!=null && !"java.lang.Object".equals(currentType.getCanonicalName())){ + fields.addAll(Arrays.asList(getNonStaticDeclaredFields(currentType))); + currentType = currentType.getSuperclass(); + } } return fields; } /** - * TODO + * Instantiate an object of the given type. The default constructor with no parameters is used. */ public static T instantiate(Class clazz) { T object = null; @@ -282,7 +294,7 @@ public final class Reflections { } /** - * TODO + * Return an URL to access a resource available to the active classloader for the calling thread. */ public static URL getResourceAsURL(final String resource) { ClassLoader classLoader = getClassLoaderForResource(resource); @@ -290,7 +302,7 @@ public final class Reflections { } /** - * TODO + * Loads a class with the given name using the active classloader for the current thread. */ @SuppressWarnings("unchecked") public static Class forName(final String className) throws ClassNotFoundException { -- libgit2 0.21.2