Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
ProxyPointcut pointcut = MethodWithAnnotationPointcut.of(Log.class);ProxyPointcut pointcut = ((ProxyPointcut)
methodInfo -> methodInfo.isPublicMethod()
&& methodInfo.isTopLevelMethod())
.and(MethodWithAnnotationPointcut.of(Log.class));Methref.of(Str.class).name(Str::boo);
// returns String: 'boo' Methref.of(Str.class).name((str) -> str.hello(null, 0));
// returns 'hello'Methref m = Methref.of(Str.class);
// get proxy
Str str = m.proxy();
// invoke method
str.foo();
// get invoked method name
String name = m.lastName();Proxy,
Wrapperand InvokeReplacer.WrapperProxetta proxetta = Proxetta
.wrapperProxetta()
.withAspect(aspect);
WrapperProxettaFactory factory = proxetta
.proxy()
.setTarget(calc.getClass())
.setTargetInterface(Calc.class);
Calc calc = factory.newInstance();
factory.injectTargetIntoWrapper(calc, calculatorObject);public static class Foo {
public Foo(String something) {}
public void hello() {}
public void two(String username, String password) {}
}MethodParameter[] s = Paramo.resolveParameters(constructor);
System.out.println(s.length); // 1
System.out.println(s[0].getName()); // somethingMethodParameter[] s = Paramo.resolveParameters(helloMethod);
System.out.println(s.length); // 0MethodParameter[] s = Paramo.resolveParameters(twoMethod);
System.out.println(s.length); // 2
System.out.println(s[0].getName()); // username
System.out.println(s[1].getName()); // passwordpublic class LogProxyAdvice implements ProxyAdvice {
public Object execute() {
int totalArgs = ProxyTarget.argumentsCount();
Class target = ProxyTarget.targetClass();
String methodName = ProxyTarget.targetMethodName();
System.out.println(">>>" + target.getSimpleName()
+ '#' + methodName + ':' + totalArgs);
Object result = ProxyTarget.invoke();
System.out.println("<<<" + result);
return result;
}
}public class Foo {
public String someMethod(Integer first, double second) {...}
}public class Foo$Proxy extends Foo {
public String someMethod(Integer first, double second) {
int totalArgs = 2; // arguments count
Class target = Foo.class; // target class
String methodName = "someMethod" // target method name
System.out.println(">>>" + target.getSimpleName()
+ '#' + methodName + ':' + totalArgs);
Object result = super.someMethod(first, second);
System.out.println("<<<" + result);
return result;
}
}Proxetta proxetta = Proxy.invokeProxetta().withAspect(
invokeInfo -> {
if (invokeInfo.getMethodName().equals("foo")) {
return InvokeReplacer.with(Replacer.class, "bar");
}
return null;
}
};One one = proxetta.proxy().setTarget(One.class).newInstance();public class One {
public void example1() {
Two two = new Two();
int i = two.foo("one");
System.out.print(i);
}
}public void example1() {
Two two = new Two();
int i = Replacer.bar(two);
System.out.print(i);
}public class TimeClass {
public long time() {
return System.currentTimeMillis();
}
}TimeClass timeClass =
(TimeClass) InvokeProxetta.withAspects(new InvokeAspect() {
@Override
public boolean apply(MethodInfo methodInfo) {
return methodInfo.isTopLevelMethod();
}
@Override
public InvokeReplacer pointcut(InvokeInfo invokeInfo) {
if (
invokeInfo.getClassName().equals("java.lang.System") &&
invokeInfo.getMethodName().equals("currentTimeMillis")
) {
return InvokeReplacer.with(MySystem.class, "currentTimeMillis");
}
return null;
}
}).builder(TimeClass.class).newInstance();invokeInfo -> {
return InvokeReplacer.with(Replacer.class,
invokeInfo.getMethodName() + invokeInfo.getArgumentsCount());
}public class One {
public void example() {
Two two = new Two();
two.hello();
}
}
public class Two() {
public String value;
public void hello() {
System.out.println(value);
}
}InvokeProxetta proxetta = Proxy.invokeProxetta.proxy().withAspect(
invokeInfo -> {
if (invokeInfo.getMethodName().equals("<init>")) {
return InvokeReplacer.with(Replacer.class,
"new" + invokeInfo.getClassShortName());
} else {
return null;
}
}
);public class Replacer {
public static Two newTwo() {
Two two = new Two();
two.value = "hello";
return two;
}
}
ProxyAspect aspect = ProxyAspect.of(LogProxyAdvice.class, pointcut);Pathref<User> p = Pathref.on(User.class);
p.path(p.to()
.getFriends()
.get(2)
.getAddress()
.getStreet()); // friends[2].address.streetnewInstance() - instantiates default constructor for defined class.
Proxetta.proxyProxetta();
Proxetta.wrapperProxetta();
Proxetta.invokeProxetta();ProxyProxetta proxetta = Proxetta
.proxyProxetta()
.withAspect(aspect1)
.withAspect(aspect2);proxetta.proxy().setTarget(targetClass);Class fooClass = proxetta.proxy().setTarget(Foo.class).define();Foo foo = proxetta.proxy().setTarget(Foo.class).newInstance();

