mirror of
https://github.com/CarmJos/EasyConfiguration.git
synced 2026-06-04 10:38:19 +08:00
fix(comment): Fixed yaml comments
This commit is contained in:
@@ -36,6 +36,12 @@ public interface DemoConfiguration extends Configuration {
|
||||
@FooterComments({"上述的枚举内容本质上是通过STRING解析的"})
|
||||
ConfigValue<ChronoUnit> TEST_ENUM = ConfiguredValue.of(ChronoUnit.class, ChronoUnit.DAYS);
|
||||
|
||||
@HeaderComments({"空值测试"})
|
||||
@InlineComment("空值Inline注释")
|
||||
ConfiguredMap<String, String> EMPTY = ConfiguredMap.builderOf(String.class, String.class)
|
||||
.asLinkedMap().fromString()
|
||||
.build();
|
||||
|
||||
@ConfigPath("registered_users") // 通过注解规定配置文件中的路径,若不进行注解则以变量名自动生成。
|
||||
@HeaderComments({"Section类型数据测试"}) // 通过注解给配置添加注释。
|
||||
@InlineComment("默认地注释会加到Section的首行末尾") // 通过注解给配置添加注释。
|
||||
|
||||
+11
@@ -49,6 +49,17 @@ public interface CommentableMeta {
|
||||
FooterComments.class, FOOTER,
|
||||
a -> Arrays.asList(a.value())
|
||||
);
|
||||
initializer.registerAnnotation(InlineComment.class, INLINE, a -> {
|
||||
Map<String, String> map = new HashMap<>();
|
||||
if (a.regex().length == 0) { // for current path
|
||||
map.put(null, a.value());
|
||||
return map;
|
||||
}
|
||||
for (String regex : a.regex()) { // for specified path
|
||||
map.put(regex, a.value());
|
||||
}
|
||||
return map;
|
||||
});
|
||||
initializer.registerAnnotation(InlineComments.class, INLINE, a -> {
|
||||
Map<String, String> map = new HashMap<>();
|
||||
for (InlineComment comment : a.value()) {
|
||||
|
||||
@@ -14,7 +14,7 @@
|
||||
<maven.compiler.target>${project.jdk.version}</maven.compiler.target>
|
||||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
||||
<maven.compiler.encoding>UTF-8</maven.compiler.encoding>
|
||||
<deps.yamlcommentwriter.version>1.2.0</deps.yamlcommentwriter.version>
|
||||
<deps.yamlcommentwriter.version>1.2.1</deps.yamlcommentwriter.version>
|
||||
</properties>
|
||||
|
||||
<artifactId>easyconfiguration-yaml</artifactId>
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package yaml.test;
|
||||
|
||||
import cc.carm.lib.configuration.commentable.Commentable;
|
||||
import cc.carm.lib.configuration.commentable.CommentableMeta;
|
||||
import cc.carm.lib.configuration.demo.tests.ConfigurationTest;
|
||||
import cc.carm.lib.configuration.source.ConfigurationHolder;
|
||||
@@ -21,7 +22,6 @@ public class YamlTests {
|
||||
ConfigurationTest.testDemo(holder);
|
||||
ConfigurationTest.testInner(holder);
|
||||
|
||||
|
||||
Map<String, List<String>> headers = holder.extractMetadata(CommentableMeta.HEADER);
|
||||
System.out.println("Header comments: ");
|
||||
headers.forEach((k, v) -> {
|
||||
|
||||
Reference in New Issue
Block a user