List<ReusedLocalVariable> (@NotNull PsiElement fragmentStart, @NotNull PsiElement fragmentEnd, @NotNull Set<PsiLocalVariable> ignoreVariables, @NotNull InputVariables inputVariables) { List<PsiLocalVariable> declaredVariables = getDeclaredVariables(fragmentStart, fragmentEnd, ignoreVariables); if (declaredVariables.isEmpty()) { return Collections.emptyList(); } ReusedLocalVariablesFinder finder = createFinder(fragmentEnd); if (finder == null) { return Collections.emptyList(); } List<PsiLocalVariable> reusedVariables = ContainerUtil.filter(declaredVariables, finder::isVariableReused); if (reusedVariables.isEmpty()) { return Collections.emptyList(); } List<ReusedLocalVariable> result = new ArrayList<>(); Set<String> tempNames = new HashSet<>(ContainerUtil.map(inputVariables.getInputVariables(), data -> data.name)); for (PsiLocalVariable variable : reusedVariables) { String name = variable.getName(); String typeText = variable.getType().getCanonicalText(); if (finder.isValueReused(variable)) { String suggestedName = finder.suggestUniqueVariableName(name); String tempName = UniqueNameGenerator.generateUniqueName(suggestedName, tempNames); tempNames.add(tempName); result.add(new ReusedLocalVariable(name, tempName, typeText, true)); } else { result.add(new ReusedLocalVariable(name, null, typeText, false)); } } return result; }