mirror of
https://e.coding.net/circlecloud/YumCore.git
synced 2024-11-22 01:48:50 +00:00
feat: 添加注入配置允许Null的注解
Signed-off-by: 502647092 <admin@yumc.pw>
This commit is contained in:
parent
33ef4ffe5a
commit
2968608c71
@ -14,6 +14,11 @@ import java.lang.annotation.Target;
|
|||||||
@Retention(RetentionPolicy.RUNTIME)
|
@Retention(RetentionPolicy.RUNTIME)
|
||||||
public @interface ConfigNode {
|
public @interface ConfigNode {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return 是否允许为空
|
||||||
|
*/
|
||||||
|
boolean notNull() default false;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Defines the path to the node if it has another as the variable name.
|
* Defines the path to the node if it has another as the variable name.
|
||||||
* Every indention is separated with an dot ('.')
|
* Every indention is separated with an dot ('.')
|
||||||
|
@ -72,8 +72,8 @@ public abstract class InjectConfig extends AbstractInjectConfig {
|
|||||||
} catch (final IllegalAccessException ex) {
|
} catch (final IllegalAccessException ex) {
|
||||||
Log.log(Level.SEVERE, "自动注入配置错误!", ex);
|
Log.log(Level.SEVERE, "自动注入配置错误!", ex);
|
||||||
}
|
}
|
||||||
} else {
|
} else if (field.getAnnotation(Nullable.class) == null) {
|
||||||
Log.debug("配置节点 {0} 丢失!", realPath);
|
Log.warning(String.format("配置节点 %s 丢失!", realPath));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -53,8 +53,8 @@ public class InjectConfigurationSection extends AbstractInjectConfig {
|
|||||||
} catch (final IllegalAccessException ex) {
|
} catch (final IllegalAccessException ex) {
|
||||||
Log.log(Level.SEVERE, "自动注入配置错误!", ex);
|
Log.log(Level.SEVERE, "自动注入配置错误!", ex);
|
||||||
}
|
}
|
||||||
} else {
|
} else if (field.getAnnotation(Nullable.class) == null) {
|
||||||
Log.debug("配置节点 {0} 丢失!", realPath);
|
Log.warning(String.format("配置节点 %s 丢失!", realPath));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
19
src/main/java/pw/yumc/YumCore/config/Nullable.java
Normal file
19
src/main/java/pw/yumc/YumCore/config/Nullable.java
Normal file
@ -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 {
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user