-
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
Migrate from lombok API to Psi APIs #227
Migrate from lombok API to Psi APIs #227
Conversation
I'm getting an error when I run Could not load custom rule jar file ~/.android/lint/lint.jar
java.lang.NoClassDefFoundError: com/android/tools/lint/detector/api/Detector$JavaPsiScanner
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClass(ClassLoader.java:763)
at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:142)
at java.net.URLClassLoader.defineClass(URLClassLoader.java:467)
at java.net.URLClassLoader.access$100(URLClassLoader.java:73)
at java.net.URLClassLoader$1.run(URLClassLoader.java:368)
at java.net.URLClassLoader$1.run(URLClassLoader.java:362)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:361)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
at permissions.dispatcher.PermissionsDispatcherIssueRegistry.getIssues(PermissionsDispatcherIssueRegistry.java:13)
at com.android.tools.lint.client.api.JarFileIssueRegistry.<init>(JarFileIssueRegistry.java:104)
at com.android.tools.lint.client.api.JarFileIssueRegistry.get(JarFileIssueRegistry.java:80)
at com.android.tools.lint.client.api.LintDriver.registerCustomDetectors(LintDriver.java:481)
at com.android.tools.lint.client.api.LintDriver.analyze(LintDriver.java:415)
at com.android.tools.lint.client.api.LintDriver.analyze(LintDriver.java:377)
at com.android.tools.lint.LintCliClient.run(LintCliClient.java:131)
at com.android.tools.lint.Main.run(Main.java:674)
at com.android.tools.lint.Main.main(Main.java:118)
Caused by: java.lang.ClassNotFoundException: com.android.tools.lint.detector.api.Detector$JavaPsiScanner
at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
... 20 more |
a6bd02f
to
3b620d8
Compare
@eyedol Thx! Let me take a look. |
Is this still a WIP? I dunno the reason but seems ci had passed. |
return Collections.<Class<? extends PsiElement>>singletonList(PsiClass.class); | ||
} | ||
|
||
public CallNeedsPermissionDetector() { |
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.
Is this constructor needed?
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.
Yeah. It's being used by its corresponding test class. Plus the documentation on writing a lint-check recommends adding 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.
Noted.
@hotchemi Yes still a WIP. I'm yet to migrate |
I'm not sure the new api works well or not. But when I used |
@eyedol Thx. Can you continue to convert |
Got it, Thx! |
|
||
static List<String> generatedClassNames = new ArrayList<String>(); | ||
|
||
static List<String> METHODS = Collections.emptyList(); |
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.
private static final
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.
Well, it's a little bit not intuitive to add something to final list for me, so how about make this variable being just static and rename like normal variable?
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.
if you omit the getApplicableMethodNames()
method, then you don't need this at all
private static class AnnotationChecker extends ForwardingAstVisitor { | ||
@Override | ||
public List<String> getApplicableMethodNames() { | ||
return METHODS; |
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.
if you never plan to add explicit method names here, it's safe to omit this method
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.
Good to know.
|
||
private Set<PsiAnnotation> needsPermissionAnnotations; | ||
|
||
private Set<PsiAnnotation> onShowRationaleAnnotations; |
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.
final both
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.
Fixed
baz.append("public class Baz {\n"); | ||
baz.append("public void fooBar() {\n"); | ||
baz.append("}\n"); | ||
baz.append("}"); |
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's no need to use a StringBuilder here. Just concatenate strings directly
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.
It was a bit messy concatenating them together using +
because of the code formatter.
// Needed for lint-tests and testutils 25.2.0 packages | ||
maven { | ||
url 'https://oss.sonatype.org/content/repositories/releases/' | ||
} |
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.
use mavenCentral()
instead
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.
Noted.
if (classes.length > 0 && classes[0].getName() != null) { | ||
String qualifiedName = classes[0].getName(); | ||
if (qualifiedName.contains("PermissionsDispatcher") || qualifiedName | ||
.contains("PermissionsDispatcher")) { |
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.
you got the exact same check twice in this if statement
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.
forgot to remove this duplicated check?
@@ -24,3 +24,8 @@ jar { | |||
attributes("Lint-Registry": "permissions.dispatcher.PermissionsDispatcherIssueRegistry") | |||
} | |||
} | |||
|
|||
// Enable test build status on stdout | |||
tasks.matching { it instanceof Test }.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.
Is this needed?
|
||
static List<String> generatedClassNames = new ArrayList<String>(); | ||
|
||
static List<String> METHODS = Collections.emptyList(); |
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.
Well, it's a little bit not intuitive to add something to final list for me, so how about make this variable being just static and rename like normal variable?
return Collections.<Class<? extends PsiElement>>singletonList(PsiClass.class); | ||
} | ||
|
||
public CallNeedsPermissionDetector() { |
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.
Noted.
3b620d8
to
df04784
Compare
Ported the last detector class. I'll appreciate a review @shiraji @hotchemi @felipecsl |
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.
Thx for your great work!
@@ -14,5 +14,7 @@ buildscript { | |||
allprojects { | |||
repositories { | |||
jcenter() | |||
// Needed for lint-tests and testutils 25.2.0 packages |
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.
This line is not needed:D
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 agree :-D
@@ -16,6 +16,10 @@ android { | |||
targetCompatibility JavaVersion.VERSION_1_6 | |||
} | |||
|
|||
lintOptions { | |||
abortOnError false |
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 this line is needed?
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.
yeah this should definitely be removed :)
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.
@hotchemi It was complaining earlier from a broken build. I had to set it as a workaround. It slid through by mistake. Removed.
@Override | ||
protected List<Issue> getIssues() { | ||
return ImmutableList.of(CallOnRequestPermissionsResultDetector.ISSUE); | ||
|
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.
Please remove this line.
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.
It's an abstract method from LintDetectorTest
that needs to be implemented.
if (hasRuntimePermissionAnnotation && !hasOnRequestPermissionResultCall) { | ||
context.report(ISSUE, context.getLocation(classDeclaration), "Generated onRequestPermissionsResult method not called"); | ||
private static boolean checkMethodCall(PsiMethod method, PsiClass psiClass) { | ||
// FIXME: I'm sure there is a better way of checking if the on onRequestPermissionsResult |
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.
Any idea for this?
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's a bunch of comments that haven't been addressed yet, but making progress. Good work 👍
@@ -16,6 +16,10 @@ android { | |||
targetCompatibility JavaVersion.VERSION_1_6 | |||
} | |||
|
|||
lintOptions { | |||
abortOnError false |
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.
yeah this should definitely be removed :)
private final JavaContext context; | ||
|
||
private Set<String> matchingAnnotationTypeNames; |
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 know you didnt change this line, but while you're at it, make it final
df04784
to
7fdcb6f
Compare
Thanks guys. I have fixed the comments. |
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.
Still some stuff missing
private static class AnnotationChecker extends ForwardingAstVisitor { | ||
@Override | ||
public List<String> getApplicableMethodNames() { | ||
return methods; |
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.
this still can be omitted
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.
If I remove test breaks.
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 never mind then
if (classes.length > 0 && classes[0].getName() != null) { | ||
String qualifiedName = classes[0].getName(); | ||
if (qualifiedName.contains("PermissionsDispatcher") || qualifiedName | ||
.contains("PermissionsDispatcher")) { |
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.
forgot to remove this duplicated check?
8f58687
to
1960b69
Compare
- Bump lint library version - Migrate `CallNeedsPermissionDector` to the new Psi API - Migrate `NoCorrespondingNeedsPermissionDector` to the new Psi API - Add maven repository for needed depenencies for test compiles - Add test for the migrations - Show test status on the console. Useful on CI - Remove @VisibleOnTesting annotation detector default constructors. - Hand create mock classes in the test class instead of loading them from a separate package - Migrate `CallOnRequestPermissionsResultDetector` to the new Psi API - Upgrade android gradle plugin - Pull dependencies from `mavencentral`
1960b69
to
96df703
Compare
@eyedol Thx!!! Can I merge? |
what |
I think it hasn't updated it because there were no changes. LGTM! Thanks for your contribution! |
@shiraji Well, actually we have shameful dependency relationship between each modules so that we have workaround...will be fixed on #27. |
@eyedol Really appreciate for your awesome work!!!!! |
Awesome, thank you very much guys!! |
This fixes #226
CallNeedsPermissionDector
to use the new Psi APIs.NoCorrespondingNeedsPermissionDector
to the new Psi APIs.CallOnRequestPermissionsResultDetector
to the new Psi APIs.CallNeedsPermissionDector
migration.NoCorrespondingNeedsPermissionDector
migration.CallOnRequestPermissionsResultDetector
migration.@hotchemi for a review before I cause enough mess :-)