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

Add extraFields to a BoundBox #4

Closed
flavienlaurent opened this issue Sep 23, 2013 · 18 comments
Closed

Add extraFields to a BoundBox #4

flavienlaurent opened this issue Sep 23, 2013 · 18 comments

Comments

@flavienlaurent
Copy link
Collaborator

UPDATE ---
The thread has been renamed. On Android, we use stub Android jars to compile an app, and those stubs only contain method signatures (their bodies all send the "Stub !" exception), and no fields. So it is interesting to be able to add fields explicitly to a BoundBox class so that, when a call to the BoundBox setters/getters will be made, it will be resolved at runtime by reflection and the field will be accessed for real.
UPDATE ---

The code

@BoundBox(boundClass=TextView.class)
BoundBoxOfTextView boundBoxOfTextView;

BoundBoxOfTextView class isn't well generated:

  • import statement conflict
import android.text.Editable.Factory;
import android.text.Layout;
import android.text.Spannable.Factory;
  • private fields are missing. For example, TextView contains
private ArrayList<TextWatcher> mListeners;

and there is no method to access to it in BoundBoxOfTextView

@stephanenicolas
Copy link
Owner

Woopss. Looks like a miss ;)

Thank you very much for reporting these bugs. It would be very nice to have
gists reproducing the problem but without using android classes.

I mean having a dependency on Android would be too heavy, even just for
testing.

We could isolate what's going wrong and create small test cases for each
problem. For instance a generics field seems to be a source of problem.

For the import conflict I still don't see clearly what's wrong and even
less what the problem can be.

Stephane
Le 23 sept. 2013 14:19, "Flavien Laurent" [email protected] a
écrit :

The code

@Boundbox(boundClass=TextView.class)
BoundBoxOfTextView boundBoxOfTextView;

BoundBoxOfTextView class isn't well generated:

  • import statement conflict import android.text.Editable.Factory;
    import android.text.Layout; import android.text.Spannable.Factory;
  • private fields are missing. For example, TextView contains private
    ArrayList mListeners; and there is no method to access to
    it in BoundBoxOfTextView


Reply to this email directly or view it on GitHubhttps://github.com//issues/4
.

@flavienlaurent
Copy link
Collaborator Author

You're welcome :)

I don't think it's because of generics.
I wrote a simple test in library-integration-tests: you can take a look on https://gist.github.com/flavienlaurent/6673763

@stephanenicolas
Copy link
Owner

for imports, I found out that the problem comes from javawriter. it compresses types by default and doesn't handle very well conflicting imports.

see square/javapoet#24 (comment)

@stephanenicolas
Copy link
Owner

see issue #2

@flavienlaurent
Copy link
Collaborator Author

Ok for import statements conflict but did you fixed missing private fields issue?

@stephanenicolas
Copy link
Owner

For import statements, I initiated a pull request in java writer. With this fix, everything is going well for TextView.
(apart of the private field issue you mention. Please in the future, try to issue one bug per bug/feature request.)

@stephanenicolas
Copy link
Owner

About the missing field. I think I got the explanation. I could reproduce the "bug" locally. It's indeed not a bug to my mind. What happens is that the android jars that are used for compilation are indeed android jars containing only methods that send the "Stub !" exception. They just provide signatures of all methods of android classes but don't actually contain any field of those classes.

Therefore, due to full android classes being unavailable at runtime, it will not be possible to get their fields. All fields of your own classes are available, as well as their super class, but, whenver you use an android class, you won't have access to anything other than methods.

@flavienlaurent
Copy link
Collaborator Author

I suspected this problem ... It could be interesting to add extra informations in annotation to force specific field to be bound boxed.

Let's imagine

@BoundBox(
    boundClass=TextView.class,
    boundFields={
        @BoundBoxField(fieldClass=ArrayList.class, fieldName="mListeners"),
        @BoundBoxField(fieldClass=TextPaint.class, fieldName="mTextPaint"),
    }
)

What do you think?

@stephanenicolas
Copy link
Owner

ok for extraBoundFields. Do you feel like coding it ?

I am really eager to see java writer released with optional type
compression, before that we can't release anything. This might give us some
time to develop better features.

2013/9/24 Flavien Laurent [email protected]

I suspected this problem ... It could be interesting to add extra
informations in annotation to force specific field to be bound boxed.

Let's imagine

@Boundbox(
boundClass=TextView.class,
boundFields={
@BoundBoxField(fieldClass=ArrayList.class, fieldName="mListeners"),
@BoundBoxField(fieldClass=TextPaint.class, fieldName="mTextPaint"),
}
)

What do you think?


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

Stéphane NICOLAS,
OCTO Technology
Développeur & Consultant Android / Java
..........................................................
50, Avenue des Champs-Elysées
75008 Paris
+33 (0)6.26.32.34.09
www.octo.com - mobilite.octo.com
blog.octo.com - www.usievents.com
...........................................................

@flavienlaurent
Copy link
Collaborator Author

