/*
 * Copyright 2000-2010 JetBrains s.r.o.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.intellij.testFramework;

import com.intellij.ide.DataManager;
import com.intellij.openapi.actionSystem.*;
import com.intellij.openapi.editor.Editor;
import com.intellij.openapi.editor.actionSystem.EditorActionHandler;
import com.intellij.openapi.editor.actionSystem.EditorActionManager;
import com.intellij.openapi.editor.actionSystem.TypedAction;
import junit.framework.Assert;

/**
 * User: Maxim.Mossienko
 * Date: 15.03.2010
 * Time: 21:00:49
 */
public class EditorTestUtil {
  public static final char BACKSPACE_FAKE_CHAR = '\uFFFF';
  public static final char SMART_ENTER_FAKE_CHAR = '\uFFFE';

  public static void performTypingAction(Editor editor, char c) {
    EditorActionManager actionManager = EditorActionManager.getInstance();
    if (c == BACKSPACE_FAKE_CHAR) {
      EditorActionHandler actionHandler = actionManager.getActionHandler(IdeActions.ACTION_EDITOR_BACKSPACE);
      actionHandler.execute(editor, DataManager.getInstance().getDataContext());
    } else if (c == SMART_ENTER_FAKE_CHAR) {
      EditorActionHandler actionHandler = actionManager.getActionHandler(IdeActions.ACTION_EDITOR_COMPLETE_STATEMENT);
      actionHandler.execute(editor, DataManager.getInstance().getDataContext());
    }
    else if (c == '\n') {
      EditorActionHandler actionHandler = actionManager.getActionHandler(IdeActions.ACTION_EDITOR_ENTER);
      actionHandler.execute(editor, DataManager.getInstance().getDataContext());
    }
    else {
      TypedAction action = actionManager.getTypedAction();
      action.actionPerformed(editor, c, DataManager.getInstance().getDataContext());
    }
  }

  public static void performReferenceCopy(DataContext dataContext) {
    ActionManager actionManager = ActionManager.getInstance();
    AnAction action = actionManager.getAction(IdeActions.ACTION_COPY_REFERENCE);
    AnActionEvent
      event = new AnActionEvent(null, dataContext, "", action.getTemplatePresentation(),
                                            ActionManager.getInstance(), 0);
    action.update(event);
    Assert.assertTrue(event.getPresentation().isEnabled());
    action.actionPerformed(event);
  }

  public static void performPaste(Editor editor) {
    EditorActionManager actionManager = EditorActionManager.getInstance();
    EditorActionHandler actionHandler = actionManager.getActionHandler(IdeActions.ACTION_EDITOR_PASTE);
    actionHandler.execute(editor, DataManager.getInstance().getDataContext());
  }
}

@@ -965,29 +965,258 @@
 ort 
-junit.framework.Asser
+com.intellij.openapi.editor.highlighter.EditorHighlighter;%0Aimport com.intellij.openapi.editor.highlighter.HighlighterIterator;%0Aimport com.intellij.psi.tree.IElementType;%0Aimport junit.framework.Assert;%0A%0Aimport java.util.ArrayList;%0Aimport java.util.Lis
 t;%0A%0A
@@ -3276,11 +3276,352 @@
 ());%0A  %7D
+%0A%0A  public static List%3CIElementType%3E getAllTokens(EditorHighlighter highlighter) %7B%0A    List%3CIElementType%3E tokens = new ArrayList%3CIElementType%3E();%0A    HighlighterIterator iterator = highlighter.createIterator(0);%0A    while (!iterator.atEnd()) %7B%0A      tokens.add(iterator.getTokenType());%0A      iterator.advance();%0A    %7D%0A    return tokens;%0A  %7D
 %0A%7D%0A

move test utility method to utility class