field.getName(),
(String) field.get(this)
);
- } catch (Exception ignored) {
+ } catch (ReflectiveOperationException ignored) {
}
}
}
String fieldName
) {
String result = null;
- Class<?> clazz = getClass();
- for (Field field : clazz.getDeclaredFields()) {
+ try {
+ Class<?> clazz = getClass();
+ Field field = clazz.getDeclaredField(fieldName);
if (field.isAnnotationPresent(annotationClass)
- && field.getName().equals(fieldName)
&& field.getType().equals(String.class))
{
field.setAccessible(true);
- try {
- result = (String) field.get(this);
- } catch (Exception ignored) {
- }
+ result = (String) field.get(this);
}
+ } catch (ReflectiveOperationException ignored) {
}
return result;
}
) {
Map<String, String> result = new HashMap<>();
Class<?> clazz = getClass();
- for (Method method : clazz.getMethods()) {
+ for (Method method : clazz.getDeclaredMethods()) {
if (method.isAnnotationPresent(annotationClass)
- && method.getReturnType().equals(String.class)
- && method.getParameterCount() == 0)
+ && method.getParameterCount() == 0
+ && method.getReturnType().equals(String.class))
{
try {
result.put(
method.getName(),
(String) method.invoke(this)
);
- } catch (Exception ignored) {
+ } catch (ReflectiveOperationException ignored) {
}
}
}
String methodName
) {
String result = null;
- Class<?> clazz = getClass();
- for (Method method : clazz.getMethods()) {
+ try {
+ Class<?> clazz = getClass();
+ Method method = clazz.getDeclaredMethod(methodName);
if (method.isAnnotationPresent(annotationClass)
- && method.getName().equals(methodName)
- && method.getReturnType().equals(String.class)
- && method.getParameterCount() == 0)
+ && method.getReturnType().equals(String.class))
{
- try {
- result = (String) method.invoke(this);
- } catch (Exception ignored) {
- }
+ result = (String) method.invoke(this);
}
+ } catch (ReflectiveOperationException ignored) {
}
return result;
}