Skip to content

Commit f379757

Browse files
committed
Add comments describing public methods
1 parent b33ebae commit f379757

File tree

2 files changed

+42
-0
lines changed

2 files changed

+42
-0
lines changed

src/main/java/io/appium/java_client/proxy/ElementAwareWebDriverListener.java

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,13 +34,36 @@
3434
public class ElementAwareWebDriverListener implements MethodCallListener, ProxyAwareListener {
3535
private WebDriver parent;
3636

37+
/**
38+
* Attaches the WebDriver proxy instance to this listener.
39+
* <p>
40+
* The listener stores the WebDriver instance to associate it as parent to RemoteWebElement proxies.
41+
*
42+
* @param proxy A proxy instance of {@link WebDriver}.
43+
*/
3744
@Override
3845
public void attachProxyInstance(Object proxy) {
3946
if (proxy instanceof WebDriver) {
4047
this.parent = (WebDriver) proxy;
4148
}
4249
}
4350

51+
/**
52+
* Intercepts method calls on a proxied WebDriver.
53+
* <p>
54+
* If the result of the method call is a {@link RemoteWebElement},
55+
* it is wrapped with a proxy to allow further interception of RemoteWebElement method calls.
56+
* If the result is a list, each item is checked, and all RemoteWebElements are
57+
* individually proxied. All other return types are passed through unmodified.
58+
* Avoid overriding this method, it will alter the behaviour of the listener.
59+
*
60+
* @param obj The object on which the method was invoked.
61+
* @param method The method being invoked.
62+
* @param args The arguments passed to the method.
63+
* @param original A {@link Callable} that represents the original method execution.
64+
* @return The (possibly wrapped) result of the method call.
65+
* @throws Throwable if the original method or any wrapping logic throws an exception.
66+
*/
4467
@Override
4568
public Object call(Object obj, Method method, Object[] args, Callable<?> original) throws Throwable {
4669
Object result = original.call();

src/main/java/io/appium/java_client/proxy/ProxyAwareListener.java

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,26 @@
1616

1717
package io.appium.java_client.proxy;
1818

19+
/**
20+
* Extension of {@link MethodCallListener} that allows access to the proxy instance it depends on.
21+
* <p>
22+
* This interface is intended for listeners that need a reference to the proxy object.
23+
* <p>
24+
* The {@link #attachProxyInstance(Object)} method will be invoked immediately after the proxy is created,
25+
* allowing the listener to bind to it before any method interception begins.
26+
* <p>
27+
* Example usage: Working with elements such as
28+
* {@code RemoteWebElement} that require runtime mutation (e.g. setting parent driver or element ID).
29+
*/
1930
public interface ProxyAwareListener extends MethodCallListener {
31+
32+
/**
33+
* Binds the listener to the proxy instance passed.
34+
* <p>
35+
* This is called once, immediately after proxy creation and before the proxy is returned to the caller.
36+
*
37+
* @param proxy the proxy instance created via {@code createProxy} that this listener is attached to.
38+
*/
2039
void attachProxyInstance(Object proxy);
2140
}
2241

0 commit comments

Comments
 (0)