-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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
Can't use with AndroidAnnotations #14
Comments
Rather than checking the class name for "Activity" or "Fragment", the processor should check if the class annotated with In an annotation processor I recently wrote, I also only allow for some annotated elements to be of a certain type. Applying this to PermissionsDispatcher could look something like this: // PermissionsProcessor.java:
public synchronized void init(ProcessingEnvironment env) {
// ...
this.types = env.getTypeUtils();
this.elements = env.getElementUtils();
}
// RuntimePermissionsAnnotatedElement.java:
class RuntimePermissionsAnnotatedElement {
//...
private final TypeMirror type;
RuntimePermissionsAnnotatedElement(TypeElement element) {
// ...
type = element.asType();
}
public TypeMirror asType() {
return type;
}
}
// Now, to check if an annotated element is an Activity:
// "types" are the TypeUtils retrieved from the ProcessingEnvironment at init time
// "elements" are the ElementUtils retrieved from the ProcessingEnvironment at init time
TypeMirror activityType = types.getDeclaredType(elements.getTypeElement("android.app.Activity"));
RuntimePermissionsAnnotatedElement element = // ...
if (types.isSubType(element.asType(), activityType)) {
// This is an activity sub-class.
} else if (//Same for Fragment) {
} else if (// Same for Support Fragment) {
} else {
// Invalid element
throw new WrongClassException(...);
} |
Oh it's really nice idea! |
Any update on this? I also ran into the |
@Fleker Do u use AndroidAnnotations? |
I spent some more time and figured out my problem. I think it had to do with trying to annotate a private method and it broke on compilation. Now my issue has been resolved. |
OK but the error message is wired... |
I'm gonna delete validation. If user don't annotate proper class, it causes compile error so it doesn't matter. |
@hotchemi sorry, i cannot say it is a good idea. Generating a non-compilable class is not user friendly, and should be always avoided. Moreover, it will not be clear to the user that the processor is buggy, or she/he used it in a wrong way. Why don't you just apply the easy fix which was already proposed? |
@WonderCsabo Thanks, I changed my mind! |
…rror comparison checks * rather than checking if an annotated class ends in "Activity" or "Fragment", its type is compared to `android.app.Activity` and `android.support.v4.app.Fragment` in order to find their ClassType * this fixes permissions-dispatcher#14 (Can't use with AndroidAnnotations)
I realized this implementation can't catch nested super class problem. |
@hotchemi I think you are wrong. |
@WonderCsabo Oh really? I tried to add this test data but it doesn't go well...anything wrong? |
I think the test data is OK. However |
@WonderCsabo @aurae |
In your test data you extend the outer class with the inner class. Am I
seeing this right?
|
I wrote like below. |
You deleted the commit unfortunately, but i think your test case looked like this: public class MyChildClass extends MyChildClass.SuperClass {
static class SuperClass extends Object {}
} This cannot compile, because of cyclic inheritance. So that is why |
@WonderCsabo Oh sorry that was my mistake... |
Hi, its me, again. Tried to use this lib one more time and got this message:
I have my fragment generated and dispatcher is generated too. But there is no code for calling the dispatcher inside the generated fragment. I can't find much details on that in log. |
Could u paste the code of fragment? I guess you don't define @NeedsPermission. |
As stated before I have my TestFragment_ generated as well as TestFragmentPermissionsDispatcher but in TestFragment_ there are no references to Dispatcher. I have compilation error https://gist.github.com/BukT0p/572e431288b698f25de0 |
@BukT0p Umm it's make sense because u don't use original fragment. Could u send pull request? |
Because they use _ ends with classes actually.
The text was updated successfully, but these errors were encountered: