GroupingTerminal (@NotNull TerminalBlock terminalBlock) { PsiStatement[] statements = terminalBlock.getStatements(); PsiDeclarationStatement assignmentStmt = tryCast(statements[0], PsiDeclarationStatement.class); if(assignmentStmt == null) return null; PsiElement[] elements = assignmentStmt.getDeclaredElements(); if(elements.length != 1) return null; PsiLocalVariable variable = tryCast(elements[0], PsiLocalVariable.class); if(variable == null) return null; PsiExpressionStatement addStmt = tryCast(statements[1], PsiExpressionStatement.class); if(addStmt == null) return null; PsiMethodCallExpression maybeAddCall = tryCast(addStmt.getExpression(), PsiMethodCallExpression.class); if(maybeAddCall == null) return null; PsiExpression qualifier = maybeAddCall.getMethodExpression().getQualifierExpression(); if(!ExpressionUtils.isReferenceTo(qualifier, variable)) return null; return tryExtractJava8Style(terminalBlock, tryCast(variable.getInitializer(), PsiMethodCallExpression.class), maybeAddCall); }