Skip to content

Conversation

Pesekjak
Copy link
Contributor

@Pesekjak Pesekjak commented Aug 11, 2025

Problem

The syntax info suppliers developers can provide in the new API are lost during the conversion to SyntaxElementInfo.

Solution

SyntaxElementInfo now stores its instance supplier. If none is provided, it uses the nullary constructor instead.
I also replaced repeated reflection calls with Supplier created using LambdaMetafactory that delegates to the nullary constructor.

Testing Completed

quick test


Completes: none
Related: none

…gacy api,

replaced reflection calls for creating instances of syntax infos with LambdaMetafactory
@Pesekjak Pesekjak requested review from APickledWalrus and a team as code owners August 11, 2025 12:48
@Pesekjak Pesekjak requested review from TheMug06 and removed request for a team August 11, 2025 12:48
@skriptlang-automation skriptlang-automation bot added the needs reviews A PR that needs additional reviews label Aug 11, 2025
…ch/syntaxinfo-supply

# Conflicts:
#	src/main/java/ch/njol/skript/lang/SkriptParser.java
#	src/main/java/ch/njol/skript/lang/SyntaxElementInfo.java
@Pesekjak Pesekjak closed this Aug 11, 2025
@skriptlang-automation skriptlang-automation bot removed the needs reviews A PR that needs additional reviews label Aug 11, 2025
@Pesekjak Pesekjak reopened this Aug 11, 2025
@skriptlang-automation skriptlang-automation bot added the needs reviews A PR that needs additional reviews label Aug 11, 2025
@Pesekjak Pesekjak added the enhancement Feature request, an issue about something that could be improved, or a PR improving something. label Aug 11, 2025
Copy link
Member

@APickledWalrus APickledWalrus left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Overall looks good. I'm not sure the instance supplier changes for the legacy SyntaxElementInfo classes are necessary, given they are unused internally (apart from maybe docs, but that doesn't matter)

return supplier == null ? type.getDeclaredConstructor().newInstance() : supplier.get();
} catch (ReflectiveOperationException e) {
throw new RuntimeException(e);
if (supplier == null) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it'd be fine to set the supplier when the object is constructed so that the field can continue to be final.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think creating a lot of metafactories can get fairly expensive so I wanted to initialize them lazily. I'll check the performance cost during startup and see how bad it gets.

@@ -16,4 +23,36 @@ public static boolean isNormalClass(Class<?> clazz) {
&& !clazz.isInterface() && !Modifier.isAbstract(clazz.getModifiers());
}

private static final Map<Class<?>, Supplier<?>> instanceSuppliers = new ConcurrentHashMap<>();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you think a cache is necessary? The method would probably only be called once per registered syntax, right?

@skriptlang-automation skriptlang-automation bot removed the needs reviews A PR that needs additional reviews label Aug 11, 2025
@APickledWalrus APickledWalrus moved this to In Review in 2.13 Releases Aug 21, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement Feature request, an issue about something that could be improved, or a PR improving something.
Projects
Status: In Review
Development

Successfully merging this pull request may close these issues.

3 participants