List<VariableData> (@NotNull List<? extends PsiVariable> inputVariables) { UniqueNameGenerator nameGenerator = new UniqueNameGenerator(); List<VariableData> inputData = new ArrayList<>(inputVariables.size()); for (PsiVariable var : inputVariables) { final String defaultName = getParameterName(var); String name = nameGenerator.generateUniqueName(defaultName); PsiType type = GenericsUtil.getVariableTypeByExpressionType(var.getType()); final Map<PsiCodeBlock, PsiType> casts = new HashMap<>(); for (PsiReference reference : ReferencesSearch.search(var, myScope)) { final PsiElement element = reference.getElement(); final PsiElement parent = element.getParent(); final PsiCodeBlock block = PsiTreeUtil.getParentOfType(parent, PsiCodeBlock.class); if (parent instanceof PsiTypeCastExpression) { final PsiType currentType = casts.get(block); final PsiType castType = ((PsiTypeCastExpression)parent).getType(); casts.put(block, casts.containsKey(block) && currentType == null ? null : getBroaderType(currentType, castType)); } else { casts.put(block, null); } } if (!casts.containsValue(null)) { PsiType currentType = null; for (PsiType psiType : casts.values()) { currentType = getBroaderType(currentType, psiType); if (currentType == null) { break; } } if (currentType != null) { currentType = checkTopLevelInstanceOf(currentType, myScope); if (currentType != null) { type = currentType; } } } VariableData data = new VariableData(var, type); data.name = name; data.passAsParameter = true; inputData.add(data); if (myFoldingAvailable) { myFolding.isParameterFoldable(data, myScope, inputVariables, nameGenerator, defaultName); } } if (myFoldingAvailable) { final Set<VariableData> toDelete = new HashSet<>(); for (int i = inputData.size() - 1; i >=0; i--) { final VariableData data = inputData.get(i); if (myFolding.isParameterSafeToDelete(data, myScope)) { toDelete.add(data); } } inputData.removeAll(toDelete); } if (myPassFields) { for (PsiField var : myUsedInstanceFields) { final VariableData data = new VariableData(var, var.getType()); data.name = nameGenerator.generateUniqueName(getParameterName(var)); data.passAsParameter = true; inputData.add(data); } } return inputData; }