SuggestedNameInfo (final PsiElement element, PsiElement nameSuggestionContext) { PsiVariable var = null; if (element instanceof PsiVariable) { var = (PsiVariable)element; } else if (element instanceof PsiIdentifier identifier && identifier.getParent() instanceof PsiVariable parent) { var = parent; } if (var == null) return null; JavaCodeStyleManager codeStyleManager = JavaCodeStyleManager.getInstance(element.getProject()); VariableKind variableKind = codeStyleManager.getVariableKind(var); final SuggestedNameInfo nameInfo = codeStyleManager.suggestVariableName(variableKind, null, var.getInitializer(), var.getType()); final PsiExpression expression = PsiTreeUtil.getParentOfType(nameSuggestionContext, PsiCallExpression.class, false, PsiLambdaExpression.class, PsiClass.class); if (expression != null) { return new SuggestedNameInfo.Delegate(codeStyleManager.suggestVariableName(variableKind, null, expression, var.getType()).names, nameInfo); } return nameInfo; }