Skip to content
This repository was archived by the owner on Feb 26, 2023. It is now read-only.
This repository was archived by the owner on Feb 26, 2023. It is now read-only.

Bug in generated code with @RootContext #2203

@smaugho

Description

@smaugho

Hi, when using a method to inject the Context, and a class which is different than Context is used, the generated code is not correct.

I saw this issue while testing #2202 , both annotations have the same bug then. (Note I tested with the normal "develop" branch, to be sure this was not related to the changes on #2202).

Annotated code:

@EBean
public class MainViewModel {

    @RootContext
    void someMethod(Activity anything) {
        //Some code
    }

}

Expected generated code:

    private void init_() {
        if (context_ instanceof Activity) {
            Activity anything = ((Activity) context_);
            someMethod2(anything);
        } else {
            Log.w("MainViewModel_", (("Due to Context class "+ context_.getClass().getSimpleName())+", the @RootContext Activity won't be populated"));
        }
    }

Actual generated code:

    private void init_() {
        {
            Activity anything = null;
            someMethod2(anything);
        }
        if (context_ instanceof Activity) {
            anything = ((Activity) context_);
        } else {
            Log.w("MainViewModel_", (("Due to Context class "+ context_.getClass().getSimpleName())+", the @RootContext Activity won't be populated"));
        }
    }

The code doesn't compile in general since the field in the "if (context ..." block anything doens't exist

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions