Reformatted code using IntelliJ

This commit is contained in:
Finn
2025-09-29 18:46:31 +02:00
parent f9ec00add4
commit facac103e7
30 changed files with 298 additions and 153 deletions

View File

@@ -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;

View File

@@ -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);
}
}

View File

@@ -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;
}