-
Notifications
You must be signed in to change notification settings - Fork 2.3k
add option to change GENERATION_SUFFIX #1280
add option to change GENERATION_SUFFIX #1280
Conversation
|
damn @yDelouis you got me. i only searched for stupid me... i'll update that. |
|
I removed my notes because we don't have to change the Anyway, do you plan to add some tests to be sure that everything work together ? |
|
the comment at https://github.com/excilys/androidannotations/pull/1280/files#diff-29b59400d9e85af5aa52fae67c90103eR637 is still valid i think. this converts should i replace the other tests... yeah. there should be some but i have no idea yet how. |
|
I think we could keep the '_' for methods and fields. A method named |
|
updated the PR to to use the new suffix for |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think there is an issue if the generation suffix has more than 1 character.
|
I think we should use two constants, one which can be changed and another |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same here.
|
@WonderCsabo is right. We should have a subclass suffix which can be changed by the processor options. And another suffix for generated fields and method to prevent conflicts with the super class ones. This could be Then, for inner classes of generated classes ( |
|
@yDelouis i do not think we should remove the suffices from anywhere. The suffix also clearly shows that the class/etc. is generated by us, which is very important if you have a bigger project and/or multiple people are working on it. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We have to validate the suffix here, because the user can pass a string which is not valid in Java identifiers.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@dodgex you can use SourceVersion.isName method to the the validation.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
and what SourceVersion value to use? SourceVersion.RELEASE_6 or SourceVersion.RELEASE_7?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
BTW, isName() is static, isn't it? The enum value does not matter.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So if (!SourceVersion.isName(classSuffix) || classSuffix.contains("."))
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ah. missed that static... well i'll update the PR when i get the time.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
updated
|
About static method, you have to write |
|
Seems reasonable. But, this will break existing client code. :( We should only do the breaking changes if it is really necessary. |
|
About testing: I think the functional test project almost tests this correctly. Maybe we should add some compile time tests to check reading the options and scanning the manifest etc works well. |
|
so i'm going to update the PR:
|
Let's wait with that one, because we did not discuss that problem, i only raised it. The remainder are OK. And plus one thing: you have to validate the configurable suffix and throw an exception if it cannot be a valid Java class suffix. |
|
updated the PR. all |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should also have to be sure the string is not empty (zero-length), because it will result in duplicate class names.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
added a trim() and also checked the length.
Sorry, something went wrong.
All reactions
|
Please rebase this. |
All reactions
Sorry, something went wrong.
|
rebased. |
All reactions
Sorry, something went wrong.
|
You have Checkstyle violations. Moreover, i think the rebase was not really successful, as i removed the duplicate imports earlier, and it seems you re-added them? |
All reactions
Sorry, something went wrong.
|
yeah. on my way to fix that. |
All reactions
Sorry, something went wrong.
|
working on a test. currenlty we have in the current implementation only |
All reactions
Sorry, something went wrong.
|
|
All reactions
Sorry, something went wrong.
|
test added |
All reactions
Sorry, something went wrong.
|
@dodgex i am wondering, should'nt we remove the |
All reactions
Sorry, something went wrong.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I do not think it should use classSuffx, but generationSuffix instead.
Sorry, something went wrong.
All reactions
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why? its an generated class that is accessible for the user. so FragmentBuilderImpl is better than FragmentBuilder_ actually i'd rename the FragmentBuilder api class (to e.g. AbstractFragmentBuilder) and call the generated class FragmentBuilder so this would be CLEAN.
same to other Builder classes.
Sorry, something went wrong.
All reactions
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I do not agree. Generally we use this impl classes when there is an interface for a specific work, and then we provide an implementation for that work. Here, we do not provide implementation for the work, but we generate always the interface actually, too.
Sorry, something went wrong.
All reactions
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ok. then i'll change that.
Sorry, something went wrong.
All reactions
|
@WonderCsabo i'm currently not at home. Will try to update this PR next week. |
All reactions
Sorry, something went wrong.
…_suffix Add option to change generation suffix
|
Thanks for your work on this! Can you update the wiki? |
All reactions
Sorry, something went wrong.
Hi guys, regarding "clearly showing that the class is generated by us" - why not use @generated annotation which was meant exactly for that? http://docs.oracle.com/javaee/5/api/javax/annotation/Generated.html . As far as I understand, it is enough to modify setGeneratedClass-Method inside BaseGeneratedClassHolder adding a line like this
maybe even use a specific holder FQN instead of generic AndroidAnnotationProcessor.class |
All reactions
Sorry, something went wrong.
|
@chpasha that annotation is not available in the Android runtime, and will cause problems if we add it, despite its source only retention. BTW lombok has a |
All reactions
Sorry, something went wrong.
|
I didn't know that, so I just was hacking around and got no errors when running some test android project with this annotation applied. Which problems will it cause since it is discarded by compiler? |
All reactions
Sorry, something went wrong.
|
Okay, it seems In that case, i agree with you @chpasha. |
All reactions
Sorry, something went wrong.
|
great :) |
All reactions
Sorry, something went wrong.
|
@chpasha unfortunately i remembered correctly. |
All reactions
Sorry, something went wrong.
|
I'm not sure I get it :) . This annotation is not included in apk because of it's retention policy. So why should we care about if it is present in android.jar? Like I said, for the sake of experiment I added this annotation to the generation process and it doesn't cause any issues at all. |
All reactions
Sorry, something went wrong.
|
If the annotation is not in the jar, the compilation will fail. This is the case for Eclipse users for instance. |
All reactions
Sorry, something went wrong.
|
I'm not sure I understand what it has to do with eclipse :) . I must be missing something, but the annotation is present in JDK6 and later, so it is available during compilation. But don't get me wrong, I'm just curious, I don't insist on introducing or implementing anything as long as I can maintain my own fork :) P. S. actually it was added in dagger2 square/dagger#265 as well ;) |
All reactions
Sorry, something went wrong.
|
@chpasha it is indeed JDK6, but that is not in the classpath in case when building an Android project in Eclipse. Only the android.jar is on the classpath. |
All reactions
Sorry, something went wrong.
|
Ok, then maybe adding an annotation processing option that disables @generated makes sense? Just for the sake of completeness, since this annotation has not much real value anyway. |
All reactions
Sorry, something went wrong.
|
Yeah, that makes sense, and as i said |
All reactions
Sorry, something went wrong.
Reviewers
No reviewsAssignees
No one assignedLabels
Projects
Milestone
4.0Development
Successfully merging this pull request may close these issues.
see #1209
this allows to set the
generationSuffixvia options. at the moment the same valule is used for all generated stuff (classes, fields, methods) where it before was_. But for a first look i already opened the PR.