String (@NotNull PsiExpression expr) { final PsiLiteralExpression[] literals = SyntaxTraverser.psiTraverser(expr) .filter(PsiLiteralExpression.class) .filter(lit -> isNameSupplier(lit.getText())) .filter(lit -> { final PsiElement exprList = lit.getParent(); if (!(exprList instanceof PsiExpressionList)) return false; final PsiElement call = exprList.getParent(); //TODO: exclude or not getA().getB("name").getC(); or getA(getB("name").getC()); It works fine for now in the most cases return call instanceof PsiNewExpression || call instanceof PsiMethodCallExpression; }) .toArray(new PsiLiteralExpression[0]); if (literals.length == 1) { return StringUtil.unquoteString(literals[0].getText()).replaceAll(" ", "_"); } return null; }