package org.jetbrains.plugins.groovy.util;

import com.intellij.codeInsight.TailType;
import com.intellij.openapi.editor.Document;
import com.intellij.openapi.editor.Editor;
import com.intellij.psi.codeStyle.CodeStyleSettings;
import com.intellij.psi.codeStyle.CodeStyleSettingsManager;

/**
 * @author Sergey Evdokimov
 */
public class FieldInitializerTailTypes extends TailType {

  public static final TailType EQ_CLOSURE = new FieldInitializerTailTypes("{}", 1);
  public static final TailType EQ_ARRAY = new FieldInitializerTailTypes("[]", 1);
  public static final TailType EQ_STRING_ARRAY = new FieldInitializerTailTypes("['']", 2);
  public static final TailType EQ_STRING = new FieldInitializerTailTypes("\"\"", 1);

  private final String myText;
  private final int myPosition;

  public FieldInitializerTailTypes(String text, int position) {
    myText = text;
    myPosition = position;
  }

  @Override
  public int processTail(Editor editor, int tailOffset) {
    CodeStyleSettings styleSettings = CodeStyleSettingsManager.getSettings(editor.getProject());
    Document document = editor.getDocument();
    CharSequence chars = document.getCharsSequence();
    int textLength = chars.length();

    if (tailOffset < textLength - 1 && chars.charAt(tailOffset) == ' ' && chars.charAt(tailOffset + 1) == '='){
      return moveCaret(editor, tailOffset, 2);
    }
    if (tailOffset < textLength && chars.charAt(tailOffset) == '='){
      return moveCaret(editor, tailOffset, 1);
    }
    if (styleSettings.SPACE_AROUND_ASSIGNMENT_OPERATORS){
      document.insertString(tailOffset, " =");
      tailOffset = moveCaret(editor, tailOffset, 2);
    }
    else{
      document.insertString(tailOffset, "=");
      tailOffset = moveCaret(editor, tailOffset, 1);

    }
    if (styleSettings.SPACE_AROUND_ASSIGNMENT_OPERATORS){
      tailOffset = insertChar(editor, tailOffset, ' ');
    }

    document.insertString(tailOffset, myText);
    return moveCaret(editor, tailOffset, myPosition);
  }

}

@@ -207,59 +207,12 @@
 e.Co
-deStyleSettings;%0Aimport com.intellij.psi.codeStyle.
+mmon
 Code
@@ -224,23 +224,16 @@
 Settings
-Manager
 ;%0A%0A/**%0A 
@@ -918,16 +918,22 @@
 ) %7B%0A    
+Common
 CodeStyl
@@ -958,16 +958,24 @@
 tings = 
+getLocal
 CodeStyl
@@ -987,47 +987,27 @@
 ings
-Manager.getSettings(editor.getProject()
+(editor, tailOffset
 );%0A 

Use code style settings from language context