Skip to content

Commit

Permalink
Fix code style inconsistencies; Add opel placeholder evaluator as add…
Browse files Browse the repository at this point in the history
…on to prevent all of its dependencies from being included
  • Loading branch information
shitzuu committed Aug 15, 2024
1 parent af013bc commit 09b3ddc
Show file tree
Hide file tree
Showing 8 changed files with 13 additions and 133 deletions.
10 changes: 2 additions & 8 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
@@ -1,17 +1,11 @@
[versions]
allegro-opel = "1.1.14"
apache-commons-lang3 = "3.16.0"
spotify-completable-futures = "0.3.6"
futures = "0.3.6"
adventure = "4.17.0"
parboiled = "1.4.1"

[libraries]
opel = { module = "pl.allegro.tech:opel", version.ref = "allegro-opel" }
lang = { module = "org.apache.commons:commons-lang3", version.ref = "apache-commons-lang3" }
futures = { module = "com.spotify:completable-futures", version.ref = "spotify-completable-futures" }
futures = { module = "com.spotify:completable-futures", version.ref = "futures" }
adventure-api = { module = "net.kyori:adventure-api", version.ref = "adventure" }
adventure-minimessage = { module = "net.kyori:adventure-text-minimessage", version.ref = "adventure" }
parboiled = { module = "org.parboiled:parboiled-java", version.ref = "parboiled" }

[bundles]
adventure = ["adventure-api", "adventure-minimessage"]
3 changes: 0 additions & 3 deletions honey-common/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,6 @@ plugins {

dependencies {
api(libs.futures)
api(libs.lang)
api(libs.opel)
api(libs.parboiled)
compileOnly(libs.bundles.adventure)
}

Expand Down
15 changes: 0 additions & 15 deletions honey-common/src/dev/shiza/honey/adventure/AdventureHoney.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,12 @@

import dev.shiza.honey.Honey;
import dev.shiza.honey.message.MessageCompiler;
import dev.shiza.honey.opel.OpelPlaceholderEvaluatorFactory;
import dev.shiza.honey.placeholder.evaluator.PlaceholderEvaluator;
import dev.shiza.honey.placeholder.resolver.PlaceholderResolver;
import dev.shiza.honey.placeholder.sanitizer.PlaceholderSanitizer;
import dev.shiza.honey.reflection.ReflectivePlaceholderEvaluatorFactory;
import net.kyori.adventure.text.Component;
import net.kyori.adventure.text.minimessage.MiniMessage;
import pl.allegro.tech.opel.OpelEngine;
import pl.allegro.tech.opel.OpelEngineBuilder;

public interface AdventureHoney extends Honey<Component> {

Expand All @@ -28,18 +25,6 @@ static AdventureHoney createReflective(final MiniMessage miniMessage) {
ReflectivePlaceholderEvaluatorFactory.create());
}

static AdventureHoney createOpel() {
return createOpel(miniMessage(), OpelEngineBuilder.create().build());
}

static AdventureHoney createOpel(final MiniMessage miniMessage, final OpelEngine opelEngine) {
return create(
AdventureMessageCompilerFactory.create(miniMessage),
PlaceholderResolver.create(),
PlaceholderSanitizer.create(),
OpelPlaceholderEvaluatorFactory.create(opelEngine));
}

private static AdventureHoney create(
final MessageCompiler<Component> messageCompiler,
final PlaceholderResolver placeholderResolver,
Expand Down
20 changes: 0 additions & 20 deletions honey-common/src/dev/shiza/honey/opel/OpelImplicitConversion.java

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -68,17 +68,6 @@ private CompletableFuture<EvaluatedPlaceholder> asEvaluatedPlaceholder(
return evaluatedValue.thenApply(value -> new EvaluatedPlaceholder(placeholder, value));
}

private Object invokeMethodHandle(final Object parent, final MethodHandle handle) {
try {
return handle.invoke(parent);
} catch (final Throwable exception) {
throw new ReflectivePlaceholderEvaluationException(
"Could not invoke method handle %s for %s parent, because of unexpected exception."
.formatted(handle.toString(), parent.getClass().getSimpleName()),
exception);
}
}

private MethodHandle getMethodHandle(final Object parent, final String path) {
final MethodHandleCompositeKey compositeKey = new MethodHandleCompositeKey(parent, path);
return methodHandles.computeIfAbsent(compositeKey, key -> getMethodHandleUnsafe(parent, path));
Expand All @@ -96,6 +85,17 @@ private MethodHandle getMethodHandleUnsafe(final Object parent, final String pat
}
}

private Object invokeMethodHandle(final Object parent, final MethodHandle handle) {
try {
return handle.invoke(parent);
} catch (final Throwable exception) {
throw new ReflectivePlaceholderEvaluationException(
"Could not invoke method handle %s for %s parent, because of unexpected exception."
.formatted(handle.toString(), parent.getClass().getSimpleName()),
exception);
}
}

record MethodHandleCompositeKey(String className, String methodName) {

MethodHandleCompositeKey(Object parent, String methodName) {
Expand Down

0 comments on commit 09b3ddc

Please sign in to comment.