mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
merged ReformatCodeActionInEditorTest into MultiActionCodeProcessorTest, test data moved. Fixed compilation and other minor after merge issues.
This commit is contained in:
-18
@@ -1,18 +0,0 @@
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
|
||||
public class Test {
|
||||
|
||||
public static void main(String[] args) {
|
||||
List<String> list = new ArrayList<String>();
|
||||
int a = 3;
|
||||
|
||||
int b = 3;
|
||||
}
|
||||
|
||||
|
||||
public void test() {
|
||||
}
|
||||
|
||||
}
|
||||
-22
@@ -1,22 +0,0 @@
|
||||
import java.util.HashMap;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
import java.util.HashSet;
|
||||
|
||||
|
||||
public class Test {
|
||||
|
||||
public static void main(String[] args) {
|
||||
<selection> List<String> list = new ArrayList<String>();
|
||||
int a = 3;<caret></selection>
|
||||
|
||||
int b = 3;
|
||||
}
|
||||
|
||||
|
||||
<selection><caret>
|
||||
public void test() {
|
||||
}</selection>
|
||||
|
||||
}
|
||||
@@ -1,19 +0,0 @@
|
||||
public class Test {
|
||||
|
||||
int a = 3;
|
||||
int b = 12;
|
||||
|
||||
long t = 12;
|
||||
|
||||
public void test() {
|
||||
|
||||
int a = 3;
|
||||
int b = 4;
|
||||
}
|
||||
|
||||
int rest = -12;
|
||||
|
||||
public void run() {
|
||||
}
|
||||
|
||||
}
|
||||
@@ -1,18 +0,0 @@
|
||||
public class Test {
|
||||
|
||||
<selection> int a = 3;
|
||||
<caret>int b = 12;</selection>
|
||||
|
||||
long t = 12;
|
||||
|
||||
public void test() {
|
||||
|
||||
<selection> int a = 3;
|
||||
<caret>int b = 4;</selection>
|
||||
}
|
||||
|
||||
int rest = -12;
|
||||
|
||||
<selection>public void run() {}<caret></selection>
|
||||
|
||||
}
|
||||
+47
-28
@@ -18,7 +18,9 @@ package com.intellij.codeInsight.actions;
|
||||
import com.intellij.JavaTestUtil;
|
||||
import com.intellij.openapi.editor.Caret;
|
||||
import com.intellij.openapi.editor.CaretModel;
|
||||
import com.intellij.openapi.editor.Document;
|
||||
import com.intellij.openapi.util.TextRange;
|
||||
import com.intellij.psi.PsiFile;
|
||||
import com.intellij.testFramework.fixtures.LightPlatformCodeInsightFixtureTestCase;
|
||||
import com.intellij.util.Function;
|
||||
import com.intellij.util.containers.ContainerUtil;
|
||||
@@ -31,38 +33,31 @@ public class MultiActionCodeProcessorTest extends LightPlatformCodeInsightFixtur
|
||||
|
||||
@Override
|
||||
protected String getTestDataPath() {
|
||||
return JavaTestUtil.getJavaTestDataPath() + "/actions/codeProcessor/";
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setUp() throws Exception {
|
||||
super.setUp();
|
||||
return JavaTestUtil.getJavaTestDataPath() + "/actions/reformatFileInEditor/";
|
||||
}
|
||||
|
||||
@Override
|
||||
public void tearDown() throws Exception {
|
||||
myFixture.getFile().putUserData(FormatChangedTextUtil.CHANGED_RANGES, null);
|
||||
myFixture.getFile().putUserData(FormatChangedTextUtil.TEST_REVISION_CONTENT, null);
|
||||
super.tearDown();
|
||||
}
|
||||
|
||||
public void doTest(LayoutCodeOptions options) {
|
||||
myFixture.configureByFile(getTestDataPath() + getTestName(true) + "_before.java");
|
||||
CodeProcessor processor = new CodeProcessor(myFixture.getFile(), myFixture.getEditor(), options);
|
||||
|
||||
CharSequence revisionContent = null;
|
||||
if (options.getTextRangeType() == VCS_CHANGED_TEXT) {
|
||||
CaretModel model = myFixture.getEditor().getCaretModel();
|
||||
List<TextRange> ranges = ContainerUtil.mapNotNull(model.getAllCarets(), new Function<Caret, TextRange>() {
|
||||
@Override
|
||||
public TextRange fun(Caret caret) {
|
||||
if (caret.hasSelection()) {
|
||||
return new TextRange(caret.getSelectionStart(), caret.getSelectionEnd());
|
||||
}
|
||||
return null;
|
||||
}
|
||||
});
|
||||
myFixture.getFile().putUserData(FormatChangedTextUtil.CHANGED_RANGES, ranges);
|
||||
myFixture.configureByFile(getTestName(true) + "_revision.java");
|
||||
PsiFile file = myFixture.getFile();
|
||||
Document document = myFixture.getDocument(file);
|
||||
revisionContent = document.getCharsSequence();
|
||||
}
|
||||
|
||||
myFixture.configureByFile(getTestName(true) + "_before.java");
|
||||
if (revisionContent != null) {
|
||||
myFixture.getFile().putUserData(FormatChangedTextUtil.TEST_REVISION_CONTENT, revisionContent);
|
||||
}
|
||||
|
||||
CodeProcessor processor = new CodeProcessor(myFixture.getFile(), myFixture.getEditor(), options);
|
||||
|
||||
processor.processCode();
|
||||
myFixture.checkResultByFile(getTestName(true) + "_after.java");
|
||||
}
|
||||
@@ -75,10 +70,6 @@ public class MultiActionCodeProcessorTest extends LightPlatformCodeInsightFixtur
|
||||
doTest(new ReformatCodeRunOptions(WHOLE_FILE));
|
||||
}
|
||||
|
||||
public void testVcsChangedTextReformat() {
|
||||
doTest(new ReformatCodeRunOptions(VCS_CHANGED_TEXT));
|
||||
}
|
||||
|
||||
public void testWholeFileReformatAndOptimize() {
|
||||
doTest(new ReformatCodeRunOptions(WHOLE_FILE).setOptimizeImports(true));
|
||||
}
|
||||
@@ -87,7 +78,35 @@ public class MultiActionCodeProcessorTest extends LightPlatformCodeInsightFixtur
|
||||
doTest(new ReformatCodeRunOptions(SELECTED_TEXT).setOptimizeImports(true));
|
||||
}
|
||||
|
||||
//public void testVcsChangedTextReformatAndOptimize() {
|
||||
// doTest(new ReformatCodeRunOptions(VCS_CHANGED_TEXT).setOptimizeImports(true));
|
||||
//}
|
||||
public void testFormatWholeFile() {
|
||||
doTest(new ReformatCodeRunOptions(WHOLE_FILE));
|
||||
}
|
||||
|
||||
public void testFormatOptimizeWholeFile() {
|
||||
doTest(new ReformatCodeRunOptions(WHOLE_FILE).setOptimizeImports(true));
|
||||
}
|
||||
|
||||
public void testFormatOptimizeRearrangeWholeFile() {
|
||||
doTest(new ReformatCodeRunOptions(WHOLE_FILE).setOptimizeImports(true).setRearrangeCode(true));
|
||||
}
|
||||
|
||||
public void testFormatSelection() {
|
||||
doTest(new ReformatCodeRunOptions(SELECTED_TEXT));
|
||||
}
|
||||
|
||||
public void testFormatRearrangeSelection() {
|
||||
doTest(new ReformatCodeRunOptions(SELECTED_TEXT).setRearrangeCode(true));
|
||||
}
|
||||
|
||||
public void testFormatVcsChanges() {
|
||||
doTest(new ReformatCodeRunOptions(VCS_CHANGED_TEXT));
|
||||
}
|
||||
|
||||
public void testFormatOptimizeVcsChanges() {
|
||||
doTest(new ReformatCodeRunOptions(VCS_CHANGED_TEXT).setOptimizeImports(true));
|
||||
}
|
||||
|
||||
public void testFormatOptimizeRearrangeVcsChanges() {
|
||||
doTest(new ReformatCodeRunOptions(VCS_CHANGED_TEXT).setOptimizeImports(true).setRearrangeCode(true));
|
||||
}
|
||||
}
|
||||
|
||||
-121
@@ -1,121 +0,0 @@
|
||||
/*
|
||||
* 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.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package com.intellij.codeInsight.actions;
|
||||
|
||||
import com.intellij.JavaTestUtil;
|
||||
import com.intellij.openapi.actionSystem.*;
|
||||
import com.intellij.openapi.editor.Document;
|
||||
import com.intellij.openapi.editor.Editor;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.openapi.vcs.FilePath;
|
||||
import com.intellij.openapi.vcs.VcsException;
|
||||
import com.intellij.openapi.vcs.changes.Change;
|
||||
import com.intellij.openapi.vcs.changes.ContentRevision;
|
||||
import com.intellij.openapi.vcs.history.VcsRevisionNumber;
|
||||
import com.intellij.psi.PsiFile;
|
||||
import com.intellij.testFramework.fixtures.LightCodeInsightFixtureTestCase;
|
||||
import org.jetbrains.annotations.NonNls;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
public class ReformatCodeActionInEditorTest extends LightCodeInsightFixtureTestCase {
|
||||
|
||||
@Override
|
||||
protected String getTestDataPath() {
|
||||
return JavaTestUtil.getJavaTestDataPath() + "/actions/reformatFileInEditor/";
|
||||
}
|
||||
|
||||
public void doTest(@NotNull ReformatFilesOptions options) {
|
||||
setOptions(options);
|
||||
|
||||
String before = null;
|
||||
if (options.isProcessOnlyChangedText()) {
|
||||
myFixture.configureByFile(getTestName(true) + "_revision.java");
|
||||
PsiFile file = myFixture.getFile();
|
||||
Document document = myFixture.getDocument(file);
|
||||
before = document.getText();
|
||||
}
|
||||
|
||||
myFixture.configureByFile(getTestName(true) + "_before.java");
|
||||
|
||||
if (before != null) {
|
||||
myFixture.getFile().putUserData(FormatChangedTextUtil.TEST_REVISION_CONTENT, before);
|
||||
}
|
||||
|
||||
final String actionId = IdeActions.ACTION_EDITOR_REFORMAT;
|
||||
AnAction action = ActionManager.getInstance().getAction(actionId);
|
||||
|
||||
AnActionEvent event = createEventFor(action, getProject(), myFixture.getEditor());
|
||||
|
||||
action.actionPerformed(event);
|
||||
myFixture.checkResultByFile(getTestName(true) + "_after.java");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void tearDown() throws Exception {
|
||||
myFixture.getFile().putUserData(FormatChangedTextUtil.TEST_REVISION_CONTENT, null);
|
||||
super.tearDown();
|
||||
}
|
||||
|
||||
protected AnActionEvent createEventFor(@NotNull AnAction action, @NotNull final Project project, @NotNull final Editor editor) {
|
||||
return new AnActionEvent(null, new DataContext() {
|
||||
@Nullable
|
||||
@Override
|
||||
public Object getData(@NonNls String dataId) {
|
||||
if (CommonDataKeys.PROJECT.is(dataId)) return project;
|
||||
if (CommonDataKeys.EDITOR.is(dataId)) return editor;
|
||||
return null;
|
||||
}
|
||||
}, "", action.getTemplatePresentation(), ActionManager.getInstance(), 0);
|
||||
}
|
||||
|
||||
protected void setOptions(ReformatFilesOptions options) {
|
||||
ReformatCodeAction.setTestOptions(options);
|
||||
}
|
||||
|
||||
public void testFormatWholeFile() {
|
||||
doTest(new MockReformatFileSettings().setProcessWholeFile(true));
|
||||
}
|
||||
|
||||
public void testFormatOptimizeWholeFile() {
|
||||
doTest(new MockReformatFileSettings().setProcessWholeFile(true).setOptimizeImports(true));
|
||||
}
|
||||
|
||||
public void testFormatOptimizeRearrangeWholeFile() {
|
||||
doTest(new MockReformatFileSettings().setProcessWholeFile(true).setOptimizeImports(true).setRearrange(true));
|
||||
}
|
||||
|
||||
public void testFormatSelection() {
|
||||
doTest(new MockReformatFileSettings().setProcessWholeFile(false));
|
||||
}
|
||||
|
||||
public void testFormatRearrangeSelection() {
|
||||
doTest(new MockReformatFileSettings().setProcessWholeFile(false).setRearrange(true));
|
||||
}
|
||||
|
||||
public void testFormatVcsChanges() {
|
||||
doTest(new MockReformatFileSettings().setProcessOnlyChangedText(true));
|
||||
}
|
||||
|
||||
public void testFormatOptimizeVcsChanges() {
|
||||
doTest(new MockReformatFileSettings().setProcessOnlyChangedText(true).setOptimizeImports(true));
|
||||
}
|
||||
|
||||
public void testFormatOptimizeRearrangeVcsChanges() {
|
||||
doTest(new MockReformatFileSettings().setProcessOnlyChangedText(true).setOptimizeImports(true).setRearrange(true));
|
||||
}
|
||||
|
||||
}
|
||||
+1
-30
@@ -34,30 +34,11 @@ public class ReformatCodeActionTest extends AbstractLayoutCodeProcessorTest {
|
||||
|
||||
public void testReformatAndOptimizeMultipleFiles() throws IOException {
|
||||
List<PsiFile> files = createTestFiles(getTempRootDirectory(), classNames);
|
||||
|
||||
//todo mock this guy
|
||||
//LastRunReformatCodeOptionsProvider provider = new LastRunReformatCodeOptionsProvider(PropertiesComponent.getInstance());
|
||||
|
||||
injectMockDialogFlags(new MockReformatFileSettings().setOptimizeImports(true));
|
||||
performReformatActionOnSelectedFiles(files);
|
||||
checkFormationAndImportsOptimizationFor(files);
|
||||
}
|
||||
|
||||
public void testReformatSingleSelected_FileWithoutEditor() throws IOException {
|
||||
//todo fill
|
||||
}
|
||||
|
||||
public void testReformatAndOptimizeFileFromEditor() throws IOException {
|
||||
List<PsiFile> files = createTestFiles(getTempRootDirectory(), classNames);
|
||||
injectMockDialogFlags(new MockReformatFileSettings().setOptimizeImports(true));
|
||||
|
||||
PsiFile fileToFormat = files.get(0);
|
||||
List<PsiFile> shouldNotBeFormatted = files.subList(1, files.size());
|
||||
|
||||
performReformatActionOnFileInEditor(fileToFormat);
|
||||
checkFormationAndImportsOptimizationFor(Arrays.asList(fileToFormat));
|
||||
checkNoProcessingWasPerformedOn(shouldNotBeFormatted);
|
||||
}
|
||||
|
||||
public void testOptimizeAndReformatOnlySelectedFiles() throws IOException {
|
||||
List<PsiFile> files = createTestFiles(getTempRootDirectory(), classNames);
|
||||
List<PsiFile> forProcessing = ContainerUtil.newArrayList(files.get(0), files.get(1));
|
||||
@@ -71,10 +52,6 @@ public class ReformatCodeActionTest extends AbstractLayoutCodeProcessorTest {
|
||||
checkNoProcessingWasPerformedOn(noProcessing);
|
||||
}
|
||||
|
||||
public void testOptimizeAndReformat_AllFilesInDirectoryIncludeSubdirs() throws IOException {
|
||||
//todo create tests for AbstractLayoutCodeProcessor
|
||||
}
|
||||
|
||||
public void testOptimizeAndReformatInModule() throws IOException {
|
||||
Module module = createModuleWithSourceRoot("newModule");
|
||||
VirtualFile srcDir = ModuleRootManager.getInstance(module).getSourceRoots()[0];
|
||||
@@ -85,10 +62,4 @@ public class ReformatCodeActionTest extends AbstractLayoutCodeProcessorTest {
|
||||
|
||||
checkFormationAndImportsOptimizationFor(files);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -54,9 +54,8 @@ import org.jetbrains.annotations.Nullable;
|
||||
import java.util.*;
|
||||
|
||||
public class FormatChangedTextUtil {
|
||||
public static final Key<String> TEST_REVISION_CONTENT = Key.create("test.revision.content");
|
||||
public static final Key<CharSequence> TEST_REVISION_CONTENT = Key.create("test.revision.content");
|
||||
private static final Logger LOG = Logger.getInstance("#com.intellij.codeInsight.actions.FormatChangedTextUtil");
|
||||
protected static final Key<List<TextRange>> CHANGED_RANGES = Key.create("changed.ranges.since.last.revision");
|
||||
|
||||
|
||||
private FormatChangedTextUtil() {
|
||||
@@ -234,15 +233,18 @@ public class FormatChangedTextUtil {
|
||||
|
||||
@NotNull
|
||||
public static List<TextRange> getChangedTextRanges(@NotNull Project project, @NotNull PsiFile file) throws FilesTooBigForDiffException {
|
||||
List<TextRange> cachedChangedLines = getCachedChangedLines(project, file);
|
||||
Document document = PsiDocumentManager.getInstance(project).getDocument(file);
|
||||
if (document == null) return ContainerUtil.emptyList();
|
||||
|
||||
List<TextRange> cachedChangedLines = getCachedChangedLines(project, document);
|
||||
if (cachedChangedLines != null) {
|
||||
return cachedChangedLines;
|
||||
}
|
||||
|
||||
if (ApplicationManager.getApplication().isUnitTestMode()) {
|
||||
String testContent = file.getUserData(TEST_REVISION_CONTENT);
|
||||
CharSequence testContent = file.getUserData(TEST_REVISION_CONTENT);
|
||||
if (testContent != null) {
|
||||
return calculateChangedTextRanges(file.getProject(), file, testContent);
|
||||
return calculateChangedTextRanges(document, testContent);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+3
-15
@@ -47,25 +47,13 @@ public class RearrangeCodeProcessor extends AbstractLayoutCodeProcessor {
|
||||
super(previousProcessor, COMMAND_NAME, PROGRESS_TEXT);
|
||||
}
|
||||
|
||||
public RearrangeCodeProcessor(@NotNull AbstractLayoutCodeProcessor previousProcessor, @NotNull SelectionModel model) {
|
||||
super(previousProcessor, COMMAND_NAME, PROGRESS_TEXT);
|
||||
mySelectionModel = model;
|
||||
}
|
||||
|
||||
public RearrangeCodeProcessor(@NotNull PsiFile file,
|
||||
@NotNull SelectionModel selectionModel)
|
||||
{
|
||||
super(file.getProject(), file, PROGRESS_TEXT, COMMAND_NAME, false);
|
||||
|
||||
public RearrangeCodeProcessor(@NotNull AbstractLayoutCodeProcessor previousProcessor, @NotNull SelectionModel selectionModel) {
|
||||
super(previousProcessor, COMMAND_NAME, PROGRESS_TEXT);
|
||||
mySelectionModel = selectionModel;
|
||||
}
|
||||
|
||||
public RearrangeCodeProcessor(@NotNull Project project,
|
||||
@NotNull PsiFile file,
|
||||
@Nullable SelectionModel selectionModel) {
|
||||
super(project, file, PROGRESS_TEXT, COMMAND_NAME, false);
|
||||
|
||||
public RearrangeCodeProcessor(@NotNull PsiFile file, @NotNull SelectionModel selectionModel) {
|
||||
super(file.getProject(), file, PROGRESS_TEXT, COMMAND_NAME, false);
|
||||
mySelectionModel = selectionModel;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user