From b9db8496a3bf7faafe258a5769c822377c4346ab Mon Sep 17 00:00:00 2001 From: Roman Shevchenko Date: Wed, 9 Dec 2015 15:41:20 +0100 Subject: [PATCH] [test framework] cleaner behavior of CodeInsightTestFixture.copyFileToProject() --- .../ExpectedHighlightingData.java | 203 +++++++++--------- .../fixtures/CodeInsightTestFixture.java | 115 +++++----- .../fixtures/TempDirTestFixture.java | 9 +- .../impl/CodeInsightTestFixtureImpl.java | 156 ++++++-------- .../impl/LightTempDirTestFixtureImpl.java | 65 ++---- .../fixtures/impl/TempDirTestFixtureImpl.java | 71 +++--- .../SpellCheckingEditorCustomizationTest.java | 5 +- 7 files changed, 263 insertions(+), 361 deletions(-) diff --git a/platform/testFramework/src/com/intellij/testFramework/ExpectedHighlightingData.java b/platform/testFramework/src/com/intellij/testFramework/ExpectedHighlightingData.java index 58a076c503ea..e3d99c685786 100644 --- a/platform/testFramework/src/com/intellij/testFramework/ExpectedHighlightingData.java +++ b/platform/testFramework/src/com/intellij/testFramework/ExpectedHighlightingData.java @@ -38,13 +38,13 @@ import com.intellij.openapi.vfs.VirtualFile; import com.intellij.psi.PsiElement; import com.intellij.psi.PsiFile; import com.intellij.rt.execution.junit.FileComparisonFailure; +import com.intellij.testFramework.fixtures.CodeInsightTestFixture; import com.intellij.util.ConstantFunction; import com.intellij.util.Function; import com.intellij.util.NullableFunction; import com.intellij.util.containers.ContainerUtil; import gnu.trove.THashMap; import gnu.trove.THashSet; -import org.jetbrains.annotations.NonNls; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; import org.junit.Assert; @@ -62,20 +62,16 @@ import java.util.regex.Pattern; public class ExpectedHighlightingData { private static final Logger LOG = Logger.getInstance("#com.intellij.testFramework.ExpectedHighlightingData"); - @NonNls private static final String ERROR_MARKER = "error"; - @NonNls private static final String WARNING_MARKER = "warning"; - @NonNls private static final String WEAK_WARNING_MARKER = "weak_warning"; - @NonNls private static final String INFO_MARKER = "info"; - @NonNls private static final String END_LINE_HIGHLIGHT_MARKER = "EOLError"; - @NonNls private static final String END_LINE_WARNING_MARKER = "EOLWarning"; - @NonNls private static final String LINE_MARKER = "lineMarker"; - - @NotNull private final Document myDocument; - private final PsiFile myFile; - @NonNls private static final String ANY_TEXT = "*"; - private final String myText; - - private boolean myIgnoreExtraHighlighting; + private static final String ERROR_MARKER = CodeInsightTestFixture.ERROR_MARKER; + private static final String WARNING_MARKER = CodeInsightTestFixture.WARNING_MARKER; + private static final String WEAK_WARNING_MARKER = CodeInsightTestFixture.WEAK_WARNING_MARKER; + private static final String INFO_MARKER = CodeInsightTestFixture.INFO_MARKER; + private static final String END_LINE_HIGHLIGHT_MARKER = CodeInsightTestFixture.END_LINE_HIGHLIGHT_MARKER; + private static final String END_LINE_WARNING_MARKER = CodeInsightTestFixture.END_LINE_WARNING_MARKER; + private static final String INJECT_MARKER = "inject"; + private static final String SYMBOL_NAME_MARKER = "symbolName"; + private static final String LINE_MARKER = "lineMarker"; + private static final String ANY_TEXT = "*"; public static class ExpectedHighlightingSet { private final HighlightSeverity severity; @@ -87,79 +83,39 @@ public class ExpectedHighlightingData { this.severity = severity; this.endOfLine = endOfLine; this.enabled = enabled; - infos = new THashSet(); + this.infos = new THashSet(); } } - @SuppressWarnings("WeakerAccess") - protected final Map highlightingTypes; - private final Map lineMarkerInfos = new THashMap(); - public void init() { - new WriteCommandAction(null){ - @Override - protected void run(@NotNull Result result) throws Throwable { - extractExpectedLineMarkerSet(myDocument); - extractExpectedHighlightsSet(myDocument); - refreshLineMarkers(); - } - }.execute(); - } + private final Map myHighlightingTypes = new LinkedHashMap(); + private final Map myLineMarkerInfos = new THashMap(); + private final Document myDocument; + @SuppressWarnings("StatefulEp") private final PsiFile myFile; + private final String myText; + private boolean myIgnoreExtraHighlighting; public ExpectedHighlightingData(@NotNull Document document,boolean checkWarnings, boolean checkInfos) { this(document, checkWarnings, false, checkInfos); } - public ExpectedHighlightingData(@NotNull Document document, - boolean checkWarnings, - boolean checkWeakWarnings, - boolean checkInfos) { + public ExpectedHighlightingData(@NotNull Document document, boolean checkWarnings, boolean checkWeakWarnings, boolean checkInfos) { this(document, checkWarnings, checkWeakWarnings, checkInfos, null); } - public ExpectedHighlightingData(@NotNull final Document document, PsiFile file) { - myDocument = document; - myFile = file; - myText = document.getText(); - highlightingTypes = new LinkedHashMap(); - new WriteCommandAction.Simple(file == null ? null : file.getProject()) { - public void run() { - boolean checkWarnings = false; - boolean checkWeakWarnings = false; - boolean checkInfos = false; - - highlightingTypes.put(ERROR_MARKER, new ExpectedHighlightingSet(HighlightSeverity.ERROR, false, true)); - highlightingTypes.put(WARNING_MARKER, new ExpectedHighlightingSet(HighlightSeverity.WARNING, false, checkWarnings)); - highlightingTypes.put(WEAK_WARNING_MARKER, new ExpectedHighlightingSet(HighlightSeverity.WEAK_WARNING, false, checkWeakWarnings)); - highlightingTypes.put("inject", new ExpectedHighlightingSet(HighlightInfoType.INJECTED_FRAGMENT_SEVERITY, false, checkInfos)); - highlightingTypes.put(INFO_MARKER, new ExpectedHighlightingSet(HighlightSeverity.INFORMATION, false, checkInfos)); - highlightingTypes.put("symbolName", new ExpectedHighlightingSet(HighlightInfoType.SYMBOL_TYPE_SEVERITY, false, false)); - for (SeveritiesProvider provider : Extensions.getExtensions(SeveritiesProvider.EP_NAME)) { - for (HighlightInfoType type : provider.getSeveritiesHighlightInfoTypes()) { - final HighlightSeverity severity = type.getSeverity(null); - highlightingTypes.put(severity.getName(), new ExpectedHighlightingSet(severity, false, true)); - } - } - highlightingTypes.put(END_LINE_HIGHLIGHT_MARKER, new ExpectedHighlightingSet(HighlightSeverity.ERROR, true, true)); - highlightingTypes.put(END_LINE_WARNING_MARKER, new ExpectedHighlightingSet(HighlightSeverity.WARNING, true, checkWarnings)); - initAdditionalHighlightingTypes(); - } - }.execute().throwException(); - } - - public ExpectedHighlightingData(@NotNull final Document document, - final boolean checkWarnings, - final boolean checkWeakWarnings, - final boolean checkInfos, - @Nullable final PsiFile file) { + public ExpectedHighlightingData(@NotNull Document document, + boolean checkWarnings, + boolean checkWeakWarnings, + boolean checkInfos, + @Nullable PsiFile file) { this(document, checkWarnings, checkWeakWarnings, checkInfos, false, file); } - public ExpectedHighlightingData(@NotNull final Document document, - final boolean checkWarnings, - final boolean checkWeakWarnings, - final boolean checkInfos, - final boolean ignoreExtraHighlighting, - @Nullable final PsiFile file) { + public ExpectedHighlightingData(@NotNull Document document, + boolean checkWarnings, + boolean checkWeakWarnings, + boolean checkInfos, + boolean ignoreExtraHighlighting, + @Nullable PsiFile file) { this(document, file); myIgnoreExtraHighlighting = ignoreExtraHighlighting; if (checkWarnings) checkWarnings(); @@ -167,32 +123,74 @@ public class ExpectedHighlightingData { if (checkInfos) checkInfos(); } - public void checkWarnings() { - highlightingTypes.put(WARNING_MARKER, new ExpectedHighlightingSet(HighlightSeverity.WARNING, false, true)); - highlightingTypes.put(END_LINE_WARNING_MARKER, new ExpectedHighlightingSet(HighlightSeverity.WARNING, true, true)); + public ExpectedHighlightingData(@NotNull Document document, @Nullable PsiFile file) { + myDocument = document; + myFile = file; + myText = document.getText(); + registerHighlightingType(ERROR_MARKER, new ExpectedHighlightingSet(HighlightSeverity.ERROR, false, true)); + registerHighlightingType(WARNING_MARKER, new ExpectedHighlightingSet(HighlightSeverity.WARNING, false, false)); + registerHighlightingType(WEAK_WARNING_MARKER, new ExpectedHighlightingSet(HighlightSeverity.WEAK_WARNING, false, false)); + registerHighlightingType(INJECT_MARKER, new ExpectedHighlightingSet(HighlightInfoType.INJECTED_FRAGMENT_SEVERITY, false, false)); + registerHighlightingType(INFO_MARKER, new ExpectedHighlightingSet(HighlightSeverity.INFORMATION, false, false)); + registerHighlightingType(SYMBOL_NAME_MARKER, new ExpectedHighlightingSet(HighlightInfoType.SYMBOL_TYPE_SEVERITY, false, false)); + for (SeveritiesProvider provider : Extensions.getExtensions(SeveritiesProvider.EP_NAME)) { + for (HighlightInfoType type : provider.getSeveritiesHighlightInfoTypes()) { + HighlightSeverity severity = type.getSeverity(null); + registerHighlightingType(severity.getName(), new ExpectedHighlightingSet(severity, false, true)); + } + } + registerHighlightingType(END_LINE_HIGHLIGHT_MARKER, new ExpectedHighlightingSet(HighlightSeverity.ERROR, true, true)); + registerHighlightingType(END_LINE_WARNING_MARKER, new ExpectedHighlightingSet(HighlightSeverity.WARNING, true, false)); } + + public void init() { + new WriteCommandAction(null) { + @Override + protected void run(@NotNull Result result) { + extractExpectedLineMarkerSet(myDocument); + extractExpectedHighlightsSet(myDocument); + refreshLineMarkers(); + } + }.execute(); + } + + public void checkWarnings() { + registerHighlightingType(WARNING_MARKER, new ExpectedHighlightingSet(HighlightSeverity.WARNING, false, true)); + registerHighlightingType(END_LINE_WARNING_MARKER, new ExpectedHighlightingSet(HighlightSeverity.WARNING, true, true)); + } + public void checkWeakWarnings() { - highlightingTypes.put(WEAK_WARNING_MARKER, new ExpectedHighlightingSet(HighlightSeverity.WEAK_WARNING, false, true)); + registerHighlightingType(WEAK_WARNING_MARKER, new ExpectedHighlightingSet(HighlightSeverity.WEAK_WARNING, false, true)); } + public void checkInfos() { - highlightingTypes.put(INFO_MARKER, new ExpectedHighlightingSet(HighlightSeverity.INFORMATION, false, true)); - highlightingTypes.put("inject", new ExpectedHighlightingSet(HighlightInfoType.INJECTED_FRAGMENT_SEVERITY, false, true)); + registerHighlightingType(INFO_MARKER, new ExpectedHighlightingSet(HighlightSeverity.INFORMATION, false, true)); + registerHighlightingType(INJECT_MARKER, new ExpectedHighlightingSet(HighlightInfoType.INJECTED_FRAGMENT_SEVERITY, false, true)); } + public void checkSymbolNames() { - highlightingTypes.put("symbolName", new ExpectedHighlightingSet(HighlightInfoType.SYMBOL_TYPE_SEVERITY, false, true)); + registerHighlightingType(SYMBOL_NAME_MARKER, new ExpectedHighlightingSet(HighlightInfoType.SYMBOL_TYPE_SEVERITY, false, true)); + } + + public void registerHighlightingType(@NotNull String key, @NotNull ExpectedHighlightingSet highlightingSet) { + myHighlightingTypes.put(key, highlightingSet); } private void refreshLineMarkers() { - for (Map.Entry entry : lineMarkerInfos.entrySet()) { + for (Map.Entry entry : myLineMarkerInfos.entrySet()) { RangeMarker rangeMarker = entry.getKey(); int startOffset = rangeMarker.getStartOffset(); int endOffset = rangeMarker.getEndOffset(); - final LineMarkerInfo value = entry.getValue(); - LineMarkerInfo markerInfo = new LineMarkerInfo(value.getElement(), new TextRange(startOffset,endOffset), null, value.updatePass, new Function() { + LineMarkerInfo value = entry.getValue(); + PsiElement element = value.getElement(); + assert element != null : value; + TextRange range = new TextRange(startOffset, endOffset); + final String tooltip = value.getLineMarkerTooltip(); + LineMarkerInfo markerInfo = new LineMarkerInfo(element, range, null, value.updatePass, new Function() { @Override - public String fun(PsiElement psiElement) { - return value.getLineMarkerTooltip(); + public String fun(PsiElement e) { + return tooltip; } }, null, GutterIconRenderer.Alignment.RIGHT); entry.setValue(markerInfo); @@ -202,7 +200,7 @@ public class ExpectedHighlightingData { private void extractExpectedLineMarkerSet(Document document) { String text = document.getText(); - @NonNls String pat = ".*?((<" + LINE_MARKER + ")(?: descr=\"((?:[^\"\\\\]|\\\\\")*)\")?>)(.*)"; + String pat = ".*?((<" + LINE_MARKER + ")(?: descr=\"((?:[^\"\\\\]|\\\\\")*)\")?>)(.*)"; final Pattern p = Pattern.compile(pat, Pattern.DOTALL); final Pattern pat2 = Pattern.compile("(.*?)()(.*)", Pattern.DOTALL); @@ -228,16 +226,11 @@ public class ExpectedHighlightingData { new ConstantFunction(descr), null, GutterIconRenderer.Alignment.RIGHT); - lineMarkerInfos.put(document.createRangeMarker(startOffset, endOffset), markerInfo); + myLineMarkerInfos.put(document.createRangeMarker(startOffset, endOffset), markerInfo); text = document.getText(); } } - /** - * Override in order to register special highlighting - */ - protected void initAdditionalHighlightingTypes() {} - /** * remove highlights (bounded with ...) from test case file * @param document document to process @@ -245,7 +238,7 @@ public class ExpectedHighlightingData { private void extractExpectedHighlightsSet(final Document document) { final String text = document.getText(); - final Set markers = highlightingTypes.keySet(); + final Set markers = myHighlightingTypes.keySet(); final String typesRx = "(?:" + StringUtil.join(markers, ")|(?:") + ")"; final String openingTagRx = "<(" + typesRx + ")" + "(?:\\s+descr=\"((?:[^\"]|\\\\\"|\\\\\\\\\"|\\\\\\[|\\\\\\])*)\")?" + @@ -272,7 +265,7 @@ public class ExpectedHighlightingData { int groupIdx = 1; final String marker = matcher.group(groupIdx++); - @NonNls String descr = matcher.group(groupIdx++); + String descr = matcher.group(groupIdx++); final String typeString = matcher.group(groupIdx++); final String foregroundColor = matcher.group(groupIdx++); final String backgroundColor = matcher.group(groupIdx++); @@ -338,7 +331,7 @@ public class ExpectedHighlightingData { } } - final ExpectedHighlightingSet expectedHighlightingSet = highlightingTypes.get(marker); + final ExpectedHighlightingSet expectedHighlightingSet = myHighlightingTypes.get(marker); if (expectedHighlightingSet.enabled) { TextAttributesKey forcedTextAttributesKey = attrKey == null ? null : TextAttributesKey.createTextAttributesKey(attrKey); HighlightInfo.Builder builder = @@ -363,7 +356,7 @@ public class ExpectedHighlightingData { String failMessage = ""; for (LineMarkerInfo info : markerInfos) { - if (!containsLineMarker(info, lineMarkerInfos.values())) { + if (!containsLineMarker(info, myLineMarkerInfos.values())) { if (!failMessage.isEmpty()) failMessage += '\n'; failMessage += fileName + "Extra line marker highlighted " + rangeString(text, info.startOffset, info.endOffset) @@ -372,7 +365,7 @@ public class ExpectedHighlightingData { } } - for (LineMarkerInfo expectedLineMarker : lineMarkerInfos.values()) { + for (LineMarkerInfo expectedLineMarker : myLineMarkerInfos.values()) { if (!markerInfos.isEmpty() && !containsLineMarker(expectedLineMarker, markerInfos)) { if (!failMessage.isEmpty()) failMessage += '\n'; failMessage += fileName + "Line marker was not highlighted " + @@ -432,7 +425,7 @@ public class ExpectedHighlightingData { } } - final Collection expectedHighlights = highlightingTypes.values(); + final Collection expectedHighlights = myHighlightingTypes.values(); for (ExpectedHighlightingSet highlightingSet : reverseCollection(expectedHighlights)) { final Set expInfos = highlightingSet.infos; for (HighlightInfo expectedInfo : expInfos) { @@ -462,7 +455,7 @@ public class ExpectedHighlightingData { } private void compareTexts(Collection infos, String text, String failMessage, @Nullable String filePath) { - String actual = composeText(highlightingTypes, infos, text); + String actual = composeText(myHighlightingTypes, infos, text); if (filePath != null && !myText.equals(actual)) { // uncomment to overwrite, don't forget to revert on commit! //VfsTestUtil.overwriteTestData(filePath, actual); @@ -580,7 +573,7 @@ public class ExpectedHighlightingData { private boolean expectedInfosContainsInfo(HighlightInfo info) { if (info.getTextAttributes(null, null) == TextAttributes.ERASE_MARKER) return true; - final Collection expectedHighlights = highlightingTypes.values(); + final Collection expectedHighlights = myHighlightingTypes.values(); for (ExpectedHighlightingSet highlightingSet : expectedHighlights) { if (highlightingSet.severity != info.getSeverity()) continue; if (!highlightingSet.enabled) return true; @@ -602,10 +595,8 @@ public class ExpectedHighlightingData { info.endOffset == expectedInfo.endOffset && info.isAfterEndOfLine() == expectedInfo.isAfterEndOfLine() && (expectedInfo.type == WHATEVER || expectedInfo.type.equals(info.type)) && - (Comparing.strEqual(ANY_TEXT, expectedInfo.getDescription()) || Comparing.strEqual(info.getDescription(), - expectedInfo.getDescription())) && - (expectedInfo.forcedTextAttributes == null || Comparing.equal(expectedInfo.getTextAttributes(null, null), - info.getTextAttributes(null, null))) && + (Comparing.strEqual(ANY_TEXT, expectedInfo.getDescription()) || Comparing.strEqual(info.getDescription(), expectedInfo.getDescription())) && + (expectedInfo.forcedTextAttributes == null || Comparing.equal(expectedInfo.getTextAttributes(null, null), info.getTextAttributes(null, null))) && (expectedInfo.forcedTextAttributesKey == null || expectedInfo.forcedTextAttributesKey.equals(info.forcedTextAttributesKey)); } @@ -621,4 +612,4 @@ public class ExpectedHighlightingData { } return String.format("(%d:%d..%d:%d)", startLine + 1, endLine + 1, startCol + 1, endCol + 1); } -} +} \ No newline at end of file diff --git a/platform/testFramework/src/com/intellij/testFramework/fixtures/CodeInsightTestFixture.java b/platform/testFramework/src/com/intellij/testFramework/fixtures/CodeInsightTestFixture.java index de8374e68084..9747a3a76ea3 100644 --- a/platform/testFramework/src/com/intellij/testFramework/fixtures/CodeInsightTestFixture.java +++ b/platform/testFramework/src/com/intellij/testFramework/fixtures/CodeInsightTestFixture.java @@ -1,5 +1,5 @@ /* - * Copyright 2000-2014 JetBrains s.r.o. + * Copyright 2000-2015 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. @@ -13,7 +13,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package com.intellij.testFramework.fixtures; import com.intellij.codeInsight.completion.CompletionType; @@ -47,7 +46,6 @@ import com.intellij.testFramework.TestDataFile; import com.intellij.usageView.UsageInfo; import com.intellij.util.Consumer; import org.intellij.lang.annotations.MagicConstant; -import org.jetbrains.annotations.NonNls; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -56,20 +54,19 @@ import java.util.List; /** * @author Dmitry Avdeev - * @link http://confluence.jetbrains.net/display/IDEADEV/Testing+IntelliJ+IDEA+Plugins + * @link http://www.jetbrains.org/intellij/sdk/docs/basics/testing_plugins.html * @see IdeaTestFixtureFactory#createCodeInsightFixture(IdeaProjectTestFixture) */ public interface CodeInsightTestFixture extends IdeaProjectTestFixture { - @NonNls String CARET_MARKER = EditorTestUtil.CARET_TAG; + String CARET_MARKER = EditorTestUtil.CARET_TAG; - @NonNls String ERROR_MARKER = "error"; - @NonNls String WARNING_MARKER = "warning"; - @NonNls String INFORMATION_MARKER = "weak_warning"; - @NonNls String SERVER_PROBLEM_MARKER = "server_problem"; - @NonNls String INFO_MARKER = "info"; - @NonNls String END_LINE_HIGHLIGHT_MARKER = "EOLError"; - @NonNls String END_LINE_WARNING_MARKER = "EOLWarning"; + String ERROR_MARKER = "error"; + String WARNING_MARKER = "warning"; + String WEAK_WARNING_MARKER = "weak_warning"; + String INFO_MARKER = "info"; + String END_LINE_HIGHLIGHT_MARKER = "EOLError"; + String END_LINE_WARNING_MARKER = "EOLWarning"; /** * Returns the in-memory editor instance. @@ -92,7 +89,7 @@ public interface CodeInsightTestFixture extends IdeaProjectTestFixture { */ PsiFile getFile(); - void setTestDataPath(@NotNull @NonNls String dataPath); + void setTestDataPath(@NotNull String dataPath); @NotNull String getTestDataPath(); @@ -103,6 +100,14 @@ public interface CodeInsightTestFixture extends IdeaProjectTestFixture { @NotNull TempDirTestFixture getTempDirFixture(); + /** + * Copies a file from the testdata directory to the same relative path in the test project directory. + * + * @return the VirtualFile for the copied file in the test project directory. + */ + @NotNull + VirtualFile copyFileToProject(@TestDataFile @NotNull String sourceFilePath); + /** * Copies a file from the testdata directory to the specified path in the test project directory. * @@ -111,7 +116,7 @@ public interface CodeInsightTestFixture extends IdeaProjectTestFixture { * @return the VirtualFile for the copied file in the test project directory. */ @NotNull - VirtualFile copyFileToProject(@TestDataFile @NonNls @NotNull String sourceFilePath, @NonNls @NotNull String targetPath); + VirtualFile copyFileToProject(@TestDataFile @NotNull String sourceFilePath, @NotNull String targetPath); /** * Copies a directory from the testdata directory to the specified path in the test project directory. @@ -121,15 +126,7 @@ public interface CodeInsightTestFixture extends IdeaProjectTestFixture { * @return the VirtualFile for the copied directory in the test project directory. */ @NotNull - VirtualFile copyDirectoryToProject(@TestDataFile @NonNls @NotNull String sourceFilePath, @NonNls @NotNull String targetPath); - - /** - * Copies a file from the testdata directory to the same relative path in the test project directory. - * - * @return the VirtualFile for the copied file in the test project directory. - */ - @NotNull - VirtualFile copyFileToProject(@TestDataFile @NonNls @NotNull String sourceFilePath); + VirtualFile copyDirectoryToProject(@TestDataFile @NotNull String sourceFilePath, @NotNull String targetPath); /** * Copies a file from the testdata directory to the same relative path in the test project directory @@ -138,7 +135,7 @@ public interface CodeInsightTestFixture extends IdeaProjectTestFixture { * @param filePath path to the file, relative to the testdata path. * @return the PSI file for the copied and opened file. */ - PsiFile configureByFile(@TestDataFile @NonNls @NotNull String filePath); + PsiFile configureByFile(@TestDataFile @NotNull String filePath); /** * Copies multiple files from the testdata directory to the same relative paths in the test project directory @@ -148,7 +145,7 @@ public interface CodeInsightTestFixture extends IdeaProjectTestFixture { * @return the PSI files for the copied files. */ @NotNull - PsiFile[] configureByFiles(@TestDataFile @NonNls @NotNull String... filePaths); + PsiFile[] configureByFiles(@TestDataFile @NotNull String... filePaths); /** * Loads the specified text, treated as the contents of a file with the specified file type, into the in-memory @@ -158,7 +155,7 @@ public interface CodeInsightTestFixture extends IdeaProjectTestFixture { * @param text the text to load into the in-memory editor. * @return the PSI file created from the specified text. */ - PsiFile configureByText(@NotNull FileType fileType, @NotNull @NonNls String text); + PsiFile configureByText(@NotNull FileType fileType, @NotNull String text); /** * Loads the specified text, treated as the contents of a file with the specified name, into the in-memory @@ -168,7 +165,7 @@ public interface CodeInsightTestFixture extends IdeaProjectTestFixture { * @param text the text to load into the in-memory editor. * @return the PSI file created from the specified text. */ - PsiFile configureByText(@NotNull String fileName, @NotNull @NonNls String text); + PsiFile configureByText(@NotNull String fileName, @NotNull String text); /** * Loads the specified file from the test project directory into the in-memory editor. @@ -192,7 +189,7 @@ public interface CodeInsightTestFixture extends IdeaProjectTestFixture { * @param fileText the text to put into the created file. * @return the PSI file for the created file. */ - PsiFile addFileToProject(@NonNls @NotNull String relativePath, @NotNull @NonNls String fileText); + PsiFile addFileToProject(@NotNull String relativePath, @NotNull String fileText); /** * Compares the contents of the in-memory editor with the specified file. The trailing whitespaces are not ignored @@ -200,7 +197,7 @@ public interface CodeInsightTestFixture extends IdeaProjectTestFixture { * * @param expectedFile path to file to check against, relative to the testdata path. */ - void checkResultByFile(@TestDataFile @NonNls @NotNull String expectedFile); + void checkResultByFile(@TestDataFile @NotNull String expectedFile); /** * Compares the contents of the in-memory editor with the specified file, optionally ignoring trailing whitespaces. @@ -208,7 +205,7 @@ public interface CodeInsightTestFixture extends IdeaProjectTestFixture { * @param expectedFile path to file to check against, relative to the testdata path. * @param ignoreTrailingWhitespaces whether trailing whitespaces should be ignored by the comparison. */ - void checkResultByFile(@TestDataFile @NonNls @NotNull String expectedFile, boolean ignoreTrailingWhitespaces); + void checkResultByFile(@TestDataFile @NotNull String expectedFile, boolean ignoreTrailingWhitespaces); /** * Compares a file in the test project with a file in the testdata directory. @@ -217,8 +214,8 @@ public interface CodeInsightTestFixture extends IdeaProjectTestFixture { * @param expectedFile path to file to check against, relative to the testdata path. * @param ignoreTrailingWhitespaces whether trailing whitespaces should be ignored by the comparison. */ - void checkResultByFile(@NonNls @NotNull String filePath, - @TestDataFile @NonNls @NotNull String expectedFile, + void checkResultByFile(@NotNull String filePath, + @TestDataFile @NotNull String expectedFile, boolean ignoreTrailingWhitespaces); /** @@ -226,7 +223,7 @@ public interface CodeInsightTestFixture extends IdeaProjectTestFixture { * Should be called BEFORE {@link #setUp()}. And do not forget to call {@link #tearDown()} * * @param inspections inspections to be enabled in highlighting tests. - * @see #enableInspections(com.intellij.codeInspection.InspectionToolProvider...) + * @see #enableInspections(InspectionToolProvider...) */ void enableInspections(@NotNull InspectionProfileEntry... inspections); @@ -253,24 +250,24 @@ public interface CodeInsightTestFixture extends IdeaProjectTestFixture { * * @param checkWarnings enables {@link #WARNING_MARKER} support. * @param checkInfos enables {@link #INFO_MARKER} support. - * @param checkWeakWarnings enables {@link #INFORMATION_MARKER} support. + * @param checkWeakWarnings enables {@link #WEAK_WARNING_MARKER} support. * @param filePaths the first file is tested only; the others are just copied along the first. * @return highlighting duration in milliseconds. */ long testHighlighting(boolean checkWarnings, boolean checkInfos, boolean checkWeakWarnings, - @TestDataFile @NonNls @NotNull String... filePaths); + @TestDataFile @NotNull String... filePaths); long testHighlightingAllFiles(boolean checkWarnings, boolean checkInfos, boolean checkWeakWarnings, - @TestDataFile @NonNls @NotNull String... filePaths); + @TestDataFile @NotNull String... filePaths); long testHighlightingAllFiles(boolean checkWarnings, boolean checkInfos, boolean checkWeakWarnings, - @TestDataFile @NonNls @NotNull VirtualFile... files); + @TestDataFile @NotNull VirtualFile... files); /** * Check highlighting of file already loaded by configure* methods @@ -290,12 +287,12 @@ public interface CodeInsightTestFixture extends IdeaProjectTestFixture { * @param filePaths the first file is tested only; the others are just copied along with the first. * @return highlighting duration in milliseconds */ - long testHighlighting(@TestDataFile @NonNls @NotNull String... filePaths); + long testHighlighting(@TestDataFile @NotNull String... filePaths); long testHighlighting(boolean checkWarnings, boolean checkInfos, boolean checkWeakWarnings, @NotNull VirtualFile file); @NotNull - HighlightTestInfo testFile(@NonNls @NotNull String... filePath); + HighlightTestInfo testFile(@NotNull String... filePath); void openFileInEditor(@NotNull VirtualFile file); @@ -317,7 +314,7 @@ public interface CodeInsightTestFixture extends IdeaProjectTestFixture { * @see #getReferenceAtCaretPositionWithAssertion(String...) */ @Nullable - PsiReference getReferenceAtCaretPosition(@TestDataFile @NonNls @NotNull String... filePaths); + PsiReference getReferenceAtCaretPosition(@TestDataFile @NotNull String... filePaths); /** * Finds the reference in position marked by {@link #CARET_MARKER}. @@ -327,7 +324,7 @@ public interface CodeInsightTestFixture extends IdeaProjectTestFixture { * @see #getReferenceAtCaretPosition(String...) */ @NotNull - PsiReference getReferenceAtCaretPositionWithAssertion(@NonNls @TestDataFile @NotNull String... filePaths); + PsiReference getReferenceAtCaretPositionWithAssertion(@TestDataFile @NotNull String... filePaths); /** * Collects available intentions at caret position. @@ -337,16 +334,16 @@ public interface CodeInsightTestFixture extends IdeaProjectTestFixture { * @see #CARET_MARKER */ @NotNull - List getAvailableIntentions(@NonNls @TestDataFile @NotNull String... filePaths); + List getAvailableIntentions(@TestDataFile @NotNull String... filePaths); @NotNull - List getAllQuickFixes(@NonNls @TestDataFile @NotNull String... filePaths); + List getAllQuickFixes(@TestDataFile @NotNull String... filePaths); @NotNull List getAvailableIntentions(); /** - * Returns all intentions or quickfixes which are available at the current caret position and whose text starts with the specified hint text. + * Returns all intentions or quick fixes which are available at the current caret position and whose text starts with the specified hint text. * * @param hint the text that the intention text should begin with. * @return the list of matching intentions @@ -360,7 +357,7 @@ public interface CodeInsightTestFixture extends IdeaProjectTestFixture { * * @param hint the text that the intention text should begin with. * @return the matching intention - * @throws java.lang.AssertionError if no intentions are found or if multiple intentions match the hint text. + * @throws AssertionError if no intentions are found or if multiple intentions match the hint text. */ IntentionAction findSingleIntention(@NotNull String hint); @@ -382,21 +379,21 @@ public interface CodeInsightTestFixture extends IdeaProjectTestFixture { */ void launchAction(@NotNull IntentionAction action); - void testCompletion(@NonNls @NotNull String[] filesBefore, @TestDataFile @NonNls @NotNull String fileAfter); + void testCompletion(@NotNull String[] filesBefore, @TestDataFile @NotNull String fileAfter); - void testCompletionTyping(@NonNls @NotNull String[] filesBefore, @NotNull String toType, @NotNull @TestDataFile @NonNls String fileAfter); + void testCompletionTyping(@NotNull String[] filesBefore, @NotNull String toType, @NotNull @TestDataFile String fileAfter); /** * Runs basic completion in caret position in fileBefore. * Implies that there is only one completion variant and it was inserted automatically, and checks the result file text with fileAfter */ - void testCompletion(@TestDataFile @NonNls @NotNull String fileBefore, - @NotNull @TestDataFile @NonNls String fileAfter, + void testCompletion(@TestDataFile @NotNull String fileBefore, + @NotNull @TestDataFile String fileAfter, @NotNull String... additionalFiles); - void testCompletionTyping(@NotNull @TestDataFile @NonNls String fileBefore, + void testCompletionTyping(@NotNull @TestDataFile String fileBefore, @NotNull String toType, - @NotNull @TestDataFile @NonNls String fileAfter, + @NotNull @TestDataFile String fileAfter, @NotNull String... additionalFiles); /** @@ -405,7 +402,7 @@ public interface CodeInsightTestFixture extends IdeaProjectTestFixture { * * @param items most probably will contain > 1 items */ - void testCompletionVariants(@NotNull @TestDataFile @NonNls String fileBefore, @NotNull @NonNls String... items); + void testCompletionVariants(@NotNull @TestDataFile String fileBefore, @NotNull String... items); /** * Launches renaming refactoring and checks the result. @@ -415,15 +412,15 @@ public interface CodeInsightTestFixture extends IdeaProjectTestFixture { * @param newName new name for the element. * @see #testRename(String, String) */ - void testRename(@NotNull @TestDataFile @NonNls String fileBefore, - @NotNull @TestDataFile @NonNls String fileAfter, - @NotNull @NonNls String newName, + void testRename(@NotNull @TestDataFile String fileBefore, + @NotNull @TestDataFile String fileAfter, + @NotNull String newName, @NotNull String... additionalFiles); void testRename(@NotNull @TestDataFile String fileAfter, @NotNull String newName); @NotNull - Collection testFindUsages(@TestDataFile @NonNls @NotNull String... fileNames); + Collection testFindUsages(@TestDataFile @NotNull String... fileNames); @NotNull Collection findUsages(@NotNull PsiElement to); @@ -431,7 +428,7 @@ public interface CodeInsightTestFixture extends IdeaProjectTestFixture { @NotNull RangeHighlighter[] testHighlightUsages(@NotNull @TestDataFile String... files); - void moveFile(@NotNull @NonNls @TestDataFile String filePath, @NotNull @NonNls String to, @NotNull String... additionalFiles); + void moveFile(@NotNull @TestDataFile String filePath, @NotNull String to, @NotNull String... additionalFiles); /** * Returns gutter renderer at the caret position. @@ -441,7 +438,7 @@ public interface CodeInsightTestFixture extends IdeaProjectTestFixture { * @return gutter renderer at the caret position. */ @Nullable - GutterMark findGutter(@NotNull @TestDataFile @NonNls String filePath); + GutterMark findGutter(@NotNull @TestDataFile String filePath); @NotNull List findGuttersAtCaret(); @@ -538,7 +535,7 @@ public interface CodeInsightTestFixture extends IdeaProjectTestFixture { void testFoldingWithCollapseStatus(@NotNull String fileName); - void assertPreferredCompletionItems(int selected, @NotNull @NonNls String... expected); + void assertPreferredCompletionItems(int selected, @NotNull String... expected); /** * Initializes the structure view for the file currently loaded in the editor and passes it to the specified consumer. diff --git a/platform/testFramework/src/com/intellij/testFramework/fixtures/TempDirTestFixture.java b/platform/testFramework/src/com/intellij/testFramework/fixtures/TempDirTestFixture.java index e27d53b73cc2..519d031465fb 100644 --- a/platform/testFramework/src/com/intellij/testFramework/fixtures/TempDirTestFixture.java +++ b/platform/testFramework/src/com/intellij/testFramework/fixtures/TempDirTestFixture.java @@ -18,6 +18,7 @@ package com.intellij.testFramework.fixtures; import com.intellij.openapi.vfs.VirtualFile; import com.intellij.openapi.vfs.VirtualFileFilter; import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; import java.io.IOException; @@ -25,9 +26,6 @@ import java.io.IOException; * @author Dmitry Avdeev */ public interface TempDirTestFixture extends IdeaTestFixture { - @NotNull - VirtualFile copyFile(@NotNull VirtualFile file, @NotNull String targetPath); - @NotNull VirtualFile copyAll(@NotNull String dataDir, @NotNull String targetDir); @@ -37,6 +35,7 @@ public interface TempDirTestFixture extends IdeaTestFixture { @NotNull String getTempDirPath(); + @Nullable VirtualFile getFile(@NotNull String path); @NotNull @@ -46,5 +45,5 @@ public interface TempDirTestFixture extends IdeaTestFixture { VirtualFile findOrCreateDir(@NotNull String name) throws IOException; @NotNull - VirtualFile createFile(@NotNull String name, String text) throws IOException; -} + VirtualFile createFile(@NotNull String name, @NotNull String text) throws IOException; +} \ No newline at end of file diff --git a/platform/testFramework/src/com/intellij/testFramework/fixtures/impl/CodeInsightTestFixtureImpl.java b/platform/testFramework/src/com/intellij/testFramework/fixtures/impl/CodeInsightTestFixtureImpl.java index f32e275c7337..3ed0498f6235 100644 --- a/platform/testFramework/src/com/intellij/testFramework/fixtures/impl/CodeInsightTestFixtureImpl.java +++ b/platform/testFramework/src/com/intellij/testFramework/fixtures/impl/CodeInsightTestFixtureImpl.java @@ -13,7 +13,6 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package com.intellij.testFramework.fixtures.impl; import com.intellij.analysis.AnalysisScope; @@ -85,7 +84,6 @@ import com.intellij.openapi.util.*; import com.intellij.openapi.util.io.FileUtil; import com.intellij.openapi.util.text.StringUtil; import com.intellij.openapi.vfs.*; -import com.intellij.openapi.vfs.newvfs.impl.VfsRootAccess; import com.intellij.profile.Profile; import com.intellij.profile.codeInspection.InspectionProfileManager; import com.intellij.profile.codeInspection.InspectionProjectProfileManager; @@ -114,7 +112,6 @@ import com.intellij.util.containers.ContainerUtil; import com.intellij.util.indexing.FileBasedIndex; import com.intellij.util.ui.UIUtil; import junit.framework.ComparisonFailure; -import org.jetbrains.annotations.NonNls; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; import org.jetbrains.annotations.TestOnly; @@ -130,17 +127,17 @@ import java.util.*; */ @SuppressWarnings({"TestMethodWithIncorrectSignature", "JUnitTestCaseWithNoTests", "JUnitTestClassNamingConvention", "TestOnlyProblems"}) public class CodeInsightTestFixtureImpl extends BaseFixture implements CodeInsightTestFixture { - private static final Function INTENTION_NAME_FUN = new Function() { + private static final Function INTENTION_NAME_FUN = new Function() { @Override public String fun(final IntentionAction intentionAction) { return "\"" + intentionAction.getText() + "\""; } }; + private static final String START_FOLD = ""; private static final String END_FOLD = ""; - // this allows an inspection to be represented in profile, but to appear disabled - public final Set myDisabledInspections = new HashSet(); - protected final IdeaProjectTestFixture myProjectFixture; + + private final IdeaProjectTestFixture myProjectFixture; private final TempDirTestFixture myTempDirFixture; private PsiManagerImpl myPsiManager; private VirtualFile myFile; @@ -384,66 +381,48 @@ public class CodeInsightTestFixtureImpl extends BaseFixture implements CodeInsig @NotNull @Override - public VirtualFile copyFileToProject(@NotNull @NonNls final String sourceFilePath, @NotNull @NonNls final String targetPath) { - final String testDataPath = getTestDataPath(); - - File fromFile = new File(testDataPath + "/" + sourceFilePath); - if (!fromFile.exists()) { - fromFile = new File(sourceFilePath); - } - - VirtualFile result; - final String path = fromFile.getAbsolutePath(); - if (myTempDirFixture instanceof LightTempDirTestFixtureImpl) { - VfsRootAccess.allowRootAccess(path); - Disposer.register(getTestRootDisposable(), new Disposable() { - @Override - public void dispose() { - VfsRootAccess.disallowRootAccess(path); - } - }); - VirtualFile fromVFile = LocalFileSystem.getInstance().refreshAndFindFileByIoFile(fromFile); - if (fromVFile == null) { - fromVFile = myTempDirFixture.getFile(sourceFilePath); - } - Assert.assertNotNull("can't find test data file " + sourceFilePath + " (" + testDataPath + ")", fromVFile); - VfsTestUtil.assertFilePathEndsWithCaseSensitivePath(fromVFile, sourceFilePath); - result = myTempDirFixture.copyFile(fromVFile, targetPath); - } - else { - - final File targetFile = new File(getTempDirPath() + "/" + targetPath); - if (!targetFile.exists()) { - if (fromFile.isDirectory()) { - Assert.assertTrue(targetFile.toString(), targetFile.mkdirs()); - } - else { - if (!fromFile.exists()) { - Assert.fail("Cannot find source file: '" + sourceFilePath + "'. getTestDataPath()='" + testDataPath + "'. "); - } - try { - FileUtil.copy(fromFile, targetFile); - } - catch (IOException e) { - throw new RuntimeException("Cannot copy " + fromFile + " to " + targetFile, e); - } - } - } - - final VirtualFile file = LocalFileSystem.getInstance().refreshAndFindFileByIoFile(targetFile); - Assert.assertNotNull(targetFile.toString(), file); - result = file; - } - result.putUserData(VfsTestUtil.TEST_DATA_FILE_PATH, path); - return result; + public VirtualFile copyFileToProject(@NotNull String sourcePath) { + return copyFileToProject(sourcePath, sourcePath); } @NotNull @Override - public VirtualFile copyDirectoryToProject(@NotNull @NonNls final String sourceFilePath, @NotNull @NonNls final String targetPath) { + public VirtualFile copyFileToProject(@NotNull String sourcePath, @NotNull String targetPath) { + String testDataPath = getTestDataPath(); + File sourceFile = FileUtil.findFirstThatExist(testDataPath + '/' + sourcePath, sourcePath); + VirtualFile targetFile = myTempDirFixture.getFile(targetPath); + + if (sourceFile == null && targetFile != null && targetPath.equals(sourcePath)) { + return targetFile; + } + + Assert.assertNotNull("Cannot find source file: " + sourcePath + "; test data path: " + testDataPath, sourceFile); + Assert.assertTrue("Not a file: " + sourceFile, sourceFile.isFile()); + + if (targetFile == null) { + targetFile = myTempDirFixture.createFile(targetPath); + VfsTestUtil.assertFilePathEndsWithCaseSensitivePath(targetFile, sourcePath); + targetFile.putUserData(VfsTestUtil.TEST_DATA_FILE_PATH, sourceFile.getAbsolutePath()); + } + + final File _source = sourceFile; + final VirtualFile _target = targetFile; + new WriteAction() { + @Override + protected void run(@NotNull Result result) throws IOException { + _target.setBinaryContent(FileUtil.loadFileBytes(_source)); + } + }.execute(); + + return targetFile; + } + + @NotNull + @Override + public VirtualFile copyDirectoryToProject(@NotNull String sourcePath, @NotNull String targetPath) { final String testDataPath = getTestDataPath(); - final File fromFile = new File(testDataPath + "/" + sourceFilePath); + final File fromFile = new File(testDataPath + "/" + sourcePath); if (myTempDirFixture instanceof LightTempDirTestFixtureImpl) { return myTempDirFixture.copyAll(fromFile.getPath(), targetPath); } @@ -461,12 +440,6 @@ public class CodeInsightTestFixtureImpl extends BaseFixture implements CodeInsig return file; } - @NotNull - @Override - public VirtualFile copyFileToProject(@NotNull @NonNls final String sourceFilePath) { - return copyFileToProject(sourceFilePath, sourceFilePath); - } - @Override public void enableInspections(@NotNull InspectionProfileEntry... inspections) { assertInitialized(); @@ -475,10 +448,6 @@ public class CodeInsightTestFixtureImpl extends BaseFixture implements CodeInsig } } - private boolean isInitialized() { - return myPsiManager != null; - } - @Override public void enableInspections(@NotNull final Class... inspections) { enableInspections(Arrays.asList(inspections)); @@ -511,7 +480,7 @@ public class CodeInsightTestFixtureImpl extends BaseFixture implements CodeInsig public void enableInspections(@NotNull InspectionToolProvider... providers) { List tools = new ArrayList(); for (InspectionToolProvider provider : providers) { - for (Class clazz : provider.getInspectionClasses()) { + for (Class clazz : provider.getInspectionClasses()) { try { Object o = clazz.getConstructor().newInstance(); if (o instanceof LocalInspectionTool) { @@ -547,7 +516,7 @@ public class CodeInsightTestFixtureImpl extends BaseFixture implements CodeInsig public long testHighlightingAllFiles(final boolean checkWarnings, final boolean checkInfos, final boolean checkWeakWarnings, - @NotNull @NonNls final String... filePaths) { + @NotNull final String... filePaths) { final ArrayList files = new ArrayList(); for (String path : filePaths) { files.add(copyFileToProject(path)); @@ -559,7 +528,7 @@ public class CodeInsightTestFixtureImpl extends BaseFixture implements CodeInsig public long testHighlightingAllFiles(final boolean checkWarnings, final boolean checkInfos, final boolean checkWeakWarnings, - @NotNull @NonNls final VirtualFile... files) { + @NotNull final VirtualFile... files) { return collectAndCheckHighlightings(checkWarnings, checkInfos, checkWeakWarnings, files); } @@ -630,7 +599,7 @@ public class CodeInsightTestFixtureImpl extends BaseFixture implements CodeInsig @NotNull @Override - public HighlightTestInfo testFile(@NonNls @NotNull String... filePath) { + public HighlightTestInfo testFile(@NotNull String... filePath) { return new HighlightTestInfo(getTestRootDisposable(), filePath) { @Override public HighlightTestInfo doTest() { @@ -653,8 +622,10 @@ public class CodeInsightTestFixtureImpl extends BaseFixture implements CodeInsig @Override public void testInspection(@NotNull String testDir, @NotNull InspectionToolWrapper toolWrapper) { VirtualFile sourceDir = copyDirectoryToProject(new File(testDir, "src").getPath(), "src"); - AnalysisScope scope = new AnalysisScope(getPsiManager().findDirectory(sourceDir)); + PsiDirectory psiDirectory = getPsiManager().findDirectory(sourceDir); + Assert.assertNotNull(psiDirectory); + AnalysisScope scope = new AnalysisScope(psiDirectory); scope.invalidate(); InspectionManagerEx inspectionManager = (InspectionManagerEx)InspectionManager.getInstance(getProject()); @@ -692,7 +663,7 @@ public class CodeInsightTestFixtureImpl extends BaseFixture implements CodeInsig @Override @NotNull - public List getAllQuickFixes(@NotNull @NonNls final String... filePaths) { + public List getAllQuickFixes(@NotNull final String... filePaths) { if (filePaths.length != 0) { configureByFilesInner(filePaths); } @@ -718,6 +689,7 @@ public class CodeInsightTestFixtureImpl extends BaseFixture implements CodeInsig editor = ((EditorWindow)editor).getDelegate(); file = InjectedLanguageUtil.getTopLevelFile(file); } + Assert.assertNotNull(file); return getAvailableIntentions(editor, file); } @@ -767,7 +739,7 @@ public class CodeInsightTestFixtureImpl extends BaseFixture implements CodeInsig } @Override - public void testCompletion(@NotNull @NonNls String[] filesBefore, @NotNull @TestDataFile @NonNls String fileAfter) { + public void testCompletion(@NotNull String[] filesBefore, @NotNull @TestDataFile String fileAfter) { testCompletionTyping(filesBefore, "", fileAfter); } @@ -796,9 +768,9 @@ public class CodeInsightTestFixtureImpl extends BaseFixture implements CodeInsig } @Override - public void testCompletionTyping(@NotNull @TestDataFile @NonNls String fileBefore, + public void testCompletionTyping(@NotNull @TestDataFile String fileBefore, @NotNull String toType, - @NotNull @TestDataFile @NonNls String fileAfter, + @NotNull @TestDataFile String fileAfter, @NotNull String... additionalFiles) { testCompletionTyping(ArrayUtil.reverseArray(ArrayUtil.append(additionalFiles, fileBefore)), toType, fileAfter); } @@ -889,7 +861,7 @@ public class CodeInsightTestFixtureImpl extends BaseFixture implements CodeInsig final DataContext editorContext = ((EditorEx)myEditor).getDataContext(); final DataContext context = new DataContext() { @Override - public Object getData(@NonNls final String dataId) { + public Object getData(final String dataId) { return PsiElementRenameHandler.DEFAULT_NAME.getName().equals(dataId) ? newName : editorContext.getData(dataId); @@ -1036,7 +1008,7 @@ public class CodeInsightTestFixtureImpl extends BaseFixture implements CodeInsig @NotNull @Override - public Collection testFindUsages(@NotNull @NonNls final String... fileNames) { + public Collection testFindUsages(@NotNull final String... fileNames) { assertInitialized(); configureByFiles(fileNames); final PsiElement targetElement = TargetElementUtil @@ -1081,7 +1053,7 @@ public class CodeInsightTestFixtureImpl extends BaseFixture implements CodeInsig } @Override - public void moveFile(@NotNull @NonNls final String filePath, @NotNull @NonNls final String to, @NotNull final String... additionalFiles) { + public void moveFile(@NotNull final String filePath, @NotNull final String to, @NotNull final String... additionalFiles) { assertInitialized(); final Project project = getProject(); new WriteCommandAction.Simple(project) { @@ -1165,7 +1137,7 @@ public class CodeInsightTestFixtureImpl extends BaseFixture implements CodeInsig } @Override - public PsiFile addFileToProject(@NotNull @NonNls final String relativePath, @NotNull @NonNls final String fileText) { + public PsiFile addFileToProject(@NotNull final String relativePath, @NotNull final String fileText) { assertInitialized(); return addFileToProject(getTempDirPath(), relativePath, fileText); } @@ -1434,7 +1406,7 @@ public class CodeInsightTestFixtureImpl extends BaseFixture implements CodeInsig } @NotNull - private PsiFile[] configureByFilesInner(@NonNls @NotNull String... filePaths) { + private PsiFile[] configureByFilesInner(@NotNull String... filePaths) { assertInitialized(); myFile = null; myEditor = null; @@ -1453,12 +1425,12 @@ public class CodeInsightTestFixtureImpl extends BaseFixture implements CodeInsig @NotNull @Override - public PsiFile[] configureByFiles(@NotNull @NonNls final String... files) { + public PsiFile[] configureByFiles(@NotNull final String... files) { return configureByFilesInner(files); } @Override - public PsiFile configureByText(@NotNull final FileType fileType, @NotNull @NonNls final String text) { + public PsiFile configureByText(@NotNull final FileType fileType, @NotNull final String text) { assertInitialized(); final String extension = fileType.getDefaultExtension(); final FileTypeManager fileTypeManager = FileTypeManager.getInstance(); @@ -1475,7 +1447,7 @@ public class CodeInsightTestFixtureImpl extends BaseFixture implements CodeInsig } @Override - public PsiFile configureByText(@NotNull final String fileName, @NotNull @NonNls final String text) { + public PsiFile configureByText(@NotNull final String fileName, @NotNull final String text) { assertInitialized(); return new WriteCommandAction(getProject()) { @Override @@ -1518,7 +1490,7 @@ public class CodeInsightTestFixtureImpl extends BaseFixture implements CodeInsig return PsiDocumentManager.getInstance(getProject()).getDocument(file); } - private PsiFile configureByFileInner(@NonNls @NotNull String filePath) { + private PsiFile configureByFileInner(@NotNull String filePath) { assertInitialized(); final VirtualFile file = copyFileToProject(filePath); return configureByFileInner(file); @@ -1757,7 +1729,7 @@ public class CodeInsightTestFixtureImpl extends BaseFixture implements CodeInsig ((FileTreeAccessFilter)myVirtualFileFilter).allowTreeAccessForAllFiles(); } - private void checkResultByFile(@NonNls @NotNull String expectedFile, + private void checkResultByFile(@NotNull String expectedFile, @NotNull PsiFile originalFile, boolean stripTrailingSpaces) throws IOException { if (!stripTrailingSpaces) { @@ -1884,7 +1856,7 @@ public class CodeInsightTestFixtureImpl extends BaseFixture implements CodeInsig } @Override - public void assertPreferredCompletionItems(final int selected, @NotNull @NonNls final String... expected) { + public void assertPreferredCompletionItems(final int selected, @NotNull final String... expected) { final LookupImpl lookup = getLookup(); Assert.assertNotNull("No lookup is shown", lookup); @@ -2011,4 +1983,4 @@ public class CodeInsightTestFixtureImpl extends BaseFixture implements CodeInsig return getOffset() < o.getOffset() ? 1 : -1; } } -} +} \ No newline at end of file diff --git a/platform/testFramework/src/com/intellij/testFramework/fixtures/impl/LightTempDirTestFixtureImpl.java b/platform/testFramework/src/com/intellij/testFramework/fixtures/impl/LightTempDirTestFixtureImpl.java index 7d37f23a01bc..e7d9ecc90e4c 100644 --- a/platform/testFramework/src/com/intellij/testFramework/fixtures/impl/LightTempDirTestFixtureImpl.java +++ b/platform/testFramework/src/com/intellij/testFramework/fixtures/impl/LightTempDirTestFixtureImpl.java @@ -66,31 +66,6 @@ public class LightTempDirTestFixtureImpl extends BaseFixture implements TempDirT } } - @NotNull - @Override - public VirtualFile copyFile(@NotNull final VirtualFile file, @NotNull final String targetPath) { - final String path = PathUtil.getParentPath(targetPath); - return ApplicationManager.getApplication().runWriteAction(new Computable() { - @Override - public VirtualFile compute() { - try { - VirtualFile targetDir = findOrCreateDir(path); - final String newName = PathUtil.getFileName(targetPath); - final VirtualFile existing = targetDir.findChild(newName); - if (existing != null) { - existing.setBinaryContent(file.contentsToByteArray()); - return existing; - } - - return VfsUtilCore.copyFile(this, file, targetDir, newName); - } - catch (IOException e) { - throw new RuntimeException(e); - } - } - }); - } - @Override @NotNull public VirtualFile findOrCreateDir(@NotNull final String path) { @@ -176,11 +151,11 @@ public class LightTempDirTestFixtureImpl extends BaseFixture implements TempDirT @Override public VirtualFile getFile(@NotNull String path) { - final VirtualFile sourceRoot = getSourceRoot(); - final VirtualFile result = sourceRoot.findFileByRelativePath(path); + VirtualFile sourceRoot = getSourceRoot(); + VirtualFile result = sourceRoot.findFileByRelativePath(path); if (result == null) { sourceRoot.refresh(false, true); - return sourceRoot.findFileByRelativePath(path); + result = sourceRoot.findFileByRelativePath(path); } return result; } @@ -190,35 +165,25 @@ public class LightTempDirTestFixtureImpl extends BaseFixture implements TempDirT public VirtualFile createFile(@NotNull String targetPath) { final String path = PathUtil.getParentPath(targetPath); final String name = PathUtil.getFileName(targetPath); - return ApplicationManager.getApplication().runWriteAction(new Computable() { + return new WriteAction() { @Override - public VirtualFile compute() { - try { - VirtualFile targetDir = findOrCreateDir(path); - return targetDir.createChildData(this, name); - } - catch (IOException e) { - throw new RuntimeException(e); - } + protected void run(@NotNull Result result) throws IOException { + VirtualFile targetDir = findOrCreateDir(path); + result.setResult(targetDir.createChildData(this, name)); } - }); + }.execute().getResultObject(); } @Override @NotNull - public VirtualFile createFile(@NotNull String targetPath, final String text) throws IOException { - final VirtualFile file = createFile(targetPath); - ApplicationManager.getApplication().runWriteAction(new Runnable() { + public VirtualFile createFile(@NotNull String name, @NotNull final String text) throws IOException { + final VirtualFile file = createFile(name); + new WriteAction() { @Override - public void run() { - try { - VfsUtil.saveText(file, text); - } - catch (IOException e) { - throw new RuntimeException(e); - } + protected void run(@NotNull Result result) throws IOException { + VfsUtil.saveText(file, text); } - }); + }.execute(); return file; } @@ -251,4 +216,4 @@ public class LightTempDirTestFixtureImpl extends BaseFixture implements TempDirT } return mySourceRoot; } -} +} \ No newline at end of file diff --git a/platform/testFramework/src/com/intellij/testFramework/fixtures/impl/TempDirTestFixtureImpl.java b/platform/testFramework/src/com/intellij/testFramework/fixtures/impl/TempDirTestFixtureImpl.java index 553e4c344ea3..0915093a13c2 100644 --- a/platform/testFramework/src/com/intellij/testFramework/fixtures/impl/TempDirTestFixtureImpl.java +++ b/platform/testFramework/src/com/intellij/testFramework/fixtures/impl/TempDirTestFixtureImpl.java @@ -13,20 +13,20 @@ * See the License for the specific language governing permissions and * limitations under the License. */ - package com.intellij.testFramework.fixtures.impl; import com.intellij.openapi.application.ApplicationManager; import com.intellij.openapi.application.Result; import com.intellij.openapi.application.WriteAction; import com.intellij.openapi.util.Computable; -import com.intellij.openapi.util.Ref; import com.intellij.openapi.util.io.FileUtil; import com.intellij.openapi.util.text.StringUtil; -import com.intellij.openapi.vfs.*; +import com.intellij.openapi.vfs.LocalFileSystem; +import com.intellij.openapi.vfs.VfsUtil; +import com.intellij.openapi.vfs.VirtualFile; +import com.intellij.openapi.vfs.VirtualFileFilter; import com.intellij.testFramework.fixtures.TempDirTestFixture; import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; import org.junit.Assert; import java.io.File; @@ -40,20 +40,6 @@ public class TempDirTestFixtureImpl extends BaseFixture implements TempDirTestFi private final ArrayList myFilesToDelete = new ArrayList(); private File myTempDir; - @NotNull - @Override - public VirtualFile copyFile(@NotNull VirtualFile file, @NotNull String targetPath) { - try { - createTempDirectory(); - VirtualFile tempDir = - LocalFileSystem.getInstance().refreshAndFindFileByPath(myTempDir.getCanonicalPath().replace(File.separatorChar, '/')); - return VfsUtilCore.copyFile(this, file, tempDir); - } - catch (IOException e) { - throw new RuntimeException("Cannot copy " + file, e); - } - } - @NotNull @Override public VirtualFile copyAll(@NotNull String dataDir, @NotNull String targetDir) { @@ -107,36 +93,26 @@ public class TempDirTestFixtureImpl extends BaseFixture implements TempDirTestFi } @Override - @Nullable public VirtualFile getFile(@NotNull final String path) { - - final Ref result = new Ref(null); - ApplicationManager.getApplication().runWriteAction(new Runnable() { + return new WriteAction() { @Override - public void run() { - try { - final String fullPath = myTempDir.getCanonicalPath().replace(File.separatorChar, '/') + "/" + path; - final VirtualFile file = LocalFileSystem.getInstance().refreshAndFindFileByPath(fullPath); - result.set(file); - } - catch (IOException e) { - Assert.fail("Cannot find " + path + ": " + e); - } + protected void run(@NotNull Result result) throws IOException { + final String fullPath = myTempDir.getCanonicalPath() + '/' + path; + final VirtualFile file = LocalFileSystem.getInstance().refreshAndFindFileByPath(fullPath); + result.setResult(file); } - }); - return result.get(); + }.execute().getResultObject(); } @Override @NotNull public VirtualFile createFile(@NotNull final String name) { - final File file = createTempDirectory(); + final File file = new File(createTempDirectory(), name); return ApplicationManager.getApplication().runWriteAction(new Computable() { @Override public VirtualFile compute() { - final File file1 = new File(file, name); - FileUtil.createIfDoesntExist(file1); - return LocalFileSystem.getInstance().refreshAndFindFileByIoFile(file1); + FileUtil.createIfDoesntExist(file); + return LocalFileSystem.getInstance().refreshAndFindFileByIoFile(file); } }); } @@ -149,14 +125,14 @@ public class TempDirTestFixtureImpl extends BaseFixture implements TempDirTestFi @Override @NotNull - public VirtualFile createFile(@NotNull final String name, final String text) throws IOException { + public VirtualFile createFile(@NotNull String name, @NotNull final String text) throws IOException { final VirtualFile file = createFile(name); new WriteAction() { @Override - protected void run(@NotNull Result result) throws Throwable { + protected void run(@NotNull Result result) throws IOException { VfsUtil.saveText(file, text); } - }.execute().throwException(); + }.execute(); return file; } @@ -168,11 +144,15 @@ public class TempDirTestFixtureImpl extends BaseFixture implements TempDirTestFi @Override public void tearDown() throws Exception { - for (final File fileToDelete : myFilesToDelete) { - boolean deleted = FileUtil.delete(fileToDelete); - Assert.assertTrue("Can't delete " + fileToDelete, deleted); + try { + for (final File fileToDelete : myFilesToDelete) { + boolean deleted = FileUtil.delete(fileToDelete); + Assert.assertTrue("Can't delete " + fileToDelete, deleted); + } + } + finally { + super.tearDown(); } - super.tearDown(); } protected File getTempHome() { @@ -194,5 +174,4 @@ public class TempDirTestFixtureImpl extends BaseFixture implements TempDirTestFi throw new RuntimeException("Cannot create temp dir", e); } } - -} +} \ No newline at end of file diff --git a/spellchecker/testSrc/com/intellij/spellchecker/ui/SpellCheckingEditorCustomizationTest.java b/spellchecker/testSrc/com/intellij/spellchecker/ui/SpellCheckingEditorCustomizationTest.java index 679b32f72f90..d3cc45367abf 100644 --- a/spellchecker/testSrc/com/intellij/spellchecker/ui/SpellCheckingEditorCustomizationTest.java +++ b/spellchecker/testSrc/com/intellij/spellchecker/ui/SpellCheckingEditorCustomizationTest.java @@ -21,7 +21,6 @@ import com.intellij.openapi.editor.ex.EditorEx; import com.intellij.openapi.fileTypes.PlainTextFileType; import com.intellij.spellchecker.inspections.SpellCheckingInspection; import com.intellij.testFramework.fixtures.LightPlatformCodeInsightFixtureTestCase; -import com.intellij.testFramework.fixtures.impl.CodeInsightTestFixtureImpl; import com.intellij.ui.EditorCustomization; @SuppressWarnings("SpellCheckingInspection") @@ -35,7 +34,7 @@ public class SpellCheckingEditorCustomizationTest extends LightPlatformCodeInsig } public void testEnabledEvenIfDisabledInMainProfile() throws Exception { - ((CodeInsightTestFixtureImpl)myFixture).myDisabledInspections.add(SpellCheckingInspection.SPELL_CHECKING_INSPECTION_TOOL_NAME); + //todo[batrak] ((CodeInsightTestFixtureImpl)myFixture).myDisabledInspections.add(SpellCheckingInspection.SPELL_CHECKING_INSPECTION_TOOL_NAME); testEnabled(); } @@ -60,4 +59,4 @@ public class SpellCheckingEditorCustomizationTest extends LightPlatformCodeInsig InspectionProfileImpl.INIT_INSPECTIONS = false; } } -} +} \ No newline at end of file