2 * Copyright 2000-2007 JetBrains s.r.o.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
17 package com
.intellij
.testFramework
.fixtures
;
19 import com
.intellij
.codeInsight
.intention
.IntentionAction
;
20 import com
.intellij
.codeInsight
.lookup
.LookupElement
;
21 import com
.intellij
.codeInspection
.InspectionToolProvider
;
22 import com
.intellij
.codeInspection
.LocalInspectionTool
;
23 import com
.intellij
.openapi
.editor
.Document
;
24 import com
.intellij
.openapi
.editor
.Editor
;
25 import com
.intellij
.openapi
.editor
.markup
.GutterIconRenderer
;
26 import com
.intellij
.openapi
.fileTypes
.FileType
;
27 import com
.intellij
.openapi
.module
.Module
;
28 import com
.intellij
.openapi
.project
.Project
;
29 import com
.intellij
.openapi
.vfs
.VirtualFile
;
30 import com
.intellij
.psi
.*;
31 import org
.jetbrains
.annotations
.NonNls
;
32 import org
.jetbrains
.annotations
.NotNull
;
33 import org
.jetbrains
.annotations
.Nullable
;
35 import java
.io
.IOException
;
36 import java
.util
.Collection
;
37 import java
.util
.List
;
41 * @see IdeaTestFixtureFactory#createCodeInsightFixture(IdeaProjectTestFixture)
43 * @author Dmitry Avdeev
45 public interface CodeInsightTestFixture
extends IdeaTestFixture
{
47 @NonNls String CARET_MARKER
= "<caret>";
48 @NonNls String SELECTION_START_MARKER
= "<selection>";
49 @NonNls String SELECTION_END_MARKER
= "</selection>";
51 @NonNls String ERROR_MARKER
= "error";
52 @NonNls String WARNING_MARKER
= "warning";
53 @NonNls String INFORMATION_MARKER
= "weak_warning";
54 @NonNls String SERVER_PROBLEM_MARKER
= "server_problem";
55 @NonNls String INFO_MARKER
= "info";
56 @NonNls String END_LINE_HIGHLIGHT_MARKER
= "EOLError";
57 @NonNls String END_LINE_WARNING_MARKER
= "EOLWarning";
67 void setTestDataPath(@NonNls String dataPath
);
69 String
getTempDirPath();
71 TempDirTestFixture
getTempDirFixture();
73 VirtualFile
copyFileToProject(@NonNls String sourceFilePath
, @NonNls String targetPath
) throws IOException
;
75 VirtualFile
copyDirectoryToProject(@NonNls String sourceFilePath
, @NonNls String targetPath
) throws IOException
;
77 VirtualFile
copyFileToProject(@NonNls String sourceFilePath
) throws IOException
;
80 * Enables inspections for highlighting tests.
81 * Should be called BEFORE {@link #setUp()}.
83 * @param inspections inspections to be enabled in highliting tests.
84 * @see #enableInspections(com.intellij.codeInspection.InspectionToolProvider[])
86 void enableInspections(LocalInspectionTool
... inspections
);
88 void enableInspections(Class
<?
extends LocalInspectionTool
>... inspections
);
90 void disableInspections(LocalInspectionTool
... inspections
);
93 * Enable all inspections provided by given providers.
95 * @param providers providers to be enabled.
96 * @see #enableInspections(com.intellij.codeInspection.LocalInspectionTool[])
98 void enableInspections(InspectionToolProvider
... providers
);
101 * Runs highliting test for the given files.
102 * Checks for {@link #ERROR_MARKER} markers by default.
104 * @param checkWarnings enables {@link #WARNING_MARKER} support.
105 * @param checkInfos enables {@link #INFO_MARKER} support.
106 * @param checkWeakWarnings enables {@link #INFORMATION_MARKER} support.
107 * @param filePaths the first file is tested only; the others are just copied along the first.
109 * @return highlighting duration in milliseconds.
110 * @throws Throwable any exception thrown during highlighting.
112 long testHighlighting(boolean checkWarnings
, boolean checkInfos
, boolean checkWeakWarnings
, @NonNls String
... filePaths
) throws Throwable
;
115 * Check highlighting of file already loaded by configure* methods
116 * @param checkWarnings
118 * @param checkWeakWarnings
122 long checkHighlighting(boolean checkWarnings
, boolean checkInfos
, boolean checkWeakWarnings
) throws Throwable
;
124 long checkHighlighting() throws Throwable
;
127 * Runs highliting test for the given files.
128 * The same as {@link #testHighlighting(boolean, boolean, boolean, String...)} with all options set.
130 * @param filePaths the first file is tested only; the others are just copied along with the first.
132 * @return highlighting duration in milliseconds
133 * @throws Throwable any exception thrown during highlighting
135 long testHighlighting(@NonNls String
... filePaths
) throws Throwable
;
137 long testHighlighting(boolean checkWarnings
, boolean checkInfos
, boolean checkWeakWarnings
, VirtualFile file
) throws Throwable
;
139 * Finds the reference in position marked by {@link #CARET_MARKER}.
142 * @return null if no reference found.
143 * @throws Throwable any exception.
145 * @see #getReferenceAtCaretPositionWithAssertion(String...)
148 PsiReference
getReferenceAtCaretPosition(@NonNls String
... filePaths
) throws Throwable
;
151 * Finds the reference in position marked by {@link #CARET_MARKER}.
152 * Asserts that the reference exists.
155 * @return founded reference
156 * @throws Throwable any exception
158 * @see #getReferenceAtCaretPosition(String...)
161 PsiReference
getReferenceAtCaretPositionWithAssertion(@NonNls String
... filePaths
) throws Throwable
;
164 * Collects available intentions in the whole file or at caret position if {@link #CARET_MARKER} presents.
166 * @param filePaths the first file is tested only; the others are just copied along with the first.
167 * @return available intentions.
168 * @throws Throwable any exception.
171 List
<IntentionAction
> getAvailableIntentions(@NonNls String
... filePaths
) throws Throwable
;
174 List
<IntentionAction
> getAvailableIntentions() throws Throwable
;
176 IntentionAction
getAvailableIntention(final String intentionName
, final String
... filePaths
) throws Throwable
;
179 * Launches the given action. Use {@link #checkResultByFile(String)} to check the result.
181 * @param action the action to be launched.
182 * @throws Throwable any exception.
184 void launchAction(@NotNull IntentionAction action
) throws Throwable
;
186 void configureByFile(@NonNls String file
) throws Throwable
;
188 void configureByFiles(@NonNls String
... files
) throws Throwable
;
190 PsiFile
configureByText(FileType fileType
, @NonNls String text
) throws Throwable
;
193 * Compares current file against the given one.
195 * @param expectedFile file to check against.
196 * @throws Throwable any exception.
198 void checkResultByFile(@NonNls String expectedFile
) throws Throwable
;
201 * Compares two files.
203 * @param filePath file to be checked.
204 * @param expectedFile file to check against.
205 * @param ignoreWhitespaces set to true to ignore differences in whitespaces.
206 * @throws Throwable any exception.
208 void checkResultByFile(@NonNls String filePath
, @NonNls String expectedFile
, boolean ignoreWhitespaces
) throws Throwable
;
210 void testCompletion(@NonNls String
[] filesBefore
, @NonNls String fileAfter
) throws Throwable
;
213 * Runs basic completion in caret position in fileBefore.
214 * Implies that there is only one completion variant and it was inserted automatically, and checks the result file text with fileAfter
217 * @param additionalFiles
220 void testCompletion(@NonNls String fileBefore
, @NonNls String fileAfter
, final String
... additionalFiles
) throws Throwable
;
223 * Runs basic completion in caret position in fileBefore.
224 * Checks that lookup is shown and it contains items with given lookup strings
226 * @param items most probably will contain > 1 items
229 void testCompletionVariants(@NonNls String fileBefore
, @NonNls String
... items
) throws Throwable
;
232 * Launches renaming refactoring and checks the result.
234 * @param fileBefore original file path. Use {@link #CARET_MARKER} to mark the element to rename.
235 * @param fileAfter result file to be checked against.
236 * @param newName new name for the element.
237 * @param additionalFiles
238 * @throws Throwable any exception.
239 * @see #testRename(String, String, String, String[])
241 void testRename(@NonNls String fileBefore
, @NonNls String fileAfter
, @NonNls String newName
, final String
... additionalFiles
) throws Throwable
;
243 void testRename(String fileAfter
, String newName
) throws Throwable
;
245 PsiReference
[] testFindUsages(@NonNls String
... fileNames
) throws Throwable
;
247 void moveFile(@NonNls String filePath
, @NonNls String to
, final String
... additionalFiles
) throws Throwable
;
250 * Returns gutter renderer at the caret position.
251 * Use {@link #CARET_MARKER} to mark the element to check.
253 * @param filePath file path
254 * @return gutter renderer at the caret position.
255 * @throws Throwable any exception.
258 GutterIconRenderer
findGutter(@NonNls String filePath
) throws Throwable
;
260 PsiClass
addClass(@NotNull @NonNls final String classText
) throws IOException
;
262 PsiManager
getPsiManager();
264 @Nullable LookupElement
[] completeBasic();
266 void checkResult(final String text
) throws IOException
;
268 Document
getDocument(PsiFile file
);
270 void setFileContext(@Nullable PsiElement context
);
273 Collection
<GutterIconRenderer
> findAllGutters(String filePath
) throws Throwable
;
275 void type(final char c
);
277 void performEditorAction(String actionId
);
279 JavaPsiFacade
getJavaFacade();
281 int configureFromTempProjectFile(String filePath
) throws IOException
;
283 void configureFromExistingVirtualFile(VirtualFile f
) throws IOException
;
285 PsiFile
addFileToProject(@NonNls String relativePath
, @NonNls String fileText
) throws IOException
;
287 List
<String
> getCompletionVariants(String fileBefore
) throws Throwable
;
290 LookupElement
[] getLookupElements();