1 package com
.intellij
.codeInsight
;
3 import com
.intellij
.codeInsight
.highlighting
.HighlightUsagesHandler
;
4 import com
.intellij
.ide
.DataManager
;
5 import com
.intellij
.injected
.editor
.EditorWindow
;
6 import com
.intellij
.openapi
.actionSystem
.*;
7 import com
.intellij
.openapi
.application
.Result
;
8 import com
.intellij
.openapi
.application
.ex
.PathManagerEx
;
9 import com
.intellij
.openapi
.command
.WriteCommandAction
;
10 import com
.intellij
.openapi
.editor
.*;
11 import com
.intellij
.openapi
.editor
.actionSystem
.EditorActionHandler
;
12 import com
.intellij
.openapi
.editor
.actionSystem
.EditorActionManager
;
13 import com
.intellij
.openapi
.editor
.actionSystem
.TypedAction
;
14 import com
.intellij
.openapi
.editor
.ex
.DocumentEx
;
15 import com
.intellij
.openapi
.fileEditor
.FileEditorManager
;
16 import com
.intellij
.openapi
.fileEditor
.OpenFileDescriptor
;
17 import com
.intellij
.openapi
.fileTypes
.FileType
;
18 import com
.intellij
.openapi
.fileTypes
.FileTypeManager
;
19 import com
.intellij
.openapi
.roots
.ContentEntry
;
20 import com
.intellij
.openapi
.roots
.ModifiableRootModel
;
21 import com
.intellij
.openapi
.roots
.ModuleRootManager
;
22 import com
.intellij
.openapi
.util
.io
.FileUtil
;
23 import com
.intellij
.openapi
.util
.text
.StringUtil
;
24 import com
.intellij
.openapi
.vfs
.LocalFileSystem
;
25 import com
.intellij
.openapi
.vfs
.VfsUtil
;
26 import com
.intellij
.openapi
.vfs
.VirtualFile
;
27 import com
.intellij
.openapi
.vfs
.VirtualFileManager
;
28 import com
.intellij
.psi
.PsiDocumentManager
;
29 import com
.intellij
.psi
.PsiFile
;
30 import com
.intellij
.psi
.impl
.source
.PostprocessReformattingAspect
;
31 import com
.intellij
.testFramework
.PsiTestCase
;
32 import com
.intellij
.testFramework
.PsiTestData
;
33 import com
.intellij
.util
.ArrayUtil
;
34 import com
.intellij
.util
.Function
;
35 import com
.intellij
.util
.containers
.ContainerUtil
;
36 import org
.jetbrains
.annotations
.NonNls
;
39 import java
.io
.IOException
;
40 import java
.io
.OutputStream
;
41 import java
.util
.ArrayList
;
42 import java
.util
.LinkedHashMap
;
43 import java
.util
.List
;
48 public abstract class CodeInsightTestCase
extends PsiTestCase
{
49 protected Editor myEditor
;
51 public CodeInsightTestCase() {
52 myRunCommandForTest
= true;
55 protected Editor
createEditor(VirtualFile file
) {
56 final FileEditorManager instance
= FileEditorManager
.getInstance(myProject
);
58 if (file
.getFileType().isBinary()) {
62 return instance
.openTextEditor(new OpenFileDescriptor(myProject
, file
, 0), false);
66 protected void setUp() throws Exception
{
70 protected void tearDown() throws Exception
{
71 FileEditorManager editorManager
= FileEditorManager
.getInstance(myProject
);
72 VirtualFile
[] openFiles
= editorManager
.getOpenFiles();
73 for (VirtualFile openFile
: openFiles
) {
74 editorManager
.closeFile(openFile
);
80 protected PsiTestData
createData() {
81 return new CodeInsightTestData();
84 public static final String CARET_MARKER
= "<caret>";
85 public static final String SELECTION_START_MARKER
= "<selection>";
86 public static final String SELECTION_END_MARKER
= "</selection>";
88 protected void configureByFile(@NonNls String filePath
) throws Exception
{
89 configureByFile(filePath
, null);
91 protected VirtualFile
configureByFiles(String projectRoot
,String
... files
) throws Exception
{
92 final VirtualFile
[] vFiles
= new VirtualFile
[files
.length
];
93 for (int i
= 0; i
< files
.length
; i
++) {
94 String path
= files
[i
];
95 final String fullPath
= FileUtil
.toSystemIndependentName(getTestDataPath() + path
);
96 VirtualFile vFile
= LocalFileSystem
.getInstance().findFileByPath(fullPath
);
98 assertNotNull("file " + fullPath
+ " not found", vFile
);
101 File projectFile
= projectRoot
== null ?
null : new File(getTestDataPath() + projectRoot
);
103 return configureByFiles(projectFile
, vFiles
);
105 protected VirtualFile
configureByFile(String filePath
, String projectRoot
) throws Exception
{
106 String fullPath
= getTestDataPath() + filePath
;
108 final VirtualFile vFile
= LocalFileSystem
.getInstance().findFileByPath(fullPath
.replace(File
.separatorChar
, '/'));
109 assertNotNull("file " + fullPath
+ " not found", vFile
);
111 File projectFile
= projectRoot
== null ?
null : new File(getTestDataPath() + projectRoot
);
113 return configureByFile(vFile
, projectFile
);
116 protected PsiFile
configureByText(final FileType fileType
, @NonNls final String text
) throws Throwable
{
117 return configureByText(fileType
, text
, null);
120 protected PsiFile
configureByText(final FileType fileType
, @NonNls final String text
, final String _extension
) throws Throwable
{
121 final String extension
= _extension
== null ? fileType
.getDefaultExtension():_extension
;
123 File dir
= createTempDirectory();
124 final File tempFile
= File
.createTempFile("aaa", "." + extension
, dir
);
125 final FileTypeManager fileTypeManager
= FileTypeManager
.getInstance();
126 if (fileTypeManager
.getFileTypeByExtension(extension
) != fileType
) {
127 new WriteCommandAction(getProject()) {
128 protected void run(Result result
) throws Throwable
{
129 fileTypeManager
.associateExtension(fileType
, extension
);
133 final VirtualFile vFile
= LocalFileSystem
.getInstance().refreshAndFindFileByIoFile(tempFile
);
134 VfsUtil
.saveText(vFile
, text
);
135 assert vFile
!= null;
137 VirtualFile vdir
= LocalFileSystem
.getInstance().refreshAndFindFileByIoFile(dir
);
139 final ModuleRootManager rootManager
= ModuleRootManager
.getInstance(myModule
);
140 final ModifiableRootModel rootModel
= rootManager
.getModifiableModel();
141 final ContentEntry contentEntry
= rootModel
.addContentEntry(vdir
);
142 contentEntry
.addSourceFolder(vdir
, false);
145 configureByExistingFile(vFile
);
147 assertEquals(fileType
, myFile
.getVirtualFile().getFileType());
152 protected String
getTestDataPath() {
153 return PathManagerEx
.getTestDataPath();
156 protected void configureByFile(final VirtualFile vFile
) throws IOException
{
157 configureByFile(vFile
, null);
160 protected void configureByExistingFile(VirtualFile virtualFile
) {
164 Editor editor
= createEditor(virtualFile
);
166 Document document
= editor
.getDocument();
167 EditorInfo editorInfo
= new EditorInfo(document
.getText());
169 String newFileText
= editorInfo
.getNewFileText();
170 if (!document
.getText().equals(newFileText
)) {
171 document
.setText(newFileText
);
174 PsiFile file
= myPsiManager
.findFile(virtualFile
);
175 if (myFile
== null) myFile
= file
;
177 if (myEditor
== null) myEditor
= editor
;
179 editorInfo
.applyToEditor(editor
);
181 PsiDocumentManager
.getInstance(getProject()).commitAllDocuments();
184 protected VirtualFile
configureByFiles(final File projectRoot
, VirtualFile
[] vFiles
) throws IOException
{
188 final ModuleRootManager rootManager
= ModuleRootManager
.getInstance(myModule
);
189 final ModifiableRootModel rootModel
= rootManager
.getModifiableModel();
190 if (clearModelBeforeConfiguring()) {
193 File toDirIO
= createTempDirectory();
194 VirtualFile toDir
= LocalFileSystem
.getInstance().refreshAndFindFileByPath(toDirIO
.getCanonicalPath().replace(File
.separatorChar
, '/'));
196 // auxiliary files should be copied first
197 vFiles
= ArrayUtil
.reverseArray(vFiles
);
198 final LinkedHashMap
<VirtualFile
, EditorInfo
> editorInfos
;
199 if (projectRoot
!= null) {
200 FileUtil
.copyDir(projectRoot
, toDirIO
);
201 VirtualFile fromDir
= LocalFileSystem
.getInstance().refreshAndFindFileByIoFile(projectRoot
);
203 copyFilesFillingEditorInfos(fromDir
, toDir
, ContainerUtil
.map2Array(vFiles
, String
.class, new Function
<VirtualFile
, String
>() {
204 public String
fun(final VirtualFile s
) {
205 return s
.getPath().substring(projectRoot
.getPath().length());
209 VirtualFileManager
.getInstance().refresh(false);
212 editorInfos
= new LinkedHashMap
<VirtualFile
, EditorInfo
>();
213 for (final VirtualFile vFile
: vFiles
) {
214 editorInfos
.putAll(copyFilesFillingEditorInfos(vFile
.getParent(), toDir
, vFile
.getName()));
218 boolean sourceRootAdded
= false;
219 if (isAddDirToContentRoot()) {
220 final ContentEntry contentEntry
= rootModel
.addContentEntry(toDir
);
221 if (isAddDirToSource()) {
222 sourceRootAdded
= true;
223 contentEntry
.addSourceFolder(toDir
, false);
226 doCommitModel(rootModel
);
227 if (sourceRootAdded
) {
228 sourceRootAdded(toDir
);
231 openEditorsAndActivateLast(editorInfos
);
236 protected void doCommitModel(final ModifiableRootModel rootModel
) {
240 protected void sourceRootAdded(final VirtualFile dir
) {
243 protected LinkedHashMap
<VirtualFile
, EditorInfo
> copyFilesFillingEditorInfos(String testDataFromDir
,
244 final VirtualFile toDir
,
245 final String
... relativePaths
) throws IOException
{
246 if (!testDataFromDir
.startsWith("/")) testDataFromDir
= "/" + testDataFromDir
;
247 return copyFilesFillingEditorInfos(LocalFileSystem
.getInstance().refreshAndFindFileByPath(getTestDataPath() + testDataFromDir
), toDir
, relativePaths
);
250 protected LinkedHashMap
<VirtualFile
, EditorInfo
> copyFilesFillingEditorInfos(final VirtualFile fromDir
, final VirtualFile toDir
, final String
... relativePaths
) throws IOException
{
251 LinkedHashMap
<VirtualFile
, EditorInfo
> editorInfos
= new LinkedHashMap
<VirtualFile
, EditorInfo
>();
253 List
<OutputStream
> streamsToClose
= new ArrayList
<OutputStream
>();
255 for (String relativePath
: relativePaths
) {
256 if (relativePath
.startsWith("/")) {
257 relativePath
= relativePath
.substring(1);
259 final VirtualFile fromFile
= fromDir
.findFileByRelativePath(relativePath
);
260 assertNotNull(fromDir
.getPath() + "/" + relativePath
, fromFile
);
261 VirtualFile toFile
= toDir
.findFileByRelativePath(relativePath
);
262 if (toFile
== null) {
263 final File file
= new File(toDir
.getPath(), relativePath
);
264 FileUtil
.createIfDoesntExist(file
);
265 toFile
= LocalFileSystem
.getInstance().refreshAndFindFileByIoFile(file
);
266 assertNotNull(file
.getCanonicalPath(), toFile
);
269 editorInfos
.put(toFile
, copyContent(fromFile
, toFile
, streamsToClose
));
272 for(int i
= streamsToClose
.size() -1; i
>= 0 ; --i
) {
273 streamsToClose
.get(i
).close();
278 /*protected LinkedHashMap<VirtualFile, EditorInfo> copyFilesFillingEditorInfos(final VirtualFile fromDir, final VirtualFile toDir) throws IOException {
279 final LinkedHashMap<VirtualFile, EditorInfo> map = new LinkedHashMap<VirtualFile, EditorInfo>();
280 copyFilesFillingEditorInfos(fromDir, toDir, map);
285 private void copyFilesFillingEditorInfos(final VirtualFile fromDir, final VirtualFile toDir, LinkedHashMap<VirtualFile, EditorInfo> editorInfos) throws IOException {
287 List<OutputStream> streamsToClose = new ArrayList<OutputStream>();
289 final VirtualFile[] files = fromDir.getChildren();
290 for (final VirtualFile fromFile : files) {
291 if (fromFile.isDirectory()) {
292 copyFilesFillingEditorInfos(fromFile, toDir.createChildDirectory(this, fromFile.getName()), editorInfos);
294 final VirtualFile toFile = toDir.createChildData(this, fromFile.getName());
295 editorInfos.put(toFile, copyContent(fromFile, toFile, streamsToClose));
299 for(int i = streamsToClose.size() -1; i >= 0 ; --i) {
300 streamsToClose.get(i).close();
304 private EditorInfo
copyContent(final VirtualFile from
, final VirtualFile to
, final List
<OutputStream
> streamsToClose
) throws IOException
{
305 byte[] content
= from
.getFileType().isBinary() ? from
.contentsToByteArray(): null;
306 final String fileText
= from
.getFileType().isBinary() ?
null : StringUtil
.convertLineSeparators(VfsUtil
.loadText(from
));
308 EditorInfo editorInfo
= fileText
!= null ?
new EditorInfo(fileText
) : null;
309 String newFileText
= fileText
!= null ? editorInfo
.getNewFileText() : null;
310 doWrite(newFileText
, to
, content
, streamsToClose
);
314 protected final void setActiveEditor(Editor editor
) {
316 myFile
= getPsiFile(editor
.getDocument());
319 protected List
<Editor
> openEditorsAndActivateLast(final LinkedHashMap
<VirtualFile
, EditorInfo
> editorInfos
) {
320 final List
<Editor
> list
= openEditors(editorInfos
);
321 setActiveEditor(list
.get(list
.size() - 1));
325 protected final List
<Editor
> openEditors(final LinkedHashMap
<VirtualFile
, EditorInfo
> editorInfos
) {
326 return ContainerUtil
.map(editorInfos
.keySet(), new Function
<VirtualFile
, Editor
>() {
327 public Editor
fun(final VirtualFile newVFile
) {
328 PsiFile file
= myPsiManager
.findFile(newVFile
);
329 if (myFile
== null) myFile
= file
;
331 Editor editor
= createEditor(newVFile
);
332 if (myEditor
== null) myEditor
= editor
;
334 EditorInfo editorInfo
= editorInfos
.get(newVFile
);
335 if (editorInfo
!= null) {
336 editorInfo
.applyToEditor(editor
);
343 private void doWrite(final String newFileText
, final VirtualFile newVFile
, final byte[] content
, final List
<OutputStream
> streamsToClose
) throws IOException
{
344 if (newFileText
!= null) {
345 VfsUtil
.saveText(newVFile
, newFileText
);
347 final OutputStream outputStream
= newVFile
.getOutputStream(this, -1, -1);
348 outputStream
.write(content
);
349 streamsToClose
.add(outputStream
);
353 protected boolean isAddDirToContentRoot() {
357 protected boolean isAddDirToSource() {
361 protected VirtualFile
configureByFile(final VirtualFile vFile
, final File projectRoot
) throws IOException
{
362 return configureByFiles(projectRoot
, new VirtualFile
[] {vFile
});
365 protected boolean clearModelBeforeConfiguring() {
369 protected void setupCursorAndSelection(Editor editor
) {
370 Document document
= editor
.getDocument();
371 final String text
= document
.getText();
373 int caretIndex
= text
.indexOf(CARET_MARKER
);
374 int selStartIndex
= text
.indexOf(SELECTION_START_MARKER
);
375 int selEndIndex
= text
.indexOf(SELECTION_END_MARKER
);
377 final RangeMarker caretMarker
= caretIndex
>= 0 ? document
.createRangeMarker(caretIndex
, caretIndex
) : null;
378 final RangeMarker selStartMarker
= selStartIndex
>= 0 ? document
.createRangeMarker(selStartIndex
, selStartIndex
) : null;
379 final RangeMarker selEndMarker
= selEndIndex
>= 0 ? document
.createRangeMarker(selEndIndex
, selEndIndex
) : null;
381 if (caretMarker
!= null) {
382 document
.deleteString(caretMarker
.getStartOffset(), caretMarker
.getStartOffset() + CARET_MARKER
.length());
384 if (selStartMarker
!= null) {
385 document
.deleteString(selStartMarker
.getStartOffset(), selStartMarker
.getStartOffset() + SELECTION_START_MARKER
.length());
387 if (selEndMarker
!= null) {
388 document
.deleteString(selEndMarker
.getStartOffset(), selEndMarker
.getStartOffset() + SELECTION_END_MARKER
.length());
391 final String newText
= document
.getText();
393 if (caretMarker
!= null) {
394 int caretLine
= StringUtil
.offsetToLineNumber(newText
, caretMarker
.getStartOffset());
395 int caretCol
= caretMarker
.getStartOffset() - StringUtil
.lineColToOffset(newText
, caretLine
, 0);
396 LogicalPosition pos
= new LogicalPosition(caretLine
, caretCol
);
397 editor
.getCaretModel().moveToLogicalPosition(pos
);
400 if (selStartMarker
!= null) {
401 editor
.getSelectionModel().setSelection(selStartMarker
.getStartOffset(), selEndMarker
.getStartOffset());
404 PsiDocumentManager
.getInstance(myProject
).commitAllDocuments();
407 protected void configure(String path
, String dataName
) throws Exception
{
408 super.configure(path
, dataName
);
410 myEditor
= createEditor(myFile
.getVirtualFile());
412 CodeInsightTestData data
= (CodeInsightTestData
) myTestDataBefore
;
414 LogicalPosition pos
= new LogicalPosition(data
.getLineNumber() - 1, data
.getColumnNumber() - 1);
415 myEditor
.getCaretModel().moveToLogicalPosition(pos
);
418 int selectionStart
= selectionEnd
= myEditor
.getCaretModel().getOffset();
420 if (data
.getSelectionStartColumnNumber() >= 0) {
421 selectionStart
= myEditor
.logicalPositionToOffset(new LogicalPosition(data
.getSelectionEndLineNumber() - 1, data
.getSelectionStartColumnNumber() - 1));
422 selectionEnd
= myEditor
.logicalPositionToOffset(new LogicalPosition(data
.getSelectionEndLineNumber() - 1, data
.getSelectionEndColumnNumber() - 1));
425 myEditor
.getSelectionModel().setSelection(selectionStart
, selectionEnd
);
428 protected void checkResultByFile(@NonNls String filePath
) throws Exception
{
429 checkResultByFile(filePath
, false);
432 protected void checkResultByFile(String filePath
, boolean stripTrailingSpaces
) throws Exception
{
433 getProject().getComponent(PostprocessReformattingAspect
.class).doPostponedFormatting();
434 if (stripTrailingSpaces
) {
435 ((DocumentEx
)myEditor
.getDocument()).stripTrailingSpaces(false);
438 PsiDocumentManager
.getInstance(myProject
).commitAllDocuments();
440 String fullPath
= getTestDataPath() + filePath
;
442 final VirtualFile vFile
= LocalFileSystem
.getInstance().findFileByPath(fullPath
.replace(File
.separatorChar
, '/'));
443 assertNotNull("Cannot find file " + fullPath
, vFile
);
444 String fileText
= StringUtil
.convertLineSeparators(VfsUtil
.loadText(vFile
));
445 Document document
= EditorFactory
.getInstance().createDocument(fileText
);
447 int caretIndex
= fileText
.indexOf(CARET_MARKER
);
448 int selStartIndex
= fileText
.indexOf(SELECTION_START_MARKER
);
449 int selEndIndex
= fileText
.indexOf(SELECTION_END_MARKER
);
451 final RangeMarker caretMarker
= caretIndex
>= 0 ? document
.createRangeMarker(caretIndex
, caretIndex
) : null;
452 final RangeMarker selStartMarker
= selStartIndex
>= 0 ? document
.createRangeMarker(selStartIndex
, selStartIndex
) : null;
453 final RangeMarker selEndMarker
= selEndIndex
>= 0 ? document
.createRangeMarker(selEndIndex
, selEndIndex
) : null;
455 if (caretMarker
!= null) {
456 document
.deleteString(caretMarker
.getStartOffset(), caretMarker
.getStartOffset() + CARET_MARKER
.length());
458 if (selStartMarker
!= null) {
459 document
.deleteString(selStartMarker
.getStartOffset(), selStartMarker
.getStartOffset() + SELECTION_START_MARKER
.length());
461 if (selEndMarker
!= null) {
462 document
.deleteString(selEndMarker
.getStartOffset(), selEndMarker
.getStartOffset() + SELECTION_END_MARKER
.length());
465 String newFileText
= document
.getText();
466 String newFileText1
= newFileText
;
467 if (stripTrailingSpaces
) {
468 Document document1
= EditorFactory
.getInstance().createDocument(newFileText
);
469 ((DocumentEx
)document1
).stripTrailingSpaces(false);
470 newFileText1
= document1
.getText();
473 if (myEditor
instanceof EditorWindow
) {
474 myEditor
= ((EditorWindow
)myEditor
).getDelegate();
475 myFile
= PsiDocumentManager
.getInstance(getProject()).getPsiFile(myEditor
.getDocument());
478 String text
= myFile
.getText();
479 text
= StringUtil
.convertLineSeparators(text
);
481 assertEquals("Text mismatch in file " + filePath
, newFileText1
, text
);
483 if (caretMarker
!= null) {
484 int caretLine
= StringUtil
.offsetToLineNumber(newFileText
, caretMarker
.getStartOffset());
485 int caretCol
= caretMarker
.getStartOffset() - StringUtil
.lineColToOffset(newFileText
, caretLine
, 0);
487 assertEquals("caretLine", caretLine
+ 1, myEditor
.getCaretModel().getLogicalPosition().line
+ 1);
488 assertEquals("caretColumn", caretCol
+ 1, myEditor
.getCaretModel().getLogicalPosition().column
+ 1);
491 if (selStartMarker
!= null && selEndMarker
!= null) {
492 int selStartLine
= StringUtil
.offsetToLineNumber(newFileText
, selStartMarker
.getStartOffset());
493 int selStartCol
= selStartMarker
.getStartOffset() - StringUtil
.lineColToOffset(newFileText
, selStartLine
, 0);
495 int selEndLine
= StringUtil
.offsetToLineNumber(newFileText
, selEndMarker
.getEndOffset());
496 int selEndCol
= selEndMarker
.getEndOffset() - StringUtil
.lineColToOffset(newFileText
, selEndLine
, 0);
498 assertEquals("selectionStartLine", selStartLine
+ 1,
499 StringUtil
.offsetToLineNumber(newFileText
, myEditor
.getSelectionModel().getSelectionStart()) + 1);
501 assertEquals("selectionStartCol", selStartCol
+ 1,
502 myEditor
.getSelectionModel().getSelectionStart() - StringUtil
.lineColToOffset(newFileText
, selStartLine
, 0) + 1);
504 assertEquals("selectionEndLine", selEndLine
+ 1,
505 StringUtil
.offsetToLineNumber(newFileText
, myEditor
.getSelectionModel().getSelectionEnd()) + 1);
507 assertEquals("selectionEndCol", selEndCol
+ 1,
508 myEditor
.getSelectionModel().getSelectionEnd() - StringUtil
.lineColToOffset(newFileText
, selEndLine
, 0) + 1);
511 assertTrue("has no selection", !myEditor
.getSelectionModel().hasSelection());
515 protected void checkResult(String dataName
) throws Exception
{
516 PsiDocumentManager
.getInstance(myProject
).commitAllDocuments();
517 super.checkResult(dataName
);
519 CodeInsightTestData data
= (CodeInsightTestData
) myTestDataAfter
;
521 if (data
.getColumnNumber() >= 0) {
522 assertEquals(dataName
+ ":caretColumn", data
.getColumnNumber(), myEditor
.getCaretModel().getLogicalPosition().column
+ 1);
524 if (data
.getLineNumber() >= 0) {
525 assertEquals(dataName
+ ":caretLine", data
.getLineNumber(), myEditor
.getCaretModel().getLogicalPosition().line
+ 1);
528 int selectionStart
= myEditor
.getSelectionModel().getSelectionStart();
529 int selectionEnd
= myEditor
.getSelectionModel().getSelectionEnd();
530 LogicalPosition startPosition
= myEditor
.offsetToLogicalPosition(selectionStart
);
531 LogicalPosition endPosition
= myEditor
.offsetToLogicalPosition(selectionEnd
);
533 if (data
.getSelectionStartColumnNumber() >= 0) {
534 assertEquals(dataName
+ ":selectionStartColumn", data
.getSelectionStartColumnNumber(), startPosition
.column
+ 1);
536 if (data
.getSelectionStartLineNumber() >= 0) {
537 assertEquals(dataName
+ ":selectionStartLine", data
.getSelectionStartLineNumber(), startPosition
.line
+ 1);
539 if (data
.getSelectionEndColumnNumber() >= 0) {
540 assertEquals(dataName
+ ":selectionEndColumn", data
.getSelectionEndColumnNumber(), endPosition
.column
+ 1);
542 if (data
.getSelectionEndLineNumber() >= 0) {
543 assertEquals(dataName
+ ":selectionEndLine", data
.getSelectionEndLineNumber(), endPosition
.line
+ 1);
547 public Object
getData(String dataId
) {
548 return dataId
.equals(DataConstants
.EDITOR
) ? myEditor
: super.getData(dataId
);
551 protected VirtualFile
getVirtualFile(@NonNls String filePath
) {
552 String fullPath
= getTestDataPath() + filePath
;
554 final VirtualFile vFile
= LocalFileSystem
.getInstance().findFileByPath(fullPath
.replace(File
.separatorChar
, '/'));
555 assertNotNull("file " + fullPath
+ " not found", vFile
);
559 protected String
getTestRoot(){
560 return FileUtil
.toSystemIndependentName(getTestDataPath());
563 public Editor
getEditor() {
567 protected void type(char c
) {
568 EditorActionManager actionManager
= EditorActionManager
.getInstance();
569 TypedAction action
= actionManager
.getTypedAction();
570 action
.actionPerformed(getEditor(), c
, DataManager
.getInstance().getDataContext());
573 protected void type(@NonNls String s
) {
574 for (char c
: s
.toCharArray()) {
579 protected void backspace() {
580 EditorActionManager actionManager
= EditorActionManager
.getInstance();
581 EditorActionHandler actionHandler
= actionManager
.getActionHandler(IdeActions
.ACTION_EDITOR_BACKSPACE
);
583 actionHandler
.execute(getEditor(), DataManager
.getInstance().getDataContext());
586 protected void ctrlShiftF7() {
587 HighlightUsagesHandler
.invoke(getProject(), getEditor(), getFile());
590 public static void ctrlW() {
591 AnAction action
= ActionManager
.getInstance().getAction(IdeActions
.ACTION_EDITOR_SELECT_WORD_AT_CARET
);
592 AnActionEvent event
= new AnActionEvent(null, DataManager
.getInstance().getDataContext(), "", action
.getTemplatePresentation(),
593 ActionManager
.getInstance(), 0);
594 event
.setInjectedContext(true);
595 action
.actionPerformed(event
);