NamesByExprInfo (@NotNull PsiExpression expr, @Nullable VariableKind variableKind, boolean useAllMethodNames) { if (expr instanceof PsiMethodCallExpression) { PsiReferenceExpression methodExpr = ((PsiMethodCallExpression)expr).getMethodExpression(); String methodName = methodExpr.getReferenceName(); if (methodName != null) { if ("of".equals(methodName) || "ofNullable".equals(methodName)) { if (isJavaUtilMethodCall((PsiMethodCallExpression)expr)) { PsiExpression[] expressions = ((PsiMethodCallExpression)expr).getArgumentList().getExpressions(); if (expressions.length > 0) { return suggestVariableNameByExpressionOnly(expressions[0], variableKind, useAllMethodNames); } } } if ("map".equals(methodName) || "flatMap".equals(methodName) || "filter".equals(methodName)) { if (isJavaUtilMethodCall((PsiMethodCallExpression)expr)) { return NamesByExprInfo.EMPTY; } } String[] words = NameUtilCore.nameToWords(methodName); if (words.length > 0) { final String firstWord = words[0]; if (GET_PREFIX.equals(firstWord) || IS_PREFIX.equals(firstWord) || FIND_PREFIX.equals(firstWord) || CREATE_PREFIX.equals(firstWord) || AS_PREFIX.equals(firstWord) || TO_PREFIX.equals(firstWord)) { if (words.length > 1) { final String propertyName = methodName.substring(firstWord.length()); final PsiExpression qualifierExpression = methodExpr.getQualifierExpression(); if (qualifierExpression instanceof PsiReferenceExpression && ((PsiReferenceExpression)qualifierExpression).resolve() instanceof PsiVariable) { String name = ((PsiReferenceExpression)qualifierExpression).getReferenceName() + StringUtil.capitalize(propertyName); return new NamesByExprInfo(propertyName, name); } return new NamesByExprInfo(propertyName); } } else if (words.length == 1 || useAllMethodNames) { if (Registry.is("add.past.participle.to.suggested.names") && !"equals".equals(firstWord) && !"valueOf".equals(methodName)) { words[0] = PastParticiple.pastParticiple(firstWord); return new NamesByExprInfo(methodName, words[0], StringUtil.join(words)); } else { return new NamesByExprInfo(methodName); } } } } } else if (expr instanceof PsiReferenceExpression) { String propertyName = getPropertyName((PsiReferenceExpression)expr, true); if (propertyName != null) { return new NamesByExprInfo(propertyName); } } else if (expr instanceof PsiArrayAccessExpression) { NamesByExprInfo info = suggestVariableNameByExpressionOnly(((PsiArrayAccessExpression)expr).getArrayExpression(), variableKind, useAllMethodNames); String singular = info.propertyName == null ? null : StringUtil.unpluralize(info.propertyName); if (singular != null) { return new NamesByExprInfo(singular, ContainerUtil.mapNotNull(info.names, StringUtil::unpluralize)); } } else if (expr instanceof PsiLiteralExpression literalExpression && variableKind == VariableKind.STATIC_FINAL_FIELD) { final Object value = literalExpression.getValue(); if (value instanceof String stringValue) { String[] names = getSuggestionsByValue(stringValue); if (names.length > 0) { return new NamesByExprInfo(null, constantValueToConstantName(names)); } } } else if (expr instanceof PsiParenthesizedExpression) { final PsiExpression expression = ((PsiParenthesizedExpression)expr).getExpression(); if (expression != null) { return suggestVariableNameByExpressionOnly(expression, variableKind, useAllMethodNames); } } else if (expr instanceof PsiTypeCastExpression) { final PsiExpression operand = ((PsiTypeCastExpression)expr).getOperand(); if (operand != null) { return suggestVariableNameByExpressionOnly(operand, variableKind, useAllMethodNames); } } else if (expr instanceof PsiLiteralExpression) { final String text = StringUtil.unquoteString(expr.getText()); if (isIdentifier(text)) { return new NamesByExprInfo(text); } } else if (expr instanceof PsiFunctionalExpression && variableKind != null) { final PsiType functionalInterfaceType = ((PsiFunctionalExpression)expr).getFunctionalInterfaceType(); if (functionalInterfaceType != null) { return new NamesByExprInfo(null, doSuggestNamesByType(functionalInterfaceType, variableKind)); } } return NamesByExprInfo.EMPTY; }