@@ -44,6 +44,7 @@ static <V> YamlValue.Builder<V> builder(String key, YamlAccessor<V> accessor)
4444 static class BuilderImpl <V > implements YamlValue .Builder <V >
4545 {
4646 @ NullOr List <Migration > migrations = null ;
47+ @ NullOr List <String > comments = null ;
4748
4849 final String key ;
4950 final YamlAccessor <V > accessor ;
@@ -64,23 +65,34 @@ public YamlValue.Builder<V> migrates(Migration ... policies)
6465
6566 return this ;
6667 }
67-
68+
69+ @ Override
70+ public YamlValue .Builder <V > comments (String ... lines )
71+ {
72+ Objects .requireNonNull (lines , "lines" );
73+
74+ if (comments == null ) { comments = new ArrayList <>(); }
75+ Collections .addAll (comments , lines );
76+
77+ return this ;
78+ }
79+
6880 @ Override
6981 public YamlValue <V > maybe ()
7082 {
71- return new MaybeImpl <>(key , accessor , migrations );
83+ return new MaybeImpl <>(key , accessor , migrations , comments );
7284 }
7385
7486 @ Override
7587 public DefaultYamlValue <V > defaults (V def )
7688 {
77- return new DefaultImpl <>(key , accessor , migrations , def );
89+ return new DefaultImpl <>(key , accessor , migrations , comments , def );
7890 }
79-
91+
8092 @ Override
8193 public ExampleYamlValue <V > example (V example )
8294 {
83- return new ExampleImpl <>(key , accessor , migrations , example );
95+ return new ExampleImpl <>(key , accessor , migrations , comments , example );
8496 }
8597 }
8698
@@ -93,20 +105,30 @@ static class MaybeImpl<V> implements YamlValue<V>
93105 final String key ;
94106 final YamlAccessor <V > accessor ;
95107 final List <Migration > migrations ;
96-
97- MaybeImpl (String key , YamlAccessor <V > accessor , @ NullOr List <Migration > migrations )
108+ final List <String > comments ;
109+
110+ MaybeImpl (
111+ String key ,
112+ YamlAccessor <V > accessor ,
113+ @ NullOr List <Migration > migrations ,
114+ @ NullOr List <String > comments
115+ )
98116 {
99117 this .key = key ;
100118 this .accessor = accessor ;
101119 this .migrations = (migrations == null ) ? List .of () : List .copyOf (migrations );
120+ this .comments = (comments == null ) ? List .of () : List .copyOf (comments );
102121 }
103-
122+
104123 @ Override
105124 public String key () { return key ; }
106-
125+
107126 @ Override
108127 public List <Migration > migrations () { return migrations ; }
109128
129+ @ Override
130+ public List <String > comments () { return comments ; }
131+
110132 @ Override
111133 public Optional <V > get (ConfigurationSection storage ) { return accessor .get (storage , key ); }
112134
@@ -117,10 +139,16 @@ static class MaybeImpl<V> implements YamlValue<V>
117139 static class DefaultImpl <V > extends MaybeImpl <V > implements DefaultYamlValue <V >
118140 {
119141 V def ;
120-
121- DefaultImpl (String key , YamlAccessor <V > accessor , @ NullOr List <Migration > migrations , V def )
142+
143+ DefaultImpl (
144+ String key ,
145+ YamlAccessor <V > accessor ,
146+ @ NullOr List <Migration > migrations ,
147+ @ NullOr List <String > comments ,
148+ V def
149+ )
122150 {
123- super (key , accessor , migrations );
151+ super (key , accessor , migrations , comments );
124152 this .def = Objects .requireNonNull (def , "def" );
125153 }
126154
@@ -131,9 +159,15 @@ static class DefaultImpl<V> extends MaybeImpl<V> implements DefaultYamlValue<V>
131159
132160 static class ExampleImpl <V > extends DefaultImpl <V > implements ExampleYamlValue <V >
133161 {
134- ExampleImpl (String key , YamlAccessor <V > accessor , @ NullOr List <Migration > migrations , V example )
162+ ExampleImpl (
163+ String key ,
164+ YamlAccessor <V > accessor ,
165+ @ NullOr List <Migration > migrations ,
166+ @ NullOr List <String > comments ,
167+ V example
168+ )
135169 {
136- super (key , accessor , migrations , example );
170+ super (key , accessor , migrations , comments , example );
137171 }
138172 }
139173}
0 commit comments