package io.qameta.htmlelements.extension;

import io.qameta.htmlelements.annotation.FindBy;
import io.qameta.htmlelements.context.Context;

import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
import java.lang.reflect.Method;
import java.util.NoSuchElementException;

@Target(ElementType.METHOD)
@Retention(RetentionPolicy.RUNTIME)
@HandleWith(SelectorProvider.Extension.class)
@ExtendWith(SelectorProvider.Extension.class)
public @interface SelectorProvider {

    class Extension implements ContextEnricher, MethodHandler<String> {

        private static final String SELECTOR_KEY = "selector";

        @Override
        public void enrich(Context context, Method method, Object[] args) {
            String selector = method.getAnnotation(FindBy.class).value();
            context.getStore().put(SELECTOR_KEY, selector);
        }

        @Override
        public String handle(Context context, Object proxy, Method method, Object[] args) throws Throwable {
            return context.getStore().get(SELECTOR_KEY, String.class)
                    .orElseThrow(() -> new NoSuchElementException("Missing selector"));
        }
    }

}

@@ -131,16 +131,68 @@
 Context;
+%0Aimport io.qameta.htmlelements.util.ReflectionUtils;
 %0A%0Aimport
@@ -880,49 +880,48 @@
 r = 
-method.getAnnotation(FindBy.class).value(
+ReflectionUtils.getSelector(method, args
 );%0A 

fix selector provider