private static boolean isEffectivelyFinal(
      PsiVariable variable, PsiElement scope, PsiJavaCodeReferenceElement context) {
    boolean effectivelyFinal;
    if (variable instanceof PsiParameter) {
      effectivelyFinal =
          notAccessedForWriting(
              variable, new LocalSearchScope(((PsiParameter) variable).getDeclarationScope()));
    } else {
      final ControlFlow controlFlow;
      try {
        controlFlow = getControlFlow(PsiUtil.getVariableCodeBlock(variable, context));
      } catch (AnalysisCanceledException e) {
        return true;
      }

      if (ControlFlowUtil.isVariableDefinitelyAssigned(variable, controlFlow)) {
        final Collection<ControlFlowUtil.VariableInfo> initializedTwice =
            ControlFlowUtil.getInitializedTwice(controlFlow);
        effectivelyFinal =
            !initializedTwice.contains(new ControlFlowUtil.VariableInfo(variable, null));
        if (effectivelyFinal) {
          effectivelyFinal = notAccessedForWriting(variable, new LocalSearchScope(scope));
        }
      } else {
        effectivelyFinal = false;
      }
    }
    return effectivelyFinal;
  }
 /**
  * see JLS chapter 16
  *
  * @return true if variable assigned (maybe more than once)
  */
 private static boolean variableDefinitelyAssignedIn(PsiVariable variable, PsiElement context) {
   try {
     ControlFlow controlFlow = getControlFlow(context);
     return ControlFlowUtil.isVariableDefinitelyAssigned(variable, controlFlow);
   } catch (AnalysisCanceledException e) {
     return false;
   }
 }