File tree Expand file tree Collapse file tree 4 files changed +19
-2
lines changed
demo/src/main/java/cc/carm/lib/configuration/demo/tests/conf
features/commentable/src/main/java/cc/carm/lib/configuration/commentable Expand file tree Collapse file tree 4 files changed +19
-2
lines changed Original file line number Diff line number Diff line change @@ -36,6 +36,12 @@ public interface DemoConfiguration extends Configuration {
3636 @ FooterComments ({"上述的枚举内容本质上是通过STRING解析的" })
3737 ConfigValue <ChronoUnit > TEST_ENUM = ConfiguredValue .of (ChronoUnit .class , ChronoUnit .DAYS );
3838
39+ @ HeaderComments ({"空值测试" })
40+ @ InlineComment ("空值Inline注释" )
41+ ConfiguredMap <String , String > EMPTY = ConfiguredMap .builderOf (String .class , String .class )
42+ .asLinkedMap ().fromString ()
43+ .build ();
44+
3945 @ ConfigPath ("registered_users" ) // 通过注解规定配置文件中的路径,若不进行注解则以变量名自动生成。
4046 @ HeaderComments ({"Section类型数据测试" }) // 通过注解给配置添加注释。
4147 @ InlineComment ("默认地注释会加到Section的首行末尾" ) // 通过注解给配置添加注释。
Original file line number Diff line number Diff line change @@ -49,6 +49,17 @@ static void register(@NotNull ConfigurationInitializer initializer) {
4949 FooterComments .class , FOOTER ,
5050 a -> Arrays .asList (a .value ())
5151 );
52+ initializer .registerAnnotation (InlineComment .class , INLINE , a -> {
53+ Map <String , String > map = new HashMap <>();
54+ if (a .regex ().length == 0 ) { // for current path
55+ map .put (null , a .value ());
56+ return map ;
57+ }
58+ for (String regex : a .regex ()) { // for specified path
59+ map .put (regex , a .value ());
60+ }
61+ return map ;
62+ });
5263 initializer .registerAnnotation (InlineComments .class , INLINE , a -> {
5364 Map <String , String > map = new HashMap <>();
5465 for (InlineComment comment : a .value ()) {
Original file line number Diff line number Diff line change 1414 <maven .compiler.target>${project.jdk.version} </maven .compiler.target>
1515 <project .build.sourceEncoding>UTF-8</project .build.sourceEncoding>
1616 <maven .compiler.encoding>UTF-8</maven .compiler.encoding>
17- <deps .yamlcommentwriter.version>1.2.0 </deps .yamlcommentwriter.version>
17+ <deps .yamlcommentwriter.version>1.2.1 </deps .yamlcommentwriter.version>
1818 </properties >
1919
2020 <artifactId >easyconfiguration-yaml</artifactId >
Original file line number Diff line number Diff line change 11package yaml .test ;
22
3+ import cc .carm .lib .configuration .commentable .Commentable ;
34import cc .carm .lib .configuration .commentable .CommentableMeta ;
45import cc .carm .lib .configuration .demo .tests .ConfigurationTest ;
56import cc .carm .lib .configuration .source .ConfigurationHolder ;
@@ -21,7 +22,6 @@ public void test() {
2122 ConfigurationTest .testDemo (holder );
2223 ConfigurationTest .testInner (holder );
2324
24-
2525 Map <String , List <String >> headers = holder .extractMetadata (CommentableMeta .HEADER );
2626 System .out .println ("Header comments: " );
2727 headers .forEach ((k , v ) -> {
You can’t perform that action at this time.
0 commit comments