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)));
    }
  }
 @Nullable
 public static GrTypeDefinition findContainingClass(GrIntroduceContext context) {
   PsiElement place = context.getPlace();
   while (true) {
     final GrTypeDefinition typeDefinition =
         PsiTreeUtil.getParentOfType(place, GrTypeDefinition.class, true, GroovyFileBase.class);
     if (typeDefinition == null) return null;
     if (!typeDefinition.isAnonymous()
         && (typeDefinition.hasModifierProperty(PsiModifier.STATIC)
             || typeDefinition.getContainingClass() == null)) {
       return typeDefinition;
     }
     place = typeDefinition;
   }
 }
 @Override
 protected GrVariable runRefactoring(
     GrIntroduceContext context, GrIntroduceConstantSettings settings, boolean processUsages) {
   return refactorInWriteAction(
       () -> {
         if (processUsages) {
           return new GrIntroduceConstantProcessor(context, settings).run();
         } else {
           PsiElement scope = context.getScope();
           return new GrIntroduceConstantProcessor(context, settings)
               .addDeclaration(
                   scope instanceof GroovyFileBase
                       ? ((GroovyFileBase) scope).getScriptClass()
                       : (PsiClass) scope)
               .getVariables()[0];
         }
       });
 }