public GrInplaceConstantIntroducer( GrIntroduceContext context, OccurrencesChooser.ReplaceChoice choice) { super(IntroduceConstantHandler.REFACTORING_NAME, choice, context); myContext = context; myPanel = new GrInplaceIntroduceConstantPanel(); GrVariable localVar = GrIntroduceHandlerBase.resolveLocalVar(context); if (localVar != null) { ArrayList<String> result = ContainerUtil.newArrayList(localVar.getName()); GrExpression initializer = localVar.getInitializerGroovy(); if (initializer != null) { ContainerUtil.addAll( result, GroovyNameSuggestionUtil.suggestVariableNames( initializer, new GroovyInplaceFieldValidator(context), true)); } mySuggestedNames = ArrayUtil.toStringArray(result); } else { GrExpression expression = context.getExpression(); assert expression != null; mySuggestedNames = GroovyNameSuggestionUtil.suggestVariableNames( expression, new GroovyInplaceFieldValidator(context), true); } }
@NotNull public LinkedHashSet<String> suggestNames() { final GrExpression expression = myContext.getExpression(); final GrVariable var = myContext.getVar(); final StringPartInfo stringPart = myContext.getStringPart(); if (expression != null) { return new LinkedHashSet<String>( Arrays.asList( GroovyNameSuggestionUtil.suggestVariableNames(expression, myValidator, myForStatic))); } else if (stringPart != null) { return new LinkedHashSet<String>( Arrays.asList( GroovyNameSuggestionUtil.suggestVariableNames( stringPart.getLiteral(), myValidator, myForStatic))); } else { assert var != null; return new LinkedHashSet<String>( Arrays.asList( GroovyNameSuggestionUtil.suggestVariableNameByType(var.getType(), myValidator))); } }