Reformatted code using IntelliJ
This commit is contained in:
@@ -14,6 +14,7 @@ public @interface ProtocolInfo {
|
||||
/**
|
||||
* Specifies the side of the protocol that the annotated class or method is associated with.
|
||||
* Default is ALL, indicating that it can be used on any side.
|
||||
*
|
||||
* @return The protocol side.
|
||||
*/
|
||||
ProtocolVersion.ProtocolSide protocolSide() default ProtocolVersion.ProtocolSide.ALL;
|
||||
|
||||
@@ -36,21 +36,16 @@ public class CallTracker<A extends Annotation> extends GenericReflectClass<A> {
|
||||
}
|
||||
|
||||
public abstract static class CallInterceptor {
|
||||
private static Set<CallInterceptor> interceptors = new HashSet<>();
|
||||
private static final Set<CallInterceptor> interceptors = new HashSet<>();
|
||||
|
||||
public CallInterceptor() {
|
||||
interceptors.add(this);
|
||||
}
|
||||
|
||||
/**
|
||||
* Code executed on any method call
|
||||
*/
|
||||
public abstract void onCall(Method method, @Nullable StackTraceElement callerMethod);
|
||||
|
||||
@Advice.OnMethodEnter
|
||||
static void intercept(@Advice.Origin Method method) {
|
||||
|
||||
for(CallInterceptor interceptor : interceptors) {
|
||||
for (CallInterceptor interceptor : interceptors) {
|
||||
StackTraceElement[] stack = Thread.currentThread().getStackTrace();
|
||||
|
||||
if (stack.length <= 3)
|
||||
@@ -79,5 +74,10 @@ public class CallTracker<A extends Annotation> extends GenericReflectClass<A> {
|
||||
//
|
||||
// }
|
||||
}
|
||||
|
||||
/**
|
||||
* Code executed on any method call
|
||||
*/
|
||||
public abstract void onCall(Method method, @Nullable StackTraceElement callerMethod);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -41,42 +41,41 @@ public class ProtocolInfoProcessing extends AnnotationProcessor<ProtocolInfo> {
|
||||
|
||||
Object o;
|
||||
|
||||
if((o = methodGetByName(callerMethod.getMethodName())) != null)
|
||||
if ((o = methodGetByName(callerMethod.getMethodName())) != null)
|
||||
callerSide = ((Method) o).getAnnotation(ProtocolInfo.class).protocolSide();
|
||||
else if((o = typeHasAnnotation(callerMethod.getClassName())) != null)
|
||||
else if ((o = typeHasAnnotation(callerMethod.getClassName())) != null)
|
||||
callerSide = ((Class<?>) o).getAnnotation(ProtocolInfo.class).protocolSide();
|
||||
else
|
||||
return;
|
||||
|
||||
|
||||
if(methodReferences.get().contains(method))
|
||||
if (methodReferences.get().contains(method))
|
||||
side = method.getAnnotation(ProtocolInfo.class).protocolSide();
|
||||
|
||||
else if(typeReferences.get().contains(method.getDeclaringClass()))
|
||||
else if (typeReferences.get().contains(method.getDeclaringClass()))
|
||||
side = method.getDeclaringClass().getAnnotation(ProtocolInfo.class).protocolSide();
|
||||
else
|
||||
return;
|
||||
|
||||
if(callerSide.equals(ProtocolVersion.ProtocolSide.CLIENT) &&
|
||||
if (callerSide.equals(ProtocolVersion.ProtocolSide.CLIENT) &&
|
||||
!side.equals(callerSide))
|
||||
throw new IncompatibleProtocolSideException(callerSide, side);
|
||||
|
||||
|
||||
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private Method methodGetByName(String methodName) {
|
||||
for(Method method : this.annotatedMethods)
|
||||
if(method.getName().equals(methodName))
|
||||
for (Method method : this.annotatedMethods)
|
||||
if (method.getName().equals(methodName))
|
||||
return method;
|
||||
return null;
|
||||
}
|
||||
|
||||
private Class<?> typeHasAnnotation(String typeName) {
|
||||
for(Class<?> type : this.annotatedTypes)
|
||||
if(type.getName().equals(typeName))
|
||||
for (Class<?> type : this.annotatedTypes)
|
||||
if (type.getName().equals(typeName))
|
||||
return type;
|
||||
return null;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user