Skip to content

Commit 2ce7fd4

Browse files
committed
Bug Fix
1 parent a0a39ab commit 2ce7fd4

File tree

3 files changed

+35
-27
lines changed

3 files changed

+35
-27
lines changed

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

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -95,16 +95,16 @@ private void writeNode(final @NotNull BufferedWriter writer, final @NotNull Insc
9595
writeNode(writer, child, depth + 1);
9696
}
9797

98-
writer.write(indent + InscriptConstants.SECTION_END + "\n");
98+
writer.write(indent + InscriptConstants.SECTION_END.get() + "\n");
9999
} else if (node instanceof ScalarNode<?> scalar) {
100100
final Object objectValue = scalar.getValue();
101101
final Class<?> type = objectValue.getClass();
102102

103103
if (objectValue instanceof List<?> list) {
104104
if (list.isEmpty()) {
105-
writer.write(indent + key + " = " + InscriptConstants.LIST_START + InscriptConstants.LIST_END);
105+
writer.write(indent + key + " = " + InscriptConstants.LIST_START.get() + InscriptConstants.LIST_END.get());
106106
} else {
107-
writer.write(indent + key + " = " + InscriptConstants.LIST_START + "\n");
107+
writer.write(indent + key + " = " + InscriptConstants.LIST_START.get() + "\n");
108108

109109
for (int i = 0; i < list.size(); i++) {
110110
final Object element = list.get(i);
@@ -127,7 +127,7 @@ private void writeNode(final @NotNull BufferedWriter writer, final @NotNull Insc
127127
break;
128128
}
129129

130-
writer.write(indent + InscriptConstants.LIST_END + "\n");
130+
writer.write(indent + InscriptConstants.LIST_END.get() + "\n");
131131
}
132132
} else {
133133
final InlineValue<Object> value = ValueRegistry.REGISTRY.<Object>getInline(type).orElse(null);
@@ -194,8 +194,8 @@ private InscriptNode parseNode(@NotNull String line, final @NotNull BufferedRead
194194
final String name = parts[0].trim();
195195

196196
final String key = name
197-
.replaceAll(InscriptConstants.SECTION_START.get(), "")
198-
.replaceAll(InscriptConstants.SECTION_END.get(), "")
197+
.replace(InscriptConstants.SECTION_START.get(), "")
198+
.replace(InscriptConstants.SECTION_END.get(), "")
199199
.trim();
200200

201201
if (parts.length == 1) {
@@ -270,6 +270,8 @@ public String getKey() {
270270
InlineValue<?> inlineMatched = new StringValue();
271271

272272
for (final InlineValue<?> inline : ValueRegistry.REGISTRY.getInlineRegistry().values()) {
273+
if (inline.equals(new StringValue())) continue;
274+
273275
if (inline.matches(value)) {
274276
inlineMatched = inline;
275277
break;
@@ -297,6 +299,8 @@ public String getKey() {
297299
InlineValue<?> inlineMatched = new StringValue();
298300

299301
for (final InlineValue<?> inline : ValueRegistry.REGISTRY.getInlineRegistry().values()) {
302+
if (inline.equals(new StringValue())) continue;
303+
300304
if (inline.matches(value)) {
301305
inlineMatched = inline;
302306
break;

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

Lines changed: 22 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -5,32 +5,34 @@
55
import org.jetbrains.annotations.NotNull;
66
import org.jetbrains.annotations.Unmodifiable;
77

8+
import java.util.LinkedHashMap;
89
import java.util.Map;
910
import java.util.Optional;
1011
import java.util.UUID;
11-
import java.util.concurrent.ConcurrentHashMap;
1212

1313
public class ValueRegistry {
14-
public static final ValueRegistry REGISTRY = new ValueRegistry()
15-
.register(Boolean.class, new BooleanValue())
16-
17-
.register(Byte.class, new ByteValue())
18-
.register(Short.class, new ShortValue())
19-
20-
.register(Integer.class, new IntegerValue())
21-
.register(Double.class, new DoubleValue())
22-
.register(Float.class, new FloatValue())
23-
.register(Long.class, new LongValue())
24-
25-
.register(UUID.class, new UUIDValue())
26-
27-
.register(Character.class, new CharacterValue())
28-
.register(String.class, new StringValue());
14+
public static final ValueRegistry REGISTRY;
15+
16+
static {
17+
REGISTRY = new ValueRegistry()
18+
.register(Boolean.class, new BooleanValue())
19+
.register(Byte.class, new ByteValue())
20+
.register(Short.class, new ShortValue())
21+
.register(Integer.class, new IntegerValue())
22+
.register(Double.class, new DoubleValue())
23+
.register(Float.class, new FloatValue())
24+
.register(Long.class, new LongValue())
25+
.register(UUID.class, new UUIDValue())
26+
.register(Character.class, new CharacterValue());
27+
28+
// Ensure String is always registered last.
29+
REGISTRY.register(String.class, new StringValue());
30+
}
2931

3032
private ValueRegistry() {}
3133

32-
private final Map<Class<?>, InlineValue<?>> inlineRegistry = new ConcurrentHashMap<>();
33-
private final Map<Class<?>, InscriptValue<?>> inscriptRegistry = new ConcurrentHashMap<>();
34+
private final Map<Class<?>, InlineValue<?>> inlineRegistry = new LinkedHashMap<>();
35+
private final Map<Class<?>, InscriptValue<?>> inscriptRegistry = new LinkedHashMap<>();
3436

3537
@NotNull
3638
public <T> Optional<InlineValue<T>> getInline(final @NotNull Class<? extends T> ignoredKey) {
@@ -73,12 +75,12 @@ public <T> ValueRegistry register(final @NotNull Class<? super T> key, final @No
7375
@NotNull
7476
@Unmodifiable
7577
public Map<Class<?>, InlineValue<?>> getInlineRegistry() {
76-
return Map.copyOf(inlineRegistry);
78+
return new LinkedHashMap<>(inlineRegistry);
7779
}
7880

7981
@NotNull
8082
@Unmodifiable
8183
public Map<Class<?>, InscriptValue<?>> getInscriptRegistry() {
82-
return Map.copyOf(inscriptRegistry);
84+
return new LinkedHashMap<>(inscriptRegistry);
8385
}
8486
}

src/main/java/dev/manere/inscript/value/impl/UUIDValue.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,9 @@
99
public class UUIDValue implements InlineValue<UUID> {
1010
@Override
1111
public boolean matches(final @NotNull String text) {
12-
if (!text.startsWith("uuid(") && !text.endsWith(")")) return false;
12+
if (!text.startsWith("uuid(") && !text.endsWith(")")) {
13+
return false;
14+
}
1315

1416
try {
1517
UUID.fromString(text.replaceAll("uuid\\(", "").replaceAll("\\)", ""));

0 commit comments

Comments
 (0)