/** Returns true if the given type matches the given fully qualified type name */ public boolean parameterHasType( @Nullable PsiMethod method, int parameterIndex, @NonNull String typeName) { if (method == null) { return false; } PsiParameterList parameterList = method.getParameterList(); return parameterList.getParametersCount() > parameterIndex && typeMatches(parameterList.getParameters()[parameterIndex].getType(), typeName); }
private static boolean isXmlConstructor( @NonNull JavaEvaluator evaluator, @NonNull PsiMethod method) { // Accept // android.content.Context // android.content.Context,android.util.AttributeSet // android.content.Context,android.util.AttributeSet,int PsiParameterList parameterList = method.getParameterList(); int argumentCount = parameterList.getParametersCount(); if (argumentCount == 0 || argumentCount > 3) { return false; } PsiParameter[] parameters = parameterList.getParameters(); if (!evaluator.typeMatches(parameters[0].getType(), CLASS_CONTEXT)) { return false; } if (argumentCount == 1) { return true; } if (!evaluator.typeMatches(parameters[1].getType(), CLASS_ATTRIBUTE_SET)) { return false; } //noinspection SimplifiableIfStatement if (argumentCount == 2) { return true; } return PsiType.INT.equals(parameters[2].getType()); }
/** * 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; }