private static boolean isReplaceableStringBuffer(PsiVariable variable, PsiElement context) {
      if (context == null) {
        return false;
      }
      final PsiType type = variable.getType();
      if (!TypeUtils.typeEquals(CommonClassNames.JAVA_LANG_STRING_BUFFER, type)) {
        return false;
      }
      final PsiExpression initializer = variable.getInitializer();
      if (initializer != null && getNewStringBuffer(initializer) == null) {
        return false;
      }
      final Predicate<PsiAssignmentExpression> skipFilter = e -> getNewStringBuffer(e.getRExpression()) != null;
      if (VariableAccessUtils.variableIsAssigned(variable, skipFilter, context)) {
        return false;
      }
      if (VariableAccessUtils.variableIsAssignedFrom(variable, context)) {
        return false;
      }
      if (VariableAccessUtils.variableIsReturned(variable, context, true)) {
        return false;
      }
      if (VariableAccessUtils.variableIsUsedInInnerClass(variable, context)) {
        return false;
      }
      final Processor<PsiCall> processor = call -> {
        final PsiMethod method = call.resolveMethod();
        if (method == null) {
          return false;
        }
        final PsiClass aClass = method.getContainingClass();
        if (aClass == null) {
          return false;
        }
        final String fqName = aClass.getQualifiedName();
        if ("java.util.regex.Matcher".equals(fqName)) {
          if (!PsiUtil.isLanguageLevel9OrHigher(call)) {
            return false;
          }
          final String methodName = method.getName();
          if ("appendTail".equals(methodName)) {
            return call instanceof PsiExpression && isSafeStringBufferUsage((PsiExpression)call);
          }
          else if ("appendReplacement".equals(methodName)) {
            return true;
          }
        }
        return SAFE_CLASSES.contains(fqName);
      };
      if (VariableAccessUtils.variableIsPassedAsMethodArgument(variable, context, true, processor)) {
        return false;
      }
      return true;
    }
private static boolean isReplaceableStringBuffer(PsiVariable variable, PsiElement context)