List<PsiVariable> (PsiParameterListOwner method) { List<PsiVariable> variables = new ArrayList<>(); PsiCodeBlock body = ObjectUtils.tryCast(method.getBody(), PsiCodeBlock.class); if (body != null) { PsiStatement[] statements = body.getStatements(); for (PsiStatement statement : statements) { if (statement instanceof PsiDeclarationStatement) { PsiElement[] declaredElements = ((PsiDeclarationStatement)statement).getDeclaredElements(); for (PsiElement declaredElement : declaredElements) { if (declaredElement instanceof PsiLocalVariable) variables.add((PsiVariable)declaredElement); } } } } PsiParameter[] parameters = method.getParameterList().getParameters(); ContainerUtil.addAll(variables, parameters); return variables; }