Commit 3cd30a8f945fa0028bc97fbec9336dbc3250b93e

Authored by Emerson Oliveira
1 parent d41c1132
Exists in master

Adição de javadoc à classe br.gov.frameworkdemoiselle.util.Reflections.

Ainda não está completo.
impl/core/src/main/java/br/gov/frameworkdemoiselle/util/Reflections.java
... ... @@ -47,11 +47,19 @@ import java.util.ArrayList;
47 47 import java.util.Arrays;
48 48 import java.util.List;
49 49  
  50 +/**
  51 + * Provides some features to do some operations relating to java reflection.
  52 + *
  53 + * @author SERPRO
  54 + */
50 55 public final class Reflections {
51 56  
52 57 private Reflections() {
53 58 }
54 59  
  60 + /**
  61 + * TODO
  62 + */
55 63 @SuppressWarnings("unchecked")
56 64 public static <T> Class<T> getGenericTypeArgument(final Class<?> clazz, final int idx) {
57 65 final Type type = clazz.getGenericSuperclass();
... ... @@ -66,6 +74,9 @@ public final class Reflections {
66 74 return (Class<T>) paramType.getActualTypeArguments()[idx];
67 75 }
68 76  
  77 + /**
  78 + * TODO
  79 + */
69 80 @SuppressWarnings("unchecked")
70 81 public static <T> Class<T> getGenericTypeArgument(final Field field, final int idx) {
71 82 final Type type = field.getGenericType();
... ... @@ -74,6 +85,9 @@ public final class Reflections {
74 85 return (Class<T>) paramType.getActualTypeArguments()[idx];
75 86 }
76 87  
  88 + /**
  89 + * TODO
  90 + */
77 91 public static <T> Class<T> getGenericTypeArgument(final Member member, final int idx) {
78 92 Class<T> result = null;
79 93  
... ... @@ -86,11 +100,23 @@ public final class Reflections {
86 100 return result;
87 101 }
88 102  
  103 + /**
  104 + * TODO
  105 + */
89 106 @SuppressWarnings("unchecked")
90 107 public static <T> Class<T> getGenericTypeArgument(final Method method, final int pos) {
91 108 return (Class<T>) method.getGenericParameterTypes()[pos];
92 109 }
93 110  
  111 + /**
  112 + * Returns the value contained in the given field.
  113 + *
  114 + * @param field
  115 + * field to be extracted the value.
  116 + * @param object
  117 + * object that contains the field.
  118 + * @return value of the field.
  119 + */
94 120 @SuppressWarnings("unchecked")
95 121 public static <T> T getFieldValue(Field field, Object object) {
96 122 T result = null;
... ... @@ -108,6 +134,16 @@ public final class Reflections {
108 134 return result;
109 135 }
110 136  
  137 + /**
  138 + * Sets a value in a field.
  139 + *
  140 + * @param field
  141 + * field to be setted.
  142 + * @param object
  143 + * object that contains the field.
  144 + * @param value
  145 + * value to be setted in the field.
  146 + */
111 147 public static void setFieldValue(Field field, Object object, Object value) {
112 148 try {
113 149 boolean acessible = field.isAccessible();
... ... @@ -120,6 +156,9 @@ public final class Reflections {
120 156 }
121 157 }
122 158  
  159 + /**
  160 + * TODO
  161 + */
123 162 public static Field[] getNonStaticDeclaredFields(Class<?> type) {
124 163 List<Field> fields = new ArrayList<Field>();
125 164  
... ... @@ -134,6 +173,9 @@ public final class Reflections {
134 173 return fields.toArray(new Field[0]);
135 174 }
136 175  
  176 + /**
  177 + * TODO
  178 + */
137 179 public static List<Field> getNonStaticFields(Class<?> type) {
138 180 List<Field> fields = new ArrayList<Field>();
139 181  
... ... @@ -145,10 +187,13 @@ public final class Reflections {
145 187 return fields;
146 188 }
147 189  
148   - public static <T> T instantiate(Class<T> clasz) {
  190 + /**
  191 + * TODO
  192 + */
  193 + public static <T> T instantiate(Class<T> clazz) {
149 194 T object = null;
150 195 try {
151   - object = clasz.newInstance();
  196 + object = clazz.newInstance();
152 197 } catch (InstantiationException e) {
153 198 Exceptions.handleToRuntimeException(e);
154 199 } catch (IllegalAccessException e) {
... ... @@ -157,14 +202,40 @@ public final class Reflections {
157 202 return object;
158 203 }
159 204  
  205 + /**
  206 + * Verifies if a given class could be converted to a given type.
  207 + *
  208 + * @param clazz
  209 + * class to be checked.
  210 + * @param type
  211 + * type to be checked.
  212 + * @return {@link Boolean}
  213 + * true if the given class can be converted to a given type, and false otherwise.
  214 + */
160 215 public static boolean isOfType(Class<?> clazz, Class<?> type) {
161 216 return type.isAssignableFrom(clazz) && clazz != type;
162 217 }
163 218  
  219 + /**
  220 + * Obtains the {@link ClassLoader} for the given class, from his canonical name.
  221 + *
  222 + * @param canonicalName
  223 + * canonical name of the the given class.
  224 + * @return {@link ClassLoader}
  225 + * ClassLoader for the given class.
  226 + */
164 227 public static ClassLoader getClassLoaderForClass(final String canonicalName) {
165 228 return Reflections.getClassLoaderForResource(canonicalName.replaceAll("\\.", "/") + ".class");
166 229 }
167 230  
  231 + /**
  232 + * Obtains the {@link ClassLoader} for the given resource.
  233 + *
  234 + * @param resource
  235 + *
  236 + * @return {@link ClassLoader}
  237 + * ClassLoader for the given resource.
  238 + */
168 239 public static ClassLoader getClassLoaderForResource(final String resource) {
169 240 final String stripped = resource.charAt(0) == '/' ? resource.substring(1) : resource;
170 241  
... ... @@ -187,11 +258,17 @@ public final class Reflections {
187 258 return result;
188 259 }
189 260  
  261 + /**
  262 + * TODO
  263 + */
190 264 public static URL getResourceAsURL(final String resource) {
191 265 ClassLoader classLoader = getClassLoaderForResource(resource);
192 266 return classLoader != null ? classLoader.getResource(resource) : null;
193 267 }
194 268  
  269 + /**
  270 + * TODO
  271 + */
195 272 @SuppressWarnings("unchecked")
196 273 public static <T> Class<T> forName(final String className) throws ClassNotFoundException {
197 274 ClassLoader classLoader = getClassLoaderForClass(className);
... ...