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

Conversation

@jiongxuan
Copy link
Contributor

Implement #943 issue.

Please review my code. Thx!

@jiongxuan
Copy link
Contributor Author

I should only beautify my own code. Revert other beautify code.
Sorry about that!

The logic be Ok, not need to modify.

@WonderCsabo
Copy link
Member

Please rebase this branch as to meld the last two commits into the first.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unused variable.

@WonderCsabo
Copy link
Member

Please do not reformat whole classes. We are using tabs for indenting etc. You can use our Eclipse formatter profile, if you save in Eclipse, it automatically formats the code with the proper settings.

@WonderCsabo
Copy link
Member

BTW i just realized if the client uses daos which uses different helpers, OpenHelperManager will throw an IllegalStateException. I do not think we can validate this, but we should warn users in JavaDoc and wiki.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it possible that the databaseHelper is null at this point?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oftentimes, not.

But I think this is a good habit that can help us to write more strong code.
I'll change it

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is not a question of "habit". If the reference cannot be null, it is
absolutely unnecessary to use a null check. If the reference can be null,
you must add a null check. Actually you even get warnings if you use
@Nullable/@NotNull annotations and a static analysis tool which
inspects them.

@WonderCsabo
Copy link
Member

And a small note about commit messages: please carefully write them, check grammar, typos etc. The commit messages should follow the standard git format (we refer to this in the contributing code page.

@jiongxuan jiongxuan force-pushed the 943_release_openhelpermanager branch from 0f3b459 to 9d8e982 Compare November 17, 2014 06:08
@jiongxuan
Copy link
Contributor Author

Thanks for your advice!

I rebased some commit and push to AA. That's my first step.
Next, I'll based on your advices and rewrites new codes.

@jiongxuan
Copy link
Contributor Author

From @WonderCsabo :
BTW i just realized if the client uses daos which uses different helpers, OpenHelperManager will throw an IllegalStateException. I do not think we can validate this, but we should warn users in JavaDoc and wiki.

I'm trying to learn English well. But, you know, in such a formal occasion, I still hope you help me write some text to warn users in JavaDoc and wiki.

Thx!

@jiongxuan jiongxuan force-pushed the 943_release_openhelpermanager branch from f16c550 to 50868a8 Compare November 17, 2014 08:37
@jiongxuan
Copy link
Contributor Author

From @WonderCsabo :
This is very ugly, and we do not need it. You can modify OrmLiteDaoHandler to use HasReceiverRegistration instead of EComponentHolder, just extend BaseAnnotationHandler<HasReceiverRegistration>. But in that case , you should rename HasReceiverRegistration to use a more general description.

I have been considering this issue long time before start writing the code.

But:
You should rename HasReceiverRegistration to use a more general description.

I'm not rashly to modify the overall framework.
Can you give me some advise to design?

@WonderCsabo
Copy link
Member

Maye you can create a new interface HasLifecycleMethods which extends GeneratedClassHolder and move the getOnXXX methods there. Then let HasReceiverRegistration extend HasLifecycleMethods. Then you can use HasLifecycleMethods in OrmLiteDaoHandler.

@WonderCsabo
Copy link
Member

Please rebase this whole branch into two commits: a code and a test commit.

@WonderCsabo
Copy link
Member

I'm trying to learn English well. But, you know, in such a formal occasion, I still hope you help me write some text to warn users in JavaDoc and wiki.

No problem, that's actually another issue, i'll open a new ticket for it.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Since we do not actually use this test, please remove any changes from here.

@jiongxuan jiongxuan force-pushed the 943_release_openhelpermanager branch from 50868a8 to cd34694 Compare November 17, 2014 11:32
@jiongxuan
Copy link
Contributor Author

Push again.

Maye you can create a new interface HasLifecycleMethods which extends GeneratedClassHolder and move the getOnXXX methods there. Then let HasReceiverRegistration extend HasLifecycleMethods. Then you can use HasLifecycleMethods in OrmLiteDaoHandler.

I'll solute this issue tomorrow :)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove all changes from this class, if you do not add anything interesting.

@jiongxuan
Copy link
Contributor Author

Rebase has some error on it. I'll check again.

Sorry about that.

@jiongxuan jiongxuan force-pushed the 943_release_openhelpermanager branch from cd34694 to 3c197d3 Compare November 17, 2014 11:51
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use staticField for static fields.

@jiongxuan jiongxuan force-pushed the 943_release_openhelpermanager branch from 3c197d3 to dcee2d3 Compare November 17, 2014 12:50
@jiongxuan jiongxuan force-pushed the 943_release_openhelpermanager branch 2 times, most recently from 2e009cc to d5012ee Compare November 17, 2014 14:45
@jiongxuan
Copy link
Contributor Author

I'm terribly sorry. I have no idea to avoid the "instanceof" condition.

Because the OrmliteDaoHandler can handle two scenarios: with an onDestory method or not.
We cannot create getOnDestroy into HasLifecycleMethods, thus will be ignore annother scenario.

Can u give me some advices? :)

@WonderCsabo
Copy link
Member

Yep, this is a tricky one. You can create the similar solution to the receiver registration. Move the release helper method invocation to a separate class. Then in EActivityHolder, EFragmentHolder and EServiceHolder, override the setDatabaseHelperRef, which wich will call super and also delegates to the newly created class which will do the releaseHelper invocation.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you wanted to write this instanceof HasLifecycleMethods, right ?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, the logic is OK. But we should refactor this.

