Search in sources :

Example 1 with NameSuggestionsGenerator

use of com.intellij.refactoring.ui.NameSuggestionsGenerator in project intellij-community by JetBrains.

the class IntroduceParameterHandler method createNameSuggestionGenerator.

protected static NameSuggestionsGenerator createNameSuggestionGenerator(final PsiExpression expr, final String propName, final Project project, final String enteredName) {
    return new NameSuggestionsGenerator() {

        public SuggestedNameInfo getSuggestedNameInfo(PsiType type) {
            final JavaCodeStyleManager codeStyleManager = JavaCodeStyleManager.getInstance(project);
            SuggestedNameInfo info = codeStyleManager.suggestVariableName(VariableKind.PARAMETER, propName, expr != null && expr.isValid() ? expr : null, type);
            if (expr != null && expr.isValid()) {
                info = codeStyleManager.suggestUniqueVariableName(info, expr, true);
            }
            final String[] strings = AbstractJavaInplaceIntroducer.appendUnresolvedExprName(JavaCompletionUtil.completeVariableNameForRefactoring(codeStyleManager, type, VariableKind.LOCAL_VARIABLE, info), expr);
            return new SuggestedNameInfo.Delegate(enteredName != null ? ArrayUtil.mergeArrays(new String[] { enteredName }, strings) : strings, info);
        }
    };
}
Also used : NameSuggestionsGenerator(com.intellij.refactoring.ui.NameSuggestionsGenerator) JavaCodeStyleManager(com.intellij.psi.codeStyle.JavaCodeStyleManager) SuggestedNameInfo(com.intellij.psi.codeStyle.SuggestedNameInfo)

Aggregations

JavaCodeStyleManager (com.intellij.psi.codeStyle.JavaCodeStyleManager)1 SuggestedNameInfo (com.intellij.psi.codeStyle.SuggestedNameInfo)1 NameSuggestionsGenerator (com.intellij.refactoring.ui.NameSuggestionsGenerator)1