nicer enter key indentation handling after -> and before } in closures
[fedora-idea.git] / platform / testFramework / src / com / intellij / testFramework / fixtures / CodeInsightTestFixture.java
blobe58188cb71499c074aefaf0a3e2097392eafd399
1 /*
2 * Copyright 2000-2010 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.completion.CompletionType;
20 import com.intellij.codeInsight.intention.IntentionAction;
21 import com.intellij.codeInsight.lookup.LookupElement;
22 import com.intellij.codeInspection.InspectionProfileEntry;
23 import com.intellij.codeInspection.InspectionToolProvider;
24 import com.intellij.codeInspection.LocalInspectionTool;
25 import com.intellij.codeInspection.ex.InspectionTool;
26 import com.intellij.openapi.editor.Document;
27 import com.intellij.openapi.editor.Editor;
28 import com.intellij.openapi.editor.markup.GutterIconRenderer;
29 import com.intellij.openapi.fileTypes.FileType;
30 import com.intellij.openapi.vfs.VirtualFile;
31 import com.intellij.psi.PsiElement;
32 import com.intellij.psi.PsiFile;
33 import com.intellij.psi.PsiManager;
34 import com.intellij.psi.PsiReference;
35 import com.intellij.testFramework.TestDataFile;
36 import com.intellij.usageView.UsageInfo;
37 import org.jetbrains.annotations.NonNls;
38 import org.jetbrains.annotations.NotNull;
39 import org.jetbrains.annotations.Nullable;
41 import java.io.IOException;
42 import java.util.Collection;
43 import java.util.List;
45 /**
47 * @see IdeaTestFixtureFactory#createCodeInsightFixture(IdeaProjectTestFixture)
49 * @author Dmitry Avdeev
51 public interface CodeInsightTestFixture extends IdeaProjectTestFixture {
53 @NonNls String CARET_MARKER = "<caret>";
54 @NonNls String SELECTION_START_MARKER = "<selection>";
55 @NonNls String SELECTION_END_MARKER = "</selection>";
57 @NonNls String ERROR_MARKER = "error";
58 @NonNls String WARNING_MARKER = "warning";
59 @NonNls String INFORMATION_MARKER = "weak_warning";
60 @NonNls String SERVER_PROBLEM_MARKER = "server_problem";
61 @NonNls String INFO_MARKER = "info";
62 @NonNls String END_LINE_HIGHLIGHT_MARKER = "EOLError";
63 @NonNls String END_LINE_WARNING_MARKER = "EOLWarning";
65 Editor getEditor();
67 PsiFile getFile();
69 void setTestDataPath(@NonNls String dataPath);
71 String getTestDataPath();
73 String getTempDirPath();
75 TempDirTestFixture getTempDirFixture();
77 VirtualFile copyFileToProject(@NonNls String sourceFilePath, @NonNls String targetPath) throws IOException;
79 VirtualFile copyDirectoryToProject(@NonNls String sourceFilePath, @NonNls String targetPath) throws IOException;
81 VirtualFile copyFileToProject(@NonNls String sourceFilePath) throws IOException;
83 /**
84 * Enables inspections for highlighting tests.
85 * Should be called BEFORE {@link #setUp()}. And do not forget to call {@link #tearDown()}
87 * @param inspections inspections to be enabled in highliting tests.
88 * @see #enableInspections(com.intellij.codeInspection.InspectionToolProvider[])
90 void enableInspections(InspectionProfileEntry... inspections);
92 void enableInspections(Class<? extends LocalInspectionTool>... inspections);
94 void disableInspections(InspectionProfileEntry... inspections);
96 /**
97 * Enable all inspections provided by given providers.
99 * @param providers providers to be enabled.
100 * @see #enableInspections(com.intellij.codeInspection.LocalInspectionTool[])
102 void enableInspections(InspectionToolProvider... providers);
105 * Runs highliting test for the given files.
106 * Checks for {@link #ERROR_MARKER} markers by default.
108 * @param checkWarnings enables {@link #WARNING_MARKER} support.
109 * @param checkInfos enables {@link #INFO_MARKER} support.
110 * @param checkWeakWarnings enables {@link #INFORMATION_MARKER} support.
111 * @param filePaths the first file is tested only; the others are just copied along the first.
113 * @return highlighting duration in milliseconds.
114 * @throws Exception any exception thrown during highlighting.
116 long testHighlighting(boolean checkWarnings, boolean checkInfos, boolean checkWeakWarnings, @TestDataFile @NonNls String... filePaths) throws Exception;
118 long testHighlightingAllFiles(boolean checkWarnings, boolean checkInfos, boolean checkWeakWarnings, @TestDataFile @NonNls String... filePaths) throws Exception;
120 long testHighlightingAllFiles(boolean checkWarnings, boolean checkInfos, boolean checkWeakWarnings, @NonNls VirtualFile... files) throws Exception;
123 * Check highlighting of file already loaded by configure* methods
124 * @param checkWarnings
125 * @param checkInfos
126 * @param checkWeakWarnings
127 * @return
128 * @throws Exception
130 long checkHighlighting(boolean checkWarnings, boolean checkInfos, boolean checkWeakWarnings) throws Exception;
132 long checkHighlighting() throws Exception;
135 * Runs highlighting test for the given files.
136 * The same as {@link #testHighlighting(boolean, boolean, boolean, String...)} with all options set.
138 * @param filePaths the first file is tested only; the others are just copied along with the first.
140 * @return highlighting duration in milliseconds
141 * @throws Exception any exception thrown during highlighting
143 long testHighlighting(@NonNls String... filePaths) throws Exception;
145 long testHighlighting(boolean checkWarnings, boolean checkInfos, boolean checkWeakWarnings, VirtualFile file) throws Exception;
147 void testInspection(String testDir, InspectionTool tool) throws Exception;
150 * Finds the reference in position marked by {@link #CARET_MARKER}.
152 * @param filePaths
153 * @return null if no reference found.
154 * @throws Exception any exception.
156 * @see #getReferenceAtCaretPositionWithAssertion(String...)
158 @Nullable
159 PsiReference getReferenceAtCaretPosition(@NonNls String... filePaths) throws Exception;
162 * Finds the reference in position marked by {@link #CARET_MARKER}.
163 * Asserts that the reference exists.
165 * @param filePaths
166 * @return founded reference
167 * @throws Exception any exception
169 * @see #getReferenceAtCaretPosition(String...)
171 @NotNull
172 PsiReference getReferenceAtCaretPositionWithAssertion(@NonNls String... filePaths) throws Exception;
175 * Collects available intentions in the whole file or at caret position if {@link #CARET_MARKER} presents.
177 * @param filePaths the first file is tested only; the others are just copied along with the first.
178 * @return available intentions.
179 * @throws Exception any exception.
181 @NotNull
182 List<IntentionAction> getAvailableIntentions(@NonNls String... filePaths) throws Exception;
184 @NotNull
185 List<IntentionAction> getAvailableIntentions() throws Exception;
188 * Returns all intentions whose text contains hint
189 * @param hint
190 * @return
191 * @throws Exception
193 List<IntentionAction> filterAvailableIntentions(@NotNull String hint) throws Exception;
195 IntentionAction findSingleIntention(@NotNull String hint) throws Exception;
197 IntentionAction getAvailableIntention(final String intentionName, final String... filePaths) throws Exception;
200 * Launches the given action. Use {@link #checkResultByFile(String)} to check the result.
202 * @param action the action to be launched.
203 * @throws Exception any exception.
205 void launchAction(@NotNull IntentionAction action) throws Exception;
207 void configureByFile(@TestDataFile @NonNls String file) throws Exception;
209 void configureByFiles(@NonNls String... files) throws Exception;
211 PsiFile configureByText(FileType fileType, @NonNls String text) throws IOException;
213 PsiFile configureByText(String fileName, @NonNls String text) throws IOException;
216 * Compares current file against the given one.
218 * @param expectedFile file to check against.
219 * @throws Exception any exception.
221 void checkResultByFile(@TestDataFile @NonNls String expectedFile) throws Exception;
223 void checkResultByFile(@TestDataFile @NonNls String expectedFile, boolean ignoreTrailingWhitespaces) throws Exception;
226 * Compares two files.
228 * @param filePath file to be checked.
229 * @param expectedFile file to check against.
230 * @param ignoreTrailingWhitespaces set to true to ignore differences in whitespaces.
231 * @throws Exception any exception.
233 void checkResultByFile(@NonNls String filePath, @TestDataFile @NonNls String expectedFile, boolean ignoreTrailingWhitespaces) throws Exception;
235 void testCompletion(@NonNls String[] filesBefore, @TestDataFile @NonNls String fileAfter) throws Exception;
238 * Runs basic completion in caret position in fileBefore.
239 * Implies that there is only one completion variant and it was inserted automatically, and checks the result file text with fileAfter
240 * @param fileBefore
241 * @param fileAfter
242 * @param additionalFiles
243 * @throws Exception
245 void testCompletion(@TestDataFile @NonNls String fileBefore, @TestDataFile @NonNls String fileAfter, final String... additionalFiles) throws Exception;
248 * Runs basic completion in caret position in fileBefore.
249 * Checks that lookup is shown and it contains items with given lookup strings
250 * @param fileBefore
251 * @param items most probably will contain > 1 items
252 * @throws Exception
254 void testCompletionVariants(@TestDataFile @NonNls String fileBefore, @NonNls String... items) throws Exception;
257 * Launches renaming refactoring and checks the result.
259 * @param fileBefore original file path. Use {@link #CARET_MARKER} to mark the element to rename.
260 * @param fileAfter result file to be checked against.
261 * @param newName new name for the element.
262 * @param additionalFiles
263 * @throws Exception any exception.
264 * @see #testRename(String, String, String, String[])
266 void testRename(@TestDataFile @NonNls String fileBefore,
267 @TestDataFile @NonNls String fileAfter, @NonNls String newName, final String... additionalFiles) throws Exception;
269 void testRename(String fileAfter, String newName) throws Exception;
271 Collection<UsageInfo> testFindUsages(@NonNls String... fileNames) throws Exception;
273 Collection<UsageInfo> findUsages(final PsiElement to) throws Exception;
275 void moveFile(@NonNls String filePath, @NonNls String to, final String... additionalFiles) throws Exception;
278 * Returns gutter renderer at the caret position.
279 * Use {@link #CARET_MARKER} to mark the element to check.
281 * @param filePath file path
282 * @return gutter renderer at the caret position.
283 * @throws Exception any exception.
285 @Nullable
286 GutterIconRenderer findGutter(@NonNls String filePath) throws Exception;
288 PsiManager getPsiManager();
290 @Nullable LookupElement[] completeBasic();
292 @Nullable LookupElement[] complete(CompletionType type);
294 void checkResult(final String text) throws IOException;
296 void checkResult(final String text, boolean stripTrailingSpaces) throws IOException;
298 Document getDocument(PsiFile file);
300 void setFileContext(@Nullable PsiElement context);
302 @NotNull
303 Collection<GutterIconRenderer> findAllGutters(String filePath) throws Exception;
305 void type(final char c);
307 void performEditorAction(String actionId);
309 int configureFromTempProjectFile(String filePath) throws IOException;
311 void configureFromExistingVirtualFile(VirtualFile f) throws IOException;
313 PsiFile addFileToProject(@NonNls String relativePath, @NonNls String fileText) throws IOException;
315 List<String> getCompletionVariants(String... filesBefore) throws Exception;
317 @Nullable
318 LookupElement[] getLookupElements();
320 VirtualFile findFileInTempDir(String filePath);
322 @Nullable
323 List<String> getLookupElementStrings();
325 void renameElementAtCaret(String newName) throws Exception;
327 void renameElement(PsiElement element, String newName) throws Exception;
329 void allowTreeAccessForFile(VirtualFile file);
331 void allowTreeAccessForAllFiles();