@Override public void visitClass(UClass node) { if (evaluator.isAbstract(node)) { return; if (!evaluator.isPublic(node)) { String message = String.format("This ControllerChangeHandler class should be public (%1$s)", node.getQualifiedName()); context.report(ISSUE, node, context.getLocation((UElement) node), message); if (node.getContainingClass() != null && !evaluator.isStatic(node)) { String message = String.format("This ControllerChangeHandler inner class should be static (%1$s)", node.getQualifiedName()); context.report(ISSUE, node, context.getLocation((UElement) node), message); if (method.isConstructor()) { hasConstructor = true; if (evaluator.isPublic(method) && method.getUastParameters().size() == 0) { hasDefaultConstructor = true; break;
private boolean appendJvmTypeName(@NonNull StringBuilder signature, @NonNull PsiClass outerClass) { String className = getInternalName(outerClass); if (className == null) { return false; } signature.append('L').append(className.replace('.', '/')).append(';'); return true; }
private boolean isInJob(PsiField field) { JavaEvaluator evaluator = context.getEvaluator(); if (evaluator.isMemberInSubClassOf(field, JOBQUEUE_JOB, true)) { return true; } return false; }
private static boolean isAppBarActivityCall(@NonNull JavaContext context, @NonNull PsiMethodCallExpression node, @NonNull PsiMethod method) { JavaEvaluator evaluator = context.getEvaluator(); if (evaluator.isMemberInSubClassOf(method, CLASS_ACTIVITY, false)) { // Make sure that the calling context is a subclass of ActionBarActivity; // we don't want to flag these calls if they are in non-appcompat activities // such as PreferenceActivity (see b.android.com/58512) PsiClass cls = PsiTreeUtil.getParentOfType(node, PsiClass.class, true); return cls != null && evaluator.extendsClass(cls, "android.support.v7.app.ActionBarActivity", false); } return false; }
@Override public void visitMethod(JavaContext context, UCallExpression node, PsiMethod method) { if (context.getEvaluator().isMemberInClass(method, "android.util.Log")) { context.report(ISSUE, node, context.getLocation(node), ISSUE_DESCRIPTION); } } }
if (!evaluator.isMemberInSubClassOf(method, CLASS_VIEW, false)) { return; if (evaluator.extendsClass(typeClass, CLASS_VIEW, false)) { objectType = "views"; } else if (evaluator.implementsInterface(typeClass, CURSOR_CLS, false)) { objectType = "cursors"; } else if (typeClass.getName() != null && typeClass.getName().endsWith("ViewHolder")) {
PsiMethod directSuper = evaluator.getSuperMethod(method); if (directSuper == null) { return null; if (!evaluator.isMemberInSubClassOf(method, CLASS_VIEW, false)) { return null; if (!evaluator.isMemberInSubClassOf(method, "android.support.wearable.watchface.WatchFaceService.Engine", false)) { return null; PsiAnnotation[] annotations = evaluator.getAllAnnotations(directSuper, true); for (PsiAnnotation annotation : annotations) { String signature = annotation.getQualifiedName();
private static boolean isLeakCandidate( @NonNull PsiClass cls, @NonNull JavaEvaluator evaluator) { return evaluator.extendsClass(cls, CLASS_CONTEXT, false) || evaluator.extendsClass(cls, CLASS_VIEW, false) || evaluator.extendsClass(cls, CLASS_FRAGMENT, false); } }
if (evaluator.isMemberInClass(method, JAVA_SECURITY_SECURE_RANDOM) || evaluator.isMemberInSubClassOf(method, JAVA_UTIL_RANDOM, false) && isSecureRandomReceiver(context, call)) { } else { PsiElement resolvedArgument = evaluator.resolve(seedArgument); if (resolvedArgument instanceof PsiMethod) { PsiMethod seedMethod = (PsiMethod) resolvedArgument;
/** * Returns true if the given method (which is typically looked up by resolving a method call) is * either a method in the exact given class, or if {@code allowInherit} is true, a method in a * class possibly extending the given class, and if the parameter types are the exact types * specified. * * @param method the method in question * @param className the class name the method should be defined in or inherit from (or * if null, allow any class) * @param allowInherit whether we allow checking for inheritance * @param argumentTypes the names of the types of the parameters * @return true if this method is defined in the given class and with the given parameters */ public boolean methodMatches( @NonNull PsiMethod method, @Nullable String className, boolean allowInherit, @NonNull String... argumentTypes) { if (className != null && allowInherit) { if (!isMemberInSubClassOf(method, className, false)) { return false; } } return parametersMatch(method, argumentTypes); }
if (evaluator.isAbstract(cls) || evaluator.isPrivate(cls)) { if (framework == null) { reportMissing(context, cls, className, rightTag); } else if (!evaluator.extendsClass(cls, framework, false)) { reportWrongTag(context, cls, rightTag, className, framework);
if (evaluator.isAbstract(declaration) || evaluator.isPrivate(declaration) || declaration instanceof PsiAnonymousClass) { !evaluator.isStatic(declaration)) {
String methodName = method.getName(); if (methodName.equals(FORMAT_METHOD)) { if (evaluator.isMemberInClass(method, TYPE_STRING)) { if (evaluator.isMemberInSubClassOf(method, CLASS_RESOURCES, false) || evaluator.isMemberInSubClassOf(method, CLASS_CONTEXT, false) || evaluator.isMemberInSubClassOf(method, CLASS_FRAGMENT, false) || evaluator.isMemberInSubClassOf(method, CLASS_V4_FRAGMENT, false)) { checkStringFormatCall(context, method, node, false);
/** * Checks whether the class extends a super class or implements a given interface. Like calling * both {@link #extendsClass(PsiClass, String, boolean)} and {@link * #implementsInterface(PsiClass, String, boolean)}. */ public boolean inheritsFrom( @NonNull PsiClass cls, @NonNull String className, boolean strict) { return extendsClass(cls, className, strict) || implementsInterface(cls, className, strict); }
String name = method.getName(); JavaEvaluator evaluator = mContext.getEvaluator(); PsiMethod superMethod = evaluator.getSuperMethod(method); while (superMethod != null) { PsiClass cls = superMethod.getContainingClass(); && !fqcn.equals(CommonClassNames.JAVA_LANG_OBJECT) || fqcn.startsWith("javax.")) { String desc = evaluator.getInternalDescription(superMethod, false, false); if (desc != null) { String owner = evaluator.getInternalName(cls); if (owner == null) { return; superMethod = evaluator.getSuperMethod(superMethod);
String owner = evaluator.getInternalName(containingClass); if (owner == null) { return; // Couldn't resolve type String desc = evaluator.getInternalDescription(method, false, false); if (desc == null) { PsiType type = qualifier.getType(); if (type instanceof PsiClassType) { String expressionOwner = evaluator.getInternalName((PsiClassType) type); if (expressionOwner != null && !expressionOwner.equals(owner)) { int specificApi = mApiDatabase String expressionOwner = evaluator.getInternalName(cls); if (expressionOwner == null || "java/lang/Object".equals(expressionOwner)) { break; .getParentOfType(expression, PsiMethod.class, true); if (containingMethod != null && name.equals(containingMethod.getName()) && evaluator.areSignaturesEqual(method, containingMethod)
@Override public void visitMethod(@NonNull JavaContext context, @Nullable JavaElementVisitor visitor, @NonNull PsiMethodCallExpression node, @NonNull PsiMethod method) { JavaEvaluator evaluator = context.getEvaluator(); if (!evaluator.isMemberInClass(method, "android.database.sqlite.SQLiteDatabase")) { return; } int parameterCount = evaluator.getParameterCount(method); if (parameterCount == 0) { return; } if (!evaluator.parameterHasType(method, 0, TYPE_STRING)) { return; } // Try to resolve the String and look for STRING keys PsiExpression argument = node.getArgumentList().getExpressions()[0]; String sql = ConstantEvaluator.evaluateString(context, argument, true); if (sql != null && (sql.startsWith("CREATE TABLE") || sql.startsWith("ALTER TABLE")) && sql.matches(".*\\bSTRING\\b.*")) { String message = "Using column type STRING; did you mean to use TEXT? " + "(STRING is a numeric type and its value can be adjusted; for example, " + "strings that look like integers can drop leading zeroes. See issue " + "explanation for details.)"; context.report(ISSUE, node, context.getLocation(node), message); } } }
@Override public void visitMethod(@NonNull JavaContext context, @Nullable JavaElementVisitor visitor, @NonNull PsiMethodCallExpression call, @NonNull PsiMethod method) { JavaEvaluator evaluator = context.getEvaluator(); if (!evaluator.isMemberInSubClassOf(method, TEXT_VIEW_CLS, false)) { return; } if (method.getParameterList().getParametersCount() > 0 && evaluator.parameterHasType(method, 0, CHAR_SEQUENCE_CLS)) { checkNode(context, call.getArgumentList().getExpressions()[0]); } }
/** * Given a context type (of a parameter or field), check to see if that type implies * that the context is not the application context (for example because it's an Activity * rather than a plain context). * <p> * Returns true if it finds and reports a problem. */ private static boolean checkWifiContextType(@NonNull JavaContext context, @NonNull PsiMethodCallExpression call, @NonNull PsiType type, boolean flagPlainContext) { JavaEvaluator evaluator = context.getEvaluator(); if (type instanceof PsiClassType) { PsiClass psiClass = ((PsiClassType) type).resolve(); if (evaluator.extendsClass(psiClass, CLASS_APPLICATION, false)) { return false; } } if (evaluator.typeMatches(type, CLASS_CONTEXT)) { if (flagPlainContext) { reportWifiServiceLeak(WIFI_MANAGER_UNCERTAIN, context, call); return true; } return false; } reportWifiServiceLeak(WIFI_MANAGER, context, call); return true; }
String owner = evaluator.getInternalName(containingClass); if (owner == null) { return; // Couldn't resolve type String desc = evaluator.getInternalDescription(method, false, false); if (desc == null) {