Skip to content

Commit adf6653

Browse files
committed
update for changes
1 parent 796490a commit adf6653

22 files changed

Lines changed: 413 additions & 53 deletions

File tree

buildSrc/src/main/kotlin/org/spongepowered/configurate/build/component.gradle.kts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,7 @@ sourceSets.configureEach set@{
179179
)
180180
"cpd"(
181181
"encoding" to "UTF-8",
182-
"minimumtokencount" to 105,
182+
"minimumtokencount" to 121,
183183
"outputFile" to outputFile.get().asFile,
184184
"skipLexicalErrors" to true
185185
) {

format/yaml/src/main/java/org/spongepowered/configurate/yaml/ScalarStyle.java

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,24 +24,50 @@
2424

2525
/**
2626
* Style that can be used to represent a scalar.
27+
*
28+
* @since 4.1.0
2729
*/
2830
public enum ScalarStyle {
2931

3032
/**
3133
* A double-quoted string.
3234
*
3335
* <p><pre>"hello world"</pre></p>
36+
*
37+
* @since 4.1.0
3438
*/
3539
DOUBLE_QUOTED(DumperOptions.ScalarStyle.DOUBLE_QUOTED),
3640

3741
/**
3842
* A single-quoted string.
3943
*
4044
* <p><pre>'hello world'</pre></p>
45+
*
46+
* @since 4.1.0
4147
*/
4248
SINGLE_QUOTED(DumperOptions.ScalarStyle.SINGLE_QUOTED),
49+
50+
/**
51+
* String without any quotation.
52+
*
53+
* <p>This may be ambiguous with non-string types.</p>
54+
*
55+
* @since 4.1.0
56+
*/
4357
UNQUOTED(DumperOptions.ScalarStyle.PLAIN),
58+
59+
/**
60+
* Folded scalar.
61+
*
62+
* @since 4.1.0
63+
*/
4464
FOLDED(DumperOptions.ScalarStyle.FOLDED),
65+
66+
/**
67+
* Literal scalar.
68+
*
69+
* @since 4.1.0
70+
*/
4571
LITERAL(DumperOptions.ScalarStyle.LITERAL)
4672
;
4773

format/yaml/src/main/java/org/spongepowered/configurate/yaml/Tag.java

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
* A YAML 1.1/1.2 tag
2828
*
2929
* @apiNote Design based on §3.2.1.1 of the YAML 1.1 spec
30+
* @since 4.1.0
3031
*/
3132
@AutoValue
3233
public abstract class Tag {
@@ -35,6 +36,7 @@ public abstract class Tag {
3536
* Create a new builder for a {@link Tag}.
3637
*
3738
* @return a new builder
39+
* @since 4.1.0
3840
*/
3941
public static Tag.Builder builder() {
4042
return new AutoValue_Tag.Builder();
@@ -47,13 +49,15 @@ public static Tag.Builder builder() {
4749
* The canonical tag URI.
4850
*
4951
* @return tag uri, with `tag:` schema
52+
* @since 4.1.0
5053
*/
5154
public abstract URI uri();
5255

5356
/**
5457
* The native type that maps to this tag.
5558
*
5659
* @return native type for tag
60+
* @since 4.1.0
5761
*/
5862
public abstract Type nativeType();
5963

@@ -62,20 +66,24 @@ public static Tag.Builder builder() {
6266
*
6367
* @return match pattern
6468
* @apiNote See §3.3.2 of YAML 1.1 spec
69+
* @since 4.1.0
6570
*/
6671
public abstract Pattern targetPattern();
6772

6873
/**
6974
* Whether this tag is a global tag with a full namespace or a local one.
7075
*
7176
* @return if this is a global tag
77+
* @since 4.1.0
7278
*/
7379
public final boolean global() {
7480
return uri().getScheme().equals("tag");
7581
}
7682

7783
/**
7884
* A builder for {@link Tag Tags}.
85+
*
86+
* @since 4.1.0
7987
*/
8088
@AutoValue.Builder
8189
public abstract static class Builder {
@@ -85,6 +93,7 @@ public abstract static class Builder {
8593
*
8694
* @param url canonical tag URI
8795
* @return this builder
96+
* @since 4.1.0
8897
*/
8998
public abstract Builder uri(URI url);
9099

@@ -94,6 +103,7 @@ public abstract static class Builder {
94103
*
95104
* @param tagUrl canonical tag URI
96105
* @return this builder
106+
* @since 4.1.0
97107
*/
98108
public final Builder uri(final String tagUrl) {
99109
try {
@@ -113,6 +123,7 @@ public final Builder uri(final String tagUrl) {
113123
*
114124
* @param type type for the value
115125
* @return this builder
126+
* @since 4.1.0
116127
*/
117128
public abstract Builder nativeType(Type type);
118129

@@ -122,13 +133,15 @@ public final Builder uri(final String tagUrl) {
122133
*
123134
* @param targetPattern pattern to match
124135
* @return this builder
136+
* @since 4.1.0
125137
*/
126138
public abstract Builder targetPattern(Pattern targetPattern);
127139

128140
/**
129141
* Create a new tag from the provided parameters.
130142
*
131143
* @return a new tag
144+
* @since 4.1.0
132145
*/
133146
public abstract Tag build();
134147

format/yaml/src/main/java/org/spongepowered/configurate/yaml/TagRepository.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@
2626

2727
/**
2828
* A collection of tags that are understood when reading a document.
29+
*
30+
* @since 4.1.0
2931
*/
3032
public final class TagRepository {
3133

@@ -38,6 +40,7 @@ public final class TagRepository {
3840
*
3941
* @param tags known tags
4042
* @return new tag repository
43+
* @since 4.1.0
4144
*/
4245
public static TagRepository of(final List<Tag> tags) {
4346
return new TagRepository(UnmodifiableCollections.copyOf(tags));
@@ -62,6 +65,7 @@ public static TagRepository of(final List<Tag> tags) {
6265
*
6366
* @param scalar scalar to test
6467
* @return the first matching tag
68+
* @since 4.1.0
6569
*/
6670
public @Nullable Tag forInput(final String scalar) {
6771
for (final Tag tag : this.tags) {

format/yaml/src/main/java/org/spongepowered/configurate/yaml/Yaml11Tags.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@
2424
/**
2525
* Standard types defined on the <a href="https://yaml.org/type/">yaml.org
2626
* tag repository</a>.
27+
*
28+
* @since 4.1.0
2729
*/
2830
public final class Yaml11Tags {
2931

@@ -38,6 +40,7 @@ private static String yamlOrg(final String specific) {
3840
* A binary data tag.
3941
*
4042
* @see <a href="https://yaml.org/type/binary.html">tag:yaml.org,2002:binary</a>
43+
* @since 4.1.0
4144
*/
4245
public static final Tag BINARY = Tag.builder()
4346
.uri(yamlOrg("binary"))
@@ -52,6 +55,7 @@ private static String yamlOrg(final String specific) {
5255
* will only support true|false, we will treat those as the default
5356
* output format.
5457
* @see <a href="https://yaml.org/type/bool.html">tag:yaml.org,2002:bool</a>
58+
* @since 4.1.0
5559
*/
5660
public static final Tag BOOL = Tag.builder()
5761
.uri(yamlOrg("bool"))
@@ -65,6 +69,7 @@ private static String yamlOrg(final String specific) {
6569
* A floating-point number.
6670
*
6771
* @see <a href="https://yaml.org/type/float.html">tag:yaml.org,2002:float</a>
72+
* @since 4.1.0
6873
*/
6974
public static final Tag FLOAT = Tag.builder()
7075
.uri(yamlOrg("float"))
@@ -79,6 +84,7 @@ private static String yamlOrg(final String specific) {
7984
* An integer.
8085
*
8186
* @see <a href="https://yaml.org/type/int.html">tag:yaml.org,2002:int</a>
87+
* @since 4.1.0
8288
*/
8389
public static final Tag INT = Tag.builder()
8490
.uri(yamlOrg("int"))
@@ -97,6 +103,7 @@ private static String yamlOrg(final String specific) {
97103
* are fully implemented.</p>
98104
*
99105
* @see <a href="https://yaml.org/type/merge.html">tag:yaml.org,2002:merge</a>
106+
* @since 4.1.0
100107
*/
101108
public static final Tag MERGE = Tag.builder()
102109
.uri(yamlOrg("merge"))
@@ -112,6 +119,7 @@ private static String yamlOrg(final String specific) {
112119
* likely never be encountered in an in-memory representation.</p>
113120
*
114121
* @see <a href="https://yaml.org/type/null.html">tag:yaml.org,2002:null</a>
122+
* @since 4.1.0
115123
*/
116124
public static final Tag NULL = Tag.builder()
117125
.uri(yamlOrg("null"))
@@ -125,6 +133,7 @@ private static String yamlOrg(final String specific) {
125133
* Any string.
126134
*
127135
* @see <a href="https://yaml.org/type/str.html">tag:yaml.org,2002:str</a>
136+
* @since 4.1.0
128137
*/
129138
public static final Tag STR = Tag.builder()
130139
.uri(yamlOrg("str"))
@@ -136,6 +145,7 @@ private static String yamlOrg(final String specific) {
136145
* A timestamp, containing date, time, and timezone.
137146
*
138147
* @see <a href="https://yaml.org/type/timestamp.html">tag:yaml.org,2002:timestamp</a>
148+
* @since 4.1.0
139149
*/
140150
public static final Tag TIMESTAMP = Tag.builder()
141151
.uri(yamlOrg("timestamp"))

format/yaml/src/test/java/org/spongepowered/configurate/yaml/CommentTest.java

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,8 @@ void testLoadScalarComment() {
3333
+ "\"i'm a string\""
3434
);
3535

36-
assertEquals("Hello world", node.getComment());
37-
assertEquals("i'm a string", node.getValue());
36+
assertEquals("Hello world", node.comment());
37+
assertEquals("i'm a string", node.raw());
3838
}
3939

4040
@Test
@@ -45,8 +45,8 @@ void testLoadBlockMappingComment() {
4545
+ " cat: purrs\n"
4646
);
4747

48-
assertEquals("purrs", node.getNode("test", "cat").getValue());
49-
assertEquals("meow", node.getNode("test", "cat").getComment());
48+
assertEquals("purrs", node.node("test", "cat").raw());
49+
assertEquals("meow", node.node("test", "cat").comment());
5050
}
5151

5252
@Test
@@ -60,9 +60,9 @@ void testLoadBlockScalarSequenceComment() {
6060
+ "- fourth\n"
6161
);
6262

63-
assertNull(test.getNode(0).getComment());
64-
assertEquals("i matter less", test.getNode(1).getComment());
65-
assertEquals("we skipped one", test.getNode(3).getComment());
63+
assertNull(test.node(0).comment());
64+
assertEquals("i matter less", test.node(1).comment());
65+
assertEquals("we skipped one", test.node(3).comment());
6666
}
6767

6868
@Test
@@ -77,11 +77,11 @@ void testLoadScalarCommentsInBlockMapping() {
7777
+ " test2: goodbye\n"
7878
);
7979

80-
final CommentedConfigurationNode child = test.getNode("blah", 0);
81-
assertFalse(child.isVirtual());
82-
assertEquals("beginning sequence", child.getComment());
83-
assertEquals("first on map entry", child.getNode("test").getComment());
84-
assertEquals("on second mapping", child.getNode("test2").getComment());
80+
final CommentedConfigurationNode child = test.node("blah", 0);
81+
assertFalse(child.virtual());
82+
assertEquals("beginning sequence", child.comment());
83+
assertEquals("first on map entry", child.node("test").comment());
84+
assertEquals("on second mapping", child.node("test2").comment());
8585
}
8686

8787
// flow collections are a bit trickier
@@ -99,9 +99,9 @@ void testLoadCommentInFlowMapping() {
9999
+ "}\n"
100100
);
101101

102-
assertEquals("hello", test.getNode("test").getComment());
103-
assertNull(test.getNode("uncommented").getComment());
104-
assertEquals("hi there", test.getNode("last").getComment());
102+
assertEquals("hello", test.node("test").comment());
103+
assertNull(test.node("uncommented").comment());
104+
assertEquals("hi there", test.node("last").comment());
105105
}
106106

107107
@Test
@@ -116,9 +116,9 @@ void testLoadCommentInFlowSequence() {
116116
+ "]"
117117
);
118118

119-
assertEquals("on list", test.getComment());
120-
assertEquals("first", test.getNode(0).getComment());
121-
assertEquals("second", test.getNode(1).getComment());
119+
assertEquals("on list", test.comment());
120+
assertEquals("first", test.node(0).comment());
121+
assertEquals("second", test.node(1).comment());
122122
}
123123

124124
@Test
@@ -130,8 +130,8 @@ void testLoadMixedStructure() {
130130
@Test
131131
void testWriteScalarCommented() {
132132
final CommentedConfigurationNode node = CommentedConfigurationNode.root()
133-
.setValue("test")
134-
.setComment("i have a comment");
133+
.raw("test")
134+
.comment("i have a comment");
135135

136136
assertEquals(
137137
"# i have a comment\n"

format/yaml/src/test/java/org/spongepowered/configurate/yaml/YamlConfigurationLoaderTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,8 @@
2929

3030
import java.io.BufferedReader;
3131
import java.io.BufferedWriter;
32-
import java.io.InputStreamReader;
3332
import java.io.IOException;
33+
import java.io.InputStreamReader;
3434
import java.io.StringWriter;
3535
import java.net.URL;
3636
import java.nio.charset.StandardCharsets;

format/yaml/src/test/java/org/spongepowered/configurate/yaml/YamlParserTest.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616
*/
1717
package org.spongepowered.configurate.yaml;
1818

19-
import static org.junit.jupiter.api.Assertions.assertNotNull;
2019
import static org.junit.jupiter.api.Assertions.assertNull;
2120
import static org.junit.jupiter.api.Assertions.assertThrows;
2221
import static org.junit.jupiter.api.Assertions.assertTrue;
@@ -31,8 +30,8 @@ public class YamlParserTest implements YamlTest {
3130
@Test
3231
void testEmptyDocument() throws IOException {
3332
final ConfigurationNode result = parseString("");
34-
assertTrue(result.isEmpty());
35-
assertNull(result.getValue());
33+
assertTrue(result.empty());
34+
assertNull(result.raw());
3635
}
3736

3837
@Test

format/yaml/src/test/java/org/spongepowered/configurate/yaml/YamlTest.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -67,14 +67,13 @@ default String dump(final CommentedConfigurationNode input, final @Nullable Node
6767
final StringWriter writer = new StringWriter();
6868
try {
6969
YamlConfigurationLoader.builder()
70-
.setSink(() -> new BufferedWriter(writer))
71-
.setNodeStyle(preferredStyle)
70+
.sink(() -> new BufferedWriter(writer))
71+
.nodeStyle(preferredStyle)
7272
.build().save(input);
7373
} catch (IOException e) {
7474
fail(e);
7575
}
7676
return writer.toString();
7777
}
7878

79-
8079
}

0 commit comments

Comments
 (0)