This commit is contained in:
Alexey Kudravtsev
2014-07-23 14:41:50 +04:00
parent 6194f4d66c
commit d86ae6c6f0
4 changed files with 31 additions and 23 deletions
@@ -463,7 +463,7 @@ public interface CodeInsightTestFixture extends IdeaProjectTestFixture {
void type(final char c);
void type(final String s);
void type(@NotNull String s);
void performEditorAction(@NotNull String actionId);
@@ -1,5 +1,5 @@
/*
* Copyright 2000-2009 JetBrains s.r.o.
* Copyright 2000-2014 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.
@@ -17,6 +17,7 @@ package com.intellij.testFramework.fixtures;
import com.intellij.psi.PsiFile;
import org.jetbrains.annotations.NonNls;
import org.jetbrains.annotations.NotNull;
import java.io.IOException;
@@ -25,5 +26,5 @@ import java.io.IOException;
* @author peter
*/
public interface HeavyIdeaTestFixture extends IdeaProjectTestFixture {
PsiFile addFileToProject(@NonNls String rootPath, @NonNls String relativePath, @NonNls String fileText) throws IOException;
PsiFile addFileToProject(@NonNls @NotNull String rootPath, @NonNls @NotNull String relativePath, @NonNls @NotNull String fileText) throws IOException;
}
@@ -368,7 +368,7 @@ public class CodeInsightTestFixtureImpl extends BaseFixture implements CodeInsig
private long collectAndCheckHighlightings(final boolean checkWarnings,
final boolean checkInfos,
final boolean checkWeakWarnings,
final VirtualFile[] files) {
@NotNull VirtualFile[] files) {
final List<Trinity<PsiFile, Editor, ExpectedHighlightingData>> datas =
ContainerUtil.map2List(files, new Function<VirtualFile, Trinity<PsiFile, Editor, ExpectedHighlightingData>>() {
@Override
@@ -786,12 +786,13 @@ public class CodeInsightTestFixtureImpl extends BaseFixture implements CodeInsig
});
}
@NotNull
private DataContext getEditorDataContext() {
return ((EditorEx)myEditor).getDataContext();
}
@Override
public void type(String s) {
public void type(@NotNull String s) {
for (int i = 0; i < s.length(); i++) {
type(s.charAt(i));
}
@@ -803,7 +804,7 @@ public class CodeInsightTestFixtureImpl extends BaseFixture implements CodeInsig
_performEditorAction(actionId);
}
private boolean _performEditorAction(String actionId) {
private boolean _performEditorAction(@NotNull String actionId) {
final DataContext dataContext = getEditorDataContext();
final ActionManagerEx managerEx = ActionManagerEx.getInstanceEx();
@@ -947,7 +948,7 @@ public class CodeInsightTestFixtureImpl extends BaseFixture implements CodeInsig
private static void addGutterIconRenderer(final GutterMark renderer,
final int offset,
SortedMap<Integer, List<GutterMark>> result) {
@NotNull SortedMap<Integer, List<GutterMark>> result) {
if (renderer == null) return;
List<GutterMark> renderers = result.get(offset);
@@ -964,7 +965,7 @@ public class CodeInsightTestFixtureImpl extends BaseFixture implements CodeInsig
return addFileToProject(getTempDirPath(), relativePath, fileText);
}
protected PsiFile addFileToProject(final String rootPath, final String relativePath, final String fileText) {
protected PsiFile addFileToProject(@NotNull final String rootPath, @NotNull final String relativePath, @NotNull final String fileText) {
return new WriteCommandAction<PsiFile>(getProject()) {
@Override
protected void run(@NotNull Result<PsiFile> result) throws Throwable {
@@ -1376,7 +1377,7 @@ public class CodeInsightTestFixtureImpl extends BaseFixture implements CodeInsig
return PsiDocumentManager.getInstance(getProject()).getDocument(file);
}
private PsiFile configureByFileInner(@NonNls String filePath) {
private PsiFile configureByFileInner(@NonNls @NotNull String filePath) {
assertInitialized();
final VirtualFile file = copyFileToProject(filePath);
return configureByFileInner(file);
@@ -1400,7 +1401,7 @@ public class CodeInsightTestFixtureImpl extends BaseFixture implements CodeInsig
return configureInner(copy, SelectionAndCaretMarkupLoader.fromFile(copy));
}
private PsiFile configureInner(@NotNull final VirtualFile copy, final SelectionAndCaretMarkupLoader loader) {
private PsiFile configureInner(@NotNull final VirtualFile copy, @NotNull final SelectionAndCaretMarkupLoader loader) {
assertInitialized();
new WriteCommandAction.Simple(getProject()) {
@Override
@@ -1458,7 +1459,7 @@ public class CodeInsightTestFixtureImpl extends BaseFixture implements CodeInsig
}
@Nullable
private Editor createEditor(VirtualFile file) {
private Editor createEditor(@NotNull VirtualFile file) {
final Project project = getProject();
final FileEditorManager instance = FileEditorManager.getInstance(project);
if (file.getFileType().isBinary()) {
@@ -1509,7 +1510,7 @@ public class CodeInsightTestFixtureImpl extends BaseFixture implements CodeInsig
return elapsed;
}
private static void removeDuplicatedRangesForInjected(List<HighlightInfo> infos) {
private static void removeDuplicatedRangesForInjected(@NotNull List<HighlightInfo> infos) {
Collections.sort(infos, new Comparator<HighlightInfo>() {
@Override
public int compare(HighlightInfo o1, HighlightInfo o2) {
@@ -1581,7 +1582,7 @@ public class CodeInsightTestFixtureImpl extends BaseFixture implements CodeInsig
throw exception;
}
public static void ensureIndexesUpToDate(Project project) {
public static void ensureIndexesUpToDate(@NotNull Project project) {
if (!DumbService.isDumb(project)) {
FileBasedIndex.getInstance().ensureUpToDate(StubUpdatingIndex.INDEX_ID, project, null);
FileBasedIndex.getInstance().ensureUpToDate(TodoIndex.NAME, project, null);
@@ -1624,6 +1625,7 @@ public class CodeInsightTestFixtureImpl extends BaseFixture implements CodeInsig
});
}
@NotNull
public static List<IntentionAction> getAvailableIntentions(@NotNull final Editor editor, @NotNull final PsiFile file) {
return ApplicationManager.getApplication().runReadAction(new Computable<List<IntentionAction>>() {
@Override
@@ -1633,6 +1635,7 @@ public class CodeInsightTestFixtureImpl extends BaseFixture implements CodeInsig
});
}
@NotNull
private static List<IntentionAction> doGetAvailableIntentions(@NotNull Editor editor, @NotNull PsiFile file) {
ShowIntentionsPass.IntentionsInfo intentions = new ShowIntentionsPass.IntentionsInfo();
ShowIntentionsPass.getActionsToShow(editor, file, intentions, -1);
@@ -1680,15 +1683,17 @@ public class CodeInsightTestFixtureImpl extends BaseFixture implements CodeInsig
myJavaFilesFilter.allowTreeAccessForAllFiles();
}
static class SelectionAndCaretMarkupLoader {
private static class SelectionAndCaretMarkupLoader {
final String filePath;
final String newFileText;
final EditorTestUtil.CaretAndSelectionState caretState;
static SelectionAndCaretMarkupLoader fromFile(String path, String charset) throws IOException {
@NotNull
static SelectionAndCaretMarkupLoader fromFile(@NotNull String path, String charset) throws IOException {
return new SelectionAndCaretMarkupLoader(StringUtil.convertLineSeparators(FileUtil.loadFile(new File(path), charset)), path);
}
@NotNull
static SelectionAndCaretMarkupLoader fromFile(@NotNull VirtualFile file) {
final String text;
try {
@@ -1700,11 +1705,12 @@ public class CodeInsightTestFixtureImpl extends BaseFixture implements CodeInsig
return new SelectionAndCaretMarkupLoader(StringUtil.convertLineSeparators(text), file.getPath());
}
static SelectionAndCaretMarkupLoader fromText(String text) {
@NotNull
static SelectionAndCaretMarkupLoader fromText(@NotNull String text) {
return new SelectionAndCaretMarkupLoader(text, null);
}
private SelectionAndCaretMarkupLoader(String fileText, String filePath) {
private SelectionAndCaretMarkupLoader(@NotNull String fileText, String filePath) {
this.filePath = filePath;
final Document document = EditorFactory.getInstance().createDocument(fileText);
caretState = EditorTestUtil.extractCaretAndSelectionMarkers(document);
@@ -1734,11 +1740,10 @@ public class CodeInsightTestFixtureImpl extends BaseFixture implements CodeInsig
}
@SuppressWarnings("ConstantConditions")
private void checkResult(@NotNull String expectedFile,
final boolean stripTrailingSpaces,
final SelectionAndCaretMarkupLoader loader,
String actualText) {
@NotNull SelectionAndCaretMarkupLoader loader,
@NotNull String actualText) {
assertInitialized();
Project project = getProject();
Editor editor = getEditor();
@@ -1772,7 +1777,8 @@ public class CodeInsightTestFixtureImpl extends BaseFixture implements CodeInsig
EditorTestUtil.verifyCaretAndSelectionState(editor, loader.caretState, expectedFile);
}
private String stripTrailingSpaces(String actualText) {
@NotNull
private String stripTrailingSpaces(@NotNull String actualText) {
final Document document = EditorFactory.getInstance().createDocument(actualText);
((DocumentImpl)document).stripTrailingSpaces(getProject());
actualText = document.getText();
@@ -1823,6 +1829,7 @@ public class CodeInsightTestFixtureImpl extends BaseFixture implements CodeInsig
}
}
@NotNull
public String getFoldingDescription(boolean withCollapseStatus) {
CodeFoldingManager.getInstance(getProject()).buildInitialFoldings(myEditor);
@@ -1848,7 +1855,7 @@ public class CodeInsightTestFixtureImpl extends BaseFixture implements CodeInsig
return result.toString();
}
private void testFoldingRegions(final String verificationFileName, boolean doCheckCollapseStatus) {
private void testFoldingRegions(@NotNull String verificationFileName, boolean doCheckCollapseStatus) {
String expectedContent;
try {
expectedContent = FileUtil.loadFile(new File(verificationFileName));
@@ -235,7 +235,7 @@ class HeavyIdeaTestFixtureImpl extends BaseFixture implements HeavyIdeaTestFixtu
}
@Override
public PsiFile addFileToProject(@NonNls String rootPath, @NonNls final String relativePath, @NonNls final String fileText) throws IOException {
public PsiFile addFileToProject(@NotNull @NonNls String rootPath, @NotNull @NonNls final String relativePath, @NotNull @NonNls final String fileText) throws IOException {
final VirtualFile dir = VfsUtil.createDirectories(rootPath + "/" + PathUtil.getParentPath(relativePath));
final VirtualFile[] virtualFile = new VirtualFile[1];