diff --git a/src/main/java/com/cleanroommc/groovyscript/gameobjects/GohMetaMethod.java b/src/main/java/com/cleanroommc/groovyscript/gameobjects/GohMetaMethod.java deleted file mode 100644 index 0b2270714..000000000 --- a/src/main/java/com/cleanroommc/groovyscript/gameobjects/GohMetaMethod.java +++ /dev/null @@ -1,56 +0,0 @@ -package com.cleanroommc.groovyscript.gameobjects; - -import com.cleanroommc.groovyscript.mapper.ObjectMapper; -import com.cleanroommc.groovyscript.sandbox.expand.IDocumented; -import groovy.lang.MetaMethod; -import org.codehaus.groovy.reflection.CachedClass; -import org.codehaus.groovy.reflection.ReflectionCache; -import org.jetbrains.annotations.ApiStatus; - -import java.lang.reflect.Modifier; - -@Deprecated -@ApiStatus.ScheduledForRemoval(inVersion = "1.2.0") -public class GohMetaMethod extends MetaMethod implements IDocumented { - - private final ObjectMapper closure; - private final Class owner; - - GohMetaMethod(ObjectMapper closure, Class[] nativeParamTypes, Class owner) { - super(nativeParamTypes); - this.closure = closure; - this.nativeParamTypes = nativeParamTypes; - this.owner = owner; - } - - @Override - public int getModifiers() { - return Modifier.PUBLIC; - } - - @Override - public String getName() { - return this.closure.getName(); - } - - @Override - public Class getReturnType() { - return this.closure.getReturnType(); - } - - @Override - public CachedClass getDeclaringClass() { - return ReflectionCache.getCachedClass(this.owner); - } - - @Override - public Object invoke(Object object, Object[] arguments) { - arguments = coerceArgumentsToClasses(arguments); - return this.closure.call(arguments); - } - - @Override - public String getDocumentation() { - return this.closure.getDocumentation(); - } -} diff --git a/src/main/java/com/cleanroommc/groovyscript/mapper/ObjectMapper.java b/src/main/java/com/cleanroommc/groovyscript/mapper/ObjectMapper.java index 18536dcb3..503f8853e 100644 --- a/src/main/java/com/cleanroommc/groovyscript/mapper/ObjectMapper.java +++ b/src/main/java/com/cleanroommc/groovyscript/mapper/ObjectMapper.java @@ -54,7 +54,7 @@ private ObjectMapper(String name, GroovyContainer mod, IGameObjectParser h } T invoke(String s, Object... args) { - Result t = Objects.requireNonNull(handler.parse(s, args), "Bracket handlers must return a non null result!"); + Result 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); @@ -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() { @@ -216,9 +216,9 @@ public Builder 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); diff --git a/src/main/java/com/cleanroommc/groovyscript/mapper/ObjectMapperManager.java b/src/main/java/com/cleanroommc/groovyscript/mapper/ObjectMapperManager.java index 57844c98e..4097067c8 100644 --- a/src/main/java/com/cleanroommc/groovyscript/mapper/ObjectMapperManager.java +++ b/src/main/java/com/cleanroommc/groovyscript/mapper/ObjectMapperManager.java @@ -39,7 +39,9 @@ public class ObjectMapperManager { private static final Map> handlers = new Object2ObjectOpenHashMap<>(); private static final Map>> handlerConflicts = new Object2ObjectOpenHashMap<>(); private static final Map, Map>> 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(); @@ -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); } diff --git a/src/main/java/com/cleanroommc/groovyscript/mapper/ObjectMappers.java b/src/main/java/com/cleanroommc/groovyscript/mapper/ObjectMappers.java index 3f9b7e6e9..5d2731b55 100644 --- a/src/main/java/com/cleanroommc/groovyscript/mapper/ObjectMappers.java +++ b/src/main/java/com/cleanroommc/groovyscript/mapper/ObjectMappers.java @@ -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 parseResourceLocation(String mainArg, Object... args) { String[] parts = mainArg.split(SPLITTER); @@ -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])); } @@ -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]; } diff --git a/src/main/java/com/cleanroommc/groovyscript/sandbox/transformer/GroovyScriptTransformer.java b/src/main/java/com/cleanroommc/groovyscript/sandbox/transformer/GroovyScriptTransformer.java index ce05478a1..cafbd923a 100644 --- a/src/main/java/com/cleanroommc/groovyscript/sandbox/transformer/GroovyScriptTransformer.java +++ b/src/main/java/com/cleanroommc/groovyscript/sandbox/transformer/GroovyScriptTransformer.java @@ -106,7 +106,7 @@ private Expression transformMethodCall(MethodCallExpression mce) { List 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)); }