yes, I can focus on this feature.

@stephanenicolas
Copy link
Owner

Wonderful. On my side, I will focus on adding support for inner classes,
and generate a relevant javadoc, and wait for Javawriter's new release and
its integration.

I should get it within 15 days, at most. Except for javawriter, as it will
depend on their side.

S.

2013/9/24 Flavien Laurent [email protected]

yes, I can focus on this feature.


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

Stéphane NICOLAS,
OCTO Technology
Développeur & Consultant Android / Java
..........................................................
50, Avenue des Champs-Elysées
75008 Paris
+33 (0)6.26.32.34.09
www.octo.com - mobilite.octo.com
blog.octo.com - www.usievents.com
...........................................................

@flavienlaurent
Copy link
Collaborator Author

Ok.

Some advices on how to see logs?
Can you provide your codestyle?

@stephanenicolas
Copy link
Owner

mvn clean install will show logs.
I think they is a tab in eclipse's console output that displays errors and
logs as well.

I don't debug, I just trace. If you find a better way, I would use it.

S.

2013/9/24 Flavien Laurent [email protected]

Ok. Some advices on how to debug the annotation processor and how to see
logs?


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

Stéphane NICOLAS,
OCTO Technology
Développeur & Consultant Android / Java
..........................................................
50, Avenue des Champs-Elysées
75008 Paris
+33 (0)6.26.32.34.09
www.octo.com - mobilite.octo.com
blog.octo.com - www.usievents.com
...........................................................

@flavienlaurent
Copy link
Collaborator Author

I just finished to code a basic implementation of this feature. Do you known how to test this feature? I wrote test in boundbox-library and boundbox-android-sample-tests but I have no idea how to test it in boundbox-library-integration-tests.

Actually, I've this test

package org.boundbox.sample;

import org.boundbox.BoundBox;
import org.boundbox.BoundBoxField;
import org.junit.Before;
import org.junit.Test;

public class ExtraFieldTest {

    private FieldTestClassB fieldTestClassB;
    @BoundBox(
            boundClass = FieldTestClassB.class,
            extraBoundFields = {
                @BoundBoxField(
                        fieldName =  "fakeField1",
                        fieldClass = String.class
                )
            }
    )
    private BoundBoxOfFieldTestClassB boundBoxOfB;

    @Before
    public void setup() {
        fieldTestClassB = new FieldTestClassB();
        boundBoxOfB = new BoundBoxOfFieldTestClassB(fieldTestClassB);
    }

    @Test
    public void test_read_access_to_field() {
        boundBoxOfB.boundBox_getFakeField1(); // <-- throws NoSuchFieldException obviously
    }
}

@stephanenicolas
Copy link
Owner

In a unit test for the writer, you would check that the getters and setters
are present in the boundboxofX class (via reflection).
In a unit test for the processor, you would check that the FieldInfo
contains correct data for the extra field.

In an integration test you would test that the read access fails on a bound
class that doesn't contain the field.

Can you change extraBoundFields --> extraFields
My fault.

Nice ! Any pull request ready ?

Stéphane

2013/9/24 Flavien Laurent [email protected]

I just finished to code a basic implementation of this feature. Do you
known how to test this feature? I wrote test in boundbox-library,
boundbox-android-sample-tests and boundbox-android-sample but I have no
idea how to test it in boundbox-library-integration-tests.

Actually, I've this test

package org.boundbox.sample;

import org.boundbox.BoundBox;
import org.boundbox.BoundBoxField;
import org.junit.Before;
import org.junit.Test;

public class ExtraFieldTest {

private FieldTestClassB fieldTestClassB;
@BoundBox(
        boundClass = FieldTestClassB.class,
        extraBoundFields = {
            @BoundBoxField(
                    fieldName =  "fakeField1",
                    fieldClass = String.class
            )
        }
)
private BoundBoxOfFieldTestClassB boundBoxOfB;

@Before
public void setup() {
    fieldTestClassB = new FieldTestClassB();
    boundBoxOfB = new BoundBoxOfFieldTestClassB(fieldTestClassB);
}

@Test
public void test_read_access_to_field() {
    boundBoxOfB.boundBox_getFakeField1(); // <-- throws NoSuchFieldException obviously
}

}


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

Stéphane NICOLAS,
OCTO Technology
Développeur & Consultant Android / Java
..........................................................
50, Avenue des Champs-Elysées
75008 Paris
+33 (0)6.26.32.34.09
www.octo.com - mobilite.octo.com
blog.octo.com - www.usievents.com
...........................................................

@stephanenicolas
Copy link
Owner

Please, when done, document the feature here : https://github.com/stephanenicolas/boundbox/wiki/Adding-extra-fields-to-a-boundbox

This page is already referenced/linked from Wiki's main page (section usage).

@flavienlaurent
Copy link
Collaborator Author

Request pulled. Don't hesitate if you have a comment on something!
I wrote the documentation as well.

@stephanenicolas
Copy link
Owner

#7

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