Skip to content

Commit 0b04a19

Browse files
committed
chore(text-logger-slf4j): Refactor module to use modern language features
Also adds a missing `PlatformAPI` annotation and removes an unused method in CallerClassFinder.
1 parent f216cb3 commit 0b04a19

File tree

3 files changed

+11
-13
lines changed

3 files changed

+11
-13
lines changed

text-logger-slf4j/src/main/java/net/kyori/adventure/text/logger/slf4j/CallerClassFinder.java

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -28,13 +28,9 @@ private CallerClassFinder() {
2828
}
2929

3030
static String callingClassName() {
31-
return callingClassName(2); // this, plus the calling method
32-
}
33-
34-
static String callingClassName(final int elementsToSkip) { // elementsToSkip not counting this method
3531
return StackWalker.getInstance().walk(stream -> stream.map(StackWalker.StackFrame::getClassName)
36-
.skip(elementsToSkip + 1)
32+
.skip(2) // Skip this method, plus the calling method.
3733
.findFirst())
38-
.orElseThrow(() -> new IllegalArgumentException("Not enough stack elements to skip " + elementsToSkip + " elements"));
34+
.orElseThrow(() -> new IllegalArgumentException("Not enough stack elements to skip 2 elements"));
3935
}
4036
}

text-logger-slf4j/src/main/java/net/kyori/adventure/text/logger/slf4j/ComponentLoggerProvider.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525

2626
import java.util.function.Function;
2727
import net.kyori.adventure.text.Component;
28+
import net.kyori.adventure.util.PlatformAPI;
2829
import org.jetbrains.annotations.ApiStatus;
2930
import org.jetbrains.annotations.NotNull;
3031
import org.slf4j.Logger;
@@ -34,7 +35,8 @@
3435
*
3536
* @since 4.11.0
3637
*/
37-
@ApiStatus.Internal // SPI for platform use only
38+
@ApiStatus.Internal
39+
@PlatformAPI
3840
public interface ComponentLoggerProvider {
3941
/**
4042
* Create a component logger for the provided logger name.
@@ -52,10 +54,11 @@ public interface ComponentLoggerProvider {
5254
* @since 4.11.0
5355
*/
5456
@ApiStatus.NonExtendable
57+
@PlatformAPI
5558
interface LoggerHelper {
5659

5760
/**
58-
* Create a serializer function that will translate logged output into the system default locale, and then serialize it to plain text.
61+
* Create a serializer function that will translate logged output into the system default locale and then serialize it to plain text.
5962
*
6063
* @return a plain serializer
6164
* @since 4.11.0

text-logger-slf4j/src/main/java/net/kyori/adventure/text/logger/slf4j/UnpackedComponentThrowable.java

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
*/
2424
package net.kyori.adventure.text.logger.slf4j;
2525

26+
import java.io.Serial;
2627
import java.util.function.Function;
2728
import net.kyori.adventure.text.Component;
2829
import net.kyori.adventure.util.ComponentMessageThrowable;
@@ -33,7 +34,7 @@
3334
*/
3435
@SuppressWarnings("OverrideThrowableToString")
3536
final class UnpackedComponentThrowable extends Throwable {
36-
private static final long serialVersionUID = -1L;
37+
@Serial private static final long serialVersionUID = -1L;
3738

3839
private final Class<? extends Throwable> backingType;
3940

@@ -46,10 +47,8 @@ static Throwable unpack(final Throwable maybeRich, final Function<Component, Str
4647

4748
final UnpackedComponentThrowable ret = new UnpackedComponentThrowable(maybeRich.getClass(), serializer.apply(message), cause);
4849
ret.setStackTrace(maybeRich.getStackTrace());
49-
if (suppressed.length > 0) {
50-
for (int i = 0; i < suppressed.length; i++) {
51-
ret.addSuppressed(unpack(suppressed[i], serializer));
52-
}
50+
for (final Throwable throwable : suppressed) {
51+
ret.addSuppressed(unpack(throwable, serializer));
5352
}
5453

5554
return ret;

0 commit comments

Comments
 (0)