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

Loan pattern api for ClassCreator to control life cycle of object from API #181

Open
poldinik opened this issue Mar 30, 2024 · 0 comments
Open

Comments

@poldinik
Copy link

poldinik commented Mar 30, 2024

I would be nice if ClassCreator provides a static API to produce an instance of ClassCreator with try/catch with resource inside API, instead to delegate to a calling function the responsibility to implement try/catch

public static void withClassCreator(ClassCreator.Builder builder, Consumer<ClassCreator> consumer){
        try(ClassCreator classCreator = builder.build()){
            consumer.accept(classCreator);
        }
    } 

An example of usage

withClassCreator(
                ClassCreator.builder()
                        .classOutput(cl)
                        .className("com.MyTest")
                        .interfaces(MyInterface.class),
                creator -> {
                    MethodCreator method = creator.getMethodCreator("transform", String.class, String.class);
                    ResultHandle existingVal = method.load("complete");
                    TryBlock tb = method.tryBlock();
                    tb.addCatch(IllegalStateException.class).load(34);
                    tb.invokeStaticMethod(MethodDescriptor.ofMethod(ExceptionClass.class.getName(), "throwIllegalState", "V"));
                });
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

No branches or pull requests

1 participant