限制标记@RestOnMessage方法的条件

This commit is contained in:
Redkale
2018-01-11 19:13:14 +08:00
parent f254519a1c
commit 21af487aab
2 changed files with 10 additions and 1 deletions

View File

@@ -239,6 +239,10 @@ public final class Rest {
RestOnMessage rom = method.getAnnotation(RestOnMessage.class);
if (rom == null) continue;
String name = rom.name();
if (Modifier.isFinal(method.getModifiers())) throw new RuntimeException("@RestOnMessage method can not final but (" + method + ")");
if (Modifier.isStatic(method.getModifiers())) throw new RuntimeException("@RestOnMessage method can not static but (" + method + ")");
if (method.getReturnType() != void.class) throw new RuntimeException("@RestOnMessage method must return void but (" + method + ")");
if (method.getExceptionTypes().length > 0) throw new RuntimeException("@RestOnMessage method can not throw exception but (" + method + ")");
if (name.isEmpty()) throw new RuntimeException(method + " RestOnMessage.name is empty createRestWebSocketServlet");
if (messageNames.contains(name)) throw new RuntimeException(method + " repeat RestOnMessage.name(" + name + ") createRestWebSocketServlet");
messageNames.add(name);

View File

@@ -10,7 +10,12 @@ import static java.lang.annotation.ElementType.METHOD;
import static java.lang.annotation.RetentionPolicy.RUNTIME;
/**
* 标记在RestWebSocket的接收消息方法上方法通常是void返回类型
* 标记在RestWebSocket的接收消息方法上; <br>
* 注意:被标记的方法必须同时符合以下条件: <br>
* 1、必须修饰为public
* 2、不能修饰为final和static
* 3、返回值必须是void
* 4、不能throws检查型异常
*
* <br><p>
* 详情见: https://redkale.org