boolean (PsiVariable variable) { Set<VarUseContext> insideContexts = new HashSet<>(); Set<VarUseContext> outsideContexts = new HashSet<>(); for (PsiReferenceExpression ref : VariableAccessUtils.getVariableReferences(variable, myParent)) { VarUseContext context = VarUseContext.from(ref); if (context != null) { (isInside(ref) ? insideContexts : outsideContexts).add(context); } } if (!Collections.disjoint(insideContexts, outsideContexts)) return true; return false; }