Skip to content

Commit 05c465d

Browse files
committed
v1.1.3
Minimal non-breaking changes
1 parent 5f8525a commit 05c465d

File tree

12 files changed

+46
-22
lines changed

12 files changed

+46
-22
lines changed

build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ plugins {
33
}
44

55
group = 'dev.manere.inscript'
6-
version = '1.1.2'
6+
version = '1.1.3'
77

88
repositories {
99
mavenCentral()

src/main/java/dev/manere/inscript/ConfigSection.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,4 +155,9 @@ default Collection<String> getComments(final @NotNull String key) {
155155
default ConfigSection comment(final @NotNull String key, final @NotNull String @NotNull ... comments) {
156156
return comment(key, Arrays.asList(comments));
157157
}
158+
159+
@NotNull
160+
default String getKey() {
161+
return getSection().getKey();
162+
}
158163
}

src/main/java/dev/manere/inscript/Inscript.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import dev.manere.inscript.format.FileFormat;
55
import dev.manere.inscript.format.FileFormats;
66
import dev.manere.inscript.node.RootSectionNode;
7+
import dev.manere.inscript.value.ValueRegistry;
78
import org.jetbrains.annotations.NotNull;
89
import org.jetbrains.annotations.Nullable;
910

@@ -59,6 +60,11 @@ public static Inscript newInscript(final @NotNull FileFormat format) {
5960
return new Inscript(null, format);
6061
}
6162

63+
@NotNull
64+
public static ValueRegistry getRegistry() {
65+
return ValueRegistry.REGISTRY;
66+
}
67+
6268
@NotNull
6369
public ConfigSection getRoot() {
6470
return root;

src/main/java/dev/manere/inscript/InscriptConstant.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,19 +12,19 @@ public InscriptConstant(final @NotNull T value) {
1212

1313
@NotNull
1414
@CanIgnoreReturnValue
15-
public InscriptConstant<T> set(final @NotNull T value) {
15+
public InscriptConstant<T> value(final @NotNull T value) {
1616
this.value = value;
1717
return this;
1818
}
1919

2020
@NotNull
21-
public T get() {
21+
public T getValue() {
2222
return value;
2323
}
2424

2525
@NotNull
2626
@Override
2727
public String toString() {
28-
return get().toString();
28+
return getValue().toString();
2929
}
3030
}

src/main/java/dev/manere/inscript/SimpleConfigSection.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ public record SimpleConfigSection(@NotNull SectionNode sectionNode) implements C
2525

2626
@Override
2727
public @NotNull ConfigSection createSection(final @NotNull String key) {
28-
if (key.equalsIgnoreCase(InscriptConstants.ROOT_SECTION_KEY.get())) throw new IllegalArgumentException("Illegal attempt to create a root section.");
28+
if (key.equalsIgnoreCase(InscriptConstants.ROOT_SECTION_KEY.getValue())) throw new IllegalArgumentException("Illegal attempt to create a root section.");
2929

3030
final Optional<ConfigSection> sectionFound = getSection(key);
3131
if (sectionFound.isPresent()) return sectionFound.get();

src/main/java/dev/manere/inscript/format/DataScriptFormat.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ public Collection<String> getValidFileExtensions() {
5555
@Nullable
5656
@ApiStatus.Internal
5757
private ConfigNode parseNode(@NotNull String line, final @NotNull BufferedReader reader, final int depth, final @NotNull Set<String> tempComments) throws Exception {
58-
final String indent = InscriptConstants.INDENT.get().apply(depth);
58+
final String indent = InscriptConstants.INDENT.getValue().apply(depth);
5959
if (!line.startsWith(indent)) return null;
6060

6161
line = line.substring(indent.length());
@@ -244,7 +244,7 @@ public String getKey() {
244244
private void writeNode(final @NotNull InscriptStringWriter writer, final @NotNull ConfigNode node, final int depth) {
245245
if (depth < 0) throw new InscriptException();
246246

247-
final String indent = InscriptConstants.INDENT.get().apply(depth);
247+
final String indent = InscriptConstants.INDENT.getValue().apply(depth);
248248

249249
final String key = node.getKey();
250250

@@ -288,9 +288,9 @@ private void writeNode(final @NotNull InscriptStringWriter writer, final @NotNul
288288
final InlineValue<Object> value = ValueRegistry.REGISTRY.<Object>getInline(element.getClass()).orElse(null);
289289

290290
if (value == null) {
291-
writer.write(indent + InscriptConstants.INDENT.get().apply(1) + element);
291+
writer.write(indent + InscriptConstants.INDENT.getValue().apply(1) + element);
292292
} else {
293-
writer.write(indent + InscriptConstants.INDENT.get().apply(1) + value.serialize(element));
293+
writer.write(indent + InscriptConstants.INDENT.getValue().apply(1) + value.serialize(element));
294294
}
295295

296296
if (i != list.size() - 1) {

src/main/java/dev/manere/inscript/format/YAMLFormat.java

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ public String save(final @NotNull ConfigSection root) {
5757
private ConfigNode parseNode(@NotNull String line, final @NotNull BufferedReader reader, final int depth, final @NotNull Set<String> tempComments) throws Exception {
5858
if (line.isBlank() || line.trim().startsWith("-")) return null;
5959

60-
final String indent = InscriptConstants.INDENT.get().apply(depth);
60+
final String indent = InscriptConstants.INDENT.getValue().apply(depth);
6161
if (!line.startsWith(indent)) return null;
6262

6363
line = line.substring(indent.length()).trim();
@@ -167,7 +167,7 @@ public String getKey() {
167167
section.getComments().addAll(tempComments);
168168
tempComments.clear();
169169

170-
final String justReadExpectedChildIndent = InscriptConstants.INDENT.get().apply(depth + 1);
170+
final String justReadExpectedChildIndent = InscriptConstants.INDENT.getValue().apply(depth + 1);
171171
if (justRead.startsWith(justReadExpectedChildIndent) && !justRead.trim().startsWith("-")) {
172172
final ConfigNode childNode = parseNode(justRead, reader, depth + 1, tempComments);
173173
if (childNode != null) section.getChildren().add(childNode);
@@ -176,7 +176,7 @@ public String getKey() {
176176
String childLine;
177177

178178
while ((childLine = reader.readLine()) != null) {
179-
final String expectedChildIndent = InscriptConstants.INDENT.get().apply(depth + 1);
179+
final String expectedChildIndent = InscriptConstants.INDENT.getValue().apply(depth + 1);
180180
if (!childLine.startsWith(expectedChildIndent) && !childLine.trim().startsWith("-")) break;
181181

182182
final ConfigNode childNode = parseNode(childLine, reader, depth + 1, tempComments);
@@ -298,7 +298,7 @@ public String getKey() {
298298
private void writeNode(final @NotNull InscriptStringWriter writer, final @NotNull ConfigNode node, final int depth) {
299299
if (depth < 0) throw new InscriptException();
300300

301-
final String indent = InscriptConstants.INDENT.get().apply(depth);
301+
final String indent = InscriptConstants.INDENT.getValue().apply(depth);
302302

303303
final String key = node.getKey();
304304

@@ -309,7 +309,7 @@ private void writeNode(final @NotNull InscriptStringWriter writer, final @NotNul
309309
}
310310

311311
if (section.getChildren().isEmpty()) {
312-
writer.write(indent + key + ":\n" + InscriptConstants.INDENT.get().apply(1) + "\n");
312+
writer.write(indent + key + ":\n" + InscriptConstants.INDENT.getValue().apply(1) + "\n");
313313
return;
314314
}
315315

@@ -341,9 +341,9 @@ private void writeNode(final @NotNull InscriptStringWriter writer, final @NotNul
341341
final InlineValue<Object> value = ValueRegistry.REGISTRY.<Object>getInline(element.getClass()).orElse(null);
342342

343343
if (value == null) {
344-
writer.write(indent + InscriptConstants.INDENT.get().apply(1) + "- " + element);
344+
writer.write(indent + InscriptConstants.INDENT.getValue().apply(1) + "- " + element);
345345
} else {
346-
writer.write(indent + InscriptConstants.INDENT.get().apply(1) + "- " + value.serialize(element));
346+
writer.write(indent + InscriptConstants.INDENT.getValue().apply(1) + "- " + value.serialize(element));
347347
}
348348

349349
writer.newLine();

src/main/java/dev/manere/inscript/node/RootSectionNode.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ public class RootSectionNode extends SectionNode {
1313
@NotNull
1414
@Override
1515
public String getKey() {
16-
return InscriptConstants.ROOT_SECTION_KEY.get();
16+
return InscriptConstants.ROOT_SECTION_KEY.getValue();
1717
}
1818

1919
@NotNull

src/main/java/dev/manere/inscript/value/InlineValue.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,11 @@ static <T> InlineValue.Builder<T> builder() {
4444
return new InlineValue.Builder<>();
4545
}
4646

47+
@NotNull
48+
static <T> InlineValue.Builder<T> builder(final @NotNull Class<T> ignoredType) {
49+
return builder();
50+
}
51+
4752
class Builder<T> {
4853
private Function<@NotNull String, @NotNull Boolean> matches;
4954
private Function<@NotNull String, @Nullable T> deserialize;

src/main/java/dev/manere/inscript/value/InscriptValue.java

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,14 @@ public interface InscriptValue<T> {
1212
@Nullable
1313
T deserialize(final @NotNull ConfigSection section);
1414

15-
void serialize(final @NotNull T t, final @NotNull ConfigSection section);
15+
default void serialize(final @NotNull T t, final @NotNull ConfigSection section) {
16+
throw new UnsupportedOperationException("Not implemented");
17+
}
1618

1719
@NotNull
1820
static <T> InscriptValue<T> create(
1921
final @NotNull Function<@NotNull ConfigSection, @Nullable T> deserialize,
20-
final @NotNull BiConsumer<@NotNull T, @NotNull ConfigSection> serialize
22+
final @Nullable BiConsumer<@NotNull T, @NotNull ConfigSection> serialize
2123
) {
2224
return new InscriptValue<>() {
2325
@Override
@@ -27,6 +29,7 @@ static <T> InscriptValue<T> create(
2729

2830
@Override
2931
public void serialize(@NotNull T t, @NotNull ConfigSection section) {
32+
if (serialize == null) throw new UnsupportedOperationException("Not implemented");
3033
serialize.accept(t, section);
3134
}
3235
};
@@ -38,6 +41,11 @@ static <T> InscriptValue.Builder<T> builder() {
3841
return new InscriptValue.Builder<>();
3942
}
4043

44+
@NotNull
45+
static <T> InscriptValue.Builder<T> builder(final @NotNull Class<T> ignoredType) {
46+
return builder();
47+
}
48+
4149
class Builder<T> {
4250
private Function<@NotNull ConfigSection, @Nullable T> deserialize;
4351
private BiConsumer<@NotNull T, @NotNull ConfigSection> serialize;

0 commit comments

Comments
 (0)