Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cleanup/java-hacks #145

Merged
merged 7 commits into from
Feb 9, 2025
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Updated javadoc for EntrypointManager#registerLookup
mineLdiver committed Jan 9, 2025
commit f762d18dcafd1644a23f2f641c6bb415d30805f7
Original file line number Diff line number Diff line change
@@ -22,6 +22,34 @@
public class EntrypointManager {
private static final Reference2ReferenceMap<Class<?>, MethodHandles.Lookup> LOOKUPS = new Reference2ReferenceOpenHashMap<>();

/**
* By registering a lookup via this method, an entrypoint class gives StationAPI and UnsafeEvents safe access to
* its non-public fields and methods.
*
* <p>
* This is useful if you wish to keep your
* {@link net.mine_diver.unsafeevents.listener.EventListener listener methods} or utility fields
* (such as {@link net.modificationstation.stationapi.api.mod.entrypoint.Entrypoint.Instance},
* {@link net.modificationstation.stationapi.api.mod.entrypoint.Entrypoint.Namespace},
* and {@link net.modificationstation.stationapi.api.mod.entrypoint.Entrypoint.Logger}) private.
* </p>
*
* <p>
* It's best to perform the registration as soon as possible in the static initializer of the class,
* for example:
* <pre><code>
* public class ExampleEntrypoint {
* static {
* EntrypointManager.registerLookup(MethodHandles.lookup());
* }
*
* // ... the rest of the entrypoint code ...
* }
* </code></pre>
* </p>
*
* @param lookup an entrypoint class's lookup obtained via {@link MethodHandles#lookup()}.
*/
public static void registerLookup(MethodHandles.Lookup lookup) {
Listener.registerLookup(lookup);
LOOKUPS.put(lookup.lookupClass(), lookup);