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

[Suggestion] @WrapMethod #65

Closed
KingContaria opened this issue Jan 17, 2024 · 2 comments · Fixed by #82
Closed

[Suggestion] @WrapMethod #65

KingContaria opened this issue Jan 17, 2024 · 2 comments · Fixed by #82

Comments

@KingContaria
Copy link

Hi,

a new @WrapMethod injector, which would work similar to WrapOperation, except wrapping the entire method instead of just a single call.

I am currently working on a project which requires me to do some synchronization, however it seems all the ways i can think of to accomplish my goal have some sort of downside.
Specifically, I am trying to synchronize this entire method on the this.surfaceBuilder object.

public void buildSurface(Random random, Chunk chunk, int x, int z, int worldHeight, double noise, BlockState defaultBlock, BlockState defaultFluid, int seaLevel, long seed) {
    this.surfaceBuilder.initSeed(seed);
    this.surfaceBuilder.generate(random, chunk, this, x, z, worldHeight, noise, defaultBlock, defaultFluid, seaLevel, seed);
}

I can't use two WrapOperation's because i rely on it being a single synchronization block and i can't use a mixin config plugin to synchronize the method because i want it to synchronize specifically on the surfacebuilder object AND additionally i only want to apply the synchronization conditionally.
Another solution I've considered is using some form of lock and simply injecting at head and tail, however it seems not ideal to have the lock release not be in a finally block.

Using a new @WrapMethod injector i could simply wrap the entire method with my synchronization logic. It could also allow for adding try-catch or -finally blocks.

The only thing similar in the closed issues i could find was #8 suggesting try-catch-finally injectors which are now covered by wrapoperation, however you also talked about potentially wrapping the entire method or slices of methods. While this wouldn't cover only wrapping a certain slice, it would allow catching errors in the entire method, not just on a single operation.

@LlamaLad7
Copy link
Owner

This is planned but good to have an issue tracking it.

@TropheusJ
Copy link

I also need this, pretty much need to wrap a whole method in a try-with-resources.

Need to wrap a parameter, and then close the wrapper before return.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants