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.

@Bean doesn't work with parameterized class #103

Description

@a-thomas

Annotate a parameterized class result in a wrong generated code:

The following is generated:

import com.company.dao.helper.DaoHelper<com.company.model.Client, java.lang.Long>_;
[...]
((Long>_) daoHelper).afterSetContentView_();
[...]

Activity

  1. pyricau commented on Mar 26, 2012

    @pyricau
    Contributor

    It's more than just this warning. The generated subclass should be parameterized too, and getInstance should return a covariant result.

  2. added a commit that references this issue on Apr 13, 2013
    4b23872
  3. WonderCsabo commented on Jan 10, 2014

    @WonderCsabo
    Member

    This still does not work unfortunately.

    The generated import:

    import com.example.Pojo<java.lang.String>_;

    The generated injection:

    a = String>_.getInstance_(this);
  4. Artyomcool commented on Jan 10, 2014

    @Artyomcool

    This is exactly I'm talking about in #865 (and fixed by #867 PR)

  5. WonderCsabo commented on Jan 10, 2014

    @WonderCsabo
    Member

    @DayS, can you check @Artyomcool's PR someday?

  6. DayS commented on Jan 10, 2014

    @DayS
    Contributor

    I'm on it right now. I started 3.0.1 release.. But I'll revert it. This should be fixed before

  7. WonderCsabo commented on Jan 13, 2014

    @WonderCsabo
    Member

    The problem described in my comment is still here. :S

  8. Artyomcool commented on Jan 13, 2014

    @Artyomcool

    Sorry for asking, but are you sure?
    There is exactly such test case and it's ok.
    Could you double check?

  9. Artyomcool commented on Jan 13, 2014

    @Artyomcool

    If it is, could you provide full source code?

  10. WonderCsabo commented on Jan 13, 2014

    @WonderCsabo
    Member

    Of course.

    @EBean
    public class GenericBean<T> {
    
    }
    @EActivity
    public class MainActivity extends Activity {
    
        @Bean
        GenericBean<String> bean;
    }

    Generated code:

    private void init_(Bundle savedInstanceState) {
        bean = GenericBean<T>_.getInstance_(this);
    }

    Project is available here.

  11. DayS commented on Jan 13, 2014

    @DayS
    Contributor

    Yep, just confirmed.. Fu** >_<

    By the way, generated getInstance method should look like this :

    public static <T> GenericBean_<T> getInstance_(Context context) {
        return new GenericBean_<T>(context);
    }

    instead of

    public static GenericBean_ getInstance_(Context context) {
        return new GenericBean_(context);
    }

    It's optional but it may be cleaner :) (Unless this is too much work and complexity in code)

  12. WonderCsabo commented on Jan 13, 2014

    @WonderCsabo
    Member

    I just read your comments about Eclipse internal builder, so i checked this case with maven - it builds successfully. @Artyomcool was right, there is a compile-time test for this.

  13. Artyomcool commented on Jan 13, 2014

    @Artyomcool

    Not much. I'll do my bests to fix it tomorrow.
    13.01.2014 23:01 ÐÏÌØÚÏ×ÁÔÅÌØ "Damien" notifications@github.com ÎÁÐÉÓÁÌ:

    Yep, just confirmed.. Fu** >_<

    By the way, generated getInstance method should look like this :

    public static GenericBean_ getInstance_(Context context) {
    return new GenericBean_(context);}

    instead of

    public static GenericBean_ getInstance_(Context context) {
    return new GenericBean_(context);}

    It's optional but it may be cleaner :) (Unless this is too much work and
    complexity in code)

    Reply to this email directly or view it on GitHubhttps://github.com//issues/103#issuecomment-32199408
    .

  14. Artyomcool commented on Jan 13, 2014

    @Artyomcool

    Looks like I need to install eclipse :)

  15. WonderCsabo commented on Jan 13, 2014

    @WonderCsabo
    Member

    There is an option in the m2e-apt plugin - which is in the wiki for using AA, but not in the contribution page (why?) - to use the normal APT and not the Eclipse internal JDT APT. To use this option, the POM should be changed to configure correctly the maven-processor-plugin. Unfortunately, i was not able to do so, the problem was that APT did not found the R class. May be you guys can try it out. This could solve all the problems with the Eclipse internal builder, but only for Maven users.

  16. Artyomcool commented on Jan 14, 2014

    @Artyomcool

    @DayS, looks the only way it can be fixed - if eclipse can't give me erasure - parse the class name manually:
    In BeanHandler:

    elementType = holder.processingEnvironment().getTypeUtils().erasure(elementType);
    

    My best gues - eclipse know nothing about elementType (because build is incrimental), so it is presented just as a direct declaration and erasure can't do the job. What do you think? Should I parse it manually?

  17. Artyomcool commented on Jan 14, 2014

    @Artyomcool

    This could solve all the problems with the Eclipse internal builder, but only for Maven users.

    Gradle always uses normal APT (AFAIK), so not only for Maven, but for gradle too.

  18. WonderCsabo commented on Jun 9, 2014

    @WonderCsabo
    Member

    What is the status of this issue? Should this be closed?

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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions