Skip to content

Commit 1a57de0

Browse files
committed
more
1 parent a13dc38 commit 1a57de0

File tree

4 files changed

+32
-10
lines changed

4 files changed

+32
-10
lines changed

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

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,10 +48,11 @@ public final Set<Class<?>> supportedTypes() {
4848
abstract static class Scalar<V> extends Tag {
4949

5050
private final @Nullable Pattern pattern;
51+
private final @Nullable ScalarStyle preferredScalarStyle;
5152

5253
// for unregistered tags on scalars
5354
static Scalar<String> ofUnknown(final URI tagUri) {
54-
return new Scalar<String>(tagUri, Collections.emptySet(), null) {
55+
return new Scalar<String>(tagUri, Collections.emptySet(), null, null) {
5556
@Override
5657
public String fromString(final String input) {
5758
return input;
@@ -65,8 +66,13 @@ public String toString(final String own) {
6566
}
6667

6768
Scalar(final URI tagUri, final Set<Class<? extends V>> supportedTypes, final @Nullable Pattern pattern) {
69+
this(tagUri, supportedTypes, pattern, null);
70+
}
71+
72+
Scalar(final URI tagUri, final Set<Class<? extends V>> supportedTypes, final @Nullable Pattern pattern, final @Nullable ScalarStyle preferredScalarStyle) {
6873
super(tagUri, supportedTypes);
6974
this.pattern = pattern;
75+
this.preferredScalarStyle = preferredScalarStyle;
7076
}
7177

7278
/**
@@ -76,11 +82,22 @@ public String toString(final String own) {
7682
* implicit tag.</p>
7783
*
7884
* @return the detection pattern
85+
* @since 4.2.0
7986
*/
8087
public final @Nullable Pattern pattern() {
8188
return this.pattern;
8289
}
8390

91+
/**
92+
* Get the preferred scalar style to use for this type, when none is specifically used.
93+
*
94+
* @return the preferred scalar style
95+
* @since 4.2.0
96+
*/
97+
public final @Nullable ScalarStyle preferredScalarStyle() {
98+
return this.preferredScalarStyle;
99+
}
100+
84101
public abstract V fromString(String input) throws ParsingException;
85102

86103
public abstract String toString(V own) throws ConfigurateException;

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,7 @@ static TagRepository.Builder builder() {
117117
* @return a calculated tag
118118
* @since 4.2.0
119119
*/
120+
@SuppressWarnings("rawtypes")
120121
AnalyzedTag analyze(final ConfigurationNode node) throws ConfigurateException {
121122
final @Nullable Tag explicit = node.ownHint(YamlConfigurationLoader.TAG);
122123
final @Nullable Tag calculated;

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@
9797
* where useful).</li>
9898
* <li>Alias nodes and merge keys: flattened on load, not yet supported by
9999
* the Configurate object model</li>
100-
* <li>keys: limited, tag and representation information is lost when using
100+
* <li>Keys: limited, tag and representation information is lost when using
101101
* complex keys (since keys are not preserved as a node)</li>
102102
* </ul>
103103
*
@@ -191,8 +191,8 @@ public static final class Builder extends AbstractConfigurationLoader.Builder<Bu
191191
private boolean enableComments = COMMENTS_DEFAULT;
192192

193193
Builder() {
194-
indent(4);
195-
defaultOptions(o -> o.nativeTypes(NATIVE_TYPES));
194+
this.indent(4);
195+
this.defaultOptions(o -> o.nativeTypes(NATIVE_TYPES));
196196
}
197197

198198
/**

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

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -112,25 +112,25 @@ public void enterNode(final ConfigurationNode node, final State state) throws Co
112112
public void enterMappingNode(final ConfigurationNode node, final State state) throws ConfigurateException {
113113
final TagRepository.AnalyzedTag analysis = this.tags.analyze(node);
114114
state.emit(new MappingStartEvent(
115-
anchor(node),
115+
this.anchor(node),
116116
analysis.actual().tagUri().toString(),
117117
analysis.implicit(),
118118
null,
119119
null,
120-
NodeStyle.asSnakeYaml(determineStyle(node, state))
120+
NodeStyle.asSnakeYaml(this.determineStyle(node, state))
121121
));
122122
}
123123

124124
@Override
125125
public void enterListNode(final ConfigurationNode node, final State state) throws ConfigurateException {
126126
final TagRepository.AnalyzedTag analysis = this.tags.analyze(node);
127127
state.emit(new SequenceStartEvent(
128-
anchor(node),
128+
this.anchor(node),
129129
analysis.actual().tagUri().toString(),
130130
analysis.implicit(),
131131
null,
132132
null,
133-
NodeStyle.asSnakeYaml(determineStyle(node, state))
133+
NodeStyle.asSnakeYaml(this.determineStyle(node, state))
134134
));
135135
}
136136

@@ -149,14 +149,18 @@ public void enterScalarNode(final ConfigurationNode node, final State state) thr
149149
}
150150

151151
state.emit(new ScalarEvent(
152-
anchor(node),
152+
this.anchor(node),
153153
actual.tagUri().toString(),
154154
implicity,
155155
((Tag.Scalar<Object>) actual).toString(node.rawScalar()),
156156
null,
157157
null,
158158
// todo: support configuring default scalar style
159-
ScalarStyle.asSnakeYaml(node.hint(YamlConfigurationLoader.SCALAR_STYLE), implicity, null)
159+
ScalarStyle.asSnakeYaml(
160+
node.hint(YamlConfigurationLoader.SCALAR_STYLE),
161+
implicity,
162+
((Tag.Scalar<?>) actual).preferredScalarStyle()
163+
)
160164
));
161165
}
162166

0 commit comments

Comments
 (0)