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

Feature request: Intercept method #655

Open
EotT123 opened this issue Jan 12, 2025 · 2 comments
Open

Feature request: Intercept method #655

EotT123 opened this issue Jan 12, 2025 · 2 comments

Comments

@EotT123
Copy link
Contributor

EotT123 commented Jan 12, 2025

Currently, it is possible to add methods using manifold-ext. However, overriding the body of an existing method is not supported. This feature could be useful to inject custom logic before or after the original method call, or even to completely replace the method body.

At present, this is not possible because attempting to add an extension with the same method signature results in an exception.

I propose the following solution: adding an @Intercept annotation to an extension method would allow you to override the method’s body, potentially invoking the original method within the intercepted extension. For example:

package extensions.java.lang.Object;

import manifold.ext.rt.api.Extension;
import manifold.ext.rt.api.Intercept;
import manifold.ext.rt.api.This;

@Extension
public class MyObjectExt {
 
  @Intercept
  public static String toString( @This Object object )
  {
    return object == null ? return "null" : object.toString();
  }
}
@EotT123
Copy link
Contributor Author

EotT123 commented Jan 12, 2025

I've implemented this in #656

@EotT123
Copy link
Contributor Author

EotT123 commented Jan 12, 2025

This new feature could be integrated in PR #597, so StringUtils class could override all existing String methods, null checks integrated.

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

No branches or pull requests

2 participants