int (@NotNull PsiVariable variable) { PsiElement outerCodeBlock = PsiUtil.getVariableCodeBlock(variable, null); if (outerCodeBlock == null) return UNKNOWN; List<PsiReferenceExpression> outerReferences = new ArrayList<>(); collectReferences(outerCodeBlock, variable, outerReferences); @FixType int type = MAKE_FINAL; for (PsiReferenceExpression expression : outerReferences) { // if it happens that variable referenced from another inner class, make sure it can be make final from there PsiElement innerScope = HighlightControlFlowUtil.getElementVariableReferencedFrom(variable, expression); if (innerScope != null) { @FixType int thisType = MAKE_FINAL; if (writtenInside(variable, innerScope)) { // cannot make parameter array if (variable instanceof PsiParameter) return UNKNOWN; thisType = MAKE_ARRAY; } if (thisType == MAKE_FINAL && !canBeFinal(variable, outerReferences)) { thisType = COPY_TO_FINAL; } type = type >= thisType ? type : thisType; } } return type; }