Skip to content

Commit

Permalink
some reviews
Browse files Browse the repository at this point in the history
  • Loading branch information
brachy84 committed May 25, 2024
1 parent a886ce5 commit d0bfbe3
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 67 deletions.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ private ObjectMapper(String name, GroovyContainer<?> mod, IGameObjectParser<T> h
}

T invoke(String s, Object... args) {
Result<T> t = Objects.requireNonNull(handler.parse(s, args), "Bracket handlers must return a non null result!");
Result<T> t = Objects.requireNonNull(handler.parse(s, args), "Object mapper must return a non null result!");
if (t.hasError()) {
if (this.mod == null) {
GroovyLog.get().error("Can't find {} for name {}!", name, s);
Expand All @@ -67,7 +67,7 @@ T invoke(String s, Object... args) {
t = this.defaultValue.get();
return t == null || t.hasError() ? null : t.getValue();
}
return Objects.requireNonNull(t.getValue(), "Bracket handler result must contain a non-null value!");
return Objects.requireNonNull(t.getValue(), "Object napper result must contain a non-null value!");
}

public GroovyContainer<?> getMod() {
Expand Down Expand Up @@ -216,9 +216,9 @@ public Builder<T> docOfType(String type) {
public void register() {
if (this.name == null || this.name.isEmpty()) throw new IllegalArgumentException("Name must not be empty");
if (this.mod != null && !this.mod.isLoaded())
throw new IllegalArgumentException("Tried to register GameObjectHandler for mod " + this.mod + ", but it's not loaded");
Objects.requireNonNull(this.handler, () -> "The GameObjectHandler function must no be null");
Objects.requireNonNull(this.returnType, () -> "The GameObjectHandler return type must not be null");
throw new IllegalArgumentException("Tried to register ObjectMapper for mod " + this.mod + ", but it's not loaded");
Objects.requireNonNull(this.handler, () -> "The ObjectMapper function must no be null");
Objects.requireNonNull(this.returnType, () -> "The ObjectMapper return type must not be null");
if (this.paramTypes.isEmpty()) this.paramTypes.add(new Class[]{String.class});
if (this.defaultValue == null) this.defaultValue = () -> null;
this.documentation = IDocumented.toJavaDoc(this.documentation);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,9 @@ public class ObjectMapperManager {
private static final Map<String, ObjectMapper<?>> handlers = new Object2ObjectOpenHashMap<>();
private static final Map<String, List<ObjectMapper<?>>> handlerConflicts = new Object2ObjectOpenHashMap<>();
private static final Map<Class<? extends ModPropertyContainer>, Map<String, ObjectMapper<?>>> modHandlers = new Object2ObjectOpenHashMap<>();
public static final String EMPTY = "empty", WILDCARD = "*", SPLITTER = ":";
public static final String EMPTY = "empty";
public static final String WILDCARD = "*";
public static final String SPLITTER = ":";

static void registerGameObjectHandler(GroovyContainer<?> container, ObjectMapper<?> goh) {
String key = goh.getName();
Expand All @@ -63,7 +65,7 @@ static void registerGameObjectHandler(GroovyContainer<?> container, ObjectMapper
ModPropertyContainer propertyContainer = container.get();
var map = modHandlers.computeIfAbsent(propertyContainer.getClass(), k -> new Object2ObjectOpenHashMap<>());
if (map.containsKey(key)) {
throw new IllegalStateException("There already is a GOH with name '" + key + "' in mod " + container.getContainerName());
throw new IllegalStateException("There already is a ObjectMapper with name '" + key + "' in mod " + container.getContainerName());
}
map.put(key, goh);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,8 @@

public class ObjectMappers {

private static final String COMMA = ",", EQUALS = "=";
private static final String COMMA = ",";
private static final String EQUALS = "=";

public static @NotNull Result<ResourceLocation> parseResourceLocation(String mainArg, Object... args) {
String[] parts = mainArg.split(SPLITTER);
Expand All @@ -52,7 +53,7 @@ public class ObjectMappers {

if (args.length > 0) {
if (args.length > 1 || !(args[0] instanceof String)) {
return Result.error("Arguments not valid for bracket handler. Use 'resource(String)' or 'resource(String mod, String path)'");
return Result.error("Arguments not valid for object mapper. Use 'resource(String)' or 'resource(String mod, String path)'");
}
return Result.some(new ResourceLocation(mainArg, (String) args[0]));
}
Expand Down Expand Up @@ -84,7 +85,7 @@ public class ObjectMappers {
}
if (args.length == 1) {
if (meta != 0) {
return Result.error("Defined meta value twice for item bracket handler");
return Result.error("Defined meta value twice for item mapper");
}
meta = (int) args[0];
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ private Expression transformMethodCall(MethodCallExpression mce) {
List<String> suggestions = conflicts.stream()
.map(goh -> goh.getMod() == null ? goh.getName() : "mods." + goh.getMod().getModId() + "." + goh.getName())
.collect(Collectors.toList());
String msg = GroovyLog.format("Can't infer GameObjectHandler from name {}, since one is added by {} mods. " +
String msg = GroovyLog.format("Can't infer ObjectMapper from name {}, since one is added by {} mods. " +
"Please choose one of the following: {}", mce.getMethodAsString(), conflicts.size(), suggestions);
source.addError(new SyntaxException(msg, mce));
}
Expand Down

0 comments on commit d0bfbe3

Please sign in to comment.