TypeDescriptor parameterType = context.getType(first); if (parameterType != null) { specifiesLocale = isLocaleReference(parameterType.getName()); } else if (!call.astName().astValue().equals(FORMAT_METHOD)) { specifiesLocale = 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);
@NonNull @Override public String getInternalName() { if (mBinding instanceof ReferenceBinding) { ReferenceBinding ref = (ReferenceBinding) mBinding; StringBuilder sb = new StringBuilder(100); char[][] name = ref.compoundName; if (name == null) { return super.getInternalName(); } for (char[] segment : name) { if (sb.length() != 0) { sb.append('/'); } for (char c : segment) { sb.append(c); } } return sb.toString(); } return super.getInternalName(); }
TypeDescriptor returnType = method.getReturnType(); if (returnType != null) { resolved = returnType.getTypeClass(); TypeDescriptor type = context.getType(first); if (type != null) { resolved = type.getTypeClass();
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) {
TypeDescriptor returnType = method.getReturnType(); if (returnType == null || !returnType.matchesName(ANDROID_CONTENT_SHARED_PREFERENCES_EDITOR)) { return;
int tagArgumentIndex = PRINTLN.equals(name) ? 1 : 0; if (method.getArgumentCount() > tagArgumentIndex && method.getArgumentType(tagArgumentIndex).matchesSignature(TYPE_STRING) && node.astArguments().size() == method.getArgumentCount()) { Iterator<Expression> iterator = node.astArguments().iterator();
if (!method.getArgumentType(arg).equals(getArgumentType(arg))) { sameTypes = false; break;
continue; // Wrong signature if (!method.getArgumentType(0).matchesName(STATUS_BAR_NOTIFICATION_FQN)) { continue;
&& method.getArgumentType(0).matchesSignature(TYPE_STRING) && node.astArguments().size() == method.getArgumentCount()) { Iterator<Expression> iterator = node.astArguments().iterator();
@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); } }
private static boolean isXmlConstructor(ResolvedMethod method) { // Accept // android.content.Context // android.content.Context,android.util.AttributeSet // android.content.Context,android.util.AttributeSet,int int argumentCount = method.getArgumentCount(); if (argumentCount == 0 || argumentCount > 3) { return false; } if (!method.getArgumentType(0).matchesName(CLASS_CONTEXT)) { return false; } if (argumentCount == 1) { return true; } if (!method.getArgumentType(1).matchesName(CLASS_ATTRIBUTE_SET)) { return false; } //noinspection SimplifiableIfStatement if (argumentCount == 2) { return true; } return method.getArgumentType(2).matchesName("int"); }
@Override public void visitMethod(@NonNull JavaContext context, @Nullable AstVisitor visitor, @NonNull MethodInvocation node) { ResolvedNode resolved = context.resolve(node); if (!(resolved instanceof ResolvedMethod) || !((ResolvedMethod) resolved).getContainingClass() .isSubclassOf(PACKAGE_MANAGER_CLASS, false)) { return; } StrictListAccessor<Expression, MethodInvocation> argumentList = node.astArguments(); // Ignore if the method doesn't fit our description. if (argumentList != null && argumentList.size() == 2) { TypeDescriptor firstParameterType = context.getType(argumentList.first()); if (firstParameterType != null && firstParameterType.matchesSignature(JavaParser.TYPE_STRING)) { maybeReportIssue(calculateValue(context, argumentList.last()), context, node); } } }
private static boolean isJavaScriptAnnotated(ResolvedClass clz) { while (clz != null) { for (ResolvedAnnotation annotation : clz.getAnnotations()) { if (annotation.getType().matchesSignature(JAVASCRIPT_INTERFACE_CLS)) { return true; } } for (ResolvedMethod method : clz.getMethods(false)) { for (ResolvedAnnotation annotation : method.getAnnotations()) { if (annotation.getType().matchesSignature(JAVASCRIPT_INTERFACE_CLS)) { return true; } } } clz = clz.getSuperClass(); } return false; }
@NonNull @Override public String getSimpleName() { if (mBinding instanceof ReferenceBinding) { ReferenceBinding ref = (ReferenceBinding) mBinding; char[][] name = ref.compoundName; char[] lastSegment = name[name.length - 1]; StringBuilder sb = new StringBuilder(lastSegment.length); for (char c : lastSegment) { if (c == '$') { c = '.'; } sb.append(c); } return sb.toString(); } return super.getSimpleName(); }
/** * Searches for the annotation of the given type on the method * * @param type the fully qualified name of the annotation to check * @param parameterIndex the index of the parameter to look up * @return the annotation, or null if not found */ @Nullable public ResolvedAnnotation getParameterAnnotation(@NonNull String type, int parameterIndex) { for (ResolvedAnnotation annotation : getParameterAnnotations(parameterIndex)) { if (annotation.getType().matchesSignature(type)) { return annotation; } } return null; }
/** * Searches for the annotation of the given type on this node * * @param type the fully qualified name of the annotation to check * @return the annotation, or null if not found */ @Nullable public ResolvedAnnotation getAnnotation(@NonNull String type) { for (ResolvedAnnotation annotation : getAnnotations()) { if (annotation.getType().matchesSignature(type)) { return annotation; } } return null; }
@Override public void afterVisitConstructorInvocation(@NonNull ConstructorInvocation node) { ResolvedNode resolved = mContext.resolve(node); if (resolved instanceof ResolvedMethod) { ResolvedMethod method = (ResolvedMethod) resolved; mTypes.put(node, method.getContainingClass()); } else { // Implicit constructor? TypeDescriptor type = mContext.getType(node); if (type != null) { ResolvedClass typeClass = type.getTypeClass(); if (typeClass != null) { mTypes.put(node, typeClass); } } } }
private static boolean isLocaleReference(@Nullable TypeDescriptor reference) { return reference != null && isLocaleReference(reference.getName()); }
public ResolvedClass getType() { Expression first = mTargetCall.astArguments().first(); ResolvedClass resolvedClass = mTypes.get(first); if (resolvedClass == null) { ResolvedNode resolved = mContext.resolve(first); if (resolved instanceof ResolvedVariable) { resolvedClass = mVariableTypes.get(resolved); if (resolvedClass == null) { return ((ResolvedVariable)resolved).getType().getTypeClass(); } } } return resolvedClass; }