3030import java .lang .reflect .Constructor ;
3131import java .lang .reflect .InvocationTargetException ;
3232import java .lang .reflect .Method ;
33+ import java .lang .reflect .Proxy ;
3334import java .util .ArrayList ;
3435import java .util .List ;
36+ import java .util .stream .Stream ;
3537
3638/**
3739 * It is the basic handler of Appium-specific page object annotations
@@ -45,13 +47,11 @@ public abstract class AppiumByBuilder extends AbstractAnnotations {
4547 private static final List <String > METHODS_TO_BE_EXCLUDED_WHEN_ANNOTATION_IS_READ =
4648 new ArrayList <String >() {
4749 private static final long serialVersionUID = 1L ; {
48- List <String > objectClassMethodNames =
49- getMethodNames (Object .class .getDeclaredMethods ());
50- addAll (objectClassMethodNames );
51- List <String > annotationClassMethodNames =
52- getMethodNames (Annotation .class .getDeclaredMethods ());
53- annotationClassMethodNames .removeAll (objectClassMethodNames );
54- addAll (annotationClassMethodNames );
50+ Stream .of (Object .class , Annotation .class , Proxy .class )
51+ .map (Class ::getDeclaredMethods )
52+ .map (AppiumByBuilder ::getMethodNames )
53+ .flatMap (List ::stream )
54+ .forEach (this ::add );
5555 }
5656 };
5757 protected final AnnotatedElementContainer annotatedElementContainer ;
@@ -73,13 +73,13 @@ private static List<String> getMethodNames(Method[] methods) {
7373 }
7474
7575 private static Method [] prepareAnnotationMethods (Class <? extends Annotation > annotation ) {
76- List <String > targeAnnotationMethodNamesList =
76+ List <String > targetAnnotationMethodNamesList =
7777 getMethodNames (annotation .getDeclaredMethods ());
78- targeAnnotationMethodNamesList .removeAll (METHODS_TO_BE_EXCLUDED_WHEN_ANNOTATION_IS_READ );
79- Method [] result = new Method [targeAnnotationMethodNamesList .size ()];
80- for (String methodName : targeAnnotationMethodNamesList ) {
78+ targetAnnotationMethodNamesList .removeAll (METHODS_TO_BE_EXCLUDED_WHEN_ANNOTATION_IS_READ );
79+ Method [] result = new Method [targetAnnotationMethodNamesList .size ()];
80+ for (String methodName : targetAnnotationMethodNamesList ) {
8181 try {
82- result [targeAnnotationMethodNamesList .indexOf (methodName )] =
82+ result [targetAnnotationMethodNamesList .indexOf (methodName )] =
8383 annotation .getMethod (methodName , DEFAULT_ANNOTATION_METHOD_ARGUMENTS );
8484 } catch (NoSuchMethodException | SecurityException e ) {
8585 throw new RuntimeException (e );
0 commit comments