@Nullable private MethodInfo findMethod(@NonNull ResolvedMethod method) { ClassInfo c = findClass(method.getContainingClass()); if (c == null) { return null; return null; Collection<MethodInfo> methods = c.methods.get(method.getName()); if (methods == null) { return null; boolean constructor = method.isConstructor(); for (MethodInfo m : methods) { if (constructor != m.constructor) { int index = 0; boolean matches = true; for (int i = 0, n = method.getArgumentCount(); i < n; i++) { String parameterType = method.getArgumentType(i).getSignature(); int length = parameterType.indexOf('<'); if (length == -1) {
ResolvedClass containingClass = method.getContainingClass(); if ((OBTAIN.equals(name) || OBTAIN_NO_HISTORY.equals(name)) && containingClass.isSubclassOf(MOTION_EVENT_CLS, false)) { (containingClass.isSubclassOf(CLASS_CONTEXT, false) || containingClass.isSubclassOf(RESOURCES_CLS, false))) { TypeDescriptor returnType = method.getReturnType(); if (returnType != null && returnType.matchesSignature(TYPED_ARRAY_CLS)) { checkRecycled(context, node, TYPED_ARRAY_CLS, RECYCLE);
TypeDescriptor type; ResolvedMethod method = (ResolvedMethod) resolved; if (method.isConstructor()) { ResolvedClass containingClass = method.getContainingClass(); type = containingClass.getType(); } else { type = method.getReturnType();
if (resolve instanceof ResolvedMethod) { ResolvedMethod method = (ResolvedMethod) resolve; TypeDescriptor returnType = method.getReturnType(); if (returnType == null || !returnType.matchesName(ANDROID_CONTENT_SHARED_PREFERENCES_EDITOR)) {
String name = method.getContainingClass().getSimpleName() + "." + method.getName(); String message = getMissingPermissionMessage(requirement, name, permissions); context.report(MISSING_PERMISSION, node, context.getLocation(node), message);
if (resolved instanceof JavaParser.ResolvedMethod) { ResolvedMethod method = (ResolvedMethod) resolved; JavaParser.ResolvedClass clz = method.getContainingClass(); if (clz.isSubclassOf("android.content.SharedPreferences.Editor", false) && mContext.getProject().getMinSdkVersion().getApiLevel() >= 9) {
if (method.isConstructor()) { resolved = method.getContainingClass(); } else { TypeDescriptor returnType = method.getReturnType(); if (returnType != null) { resolved = returnType.getTypeClass();
@NonNull ResolvedMethod method) { String name = method.getName(); if (ON_DETACHED_FROM_WINDOW.equals(name)) { if (!method.getContainingClass().isSubclassOf(CLASS_VIEW, false)) { return null; return method.getSuperMethod(); } else if (ON_VISIBILITY_CHANGED.equals(name)) { if (!method.getContainingClass().isSubclassOf( "android.support.wearable.watchface.WatchFaceService.Engine", false)) { return null; return method.getSuperMethod(); ResolvedMethod directSuper = method.getSuperMethod(); ResolvedMethod superMethod = directSuper; while (superMethod != null) { Iterable<JavaParser.ResolvedAnnotation> annotations = superMethod.getAnnotations(); for (JavaParser.ResolvedAnnotation annotation : annotations) { annotation = SupportAnnotationDetector.getRelevantAnnotation(annotation); superMethod = superMethod.getSuperMethod();
ResolvedClass containingClass = method.getContainingClass(); if (containingClass.matches(NOTIFICATION_LISTENER_SERVICE_FQN)) { continue; if ((method.getModifiers() & Modifier.ABSTRACT) != 0) { continue; if (method.getArgumentCount() != 1) { continue; // Wrong signature if (!method.getArgumentType(0).matchesName(STATUS_BAR_NOTIFICATION_FQN)) { continue;
if (!method.getContainingClass().matches(LOG_CLS)) { return; if (method.getArgumentCount() > tagArgumentIndex && method.getArgumentType(tagArgumentIndex).matchesSignature(TYPE_STRING) && node.astArguments().size() == method.getArgumentCount()) { Iterator<Expression> iterator = node.astArguments().iterator(); if (tagArgumentIndex == 1) {
if (resolved instanceof ResolvedMethod) { ResolvedMethod method = (ResolvedMethod) resolved; ResolvedClass cls = method.getContainingClass(); for (ResolvedAnnotation annotation : method.getAnnotations()) { String name = annotation.getSignature(); if (name.startsWith(SUPPORT_ANNOTATIONS_PREFIX) method = method.getSuperMethod();
if ((getModifiers() & Modifier.PRIVATE) != 0) { ResolvedClass cls = getContainingClass().getSuperClass(); if (cls != null) { String methodName = getName(); int argCount = getArgumentCount(); for (ResolvedMethod method : cls.getMethods(methodName, true)) { if (argCount != method.getArgumentCount()) { continue; if (!method.getArgumentType(arg).equals(getArgumentType(arg))) { sameTypes = false; break; if ((method.getModifiers() & Modifier.PRIVATE) != 0) { if (haveSameCompilationUnit(getContainingClass(), method.getContainingClass())) { return method; } else {
if (r instanceof ResolvedMethod) { ResolvedMethod method = (ResolvedMethod) r; ResolvedClass cls = method.getContainingClass(); if (cls.matches(MOTION_EVENT_CLS)) { mEscapes = false;
if (resolved instanceof ResolvedMethod) { ResolvedMethod method = (ResolvedMethod) resolved; Iterable<ResolvedAnnotation> annotations = method.getAnnotations(); for (ResolvedAnnotation annotation : annotations) { annotation = getRelevantAnnotation(annotation); ResolvedClass containingClass = method.getContainingClass(); annotations = containingClass.getAnnotations(); for (ResolvedAnnotation annotation : annotations) { for (int i = 0, n = method.getArgumentCount(); i < n && arguments.hasNext(); i++) { Expression argument = arguments.next(); annotations = method.getParameterAnnotations(i); for (ResolvedAnnotation annotation : annotations) { annotation = getRelevantAnnotation(annotation);
JavaParser.ResolvedClass clzz = method.getContainingClass(); boolean isSubClass = false;
if (!method.getContainingClass().isSubclassOf(CIPHER, false)) { return;
@Override public boolean visitConstructorInvocation(ConstructorInvocation node) { if (mVisitConstructors) { TypeReference typeReference = node.astTypeReference(); if (typeReference != null) { TypeReferencePart last = typeReference.astParts().last(); if (last != null) { String name = last.astIdentifier().astValue(); if (mConstructorSimpleNames.contains(name)) { ResolvedNode resolved = mContext.resolve(node); if (resolved instanceof ResolvedMethod) { ResolvedMethod method = (ResolvedMethod) resolved; String type = method.getContainingClass().getName(); List<VisitingDetector> list = mConstructorDetectors.get(type); if (list != null) { for (VisitingDetector v : list) { v.getJavaScanner().visitConstructor(mContext, v.getVisitor(), node, method); } } } } } } } return super.visitConstructorInvocation(node); } }
if (!method.getContainingClass().matches("android.database.sqlite.SQLiteDatabase")) { return; if (method.getArgumentCount() > 0 && method.getArgumentType(0).matchesSignature(TYPE_STRING) && node.astArguments().size() == method.getArgumentCount()) { Iterator<Expression> iterator = node.astArguments().iterator(); Node argument = iterator.next();
@Override protected boolean isCleanupCall(@NonNull MethodInvocation call) { String methodName = call.astName().astValue(); if (!recycleName.equals(methodName)) { return false; } ResolvedNode resolved = mContext.resolve(call); if (resolved instanceof ResolvedMethod) { ResolvedClass containingClass = ((ResolvedMethod) resolved).getContainingClass(); if (containingClass.isSubclassOf(recycleType, false)) { // Yes, called the right recycle() method; now make sure // we're calling it on the right variable Expression operand = call.astOperand(); if (operand != null) { resolved = mContext.resolve(operand); //noinspection SuspiciousMethodCalls if (resolved != null && mVariables.contains(resolved)) { return true; } } } } return false; } };
@Override public void visitMethod(@NonNull JavaContext context, @Nullable AstVisitor visitor, @NonNull MethodInvocation node) { // Ignore the issue if we never build for any API less than 17. if (context.getMainProject().getMinSdk() >= 17) { return; } // Ignore if the method doesn't fit our description. ResolvedNode resolved = context.resolve(node); if (!(resolved instanceof ResolvedMethod)) { return; } ResolvedMethod method = (ResolvedMethod) resolved; if (!method.getContainingClass().isSubclassOf(WEB_VIEW, false)) { return; } if (method.getArgumentCount() != 2 || !method.getArgumentType(0).matchesName(TYPE_OBJECT) || !method.getArgumentType(1).matchesName(TYPE_STRING)) { return; } String message = "`WebView.addJavascriptInterface` should not be called with minSdkVersion < 17 for security reasons: " + "JavaScript can use reflection to manipulate application"; context.report(ISSUE, node, context.getLocation(node.astName()), message); } }