Add logger when annotation is missing
*/
public final class MethodCommand extends AbstractCommand {
private static final Logger logger = LoggerFactory.getLogger(MethodCommand.class);
+ private static final String ENTITY_REF_NAME = "org.terasology.entitySystem.entity.EntityRef";
private MethodCommand(Name name, String requiredPermission, boolean runOnServer, String description, String helpText,
SpecificAccessibleObject<Method> executionMethod, Context context) {
@@ -85,8 +86,24 @@ public static MethodCommand referringTo(SpecificAccessibleObject<Method> specifi
public static void registerAvailable(Object provider, Console console, Context context) {
Predicate<? super Method> predicate = Predicates.<Method>and(ReflectionUtils.withModifier(Modifier.PUBLIC), ReflectionUtils.withAnnotation(Command.class));
Set<Method> commandMethods = ReflectionUtils.getAllMethods(provider.getClass(), predicate);
-
for (Method method : commandMethods) {
+ final Class[] paramTypes = method.getParameterTypes();
+ final Annotation[][] paramAnnotations = method.getParameterAnnotations();
+ for (int i = 0; i < paramAnnotations.length; i++) {
+ if(paramTypes[i].getTypeName().equals(ENTITY_REF_NAME)) {
+ if(paramAnnotations[i].length == 0) {
+ logger.info("Command {} contains a EntityRef without @Sender annotation, may cause a NullPointerException", method.getName());
+ } else {
+ for (Annotation annotation: paramAnnotations[i]) {
+ if (annotation instanceof Sender) {
+ } else {
+ logger.info("Command {} contains a EntityRef without @Sender annotation, may cause a NullPointerException", method.getName());
+ }
+ }
+ }
+
+ }
+ }
logger.debug("Registering command method {} in class {}", method.getName(), method.getDeclaringClass().getCanonicalName());
try {
SpecificAccessibleObject<Method> specificMethod = new SpecificAccessibleObject<>(method, provider);
