PsiVariable () { if (myOutputVariables.length == 0 && myExitStatements.isEmpty()) { if (myCanBeChainedConstructor) { final Set<PsiField> fields = new HashSet<>(); for (PsiElement element : myElements) { element.accept(new JavaRecursiveElementWalkingVisitor() { @Override public void visitReferenceExpression(@NotNull PsiReferenceExpression expression) { super.visitReferenceExpression(expression); final PsiElement resolve = expression.resolve(); if (resolve instanceof PsiField && ((PsiField)resolve).hasModifierProperty(PsiModifier.FINAL) && PsiUtil.isAccessedForWriting(expression)) { fields.add((PsiField)resolve); } } }); } if (!fields.isEmpty()) { return fields.size() == 1 ? fields.iterator().next() : null; } } final VariablesProcessor processor = new VariablesProcessor(true) { @Override protected boolean check(PsiVariable var, ResolveState state) { return isDeclaredInside(var); } }; PsiScopesUtil.treeWalkUp(processor, myElements[myElements.length - 1], myCodeFragmentMember); if (processor.size() == 1) { return processor.getResult(0); } } return null; }