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 { +}