com.android.tools.lint.client.api.JavaEvaluator Java Examples
The following examples show how to use
com.android.tools.lint.client.api.JavaEvaluator.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: InstalledBeforeSuperDetector.java From Folivora with Apache License 2.0 | 5 votes |
@Override public void visitMethod(JavaContext context, UCallExpression call, PsiMethod method) { JavaEvaluator evaluator = context.getEvaluator(); //check Folivora.installViewFactory() call String methodName = method.getName(); if (!methodName.equals(INSTALL_METHOD) || !evaluator.isMemberInClass(method, TYPE_FOLIVORA)) return; //check current class is decent of AppCompatActivity PsiClass legacyCompatActClass = evaluator.findClass(LEGACY_COMPAT_ACTIVITY); PsiClass compatActClass = evaluator.findClass(COMPAT_ACTIVITY); PsiClass c = UastUtils.getContainingClass(call); boolean isAppCompatActivity = false; if (c != null) { isAppCompatActivity = (legacyCompatActClass != null && c.isInheritor(legacyCompatActClass, true/*deep check*/)) || compatActClass != null && c.isInheritor(compatActClass, true/*deep check*/); } if (!isAppCompatActivity) return; //check current method is onCreate @SuppressWarnings("unchecked") UMethod uMethod = UastUtils.getParentOfType(call, true, UMethod.class); if (uMethod == null || !"onCreate".equals(uMethod.getName())) return; SuperOnCreateFinder finder = new SuperOnCreateFinder(call); uMethod.accept(finder); if (!finder.isSuperOnCreateCalled()) { context.report(ISSUE, call, context.getLocation(call), "calling `Folivora.installViewFactory()` before super.onCreate can cause AppCompatViews unavailable"); } }
Example #2
Source File: InternalFolivoraApiDetector.java From Folivora with Apache License 2.0 | 5 votes |
@Override public void visitMethod(@NotNull JavaContext context, @NotNull UCallExpression call, @NotNull PsiMethod method) { JavaEvaluator evaluator = context.getEvaluator(); //check Folivora.applyDrawableToView() call String methodName = method.getName(); if (!methodName.equals(APPLY_METHOD) || !evaluator.isMemberInClass(method, FOLIVORA_CLASS)) return; PsiClass viewClass = evaluator.findClass(VIEW_CLASS); PsiClass currentClass = UastUtils.getContainingClass(call); if(currentClass == null || viewClass == null) return; if (!currentClass.isInheritor(viewClass, true/*deep check*/)) { report(context, call); return; } UMethod uMethod = UastUtils.getParentOfType(call, UMethod.class, false); if(uMethod == null) return; //check it is a view's constructor if (!uMethod.isConstructor()) { report(context, call); return; } MethodSignature signature = uMethod.getSignature(PsiSubstitutor.EMPTY); PsiType[] types = signature.getParameterTypes(); if (types.length != 2) { report(context, call); return; } if (!types[0].equalsToText(CONTEXT_CLASS) || !types[1].equalsToText(ATTRS_CLASS)) { report(context, call); } }
Example #3
Source File: InjectedFieldInJobNotTransientDetector.java From cathode with Apache License 2.0 | 5 votes |
private boolean isInJob(PsiField field) { JavaEvaluator evaluator = context.getEvaluator(); if (evaluator.isMemberInSubClassOf(field, JOBQUEUE_JOB, true)) { return true; } return false; }