From 2968608c71c1fe776e306d566c0425c74c78948a Mon Sep 17 00:00:00 2001 From: 502647092 Date: Wed, 24 Aug 2016 22:29:42 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E6=B7=BB=E5=8A=A0=E6=B3=A8=E5=85=A5?= =?UTF-8?q?=E9=85=8D=E7=BD=AE=E5=85=81=E8=AE=B8Null=E7=9A=84=E6=B3=A8?= =?UTF-8?q?=E8=A7=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 502647092 --- .../pw/yumc/YumCore/config/ConfigNode.java | 5 +++++ .../pw/yumc/YumCore/config/InjectConfig.java | 4 ++-- .../config/InjectConfigurationSection.java | 4 ++-- .../java/pw/yumc/YumCore/config/Nullable.java | 19 +++++++++++++++++++ 4 files changed, 28 insertions(+), 4 deletions(-) create mode 100644 src/main/java/pw/yumc/YumCore/config/Nullable.java diff --git a/src/main/java/pw/yumc/YumCore/config/ConfigNode.java b/src/main/java/pw/yumc/YumCore/config/ConfigNode.java index d79f685..25a8f87 100644 --- a/src/main/java/pw/yumc/YumCore/config/ConfigNode.java +++ b/src/main/java/pw/yumc/YumCore/config/ConfigNode.java @@ -14,6 +14,11 @@ import java.lang.annotation.Target; @Retention(RetentionPolicy.RUNTIME) public @interface ConfigNode { + /** + * @return 是否允许为空 + */ + boolean notNull() default false; + /** * Defines the path to the node if it has another as the variable name. * Every indention is separated with an dot ('.') diff --git a/src/main/java/pw/yumc/YumCore/config/InjectConfig.java b/src/main/java/pw/yumc/YumCore/config/InjectConfig.java index ceed5b7..d88fb2c 100644 --- a/src/main/java/pw/yumc/YumCore/config/InjectConfig.java +++ b/src/main/java/pw/yumc/YumCore/config/InjectConfig.java @@ -72,8 +72,8 @@ public abstract class InjectConfig extends AbstractInjectConfig { } catch (final IllegalAccessException ex) { Log.log(Level.SEVERE, "自动注入配置错误!", ex); } - } else { - Log.debug("配置节点 {0} 丢失!", realPath); + } else if (field.getAnnotation(Nullable.class) == null) { + Log.warning(String.format("配置节点 %s 丢失!", realPath)); } } } diff --git a/src/main/java/pw/yumc/YumCore/config/InjectConfigurationSection.java b/src/main/java/pw/yumc/YumCore/config/InjectConfigurationSection.java index aa2b4db..e09119d 100644 --- a/src/main/java/pw/yumc/YumCore/config/InjectConfigurationSection.java +++ b/src/main/java/pw/yumc/YumCore/config/InjectConfigurationSection.java @@ -53,8 +53,8 @@ public class InjectConfigurationSection extends AbstractInjectConfig { } catch (final IllegalAccessException ex) { Log.log(Level.SEVERE, "自动注入配置错误!", ex); } - } else { - Log.debug("配置节点 {0} 丢失!", realPath); + } else if (field.getAnnotation(Nullable.class) == null) { + Log.warning(String.format("配置节点 %s 丢失!", realPath)); } } } diff --git a/src/main/java/pw/yumc/YumCore/config/Nullable.java b/src/main/java/pw/yumc/YumCore/config/Nullable.java new file mode 100644 index 0000000..42bf36a --- /dev/null +++ b/src/main/java/pw/yumc/YumCore/config/Nullable.java @@ -0,0 +1,19 @@ +package pw.yumc.YumCore.config; + +import java.lang.annotation.Documented; +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; + +/** + * 允许配置值为空 + * + * @author 喵♂呜 + * @since 2016年8月24日 下午10:41:55 + */ +@Target(ElementType.FIELD) +@Documented +@Retention(RetentionPolicy.RUNTIME) +public @interface Nullable { +}