@jiongxuan jiongxuan force-pushed the 943_release_openhelpermanager branch from d5012ee to 701606e Compare November 18, 2014 01:55
@jiongxuan
Copy link
Contributor Author

Yep, this is a tricky one. You can create the similar solution to the receiver registration. Move the release helper method invocation to a separate class. Then in EActivityHolder, EFragmentHolder and EServiceHolder, override the setDatabaseHelperRef, which wich will call super and also delegates to the newly created class which will do the releaseHelper invocation.

Sounds exciting!
I see your point. Please review my code.

I'm sorry to trouble you a lot.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You should not do anything here, since it is already done in EServiceHolder. This way you will add two releaseHelper invocations.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep.

I'll create new test classes for Service and Fragment to ensure there is no problem.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can leave that as is, the current test is enough for now.
On Nov 18, 2014 9:21 AM, "Jiongxuan Zhang" notifications@github.com wrote:

In
AndroidAnnotations/androidannotations/src/main/java/org/androidannotations/holder/EIntentServiceHolder.java:

@@ -76,4 +79,12 @@ private void createOnHandleIntent() {
JInvocation getActionInvocation = JExpr.invoke(onHandleIntentIntent, "getAction");
onHandleIntentIntentAction = onHandleIntentBody.decl(classes().STRING, "action", getActionInvocation);
}
+

  • @OverRide
  • protected JFieldVar setDatabaseHelperRef(TypeMirror databaseHelperTypeMirror) {

Yep.

I'll create new test classes for Service and Fragment to ensure there is
no problem.

Reply to this email directly or view it on GitHub
https://github.com/excilys/androidannotations/pull/1245/files#r20491186.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm almost finished writing it :)

Okay, I'm fixed it.

@jiongxuan jiongxuan force-pushed the 943_release_openhelpermanager branch from 701606e to 1d0f891 Compare November 18, 2014 08:36
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I still think it is not really nice if we use HasReceiverRegistration, because this code has nothing to do with receivers. I suggest to reintroduce the interface that i mentioned, and use it there instead of HasReceiverRegistration.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

HasLifecycleMethods?

Are you sure that the interface should have onDestroyBeforeSuperBlock method?
If not, how can I insert OpenHelperManager.release in the onDestroy method?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do you think that HasLifecycleMethods should not have onDestroyBeforeSuperBlock? Why?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because the OrmliteDaoHandler can handle two scenarios: with an onDestory method or not.
We cannot create getOnDestroy into HasLifecycleMethods, thus will be ignore annother scenario.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@EBean and @EActivity can use it well. But @EBean does not have a onDestroy method

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You mean we should only add onDestroyXXX in the HasLifecycleMethods?
So that it conforms to the ISP? :)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't get me wrong, I just confirm that I understand

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK, it would be seen as redundant to you, because basically everyting which is a HasLifecycleMethods is HasReceiverRegistration, too. But i still think this is better design. This is what i propose:

create a new HasLifecycleMethods interface:

public interface HasLifecycleMethods extends GeneratedClassHolder {
    JBlock getOnCreateAfterSuperBlock();
    JBlock getOnDestroyBeforeSuperBlock();

    JBlock getOnStartAfterSuperBlock();
    JBlock getOnStopBeforeSuperBlock();

    JBlock getOnResumeAfterSuperBlock();
    JBlock getOnPauseBeforeSuperBlock();

    JBlock getOnAttachAfterSuperBlock();
    JBlock getOnDetachBeforeSuperBlock();
}

Let HasReceiverRegistration extend HasLifecycleMethods, and remove redundant method declarations:

public interface HasReceiverRegistration extends HasLifecycleMethods {
    JExpression getContextRef();

    JFieldVar getIntentFilterField(String[] actions, String[] dataSchemas);
}

Use HasLifecycleMethods in OrmLiteHelper:

public static void injectReleaseInDestroy(JFieldVar databaseHelperRef, HasLifecycleMethods lifecycleMethodsHolder, ProcessHolder.Classes classes) { ... }

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep. You're right!

In fact, the most perfect solution i think is split into four interface: HasLifecycleMethods / HasStartAndStopMethods / HasAttachableMethods / HasReceiverRegistration.
There is no connection between them.

EActivityHolder and EFragmentHolder need implement: HasLifecycleMethods,HasStartAndStopMethods, HasAttachableMethods and HasReceiverRegistration
EServiceHolder need implement: HasLifecycleMethods and HasReceiverRegistration

In ReceiverHandler.registerAndUnregisterReceiver method, we can add two method with the same name.
These methods are respectively corresponding to these Interface.

However, this is a huge change. I think to do as you say.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, we could split it even further, but i think my proposal will suffice
for now.

Remove redundant method declarations in HasReceiverRegistration class.
@WonderCsabo
Copy link
Member

@yDelouis I think this code is finally OK. I would merge.

@dodgex
Copy link
Member

dodgex commented Nov 19, 2014

LGTM. Nice work. :)

@jiongxuan
Copy link
Contributor Author

Thanks. :)

WonderCsabo added a commit that referenced this pull request Nov 20, 2014
@WonderCsabo WonderCsabo merged commit 1dc834d into androidannotations:develop Nov 20, 2014
@WonderCsabo
Copy link
Member

Thanks!

@WonderCsabo WonderCsabo added this to the 3.3 milestone Nov 20, 2014
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants