ChainDeclaration (@NotNull PsiDeclarationStatement declaration, @NotNull PsiExpression chainExpression) { PsiElement[] elements = declaration.getDeclaredElements(); if (elements.length != 1) return null; PsiLocalVariable variable = tryCast(elements[0], PsiLocalVariable.class); if (variable == null || PsiUtil.skipParenthesizedExprDown(variable.getInitializer()) != chainExpression) return null; boolean needsAdditionalVariable = !VariableAccessUtils.canUseAsNonFinal(variable); String name = needsAdditionalVariable ? null : variable.getName(); return new ChainDeclaration(name, variable); }