public class CoreReflection extends Object
Modifier and Type | Method and Description |
---|---|
static Field |
findField(Object object,
String fieldName)
Finds field.
|
static Method |
findMethod(Object object,
String methodName,
Class... args)
Finds method to invoke.
|
static Annotation |
getAnnotation(Object object,
Class<? extends Annotation> annotation)
Gets the object's annotation.
|
static Object |
getField(Object object,
Field field)
Gets the value of the field.
|
static Object |
getField(Object object,
String fieldName)
Gets the value of the field.
|
static Object |
invoke(Object object,
Method method,
Object... args)
Invokes method and returns the result.
|
static Object |
invoke(Object object,
String methodName,
Object... args)
Invokes method and returns the result.
|
static Object |
invokeSafe(Object object,
String methodName,
Object... args)
Same as
invoke(Object, String, Object...) but never throws exceptions. |
static boolean |
isAnnotated(Object object,
Class<? extends Annotation> annotation)
Checks whether the object was annotated.
|
static boolean |
isAnnotatedField(Object object,
Class<? extends Annotation> annotation,
String fieldName)
Checks whether the field was annotated.
|
static boolean |
isAnnotatedMethod(Object object,
Class<? extends Annotation> annotation,
String methodName,
Class... args)
Checks whether the method was annotated.
|
static Object |
setField(Object object,
Field field,
Object newValue)
Sets the value of the field.
|
static Object |
setField(Object object,
String fieldName,
Object newValue)
Sets the value of the field.
|
public static Object invokeSafe(@NonNull Object object, @NonNull String methodName, Object... args)
invoke(Object, String, Object...)
but never throws exceptions.public static Object invoke(@NonNull Object object, @NonNull String methodName, Object... args) throws InvocationTargetException
InvocationTargetException
- please refer to the exception descriptionobject
- The object on which to call this methodmethodName
- The method nameargs
- The method argumentspublic static Object invoke(Object object, Method method, Object... args) throws InvocationTargetException
InvocationTargetException
- please refer to the exception descriptionobject
- The object on which to call this methodmethod
- The methodargs
- The method argumentspublic static Method findMethod(@NonNull Object object, @NonNull String methodName, @NonNull Class... args)
object
- The object on which to call this methodmethodName
- The method nameargs
- The method argumentspublic static Field findField(@NonNull Object object, @NonNull String fieldName)
object
- The object on which to find this fieldfieldName
- The field namepublic static Object getField(@NonNull Object object, @NonNull String fieldName)
object
- The object on which to get this fieldfieldName
- The field namepublic static Object getField(@NonNull Object object, Field field)
object
- The object on which to get this fieldfield
- The fieldpublic static Object setField(@NonNull Object object, @NonNull String fieldName, Object newValue)
object
- The object on which to set this fieldfieldName
- The field namenewValue
- The field's new valuepublic static Object setField(@NonNull Object object, Field field, Object newValue)
object
- The object on which to set this fieldfield
- The fieldnewValue
- The field's new valuepublic static Annotation getAnnotation(@NonNull Object object, @NonNull Class<? extends Annotation> annotation)
object
- The object on which to get this annotationannotation
- The annotation classpublic static boolean isAnnotated(@NonNull Object object, @NonNull Class<? extends Annotation> annotation)
object
- The object to checkannotation
- The annotation classtrue
if the object was annotated, false
otherwisepublic static boolean isAnnotatedMethod(@NonNull Object object, @NonNull Class<? extends Annotation> annotation, @NonNull String methodName, @NonNull Class... args)
object
- The object to checkannotation
- The annotation classmethodName
- The method nameargs
- The method argumentstrue
if the method was annotated, false
otherwisepublic static boolean isAnnotatedField(@NonNull Object object, @NonNull Class<? extends Annotation> annotation, @NonNull String fieldName)
object
- The object to checkannotation
- The annotation classfieldName
- The field nametrue
if the field was annotated, false
otherwise
Copyright © 2015-2017 akha, a.k.a. Alexander Kharitonov
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.