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

Imports in generated code disappear when a custom class is bound more than once #221

Closed
gstepniewski opened this Issue Jul 7, 2015 · 10 comments

Comments

Projects
None yet
2 participants
@gstepniewski

gstepniewski commented Jul 7, 2015

Consider the following case:

You have a custom View and a Robobinding Attribute which operates on a custom class (say a button which has two images and the class will hold two different id's). Everything works properly when you have only one such property in your ViewModel, but as soon as you add another compilation fails with "cannot find symbol CustomClass" in the generated code.

A workaround for this is to have the binding work on a generic wrapping the custom class (List<>, Optional<>) etc, but it's not ideal as you either need to always use generics for custom attributes or be ready to refactor as soon as you need to use another custom View in your layout.

@weicheng113

This comment has been minimized.

Member

weicheng113 commented Jul 7, 2015

Hi Greg,

Thanks for your issue report. I am not quite understand the problem. Could you please describe the issue with some pseudo-code for example?

Thanks,
Cheng Wei

@gstepniewski

This comment has been minimized.

gstepniewski commented Jul 7, 2015

Sure!

Say you have a custom PropertyViewAttribute that looks like this:

`
public class CustomViewAttribute implements PropertyViewAttribute<CustomView, CustomClass> {

@Override
public void updateView(CustomView view, CustomClass newValue) {
    view.setProperty1(newValue.property1);
    view.setPropertu2(newValue.property2);
}

public static class CustomClass {
    public String property1;
    public String property2;
}

}
`

If your layout has more than one CustomView that you want to bind, your ViewModel will need two methods:

`
public CustomClass getViewProperty1() {
return customClass1;
}

public CustomClass getViewProperty2() {
return customClass2;
}
`

Unfortunately, the compilation will fail with an error saying that "CustomClass" could not be found.
The problem only appears when the custom class is used more than once, which suggests a problem with the way imports are created in generated code.

@weicheng113

This comment has been minimized.

Member

weicheng113 commented Jul 7, 2015

Thanks a lot, Greg. I will add a unit test and try to recreate the issue.

weicheng113 added a commit to weicheng113/CustomClassMultiBindings that referenced this issue Jul 26, 2015

@weicheng113

This comment has been minimized.

Member

weicheng113 commented Jul 26, 2015

@gstepniewski , I created an example project to demo the issue - https://github.com/weicheng113/CustomClassMultiBindings. Not sure if it was fixed somehow, but with the latest RoboBinding snapshot, i could not recreate the problem. Could you please check if the example project follows your instructions properly? And when you try the example project, please issue 'gradlew build --refresh-dependencies' under command line to force update to the latest RoboBinding snapshot.

Thanks for the issue report. Highly appreciated.

Thanks, Cheng

@gstepniewski

This comment has been minimized.

gstepniewski commented Jul 27, 2015

I've been able to reproduce the problem by making a few changes in the project - I created separate packages for the classes and moved them around to replicate my project's structure. I'm now getting the same error on both projects:

(...)/MainPresentationModel$$PM.java:67: error: cannot find symbol AbstractGetSet<?> getSet = new AbstractGetSet<CustomClass>(descriptor) { ^ symbol: class CustomClass location: class MainPresentationModel$$PM

weicheng113 added a commit that referenced this issue Jul 28, 2015

@weicheng113

This comment has been minimized.

Member

weicheng113 commented Jul 28, 2015

@gstepniewski , The issue is fixed and tested. It is a codemodel bug. It is a old library by sun, but was not maintained for some time. I switched to use a version that is still maintained, https://github.com/phax/jcodemodel, which fixed the problem. You can issue the following in command line - gradlew build --refresh-dependencies in Windows or ./gradlew build --refresh-dependencies in Linux or Mac to force update to the latest RoboBinding snapshot when required.

Thanks for the good issue report. Please have a try in your end and close the issue if it also works in your side.

Thanks, Cheng

@weicheng113 weicheng113 reopened this Jul 28, 2015

@gstepniewski

This comment has been minimized.

gstepniewski commented Jul 29, 2015

Will I need to upgrade to a newer version or do I keep using 0.8.9?

@weicheng113

This comment has been minimized.

Member

weicheng113 commented Jul 29, 2015

@gstepniewski , Please have a try with CustomClassMultiBindings project in your local, there is no change in the source code. Just force gradle to pull the latest codegen jar. It should be working. Then i recommend you to upgrade your RoboBinding dependency to latest snapshot, as there won't be any new features added to this release, which i plan to do in two weeks' time(mainly to update the docs).

When you try to upgrade, please have a look the issue #224. Should be quite easy.

Cheers, Cheng

@gstepniewski

This comment has been minimized.

gstepniewski commented Jul 29, 2015

The project CustomClassMultiBindings builds properly now.
Closing issue.

My other project uses dependencies:
compile 'org.robobinding:robobinding:0.8.9' apt 'org.robobinding:codegen:0.8.9'
What should I update them to in order to get the fix?

@weicheng113

This comment has been minimized.

Member

weicheng113 commented Jul 29, 2015

@gstepniewski, please upgrade both robobinding and codegen to latest snapshot like CustomClassMultiBindings project.

@weicheng113 weicheng113 added this to the v0.8.10 milestone Aug 1, 2015

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