mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-04-30 10:20:15 +07:00
Application.assertWriteAccess does really assert in tests,
tests now run in EDT
This commit is contained in:
@@ -21,6 +21,7 @@ import com.intellij.openapi.command.WriteCommandAction;
|
||||
import com.intellij.openapi.fileTypes.FileTypeManager;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.testFramework.PlatformTestCase;
|
||||
import com.intellij.testFramework.UsefulTestCase;
|
||||
import com.intellij.testFramework.fixtures.CodeInsightTestFixture;
|
||||
import com.intellij.testFramework.fixtures.IdeaProjectTestFixture;
|
||||
import com.intellij.testFramework.fixtures.IdeaTestFixtureFactory;
|
||||
@@ -30,7 +31,7 @@ import org.intellij.lang.regexp.RegExpFileType;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
public abstract class BaseParseTestcase extends TestCase {
|
||||
public abstract class BaseParseTestcase extends UsefulTestCase{
|
||||
protected CodeInsightTestFixture myFixture;
|
||||
|
||||
@SuppressWarnings({"JUnitTestCaseWithNonTrivialConstructors"})
|
||||
|
||||
@@ -32,6 +32,8 @@ import com.intellij.diagnostic.IdeErrorsDialog;
|
||||
import com.intellij.diagnostic.PluginException;
|
||||
import com.intellij.openapi.application.ApplicationManager;
|
||||
import com.intellij.openapi.application.ModalityState;
|
||||
import com.intellij.openapi.application.Result;
|
||||
import com.intellij.openapi.application.WriteAction;
|
||||
import com.intellij.openapi.compiler.*;
|
||||
import com.intellij.openapi.compiler.Compiler;
|
||||
import com.intellij.openapi.compiler.ex.CompileContextEx;
|
||||
@@ -108,8 +110,8 @@ public class CompileDriver {
|
||||
private final Map<Module, String> myModuleOutputPaths = new HashMap<Module, String>();
|
||||
private final Map<Module, String> myModuleTestOutputPaths = new HashMap<Module, String>();
|
||||
|
||||
private static final String VERSION_FILE_NAME = "version.dat";
|
||||
private static final String LOCK_FILE_NAME = "in_progress.dat";
|
||||
@NonNls private static final String VERSION_FILE_NAME = "version.dat";
|
||||
@NonNls private static final String LOCK_FILE_NAME = "in_progress.dat";
|
||||
|
||||
private static final boolean GENERATE_CLASSPATH_INDEX = "true".equals(System.getProperty("generate.classpath.index"));
|
||||
private static final String PROP_PERFORM_INITIAL_REFRESH = "compiler.perform.outputs.refresh.on.start";
|
||||
@@ -398,10 +400,11 @@ public class CompileDriver {
|
||||
final CompilerMessage message,
|
||||
final boolean checkCachesVersion,
|
||||
final boolean trackDependencies) {
|
||||
ApplicationManager.getApplication().assertIsDispatchThread();
|
||||
final CompilerTask compileTask = new CompilerTask(myProject, CompilerWorkspaceConfiguration.getInstance(myProject).COMPILE_IN_BACKGROUND,
|
||||
forceCompile
|
||||
? CompilerBundle.message("compiler.content.name.compile")
|
||||
: CompilerBundle.message("compiler.content.name.make"), false);
|
||||
: CompilerBundle.message("compiler.content.name.make"), ApplicationManager.getApplication().isUnitTestMode());
|
||||
final WindowManager windowManager = WindowManager.getInstance();
|
||||
if (windowManager != null) {
|
||||
windowManager.getStatusBar(myProject).setInfo("");
|
||||
@@ -501,6 +504,7 @@ public class CompileDriver {
|
||||
status = doCompile(compileContext, isRebuild, forceCompile, trackDependencies, false);
|
||||
}
|
||||
catch (Throwable ex) {
|
||||
if (ApplicationManager.getApplication().isUnitTestMode()) throw new RuntimeException(ex);
|
||||
wereExceptions = true;
|
||||
final PluginId pluginId = IdeErrorsDialog.findPluginId(ex);
|
||||
|
||||
@@ -530,7 +534,9 @@ public class CompileDriver {
|
||||
}
|
||||
else {
|
||||
final long duration = System.currentTimeMillis() - compileContext.getStartCompilationStamp();
|
||||
writeStatus(new CompileStatus(CompilerConfigurationImpl.DEPENDENCY_FORMAT_VERSION, wereExceptions, vfsTimestamp), compileContext);
|
||||
if (!myProject.isDisposed()) {
|
||||
writeStatus(new CompileStatus(CompilerConfigurationImpl.DEPENDENCY_FORMAT_VERSION, wereExceptions, vfsTimestamp), compileContext);
|
||||
}
|
||||
ApplicationManager.getApplication().invokeLater(new Runnable() {
|
||||
public void run() {
|
||||
final int errorCount = compileContext.getMessageCount(CompilerMessageCategory.ERROR);
|
||||
@@ -1670,13 +1676,13 @@ public class CompileDriver {
|
||||
final List<Trinity<File, String, Boolean>> toDelete = new ArrayList<Trinity<File, String, Boolean>>();
|
||||
context.getProgressIndicator().pushState();
|
||||
|
||||
final boolean[] wereFilesDeleted = new boolean[]{false};
|
||||
final boolean[] wereFilesDeleted = {false};
|
||||
try {
|
||||
ApplicationManager.getApplication().runReadAction(new Runnable() {
|
||||
public void run() {
|
||||
|
||||
TranslatingCompilerFilesMonitor.getInstance().collectFiles(
|
||||
context, compiler, srcSnapshot.iterator(), forceCompile, isRebuild, toCompile, toDelete
|
||||
context, compiler, srcSnapshot.iterator(), forceCompile, isRebuild, toCompile, toDelete
|
||||
);
|
||||
if (trackDependencies && !toCompile.isEmpty()) { // should add dependent files
|
||||
// todo: drop this?
|
||||
@@ -1946,7 +1952,7 @@ public class CompileDriver {
|
||||
return true;
|
||||
}
|
||||
CompilerUtil.runInContext(context, CompilerBundle.message("progress.updating.caches"), new ThrowableRunnable<IOException>() {
|
||||
public void run() throws IOException {
|
||||
public void run() {
|
||||
final List<VirtualFile> vFiles = new ArrayList<VirtualFile>(processed.length);
|
||||
for (FileProcessingCompiler.ProcessingItem aProcessed : processed) {
|
||||
final VirtualFile file = aProcessed.getFile();
|
||||
@@ -2142,17 +2148,22 @@ public class CompileDriver {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
final Boolean refreshSuccess = ApplicationManager.getApplication().runWriteAction(new Computable<Boolean>() {
|
||||
public Boolean compute() {
|
||||
LocalFileSystem.getInstance().refreshIoFiles(nonExistingOutputPaths);
|
||||
for (File file : nonExistingOutputPaths) {
|
||||
if (LocalFileSystem.getInstance().findFileByIoFile(file) == null) {
|
||||
return Boolean.FALSE;
|
||||
final Boolean refreshSuccess =
|
||||
new WriteAction<Boolean>() {
|
||||
@Override
|
||||
protected void run(Result<Boolean> result) throws Throwable {
|
||||
LocalFileSystem.getInstance().refreshIoFiles(nonExistingOutputPaths);
|
||||
Boolean res = Boolean.TRUE;
|
||||
for (File file : nonExistingOutputPaths) {
|
||||
if (LocalFileSystem.getInstance().findFileByIoFile(file) == null) {
|
||||
res = Boolean.FALSE;
|
||||
break;
|
||||
}
|
||||
}
|
||||
result.setResult(res);
|
||||
}
|
||||
return Boolean.TRUE;
|
||||
}
|
||||
});
|
||||
}.execute().getResultObject();
|
||||
|
||||
if (!refreshSuccess.booleanValue()) {
|
||||
return false;
|
||||
}
|
||||
@@ -2418,7 +2429,7 @@ public class CompileDriver {
|
||||
|
||||
private TranslatorsOutputSink(CompileContextEx context, TranslatingCompiler[] compilers) {
|
||||
myContext = context;
|
||||
this.myCompilers = compilers;
|
||||
myCompilers = compilers;
|
||||
}
|
||||
|
||||
public void setCurrentCompilerIndex(int index) {
|
||||
@@ -2460,7 +2471,8 @@ public class CompileDriver {
|
||||
TranslatingCompiler.OutputItem item = it.next();
|
||||
boolean shouldPostpone = false;
|
||||
for (int idx = nextCompilerIdx; idx < myCompilers.length; idx++) {
|
||||
if (shouldPostpone = myCompilers[idx].isCompilableFile(item.getSourceFile(), myContext)) {
|
||||
shouldPostpone = myCompilers[idx].isCompilableFile(item.getSourceFile(), myContext);
|
||||
if (shouldPostpone) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
@@ -2475,7 +2487,8 @@ public class CompileDriver {
|
||||
for (TranslatingCompiler.OutputItem item : items) {
|
||||
boolean shouldPostpone = false;
|
||||
for (int idx = nextCompilerIdx; idx < myCompilers.length; idx++) {
|
||||
if (shouldPostpone = myCompilers[idx].isCompilableFile(item.getSourceFile(), myContext)) {
|
||||
shouldPostpone = myCompilers[idx].isCompilableFile(item.getSourceFile(), myContext);
|
||||
if (shouldPostpone) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -99,7 +99,7 @@ public class CompilerTask extends Task.Backgroundable {
|
||||
super(project, contentName);
|
||||
myIsBackgroundMode = compileInBackground;
|
||||
myContentName = contentName;
|
||||
myHeadlessMode = headlessMode || IS_UNIT_TEST_MODE;
|
||||
myHeadlessMode = headlessMode;
|
||||
myIdeFrame = (IdeFrame)WindowManager.getInstance().getFrame(myProject);
|
||||
}
|
||||
|
||||
@@ -172,6 +172,7 @@ public class CompilerTask extends Task.Backgroundable {
|
||||
|
||||
ApplicationManager.getApplication().invokeLater(new Runnable() {
|
||||
public void run() {
|
||||
if (myProject.isDisposed()) return;
|
||||
//if (myIsBackgroundMode) {
|
||||
// openMessageView();
|
||||
//}
|
||||
@@ -189,7 +190,9 @@ public class CompilerTask extends Task.Backgroundable {
|
||||
}
|
||||
|
||||
private void addIndicatorDelegate() {
|
||||
((ProgressIndicatorEx)myIndicator).addStateDelegate(new ProgressIndicatorBase() {
|
||||
ProgressIndicator indicator = myIndicator;
|
||||
if (!(indicator instanceof ProgressIndicatorEx)) return;
|
||||
((ProgressIndicatorEx)indicator).addStateDelegate(new ProgressIndicatorBase() {
|
||||
|
||||
public void cancel() {
|
||||
super.cancel();
|
||||
|
||||
@@ -97,7 +97,9 @@ public class CompilerPaths {
|
||||
return project.getName();
|
||||
}
|
||||
|
||||
String projectName = FileUtil.toSystemIndependentName(project.getLocation());
|
||||
String location = project.getLocation();
|
||||
if (location == null) return null;
|
||||
String projectName = FileUtil.toSystemIndependentName(location);
|
||||
if (projectName.endsWith("/")) {
|
||||
projectName = projectName.substring(0, projectName.length() - 1);
|
||||
}
|
||||
|
||||
@@ -302,7 +302,7 @@ public class CreateFromUsageUtils {
|
||||
final Module module = ModuleUtil.findModuleForPsiElement(sourceFile);
|
||||
PsiPackage aPackage = null;
|
||||
if (qualifierElement instanceof PsiPackage) {
|
||||
aPackage = ((PsiPackage)qualifierElement);
|
||||
aPackage = (PsiPackage)qualifierElement;
|
||||
}
|
||||
else {
|
||||
final PsiDirectory directory = sourceFile.getContainingDirectory();
|
||||
|
||||
@@ -2,13 +2,13 @@
|
||||
enum I {
|
||||
A {
|
||||
void m() {
|
||||
<selection>System.out.println("");</selection>
|
||||
<selection>System.out.println("");</selection>
|
||||
}
|
||||
},
|
||||
B {
|
||||
public void m(){
|
||||
System.out.println("");
|
||||
}
|
||||
};
|
||||
abstract void m();
|
||||
B {
|
||||
public void m() {
|
||||
System.out.println("");
|
||||
}
|
||||
};
|
||||
abstract void m();
|
||||
}
|
||||
|
||||
@@ -1,10 +1,10 @@
|
||||
// "Use existing implementation of 'm'" "true"
|
||||
enum I {
|
||||
A,
|
||||
B {
|
||||
public void m(){
|
||||
System.out.println("");
|
||||
}
|
||||
};
|
||||
abstract void <caret>m();
|
||||
A,
|
||||
B {
|
||||
public void m() {
|
||||
System.out.println("");
|
||||
}
|
||||
};
|
||||
abstract void <caret>m();
|
||||
}
|
||||
|
||||
@@ -9,6 +9,6 @@ class Child extends Parent {
|
||||
}
|
||||
|
||||
void bar() {
|
||||
foo(1.0, "aaa");
|
||||
foo(1.0, "aaa");
|
||||
}
|
||||
}
|
||||
@@ -9,6 +9,6 @@ class Child extends Parent {
|
||||
}
|
||||
|
||||
void bar() {
|
||||
foo(1,);
|
||||
foo(1, );
|
||||
}
|
||||
}
|
||||
@@ -10,5 +10,4 @@ class Test {
|
||||
}
|
||||
}.InnerClass(i, j);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -7,5 +7,4 @@ class Test {
|
||||
}
|
||||
}.InnerClass(i);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -5,6 +5,7 @@ import com.intellij.codeInsight.CodeInsightSettings;
|
||||
import com.intellij.codeInsight.lookup.Lookup;
|
||||
import com.intellij.codeInsight.lookup.LookupManager;
|
||||
import com.intellij.codeInsight.lookup.impl.LookupManagerImpl;
|
||||
import com.intellij.openapi.command.WriteCommandAction;
|
||||
import com.intellij.openapi.module.JavaModuleType;
|
||||
import com.intellij.openapi.module.Module;
|
||||
import com.intellij.openapi.module.ModuleManager;
|
||||
@@ -237,8 +238,14 @@ public class ClassNameCompletionTest extends CompletionTestCase {
|
||||
}
|
||||
|
||||
public void testQualifyNameOnSecondCompletion() throws Throwable {
|
||||
final Module module = ModuleManager.getInstance(getProject()).newModule("second.iml", new JavaModuleType());
|
||||
createClass(module, "package foo.bar; class AxBxCxDxEx {}");
|
||||
new WriteCommandAction.Simple(getProject()) {
|
||||
@Override
|
||||
protected void run() throws Throwable {
|
||||
final Module module = ModuleManager.getInstance(getProject()).newModule("second.iml", new JavaModuleType());
|
||||
createClass(module, "package foo.bar; class AxBxCxDxEx {}");
|
||||
}
|
||||
}.execute().throwException();
|
||||
|
||||
configureByFileNoCompletion(BASE_PATH + "/nameCompletion/java/" + getTestName(false) + "-source.java");
|
||||
new CodeCompletionHandlerBase(CompletionType.CLASS_NAME).invokeCompletion(myProject, myEditor, myFile, 2);
|
||||
checkResultByFile(BASE_PATH + "/nameCompletion/java/" + getTestName(false) + "-result.java");
|
||||
|
||||
@@ -16,34 +16,62 @@
|
||||
package com.intellij.codeInsight.completion
|
||||
|
||||
import com.intellij.codeInsight.editorActions.CompletionAutoPopupHandler
|
||||
import com.intellij.openapi.application.ApplicationManager
|
||||
import com.intellij.openapi.application.ModalityState
|
||||
import com.intellij.testFramework.fixtures.LightCodeInsightFixtureTestCase
|
||||
import com.intellij.codeInsight.lookup.LookupManager
|
||||
import com.intellij.testFramework.fixtures.LightCodeInsightFixtureTestCase
|
||||
import com.intellij.util.ui.UIUtil
|
||||
|
||||
/**
|
||||
/**
|
||||
* @author peter
|
||||
*/
|
||||
class CompletionAutoPopupTest extends LightCodeInsightFixtureTestCase {
|
||||
@Override protected void setUp() {
|
||||
super.setUp()
|
||||
UIUtil.invokeAndWaitIfNeeded(new Runnable(){
|
||||
@Override
|
||||
void run() {
|
||||
superSetUp()
|
||||
}
|
||||
|
||||
})
|
||||
CompletionAutoPopupHandler.ourTestingAutopopup = true
|
||||
}
|
||||
void superSetUp() {
|
||||
super.setUp()
|
||||
}
|
||||
void superTearDown() {
|
||||
super.tearDown()
|
||||
}
|
||||
|
||||
@Override protected void tearDown() {
|
||||
CompletionAutoPopupHandler.ourTestingAutopopup = false
|
||||
super.tearDown()
|
||||
UIUtil.invokeAndWaitIfNeeded(new Runnable(){
|
||||
@Override
|
||||
void run() {
|
||||
superTearDown()
|
||||
}
|
||||
|
||||
})
|
||||
}
|
||||
|
||||
private type(String s) {
|
||||
myFixture.type(s)
|
||||
ApplicationManager.application.invokeAndWait(({} as Runnable), ModalityState.current())
|
||||
UIUtil.invokeAndWaitIfNeeded(({} as Runnable))
|
||||
}
|
||||
|
||||
@Override protected void runTest() {
|
||||
runTestBare()
|
||||
}
|
||||
|
||||
@Override
|
||||
void runBare() {
|
||||
superRunBare()
|
||||
}
|
||||
|
||||
|
||||
@Override protected void invokeTestRunnable(Runnable runnable) {
|
||||
runnable.run()
|
||||
}
|
||||
|
||||
|
||||
public void testNewItemsOnLongerPrefix() {
|
||||
myFixture.configureByText("a.java", """
|
||||
class Foo {
|
||||
|
||||
@@ -8,6 +8,7 @@ import com.intellij.JavaTestUtil;
|
||||
import com.intellij.codeInsight.lookup.LookupElement;
|
||||
import com.intellij.codeInsight.lookup.LookupManager;
|
||||
import com.intellij.codeInsight.lookup.impl.LookupImpl;
|
||||
import com.intellij.openapi.command.WriteCommandAction;
|
||||
import com.intellij.openapi.roots.ModifiableRootModel;
|
||||
import com.intellij.openapi.roots.ModuleRootManager;
|
||||
import com.intellij.psi.JavaPsiFacade;
|
||||
@@ -24,9 +25,15 @@ public class HeavyNormalCompletionTest extends CompletionTestCase{
|
||||
|
||||
public void testPackagePrefix() throws Throwable {
|
||||
configureByFileNoCompletion("/codeInsight/completion/normal/" + getTestName(false) + ".java");
|
||||
final ModifiableRootModel model = ModuleRootManager.getInstance(getModule()).getModifiableModel();
|
||||
model.getContentEntries()[0].getSourceFolders()[0].setPackagePrefix("foo.bar.goo");
|
||||
model.commit();
|
||||
new WriteCommandAction.Simple(getProject()) {
|
||||
@Override
|
||||
protected void run() throws Throwable {
|
||||
final ModifiableRootModel model = ModuleRootManager.getInstance(getModule()).getModifiableModel();
|
||||
model.getContentEntries()[0].getSourceFolders()[0].setPackagePrefix("foo.bar.goo");
|
||||
model.commit();
|
||||
}
|
||||
}.execute().throwException();
|
||||
|
||||
complete();
|
||||
checkResultByFile("/codeInsight/completion/normal/" + getTestName(false) + "_after.java");
|
||||
assertTrue(JavaPsiFacade.getInstance(myProject).findPackage("foo").isValid());
|
||||
|
||||
@@ -3,6 +3,7 @@ package com.intellij.codeInsight.completion;
|
||||
import com.intellij.codeInsight.lookup.LookupElement;
|
||||
import com.intellij.codeInsight.lookup.LookupManager;
|
||||
import com.intellij.codeInsight.lookup.impl.LookupImpl;
|
||||
import com.intellij.openapi.command.WriteCommandAction;
|
||||
import com.intellij.psi.statistics.StatisticsManager;
|
||||
import com.intellij.psi.statistics.impl.StatisticsManagerImpl;
|
||||
import com.intellij.testFramework.fixtures.LightCodeInsightFixtureTestCase;
|
||||
@@ -43,11 +44,16 @@ public abstract class LightFixtureCompletionTestCase extends LightCodeInsightFix
|
||||
myFixture.checkResultByFile(path);
|
||||
}
|
||||
|
||||
protected void selectItem(LookupElement item, char completionChar) {
|
||||
protected void selectItem(LookupElement item, final char completionChar) {
|
||||
final LookupImpl lookup = getLookup();
|
||||
lookup.setCurrentItem(item);
|
||||
if (completionChar == 0 || completionChar == '\n' || completionChar == '\t') {
|
||||
lookup.finishLookup(completionChar);
|
||||
new WriteCommandAction.Simple(getProject()) {
|
||||
@Override
|
||||
protected void run() throws Throwable {
|
||||
lookup.finishLookup(completionChar);
|
||||
}
|
||||
}.execute().throwException();
|
||||
} else {
|
||||
type(completionChar);
|
||||
}
|
||||
|
||||
@@ -6,6 +6,7 @@ import com.intellij.codeInsight.CodeInsightSettings
|
||||
import com.intellij.codeInsight.lookup.Lookup
|
||||
import com.intellij.codeInsight.lookup.LookupElement
|
||||
import com.intellij.codeInsight.lookup.LookupManager
|
||||
import com.intellij.openapi.command.WriteCommandAction
|
||||
import com.intellij.psi.CommonClassNames
|
||||
import com.intellij.psi.JavaPsiFacade
|
||||
import com.intellij.psi.PsiFile
|
||||
@@ -500,13 +501,24 @@ public class NormalCompletionTest extends LightFixtureCompletionTestCase {
|
||||
configureByFile(getTestName(false) + ".java");
|
||||
final int parametersCount = ((PsiMethod)getLookup().getCurrentItem().getObject()).getParameterList().getParametersCount();
|
||||
assertEquals(0, parametersCount);
|
||||
getLookup().finishLookup(Lookup.NORMAL_SELECT_CHAR);
|
||||
new WriteCommandAction.Simple(getProject(), new PsiFile[0]) {
|
||||
@Override
|
||||
protected void run() throws Throwable {
|
||||
getLookup().finishLookup(Lookup.NORMAL_SELECT_CHAR);
|
||||
}
|
||||
}.execute().throwException();
|
||||
|
||||
checkResultByFile(getTestName(false) + "_after.java");
|
||||
}
|
||||
|
||||
public void testCompletionInsideClassLiteral() throws Throwable {
|
||||
configureByFile(getTestName(false) + ".java");
|
||||
getLookup().finishLookup(Lookup.NORMAL_SELECT_CHAR);
|
||||
new WriteCommandAction.Simple(getProject(), new PsiFile[0]) {
|
||||
@Override
|
||||
protected void run() throws Throwable {
|
||||
getLookup().finishLookup(Lookup.NORMAL_SELECT_CHAR);
|
||||
}
|
||||
}.execute().throwException();
|
||||
checkResultByFile(getTestName(false) + "_after.java");
|
||||
}
|
||||
|
||||
@@ -599,7 +611,12 @@ public class NormalCompletionTest extends LightFixtureCompletionTestCase {
|
||||
complete();
|
||||
assertStringItems("_bar", "_goo", "_foo");
|
||||
getLookup().setCurrentItem(getLookup().getItems().get(2));
|
||||
getLookup().finishLookup(Lookup.NORMAL_SELECT_CHAR);
|
||||
new WriteCommandAction.Simple(getProject(), new PsiFile[0]) {
|
||||
@Override
|
||||
protected void run() throws Throwable {
|
||||
getLookup().finishLookup(Lookup.NORMAL_SELECT_CHAR);
|
||||
}
|
||||
}.execute().throwException();
|
||||
checkResultByFile(getTestName(false) + "_after.java");
|
||||
}
|
||||
|
||||
|
||||
@@ -10,6 +10,7 @@ import com.intellij.codeInspection.unusedImport.UnusedImportLocalInspection;
|
||||
import com.intellij.lang.annotation.HighlightSeverity;
|
||||
import com.intellij.openapi.application.ApplicationManager;
|
||||
import com.intellij.openapi.command.CommandProcessor;
|
||||
import com.intellij.openapi.command.WriteCommandAction;
|
||||
import com.intellij.openapi.command.impl.UndoManagerImpl;
|
||||
import com.intellij.openapi.fileEditor.impl.LoadTextUtil;
|
||||
import com.intellij.openapi.fileTypes.StdFileTypes;
|
||||
@@ -50,7 +51,10 @@ public class ImportHelperTest extends DaemonAnalyzerTestCase {
|
||||
super.tearDown();
|
||||
}
|
||||
|
||||
public void testImportsInsertedAlphabetically() throws Exception {
|
||||
public void testImportsInsertedAlphabetically() throws Throwable {
|
||||
@NonNls String text = "class I {}";
|
||||
final PsiJavaFile file = (PsiJavaFile)configureByText(StdFileTypes.JAVA, text);
|
||||
assertEmpty(filter(doHighlighting(), HighlightSeverity.ERROR));
|
||||
CommandProcessor.getInstance().executeCommand(
|
||||
getProject(), new Runnable() {
|
||||
@Override
|
||||
@@ -59,10 +63,6 @@ public class ImportHelperTest extends DaemonAnalyzerTestCase {
|
||||
@Override
|
||||
public void run() {
|
||||
try {
|
||||
@NonNls String text = "class I {}";
|
||||
PsiJavaFile file = (PsiJavaFile)configureByText(StdFileTypes.JAVA, text);
|
||||
assertEmpty(filter(doHighlighting(), HighlightSeverity.ERROR));
|
||||
|
||||
checkAddImport(file, "java.util.List", "java.util.List");
|
||||
checkAddImport(file, "java.util.ArrayList", "java.util.ArrayList","java.util.List");
|
||||
checkAddImport(file, "java.util.HashMap", "java.util.ArrayList","java.util.HashMap","java.util.List");
|
||||
@@ -82,7 +82,21 @@ public class ImportHelperTest extends DaemonAnalyzerTestCase {
|
||||
}
|
||||
}, "", "");
|
||||
}
|
||||
public void testStaticImportsGrouping() throws Exception {
|
||||
public void testStaticImportsGrouping() throws Throwable {
|
||||
@NonNls String text = "import static java.lang.Math.max;\n" +
|
||||
"import java.util.Map;\n" +
|
||||
"\n" +
|
||||
"import static java.lang.Math.min;\n" +
|
||||
"\n" +
|
||||
"import java.awt.Component;\n" +
|
||||
"\n" +
|
||||
"\n" +
|
||||
"\n" +
|
||||
"import static javax.swing.SwingConstants.CENTER;\n" +
|
||||
"class I {{ max(0, 0); Map.class.hashCode(); min(0,0); Component.class.hashCode(); int i = CENTER; }}";
|
||||
|
||||
final PsiJavaFile file = (PsiJavaFile)configureByText(StdFileTypes.JAVA, text);
|
||||
assertEmpty(filter(doHighlighting(), HighlightSeverity.ERROR));
|
||||
CommandProcessor.getInstance().executeCommand(
|
||||
getProject(), new Runnable() {
|
||||
@Override
|
||||
@@ -91,20 +105,6 @@ public class ImportHelperTest extends DaemonAnalyzerTestCase {
|
||||
@Override
|
||||
public void run() {
|
||||
try {
|
||||
@NonNls String text = "import static java.lang.Math.max;\n" +
|
||||
"import java.util.Map;\n" +
|
||||
"\n" +
|
||||
"import static java.lang.Math.min;\n" +
|
||||
"\n" +
|
||||
"import java.awt.Component;\n" +
|
||||
"\n" +
|
||||
"\n" +
|
||||
"\n" +
|
||||
"import static javax.swing.SwingConstants.CENTER;\n" +
|
||||
"class I {{ max(0, 0); Map.class.hashCode(); min(0,0); Component.class.hashCode(); int i = CENTER; }}";
|
||||
|
||||
PsiJavaFile file = (PsiJavaFile)configureByText(StdFileTypes.JAVA, text);
|
||||
assertEmpty(filter(doHighlighting(), HighlightSeverity.ERROR));
|
||||
|
||||
CodeStyleSettings settings = CodeStyleSettingsManager.getSettings(getProject()).clone();
|
||||
settings.LAYOUT_STATIC_IMPORTS_SEPARATELY = true;
|
||||
@@ -175,7 +175,12 @@ public class ImportHelperTest extends DaemonAnalyzerTestCase {
|
||||
settings.CLASS_COUNT_TO_USE_IMPORT_ON_DEMAND = 2;
|
||||
CodeStyleSettingsManager.getInstance(getProject()).setTemporarySettings(settings);
|
||||
try {
|
||||
JavaCodeStyleManager.getInstance(getProject()).optimizeImports(getFile());
|
||||
new WriteCommandAction.Simple(getProject()) {
|
||||
@Override
|
||||
protected void run() throws Throwable {
|
||||
JavaCodeStyleManager.getInstance(getProject()).optimizeImports(getFile());
|
||||
}
|
||||
}.execute().throwException();
|
||||
}
|
||||
finally {
|
||||
CodeStyleSettingsManager.getInstance(getProject()).dropTemporarySettings();
|
||||
|
||||
@@ -18,6 +18,7 @@ import com.intellij.lang.LanguageAnnotators;
|
||||
import com.intellij.lang.annotation.AnnotationHolder;
|
||||
import com.intellij.lang.annotation.Annotator;
|
||||
import com.intellij.lang.annotation.HighlightSeverity;
|
||||
import com.intellij.openapi.application.ApplicationManager;
|
||||
import com.intellij.openapi.extensions.ExtensionPoint;
|
||||
import com.intellij.openapi.extensions.Extensions;
|
||||
import com.intellij.openapi.fileTypes.StdFileTypes;
|
||||
@@ -29,6 +30,7 @@ import com.intellij.psi.xml.XmlAttribute;
|
||||
import com.intellij.psi.xml.XmlTag;
|
||||
import com.intellij.psi.xml.XmlToken;
|
||||
import com.intellij.psi.xml.XmlTokenType;
|
||||
import com.intellij.util.ui.UIUtil;
|
||||
import org.jdom.Element;
|
||||
import org.jetbrains.annotations.NonNls;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
@@ -279,25 +281,31 @@ public class LightAdvHighlightingTest extends LightDaemonAnalyzerTestCase {
|
||||
assertFalse(list.toString(), list.contains(annotator));
|
||||
}
|
||||
|
||||
public void testSOEForTypeOfHugeBinaryExpression() throws IOException {
|
||||
// todo does not work without nonrecursive reparse
|
||||
public void _testSOEForTypeOfHugeBinaryExpression() throws IOException {
|
||||
configureFromFileText("a.java", "class A { String s = \"\"; }");
|
||||
assertEmpty(filter(doHighlighting(), HighlightSeverity.ERROR));
|
||||
|
||||
PsiField field = ((PsiJavaFile)getFile()).getClasses()[0].getFields()[0];
|
||||
|
||||
PsiDocumentManager.getInstance(getProject()).commitAllDocuments();
|
||||
// have to manipulate PSI, will get SOE in BlockSupportImpl otherwise
|
||||
PsiExpression literal = JavaPsiFacade.getElementFactory(getProject()).createExpressionFromText("\"xxx\"", field);
|
||||
final PsiExpression literal = JavaPsiFacade.getElementFactory(getProject()).createExpressionFromText("\"xxx\"", field);
|
||||
|
||||
PsiBinaryExpression binary = (PsiBinaryExpression)JavaPsiFacade.getElementFactory(getProject()).createExpressionFromText("a+b", field);
|
||||
final PsiBinaryExpression binary = (PsiBinaryExpression)JavaPsiFacade.getElementFactory(getProject()).createExpressionFromText("a+b", field);
|
||||
for (int i=0; i<2000;i++) {
|
||||
PsiExpression expression = field.getInitializer();
|
||||
binary.getLOperand().replace(expression);
|
||||
binary.getROperand().replace(literal);
|
||||
final PsiExpression expression = field.getInitializer();
|
||||
ApplicationManager.getApplication().runWriteAction(new Runnable() {
|
||||
public void run() {
|
||||
binary.getLOperand().replace(expression);
|
||||
binary.getROperand().replace(literal);
|
||||
|
||||
//UIUtil.dispatchAllInvocationEvents();
|
||||
expression.replace(binary);
|
||||
PostprocessReformattingAspect.getInstance(getProject()).clear(); // OOM otherwise
|
||||
}
|
||||
});
|
||||
|
||||
expression.replace(binary);
|
||||
PostprocessReformattingAspect.getInstance(getProject()).clear(); // OOM otherwise
|
||||
UIUtil.dispatchAllInvocationEvents();
|
||||
}
|
||||
|
||||
field.getInitializer().getType(); // SOE
|
||||
|
||||
@@ -3,6 +3,7 @@ package com.intellij.codeInsight.daemon;
|
||||
import com.intellij.codeInsight.daemon.impl.HighlightInfo;
|
||||
import com.intellij.codeInspection.LocalInspectionTool;
|
||||
import com.intellij.codeInspection.unusedSymbol.UnusedSymbolLocalInspection;
|
||||
import com.intellij.openapi.application.ApplicationManager;
|
||||
import com.intellij.openapi.editor.Document;
|
||||
import com.intellij.psi.PsiDocumentManager;
|
||||
import com.intellij.lang.annotation.HighlightSeverity;
|
||||
@@ -23,12 +24,17 @@ public class UnusedSymbolLocalTest extends DaemonAnalyzerTestCase {
|
||||
|
||||
public void testChangeInsideCodeBlock() throws Exception {
|
||||
doTest();
|
||||
Document document = myEditor.getDocument();
|
||||
final Document document = myEditor.getDocument();
|
||||
Collection<HighlightInfo> collection = filter(doHighlighting(), HighlightSeverity.WARNING);
|
||||
assertEquals(0, collection.size());
|
||||
|
||||
int offset = myEditor.getCaretModel().getOffset();
|
||||
document.insertString(offset, "//");
|
||||
final int offset = myEditor.getCaretModel().getOffset();
|
||||
ApplicationManager.getApplication().runWriteAction(new Runnable() {
|
||||
public void run() {
|
||||
document.insertString(offset, "//");
|
||||
}
|
||||
});
|
||||
|
||||
PsiDocumentManager.getInstance(getProject()).commitDocument(document);
|
||||
|
||||
Collection<HighlightInfo> infos = filter(doHighlighting(), HighlightSeverity.WARNING);
|
||||
|
||||
@@ -12,7 +12,6 @@ import com.intellij.openapi.project.ex.ProjectManagerEx;
|
||||
import com.intellij.openapi.roots.ModifiableRootModel;
|
||||
import com.intellij.openapi.roots.ModuleRootManager;
|
||||
import com.intellij.openapi.roots.OrderEntry;
|
||||
import com.intellij.openapi.util.Computable;
|
||||
import com.intellij.openapi.util.Pair;
|
||||
import com.intellij.openapi.util.io.FileUtil;
|
||||
import com.intellij.openapi.vfs.VirtualFile;
|
||||
@@ -32,19 +31,7 @@ public class OrderEntryTest extends DaemonAnalyzerTestCase {
|
||||
protected void setUpProject() throws Exception {
|
||||
final String root = PathManagerEx.getTestDataPath() + BASE_PATH;
|
||||
|
||||
VirtualFile tempProjectRootDir =
|
||||
ApplicationManager.getApplication().runWriteAction(new Computable<VirtualFile>(){
|
||||
@Override
|
||||
public VirtualFile compute() {
|
||||
try {
|
||||
return PsiTestUtil.createTestProjectStructure(getTestName(true), null, FileUtil.toSystemIndependentName(root), myFilesToDelete, false);
|
||||
}
|
||||
catch (Exception e) {
|
||||
LOG.error(e);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
});
|
||||
VirtualFile tempProjectRootDir = PsiTestUtil.createTestProjectStructure(getTestName(true), null, FileUtil.toSystemIndependentName(root), myFilesToDelete, false);
|
||||
|
||||
VirtualFile projectFile = tempProjectRootDir.findChild("orderEntry.ipr");
|
||||
|
||||
@@ -70,7 +57,7 @@ public class OrderEntryTest extends DaemonAnalyzerTestCase {
|
||||
final String text = pair.getFirst();
|
||||
final boolean actionShouldBeAvailable = pair.getSecond().booleanValue();
|
||||
Collection<HighlightInfo> infosBefore = highlightErrors();
|
||||
IntentionAction action = findActionWithText(text, infosBefore);
|
||||
final IntentionAction action = findActionWithText(text, infosBefore);
|
||||
|
||||
if (action == null) {
|
||||
if (actionShouldBeAvailable) {
|
||||
@@ -84,7 +71,12 @@ public class OrderEntryTest extends DaemonAnalyzerTestCase {
|
||||
if (!actionShouldBeAvailable) {
|
||||
fail("Action '" + text + "' is available in test " + testFullPath);
|
||||
}
|
||||
action.invoke(getProject(), getEditor(), getFile());
|
||||
ApplicationManager.getApplication().runWriteAction(new Runnable() {
|
||||
public void run() {
|
||||
action.invoke(getProject(), getEditor(), getFile());
|
||||
}
|
||||
});
|
||||
|
||||
Collection<HighlightInfo> infosAfter = highlightErrors();
|
||||
final IntentionAction afterAction = findActionWithText(text, infosAfter);
|
||||
if (afterAction != null) {
|
||||
@@ -99,14 +91,24 @@ public class OrderEntryTest extends DaemonAnalyzerTestCase {
|
||||
return LightQuickFixTestCase.findActionWithText(actions, actionText);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean isRunInWriteAction() {
|
||||
return false;
|
||||
}
|
||||
|
||||
public void testAddDependency() throws Exception { doTest("B/src/y/AddDependency.java"); }
|
||||
public void testAddLibrary() throws Exception { doTest("B/src/y/AddLibrary.java"); }
|
||||
public void testAddCircularDependency() throws Exception {
|
||||
Module a = ModuleManager.getInstance(getProject()).findModuleByName("A");
|
||||
Module b = ModuleManager.getInstance(getProject()).findModuleByName("B");
|
||||
ModifiableRootModel model = ModuleRootManager.getInstance(a).getModifiableModel();
|
||||
model.addModuleOrderEntry(b);
|
||||
model.commit();
|
||||
final Module a = ModuleManager.getInstance(getProject()).findModuleByName("A");
|
||||
final Module b = ModuleManager.getInstance(getProject()).findModuleByName("B");
|
||||
ApplicationManager.getApplication().runWriteAction(new Runnable() {
|
||||
public void run() {
|
||||
ModifiableRootModel model = ModuleRootManager.getInstance(a).getModifiableModel();
|
||||
model.addModuleOrderEntry(b);
|
||||
model.commit();
|
||||
}
|
||||
});
|
||||
|
||||
try {
|
||||
doTest("B/src/y/AddDependency.java");
|
||||
fail("user should have been warned");
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
|
||||
package com.intellij.codeInsight.daemon.quickFix;
|
||||
|
||||
import com.intellij.openapi.application.ApplicationManager;
|
||||
|
||||
public class VariableAccessFromInnerClassTest extends LightQuickFixTestCase {
|
||||
public void test() throws Exception {
|
||||
doAllTests();
|
||||
@@ -9,7 +11,12 @@ public class VariableAccessFromInnerClassTest extends LightQuickFixTestCase {
|
||||
@Override
|
||||
protected void beforeActionStarted(String testName, String contents) {
|
||||
for (int i=0;i<10;i++) {
|
||||
myEditor.getDocument().insertString(myEditor.getCaretModel().getOffset(), "//");
|
||||
ApplicationManager.getApplication().runWriteAction(new Runnable() {
|
||||
public void run() {
|
||||
myEditor.getDocument().insertString(myEditor.getCaretModel().getOffset(), "//");
|
||||
}
|
||||
});
|
||||
|
||||
doHighlighting();
|
||||
delete();
|
||||
delete();
|
||||
|
||||
@@ -3,6 +3,7 @@ package com.intellij.codeInsight.slice;
|
||||
import com.intellij.analysis.AnalysisScope;
|
||||
import com.intellij.codeInsight.daemon.DaemonAnalyzerTestCase;
|
||||
import com.intellij.codeInsight.daemon.impl.HighlightInfo;
|
||||
import com.intellij.openapi.application.ApplicationManager;
|
||||
import com.intellij.openapi.editor.Document;
|
||||
import com.intellij.openapi.editor.Editor;
|
||||
import com.intellij.openapi.editor.RangeMarker;
|
||||
@@ -125,19 +126,23 @@ public class SliceBackwardTest extends DaemonAnalyzerTestCase {
|
||||
}
|
||||
}
|
||||
|
||||
private static void extract(Document document, Map<String, RangeMarker> sliceUsageName2Offset, String name) {
|
||||
for (int i = 1; i < 9; i++) {
|
||||
String newName = name + i;
|
||||
String s = "<flown" + newName + ">";
|
||||
if (!document.getText().contains(s)) break;
|
||||
int off = document.getText().indexOf(s);
|
||||
private static void extract(final Document document, final Map<String, RangeMarker> sliceUsageName2Offset, final String name) {
|
||||
ApplicationManager.getApplication().runWriteAction(new Runnable() {
|
||||
public void run() {
|
||||
for (int i = 1; i < 9; i++) {
|
||||
String newName = name + i;
|
||||
String s = "<flown" + newName + ">";
|
||||
if (!document.getText().contains(s)) break;
|
||||
int off = document.getText().indexOf(s);
|
||||
|
||||
document.deleteString(off, off + s.length());
|
||||
RangeMarker prev = sliceUsageName2Offset.put(newName, document.createRangeMarker(off, off));
|
||||
assertNull(prev);
|
||||
document.deleteString(off, off + s.length());
|
||||
RangeMarker prev = sliceUsageName2Offset.put(newName, document.createRangeMarker(off, off));
|
||||
assertNull(prev);
|
||||
|
||||
extract(document, sliceUsageName2Offset, newName);
|
||||
}
|
||||
extract(document, sliceUsageName2Offset, newName);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public void testSimple() throws Exception { dotest();}
|
||||
|
||||
@@ -14,9 +14,9 @@ import com.intellij.codeInspection.ex.InspectionProfileImpl;
|
||||
import com.intellij.codeInspection.ex.InspectionToolRegistrar;
|
||||
import com.intellij.openapi.util.JDOMUtil;
|
||||
import com.intellij.profile.codeInspection.InspectionProfileManager;
|
||||
import com.intellij.testFramework.UsefulTestCase;
|
||||
import com.intellij.testFramework.fixtures.IdeaTestFixture;
|
||||
import com.intellij.testFramework.fixtures.JavaTestFixtureFactory;
|
||||
import junit.framework.TestCase;
|
||||
import org.jdom.Document;
|
||||
import org.jdom.Element;
|
||||
import org.jdom.JDOMException;
|
||||
@@ -24,7 +24,7 @@ import org.jdom.JDOMException;
|
||||
import java.io.IOException;
|
||||
import java.io.StringWriter;
|
||||
|
||||
public class InspectionProfileTest extends TestCase {
|
||||
public class InspectionProfileTest extends UsefulTestCase {
|
||||
private static final String PROFILE = "ToConvert";
|
||||
private final IdeaTestFixture myFixture = JavaTestFixtureFactory.getFixtureFactory().createLightFixtureBuilder().getFixture();
|
||||
|
||||
|
||||
@@ -7,6 +7,7 @@ package com.intellij.codeInspection;
|
||||
import com.intellij.JavaTestUtil;
|
||||
import com.intellij.codeInspection.ex.LocalInspectionToolWrapper;
|
||||
import com.intellij.codeInspection.java15api.Java15APIUsageInspection;
|
||||
import com.intellij.openapi.application.ApplicationManager;
|
||||
import com.intellij.openapi.roots.ContentIterator;
|
||||
import com.intellij.openapi.roots.LanguageLevelModuleExtension;
|
||||
import com.intellij.openapi.roots.ModifiableRootModel;
|
||||
@@ -35,19 +36,29 @@ public class JavaAPIUsagesInspectionTest extends InspectionTestCase {
|
||||
}
|
||||
|
||||
public void testConstructor() throws Exception {
|
||||
ModifiableRootModel model = ModuleRootManager.getInstance(getModule()).getModifiableModel();
|
||||
LanguageLevelModuleExtension extension = model.getModuleExtension(LanguageLevelModuleExtension.class);
|
||||
final LanguageLevel languageLevel = extension.getLanguageLevel();
|
||||
final LanguageLevel[] languageLevel = {null};
|
||||
try {
|
||||
extension.setLanguageLevel(LanguageLevel.JDK_1_4);
|
||||
model.commit();
|
||||
ApplicationManager.getApplication().runWriteAction(new Runnable() {
|
||||
public void run() {
|
||||
ModifiableRootModel model = ModuleRootManager.getInstance(getModule()).getModifiableModel();
|
||||
LanguageLevelModuleExtension extension = model.getModuleExtension(LanguageLevelModuleExtension.class);
|
||||
languageLevel[0] = extension.getLanguageLevel();
|
||||
extension.setLanguageLevel(LanguageLevel.JDK_1_4);
|
||||
model.commit();
|
||||
}
|
||||
});
|
||||
|
||||
doTest();
|
||||
}
|
||||
finally {
|
||||
model = ModuleRootManager.getInstance(getModule()).getModifiableModel();
|
||||
extension = model.getModuleExtension(LanguageLevelModuleExtension.class);
|
||||
extension.setLanguageLevel(languageLevel);
|
||||
model.commit();
|
||||
ApplicationManager.getApplication().runWriteAction(new Runnable() {
|
||||
public void run() {
|
||||
ModifiableRootModel model = ModuleRootManager.getInstance(getModule()).getModifiableModel();
|
||||
LanguageLevelModuleExtension extension = model.getModuleExtension(LanguageLevelModuleExtension.class);
|
||||
extension.setLanguageLevel(languageLevel[0]);
|
||||
model.commit();
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -89,4 +100,4 @@ public class JavaAPIUsagesInspectionTest extends InspectionTestCase {
|
||||
final VirtualFile srcFile = JarFileSystem.getInstance().findFileByPath("c:/program files/java/jdk1.6.0_12/src.zip!/");
|
||||
FileIndexImplUtil.iterateRecursively(srcFile, VirtualFileFilter.ALL, contentIterator);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -22,19 +22,9 @@ public class CyclicDependenciesTest extends PsiTestCase {
|
||||
protected void setUp() throws Exception {
|
||||
super.setUp();
|
||||
|
||||
ApplicationManager.getApplication().runWriteAction(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
try {
|
||||
String root = JavaTestUtil.getJavaTestDataPath() + "/dependencies/cycle/" + getTestName(true);
|
||||
PsiTestUtil.removeAllRoots(myModule, JavaSdkImpl.getMockJdk17());
|
||||
PsiTestUtil.createTestProjectStructure(myProject, myModule, root, myFilesToDelete);
|
||||
}
|
||||
catch (Exception e) {
|
||||
LOG.error(e);
|
||||
}
|
||||
}
|
||||
});
|
||||
String root = JavaTestUtil.getJavaTestDataPath() + "/dependencies/cycle/" + getTestName(true);
|
||||
PsiTestUtil.removeAllRoots(myModule, JavaSdkImpl.getMockJdk17());
|
||||
PsiTestUtil.createTestProjectStructure(myProject, myModule, root, myFilesToDelete);
|
||||
}
|
||||
|
||||
public void testT1() {
|
||||
|
||||
@@ -33,21 +33,9 @@ public class UsagesInAnalyzingDependenciesTest extends PsiTestCase{
|
||||
protected void setUp() throws Exception {
|
||||
super.setUp();
|
||||
|
||||
ApplicationManager.getApplication().runWriteAction(
|
||||
new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
try{
|
||||
String root = JavaTestUtil.getJavaTestDataPath() + "/dependencies/search/" + getTestName(true);
|
||||
PsiTestUtil.removeAllRoots(myModule, JavaSdkImpl.getMockJdk17());
|
||||
PsiTestUtil.createTestProjectStructure(myProject, myModule, root, myFilesToDelete);
|
||||
}
|
||||
catch(Exception e){
|
||||
LOG.error(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
);
|
||||
String root = JavaTestUtil.getJavaTestDataPath() + "/dependencies/search/" + getTestName(true);
|
||||
PsiTestUtil.removeAllRoots(myModule, JavaSdkImpl.getMockJdk17());
|
||||
PsiTestUtil.createTestProjectStructure(myProject, myModule, root, myFilesToDelete);
|
||||
}
|
||||
|
||||
public void testForwardPackageScope(){
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package com.intellij.ide.fileTemplates;
|
||||
|
||||
import com.intellij.openapi.application.ApplicationManager;
|
||||
import com.intellij.openapi.application.ex.PathManagerEx;
|
||||
import com.intellij.openapi.roots.ContentEntry;
|
||||
import com.intellij.openapi.roots.ModifiableRootModel;
|
||||
@@ -80,13 +81,18 @@ public class FileTemplatesTest extends IdeaTestCase {
|
||||
File temp = FileUtil.createTempDirectory(getTestName(true), "");
|
||||
|
||||
myFilesToDelete.add(temp);
|
||||
VirtualFile tempDir = LocalFileSystem.getInstance().refreshAndFindFileByIoFile(temp);
|
||||
final VirtualFile tempDir = LocalFileSystem.getInstance().refreshAndFindFileByIoFile(temp);
|
||||
|
||||
final ModuleRootManager rootManager = ModuleRootManager.getInstance(getModule());
|
||||
ApplicationManager.getApplication().runWriteAction(new Runnable() {
|
||||
public void run() {
|
||||
ModifiableRootModel model = rootManager.getModifiableModel();
|
||||
ContentEntry contentEntry = model.addContentEntry(tempDir);
|
||||
contentEntry.addSourceFolder(tempDir, false);
|
||||
model.commit();
|
||||
}
|
||||
});
|
||||
|
||||
ModuleRootManager rootManager = ModuleRootManager.getInstance(getModule());
|
||||
ModifiableRootModel model = rootManager.getModifiableModel();
|
||||
ContentEntry contentEntry = model.addContentEntry(tempDir);
|
||||
contentEntry.addSourceFolder(tempDir, false);
|
||||
model.commit();
|
||||
|
||||
VirtualFile sourceRoot = rootManager.getSourceRoots()[0];
|
||||
PsiDirectory psiDirectory = PsiManager.getInstance(getProject()).findDirectory(sourceRoot);
|
||||
|
||||
@@ -8,6 +8,7 @@ import com.intellij.ide.util.newProjectWizard.AddSupportForFrameworksPanel;
|
||||
import com.intellij.ide.util.newProjectWizard.FrameworkSupportNode;
|
||||
import com.intellij.ide.util.newProjectWizard.impl.FrameworkSupportCommunicator;
|
||||
import com.intellij.ide.util.newProjectWizard.impl.FrameworkSupportModelImpl;
|
||||
import com.intellij.openapi.command.WriteCommandAction;
|
||||
import com.intellij.openapi.roots.ModifiableRootModel;
|
||||
import com.intellij.openapi.roots.ModuleRootManager;
|
||||
import com.intellij.openapi.util.Disposer;
|
||||
@@ -43,28 +44,33 @@ public abstract class FrameworkSupportProviderTestCase extends IdeaTestCase {
|
||||
}
|
||||
|
||||
protected void addSupport() throws IOException {
|
||||
final VirtualFile root = getVirtualFile(createTempDir("contentRoot"));
|
||||
PsiTestUtil.addContentRoot(myModule, root);
|
||||
final ModifiableRootModel model = ModuleRootManager.getInstance(myModule).getModifiableModel();
|
||||
try {
|
||||
List<FrameworkSupportConfigurable> selectedConfigurables = new ArrayList<FrameworkSupportConfigurable>();
|
||||
for (FrameworkSupportNode node : myNodes.values()) {
|
||||
if (node.isChecked()) {
|
||||
final FrameworkSupportConfigurable configurable = getOrCreateConfigurable(node.getProvider());
|
||||
configurable.addSupport(myModule, model, null);
|
||||
selectedConfigurables.add(configurable);
|
||||
new WriteCommandAction.Simple(getProject()) {
|
||||
@Override
|
||||
protected void run() throws Throwable {
|
||||
final VirtualFile root = getVirtualFile(createTempDir("contentRoot"));
|
||||
PsiTestUtil.addContentRoot(myModule, root);
|
||||
final ModifiableRootModel model = ModuleRootManager.getInstance(myModule).getModifiableModel();
|
||||
try {
|
||||
List<FrameworkSupportConfigurable> selectedConfigurables = new ArrayList<FrameworkSupportConfigurable>();
|
||||
for (FrameworkSupportNode node : myNodes.values()) {
|
||||
if (node.isChecked()) {
|
||||
final FrameworkSupportConfigurable configurable = getOrCreateConfigurable(node.getProvider());
|
||||
configurable.addSupport(myModule, model, null);
|
||||
selectedConfigurables.add(configurable);
|
||||
}
|
||||
}
|
||||
for (FrameworkSupportCommunicator communicator : FrameworkSupportCommunicator.EP_NAME.getExtensions()) {
|
||||
communicator.onFrameworkSupportAdded(myModule, model, selectedConfigurables, myFrameworkSupportModel);
|
||||
}
|
||||
}
|
||||
finally {
|
||||
model.commit();
|
||||
}
|
||||
for (FrameworkSupportConfigurable configurable : myConfigurables.values()) {
|
||||
Disposer.dispose(configurable);
|
||||
}
|
||||
}
|
||||
for (FrameworkSupportCommunicator communicator : FrameworkSupportCommunicator.EP_NAME.getExtensions()) {
|
||||
communicator.onFrameworkSupportAdded(myModule, model, selectedConfigurables, myFrameworkSupportModel);
|
||||
}
|
||||
}
|
||||
finally {
|
||||
model.commit();
|
||||
}
|
||||
for (FrameworkSupportConfigurable configurable : myConfigurables.values()) {
|
||||
Disposer.dispose(configurable);
|
||||
}
|
||||
}.execute().throwException();
|
||||
}
|
||||
|
||||
protected FrameworkSupportConfigurable selectFramework(@NotNull FacetTypeId<?> id) {
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package com.intellij.psi;
|
||||
|
||||
import com.intellij.openapi.application.ApplicationManager;
|
||||
import com.intellij.testFramework.LightIdeaTestCase;
|
||||
import com.intellij.testFramework.PsiTestUtil;
|
||||
import com.intellij.util.IncorrectOperationException;
|
||||
@@ -33,28 +34,33 @@ public class AddRemoveInTypeParameterListTest extends LightIdeaTestCase{
|
||||
}
|
||||
|
||||
public void testRemove() throws IncorrectOperationException {
|
||||
PsiJavaFile file = (PsiJavaFile)createLightFile("Test.java", "class Test extends Type<A, B, C, D> {\n}");
|
||||
final PsiJavaFile file = (PsiJavaFile)createLightFile("Test.java", "class Test extends Type<A, B, C, D> {\n}");
|
||||
PsiClass aClass = file.getClasses()[0];
|
||||
PsiJavaCodeReferenceElement ref = aClass.getExtendsList().getReferenceElements()[0];
|
||||
PsiReferenceParameterList list = ref.getParameterList();
|
||||
PsiTypeElement[] parms = list.getTypeParameterElements();
|
||||
final PsiTypeElement[] parms = list.getTypeParameterElements();
|
||||
|
||||
parms[0].delete();
|
||||
ApplicationManager.getApplication().runWriteAction(new Runnable() {
|
||||
public void run() {
|
||||
parms[0].delete();
|
||||
|
||||
assertEquals("class Test extends Type< B, C, D> {\n}", file.getText());
|
||||
PsiTestUtil.checkFileStructure(file);
|
||||
assertEquals("class Test extends Type< B, C, D> {\n}", file.getText());
|
||||
PsiTestUtil.checkFileStructure(file);
|
||||
|
||||
parms[2].delete();
|
||||
parms[2].delete();
|
||||
|
||||
assertEquals("class Test extends Type< B, D> {\n}", file.getText());
|
||||
PsiTestUtil.checkFileStructure(file);
|
||||
assertEquals("class Test extends Type< B, D> {\n}", file.getText());
|
||||
PsiTestUtil.checkFileStructure(file);
|
||||
|
||||
parms[3].delete();
|
||||
parms[3].delete();
|
||||
|
||||
assertEquals("class Test extends Type< B > {\n}", file.getText());
|
||||
PsiTestUtil.checkFileStructure(file);
|
||||
assertEquals("class Test extends Type< B > {\n}", file.getText());
|
||||
PsiTestUtil.checkFileStructure(file);
|
||||
|
||||
parms[1].delete();
|
||||
}
|
||||
});
|
||||
|
||||
parms[1].delete();
|
||||
|
||||
assertEquals("class Test extends Type {\n}", file.getText());
|
||||
PsiTestUtil.checkFileStructure(file);
|
||||
|
||||
@@ -16,7 +16,6 @@ import com.intellij.psi.search.GlobalSearchScope;
|
||||
import com.intellij.refactoring.rename.RenameProcessor;
|
||||
import com.intellij.testFramework.PsiTestCase;
|
||||
import com.intellij.testFramework.PsiTestUtil;
|
||||
import com.intellij.util.IncorrectOperationException;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
@@ -32,21 +31,9 @@ public class ArrayIndexOutOfBoundsTest extends PsiTestCase {
|
||||
protected void setUp() throws Exception {
|
||||
super.setUp();
|
||||
|
||||
ApplicationManager.getApplication().runWriteAction(
|
||||
new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
try{
|
||||
String root = JavaTestUtil.getJavaTestDataPath() + "/psi/arrayIndexOutOfBounds/src";
|
||||
PsiTestUtil.removeAllRoots(myModule, JavaSdkImpl.getMockJdk17());
|
||||
myProjectRoot = PsiTestUtil.createTestProjectStructure(myProject, myModule, root, myFilesToDelete);
|
||||
}
|
||||
catch(Exception e){
|
||||
LOG.error(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
);
|
||||
String root = JavaTestUtil.getJavaTestDataPath() + "/psi/arrayIndexOutOfBounds/src";
|
||||
PsiTestUtil.removeAllRoots(myModule, JavaSdkImpl.getMockJdk17());
|
||||
myProjectRoot = PsiTestUtil.createTestProjectStructure(myProject, myModule, root, myFilesToDelete);
|
||||
}
|
||||
|
||||
public void testSCR10930() throws Exception {
|
||||
@@ -95,14 +82,14 @@ public class ArrayIndexOutOfBoundsTest extends PsiTestCase {
|
||||
Runnable runnable = new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
PsiPackage aPackage = JavaPsiFacade.getInstance(myPsiManager.getProject()).findPackage("anotherBla");
|
||||
final PsiPackage aPackage = JavaPsiFacade.getInstance(myPsiManager.getProject()).findPackage("anotherBla");
|
||||
assertNotNull("Package anotherBla not found", aPackage);
|
||||
try {
|
||||
aPackage.getDirectories()[0].delete();
|
||||
}
|
||||
catch (IncorrectOperationException e) {
|
||||
LOG.error(e);
|
||||
}
|
||||
ApplicationManager.getApplication().runWriteAction(new Runnable() {
|
||||
public void run() {
|
||||
aPackage.getDirectories()[0].delete();
|
||||
}
|
||||
});
|
||||
|
||||
VirtualFileManager.getInstance().refresh(false);
|
||||
}
|
||||
};
|
||||
|
||||
@@ -19,22 +19,9 @@ public class ModifyAnnotationsTest extends PsiTestCase {
|
||||
protected void setUp() throws Exception {
|
||||
super.setUp();
|
||||
|
||||
ApplicationManager.getApplication().runWriteAction(
|
||||
new Runnable() {
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
try {
|
||||
String root = JavaTestUtil.getJavaTestDataPath() + "/psi/repositoryUse/modifyAnnotations";
|
||||
PsiTestUtil.removeAllRoots(myModule, JavaSdkImpl.getMockJdk17("mock 1.5"));
|
||||
PsiTestUtil.createTestProjectStructure(myProject, myModule, root, myFilesToDelete);
|
||||
}
|
||||
catch(Exception e){
|
||||
LOG.error(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
);
|
||||
String root = JavaTestUtil.getJavaTestDataPath() + "/psi/repositoryUse/modifyAnnotations";
|
||||
PsiTestUtil.removeAllRoots(myModule, JavaSdkImpl.getMockJdk17("mock 1.5"));
|
||||
PsiTestUtil.createTestProjectStructure(myProject, myModule, root, myFilesToDelete);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -29,23 +29,10 @@ public class PsiConcurrencyStressTest extends PsiTestCase {
|
||||
protected void setUp() throws Exception {
|
||||
super.setUp();
|
||||
|
||||
ApplicationManager.getApplication().runWriteAction(
|
||||
new Runnable() {
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
try {
|
||||
LanguageLevelProjectExtension.getInstance(myProject).setLanguageLevel(LanguageLevel.JDK_1_5);
|
||||
String root = PathManagerEx.getTestDataPath() + "/psi/repositoryUse/src";
|
||||
PsiTestUtil.removeAllRoots(myModule, JavaSdkImpl.getMockJdk17());
|
||||
PsiTestUtil.createTestProjectStructure(myProject, myModule, root, myFilesToDelete);
|
||||
}
|
||||
catch(Exception e){
|
||||
LOG.error(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
);
|
||||
LanguageLevelProjectExtension.getInstance(myProject).setLanguageLevel(LanguageLevel.JDK_1_5);
|
||||
String root = PathManagerEx.getTestDataPath() + "/psi/repositoryUse/src";
|
||||
PsiTestUtil.removeAllRoots(myModule, JavaSdkImpl.getMockJdk17());
|
||||
PsiTestUtil.createTestProjectStructure(myProject, myModule, root, myFilesToDelete);
|
||||
}
|
||||
|
||||
private PsiJavaFile myFile;
|
||||
@@ -127,7 +114,11 @@ public class PsiConcurrencyStressTest extends PsiTestCase {
|
||||
mark("-");
|
||||
final PsiMethod[] psiMethods = getPsiClass().getMethods();
|
||||
if (psiMethods.length > 0) {
|
||||
psiMethods[random.nextInt(psiMethods.length)].delete();
|
||||
ApplicationManager.getApplication().runWriteAction(new Runnable() {
|
||||
public void run() {
|
||||
psiMethods[random.nextInt(psiMethods.length)].delete();
|
||||
}
|
||||
});
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -35,23 +35,10 @@ public class Src15RepositoryUseTest extends PsiTestCase {
|
||||
protected void setUp() throws Exception {
|
||||
super.setUp();
|
||||
|
||||
ApplicationManager.getApplication().runWriteAction(
|
||||
new Runnable() {
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
try {
|
||||
LanguageLevelProjectExtension.getInstance(myProject).setLanguageLevel(LanguageLevel.JDK_1_5);
|
||||
String root = PathManagerEx.getTestDataPath() + "/psi/repositoryUse/src15";
|
||||
PsiTestUtil.removeAllRoots(myModule, JavaSdkImpl.getMockJdk17("mock 1.5"));
|
||||
PsiTestUtil.createTestProjectStructure(myProject, myModule, root, myFilesToDelete);
|
||||
}
|
||||
catch(Exception e){
|
||||
LOG.error(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
);
|
||||
LanguageLevelProjectExtension.getInstance(myProject).setLanguageLevel(LanguageLevel.JDK_1_5);
|
||||
String root = PathManagerEx.getTestDataPath() + "/psi/repositoryUse/src15";
|
||||
PsiTestUtil.removeAllRoots(myModule, JavaSdkImpl.getMockJdk17("mock 1.5"));
|
||||
PsiTestUtil.createTestProjectStructure(myProject, myModule, root, myFilesToDelete);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -40,23 +40,10 @@ public class SrcRepositoryUseTest extends PsiTestCase{
|
||||
protected void setUp() throws Exception {
|
||||
super.setUp();
|
||||
|
||||
ApplicationManager.getApplication().runWriteAction(
|
||||
new Runnable() {
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
try {
|
||||
LanguageLevelProjectExtension.getInstance(myProject).setLanguageLevel(LanguageLevel.JDK_1_5);
|
||||
String root = PathManagerEx.getTestDataPath() + "/psi/repositoryUse/src";
|
||||
PsiTestUtil.removeAllRoots(myModule, JavaSdkImpl.getMockJdk17());
|
||||
PsiTestUtil.createTestProjectStructure(myProject, myModule, root, myFilesToDelete);
|
||||
}
|
||||
catch(Exception e){
|
||||
LOG.error(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
);
|
||||
LanguageLevelProjectExtension.getInstance(myProject).setLanguageLevel(LanguageLevel.JDK_1_5);
|
||||
String root = PathManagerEx.getTestDataPath() + "/psi/repositoryUse/src";
|
||||
PsiTestUtil.removeAllRoots(myModule, JavaSdkImpl.getMockJdk17());
|
||||
PsiTestUtil.createTestProjectStructure(myProject, myModule, root, myFilesToDelete);
|
||||
}
|
||||
|
||||
public void testGetClasses(){
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package com.intellij.psi.impl.source.tree.java;
|
||||
|
||||
import com.intellij.openapi.application.ApplicationManager;
|
||||
import com.intellij.psi.*;
|
||||
import com.intellij.testFramework.LightCodeInsightTestCase;
|
||||
|
||||
@@ -8,18 +9,33 @@ import com.intellij.testFramework.LightCodeInsightTestCase;
|
||||
*/
|
||||
public class ExtendsBoundListTest extends LightCodeInsightTestCase {
|
||||
public void testRemoveBoundFromFront() throws Exception {
|
||||
PsiTypeParameter typeParameter = getTypeParameter();
|
||||
typeParameter.getExtendsList().getReferenceElements()[0].delete();
|
||||
final PsiTypeParameter typeParameter = getTypeParameter();
|
||||
ApplicationManager.getApplication().runWriteAction(new Runnable() {
|
||||
public void run() {
|
||||
typeParameter.getExtendsList().getReferenceElements()[0].delete();
|
||||
}
|
||||
});
|
||||
|
||||
check();
|
||||
}
|
||||
public void testRemoveBoundFromEnd() throws Exception {
|
||||
PsiTypeParameter typeParameter = getTypeParameter();
|
||||
typeParameter.getExtendsList().getReferenceElements()[1].delete();
|
||||
final PsiTypeParameter typeParameter = getTypeParameter();
|
||||
ApplicationManager.getApplication().runWriteAction(new Runnable() {
|
||||
public void run() {
|
||||
typeParameter.getExtendsList().getReferenceElements()[1].delete();
|
||||
}
|
||||
});
|
||||
|
||||
check();
|
||||
}
|
||||
public void testRemoveBoundFromMiddle() throws Exception {
|
||||
PsiTypeParameter typeParameter = getTypeParameter();
|
||||
typeParameter.getExtendsList().getReferenceElements()[1].delete();
|
||||
final PsiTypeParameter typeParameter = getTypeParameter();
|
||||
ApplicationManager.getApplication().runWriteAction(new Runnable() {
|
||||
public void run() {
|
||||
typeParameter.getExtendsList().getReferenceElements()[1].delete();
|
||||
}
|
||||
});
|
||||
|
||||
check();
|
||||
}
|
||||
|
||||
|
||||
@@ -25,7 +25,12 @@ public class JavadocParamTagsTest extends LightIdeaTestCase {
|
||||
final PsiDocComment docComment = method.getDocComment();
|
||||
assertNotNull(docComment);
|
||||
final PsiDocTag[] tags = docComment.getTags();
|
||||
tags[0].delete();
|
||||
ApplicationManager.getApplication().runWriteAction(new Runnable() {
|
||||
public void run() {
|
||||
tags[0].delete();
|
||||
}
|
||||
});
|
||||
|
||||
assertEquals("/**\n" +
|
||||
" * Javadoc\n" +
|
||||
" * @param p2\n" +
|
||||
@@ -45,7 +50,12 @@ public class JavadocParamTagsTest extends LightIdeaTestCase {
|
||||
final PsiDocComment docComment = method.getDocComment();
|
||||
assertNotNull(docComment);
|
||||
final PsiDocTag[] tags = docComment.getTags();
|
||||
tags[1].delete();
|
||||
ApplicationManager.getApplication().runWriteAction(new Runnable() {
|
||||
public void run() {
|
||||
tags[1].delete();
|
||||
}
|
||||
});
|
||||
|
||||
assertEquals("/**\n" +
|
||||
" * Javadoc\n" +
|
||||
" * @param p1\n" +
|
||||
@@ -66,7 +76,12 @@ public class JavadocParamTagsTest extends LightIdeaTestCase {
|
||||
final PsiDocComment docComment = method.getDocComment();
|
||||
assertNotNull(docComment);
|
||||
final PsiDocTag[] tags = docComment.getTags();
|
||||
tags[1].delete();
|
||||
ApplicationManager.getApplication().runWriteAction(new Runnable() {
|
||||
public void run() {
|
||||
tags[1].delete();
|
||||
}
|
||||
});
|
||||
|
||||
assertEquals("/**\n" +
|
||||
" * Javadoc\n" +
|
||||
" * @param p1\n" +
|
||||
|
||||
@@ -18,6 +18,7 @@ package com.intellij.refactoring;
|
||||
import com.intellij.JavaTestUtil;
|
||||
import com.intellij.codeInsight.intention.IntentionAction;
|
||||
import com.intellij.openapi.command.CommandProcessor;
|
||||
import com.intellij.openapi.command.WriteCommandAction;
|
||||
import com.intellij.openapi.editor.Document;
|
||||
import com.intellij.openapi.editor.Editor;
|
||||
import com.intellij.openapi.editor.actions.EditorActionUtil;
|
||||
@@ -33,14 +34,22 @@ import java.util.List;
|
||||
* Date: Sep 9, 2010
|
||||
*/
|
||||
public class ChangeSignatureGestureTest extends LightCodeInsightFixtureTestCase {
|
||||
private void doTest(Runnable run, boolean shouldShow) {
|
||||
|
||||
private void doTest(final Runnable run, boolean shouldShow) {
|
||||
myFixture.configureByFile("/refactoring/changeSignatureGesture/" + getTestName(false) + ".java");
|
||||
final ChangeSignatureGestureDetector detector = ChangeSignatureGestureDetector.getInstance(getProject());
|
||||
final Document document = myFixture.getEditor().getDocument();
|
||||
try {
|
||||
PsiManager.getInstance(getProject()).addPsiTreeChangeListener(detector);
|
||||
detector.addDocListener(document);
|
||||
run.run();
|
||||
new WriteCommandAction.Simple(getProject()) {
|
||||
@Override
|
||||
protected void run() throws Throwable {
|
||||
run.run();
|
||||
}
|
||||
}.execute().throwException();
|
||||
|
||||
|
||||
myFixture.doHighlighting();
|
||||
final String hint = "Change signature ...";
|
||||
if (shouldShow) {
|
||||
|
||||
@@ -6,6 +6,7 @@ package com.intellij.refactoring;
|
||||
|
||||
import com.intellij.JavaTestUtil;
|
||||
import com.intellij.codeInsight.TargetElementUtilBase;
|
||||
import com.intellij.openapi.command.WriteCommandAction;
|
||||
import com.intellij.psi.PsiDocumentManager;
|
||||
import com.intellij.psi.PsiElement;
|
||||
import com.intellij.psi.PsiMethod;
|
||||
@@ -23,27 +24,33 @@ public class ExtractMethodObjectTest extends LightCodeInsightTestCase {
|
||||
doTest(true);
|
||||
}
|
||||
|
||||
private void doTest(boolean createInnerClass) throws Exception {
|
||||
private void doTest(final boolean createInnerClass) throws Exception {
|
||||
final String testName = getTestName(false);
|
||||
configureByFile("/refactoring/extractMethodObject/" + testName + ".java");
|
||||
PsiElement element = TargetElementUtilBase.findTargetElement(myEditor, TargetElementUtilBase.ELEMENT_NAME_ACCEPTED);
|
||||
assertTrue(element instanceof PsiMethod);
|
||||
PsiMethod method = (PsiMethod) element;
|
||||
|
||||
final ExtractMethodObjectProcessor processor =
|
||||
new ExtractMethodObjectProcessor(getProject(), getEditor(), method.getBody().getStatements(), "InnerClass");
|
||||
final ExtractMethodObjectProcessor.MyExtractMethodProcessor extractProcessor = processor.getExtractProcessor();
|
||||
extractProcessor.setShowErrorDialogs(false);
|
||||
extractProcessor.prepare();
|
||||
extractProcessor.testRun();
|
||||
processor.setCreateInnerClass(createInnerClass);
|
||||
processor.run();
|
||||
if (createInnerClass) {
|
||||
processor.moveUsedMethodsToInner();
|
||||
}
|
||||
DuplicatesImpl.processDuplicates(extractProcessor, getProject(), getEditor());
|
||||
PsiDocumentManager.getInstance(getProject()).commitAllDocuments();
|
||||
processor.getMethod().delete();
|
||||
final PsiMethod method = (PsiMethod) element;
|
||||
|
||||
new WriteCommandAction.Simple(getProject()) {
|
||||
@Override
|
||||
protected void run() throws Throwable {
|
||||
final ExtractMethodObjectProcessor processor =
|
||||
new ExtractMethodObjectProcessor(getProject(), getEditor(), method.getBody().getStatements(), "InnerClass");
|
||||
final ExtractMethodObjectProcessor.MyExtractMethodProcessor extractProcessor = processor.getExtractProcessor();
|
||||
extractProcessor.setShowErrorDialogs(false);
|
||||
extractProcessor.prepare();
|
||||
extractProcessor.testRun();
|
||||
processor.setCreateInnerClass(createInnerClass);
|
||||
processor.run();
|
||||
if (createInnerClass) {
|
||||
processor.moveUsedMethodsToInner();
|
||||
}
|
||||
DuplicatesImpl.processDuplicates(extractProcessor, getProject(), getEditor());
|
||||
PsiDocumentManager.getInstance(getProject()).commitAllDocuments();
|
||||
processor.getMethod().delete();
|
||||
}
|
||||
}.execute().throwException();
|
||||
|
||||
checkResultByFile("/refactoring/extractMethodObject/" + testName + ".java" + ".after");
|
||||
}
|
||||
|
||||
@@ -114,4 +121,4 @@ public class ExtractMethodObjectTest extends LightCodeInsightTestCase {
|
||||
public void testWithPrivateMethodWhichCantBeMoved() throws Exception {
|
||||
doTest();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6,6 +6,7 @@ package com.intellij.refactoring;
|
||||
|
||||
import com.intellij.JavaTestUtil;
|
||||
import com.intellij.codeInsight.CodeInsightUtil;
|
||||
import com.intellij.openapi.command.WriteCommandAction;
|
||||
import com.intellij.psi.PsiElement;
|
||||
import com.intellij.psi.PsiExpression;
|
||||
import com.intellij.refactoring.extractMethodObject.ExtractMethodObjectProcessor;
|
||||
@@ -22,13 +23,13 @@ public class ExtractMethodObjectWithMultipleExitPointsTest extends LightCodeInsi
|
||||
doTest(true);
|
||||
}
|
||||
|
||||
private void doTest(boolean createInnerClass) throws Exception {
|
||||
private void doTest(final boolean createInnerClass) throws Exception {
|
||||
final String testName = getTestName(false);
|
||||
configureByFile("/refactoring/extractMethodObject/multipleExitPoints/" + testName + ".java");
|
||||
int startOffset = myEditor.getSelectionModel().getSelectionStart();
|
||||
int endOffset = myEditor.getSelectionModel().getSelectionEnd();
|
||||
|
||||
PsiElement[] elements;
|
||||
final PsiElement[] elements;
|
||||
PsiExpression expr = CodeInsightUtil.findExpressionInRange(myFile, startOffset, endOffset);
|
||||
if (expr != null) {
|
||||
elements = new PsiElement[]{expr};
|
||||
@@ -37,16 +38,22 @@ public class ExtractMethodObjectWithMultipleExitPointsTest extends LightCodeInsi
|
||||
elements = CodeInsightUtil.findStatementsInRange(myFile, startOffset, endOffset);
|
||||
}
|
||||
|
||||
final ExtractMethodObjectProcessor processor =
|
||||
new ExtractMethodObjectProcessor(getProject(), getEditor(), elements, "Inner");
|
||||
final ExtractMethodObjectProcessor.MyExtractMethodProcessor extractProcessor = processor.getExtractProcessor();
|
||||
extractProcessor.setShowErrorDialogs(false);
|
||||
extractProcessor.prepare();
|
||||
extractProcessor.testRun();
|
||||
processor.setCreateInnerClass(createInnerClass);
|
||||
processor.run();
|
||||
DuplicatesImpl.processDuplicates(extractProcessor, getProject(), getEditor());
|
||||
processor.getMethod().delete();
|
||||
new WriteCommandAction.Simple(getProject()) {
|
||||
@Override
|
||||
protected void run() throws Throwable {
|
||||
final ExtractMethodObjectProcessor processor =
|
||||
new ExtractMethodObjectProcessor(getProject(), getEditor(), elements, "Inner");
|
||||
final ExtractMethodObjectProcessor.MyExtractMethodProcessor extractProcessor = processor.getExtractProcessor();
|
||||
extractProcessor.setShowErrorDialogs(false);
|
||||
extractProcessor.prepare();
|
||||
extractProcessor.testRun();
|
||||
processor.setCreateInnerClass(createInnerClass);
|
||||
processor.run();
|
||||
DuplicatesImpl.processDuplicates(extractProcessor, getProject(), getEditor());
|
||||
processor.getMethod().delete();
|
||||
}
|
||||
}.execute().throwException();
|
||||
|
||||
checkResultByFile("/refactoring/extractMethodObject/multipleExitPoints/" + testName + ".java" + ".after");
|
||||
}
|
||||
|
||||
@@ -73,4 +80,4 @@ public class ExtractMethodObjectWithMultipleExitPointsTest extends LightCodeInsi
|
||||
public void testOutputVariable() throws Exception {
|
||||
doTest();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -9,6 +9,7 @@
|
||||
package com.intellij.refactoring;
|
||||
|
||||
import com.intellij.codeInsight.CodeInsightTestCase;
|
||||
import com.intellij.openapi.application.ApplicationManager;
|
||||
import com.intellij.openapi.module.Module;
|
||||
import com.intellij.openapi.roots.ModifiableRootModel;
|
||||
import com.intellij.openapi.roots.ModuleRootManager;
|
||||
@@ -38,13 +39,18 @@ public class IntroduceFieldWitSetUpInitializationTest extends CodeInsightTestCas
|
||||
@Override
|
||||
protected Module createModule(final String name) {
|
||||
final Module module = super.createModule(name);
|
||||
final ModifiableRootModel model = ModuleRootManager.getInstance(module).getModifiableModel();
|
||||
final LibraryTable.ModifiableModel modifiableModel = model.getModuleLibraryTable().getModifiableModel();
|
||||
final Library library = modifiableModel.createLibrary("junit");
|
||||
final Library.ModifiableModel libModel = library.getModifiableModel();
|
||||
libModel.addRoot(VfsUtil.getUrlForLibraryRoot(new File(PathUtil.getJarPathForClass(Before.class))), OrderRootType.CLASSES);
|
||||
libModel.commit();
|
||||
model.commit();
|
||||
ApplicationManager.getApplication().runWriteAction(new Runnable() {
|
||||
public void run() {
|
||||
final ModifiableRootModel model = ModuleRootManager.getInstance(module).getModifiableModel();
|
||||
final LibraryTable.ModifiableModel modifiableModel = model.getModuleLibraryTable().getModifiableModel();
|
||||
final Library library = modifiableModel.createLibrary("junit");
|
||||
final Library.ModifiableModel libModel = library.getModifiableModel();
|
||||
libModel.addRoot(VfsUtil.getUrlForLibraryRoot(new File(PathUtil.getJarPathForClass(Before.class))), OrderRootType.CLASSES);
|
||||
libModel.commit();
|
||||
model.commit();
|
||||
}
|
||||
});
|
||||
|
||||
return module;
|
||||
}
|
||||
|
||||
@@ -91,4 +97,4 @@ public class IntroduceFieldWitSetUpInitializationTest extends CodeInsightTestCas
|
||||
}.convertLocalToField(local, myEditor);
|
||||
checkResultByFile("/refactoring/introduceField/after" + getTestName(false)+ ".java");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package com.intellij.roots;
|
||||
|
||||
import com.intellij.openapi.application.ApplicationManager;
|
||||
import com.intellij.openapi.module.Module;
|
||||
import com.intellij.openapi.module.StdModuleTypes;
|
||||
import com.intellij.openapi.roots.*;
|
||||
@@ -49,23 +50,28 @@ public class DependencyScopeTest extends ModuleTestCase {
|
||||
assertEquals(0, pathsListWithoutTests.getPathList().size());
|
||||
}
|
||||
|
||||
private Module addDependentModule(Module moduleA, final DependencyScope scope) {
|
||||
Module moduleB = createModule("b.iml", StdModuleTypes.JAVA);
|
||||
private Module addDependentModule(final Module moduleA, final DependencyScope scope) {
|
||||
final Module moduleB = createModule("b.iml", StdModuleTypes.JAVA);
|
||||
|
||||
VirtualFile rootB = myFixture.findOrCreateDir("b");
|
||||
VirtualFile outB = myFixture.findOrCreateDir("out");
|
||||
ApplicationManager.getApplication().runWriteAction(new Runnable() {
|
||||
public void run() {
|
||||
VirtualFile rootB = myFixture.findOrCreateDir("b");
|
||||
VirtualFile outB = myFixture.findOrCreateDir("out");
|
||||
|
||||
final ModifiableRootModel modelA = ModuleRootManager.getInstance(moduleA).getModifiableModel();
|
||||
modelA.addModuleOrderEntry(moduleB).setScope(scope);
|
||||
modelA.commit();
|
||||
final ModifiableRootModel modelA = ModuleRootManager.getInstance(moduleA).getModifiableModel();
|
||||
modelA.addModuleOrderEntry(moduleB).setScope(scope);
|
||||
modelA.commit();
|
||||
|
||||
final ModifiableRootModel modelB = ModuleRootManager.getInstance(moduleB).getModifiableModel();
|
||||
final ContentEntry contentEntry = modelB.addContentEntry(rootB);
|
||||
contentEntry.addSourceFolder(rootB, false);
|
||||
final CompilerModuleExtension extension = modelB.getModuleExtension(CompilerModuleExtension.class);
|
||||
extension.inheritCompilerOutputPath(false);
|
||||
extension.setCompilerOutputPath(outB);
|
||||
modelB.commit();
|
||||
}
|
||||
});
|
||||
|
||||
final ModifiableRootModel modelB = ModuleRootManager.getInstance(moduleB).getModifiableModel();
|
||||
final ContentEntry contentEntry = modelB.addContentEntry(rootB);
|
||||
contentEntry.addSourceFolder(rootB, false);
|
||||
final CompilerModuleExtension extension = modelB.getModuleExtension(CompilerModuleExtension.class);
|
||||
extension.inheritCompilerOutputPath(false);
|
||||
extension.setCompilerOutputPath(outB);
|
||||
modelB.commit();
|
||||
return moduleB;
|
||||
}
|
||||
|
||||
@@ -147,17 +153,22 @@ public class DependencyScopeTest extends ModuleTestCase {
|
||||
return ModuleRootManager.getInstance(m).orderEntries().recursively().exportedOnly().getClassesRoots();
|
||||
}
|
||||
|
||||
private VirtualFile addLibrary(Module m, final DependencyScope scope) {
|
||||
VirtualFile libraryRoot = myFixture.findOrCreateDir("lib");
|
||||
private VirtualFile addLibrary(final Module m, final DependencyScope scope) {
|
||||
final VirtualFile libraryRoot = myFixture.findOrCreateDir("lib");
|
||||
|
||||
final ModifiableRootModel model = ModuleRootManager.getInstance(m).getModifiableModel();
|
||||
final Library library = model.getModuleLibraryTable().createLibrary("l");
|
||||
final Library.ModifiableModel libraryModel = library.getModifiableModel();
|
||||
libraryModel.addRoot(libraryRoot, OrderRootType.CLASSES);
|
||||
libraryModel.commit();
|
||||
ApplicationManager.getApplication().runWriteAction(new Runnable() {
|
||||
public void run() {
|
||||
final ModifiableRootModel model = ModuleRootManager.getInstance(m).getModifiableModel();
|
||||
final Library library = model.getModuleLibraryTable().createLibrary("l");
|
||||
final Library.ModifiableModel libraryModel = library.getModifiableModel();
|
||||
libraryModel.addRoot(libraryRoot, OrderRootType.CLASSES);
|
||||
libraryModel.commit();
|
||||
|
||||
model.findLibraryOrderEntry(library).setScope(scope);
|
||||
model.commit();
|
||||
}
|
||||
});
|
||||
|
||||
model.findLibraryOrderEntry(library).setScope(scope);
|
||||
model.commit();
|
||||
return libraryRoot;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package com.intellij.roots;
|
||||
|
||||
import com.intellij.openapi.application.ApplicationManager;
|
||||
import com.intellij.openapi.command.WriteCommandAction;
|
||||
import com.intellij.openapi.diagnostic.Logger;
|
||||
import com.intellij.openapi.fileTypes.FileTypeManager;
|
||||
import com.intellij.openapi.fileTypes.ex.FileTypeManagerEx;
|
||||
@@ -242,14 +243,20 @@ public class DirectoryIndexImplTest extends IdeaTestCase {
|
||||
}
|
||||
|
||||
public void testAddProjectDir() throws Exception {
|
||||
VirtualFile newDir = myModule1Dir.getParent().createChildDirectory(null, "newDir");
|
||||
newDir.createChildDirectory(null, "subdir");
|
||||
new WriteCommandAction.Simple(getProject()) {
|
||||
@Override
|
||||
protected void run() throws Throwable {
|
||||
VirtualFile newDir = myModule1Dir.getParent().createChildDirectory(null, "newDir");
|
||||
newDir.createChildDirectory(null, "subdir");
|
||||
|
||||
myIndex.checkConsistency();
|
||||
myIndex.checkConsistency();
|
||||
|
||||
ModifiableRootModel rootModel = ModuleRootManager.getInstance(myModule).getModifiableModel();
|
||||
rootModel.addContentEntry(newDir);
|
||||
rootModel.commit();
|
||||
}
|
||||
}.execute().throwException();
|
||||
|
||||
ModifiableRootModel rootModel = ModuleRootManager.getInstance(myModule).getModifiableModel();
|
||||
rootModel.addContentEntry(newDir);
|
||||
rootModel.commit();
|
||||
|
||||
myIndex.checkConsistency();
|
||||
}
|
||||
@@ -285,26 +292,37 @@ public class DirectoryIndexImplTest extends IdeaTestCase {
|
||||
public void testAddModule() throws Exception {
|
||||
myIndex.checkConsistency();
|
||||
|
||||
VirtualFile newModuleContent = myRootVFile.createChildDirectory(null, "newModule");
|
||||
newModuleContent.createChildDirectory(null, "subDir");
|
||||
ModuleManager moduleManager = ModuleManager.getInstance(myProject);
|
||||
Module module = moduleManager.newModule(myRootVFile.getPath() + "/newModule.iml", StdModuleTypes.JAVA);
|
||||
ModifiableRootModel rootModel = ModuleRootManager.getInstance(module).getModifiableModel();
|
||||
rootModel.addContentEntry(newModuleContent);
|
||||
rootModel.commit();
|
||||
new WriteCommandAction.Simple(getProject()) {
|
||||
@Override
|
||||
protected void run() throws Throwable {
|
||||
VirtualFile newModuleContent = myRootVFile.createChildDirectory(null, "newModule");
|
||||
newModuleContent.createChildDirectory(null, "subDir");
|
||||
ModuleManager moduleManager = ModuleManager.getInstance(myProject);
|
||||
Module module = moduleManager.newModule(myRootVFile.getPath() + "/newModule.iml", StdModuleTypes.JAVA);
|
||||
ModifiableRootModel rootModel = ModuleRootManager.getInstance(module).getModifiableModel();
|
||||
rootModel.addContentEntry(newModuleContent);
|
||||
rootModel.commit();
|
||||
}
|
||||
}.execute().throwException();
|
||||
|
||||
|
||||
myIndex.checkConsistency();
|
||||
}
|
||||
|
||||
public void testExplicitExcludeOfInner() throws Exception {
|
||||
ModifiableRootModel rootModel = ModuleRootManager.getInstance(myModule).getModifiableModel();
|
||||
ApplicationManager.getApplication().runWriteAction(new Runnable() {
|
||||
public void run() {
|
||||
ModifiableRootModel rootModel = ModuleRootManager.getInstance(myModule).getModifiableModel();
|
||||
|
||||
ContentEntry[] contentEntries = rootModel.getContentEntries();
|
||||
assertEquals(1, contentEntries.length);
|
||||
ContentEntry contentEntry = contentEntries[0];
|
||||
contentEntry.addExcludeFolder(myModule2Dir);
|
||||
ContentEntry[] contentEntries = rootModel.getContentEntries();
|
||||
assertEquals(1, contentEntries.length);
|
||||
ContentEntry contentEntry = contentEntries[0];
|
||||
contentEntry.addExcludeFolder(myModule2Dir);
|
||||
|
||||
rootModel.commit();
|
||||
}
|
||||
});
|
||||
|
||||
rootModel.commit();
|
||||
|
||||
myIndex.checkConsistency();
|
||||
|
||||
@@ -349,19 +367,27 @@ public class DirectoryIndexImplTest extends IdeaTestCase {
|
||||
|
||||
CompilerProjectExtension.getInstance(myProject).setCompilerOutputUrl(projectOutput.getUrl());
|
||||
|
||||
ModifiableRootModel m = ModuleRootManager.getInstance(myModule).getModifiableModel();
|
||||
ContentEntry[] ee = m.getContentEntries();
|
||||
assertEquals(1, ee.length);
|
||||
ee[0].addExcludeFolder(excluded);
|
||||
m.commit();
|
||||
|
||||
m = ModuleRootManager.getInstance(myModule2).getModifiableModel();
|
||||
final CompilerModuleExtension compilerModuleExtension = m.getModuleExtension(CompilerModuleExtension.class);
|
||||
compilerModuleExtension.setCompilerOutputPath(module2Output);
|
||||
compilerModuleExtension.setCompilerOutputPathForTests(module2TestOutput);
|
||||
compilerModuleExtension.setExcludeOutput(true);
|
||||
compilerModuleExtension.inheritCompilerOutputPath(false);
|
||||
m.commit();
|
||||
final VirtualFile finalExcluded = excluded;
|
||||
final VirtualFile finalModule2Output = module2Output;
|
||||
final VirtualFile finalModule2TestOutput = module2TestOutput;
|
||||
ApplicationManager.getApplication().runWriteAction(new Runnable() {
|
||||
public void run() {
|
||||
ModifiableRootModel m = ModuleRootManager.getInstance(myModule).getModifiableModel();
|
||||
ContentEntry[] ee = m.getContentEntries();
|
||||
assertEquals(1, ee.length);
|
||||
ee[0].addExcludeFolder(finalExcluded);
|
||||
m.commit();
|
||||
|
||||
m = ModuleRootManager.getInstance(myModule2).getModifiableModel();
|
||||
final CompilerModuleExtension compilerModuleExtension = m.getModuleExtension(CompilerModuleExtension.class);
|
||||
compilerModuleExtension.setCompilerOutputPath(finalModule2Output);
|
||||
compilerModuleExtension.setCompilerOutputPathForTests(finalModule2TestOutput);
|
||||
compilerModuleExtension.setExcludeOutput(true);
|
||||
compilerModuleExtension.inheritCompilerOutputPath(false);
|
||||
m.commit();
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
assertNull(myIndex.getInfoForDirectory(excluded));
|
||||
assertNull(myIndex.getInfoForDirectory(projectOutput));
|
||||
@@ -404,16 +430,22 @@ public class DirectoryIndexImplTest extends IdeaTestCase {
|
||||
}
|
||||
|
||||
public void testExcludesShouldBeRecognizedRightOnRefresh() throws Exception {
|
||||
VirtualFile dir = myModule1Dir.createChildDirectory(null, "dir");
|
||||
VirtualFile excluded = dir.createChildDirectory(null, "excluded");
|
||||
final VirtualFile dir = myModule1Dir.createChildDirectory(null, "dir");
|
||||
final VirtualFile excluded = dir.createChildDirectory(null, "excluded");
|
||||
|
||||
ModifiableRootModel m = ModuleRootManager.getInstance(myModule).getModifiableModel();
|
||||
ContentEntry[] ee = m.getContentEntries();
|
||||
assertEquals(1, ee.length);
|
||||
ee[0].addExcludeFolder(excluded);
|
||||
m.commit();
|
||||
new WriteCommandAction.Simple(getProject()) {
|
||||
@Override
|
||||
protected void run() throws Throwable {
|
||||
ModifiableRootModel m = ModuleRootManager.getInstance(myModule).getModifiableModel();
|
||||
ContentEntry[] ee = m.getContentEntries();
|
||||
assertEquals(1, ee.length);
|
||||
ee[0].addExcludeFolder(excluded);
|
||||
m.commit();
|
||||
|
||||
dir.delete(null);
|
||||
}
|
||||
}.execute().throwException();
|
||||
|
||||
dir.delete(null);
|
||||
|
||||
new File(myModule1Dir.getPath(), "dir/excluded/foo").mkdirs();
|
||||
|
||||
@@ -442,29 +474,40 @@ public class DirectoryIndexImplTest extends IdeaTestCase {
|
||||
|
||||
public void testProcessingNestedContentRootsOfExcludedDirsOnCreation() {
|
||||
String rootPath = myModule1Dir.getPath();
|
||||
File f = new File(rootPath, "excludedDir/dir/anotherContentRoot");
|
||||
final File f = new File(rootPath, "excludedDir/dir/anotherContentRoot");
|
||||
|
||||
ModifiableRootModel rootModel = ModuleRootManager.getInstance(myModule).getModifiableModel();
|
||||
rootModel.getContentEntries()[0].addExcludeFolder(VfsUtil.pathToUrl(FileUtil.toSystemIndependentName(f.getParentFile().getParent())));
|
||||
rootModel.commit();
|
||||
ApplicationManager.getApplication().runWriteAction(new Runnable() {
|
||||
public void run() {
|
||||
ModifiableRootModel rootModel = ModuleRootManager.getInstance(myModule).getModifiableModel();
|
||||
rootModel.getContentEntries()[0]
|
||||
.addExcludeFolder(VfsUtil.pathToUrl(FileUtil.toSystemIndependentName(f.getParentFile().getParent())));
|
||||
rootModel.commit();
|
||||
|
||||
rootModel = ModuleRootManager.getInstance(myModule2).getModifiableModel();
|
||||
rootModel.addContentEntry(VfsUtil.pathToUrl(FileUtil.toSystemIndependentName(f.getPath())));
|
||||
rootModel.commit();
|
||||
rootModel = ModuleRootManager.getInstance(myModule2).getModifiableModel();
|
||||
rootModel.addContentEntry(VfsUtil.pathToUrl(FileUtil.toSystemIndependentName(f.getPath())));
|
||||
rootModel.commit();
|
||||
|
||||
f.mkdirs();
|
||||
LocalFileSystem.getInstance().refresh(false);
|
||||
}
|
||||
});
|
||||
|
||||
f.mkdirs();
|
||||
LocalFileSystem.getInstance().refresh(false);
|
||||
|
||||
assertNull(myIndex.getInfoForDirectory(LocalFileSystem.getInstance().findFileByIoFile(f.getParentFile().getParentFile())));
|
||||
assertNotNull(myIndex.getInfoForDirectory(LocalFileSystem.getInstance().findFileByIoFile(f)));
|
||||
}
|
||||
|
||||
public void testLibraryDirInContent() throws Exception {
|
||||
ModifiableRootModel rootModel = ModuleRootManager.getInstance(myModule).getModifiableModel();
|
||||
Library.ModifiableModel libraryModel = rootModel.getModuleLibraryTable().createLibrary().getModifiableModel();
|
||||
libraryModel.addRoot(myModule1Dir, OrderRootType.CLASSES);
|
||||
libraryModel.commit();
|
||||
rootModel.commit();
|
||||
ApplicationManager.getApplication().runWriteAction(new Runnable() {
|
||||
public void run() {
|
||||
ModifiableRootModel rootModel = ModuleRootManager.getInstance(myModule).getModifiableModel();
|
||||
Library.ModifiableModel libraryModel = rootModel.getModuleLibraryTable().createLibrary().getModifiableModel();
|
||||
libraryModel.addRoot(myModule1Dir, OrderRootType.CLASSES);
|
||||
libraryModel.commit();
|
||||
rootModel.commit();
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
myIndex.checkConsistency();
|
||||
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
*/
|
||||
package com.intellij.roots;
|
||||
|
||||
import com.intellij.openapi.application.ApplicationManager;
|
||||
import com.intellij.openapi.application.ex.PathManagerEx;
|
||||
import com.intellij.openapi.module.ModifiableModuleModel;
|
||||
import com.intellij.openapi.module.Module;
|
||||
@@ -31,44 +32,51 @@ public class ExportingModulesTest extends IdeaTestCase {
|
||||
final VirtualFile testRoot = LocalFileSystem.getInstance().refreshAndFindFileByPath(rootPath);
|
||||
assertNotNull(testRoot);
|
||||
|
||||
final ModifiableModuleModel moduleModel = ModuleManager.getInstance(myProject).getModifiableModel();
|
||||
final Module moduleA = moduleModel.newModule("A.iml", StdModuleTypes.JAVA);
|
||||
final Module moduleB = moduleModel.newModule("B.iml", StdModuleTypes.JAVA);
|
||||
final Module moduleC = moduleModel.newModule("C.iml", StdModuleTypes.JAVA);
|
||||
moduleModel.commit();
|
||||
ApplicationManager.getApplication().runWriteAction(new Runnable() {
|
||||
public void run() {
|
||||
final ModifiableModuleModel moduleModel = ModuleManager.getInstance(myProject).getModifiableModel();
|
||||
final Module moduleA = moduleModel.newModule("A.iml", StdModuleTypes.JAVA);
|
||||
final Module moduleB = moduleModel.newModule("B.iml", StdModuleTypes.JAVA);
|
||||
final Module moduleC = moduleModel.newModule("C.iml", StdModuleTypes.JAVA);
|
||||
moduleModel.commit();
|
||||
|
||||
configureModule(moduleA, testRoot, "A");
|
||||
configureModule(moduleB, testRoot, "B");
|
||||
configureModule(moduleC, testRoot, "C");
|
||||
configureModule(moduleA, testRoot, "A");
|
||||
configureModule(moduleB, testRoot, "B");
|
||||
configureModule(moduleC, testRoot, "C");
|
||||
|
||||
final ModifiableRootModel rootModelB = ModuleRootManager.getInstance(moduleB).getModifiableModel();
|
||||
final ModuleOrderEntry moduleBAentry = rootModelB.addModuleOrderEntry(moduleA);
|
||||
moduleBAentry.setExported(true);
|
||||
rootModelB.commit();
|
||||
final ModifiableRootModel rootModelB = ModuleRootManager.getInstance(moduleB).getModifiableModel();
|
||||
final ModuleOrderEntry moduleBAentry = rootModelB.addModuleOrderEntry(moduleA);
|
||||
moduleBAentry.setExported(true);
|
||||
rootModelB.commit();
|
||||
|
||||
final ModifiableRootModel rootModelC = ModuleRootManager.getInstance(moduleC).getModifiableModel();
|
||||
rootModelC.addModuleOrderEntry(moduleB);
|
||||
rootModelC.commit();
|
||||
final ModifiableRootModel rootModelC = ModuleRootManager.getInstance(moduleC).getModifiableModel();
|
||||
rootModelC.addModuleOrderEntry(moduleB);
|
||||
rootModelC.commit();
|
||||
|
||||
final PsiClass pCClass =
|
||||
JavaPsiFacade.getInstance(myProject).findClass("p.C", GlobalSearchScope.moduleWithDependenciesAndLibrariesScope(moduleC));
|
||||
assertNotNull(pCClass);
|
||||
final PsiClass pCClass =
|
||||
JavaPsiFacade.getInstance(myProject).findClass("p.C", GlobalSearchScope.moduleWithDependenciesAndLibrariesScope(moduleC));
|
||||
assertNotNull(pCClass);
|
||||
|
||||
final PsiClass pAClass =
|
||||
JavaPsiFacade.getInstance(myProject).findClass("p.A", GlobalSearchScope.moduleWithDependenciesAndLibrariesScope(moduleB));
|
||||
assertNotNull(pAClass);
|
||||
|
||||
final PsiClass pAClass2 =
|
||||
JavaPsiFacade.getInstance(myProject).findClass("p.A", GlobalSearchScope.moduleWithDependenciesAndLibrariesScope(moduleC));
|
||||
assertNotNull(pAClass2);
|
||||
final PsiClass pAClass =
|
||||
JavaPsiFacade.getInstance(myProject).findClass("p.A", GlobalSearchScope.moduleWithDependenciesAndLibrariesScope(moduleB));
|
||||
assertNotNull(pAClass);
|
||||
|
||||
final PsiClass pAClass2 =
|
||||
JavaPsiFacade.getInstance(myProject).findClass("p.A", GlobalSearchScope.moduleWithDependenciesAndLibrariesScope(moduleC));
|
||||
assertNotNull(pAClass2);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private void configureModule(final Module module, final VirtualFile testRoot, final String name) {
|
||||
final ModifiableRootModel rootModel = ModuleRootManager.getInstance(module).getModifiableModel();
|
||||
final VirtualFile contentRoot = testRoot.findChild(name);
|
||||
final ContentEntry contentEntry = rootModel.addContentEntry(contentRoot);
|
||||
contentEntry.addSourceFolder(contentRoot.findChild("src"), false);
|
||||
rootModel.commit();
|
||||
ApplicationManager.getApplication().runWriteAction(new Runnable() {
|
||||
public void run() {
|
||||
final ModifiableRootModel rootModel = ModuleRootManager.getInstance(module).getModifiableModel();
|
||||
final VirtualFile contentRoot = testRoot.findChild(name);
|
||||
final ContentEntry contentEntry = rootModel.addContentEntry(contentRoot);
|
||||
contentEntry.addSourceFolder(contentRoot.findChild("src"), false);
|
||||
rootModel.commit();
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -36,9 +36,15 @@ public class ManagingContentRootsTest extends IdeaTestCase {
|
||||
VirtualFile root = dir.createChildDirectory(null, "root");
|
||||
String url = root.getUrl();
|
||||
|
||||
ModifiableRootModel m = getRootManager().getModifiableModel();
|
||||
m.addContentEntry(root);
|
||||
m.commit();
|
||||
final VirtualFile finalRoot = root;
|
||||
ApplicationManager.getApplication().runWriteAction(new Runnable() {
|
||||
public void run() {
|
||||
ModifiableRootModel m = getRootManager().getModifiableModel();
|
||||
m.addContentEntry(finalRoot);
|
||||
m.commit();
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
assertSame(root, findContentEntry(url).getFile());
|
||||
|
||||
@@ -51,12 +57,17 @@ public class ManagingContentRootsTest extends IdeaTestCase {
|
||||
|
||||
public void testCreationOfContentRootWithUrl() throws IOException {
|
||||
VirtualFile root = dir.createChildDirectory(null, "root");
|
||||
String url = root.getUrl();
|
||||
final String url = root.getUrl();
|
||||
root.delete(null);
|
||||
|
||||
ModifiableRootModel m = getRootManager().getModifiableModel();
|
||||
m.addContentEntry(url);
|
||||
m.commit();
|
||||
ApplicationManager.getApplication().runWriteAction(new Runnable() {
|
||||
public void run() {
|
||||
ModifiableRootModel m = getRootManager().getModifiableModel();
|
||||
m.addContentEntry(url);
|
||||
m.commit();
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
assertNotNull(findContentEntry(url));
|
||||
|
||||
@@ -66,25 +77,34 @@ public class ManagingContentRootsTest extends IdeaTestCase {
|
||||
|
||||
public void testCreationOfContentRootWithUrlWhenFileExists() throws IOException {
|
||||
VirtualFile root = dir.createChildDirectory(null, "root");
|
||||
String url = root.getUrl();
|
||||
final String url = root.getUrl();
|
||||
|
||||
ApplicationManager.getApplication().runWriteAction(new Runnable() {
|
||||
public void run() {
|
||||
ModifiableRootModel m = getRootManager().getModifiableModel();
|
||||
m.addContentEntry(url);
|
||||
m.commit();
|
||||
}
|
||||
});
|
||||
|
||||
ModifiableRootModel m = getRootManager().getModifiableModel();
|
||||
m.addContentEntry(url);
|
||||
m.commit();
|
||||
|
||||
assertSame(root, findContentEntry(url).getFile());
|
||||
}
|
||||
|
||||
public void testGettingMofifiableModelCorrectlySetsRootModelForContentEntries() throws Exception {
|
||||
ModifiableRootModel m = getRootManager().getModifiableModel();
|
||||
m.addContentEntry(dir);
|
||||
m.commit();
|
||||
ApplicationManager.getApplication().runWriteAction(new Runnable() {
|
||||
public void run() {
|
||||
ModifiableRootModel m = getRootManager().getModifiableModel();
|
||||
m.addContentEntry(dir);
|
||||
m.commit();
|
||||
|
||||
m = getRootManager().getModifiableModel();
|
||||
ContentEntry e = findContentEntry(dir.getUrl(), m);
|
||||
m = getRootManager().getModifiableModel();
|
||||
ContentEntry e = findContentEntry(dir.getUrl(), m);
|
||||
|
||||
assertSame(m, ((ContentEntryImpl)e).getRootModel());
|
||||
m.dispose();
|
||||
assertSame(m, ((ContentEntryImpl)e).getRootModel());
|
||||
m.dispose();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private ContentEntry findContentEntry(String url) {
|
||||
@@ -101,4 +121,4 @@ public class ManagingContentRootsTest extends IdeaTestCase {
|
||||
private ModuleRootManager getRootManager() {
|
||||
return ModuleRootManager.getInstance(myModule);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package com.intellij.roots;
|
||||
|
||||
import com.intellij.openapi.application.ApplicationManager;
|
||||
import com.intellij.openapi.application.PathManager;
|
||||
import com.intellij.openapi.module.Module;
|
||||
import com.intellij.openapi.projectRoots.Sdk;
|
||||
@@ -68,19 +69,24 @@ public abstract class ModuleRootManagerTestCase extends ModuleTestCase {
|
||||
return root;
|
||||
}
|
||||
|
||||
protected VirtualFile setModuleOutput(Module module, boolean test) throws IOException {
|
||||
protected VirtualFile setModuleOutput(final Module module, final boolean test) throws IOException {
|
||||
final VirtualFile output = getVirtualFile(createTempDir(module.getName() + (test ? "Test" : "Prod") + "Output"));
|
||||
final ModifiableRootModel model = ModuleRootManager.getInstance(module).getModifiableModel();
|
||||
final CompilerModuleExtension extension = model.getModuleExtension(CompilerModuleExtension.class);
|
||||
assertNotNull(extension);
|
||||
extension.inheritCompilerOutputPath(false);
|
||||
if (test) {
|
||||
extension.setCompilerOutputPathForTests(output);
|
||||
}
|
||||
else {
|
||||
extension.setCompilerOutputPath(output);
|
||||
}
|
||||
model.commit();
|
||||
ApplicationManager.getApplication().runWriteAction(new Runnable() {
|
||||
public void run() {
|
||||
final ModifiableRootModel model = ModuleRootManager.getInstance(module).getModifiableModel();
|
||||
final CompilerModuleExtension extension = model.getModuleExtension(CompilerModuleExtension.class);
|
||||
assertNotNull(extension);
|
||||
extension.inheritCompilerOutputPath(false);
|
||||
if (test) {
|
||||
extension.setCompilerOutputPathForTests(output);
|
||||
}
|
||||
else {
|
||||
extension.setCompilerOutputPath(output);
|
||||
}
|
||||
model.commit();
|
||||
}
|
||||
});
|
||||
|
||||
return output;
|
||||
}
|
||||
|
||||
@@ -88,24 +94,32 @@ public abstract class ModuleRootManagerTestCase extends ModuleTestCase {
|
||||
addLibraryDependency(module, dependency, DependencyScope.COMPILE, false);
|
||||
}
|
||||
|
||||
protected void addLibraryDependency(Module module, Library dependency, DependencyScope scope, boolean exported) {
|
||||
final ModifiableRootModel model = ModuleRootManager.getInstance(module).getModifiableModel();
|
||||
final LibraryOrderEntry entry = model.addLibraryEntry(dependency);
|
||||
entry.setScope(scope);
|
||||
entry.setExported(exported);
|
||||
model.commit();
|
||||
protected void addLibraryDependency(final Module module, final Library dependency, final DependencyScope scope, final boolean exported) {
|
||||
ApplicationManager.getApplication().runWriteAction(new Runnable() {
|
||||
public void run() {
|
||||
final ModifiableRootModel model = ModuleRootManager.getInstance(module).getModifiableModel();
|
||||
final LibraryOrderEntry entry = model.addLibraryEntry(dependency);
|
||||
entry.setScope(scope);
|
||||
entry.setExported(exported);
|
||||
model.commit();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
protected void addModuleDependency(Module module, Module dependency) {
|
||||
addModuleDependency(module, dependency, DependencyScope.COMPILE, false);
|
||||
}
|
||||
|
||||
protected void addModuleDependency(Module module, Module dependency, DependencyScope scope, boolean exported) {
|
||||
final ModifiableRootModel model = ModuleRootManager.getInstance(module).getModifiableModel();
|
||||
final ModuleOrderEntry entry = model.addModuleOrderEntry(dependency);
|
||||
entry.setScope(scope);
|
||||
entry.setExported(exported);
|
||||
model.commit();
|
||||
protected void addModuleDependency(final Module module, final Module dependency, final DependencyScope scope, final boolean exported) {
|
||||
ApplicationManager.getApplication().runWriteAction(new Runnable() {
|
||||
public void run() {
|
||||
final ModifiableRootModel model = ModuleRootManager.getInstance(module).getModifiableModel();
|
||||
final ModuleOrderEntry entry = model.addModuleOrderEntry(dependency);
|
||||
entry.setScope(scope);
|
||||
entry.setExported(exported);
|
||||
model.commit();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
protected Library createLibrary(final String name, final VirtualFile classesRoot) {
|
||||
|
||||
@@ -77,7 +77,8 @@ public class ModuleRootsExternalizationTest extends ModuleTestCase {
|
||||
final Module module = createModule(moduleFile);
|
||||
final ModuleRootManagerImpl moduleRootManager =
|
||||
(ModuleRootManagerImpl)ModuleRootManager.getInstance(module);
|
||||
final Runnable action = new Runnable() {
|
||||
|
||||
ApplicationManager.getApplication().runWriteAction(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
final ModifiableRootModel rootModel = moduleRootManager.getModifiableModel();
|
||||
@@ -92,9 +93,7 @@ public class ModuleRootsExternalizationTest extends ModuleTestCase {
|
||||
contentEntry.addExcludeFolder(excludeFile);
|
||||
rootModel.commit();
|
||||
}
|
||||
};
|
||||
|
||||
ApplicationManager.getApplication().runWriteAction(action);
|
||||
});
|
||||
|
||||
|
||||
final Element element = new Element("root");
|
||||
|
||||
@@ -19,6 +19,7 @@ import com.intellij.codeInsight.highlighting.HighlightUsagesHandler;
|
||||
import com.intellij.ide.DataManager;
|
||||
import com.intellij.injected.editor.EditorWindow;
|
||||
import com.intellij.openapi.actionSystem.*;
|
||||
import com.intellij.openapi.application.ApplicationManager;
|
||||
import com.intellij.openapi.application.Result;
|
||||
import com.intellij.openapi.application.ex.PathManagerEx;
|
||||
import com.intellij.openapi.command.CommandProcessor;
|
||||
@@ -99,8 +100,8 @@ public abstract class CodeInsightTestCase extends PsiTestCase {
|
||||
}
|
||||
|
||||
public static final String CARET_MARKER = "<caret>";
|
||||
public static final String SELECTION_START_MARKER = "<selection>";
|
||||
public static final String SELECTION_END_MARKER = "</selection>";
|
||||
@NonNls public static final String SELECTION_START_MARKER = "<selection>";
|
||||
@NonNls public static final String SELECTION_END_MARKER = "</selection>";
|
||||
|
||||
protected void configureByFile(@NonNls String filePath) throws Exception {
|
||||
configureByFile(filePath, null);
|
||||
@@ -149,16 +150,20 @@ public abstract class CodeInsightTestCase extends PsiTestCase {
|
||||
}.execute();
|
||||
}
|
||||
final VirtualFile vFile = LocalFileSystem.getInstance().refreshAndFindFileByIoFile(tempFile);
|
||||
VfsUtil.saveText(vFile, text);
|
||||
assert vFile != null;
|
||||
VfsUtil.saveText(vFile, text);
|
||||
|
||||
VirtualFile vdir = LocalFileSystem.getInstance().refreshAndFindFileByIoFile(dir);
|
||||
final VirtualFile vdir = LocalFileSystem.getInstance().refreshAndFindFileByIoFile(dir);
|
||||
|
||||
final ModuleRootManager rootManager = ModuleRootManager.getInstance(myModule);
|
||||
final ModifiableRootModel rootModel = rootManager.getModifiableModel();
|
||||
final ContentEntry contentEntry = rootModel.addContentEntry(vdir);
|
||||
contentEntry.addSourceFolder(vdir, false);
|
||||
rootModel.commit();
|
||||
ApplicationManager.getApplication().runWriteAction(new Runnable() {
|
||||
public void run() {
|
||||
final ModuleRootManager rootManager = ModuleRootManager.getInstance(myModule);
|
||||
final ModifiableRootModel rootModel = rootManager.getModifiableModel();
|
||||
final ContentEntry contentEntry = rootModel.addContentEntry(vdir);
|
||||
contentEntry.addSourceFolder(vdir, false);
|
||||
rootModel.commit();
|
||||
}
|
||||
});
|
||||
|
||||
configureByExistingFile(vFile);
|
||||
|
||||
@@ -176,80 +181,96 @@ public abstract class CodeInsightTestCase extends PsiTestCase {
|
||||
configureByFile(vFile, null);
|
||||
}
|
||||
|
||||
protected void configureByExistingFile(VirtualFile virtualFile) {
|
||||
protected void configureByExistingFile(final VirtualFile virtualFile) {
|
||||
myFile = null;
|
||||
myEditor = null;
|
||||
|
||||
Editor editor = createEditor(virtualFile);
|
||||
final Editor editor = createEditor(virtualFile);
|
||||
|
||||
Document document = editor.getDocument();
|
||||
EditorInfo editorInfo = new EditorInfo(document.getText());
|
||||
final Document document = editor.getDocument();
|
||||
final EditorInfo editorInfo = new EditorInfo(document.getText());
|
||||
|
||||
String newFileText = editorInfo.getNewFileText();
|
||||
if (!document.getText().equals(newFileText)) {
|
||||
document.setText(newFileText);
|
||||
}
|
||||
final String newFileText = editorInfo.getNewFileText();
|
||||
ApplicationManager.getApplication().runWriteAction(new Runnable() {
|
||||
public void run() {
|
||||
if (!document.getText().equals(newFileText)) {
|
||||
document.setText(newFileText);
|
||||
}
|
||||
|
||||
PsiFile file = myPsiManager.findFile(virtualFile);
|
||||
if (myFile == null) myFile = file;
|
||||
PsiFile file = myPsiManager.findFile(virtualFile);
|
||||
if (myFile == null) myFile = file;
|
||||
|
||||
if (myEditor == null) myEditor = editor;
|
||||
if (myEditor == null) myEditor = editor;
|
||||
|
||||
editorInfo.applyToEditor(editor);
|
||||
}
|
||||
});
|
||||
|
||||
editorInfo.applyToEditor(editor);
|
||||
|
||||
PsiDocumentManager.getInstance(getProject()).commitAllDocuments();
|
||||
}
|
||||
|
||||
protected VirtualFile configureByFiles(final File rawProjectRoot, VirtualFile... vFiles) throws IOException {
|
||||
protected VirtualFile configureByFiles(final File rawProjectRoot, final VirtualFile... vFiles) throws IOException {
|
||||
myFile = null;
|
||||
myEditor = null;
|
||||
|
||||
final ModuleRootManager rootManager = ModuleRootManager.getInstance(myModule);
|
||||
final ModifiableRootModel rootModel = rootManager.getModifiableModel();
|
||||
if (clearModelBeforeConfiguring()) {
|
||||
rootModel.clear();
|
||||
}
|
||||
File toDirIO = createTempDirectory();
|
||||
VirtualFile toDir = getVirtualFile(toDirIO);
|
||||
final File toDirIO = createTempDirectory();
|
||||
final VirtualFile toDir = getVirtualFile(toDirIO);
|
||||
|
||||
// auxiliary files should be copied first
|
||||
vFiles = ArrayUtil.reverseArray(vFiles);
|
||||
final LinkedHashMap<VirtualFile, EditorInfo> editorInfos;
|
||||
if (rawProjectRoot != null) {
|
||||
final File projectRoot = rawProjectRoot.getCanonicalFile();
|
||||
FileUtil.copyDir(projectRoot, toDirIO);
|
||||
VirtualFile fromDir = getVirtualFile(projectRoot);
|
||||
editorInfos =
|
||||
copyFilesFillingEditorInfos(fromDir, toDir, ContainerUtil.map2Array(vFiles, String.class, new Function<VirtualFile, String>() {
|
||||
@Override
|
||||
public String fun(final VirtualFile s) {
|
||||
return s.getPath().substring(projectRoot.getPath().length());
|
||||
ApplicationManager.getApplication().runWriteAction(new Runnable() {
|
||||
public void run() {
|
||||
try {
|
||||
final ModuleRootManager rootManager = ModuleRootManager.getInstance(myModule);
|
||||
final ModifiableRootModel rootModel = rootManager.getModifiableModel();
|
||||
if (clearModelBeforeConfiguring()) {
|
||||
rootModel.clear();
|
||||
}
|
||||
}));
|
||||
|
||||
VirtualFileManager.getInstance().refresh(false);
|
||||
}
|
||||
else {
|
||||
editorInfos = new LinkedHashMap<VirtualFile, EditorInfo>();
|
||||
for (final VirtualFile vFile : vFiles) {
|
||||
editorInfos.putAll(copyFilesFillingEditorInfos(vFile.getParent(), toDir, vFile.getName()));
|
||||
// auxiliary files should be copied first
|
||||
VirtualFile[] reversed = ArrayUtil.reverseArray(vFiles);
|
||||
final LinkedHashMap<VirtualFile, EditorInfo> editorInfos;
|
||||
if (rawProjectRoot != null) {
|
||||
final File projectRoot = rawProjectRoot.getCanonicalFile();
|
||||
FileUtil.copyDir(projectRoot, toDirIO);
|
||||
VirtualFile fromDir = getVirtualFile(projectRoot);
|
||||
editorInfos =
|
||||
copyFilesFillingEditorInfos(fromDir, toDir, ContainerUtil.map2Array(reversed, String.class, new Function<VirtualFile, String>() {
|
||||
@Override
|
||||
public String fun(final VirtualFile s) {
|
||||
return s.getPath().substring(projectRoot.getPath().length());
|
||||
}
|
||||
}));
|
||||
|
||||
VirtualFileManager.getInstance().refresh(false);
|
||||
}
|
||||
else {
|
||||
editorInfos = new LinkedHashMap<VirtualFile, EditorInfo>();
|
||||
for (final VirtualFile vFile : reversed) {
|
||||
editorInfos.putAll(copyFilesFillingEditorInfos(vFile.getParent(), toDir, vFile.getName()));
|
||||
}
|
||||
}
|
||||
|
||||
boolean sourceRootAdded = false;
|
||||
if (isAddDirToContentRoot()) {
|
||||
final ContentEntry contentEntry = rootModel.addContentEntry(toDir);
|
||||
if (isAddDirToSource()) {
|
||||
sourceRootAdded = true;
|
||||
contentEntry.addSourceFolder(toDir, false);
|
||||
}
|
||||
}
|
||||
doCommitModel(rootModel);
|
||||
if (sourceRootAdded) {
|
||||
sourceRootAdded(toDir);
|
||||
}
|
||||
|
||||
openEditorsAndActivateLast(editorInfos);
|
||||
}
|
||||
catch (IOException e) {
|
||||
LOG.error(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
boolean sourceRootAdded = false;
|
||||
if (isAddDirToContentRoot()) {
|
||||
final ContentEntry contentEntry = rootModel.addContentEntry(toDir);
|
||||
if (isAddDirToSource()) {
|
||||
sourceRootAdded = true;
|
||||
contentEntry.addSourceFolder(toDir, false);
|
||||
}
|
||||
}
|
||||
doCommitModel(rootModel);
|
||||
if (sourceRootAdded) {
|
||||
sourceRootAdded(toDir);
|
||||
}
|
||||
|
||||
openEditorsAndActivateLast(editorInfos);
|
||||
|
||||
return toDir;
|
||||
}
|
||||
@@ -381,7 +402,7 @@ public abstract class CodeInsightTestCase extends PsiTestCase {
|
||||
}
|
||||
|
||||
protected VirtualFile configureByFile(final VirtualFile vFile, final File projectRoot) throws IOException {
|
||||
return configureByFiles(projectRoot, new VirtualFile[] {vFile});
|
||||
return configureByFiles(projectRoot, vFile);
|
||||
}
|
||||
|
||||
protected boolean clearModelBeforeConfiguring() {
|
||||
@@ -452,87 +473,99 @@ public abstract class CodeInsightTestCase extends PsiTestCase {
|
||||
checkResultByFile(filePath, false);
|
||||
}
|
||||
|
||||
protected void checkResultByFile(@NonNls String filePath, boolean stripTrailingSpaces) throws Exception {
|
||||
getProject().getComponent(PostprocessReformattingAspect.class).doPostponedFormatting();
|
||||
if (stripTrailingSpaces) {
|
||||
((DocumentEx)myEditor.getDocument()).stripTrailingSpaces(false);
|
||||
}
|
||||
protected void checkResultByFile(@NonNls final String filePath, final boolean stripTrailingSpaces) throws Exception {
|
||||
ApplicationManager.getApplication().runWriteAction(new Runnable() {
|
||||
public void run() {
|
||||
getProject().getComponent(PostprocessReformattingAspect.class).doPostponedFormatting();
|
||||
if (stripTrailingSpaces) {
|
||||
((DocumentEx)myEditor.getDocument()).stripTrailingSpaces(false);
|
||||
}
|
||||
|
||||
PsiDocumentManager.getInstance(myProject).commitAllDocuments();
|
||||
PsiDocumentManager.getInstance(myProject).commitAllDocuments();
|
||||
|
||||
String fullPath = getTestDataPath() + filePath;
|
||||
String fullPath = getTestDataPath() + filePath;
|
||||
|
||||
final VirtualFile vFile = LocalFileSystem.getInstance().findFileByPath(fullPath.replace(File.separatorChar, '/'));
|
||||
assertNotNull("Cannot find file " + fullPath, vFile);
|
||||
String fileText = StringUtil.convertLineSeparators(VfsUtil.loadText(vFile));
|
||||
Document document = EditorFactory.getInstance().createDocument(fileText);
|
||||
final VirtualFile vFile = LocalFileSystem.getInstance().findFileByPath(fullPath.replace(File.separatorChar, '/'));
|
||||
assertNotNull("Cannot find file " + fullPath, vFile);
|
||||
String ft = null;
|
||||
try {
|
||||
ft = VfsUtil.loadText(vFile);
|
||||
}
|
||||
catch (IOException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
|
||||
int caretIndex = fileText.indexOf(CARET_MARKER);
|
||||
int selStartIndex = fileText.indexOf(SELECTION_START_MARKER);
|
||||
int selEndIndex = fileText.indexOf(SELECTION_END_MARKER);
|
||||
String fileText = StringUtil.convertLineSeparators(ft);
|
||||
Document document = EditorFactory.getInstance().createDocument(fileText);
|
||||
|
||||
final RangeMarker caretMarker = caretIndex >= 0 ? document.createRangeMarker(caretIndex, caretIndex) : null;
|
||||
final RangeMarker selStartMarker = selStartIndex >= 0 ? document.createRangeMarker(selStartIndex, selStartIndex) : null;
|
||||
final RangeMarker selEndMarker = selEndIndex >= 0 ? document.createRangeMarker(selEndIndex, selEndIndex) : null;
|
||||
int caretIndex = fileText.indexOf(CARET_MARKER);
|
||||
int selStartIndex = fileText.indexOf(SELECTION_START_MARKER);
|
||||
int selEndIndex = fileText.indexOf(SELECTION_END_MARKER);
|
||||
|
||||
if (caretMarker != null) {
|
||||
document.deleteString(caretMarker.getStartOffset(), caretMarker.getStartOffset() + CARET_MARKER.length());
|
||||
}
|
||||
if (selStartMarker != null) {
|
||||
document.deleteString(selStartMarker.getStartOffset(), selStartMarker.getStartOffset() + SELECTION_START_MARKER.length());
|
||||
}
|
||||
if (selEndMarker != null) {
|
||||
document.deleteString(selEndMarker.getStartOffset(), selEndMarker.getStartOffset() + SELECTION_END_MARKER.length());
|
||||
}
|
||||
final RangeMarker caretMarker = caretIndex >= 0 ? document.createRangeMarker(caretIndex, caretIndex) : null;
|
||||
final RangeMarker selStartMarker = selStartIndex >= 0 ? document.createRangeMarker(selStartIndex, selStartIndex) : null;
|
||||
final RangeMarker selEndMarker = selEndIndex >= 0 ? document.createRangeMarker(selEndIndex, selEndIndex) : null;
|
||||
|
||||
String newFileText = document.getText();
|
||||
String newFileText1 = newFileText;
|
||||
if (stripTrailingSpaces) {
|
||||
Document document1 = EditorFactory.getInstance().createDocument(newFileText);
|
||||
((DocumentEx)document1).stripTrailingSpaces(false);
|
||||
newFileText1 = document1.getText();
|
||||
}
|
||||
if (caretMarker != null) {
|
||||
document.deleteString(caretMarker.getStartOffset(), caretMarker.getStartOffset() + CARET_MARKER.length());
|
||||
}
|
||||
if (selStartMarker != null) {
|
||||
document.deleteString(selStartMarker.getStartOffset(), selStartMarker.getStartOffset() + SELECTION_START_MARKER.length());
|
||||
}
|
||||
if (selEndMarker != null) {
|
||||
document.deleteString(selEndMarker.getStartOffset(), selEndMarker.getStartOffset() + SELECTION_END_MARKER.length());
|
||||
}
|
||||
|
||||
if (myEditor instanceof EditorWindow) {
|
||||
myEditor = ((EditorWindow)myEditor).getDelegate();
|
||||
myFile = PsiDocumentManager.getInstance(getProject()).getPsiFile(myEditor.getDocument());
|
||||
}
|
||||
|
||||
String text = myFile.getText();
|
||||
text = StringUtil.convertLineSeparators(text);
|
||||
String newFileText = document.getText();
|
||||
String newFileText1 = newFileText;
|
||||
if (stripTrailingSpaces) {
|
||||
Document document1 = EditorFactory.getInstance().createDocument(newFileText);
|
||||
((DocumentEx)document1).stripTrailingSpaces(false);
|
||||
newFileText1 = document1.getText();
|
||||
}
|
||||
|
||||
assertEquals("Text mismatch in file " + filePath, newFileText1, text);
|
||||
if (myEditor instanceof EditorWindow) {
|
||||
myEditor = ((EditorWindow)myEditor).getDelegate();
|
||||
myFile = PsiDocumentManager.getInstance(getProject()).getPsiFile(myEditor.getDocument());
|
||||
}
|
||||
|
||||
if (caretMarker != null) {
|
||||
int caretLine = StringUtil.offsetToLineNumber(newFileText, caretMarker.getStartOffset());
|
||||
int caretCol = caretMarker.getStartOffset() - StringUtil.lineColToOffset(newFileText, caretLine, 0);
|
||||
String text = myFile.getText();
|
||||
text = StringUtil.convertLineSeparators(text);
|
||||
|
||||
assertEquals("caretLine", caretLine + 1, myEditor.getCaretModel().getLogicalPosition().line + 1);
|
||||
assertEquals("caretColumn", caretCol + 1, myEditor.getCaretModel().getLogicalPosition().column + 1);
|
||||
}
|
||||
assertEquals("Text mismatch in file " + filePath, newFileText1, text);
|
||||
|
||||
if (selStartMarker != null && selEndMarker != null) {
|
||||
int selStartLine = StringUtil.offsetToLineNumber(newFileText, selStartMarker.getStartOffset());
|
||||
int selStartCol = selStartMarker.getStartOffset() - StringUtil.lineColToOffset(newFileText, selStartLine, 0);
|
||||
if (caretMarker != null) {
|
||||
int caretLine = StringUtil.offsetToLineNumber(newFileText, caretMarker.getStartOffset());
|
||||
int caretCol = caretMarker.getStartOffset() - StringUtil.lineColToOffset(newFileText, caretLine, 0);
|
||||
|
||||
int selEndLine = StringUtil.offsetToLineNumber(newFileText, selEndMarker.getEndOffset());
|
||||
int selEndCol = selEndMarker.getEndOffset() - StringUtil.lineColToOffset(newFileText, selEndLine, 0);
|
||||
assertEquals("caretLine", caretLine + 1, myEditor.getCaretModel().getLogicalPosition().line + 1);
|
||||
assertEquals("caretColumn", caretCol + 1, myEditor.getCaretModel().getLogicalPosition().column + 1);
|
||||
}
|
||||
|
||||
assertEquals("selectionStartLine", selStartLine + 1,
|
||||
StringUtil.offsetToLineNumber(newFileText, myEditor.getSelectionModel().getSelectionStart()) + 1);
|
||||
if (selStartMarker != null && selEndMarker != null) {
|
||||
int selStartLine = StringUtil.offsetToLineNumber(newFileText, selStartMarker.getStartOffset());
|
||||
int selStartCol = selStartMarker.getStartOffset() - StringUtil.lineColToOffset(newFileText, selStartLine, 0);
|
||||
|
||||
assertEquals("selectionStartCol", selStartCol + 1,
|
||||
myEditor.getSelectionModel().getSelectionStart() - StringUtil.lineColToOffset(newFileText, selStartLine, 0) + 1);
|
||||
int selEndLine = StringUtil.offsetToLineNumber(newFileText, selEndMarker.getEndOffset());
|
||||
int selEndCol = selEndMarker.getEndOffset() - StringUtil.lineColToOffset(newFileText, selEndLine, 0);
|
||||
|
||||
assertEquals("selectionEndLine", selEndLine + 1,
|
||||
StringUtil.offsetToLineNumber(newFileText, myEditor.getSelectionModel().getSelectionEnd()) + 1);
|
||||
assertEquals("selectionStartLine", selStartLine + 1,
|
||||
StringUtil.offsetToLineNumber(newFileText, myEditor.getSelectionModel().getSelectionStart()) + 1);
|
||||
|
||||
assertEquals("selectionEndCol", selEndCol + 1,
|
||||
myEditor.getSelectionModel().getSelectionEnd() - StringUtil.lineColToOffset(newFileText, selEndLine, 0) + 1);
|
||||
}
|
||||
else {
|
||||
assertTrue("has no selection", !myEditor.getSelectionModel().hasSelection());
|
||||
}
|
||||
assertEquals("selectionStartCol", selStartCol + 1,
|
||||
myEditor.getSelectionModel().getSelectionStart() - StringUtil.lineColToOffset(newFileText, selStartLine, 0) + 1);
|
||||
|
||||
assertEquals("selectionEndLine", selEndLine + 1,
|
||||
StringUtil.offsetToLineNumber(newFileText, myEditor.getSelectionModel().getSelectionEnd()) + 1);
|
||||
|
||||
assertEquals("selectionEndCol", selEndCol + 1,
|
||||
myEditor.getSelectionModel().getSelectionEnd() - StringUtil.lineColToOffset(newFileText, selEndLine, 0) + 1);
|
||||
}
|
||||
else {
|
||||
assertTrue("has no selection", !myEditor.getSelectionModel().hasSelection());
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -625,8 +658,8 @@ public abstract class CodeInsightTestCase extends PsiTestCase {
|
||||
|
||||
public static void ctrlW() {
|
||||
AnAction action = ActionManager.getInstance().getAction(IdeActions.ACTION_EDITOR_SELECT_WORD_AT_CARET);
|
||||
AnActionEvent event = new AnActionEvent(null, DataManager.getInstance().getDataContext(), "", action.getTemplatePresentation(),
|
||||
ActionManager.getInstance(), 0);
|
||||
DataContext dataContext = DataManager.getInstance().getDataContext();
|
||||
AnActionEvent event = new AnActionEvent(null, dataContext, "", action.getTemplatePresentation(), ActionManager.getInstance(), 0);
|
||||
event.setInjectedContext(true);
|
||||
action.actionPerformed(event);
|
||||
}
|
||||
|
||||
@@ -15,6 +15,7 @@
|
||||
*/
|
||||
package com.intellij.codeInsight;
|
||||
|
||||
import com.intellij.openapi.application.ApplicationManager;
|
||||
import com.intellij.openapi.editor.*;
|
||||
import com.intellij.openapi.util.text.StringUtil;
|
||||
import org.jetbrains.annotations.NonNls;
|
||||
@@ -32,11 +33,15 @@ public class EditorInfo {
|
||||
RangeMarker selStartMarker = null;
|
||||
RangeMarker selEndMarker = null;
|
||||
|
||||
public EditorInfo(String fileText) {
|
||||
updateCaretAndSelection(EditorFactory.getInstance().createDocument(fileText));
|
||||
public EditorInfo(final String fileText) {
|
||||
ApplicationManager.getApplication().runWriteAction(new Runnable() {
|
||||
public void run() {
|
||||
updateCaretAndSelection(EditorFactory.getInstance().createDocument(fileText));
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public boolean updateCaretAndSelection(final Document document) {
|
||||
private boolean updateCaretAndSelection(final Document document) {
|
||||
newFileText = document.getText();
|
||||
|
||||
int caretIndex = newFileText.indexOf(CARET_MARKER);
|
||||
|
||||
@@ -35,6 +35,8 @@ import com.intellij.ide.startup.StartupManagerEx;
|
||||
import com.intellij.ide.startup.impl.StartupManagerImpl;
|
||||
import com.intellij.lang.annotation.HighlightSeverity;
|
||||
import com.intellij.openapi.Disposable;
|
||||
import com.intellij.openapi.application.Result;
|
||||
import com.intellij.openapi.command.WriteCommandAction;
|
||||
import com.intellij.openapi.editor.Document;
|
||||
import com.intellij.openapi.editor.Editor;
|
||||
import com.intellij.openapi.module.Module;
|
||||
@@ -82,6 +84,11 @@ public abstract class DaemonAnalyzerTestCase extends CodeInsightTestCase {
|
||||
private boolean toInitializeDaemon;
|
||||
private final FileTreeAccessFilter myFileTreeAccessFilter = new FileTreeAccessFilter();
|
||||
|
||||
@Override
|
||||
protected boolean isRunInWriteAction() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void setUp() throws Exception {
|
||||
super.setUp();
|
||||
@@ -242,7 +249,6 @@ public abstract class DaemonAnalyzerTestCase extends CodeInsightTestCase {
|
||||
}
|
||||
|
||||
protected Collection<HighlightInfo> doDoTest(boolean checkWarnings, boolean checkInfos, boolean checkWeakWarnings) {
|
||||
|
||||
return checkHighlighting(new ExpectedHighlightingData(myEditor.getDocument(),checkWarnings, checkWeakWarnings, checkInfos, myFile));
|
||||
}
|
||||
|
||||
@@ -414,22 +420,32 @@ public abstract class DaemonAnalyzerTestCase extends CodeInsightTestCase {
|
||||
}
|
||||
|
||||
protected PsiClass createClass(final Module module, final String text) throws IOException {
|
||||
final String qname = ((PsiJavaFile)PsiFileFactory.getInstance(getProject()).createFileFromText("a.java", text)).getClasses()[0].getQualifiedName();
|
||||
final VirtualFile[] files = ModuleRootManager.getInstance(module).getSourceRoots();
|
||||
File dir;
|
||||
if (files.length > 0) {
|
||||
dir = VfsUtil.virtualToIoFile(files[0]);
|
||||
}
|
||||
else {
|
||||
dir = createTempDirectory();
|
||||
VirtualFile vDir = LocalFileSystem.getInstance().refreshAndFindFileByPath(dir.getCanonicalPath().replace(File.separatorChar, '/'));
|
||||
addSourceContentToRoots(module, vDir);
|
||||
}
|
||||
return new WriteCommandAction<PsiClass>(getProject()) {
|
||||
@Override
|
||||
protected void run(Result<PsiClass> result) throws Throwable {
|
||||
final String qname =
|
||||
((PsiJavaFile)PsiFileFactory.getInstance(getProject()).createFileFromText("a.java", text)).getClasses()[0].getQualifiedName();
|
||||
final VirtualFile[] files = ModuleRootManager.getInstance(module).getSourceRoots();
|
||||
File dir;
|
||||
if (files.length > 0) {
|
||||
dir = VfsUtil.virtualToIoFile(files[0]);
|
||||
}
|
||||
else {
|
||||
dir = createTempDirectory();
|
||||
VirtualFile vDir =
|
||||
LocalFileSystem.getInstance().refreshAndFindFileByPath(dir.getCanonicalPath().replace(File.separatorChar, '/'));
|
||||
addSourceContentToRoots(module, vDir);
|
||||
}
|
||||
|
||||
File file = new File(dir, qname.replace('.', '/') + ".java");
|
||||
FileUtil.createIfDoesntExist(file);
|
||||
VirtualFile vFile = LocalFileSystem.getInstance().refreshAndFindFileByPath(file.getCanonicalPath().replace(File.separatorChar, '/'));
|
||||
VfsUtil.saveText(vFile, text);
|
||||
return ((PsiJavaFile)myPsiManager.findFile(vFile)).getClasses()[0];
|
||||
File file = new File(dir, qname.replace('.', '/') + ".java");
|
||||
FileUtil.createIfDoesntExist(file);
|
||||
VirtualFile vFile =
|
||||
LocalFileSystem.getInstance().refreshAndFindFileByPath(file.getCanonicalPath().replace(File.separatorChar, '/'));
|
||||
VfsUtil.saveText(vFile, text);
|
||||
PsiClass psiClass = ((PsiJavaFile)myPsiManager.findFile(vFile)).getClasses()[0];
|
||||
result.setResult(psiClass);
|
||||
|
||||
}
|
||||
}.execute().throwException().getResultObject();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -19,6 +19,7 @@ import com.intellij.codeHighlighting.Pass;
|
||||
import com.intellij.codeInsight.daemon.impl.DaemonCodeAnalyzerImpl;
|
||||
import com.intellij.codeInsight.daemon.impl.HighlightInfo;
|
||||
import com.intellij.injected.editor.EditorWindow;
|
||||
import com.intellij.openapi.command.CommandProcessor;
|
||||
import com.intellij.openapi.editor.Editor;
|
||||
import com.intellij.openapi.vfs.VirtualFileFilter;
|
||||
import com.intellij.psi.PsiDocumentManager;
|
||||
@@ -54,6 +55,25 @@ public abstract class LightDaemonAnalyzerTestCase extends LightCodeInsightTestCa
|
||||
super.tearDown();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void runTest() throws Throwable {
|
||||
final Throwable[] throwable = {null};
|
||||
CommandProcessor.getInstance().executeCommand(getProject(), new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
try {
|
||||
doRunTest();
|
||||
}
|
||||
catch (Throwable t) {
|
||||
throwable[0] = t;
|
||||
}
|
||||
}
|
||||
}, "", null);
|
||||
if (throwable[0] != null) {
|
||||
throw throwable[0];
|
||||
}
|
||||
}
|
||||
|
||||
protected void doTest(@NonNls String filePath, boolean checkWarnings, boolean checkInfos) throws Exception {
|
||||
configureByFile(filePath);
|
||||
doTestConfiguredFile(checkWarnings, checkInfos);
|
||||
|
||||
@@ -21,7 +21,6 @@ import com.intellij.codeInsight.intention.IntentionAction;
|
||||
import com.intellij.codeInsight.intention.impl.ShowIntentionActionsHandler;
|
||||
import com.intellij.lang.Commenter;
|
||||
import com.intellij.lang.LanguageCommenters;
|
||||
import com.intellij.openapi.application.ApplicationManager;
|
||||
import com.intellij.openapi.command.CommandProcessor;
|
||||
import com.intellij.openapi.editor.Editor;
|
||||
import com.intellij.openapi.util.Pair;
|
||||
@@ -30,8 +29,8 @@ import com.intellij.openapi.util.text.StringUtil;
|
||||
import com.intellij.openapi.vfs.CharsetToolkit;
|
||||
import com.intellij.psi.PsiFile;
|
||||
import com.intellij.psi.impl.source.tree.injected.InjectedLanguageUtil;
|
||||
import com.intellij.testFramework.fixtures.impl.CodeInsightTestFixtureImpl;
|
||||
import com.intellij.testFramework.LightCodeInsightTestCase;
|
||||
import com.intellij.testFramework.fixtures.impl.CodeInsightTestFixtureImpl;
|
||||
import com.intellij.util.IncorrectOperationException;
|
||||
import com.intellij.util.ui.UIUtil;
|
||||
import org.intellij.lang.annotations.RegExp;
|
||||
@@ -62,37 +61,32 @@ public abstract class LightQuickFixTestCase extends LightDaemonAnalyzerTestCase
|
||||
CommandProcessor.getInstance().executeCommand(getProject(), new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
ApplicationManager.getApplication().runWriteAction(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
final String relativePath = quickFixTestCase.getBasePath() + "/" + BEFORE_PREFIX + testName;
|
||||
final String testFullPath = quickFixTestCase.getTestDataPath().replace(File.separatorChar, '/') + relativePath;
|
||||
final File ioFile = new File(testFullPath);
|
||||
try {
|
||||
String contents = StringUtil.convertLineSeparators(new String(FileUtil.loadFileText(ioFile, CharsetToolkit.UTF8)));
|
||||
quickFixTestCase.configureFromFileText(ioFile.getName(), contents);
|
||||
quickFixTestCase.bringRealEditorBack();
|
||||
final Pair<String, Boolean> pair = quickFixTestCase.parseActionHintImpl(quickFixTestCase.getFile(), contents);
|
||||
final String text = pair.getFirst();
|
||||
final boolean actionShouldBeAvailable = pair.getSecond().booleanValue();
|
||||
final String relativePath = quickFixTestCase.getBasePath() + "/" + BEFORE_PREFIX + testName;
|
||||
final String testFullPath = quickFixTestCase.getTestDataPath().replace(File.separatorChar, '/') + relativePath;
|
||||
final File ioFile = new File(testFullPath);
|
||||
try {
|
||||
String contents = StringUtil.convertLineSeparators(new String(FileUtil.loadFileText(ioFile, CharsetToolkit.UTF8)));
|
||||
quickFixTestCase.configureFromFileText(ioFile.getName(), contents);
|
||||
quickFixTestCase.bringRealEditorBack();
|
||||
final Pair<String, Boolean> pair = quickFixTestCase.parseActionHintImpl(quickFixTestCase.getFile(), contents);
|
||||
final String text = pair.getFirst();
|
||||
final boolean actionShouldBeAvailable = pair.getSecond().booleanValue();
|
||||
|
||||
quickFixTestCase.beforeActionStarted(testName, contents);
|
||||
quickFixTestCase.beforeActionStarted(testName, contents);
|
||||
|
||||
try {
|
||||
myWrapper = quickFixTestCase;
|
||||
quickFixTestCase.doAction(text, actionShouldBeAvailable, testFullPath, testName);
|
||||
}
|
||||
finally {
|
||||
myWrapper = null;
|
||||
quickFixTestCase.afterActionCompleted(testName, contents);
|
||||
}
|
||||
}
|
||||
catch (Throwable e) {
|
||||
e.printStackTrace();
|
||||
fail(testName);
|
||||
}
|
||||
try {
|
||||
myWrapper = quickFixTestCase;
|
||||
quickFixTestCase.doAction(text, actionShouldBeAvailable, testFullPath, testName);
|
||||
}
|
||||
});
|
||||
finally {
|
||||
myWrapper = null;
|
||||
quickFixTestCase.afterActionCompleted(testName, contents);
|
||||
}
|
||||
}
|
||||
catch (Throwable e) {
|
||||
e.printStackTrace();
|
||||
fail(testName);
|
||||
}
|
||||
}
|
||||
}, "", "");
|
||||
System.out.print(testName + " ");
|
||||
|
||||
@@ -138,12 +138,16 @@ public abstract class ModuleTestCase extends IdeaTestCase {
|
||||
return module;
|
||||
}
|
||||
|
||||
protected void readJdomExternalizables(ModuleImpl module) {
|
||||
final ProjectImpl project = (ProjectImpl)myProject;
|
||||
project.setOptimiseTestLoadSpeed(false);
|
||||
final ModuleRootManagerImpl moduleRootManager = (ModuleRootManagerImpl)ModuleRootManager.getInstance(module);
|
||||
module.getStateStore().initComponent(moduleRootManager, false);
|
||||
project.setOptimiseTestLoadSpeed(true);
|
||||
protected void readJdomExternalizables(final ModuleImpl module) {
|
||||
ApplicationManager.getApplication().runWriteAction(new Runnable() {
|
||||
public void run() {
|
||||
final ProjectImpl project = (ProjectImpl)myProject;
|
||||
project.setOptimiseTestLoadSpeed(false);
|
||||
final ModuleRootManagerImpl moduleRootManager = (ModuleRootManagerImpl)ModuleRootManager.getInstance(module);
|
||||
module.getStateStore().initComponent(moduleRootManager, false);
|
||||
project.setOptimiseTestLoadSpeed(true);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
protected Module createModuleFromTestData(final String dirInTestData, final String newModuleFileName, final ModuleType moduleType,
|
||||
|
||||
@@ -15,6 +15,9 @@
|
||||
*/
|
||||
package com.intellij.testFramework;
|
||||
|
||||
import com.intellij.openapi.application.ApplicationManager;
|
||||
import com.intellij.openapi.application.Result;
|
||||
import com.intellij.openapi.application.WriteAction;
|
||||
import com.intellij.openapi.application.ex.PathManagerEx;
|
||||
import com.intellij.openapi.module.Module;
|
||||
import com.intellij.openapi.projectRoots.impl.JavaSdkImpl;
|
||||
@@ -84,17 +87,22 @@ public abstract class PsiTestCase extends ModuleTestCase {
|
||||
return createFile(module, vDir, fileName, text);
|
||||
}
|
||||
|
||||
protected PsiFile createFile(Module module, VirtualFile vDir, String fileName, String text) throws IOException {
|
||||
if (!ModuleRootManager.getInstance(module).getFileIndex().isInSourceContent(vDir)) {
|
||||
addSourceContentToRoots(module, vDir);
|
||||
}
|
||||
protected PsiFile createFile(final Module module, final VirtualFile vDir, final String fileName, final String text) throws IOException {
|
||||
return new WriteAction<PsiFile>() {
|
||||
@Override
|
||||
protected void run(Result<PsiFile> result) throws Throwable {
|
||||
if (!ModuleRootManager.getInstance(module).getFileIndex().isInSourceContent(vDir)) {
|
||||
addSourceContentToRoots(module, vDir);
|
||||
}
|
||||
|
||||
final VirtualFile vFile = vDir.createChildData(vDir, fileName);
|
||||
VfsUtil.saveText(vFile, text);
|
||||
assertNotNull(vFile);
|
||||
final PsiFile file = myPsiManager.findFile(vFile);
|
||||
assertNotNull(file);
|
||||
return file;
|
||||
final VirtualFile vFile = vDir.createChildData(vDir, fileName);
|
||||
VfsUtil.saveText(vFile, text);
|
||||
assertNotNull(vFile);
|
||||
final PsiFile file = myPsiManager.findFile(vFile);
|
||||
assertNotNull(file);
|
||||
result.setResult(file);
|
||||
}
|
||||
}.execute().getResultObject();
|
||||
}
|
||||
|
||||
protected void addSourceContentToRoots(final Module module, final VirtualFile vDir) {
|
||||
@@ -141,8 +149,8 @@ public abstract class PsiTestCase extends ModuleTestCase {
|
||||
|
||||
final List nodes = documentElement.getChildren("data");
|
||||
|
||||
for (int i = 0; i < nodes.size(); i++) {
|
||||
Element node = (Element)nodes.get(i);
|
||||
for (Object node1 : nodes) {
|
||||
Element node = (Element)node1;
|
||||
String value = node.getAttributeValue("name");
|
||||
|
||||
if (value.equals(dataName)) {
|
||||
@@ -208,13 +216,17 @@ public abstract class PsiTestCase extends ModuleTestCase {
|
||||
}
|
||||
|
||||
protected static void addLibraryToRoots(final Module module, final VirtualFile jarFile, final OrderRootType rootType) {
|
||||
final ModuleRootManager manager = ModuleRootManager.getInstance(module);
|
||||
final ModifiableRootModel rootModel = manager.getModifiableModel();
|
||||
final Library jarLibrary = rootModel.getModuleLibraryTable().createLibrary();
|
||||
final Library.ModifiableModel libraryModel = jarLibrary.getModifiableModel();
|
||||
libraryModel.addRoot(jarFile, rootType);
|
||||
libraryModel.commit();
|
||||
rootModel.commit();
|
||||
ApplicationManager.getApplication().runWriteAction(new Runnable() {
|
||||
public void run() {
|
||||
final ModuleRootManager manager = ModuleRootManager.getInstance(module);
|
||||
final ModifiableRootModel rootModel = manager.getModifiableModel();
|
||||
final Library jarLibrary = rootModel.getModuleLibraryTable().createLibrary();
|
||||
final Library.ModifiableModel libraryModel = jarLibrary.getModifiableModel();
|
||||
libraryModel.addRoot(jarFile, rootType);
|
||||
libraryModel.commit();
|
||||
rootModel.commit();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -17,8 +17,6 @@ package com.intellij.testFramework.fixtures;
|
||||
|
||||
import com.intellij.lang.Language;
|
||||
import com.intellij.openapi.application.PathManager;
|
||||
import com.intellij.openapi.application.Result;
|
||||
import com.intellij.openapi.command.WriteCommandAction;
|
||||
import com.intellij.openapi.fileTypes.FileType;
|
||||
import com.intellij.openapi.module.Module;
|
||||
import com.intellij.openapi.module.ModuleType;
|
||||
@@ -116,17 +114,6 @@ public abstract class LightCodeInsightFixtureTestCase extends UsefulTestCase{
|
||||
myModule = null;
|
||||
super.tearDown();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void runTest() throws Throwable {
|
||||
new WriteCommandAction(getProject()) {
|
||||
@Override
|
||||
protected void run(Result result) throws Throwable {
|
||||
runTestBare();
|
||||
}
|
||||
}.execute();
|
||||
}
|
||||
|
||||
protected final void runTestBare() throws Throwable {
|
||||
LightCodeInsightFixtureTestCase.super.runTest();
|
||||
}
|
||||
|
||||
@@ -45,7 +45,6 @@ import com.intellij.openapi.fileEditor.TextEditor;
|
||||
import com.intellij.openapi.fileTypes.FileType;
|
||||
import com.intellij.openapi.fileTypes.StdFileTypes;
|
||||
import com.intellij.openapi.progress.ProgressIndicator;
|
||||
import com.intellij.openapi.progress.ProgressManager;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.openapi.util.*;
|
||||
import com.intellij.openapi.vfs.VirtualFile;
|
||||
@@ -72,7 +71,6 @@ import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.annotations.TestOnly;
|
||||
|
||||
import javax.swing.*;
|
||||
import java.util.*;
|
||||
|
||||
/**
|
||||
@@ -172,17 +170,14 @@ public class DaemonCodeAnalyzerImpl extends DaemonCodeAnalyzer implements JDOMEx
|
||||
public List<HighlightInfo> runPasses(@NotNull PsiFile file,
|
||||
@NotNull Document document,
|
||||
@NotNull TextEditor textEditor,
|
||||
@NotNull final ProgressIndicator progress,
|
||||
@NotNull final DaemonProgressIndicator progress,
|
||||
@NotNull int[] toIgnore,
|
||||
boolean allowDirt,
|
||||
final boolean apply) {
|
||||
boolean allowDirt) {
|
||||
ApplicationManager.getApplication().assertIsDispatchThread();
|
||||
assert !ApplicationManager.getApplication().isWriteAccessAllowed();
|
||||
|
||||
// pump first so that queued event do not interfere
|
||||
if (SwingUtilities.isEventDispatchThread()) {
|
||||
UIUtil.dispatchAllInvocationEvents();
|
||||
}
|
||||
else {
|
||||
UIUtil.pump();
|
||||
}
|
||||
UIUtil.dispatchAllInvocationEvents();
|
||||
|
||||
Project project = file.getProject();
|
||||
setUpdateByTimerEnabled(false);
|
||||
@@ -191,27 +186,35 @@ public class DaemonCodeAnalyzerImpl extends DaemonCodeAnalyzer implements JDOMEx
|
||||
fileStatusMap.markFileUpToDate(document, file, ignoreId);
|
||||
}
|
||||
fileStatusMap.allowDirt(allowDirt);
|
||||
try {
|
||||
TextEditorBackgroundHighlighter highlighter = (TextEditorBackgroundHighlighter)textEditor.getBackgroundHighlighter();
|
||||
final List<TextEditorHighlightingPass> passes = highlighter.getPasses(toIgnore);
|
||||
ProgressManager.getInstance().runProcess(new Runnable() {
|
||||
public void run() {
|
||||
for (TextEditorHighlightingPass pass : passes) {
|
||||
pass.collectInformation(progress);
|
||||
if (apply) {
|
||||
// apply incremental highlights scheduled for AWT thread
|
||||
if (SwingUtilities.isEventDispatchThread()) {
|
||||
UIUtil.dispatchAllInvocationEvents();
|
||||
}
|
||||
else {
|
||||
UIUtil.pump();
|
||||
}
|
||||
pass.applyInformationToEditor();
|
||||
}
|
||||
}
|
||||
}
|
||||
}, progress);
|
||||
|
||||
TextEditorBackgroundHighlighter highlighter = (TextEditorBackgroundHighlighter)textEditor.getBackgroundHighlighter();
|
||||
final List<TextEditorHighlightingPass> passes = highlighter.getPasses(toIgnore);
|
||||
HighlightingPass[] array = passes.toArray(new HighlightingPass[passes.size()]);
|
||||
|
||||
myPassExecutorService.submitPasses(Collections.singletonMap((FileEditor)textEditor, array), progress, Job.DEFAULT_PRIORITY);
|
||||
|
||||
while (!progress.isCanceled()) {
|
||||
progress.waitFor(100);
|
||||
try {
|
||||
UIUtil.dispatchAllInvocationEvents();
|
||||
}
|
||||
catch (RuntimeException e) {
|
||||
e.printStackTrace();
|
||||
throw e;
|
||||
}
|
||||
catch (Error e) {
|
||||
e.printStackTrace();
|
||||
throw e;
|
||||
}
|
||||
catch (Throwable e) {
|
||||
e.printStackTrace();
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
UIUtil.dispatchAllInvocationEvents();
|
||||
UIUtil.dispatchAllInvocationEvents();
|
||||
|
||||
try {
|
||||
return getHighlights(document, null, project);
|
||||
}
|
||||
finally {
|
||||
@@ -530,12 +533,6 @@ public class DaemonCodeAnalyzerImpl extends DaemonCodeAnalyzer implements JDOMEx
|
||||
ApplicationManager.getApplication().assertIsDispatchThread();
|
||||
|
||||
stripWarningsCoveredByErrors(project, markup, toAdd);
|
||||
|
||||
//DaemonCodeAnalyzer codeAnalyzer = DaemonCodeAnalyzer.getInstance(project);
|
||||
//if (codeAnalyzer instanceof DaemonCodeAnalyzerImpl && ((DaemonCodeAnalyzerImpl)codeAnalyzer).myStatusBarUpdater != null) {
|
||||
// ((DaemonCodeAnalyzerImpl)codeAnalyzer).myStatusBarUpdater.updateStatus();
|
||||
//}
|
||||
|
||||
}
|
||||
|
||||
private static void stripWarningsCoveredByErrors(Project project, MarkupModel markup, final HighlightInfo toAdd) {
|
||||
@@ -554,11 +551,7 @@ public class DaemonCodeAnalyzerImpl extends DaemonCodeAnalyzer implements JDOMEx
|
||||
return addingError || !isError || !isCoveredBy(toAdd, interval);
|
||||
}
|
||||
});
|
||||
if (toAddIsVisible) {
|
||||
// ok
|
||||
//highlightsToSet.add(toAdd);
|
||||
}
|
||||
else {
|
||||
if (!toAddIsVisible) {
|
||||
// toAdd is covered by
|
||||
markup.removeHighlighter(toAdd.highlighter);
|
||||
}
|
||||
|
||||
@@ -31,6 +31,23 @@ public class DaemonProgressIndicator extends ProgressIndicatorBase {
|
||||
}
|
||||
|
||||
public synchronized void stopIfRunning() {
|
||||
if (isRunning()) stop();
|
||||
if (isRunning()) {
|
||||
stop();
|
||||
}
|
||||
else {
|
||||
cancel();
|
||||
}
|
||||
}
|
||||
|
||||
public boolean waitFor(int millisTimeout) {
|
||||
synchronized (this) {
|
||||
try {
|
||||
// we count on ProgressManagerImpl doing progress.notifyAll() on finish
|
||||
wait(millisTimeout);
|
||||
}
|
||||
catch (InterruptedException ignored) {
|
||||
}
|
||||
}
|
||||
return isCanceled();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -323,8 +323,9 @@ public class HighlightInfo implements Segment {
|
||||
}
|
||||
if (text != null) s += " text='" + text + "'";
|
||||
if (description != null) s+= ", description='" + description + "'";
|
||||
if (toolTip != null) s+= ", toolTip='" + toolTip + "'";
|
||||
//if (toolTip != null) s+= ", toolTip='" + toolTip + "'";
|
||||
s += " severity=" + severity;
|
||||
s += " group=" + group;
|
||||
return s;
|
||||
}
|
||||
|
||||
|
||||
@@ -188,12 +188,12 @@ public abstract class PassExecutorService implements Disposable {
|
||||
|
||||
log(updateProgress, null, "---------------------starting------------------------ " + threadsToStartCountdown.get());
|
||||
|
||||
for (ScheduledPass freePass : freePasses) {
|
||||
submit(freePass);
|
||||
}
|
||||
for (ScheduledPass dependentPass : dependentPasses) {
|
||||
mySubmittedPasses.put(dependentPass, JobImpl.NULL_JOB);
|
||||
}
|
||||
for (ScheduledPass freePass : freePasses) {
|
||||
submit(freePass);
|
||||
}
|
||||
}
|
||||
|
||||
private ScheduledPass createScheduledPass(@NotNull List<FileEditor> fileEditors,
|
||||
@@ -375,28 +375,31 @@ public abstract class PassExecutorService implements Disposable {
|
||||
}
|
||||
}
|
||||
|
||||
protected void applyInformationToEditors(final List<FileEditor> fileEditors, final TextEditorHighlightingPass pass, final DaemonProgressIndicator updateProgress,
|
||||
final AtomicInteger threadsToStartCountdown) {
|
||||
if (ApplicationManager.getApplication().isUnitTestMode()) {
|
||||
protected void applyInformationToEditors(@NotNull final List<FileEditor> fileEditors,
|
||||
@NotNull final TextEditorHighlightingPass pass,
|
||||
@NotNull final DaemonProgressIndicator updateProgress,
|
||||
@NotNull final AtomicInteger threadsToStartCountdown) {
|
||||
final boolean testMode = ApplicationManager.getApplication().isUnitTestMode();
|
||||
/*if (ApplicationManager.getApplication().isUnitTestMode()) {
|
||||
ApplicationManager.getApplication().runReadAction(new Runnable() {
|
||||
public void run() {
|
||||
doApplyInformationToEditors(updateProgress, pass, fileEditors, threadsToStartCountdown, true);
|
||||
}
|
||||
});
|
||||
}
|
||||
else {
|
||||
else*/ {
|
||||
ApplicationManager.getApplication().invokeLater(new DumbAwareRunnable() {
|
||||
public void run() {
|
||||
doApplyInformationToEditors(updateProgress, pass, fileEditors, threadsToStartCountdown, false);
|
||||
doApplyInformationToEditors(updateProgress, pass, fileEditors, threadsToStartCountdown, testMode);
|
||||
}
|
||||
}, ModalityState.stateForComponent(fileEditors.get(0).getComponent()));
|
||||
}
|
||||
}
|
||||
|
||||
private void doApplyInformationToEditors(DaemonProgressIndicator updateProgress,
|
||||
TextEditorHighlightingPass pass,
|
||||
List<FileEditor> fileEditors,
|
||||
AtomicInteger threadsToStartCountdown,
|
||||
private void doApplyInformationToEditors(@NotNull DaemonProgressIndicator updateProgress,
|
||||
@NotNull TextEditorHighlightingPass pass,
|
||||
@NotNull List<FileEditor> fileEditors,
|
||||
@NotNull AtomicInteger threadsToStartCountdown,
|
||||
boolean testMode) {
|
||||
if (isDisposed() || myProject.isDisposed()) {
|
||||
updateProgress.cancel();
|
||||
@@ -474,13 +477,14 @@ public abstract class PassExecutorService implements Disposable {
|
||||
for (Object o : info) {
|
||||
s.append(o.toString());
|
||||
}
|
||||
LOG.debug(StringUtil.repeatSymbol(' ', getThreadNum() * 4)
|
||||
+ " "+pass+" "
|
||||
+ s
|
||||
+ "; progress=" + (progressIndicator == null ? null : progressIndicator.hashCode())
|
||||
+ " " + (progressIndicator == null ? "?" : progressIndicator.isCanceled() ? "X" : "V")
|
||||
+ " : '"+(pass == null ? "" : StringUtil.first(pass.getDocument().getText(), 10, true)) + "'"
|
||||
);
|
||||
String message = StringUtil.repeatSymbol(' ', getThreadNum() * 4)
|
||||
+ " " + pass + " "
|
||||
+ s
|
||||
+ "; progress=" + (progressIndicator == null ? null : progressIndicator.hashCode())
|
||||
+ " " + (progressIndicator == null ? "?" : progressIndicator.isCanceled() ? "X" : "V")
|
||||
+ " : '" + (pass == null ? "" : StringUtil.first(pass.getDocument().getText(), 10, true)) + "'";
|
||||
LOG.debug(message);
|
||||
//System.out.println(message);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -515,10 +515,9 @@ public class FileReference implements FileReferenceOwner, PsiPolyVariantReferenc
|
||||
}
|
||||
|
||||
public String getUnresolvedMessagePattern() {
|
||||
final StringBuilder builder = new StringBuilder(LangBundle.message("error.cannot.resolve"));
|
||||
builder.append(" ").append(isLast() ? LangBundle.message("terms.file") : LangBundle.message("terms.directory"));
|
||||
builder.append(" ''{0}''");
|
||||
return builder.toString();
|
||||
return LangBundle.message("error.cannot.resolve")
|
||||
+ " " + (isLast() ? LangBundle.message("terms.file") : LangBundle.message("terms.directory"))
|
||||
+ " ''{0}''";
|
||||
}
|
||||
|
||||
public final boolean isLast() {
|
||||
|
||||
@@ -462,19 +462,23 @@ public abstract class BaseRefactoringProcessor {
|
||||
UsageViewDescriptor descriptor = createUsageViewDescriptor(usages);
|
||||
if (!ensureElementsWritable(usages, descriptor)) return;
|
||||
|
||||
RefactoringListenerManagerImpl listenerManager = (RefactoringListenerManagerImpl)RefactoringListenerManager.getInstance(myProject);
|
||||
myTransaction = listenerManager.startTransaction();
|
||||
Map<RefactoringHelper, Object> preparedData = new HashMap<RefactoringHelper, Object>();
|
||||
for(RefactoringHelper helper: Extensions.getExtensions(RefactoringHelper.EP_NAME)) {
|
||||
preparedData.put(helper, helper.prepareOperation(usages));
|
||||
}
|
||||
performRefactoring(usages);
|
||||
for(Map.Entry<RefactoringHelper, Object> e: preparedData.entrySet()) {
|
||||
//noinspection unchecked
|
||||
e.getKey().performOperation(myProject, e.getValue());
|
||||
}
|
||||
myTransaction.commit();
|
||||
performPsiSpoilingRefactoring();
|
||||
ApplicationManager.getApplication().runWriteAction(new Runnable() {
|
||||
public void run() {
|
||||
RefactoringListenerManagerImpl listenerManager = (RefactoringListenerManagerImpl)RefactoringListenerManager.getInstance(myProject);
|
||||
myTransaction = listenerManager.startTransaction();
|
||||
Map<RefactoringHelper, Object> preparedData = new HashMap<RefactoringHelper, Object>();
|
||||
for (RefactoringHelper helper : Extensions.getExtensions(RefactoringHelper.EP_NAME)) {
|
||||
preparedData.put(helper, helper.prepareOperation(usages));
|
||||
}
|
||||
performRefactoring(usages);
|
||||
for (Map.Entry<RefactoringHelper, Object> e : preparedData.entrySet()) {
|
||||
//noinspection unchecked
|
||||
e.getKey().performOperation(myProject, e.getValue());
|
||||
}
|
||||
myTransaction.commit();
|
||||
performPsiSpoilingRefactoring();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public static class ConflictsInTestsException extends RuntimeException {
|
||||
|
||||
@@ -22,6 +22,7 @@ import com.intellij.history.core.revisions.Revision;
|
||||
import com.intellij.openapi.command.CommandProcessor;
|
||||
import com.intellij.openapi.util.io.FileUtil;
|
||||
import com.intellij.openapi.vfs.*;
|
||||
import com.intellij.util.ui.UIUtil;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
@@ -36,6 +37,52 @@ public class ExternalChangesAndRefreshingTest extends IntegrationTestCase {
|
||||
doTestRefreshing(true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setUp() throws Exception {
|
||||
if (getName().equals("testRefreshingAsynchronously")) {
|
||||
// this methods waits for another thread to finish, that leds
|
||||
// to deadlock in swing-thread. Therefore we have to run this test
|
||||
// outside of swing-thread
|
||||
UIUtil.invokeAndWaitIfNeeded(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
try {
|
||||
ExternalChangesAndRefreshingTest.super.setUp();
|
||||
}
|
||||
catch (Exception e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
else {
|
||||
super.setUp();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void tearDown() throws Exception {
|
||||
if (getName().equals("testRefreshingAsynchronously")) {
|
||||
// this methods waits for another thread to finish, that leds
|
||||
// to deadlock in swing-thread. Therefore we have to run this test
|
||||
// outside of swing-thread
|
||||
UIUtil.invokeAndWaitIfNeeded(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
try {
|
||||
ExternalChangesAndRefreshingTest.super.tearDown();
|
||||
}
|
||||
catch (Exception e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
else {
|
||||
super.tearDown();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void runBareRunnable(Runnable r) throws Throwable {
|
||||
if (getName().equals("testRefreshingAsynchronously")) {
|
||||
@@ -193,4 +240,4 @@ public class ExternalChangesAndRefreshingTest extends IntegrationTestCase {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -60,7 +60,7 @@ public abstract class IntegrationTestCase extends PlatformTestCase {
|
||||
|
||||
myGateway = new IdeaGateway();
|
||||
|
||||
runWriteAction(new RunnableAdapter() {
|
||||
ApplicationManager.getApplication().runWriteAction(new RunnableAdapter() {
|
||||
@Override
|
||||
public void doRun() throws Exception {
|
||||
setUpInWriteAction();
|
||||
@@ -85,10 +85,6 @@ public abstract class IntegrationTestCase extends PlatformTestCase {
|
||||
super.tearDown();
|
||||
}
|
||||
|
||||
protected void runWriteAction(Runnable r) {
|
||||
ApplicationManager.getApplication().runWriteAction(r);
|
||||
}
|
||||
|
||||
protected VirtualFile createFile(String name) throws IOException {
|
||||
return createFile(name, null);
|
||||
}
|
||||
@@ -159,21 +155,29 @@ public abstract class IntegrationTestCase extends PlatformTestCase {
|
||||
addContentRoot(myModule, path);
|
||||
}
|
||||
|
||||
protected void addContentRoot(Module module, String path) {
|
||||
ModuleRootManager rm = ModuleRootManager.getInstance(module);
|
||||
ModifiableRootModel m = rm.getModifiableModel();
|
||||
m.addContentEntry(VfsUtil.pathToUrl(FileUtil.toSystemIndependentName(path)));
|
||||
m.commit();
|
||||
protected void addContentRoot(final Module module, final String path) {
|
||||
ApplicationManager.getApplication().runWriteAction(new Runnable() {
|
||||
public void run() {
|
||||
ModuleRootManager rm = ModuleRootManager.getInstance(module);
|
||||
ModifiableRootModel m = rm.getModifiableModel();
|
||||
m.addContentEntry(VfsUtil.pathToUrl(FileUtil.toSystemIndependentName(path)));
|
||||
m.commit();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
protected void addExcludedDir(String path) {
|
||||
ModuleRootManager rm = ModuleRootManager.getInstance(myModule);
|
||||
ModifiableRootModel m = rm.getModifiableModel();
|
||||
for (ContentEntry e : m.getContentEntries()) {
|
||||
if (e.getFile() != myRoot) continue;
|
||||
e.addExcludeFolder(VfsUtil.pathToUrl(FileUtil.toSystemIndependentName(path)));
|
||||
}
|
||||
m.commit();
|
||||
protected void addExcludedDir(final String path) {
|
||||
ApplicationManager.getApplication().runWriteAction(new Runnable() {
|
||||
public void run() {
|
||||
ModuleRootManager rm = ModuleRootManager.getInstance(myModule);
|
||||
ModifiableRootModel m = rm.getModifiableModel();
|
||||
for (ContentEntry e : m.getContentEntries()) {
|
||||
if (e.getFile() != myRoot) continue;
|
||||
e.addExcludeFolder(VfsUtil.pathToUrl(FileUtil.toSystemIndependentName(path)));
|
||||
}
|
||||
m.commit();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
protected void addFileListenerDuring(VirtualFileListener l, Runnable r) throws Exception {
|
||||
|
||||
@@ -15,11 +15,14 @@
|
||||
*/
|
||||
package com.intellij.openapi.vfs;
|
||||
|
||||
import com.intellij.openapi.application.ApplicationManager;
|
||||
import com.intellij.openapi.application.Result;
|
||||
import com.intellij.openapi.application.WriteAction;
|
||||
import com.intellij.openapi.diagnostic.Logger;
|
||||
import com.intellij.openapi.fileTypes.FileTypeManager;
|
||||
import com.intellij.openapi.fileTypes.FileTypes;
|
||||
import com.intellij.openapi.util.*;
|
||||
import com.intellij.openapi.util.Comparing;
|
||||
import com.intellij.openapi.util.SystemInfo;
|
||||
import com.intellij.openapi.util.ThrowableComputable;
|
||||
import com.intellij.openapi.util.io.FileUtil;
|
||||
import com.intellij.openapi.util.text.StringUtil;
|
||||
import com.intellij.openapi.vfs.encoding.EncodingManager;
|
||||
@@ -630,20 +633,13 @@ public class VfsUtil {
|
||||
}
|
||||
|
||||
public static VirtualFile createDirectories(@NotNull final String dir) throws IOException {
|
||||
final Ref<IOException> err = new Ref<IOException>();
|
||||
VirtualFile result = ApplicationManager.getApplication().runWriteAction(new Computable<VirtualFile>() {
|
||||
public VirtualFile compute() {
|
||||
try {
|
||||
return createDirectoryIfMissing(dir);
|
||||
}
|
||||
catch (IOException e) {
|
||||
err.set(e);
|
||||
return null;
|
||||
}
|
||||
return new WriteAction<VirtualFile>() {
|
||||
@Override
|
||||
protected void run(Result<VirtualFile> result) throws Throwable {
|
||||
VirtualFile res = createDirectoryIfMissing(dir);
|
||||
result.setResult(res);
|
||||
}
|
||||
});
|
||||
if (!err.isNull()) throw err.get();
|
||||
return result;
|
||||
}.execute().throwException().getResultObject();
|
||||
}
|
||||
|
||||
public static VirtualFile createDirectoryIfMissing(VirtualFile parent, String relativePath) throws IOException {
|
||||
|
||||
@@ -853,7 +853,7 @@ public class ApplicationImpl extends ComponentManagerImpl implements Application
|
||||
*/
|
||||
}
|
||||
|
||||
private void assertCanRunWriteAction() {
|
||||
private static void assertCanRunWriteAction() {
|
||||
assertIsDispatchThread("Write access is allowed from event dispatch thread only");
|
||||
|
||||
}
|
||||
@@ -862,8 +862,8 @@ public class ApplicationImpl extends ComponentManagerImpl implements Application
|
||||
assertIsDispatchThread("Access is allowed from event dispatch thread only.");
|
||||
}
|
||||
|
||||
private void assertIsDispatchThread(String message) {
|
||||
if (myHeadlessMode || ShutDownTracker.isShutdownHookRunning()) return;
|
||||
private static void assertIsDispatchThread(String message) {
|
||||
if (ShutDownTracker.isShutdownHookRunning()) return;
|
||||
final Thread currentThread = Thread.currentThread();
|
||||
if (ourDispatchThread == currentThread) return;
|
||||
|
||||
|
||||
@@ -163,4 +163,9 @@ class RangeHighlighterImpl extends RangeMarkerImpl implements RangeHighlighterEx
|
||||
public int getAffectedAreaEndOffset() {
|
||||
return data.getAffectedAreaEndOffset();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "RangeHighlighter: ("+getStartOffset()+","+getEndOffset()+"); layer="+getLayer();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -15,14 +15,12 @@
|
||||
*/
|
||||
package com.intellij.openapi.progress.impl;
|
||||
|
||||
import com.intellij.notification.Notifications;
|
||||
import com.intellij.openapi.Disposable;
|
||||
import com.intellij.openapi.application.Application;
|
||||
import com.intellij.openapi.application.ApplicationManager;
|
||||
import com.intellij.openapi.application.ModalityState;
|
||||
import com.intellij.openapi.application.ex.ApplicationEx;
|
||||
import com.intellij.openapi.application.ex.ApplicationManagerEx;
|
||||
import com.intellij.openapi.components.ServiceManager;
|
||||
import com.intellij.openapi.extensions.Extensions;
|
||||
import com.intellij.openapi.progress.*;
|
||||
import com.intellij.openapi.progress.util.ProgressWindow;
|
||||
@@ -41,8 +39,10 @@ import org.jetbrains.annotations.*;
|
||||
|
||||
import javax.swing.*;
|
||||
import java.awt.*;
|
||||
import java.util.*;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Comparator;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
|
||||
public class ProgressManagerImpl extends ProgressManager {
|
||||
@@ -196,7 +196,7 @@ public class ProgressManagerImpl extends ProgressManager {
|
||||
executeProcessUnderProgress(new Runnable(){
|
||||
public void run() {
|
||||
synchronized (process) {
|
||||
process.notify();
|
||||
process.notifyAll();
|
||||
}
|
||||
try {
|
||||
if (progress != null && !progress.isRunning()) {
|
||||
@@ -210,6 +210,9 @@ public class ProgressManagerImpl extends ProgressManager {
|
||||
if (progress instanceof ProgressIndicatorEx) {
|
||||
((ProgressIndicatorEx)progress).processFinish();
|
||||
}
|
||||
synchronized (process) {
|
||||
process.notifyAll();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -7,6 +7,7 @@ import com.intellij.openapi.progress.Progressive;
|
||||
import com.intellij.openapi.util.*;
|
||||
import com.intellij.util.Time;
|
||||
import com.intellij.util.WaitFor;
|
||||
import com.intellij.util.ui.UIUtil;
|
||||
import junit.framework.TestSuite;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
@@ -1200,7 +1201,7 @@ public class TreeUiTest extends AbstractTreeBuilderTest {
|
||||
}
|
||||
|
||||
private void buildSiblings(final Node node, final int start, final int end, final Runnable eachRunnable, final Runnable endRunnable) throws InvocationTargetException, InterruptedException {
|
||||
SwingUtilities.invokeAndWait(new Runnable() {
|
||||
UIUtil.invokeAndWaitIfNeeded(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
for (int i = start; i <= end; i++) {
|
||||
|
||||
@@ -25,6 +25,7 @@ import com.intellij.codeInsight.daemon.impl.HighlightInfo;
|
||||
import com.intellij.codeInsight.daemon.impl.HighlightInfoType;
|
||||
import com.intellij.codeInsight.daemon.impl.SeveritiesProvider;
|
||||
import com.intellij.lang.annotation.HighlightSeverity;
|
||||
import com.intellij.openapi.command.WriteCommandAction;
|
||||
import com.intellij.openapi.diagnostic.Logger;
|
||||
import com.intellij.openapi.editor.Document;
|
||||
import com.intellij.openapi.editor.RangeMarker;
|
||||
@@ -44,6 +45,7 @@ import gnu.trove.THashMap;
|
||||
import gnu.trove.THashSet;
|
||||
import junit.framework.Assert;
|
||||
import org.jetbrains.annotations.NonNls;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.awt.*;
|
||||
import java.lang.reflect.Field;
|
||||
@@ -85,42 +87,46 @@ public class ExpectedHighlightingData {
|
||||
protected final Map<String,ExpectedHighlightingSet> highlightingTypes;
|
||||
private final Map<RangeMarker, LineMarkerInfo> lineMarkerInfos = new THashMap<RangeMarker, LineMarkerInfo>();
|
||||
|
||||
public ExpectedHighlightingData(Document document,boolean checkWarnings, boolean checkInfos) {
|
||||
public ExpectedHighlightingData(@NotNull Document document,boolean checkWarnings, boolean checkInfos) {
|
||||
this(document, checkWarnings, false, checkInfos);
|
||||
}
|
||||
|
||||
public ExpectedHighlightingData(Document document,
|
||||
public ExpectedHighlightingData(@NotNull Document document,
|
||||
boolean checkWarnings,
|
||||
boolean checkWeakWarnings,
|
||||
boolean checkInfos) {
|
||||
this(document, checkWarnings, checkWeakWarnings, checkInfos, null);
|
||||
}
|
||||
|
||||
public ExpectedHighlightingData(Document document,
|
||||
boolean checkWarnings,
|
||||
boolean checkWeakWarnings,
|
||||
boolean checkInfos,
|
||||
public ExpectedHighlightingData(@NotNull final Document document,
|
||||
final boolean checkWarnings,
|
||||
final boolean checkWeakWarnings,
|
||||
final boolean checkInfos,
|
||||
PsiFile file) {
|
||||
myFile = file;
|
||||
myText = document.getText();
|
||||
highlightingTypes = new LinkedHashMap<String,ExpectedHighlightingSet>();
|
||||
highlightingTypes.put(ERROR_MARKER, new ExpectedHighlightingSet(HighlightInfoType.ERROR, HighlightSeverity.ERROR, false, true));
|
||||
highlightingTypes.put(WARNING_MARKER, new ExpectedHighlightingSet(HighlightInfoType.WARNING, HighlightSeverity.WARNING, false, checkWarnings));
|
||||
highlightingTypes.put(INFORMATION_MARKER, new ExpectedHighlightingSet(HighlightInfoType.INFO, HighlightSeverity.INFO, false, checkWeakWarnings));
|
||||
highlightingTypes.put("inject", new ExpectedHighlightingSet(HighlightInfoType.INJECTED_LANGUAGE_FRAGMENT, HighlightInfoType.INJECTED_FRAGMENT_SEVERITY, false, checkInfos));
|
||||
highlightingTypes.put(INFO_MARKER, new ExpectedHighlightingSet(HighlightInfoType.TODO, HighlightSeverity.INFORMATION, false, checkInfos));
|
||||
for (SeveritiesProvider provider : Extensions.getExtensions(SeveritiesProvider.EP_NAME)) {
|
||||
for (HighlightInfoType type : provider.getSeveritiesHighlightInfoTypes()) {
|
||||
final HighlightSeverity severity = type.getSeverity(null);
|
||||
highlightingTypes.put(severity.toString(), new ExpectedHighlightingSet(type, severity , false, true));
|
||||
new WriteCommandAction.Simple(file == null ? null : file.getProject()) {
|
||||
public void run() {
|
||||
highlightingTypes.put(ERROR_MARKER, new ExpectedHighlightingSet(HighlightInfoType.ERROR, HighlightSeverity.ERROR, false, true));
|
||||
highlightingTypes.put(WARNING_MARKER, new ExpectedHighlightingSet(HighlightInfoType.WARNING, HighlightSeverity.WARNING, false, checkWarnings));
|
||||
highlightingTypes.put(INFORMATION_MARKER, new ExpectedHighlightingSet(HighlightInfoType.INFO, HighlightSeverity.INFO, false, checkWeakWarnings));
|
||||
highlightingTypes.put("inject", new ExpectedHighlightingSet(HighlightInfoType.INJECTED_LANGUAGE_FRAGMENT, HighlightInfoType.INJECTED_FRAGMENT_SEVERITY, false, checkInfos));
|
||||
highlightingTypes.put(INFO_MARKER, new ExpectedHighlightingSet(HighlightInfoType.TODO, HighlightSeverity.INFORMATION, false, checkInfos));
|
||||
for (SeveritiesProvider provider : Extensions.getExtensions(SeveritiesProvider.EP_NAME)) {
|
||||
for (HighlightInfoType type : provider.getSeveritiesHighlightInfoTypes()) {
|
||||
final HighlightSeverity severity = type.getSeverity(null);
|
||||
highlightingTypes.put(severity.toString(), new ExpectedHighlightingSet(type, severity, false, true));
|
||||
}
|
||||
}
|
||||
highlightingTypes.put(END_LINE_HIGHLIGHT_MARKER,new ExpectedHighlightingSet(HighlightInfoType.ERROR, HighlightSeverity.ERROR, true, true));
|
||||
highlightingTypes.put(END_LINE_WARNING_MARKER, new ExpectedHighlightingSet(HighlightInfoType.WARNING, HighlightSeverity.WARNING, true, checkWarnings));
|
||||
initAdditionalHighlightingTypes();
|
||||
extractExpectedLineMarkerSet(document);
|
||||
extractExpectedHighlightsSet(document);
|
||||
refreshLineMarkers();
|
||||
}
|
||||
}
|
||||
highlightingTypes.put(END_LINE_HIGHLIGHT_MARKER, new ExpectedHighlightingSet(HighlightInfoType.ERROR, HighlightSeverity.ERROR, true, true));
|
||||
highlightingTypes.put(END_LINE_WARNING_MARKER, new ExpectedHighlightingSet(HighlightInfoType.WARNING, HighlightSeverity.WARNING, true, checkWarnings));
|
||||
initAdditionalHighlightingTypes();
|
||||
extractExpectedLineMarkerSet(document);
|
||||
extractExpectedHighlightsSet(document);
|
||||
refreshLineMarkers();
|
||||
}.execute().throwException();
|
||||
}
|
||||
|
||||
private void refreshLineMarkers() {
|
||||
@@ -146,11 +152,11 @@ public class ExpectedHighlightingData {
|
||||
final Pattern p = Pattern.compile(pat, Pattern.DOTALL);
|
||||
final Pattern pat2 = Pattern.compile("(.*?)(</" + LINE_MARKER + ">)(.*)", Pattern.DOTALL);
|
||||
|
||||
for (; ;) {
|
||||
while (true) {
|
||||
Matcher m = p.matcher(text);
|
||||
if (!m.matches()) break;
|
||||
int startOffset = m.start(1);
|
||||
final String descr = m.group(3) != null ? m.group(3): ANY_TEXT;
|
||||
final String descr = m.group(3) != null ? m.group(3) : ANY_TEXT;
|
||||
String rest = m.group(4);
|
||||
|
||||
document.replaceString(startOffset, m.end(1), "");
|
||||
@@ -164,8 +170,8 @@ public class ExpectedHighlightingData {
|
||||
document.replaceString(startOffset, endOffset, content);
|
||||
endOffset -= endTag.length();
|
||||
|
||||
LineMarkerInfo markerInfo = new LineMarkerInfo<PsiElement>(myFile, new TextRange(startOffset,endOffset), null, Pass.LINE_MARKERS,
|
||||
new ConstantFunction<PsiElement,String>(descr), null,
|
||||
LineMarkerInfo markerInfo = new LineMarkerInfo<PsiElement>(myFile, new TextRange(startOffset, endOffset), null, Pass.LINE_MARKERS,
|
||||
new ConstantFunction<PsiElement, String>(descr), null,
|
||||
GutterIconRenderer.Alignment.RIGHT);
|
||||
|
||||
lineMarkerInfos.put(document.createRangeMarker(startOffset, endOffset), markerInfo);
|
||||
|
||||
@@ -120,34 +120,43 @@ public abstract class LightPlatformCodeInsightTestCase extends LightPlatformTest
|
||||
* @param fileText - data file text.
|
||||
* @throws java.io.IOException
|
||||
*/
|
||||
protected static void configureFromFileText(@NonNls final String fileName, @NonNls String fileText) throws IOException {
|
||||
final Document fakeDocument = new DocumentImpl(fileText);
|
||||
protected static void configureFromFileText(@NonNls final String fileName, @NonNls final String fileText) throws IOException {
|
||||
ApplicationManager.getApplication().runWriteAction(new Runnable() {
|
||||
public void run() {
|
||||
final Document fakeDocument = new DocumentImpl(fileText);
|
||||
|
||||
int caretIndex = fileText.indexOf(CARET_MARKER);
|
||||
int selStartIndex = fileText.indexOf(SELECTION_START_MARKER);
|
||||
int selEndIndex = fileText.indexOf(SELECTION_END_MARKER);
|
||||
int caretIndex = fileText.indexOf(CARET_MARKER);
|
||||
int selStartIndex = fileText.indexOf(SELECTION_START_MARKER);
|
||||
int selEndIndex = fileText.indexOf(SELECTION_END_MARKER);
|
||||
|
||||
final RangeMarker caretMarker = caretIndex >= 0 ? fakeDocument.createRangeMarker(caretIndex, caretIndex) : null;
|
||||
final RangeMarker selStartMarker = selStartIndex >= 0 ? fakeDocument.createRangeMarker(selStartIndex, selStartIndex) : null;
|
||||
final RangeMarker selEndMarker = selEndIndex >= 0 ? fakeDocument.createRangeMarker(selEndIndex, selEndIndex) : null;
|
||||
final RangeMarker caretMarker = caretIndex >= 0 ? fakeDocument.createRangeMarker(caretIndex, caretIndex) : null;
|
||||
final RangeMarker selStartMarker = selStartIndex >= 0 ? fakeDocument.createRangeMarker(selStartIndex, selStartIndex) : null;
|
||||
final RangeMarker selEndMarker = selEndIndex >= 0 ? fakeDocument.createRangeMarker(selEndIndex, selEndIndex) : null;
|
||||
|
||||
if (caretMarker != null) {
|
||||
fakeDocument.deleteString(caretMarker.getStartOffset(), caretMarker.getStartOffset() + CARET_MARKER.length());
|
||||
}
|
||||
if (selStartMarker != null) {
|
||||
fakeDocument.deleteString(selStartMarker.getStartOffset(),
|
||||
selStartMarker.getStartOffset() + SELECTION_START_MARKER.length());
|
||||
}
|
||||
if (selEndMarker != null) {
|
||||
fakeDocument.deleteString(selEndMarker.getStartOffset(),
|
||||
selEndMarker.getStartOffset() + SELECTION_END_MARKER.length());
|
||||
}
|
||||
if (caretMarker != null) {
|
||||
fakeDocument.deleteString(caretMarker.getStartOffset(), caretMarker.getStartOffset() + CARET_MARKER.length());
|
||||
}
|
||||
if (selStartMarker != null) {
|
||||
fakeDocument.deleteString(selStartMarker.getStartOffset(),
|
||||
selStartMarker.getStartOffset() + SELECTION_START_MARKER.length());
|
||||
}
|
||||
if (selEndMarker != null) {
|
||||
fakeDocument.deleteString(selEndMarker.getStartOffset(),
|
||||
selEndMarker.getStartOffset() + SELECTION_END_MARKER.length());
|
||||
}
|
||||
|
||||
String newFileText = fakeDocument.getText();
|
||||
setupFileEditorAndDocument(fileName, newFileText);
|
||||
setupCaret(caretMarker, newFileText);
|
||||
setupSelection(selStartMarker, selEndMarker);
|
||||
setupEditorForInjectedLanguage();
|
||||
String newFileText = fakeDocument.getText();
|
||||
try {
|
||||
setupFileEditorAndDocument(fileName, newFileText);
|
||||
}
|
||||
catch (IOException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
setupCaret(caretMarker, newFileText);
|
||||
setupSelection(selStartMarker, selEndMarker);
|
||||
setupEditorForInjectedLanguage();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private static void setupSelection(final RangeMarker selStartMarker, final RangeMarker selEndMarker) {
|
||||
@@ -290,48 +299,52 @@ public abstract class LightPlatformCodeInsightTestCase extends LightPlatformTest
|
||||
* @param fileText
|
||||
* @param ignoreTrailingSpaces - whether trailing spaces in editor in data file should be stripped prior to comparing.
|
||||
*/
|
||||
protected void checkResultByText(String message, String fileText, final boolean ignoreTrailingSpaces) {
|
||||
protected void checkResultByText(final String message, final String fileText, final boolean ignoreTrailingSpaces) {
|
||||
bringRealEditorBack();
|
||||
PsiDocumentManager.getInstance(getProject()).commitAllDocuments();
|
||||
final Document document = EditorFactory.getInstance().createDocument(fileText);
|
||||
ApplicationManager.getApplication().runWriteAction(new Runnable() {
|
||||
public void run() {
|
||||
final Document document = EditorFactory.getInstance().createDocument(fileText);
|
||||
|
||||
int caretIndex = fileText.indexOf(CARET_MARKER);
|
||||
int selStartIndex = fileText.indexOf(SELECTION_START_MARKER);
|
||||
int selEndIndex = fileText.indexOf(SELECTION_END_MARKER);
|
||||
int caretIndex = fileText.indexOf(CARET_MARKER);
|
||||
int selStartIndex = fileText.indexOf(SELECTION_START_MARKER);
|
||||
int selEndIndex = fileText.indexOf(SELECTION_END_MARKER);
|
||||
|
||||
final RangeMarker caretMarker = caretIndex >= 0 ? document.createRangeMarker(caretIndex, caretIndex) : null;
|
||||
final RangeMarker selStartMarker = selStartIndex >= 0
|
||||
? document.createRangeMarker(selStartIndex, selStartIndex)
|
||||
: null;
|
||||
final RangeMarker selEndMarker = selEndIndex >= 0
|
||||
? document.createRangeMarker(selEndIndex, selEndIndex)
|
||||
: null;
|
||||
final RangeMarker caretMarker = caretIndex >= 0 ? document.createRangeMarker(caretIndex, caretIndex) : null;
|
||||
final RangeMarker selStartMarker = selStartIndex >= 0
|
||||
? document.createRangeMarker(selStartIndex, selStartIndex)
|
||||
: null;
|
||||
final RangeMarker selEndMarker = selEndIndex >= 0
|
||||
? document.createRangeMarker(selEndIndex, selEndIndex)
|
||||
: null;
|
||||
|
||||
if (ignoreTrailingSpaces) {
|
||||
((DocumentEx) document).stripTrailingSpaces(false);
|
||||
}
|
||||
if (ignoreTrailingSpaces) {
|
||||
((DocumentEx)document).stripTrailingSpaces(false);
|
||||
}
|
||||
|
||||
if (caretMarker != null) {
|
||||
document.deleteString(caretMarker.getStartOffset(), caretMarker.getStartOffset() + CARET_MARKER.length());
|
||||
}
|
||||
if (selStartMarker != null) {
|
||||
document.deleteString(selStartMarker.getStartOffset(),
|
||||
selStartMarker.getStartOffset() + SELECTION_START_MARKER.length());
|
||||
}
|
||||
if (selEndMarker != null) {
|
||||
document.deleteString(selEndMarker.getStartOffset(),
|
||||
selEndMarker.getStartOffset() + SELECTION_END_MARKER.length());
|
||||
}
|
||||
if (caretMarker != null) {
|
||||
document.deleteString(caretMarker.getStartOffset(), caretMarker.getStartOffset() + CARET_MARKER.length());
|
||||
}
|
||||
if (selStartMarker != null) {
|
||||
document.deleteString(selStartMarker.getStartOffset(),
|
||||
selStartMarker.getStartOffset() + SELECTION_START_MARKER.length());
|
||||
}
|
||||
if (selEndMarker != null) {
|
||||
document.deleteString(selEndMarker.getStartOffset(),
|
||||
selEndMarker.getStartOffset() + SELECTION_END_MARKER.length());
|
||||
}
|
||||
|
||||
|
||||
PostprocessReformattingAspect.getInstance(getProject()).doPostponedFormatting();
|
||||
String newFileText = document.getText();
|
||||
PostprocessReformattingAspect.getInstance(getProject()).doPostponedFormatting();
|
||||
String newFileText = document.getText();
|
||||
|
||||
PsiDocumentManager.getInstance(getProject()).commitAllDocuments();
|
||||
assertEquals(getMessage("Text mismatch", message), newFileText, myFile.getText());
|
||||
PsiDocumentManager.getInstance(getProject()).commitAllDocuments();
|
||||
assertEquals(getMessage("Text mismatch", message), newFileText, myFile.getText());
|
||||
|
||||
checkCaretPosition(caretMarker, newFileText, message);
|
||||
checkSelection(selStartMarker, selEndMarker, newFileText, message);
|
||||
checkCaretPosition(caretMarker, newFileText, message);
|
||||
checkSelection(selStartMarker, selEndMarker, newFileText, message);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private static String getMessage(@NonNls String engineMessage, String userMessage) {
|
||||
|
||||
@@ -36,6 +36,7 @@ import com.intellij.lang.injection.InjectedLanguageManager;
|
||||
import com.intellij.openapi.actionSystem.DataProvider;
|
||||
import com.intellij.openapi.actionSystem.PlatformDataKeys;
|
||||
import com.intellij.openapi.application.ApplicationManager;
|
||||
import com.intellij.openapi.command.WriteCommandAction;
|
||||
import com.intellij.openapi.command.impl.UndoManagerImpl;
|
||||
import com.intellij.openapi.command.undo.UndoManager;
|
||||
import com.intellij.openapi.editor.Document;
|
||||
@@ -175,10 +176,10 @@ public abstract class LightPlatformTestCase extends UsefulTestCase implements Da
|
||||
private static void initProject(final LightProjectDescriptor descriptor) throws Exception {
|
||||
ourProjectDescriptor = descriptor;
|
||||
final File projectFile = File.createTempFile("lighttemp", ProjectFileType.DOT_DEFAULT_EXTENSION);
|
||||
ApplicationManager.getApplication().runWriteAction(new Runnable() {
|
||||
|
||||
new WriteCommandAction.Simple(null) {
|
||||
@Override
|
||||
@SuppressWarnings({"AssignmentToStaticFieldFromInstanceMethod"})
|
||||
public void run() {
|
||||
protected void run() throws Throwable {
|
||||
if (ourProject != null) {
|
||||
closeAndDeleteProject();
|
||||
}
|
||||
@@ -258,7 +259,8 @@ public abstract class LightPlatformTestCase extends UsefulTestCase implements Da
|
||||
}
|
||||
|
||||
@Override
|
||||
public void rootsChanged(ModuleRootEvent event) {}
|
||||
public void rootsChanged(ModuleRootEvent event) {
|
||||
}
|
||||
});
|
||||
|
||||
connection.subscribe(ProjectTopics.MODULES, new ModuleListener() {
|
||||
@@ -268,17 +270,22 @@ public abstract class LightPlatformTestCase extends UsefulTestCase implements Da
|
||||
}
|
||||
|
||||
@Override
|
||||
public void beforeModuleRemoved(Project project, Module module) {}
|
||||
public void beforeModuleRemoved(Project project, Module module) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void moduleRemoved(Project project, Module module) {}
|
||||
public void moduleRemoved(Project project, Module module) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void modulesRenamed(Project project, List<Module> modules) {}
|
||||
public void modulesRenamed(Project project, List<Module> modules) {
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
((StartupManagerImpl)StartupManager.getInstance(getProject())).runStartupActivities();
|
||||
((StartupManagerImpl)StartupManager.getInstance(ourProject)).runStartupActivities();
|
||||
}
|
||||
});
|
||||
}.execute().throwException();
|
||||
}
|
||||
|
||||
protected static Module createMainModule(final ModuleType moduleType) {
|
||||
@@ -411,9 +418,7 @@ public abstract class LightPlatformTestCase extends UsefulTestCase implements Da
|
||||
}
|
||||
|
||||
public static void doTearDown(Project project, IdeaTestApplication application, boolean checkForEditors) throws Exception {
|
||||
if (project != null) {
|
||||
CodeStyleSettingsManager.getInstance(project).dropTemporarySettings();
|
||||
}
|
||||
CodeStyleSettingsManager.getInstance(project).dropTemporarySettings();
|
||||
checkAllTimersAreDisposed();
|
||||
UsefulTestCase.doPostponedFormatting(project);
|
||||
|
||||
@@ -425,9 +430,9 @@ public abstract class LightPlatformTestCase extends UsefulTestCase implements Da
|
||||
InspectionProfileManager.getInstance().deleteProfile(PROFILE);
|
||||
assertNotNull("Application components damaged", ProjectManager.getInstance());
|
||||
|
||||
ApplicationManager.getApplication().runWriteAction(new Runnable() {
|
||||
new WriteCommandAction.Simple(getProject()) {
|
||||
@Override
|
||||
public void run() {
|
||||
protected void run() throws Throwable {
|
||||
if (ourSourceRoot != null) {
|
||||
try {
|
||||
final VirtualFile[] children = ourSourceRoot.getChildren();
|
||||
@@ -451,7 +456,8 @@ public abstract class LightPlatformTestCase extends UsefulTestCase implements Da
|
||||
ApplicationManager.getApplication().runWriteAction(EmptyRunnable.getInstance()); // Flash posponed formatting if any.
|
||||
manager.saveAllDocuments();
|
||||
}
|
||||
});
|
||||
}.execute().throwException();
|
||||
|
||||
assertFalse(PsiManager.getInstance(project).isDisposed());
|
||||
if (!ourAssertionsInTestDetected) {
|
||||
if (IdeaLogger.ourErrorsOccurred != null) {
|
||||
|
||||
@@ -26,7 +26,10 @@ import com.intellij.openapi.actionSystem.DataProvider;
|
||||
import com.intellij.openapi.actionSystem.PlatformDataKeys;
|
||||
import com.intellij.openapi.application.ApplicationManager;
|
||||
import com.intellij.openapi.application.ModalityState;
|
||||
import com.intellij.openapi.application.Result;
|
||||
import com.intellij.openapi.application.WriteAction;
|
||||
import com.intellij.openapi.command.CommandProcessor;
|
||||
import com.intellij.openapi.command.WriteCommandAction;
|
||||
import com.intellij.openapi.command.impl.UndoManagerImpl;
|
||||
import com.intellij.openapi.command.undo.UndoManager;
|
||||
import com.intellij.openapi.diagnostic.Logger;
|
||||
@@ -229,17 +232,12 @@ public abstract class PlatformTestCase extends UsefulTestCase implements DataPro
|
||||
}
|
||||
|
||||
protected void setUpModule() {
|
||||
ApplicationManager.getApplication().runWriteAction(new Runnable() {
|
||||
new WriteCommandAction.Simple(getProject()) {
|
||||
@Override
|
||||
public void run() {
|
||||
try {
|
||||
myModule = createMainModule();
|
||||
}
|
||||
catch (IOException e) {
|
||||
LOG.error(e);
|
||||
}
|
||||
protected void run() throws Throwable {
|
||||
myModule = createMainModule();
|
||||
}
|
||||
});
|
||||
}.execute().throwException();
|
||||
}
|
||||
|
||||
protected Module createMainModule() throws IOException {
|
||||
@@ -257,10 +255,15 @@ public abstract class PlatformTestCase extends UsefulTestCase implements DataPro
|
||||
moduleName + ModuleFileType.DOT_DEFAULT_EXTENSION);
|
||||
FileUtil.createIfDoesntExist(moduleFile);
|
||||
myFilesToDelete.add(moduleFile);
|
||||
final VirtualFile virtualFile = LocalFileSystem.getInstance().refreshAndFindFileByIoFile(moduleFile);
|
||||
Module module = ModuleManager.getInstance(myProject).newModule(virtualFile.getPath(), getModuleType());
|
||||
module.getModuleFile();
|
||||
return module;
|
||||
return new WriteAction<Module>() {
|
||||
@Override
|
||||
protected void run(Result<Module> result) throws Throwable {
|
||||
final VirtualFile virtualFile = LocalFileSystem.getInstance().refreshAndFindFileByIoFile(moduleFile);
|
||||
Module module = ModuleManager.getInstance(myProject).newModule(virtualFile.getPath(), getModuleType());
|
||||
module.getModuleFile();
|
||||
result.setResult(module);
|
||||
}
|
||||
}.execute().getResultObject();
|
||||
}
|
||||
|
||||
protected ModuleType getModuleType() {
|
||||
|
||||
@@ -15,6 +15,7 @@
|
||||
*/
|
||||
package com.intellij.testFramework;
|
||||
|
||||
import com.intellij.openapi.application.ApplicationManager;
|
||||
import com.intellij.openapi.application.Result;
|
||||
import com.intellij.openapi.command.WriteCommandAction;
|
||||
import com.intellij.openapi.module.Module;
|
||||
@@ -41,6 +42,7 @@ import junit.framework.Assert;
|
||||
import org.jetbrains.annotations.NonNls;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.Collection;
|
||||
|
||||
@NonNls public class PsiTestUtil {
|
||||
@@ -82,40 +84,64 @@ import java.util.Collection;
|
||||
File dir = FileUtil.createTempDirectory(tempName, null);
|
||||
filesToDelete.add(dir);
|
||||
|
||||
VirtualFile vDir = LocalFileSystem.getInstance().refreshAndFindFileByPath(dir.getCanonicalPath().replace(File.separatorChar, '/'));
|
||||
final VirtualFile vDir = LocalFileSystem.getInstance().refreshAndFindFileByPath(dir.getCanonicalPath().replace(File.separatorChar, '/'));
|
||||
|
||||
if (rootPath != null) {
|
||||
VirtualFile vDir1 = LocalFileSystem.getInstance().findFileByPath(rootPath.replace(File.separatorChar, '/'));
|
||||
if (vDir1 == null) {
|
||||
throw new Exception(rootPath + " not found");
|
||||
final Exception[] exception = {null};
|
||||
ApplicationManager.getApplication().runWriteAction(new Runnable() {
|
||||
public void run() {
|
||||
if (rootPath != null) {
|
||||
VirtualFile vDir1 = LocalFileSystem.getInstance().findFileByPath(rootPath.replace(File.separatorChar, '/'));
|
||||
if (vDir1 == null) {
|
||||
exception[0] = new Exception(rootPath + " not found");
|
||||
return;
|
||||
}
|
||||
try {
|
||||
VfsUtil.copyDirectory(null, vDir1, vDir, null);
|
||||
}
|
||||
catch (IOException e) {
|
||||
exception[0] = e;
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if (addProjectRoots) {
|
||||
addSourceContentToRoots(module, vDir);
|
||||
}
|
||||
}
|
||||
VfsUtil.copyDirectory(null, vDir1, vDir, null);
|
||||
}
|
||||
});
|
||||
if (exception[0] != null) throw exception[0];
|
||||
|
||||
if (addProjectRoots) {
|
||||
addSourceContentToRoots(module, vDir);
|
||||
}
|
||||
return vDir;
|
||||
}
|
||||
|
||||
public static void removeAllRoots(Module module, final Sdk jdk) {
|
||||
final ModuleRootManager rootManager = ModuleRootManager.getInstance(module);
|
||||
final ModifiableRootModel rootModel = rootManager.getModifiableModel();
|
||||
rootModel.clear();
|
||||
rootModel.setSdk(jdk);
|
||||
rootModel.commit();
|
||||
public static void removeAllRoots(final Module module, final Sdk jdk) {
|
||||
new WriteCommandAction.Simple(module.getProject()) {
|
||||
@Override
|
||||
protected void run() throws Throwable {
|
||||
final ModuleRootManager rootManager = ModuleRootManager.getInstance(module);
|
||||
final ModifiableRootModel rootModel = rootManager.getModifiableModel();
|
||||
rootModel.clear();
|
||||
rootModel.setSdk(jdk);
|
||||
rootModel.commit();
|
||||
}
|
||||
}.execute().throwException();
|
||||
}
|
||||
|
||||
public static void addSourceContentToRoots(Module module, VirtualFile vDir) {
|
||||
addSourceContentToRoots(module, vDir, false);
|
||||
}
|
||||
|
||||
public static void addSourceContentToRoots(Module module, VirtualFile vDir, final boolean testSource) {
|
||||
final ModuleRootManager rootManager = ModuleRootManager.getInstance(module);
|
||||
final ModifiableRootModel rootModel = rootManager.getModifiableModel();
|
||||
final ContentEntry contentEntry = rootModel.addContentEntry(vDir);
|
||||
contentEntry.addSourceFolder(vDir, testSource);
|
||||
rootModel.commit();
|
||||
public static void addSourceContentToRoots(final Module module, final VirtualFile vDir, final boolean testSource) {
|
||||
new WriteCommandAction.Simple(module.getProject()) {
|
||||
@Override
|
||||
protected void run() throws Throwable {
|
||||
final ModuleRootManager rootManager = ModuleRootManager.getInstance(module);
|
||||
final ModifiableRootModel rootModel = rootManager.getModifiableModel();
|
||||
final ContentEntry contentEntry = rootModel.addContentEntry(vDir);
|
||||
contentEntry.addSourceFolder(vDir, testSource);
|
||||
rootModel.commit();
|
||||
}
|
||||
}.execute().throwException();
|
||||
}
|
||||
|
||||
public static void addSourceRoot(Module module, final VirtualFile vDir) {
|
||||
@@ -123,25 +149,35 @@ import java.util.Collection;
|
||||
}
|
||||
|
||||
public static void addSourceRoot(final Module module, final VirtualFile vDir, final boolean isTestSource) {
|
||||
final ModuleRootManager rootManager = ModuleRootManager.getInstance(module);
|
||||
final ModifiableRootModel rootModel = rootManager.getModifiableModel();
|
||||
final ContentEntry[] contentEntries = rootModel.getContentEntries();
|
||||
ContentEntry entry = ContainerUtil.find(contentEntries, new Condition<ContentEntry>() {
|
||||
new WriteCommandAction.Simple(module.getProject()) {
|
||||
@Override
|
||||
public boolean value(final ContentEntry object) {
|
||||
return VfsUtil.isAncestor(object.getFile(), vDir, false);
|
||||
protected void run() throws Throwable {
|
||||
final ModuleRootManager rootManager = ModuleRootManager.getInstance(module);
|
||||
final ModifiableRootModel rootModel = rootManager.getModifiableModel();
|
||||
final ContentEntry[] contentEntries = rootModel.getContentEntries();
|
||||
ContentEntry entry = ContainerUtil.find(contentEntries, new Condition<ContentEntry>() {
|
||||
@Override
|
||||
public boolean value(final ContentEntry object) {
|
||||
return VfsUtil.isAncestor(object.getFile(), vDir, false);
|
||||
}
|
||||
});
|
||||
if (entry == null) entry = rootModel.addContentEntry(vDir);
|
||||
entry.addSourceFolder(vDir, isTestSource);
|
||||
rootModel.commit();
|
||||
}
|
||||
});
|
||||
if (entry == null) entry = rootModel.addContentEntry(vDir);
|
||||
entry.addSourceFolder(vDir, isTestSource);
|
||||
rootModel.commit();
|
||||
}.execute().throwException();
|
||||
}
|
||||
|
||||
public static ContentEntry addContentRoot(Module module, VirtualFile vDir) {
|
||||
public static ContentEntry addContentRoot(final Module module, final VirtualFile vDir) {
|
||||
final ModuleRootManager rootManager = ModuleRootManager.getInstance(module);
|
||||
final ModifiableRootModel rootModel = rootManager.getModifiableModel();
|
||||
rootModel.addContentEntry(vDir);
|
||||
rootModel.commit();
|
||||
new WriteCommandAction.Simple(module.getProject()) {
|
||||
@Override
|
||||
protected void run() throws Throwable {
|
||||
final ModifiableRootModel rootModel = rootManager.getModifiableModel();
|
||||
rootModel.addContentEntry(vDir);
|
||||
rootModel.commit();
|
||||
}
|
||||
}.execute().throwException();
|
||||
for (ContentEntry entry : rootManager.getContentEntries()) {
|
||||
if (entry.getFile() == vDir) {
|
||||
Assert.assertFalse(((ContentEntryImpl)entry).isDisposed());
|
||||
@@ -151,11 +187,16 @@ import java.util.Collection;
|
||||
return null;
|
||||
}
|
||||
|
||||
public static void removeContentEntry(Module m, ContentEntry e) {
|
||||
ModuleRootManager rootModel = ModuleRootManager.getInstance(m);
|
||||
ModifiableRootModel model = rootModel.getModifiableModel();
|
||||
model.removeContentEntry(e);
|
||||
model.commit();
|
||||
public static void removeContentEntry(final Module module, final ContentEntry e) {
|
||||
new WriteCommandAction.Simple(module.getProject()) {
|
||||
@Override
|
||||
protected void run() throws Throwable {
|
||||
ModuleRootManager rootModel = ModuleRootManager.getInstance(module);
|
||||
ModifiableRootModel model = rootModel.getModifiableModel();
|
||||
model.removeContentEntry(e);
|
||||
model.commit();
|
||||
}
|
||||
}.execute().throwException();
|
||||
}
|
||||
|
||||
public static void checkFileStructure(PsiFile file) throws IncorrectOperationException {
|
||||
@@ -174,30 +215,35 @@ import java.util.Collection;
|
||||
addLibrary(module, model, libName, libPath, jarArr);
|
||||
model.commit();
|
||||
}
|
||||
}.execute();
|
||||
}.execute().throwException();
|
||||
}
|
||||
|
||||
public static void addLibrary(Module module, ModifiableRootModel model, String libName, String libPath, String... jarArr) {
|
||||
final LibraryTable libraryTable = ProjectLibraryTable.getInstance(module.getProject());
|
||||
final Library library = libraryTable.createLibrary(libName);
|
||||
final Library.ModifiableModel libraryModel = library.getModifiableModel();
|
||||
for (String jar : jarArr) {
|
||||
if (!libPath.endsWith("/") && !jar.startsWith("/")) {
|
||||
jar = "/" + jar;
|
||||
public static void addLibrary(final Module module, final ModifiableRootModel model, final String libName, final String libPath, final String... jarArr) {
|
||||
new WriteCommandAction.Simple(module.getProject()) {
|
||||
@Override
|
||||
protected void run() throws Throwable {
|
||||
final LibraryTable libraryTable = ProjectLibraryTable.getInstance(module.getProject());
|
||||
final Library library = libraryTable.createLibrary(libName);
|
||||
final Library.ModifiableModel libraryModel = library.getModifiableModel();
|
||||
for (String jar : jarArr) {
|
||||
if (!libPath.endsWith("/") && !jar.startsWith("/")) {
|
||||
jar = "/" + jar;
|
||||
}
|
||||
final String path = libPath + jar;
|
||||
final VirtualFile root = JarFileSystem.getInstance().refreshAndFindFileByPath(path + "!/");
|
||||
assert root != null : "Library root folder not found: " + path + "!/";
|
||||
libraryModel.addRoot(root, OrderRootType.CLASSES);
|
||||
}
|
||||
libraryModel.commit();
|
||||
model.addLibraryEntry(library);
|
||||
final OrderEntry[] orderEntries = model.getOrderEntries();
|
||||
OrderEntry last = orderEntries[orderEntries.length - 1];
|
||||
for (int i = orderEntries.length - 2; i > -1; i--) {
|
||||
orderEntries[i + 1] = orderEntries[i];
|
||||
}
|
||||
orderEntries[0] = last;
|
||||
model.rearrangeOrderEntries(orderEntries);
|
||||
}
|
||||
final String path = libPath + jar;
|
||||
final VirtualFile root = JarFileSystem.getInstance().refreshAndFindFileByPath(path + "!/");
|
||||
assert root != null : "Library root folder not found: " + path + "!/";
|
||||
libraryModel.addRoot(root, OrderRootType.CLASSES);
|
||||
}
|
||||
libraryModel.commit();
|
||||
model.addLibraryEntry(library);
|
||||
final OrderEntry[] orderEntries = model.getOrderEntries();
|
||||
OrderEntry last = orderEntries[orderEntries.length - 1];
|
||||
for (int i = orderEntries.length - 2; i > -1; i--) {
|
||||
orderEntries[i + 1] = orderEntries[i];
|
||||
}
|
||||
orderEntries[0] = last;
|
||||
model.rearrangeOrderEntries(orderEntries);
|
||||
}.execute().throwException();
|
||||
}
|
||||
}
|
||||
@@ -37,12 +37,14 @@ import com.intellij.testFramework.exceptionCases.AbstractExceptionCase;
|
||||
import com.intellij.util.Consumer;
|
||||
import com.intellij.util.Function;
|
||||
import com.intellij.util.containers.ContainerUtil;
|
||||
import com.intellij.util.ui.UIUtil;
|
||||
import gnu.trove.THashSet;
|
||||
import junit.framework.Assert;
|
||||
import junit.framework.AssertionFailedError;
|
||||
import junit.framework.TestCase;
|
||||
import org.jdom.Element;
|
||||
import org.jetbrains.annotations.NonNls;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.io.File;
|
||||
@@ -220,9 +222,31 @@ public abstract class UsefulTestCase extends TestCase {
|
||||
}
|
||||
|
||||
protected void invokeTestRunnable(Runnable runnable) throws Exception {
|
||||
runnable.run();
|
||||
UIUtil.invokeAndWaitIfNeeded(runnable);
|
||||
//runnable.run();
|
||||
}
|
||||
|
||||
protected void superRunBare() throws Throwable {
|
||||
super.runBare();
|
||||
}
|
||||
|
||||
public void runBare() throws Throwable {
|
||||
final Throwable[] exception = {null};
|
||||
UIUtil.invokeAndWaitIfNeeded(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
try {
|
||||
superRunBare();
|
||||
}
|
||||
catch (Throwable tearingDown) {
|
||||
if (exception[0] == null) exception[0] = tearingDown;
|
||||
}
|
||||
}
|
||||
});
|
||||
if (exception[0] != null) throw exception[0];
|
||||
}
|
||||
|
||||
|
||||
@NonNls
|
||||
public static String toString(Collection<?> collection) {
|
||||
if (collection.isEmpty()) {
|
||||
@@ -267,19 +291,19 @@ public abstract class UsefulTestCase extends TestCase {
|
||||
}
|
||||
}
|
||||
|
||||
public static <T> void assertOrderedCollection(T[] collection, Consumer<T>... checkers) {
|
||||
public static <T> void assertOrderedCollection(T[] collection, @NotNull Consumer<T>... checkers) {
|
||||
Assert.assertNotNull(collection);
|
||||
assertOrderedCollection(Arrays.asList(collection), checkers);
|
||||
}
|
||||
|
||||
public static <T> void assertSameElements(T[] collection, T... expected) {
|
||||
public static <T> void assertSameElements(@NotNull T[] collection, @NotNull T... expected) {
|
||||
assertSameElements(Arrays.asList(collection), expected);
|
||||
}
|
||||
|
||||
public static <T> void assertSameElements(Collection<? extends T> collection, T... expected) {
|
||||
public static <T> void assertSameElements(@NotNull Collection<? extends T> collection, @NotNull T... expected) {
|
||||
assertSameElements(collection, Arrays.asList(expected));
|
||||
}
|
||||
public static <T> void assertSameElements(Collection<? extends T> collection, Collection<T> expected) {
|
||||
public static <T> void assertSameElements(@NotNull Collection<? extends T> collection, @NotNull Collection<T> expected) {
|
||||
if (collection.size() != expected.size() || !new HashSet<T>(expected).equals(new HashSet<T>(collection))) {
|
||||
Assert.assertEquals(toString(expected, "\n"), toString(collection, "\n"));
|
||||
Assert.assertEquals(new HashSet<T>(expected), new HashSet<T>(collection));
|
||||
|
||||
@@ -24,7 +24,6 @@ import com.intellij.testFramework.UsefulTestCase;
|
||||
import com.intellij.testFramework.builders.EmptyModuleFixtureBuilder;
|
||||
import org.jetbrains.annotations.NonNls;
|
||||
|
||||
import javax.swing.*;
|
||||
import java.io.File;
|
||||
|
||||
/**
|
||||
@@ -91,9 +90,4 @@ public abstract class CodeInsightFixtureTestCase extends UsefulTestCase {
|
||||
protected PsiFile getFile() {
|
||||
return myFixture.getFile();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void invokeTestRunnable(Runnable runnable) throws Exception {
|
||||
SwingUtilities.invokeAndWait(runnable);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -297,16 +297,15 @@ public class CodeInsightTestFixtureImpl extends BaseFixture implements CodeInsig
|
||||
final boolean checkWeakWarnings,
|
||||
final String... filePaths) {
|
||||
final Ref<Long> duration = new Ref<Long>();
|
||||
new WriteCommandAction.Simple(myProjectFixture.getProject()) {
|
||||
|
||||
@Override
|
||||
protected void run() throws Exception {
|
||||
if (filePaths.length > 0) {
|
||||
configureByFilesInner(filePaths);
|
||||
}
|
||||
collectAndCheckHighlightings(checkWarnings, checkInfos, checkWeakWarnings, duration);
|
||||
}
|
||||
}.execute().throwException();
|
||||
if (filePaths.length > 0) {
|
||||
configureByFilesInner(filePaths);
|
||||
}
|
||||
try {
|
||||
collectAndCheckHighlightings(checkWarnings, checkInfos, checkWeakWarnings, duration);
|
||||
}
|
||||
catch (Exception e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
return duration.get().longValue();
|
||||
}
|
||||
|
||||
@@ -328,13 +327,7 @@ public class CodeInsightTestFixtureImpl extends BaseFixture implements CodeInsig
|
||||
final boolean checkWeakWarnings,
|
||||
@NonNls final VirtualFile... files) {
|
||||
final Ref<Long> duration = new Ref<Long>();
|
||||
new WriteCommandAction.Simple(myProjectFixture.getProject()) {
|
||||
|
||||
@Override
|
||||
protected void run() throws Exception {
|
||||
collectAndCheckHighlightings(checkWarnings, checkInfos, checkWeakWarnings, duration, files);
|
||||
}
|
||||
}.execute().throwException();
|
||||
collectAndCheckHighlightings(checkWarnings, checkInfos, checkWeakWarnings, duration, files);
|
||||
return duration.get().longValue();
|
||||
}
|
||||
|
||||
@@ -360,12 +353,12 @@ public class CodeInsightTestFixtureImpl extends BaseFixture implements CodeInsig
|
||||
@Override
|
||||
public long checkHighlighting(final boolean checkWarnings, final boolean checkInfos, final boolean checkWeakWarnings) {
|
||||
final Ref<Long> duration = new Ref<Long>();
|
||||
new WriteCommandAction.Simple(myProjectFixture.getProject()) {
|
||||
@Override
|
||||
protected void run() throws Exception {
|
||||
collectAndCheckHighlightings(checkWarnings, checkInfos, checkWeakWarnings, duration);
|
||||
}
|
||||
}.execute().throwException();
|
||||
try {
|
||||
collectAndCheckHighlightings(checkWarnings, checkInfos, checkWeakWarnings, duration);
|
||||
}
|
||||
catch (Exception e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
return duration.get().longValue();
|
||||
}
|
||||
|
||||
@@ -382,13 +375,13 @@ public class CodeInsightTestFixtureImpl extends BaseFixture implements CodeInsig
|
||||
@Override
|
||||
public long testHighlighting(final boolean checkWarnings, final boolean checkInfos, final boolean checkWeakWarnings, final VirtualFile file) {
|
||||
final Ref<Long> duration = new Ref<Long>();
|
||||
new WriteCommandAction.Simple(myProjectFixture.getProject()) {
|
||||
@Override
|
||||
protected void run() throws Exception {
|
||||
openFileInEditor(file);
|
||||
collectAndCheckHighlightings(checkWarnings, checkInfos, checkWeakWarnings, duration);
|
||||
}
|
||||
}.execute().throwException();
|
||||
openFileInEditor(file);
|
||||
try {
|
||||
collectAndCheckHighlightings(checkWarnings, checkInfos, checkWeakWarnings, duration);
|
||||
}
|
||||
catch (Exception e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
return duration.get().longValue();
|
||||
}
|
||||
|
||||
@@ -414,12 +407,7 @@ public class CodeInsightTestFixtureImpl extends BaseFixture implements CodeInsig
|
||||
@Override
|
||||
@Nullable
|
||||
public PsiReference getReferenceAtCaretPosition(final String... filePaths) {
|
||||
new WriteCommandAction<PsiReference>(myProjectFixture.getProject()) {
|
||||
@Override
|
||||
protected void run(final Result<PsiReference> result) throws Exception {
|
||||
configureByFilesInner(filePaths);
|
||||
}
|
||||
}.execute().throwException();
|
||||
configureByFilesInner(filePaths);
|
||||
return getFile().findReferenceAt(myEditor.getCaretModel().getOffset());
|
||||
}
|
||||
|
||||
@@ -434,35 +422,24 @@ public class CodeInsightTestFixtureImpl extends BaseFixture implements CodeInsig
|
||||
@Override
|
||||
@NotNull
|
||||
public List<IntentionAction> getAvailableIntentions(final String... filePaths) {
|
||||
|
||||
return new WriteCommandAction<List<IntentionAction>>(myProjectFixture.getProject()) {
|
||||
@Override
|
||||
protected void run(final Result<List<IntentionAction>> result) throws Exception {
|
||||
if (filePaths.length > 0) {
|
||||
configureByFilesInner(filePaths);
|
||||
}
|
||||
result.setResult(getAvailableIntentions());
|
||||
}
|
||||
}.execute().throwException().getResultObject();
|
||||
if (filePaths.length > 0) {
|
||||
configureByFilesInner(filePaths);
|
||||
}
|
||||
return getAvailableIntentions();
|
||||
}
|
||||
|
||||
@Override
|
||||
@NotNull
|
||||
public List<IntentionAction> getAllQuickFixes(@NonNls final String... filePaths) {
|
||||
return new WriteCommandAction<List<IntentionAction>>(myProjectFixture.getProject()) {
|
||||
@Override
|
||||
protected void run(final Result<List<IntentionAction>> result) throws Exception {
|
||||
configureByFilesInner(filePaths);
|
||||
List<HighlightInfo> infos = doHighlighting();
|
||||
ArrayList<IntentionAction> actions = new ArrayList<IntentionAction>();
|
||||
for (HighlightInfo info : infos) {
|
||||
for (Pair<HighlightInfo.IntentionActionDescriptor, TextRange> pair : info.quickFixActionRanges) {
|
||||
actions.add(pair.getFirst().getAction());
|
||||
}
|
||||
}
|
||||
result.setResult(actions);
|
||||
configureByFilesInner(filePaths);
|
||||
List<HighlightInfo> infos = doHighlighting();
|
||||
ArrayList<IntentionAction> actions = new ArrayList<IntentionAction>();
|
||||
for (HighlightInfo info : infos) {
|
||||
for (Pair<HighlightInfo.IntentionActionDescriptor, TextRange> pair : info.quickFixActionRanges) {
|
||||
actions.add(pair.getFirst().getAction());
|
||||
}
|
||||
}.execute().throwException().getResultObject();
|
||||
}
|
||||
return actions;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -738,28 +715,20 @@ public class CodeInsightTestFixtureImpl extends BaseFixture implements CodeInsig
|
||||
@Nullable
|
||||
public GutterIconRenderer findGutter(final String filePath) {
|
||||
assertInitialized();
|
||||
final Project project = myProjectFixture.getProject();
|
||||
final Ref<GutterIconRenderer> result = new Ref<GutterIconRenderer>();
|
||||
new WriteCommandAction.Simple(project) {
|
||||
configureByFilesInner(filePath);
|
||||
int offset = myEditor.getCaretModel().getOffset();
|
||||
|
||||
@Override
|
||||
protected void run() throws Exception {
|
||||
configureByFilesInner(filePath);
|
||||
int offset = myEditor.getCaretModel().getOffset();
|
||||
|
||||
final Collection<HighlightInfo> infos = doHighlighting();
|
||||
for (HighlightInfo info :infos) {
|
||||
if (info.endOffset >= offset && info.startOffset <= offset) {
|
||||
final GutterIconRenderer renderer = info.getGutterIconRenderer();
|
||||
if (renderer != null) {
|
||||
result.set(renderer);
|
||||
return;
|
||||
}
|
||||
}
|
||||
final Collection<HighlightInfo> infos = doHighlighting();
|
||||
for (HighlightInfo info :infos) {
|
||||
if (info.endOffset >= offset && info.startOffset <= offset) {
|
||||
final GutterIconRenderer renderer = info.getGutterIconRenderer();
|
||||
if (renderer != null) {
|
||||
result.set(renderer);
|
||||
break;
|
||||
}
|
||||
|
||||
}
|
||||
}.execute().throwException();
|
||||
}
|
||||
return result.get();
|
||||
}
|
||||
|
||||
@@ -769,34 +738,28 @@ public class CodeInsightTestFixtureImpl extends BaseFixture implements CodeInsig
|
||||
assertInitialized();
|
||||
final Project project = myProjectFixture.getProject();
|
||||
final SortedMap<Integer, List<GutterIconRenderer>> result = new TreeMap<Integer, List<GutterIconRenderer>>();
|
||||
new WriteCommandAction.Simple(project) {
|
||||
configureByFilesInner(filePath);
|
||||
|
||||
@Override
|
||||
protected void run() throws Exception {
|
||||
configureByFilesInner(filePath);
|
||||
for (HighlightInfo info : doHighlighting()) {
|
||||
addGutterIconRenderer(info.getGutterIconRenderer(), info.startOffset, result);
|
||||
}
|
||||
|
||||
for (HighlightInfo info : doHighlighting()) {
|
||||
addGutterIconRenderer(info.getGutterIconRenderer(), info.startOffset);
|
||||
}
|
||||
|
||||
for (final RangeHighlighter highlighter : myEditor.getDocument().getMarkupModel(project).getAllHighlighters()) {
|
||||
addGutterIconRenderer(highlighter.getGutterIconRenderer(), highlighter.getStartOffset());
|
||||
}
|
||||
}
|
||||
|
||||
private void addGutterIconRenderer(final GutterIconRenderer renderer, final int offset) {
|
||||
if (renderer == null) return;
|
||||
|
||||
List<GutterIconRenderer> renderers = result.get(offset);
|
||||
if (renderers == null) {
|
||||
result.put(offset, renderers = new SmartList<GutterIconRenderer>());
|
||||
}
|
||||
renderers.add(renderer);
|
||||
}
|
||||
|
||||
}.execute().throwException();
|
||||
for (final RangeHighlighter highlighter : myEditor.getDocument().getMarkupModel(project).getAllHighlighters()) {
|
||||
addGutterIconRenderer(highlighter.getGutterIconRenderer(), highlighter.getStartOffset(), result);
|
||||
}
|
||||
return ContainerUtil.concat(result.values());
|
||||
}
|
||||
private static void addGutterIconRenderer(final GutterIconRenderer renderer,
|
||||
final int offset,
|
||||
SortedMap<Integer, List<GutterIconRenderer>> result) {
|
||||
if (renderer == null) return;
|
||||
|
||||
List<GutterIconRenderer> renderers = result.get(offset);
|
||||
if (renderers == null) {
|
||||
result.put(offset, renderers = new SmartList<GutterIconRenderer>());
|
||||
}
|
||||
renderers.add(renderer);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
@@ -1082,23 +1045,13 @@ public class CodeInsightTestFixtureImpl extends BaseFixture implements CodeInsig
|
||||
@Override
|
||||
public PsiFile configureByFile(final String file) {
|
||||
assertInitialized();
|
||||
new WriteCommandAction.Simple(getProject()) {
|
||||
@Override
|
||||
protected void run() throws Exception {
|
||||
configureByFilesInner(file);
|
||||
}
|
||||
}.execute();
|
||||
configureByFilesInner(file);
|
||||
return myFile;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void configureByFiles(@NonNls final String... files) {
|
||||
new WriteCommandAction.Simple(getProject()) {
|
||||
@Override
|
||||
protected void run() throws Exception {
|
||||
configureByFilesInner(files);
|
||||
}
|
||||
}.execute();
|
||||
configureByFilesInner(files);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -1184,30 +1137,37 @@ public class CodeInsightTestFixtureImpl extends BaseFixture implements CodeInsig
|
||||
|
||||
private PsiFile configureInner(@NotNull final VirtualFile copy, final SelectionAndCaretMarkupLoader loader) {
|
||||
assertInitialized();
|
||||
try {
|
||||
copy.setBinaryContent(loader.newFileText.getBytes(copy.getCharset()), 0, 0, null);
|
||||
}
|
||||
catch (IOException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
myFile = myPsiManager.findFile(copy);
|
||||
setContext(myFile, myFileContext);
|
||||
myEditor = createEditor(copy);
|
||||
assert myEditor != null : "Editor couldn't be created for file: " + copy.getPath() + ", use copyFileToProject(..) method for this file instead of configureByFile(..)" ;
|
||||
if (loader.caretMarker != null) {
|
||||
int offset = loader.caretMarker.getStartOffset();
|
||||
myEditor.getCaretModel().moveToOffset(offset);
|
||||
}
|
||||
if (loader.selStartMarker != null && loader.selEndMarker != null) {
|
||||
myEditor.getSelectionModel().setSelection(loader.selStartMarker.getStartOffset(), loader.selEndMarker.getStartOffset());
|
||||
}
|
||||
new WriteCommandAction.Simple(getProject()) {
|
||||
public void run() {
|
||||
try {
|
||||
copy.setBinaryContent(loader.newFileText.getBytes(copy.getCharset()), 0, 0, null);
|
||||
}
|
||||
catch (IOException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
myFile = myPsiManager.findFile(copy);
|
||||
setContext(myFile, myFileContext);
|
||||
myEditor = createEditor(copy);
|
||||
assert myEditor != null : "Editor couldn't be created for file: " +
|
||||
copy.getPath() +
|
||||
", use copyFileToProject(..) method for this file instead of configureByFile(..)";
|
||||
if (loader.caretMarker != null) {
|
||||
int offset = loader.caretMarker.getStartOffset();
|
||||
myEditor.getCaretModel().moveToOffset(offset);
|
||||
}
|
||||
if (loader.selStartMarker != null && loader.selEndMarker != null) {
|
||||
myEditor.getSelectionModel().setSelection(loader.selStartMarker.getStartOffset(), loader.selEndMarker.getStartOffset());
|
||||
}
|
||||
|
||||
Module module = getModule();
|
||||
if (module != null) {
|
||||
for (Facet facet : FacetManager.getInstance(module).getAllFacets()) {
|
||||
module.getMessageBus().syncPublisher(FacetManager.FACETS_TOPIC).facetConfigurationChanged(facet);
|
||||
Module module = getModule();
|
||||
if (module != null) {
|
||||
for (Facet facet : FacetManager.getInstance(module).getAllFacets()) {
|
||||
module.getMessageBus().syncPublisher(FacetManager.FACETS_TOPIC).facetConfigurationChanged(facet);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}.execute().throwException();
|
||||
|
||||
|
||||
return myFile;
|
||||
}
|
||||
@@ -1302,7 +1262,13 @@ public class CodeInsightTestFixtureImpl extends BaseFixture implements CodeInsig
|
||||
@NotNull
|
||||
public List<HighlightInfo> doHighlighting() {
|
||||
final Project project = myProjectFixture.getProject();
|
||||
PsiDocumentManager.getInstance(project).commitAllDocuments();
|
||||
new WriteCommandAction.Simple(project) {
|
||||
@Override
|
||||
protected void run() throws Throwable {
|
||||
PsiDocumentManager.getInstance(project).commitAllDocuments();
|
||||
}
|
||||
}.execute().throwException();
|
||||
|
||||
|
||||
return
|
||||
ApplicationManager.getApplication().runReadAction(new Computable<List<HighlightInfo>>() {
|
||||
@@ -1319,7 +1285,7 @@ public class CodeInsightTestFixtureImpl extends BaseFixture implements CodeInsig
|
||||
ensureIndexesUpToDate(project);
|
||||
DaemonCodeAnalyzerImpl codeAnalyzer = (DaemonCodeAnalyzerImpl)DaemonCodeAnalyzer.getInstance(project);
|
||||
TextEditor textEditor = TextEditorProvider.getInstance().getTextEditor(editor);
|
||||
return codeAnalyzer.runPasses(file, editor.getDocument(), textEditor, new DaemonProgressIndicator(), toIgnore, allowDirt, true);
|
||||
return codeAnalyzer.runPasses(file, editor.getDocument(), textEditor, new DaemonProgressIndicator(), toIgnore, allowDirt);
|
||||
}
|
||||
|
||||
public static void ensureIndexesUpToDate(Project project) {
|
||||
|
||||
@@ -132,26 +132,31 @@ class HeavyIdeaTestFixtureImpl extends BaseFixture implements HeavyIdeaTestFixtu
|
||||
|
||||
|
||||
private void setUpProject() throws Exception {
|
||||
File projectFile = File.createTempFile(PROJECT_FILE_PREFIX, PROJECT_FILE_SUFFIX);
|
||||
myFilesToDelete.add(projectFile);
|
||||
new WriteCommandAction.Simple(null) {
|
||||
@Override
|
||||
protected void run() throws Throwable {
|
||||
File projectFile = File.createTempFile(PROJECT_FILE_PREFIX, PROJECT_FILE_SUFFIX);
|
||||
myFilesToDelete.add(projectFile);
|
||||
|
||||
LocalFileSystem.getInstance().refreshAndFindFileByIoFile(projectFile);
|
||||
ByteArrayOutputStream buffer = new ByteArrayOutputStream();
|
||||
new Throwable(projectFile.getPath()).printStackTrace(new PrintStream(buffer));
|
||||
myProject = PlatformTestCase.createProject(projectFile, buffer.toString());
|
||||
LocalFileSystem.getInstance().refreshAndFindFileByIoFile(projectFile);
|
||||
ByteArrayOutputStream buffer = new ByteArrayOutputStream();
|
||||
new Throwable(projectFile.getPath()).printStackTrace(new PrintStream(buffer));
|
||||
myProject = PlatformTestCase.createProject(projectFile, buffer.toString());
|
||||
|
||||
for (ModuleFixtureBuilder moduleFixtureBuilder: myModuleFixtureBuilders) {
|
||||
moduleFixtureBuilder.getFixture().setUp();
|
||||
}
|
||||
for (ModuleFixtureBuilder moduleFixtureBuilder: myModuleFixtureBuilders) {
|
||||
moduleFixtureBuilder.getFixture().setUp();
|
||||
}
|
||||
|
||||
//PropertiesReferenceManager.getInstance(myProject).projectOpened();
|
||||
//PropertiesReferenceManager.getInstance(myProject).projectOpened();
|
||||
|
||||
StartupManagerImpl sm = (StartupManagerImpl)StartupManager.getInstance(myProject);
|
||||
sm.runStartupActivities();
|
||||
sm.runPostStartupActivities();
|
||||
StartupManagerImpl sm = (StartupManagerImpl)StartupManager.getInstance(myProject);
|
||||
sm.runStartupActivities();
|
||||
sm.runPostStartupActivities();
|
||||
|
||||
ProjectManagerEx.getInstanceEx().setCurrentTestProject(myProject);
|
||||
((PsiDocumentManagerImpl)PsiDocumentManager.getInstance(getProject())).clearUncommitedDocuments();
|
||||
ProjectManagerEx.getInstanceEx().setCurrentTestProject(myProject);
|
||||
((PsiDocumentManagerImpl)PsiDocumentManager.getInstance(myProject)).clearUncommitedDocuments();
|
||||
}
|
||||
}.execute().throwException();
|
||||
}
|
||||
|
||||
private void initApplication() throws Exception {
|
||||
@@ -179,6 +184,7 @@ class HeavyIdeaTestFixtureImpl extends BaseFixture implements HeavyIdeaTestFixtu
|
||||
return myProject;
|
||||
}
|
||||
else if (PlatformDataKeys.EDITOR.is(dataId) || OpenFileDescriptor.NAVIGATE_IN_EDITOR.is(dataId)) {
|
||||
if (myProject == null) return null;
|
||||
return FileEditorManager.getInstance(myProject).getSelectedTextEditor();
|
||||
}
|
||||
else {
|
||||
|
||||
@@ -16,6 +16,7 @@
|
||||
|
||||
package com.intellij.testFramework.fixtures.impl;
|
||||
|
||||
import com.intellij.openapi.command.WriteCommandAction;
|
||||
import com.intellij.openapi.module.Module;
|
||||
import com.intellij.testFramework.fixtures.ModuleFixture;
|
||||
|
||||
@@ -34,7 +35,14 @@ public class ModuleFixtureImpl extends BaseFixture implements ModuleFixture {
|
||||
@Override
|
||||
public Module getModule() {
|
||||
if (myModule != null) return myModule;
|
||||
myModule = myBuilder.buildModule();
|
||||
new WriteCommandAction.Simple(null) {
|
||||
@Override
|
||||
protected void run() throws Throwable {
|
||||
myModule = myBuilder.buildModule();
|
||||
}
|
||||
}.execute().throwException();
|
||||
|
||||
|
||||
//disposeOnTearDown(myModule);
|
||||
return myModule;
|
||||
}
|
||||
|
||||
@@ -25,12 +25,10 @@ import org.junit.Test;
|
||||
public class CastConflictsWithInstanceofFixesTest extends IGQuickFixesTestCase {
|
||||
|
||||
|
||||
@Test
|
||||
public void testReplaceCastInDeclaration() throws Throwable {
|
||||
doTest("replaceCastInDeclaration", "Replace cast");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testReplaceInstaneOf() throws Throwable {
|
||||
doTest("replaceInstanceOf", "Replace instanceof");
|
||||
}
|
||||
@@ -39,4 +37,4 @@ public class CastConflictsWithInstanceofFixesTest extends IGQuickFixesTestCase {
|
||||
protected String getRelativePath() {
|
||||
return "bugs/castconflicts";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -22,18 +22,17 @@ package com.siyeh.ig.fixes.bugs;
|
||||
|
||||
import com.intellij.codeInsight.intention.IntentionAction;
|
||||
import com.intellij.openapi.application.PluginPathManager;
|
||||
import com.intellij.testFramework.UsefulTestCase;
|
||||
import com.intellij.testFramework.builders.JavaModuleFixtureBuilder;
|
||||
import com.intellij.testFramework.fixtures.*;
|
||||
import com.siyeh.ig.bugs.CastConflictsWithInstanceofInspection;
|
||||
import org.junit.After;
|
||||
import org.junit.Assert;
|
||||
import org.junit.Before;
|
||||
|
||||
public abstract class IGQuickFixesTestCase {
|
||||
public abstract class IGQuickFixesTestCase extends UsefulTestCase {
|
||||
protected CodeInsightTestFixture myFixture;
|
||||
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
super.setUp();
|
||||
final IdeaTestFixtureFactory fixtureFactory = IdeaTestFixtureFactory.getFixtureFactory();
|
||||
final TestFixtureBuilder<IdeaProjectTestFixture> testFixtureBuilder = fixtureFactory.createFixtureBuilder();
|
||||
myFixture = JavaTestFixtureFactory.getFixtureFactory().createCodeInsightFixture(testFixtureBuilder.getFixture());
|
||||
@@ -47,10 +46,10 @@ public abstract class IGQuickFixesTestCase {
|
||||
myFixture.setUp();
|
||||
}
|
||||
|
||||
@After
|
||||
public void tearDown() throws Exception {
|
||||
myFixture.tearDown();
|
||||
myFixture = null;
|
||||
super.tearDown();
|
||||
}
|
||||
|
||||
protected void doTest(String testName, String hint) throws Throwable {
|
||||
@@ -62,4 +61,4 @@ public abstract class IGQuickFixesTestCase {
|
||||
}
|
||||
|
||||
protected abstract String getRelativePath();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -23,16 +23,16 @@
|
||||
package com.intellij.lang.ant;
|
||||
|
||||
import com.intellij.openapi.application.PluginPathManager;
|
||||
import com.intellij.testFramework.UsefulTestCase;
|
||||
import com.intellij.testFramework.fixtures.CodeInsightTestFixture;
|
||||
import com.intellij.testFramework.fixtures.IdeaProjectTestFixture;
|
||||
import com.intellij.testFramework.fixtures.JavaTestFixtureFactory;
|
||||
import com.intellij.testFramework.fixtures.TestFixtureBuilder;
|
||||
import junit.framework.TestCase;
|
||||
|
||||
/**
|
||||
* @author Maxim.Mossienko
|
||||
*/
|
||||
public class AntMultiFileCompletionTest extends TestCase {
|
||||
public class AntMultiFileCompletionTest extends UsefulTestCase {
|
||||
private CodeInsightTestFixture myFixture;
|
||||
|
||||
protected String getTestDataPath() {
|
||||
@@ -81,4 +81,4 @@ public class AntMultiFileCompletionTest extends TestCase {
|
||||
myFixture = null;
|
||||
super.tearDown();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -49,7 +49,7 @@ public class GenerateAntTest extends IdeaTestCase {
|
||||
public void run() {
|
||||
final ModifiableRootModel model = ModuleRootManager.getInstance(myModule).getModifiableModel();
|
||||
final VirtualFile parent = myModule.getModuleFile().getParent();
|
||||
assertTrue(parent != null);
|
||||
assertNotNull(parent);
|
||||
final CompilerModuleExtension extension = model.getModuleExtension(CompilerModuleExtension.class);
|
||||
extension.inheritCompilerOutputPath(false);
|
||||
extension.setCompilerOutputPath(parent.getUrl() + "/classes");
|
||||
@@ -118,4 +118,4 @@ public class GenerateAntTest extends IdeaTestCase {
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -92,7 +92,12 @@ public class EclipseClasspathTest extends IdeaTestCase {
|
||||
classpathReader
|
||||
.readClasspath(rootModel, new ArrayList<String>(), new ArrayList<String>(), new HashSet<String>(), new HashSet<String>(), null,
|
||||
classpathElement);
|
||||
rootModel.commit();
|
||||
ApplicationManager.getApplication().runWriteAction(new Runnable() {
|
||||
public void run() {
|
||||
rootModel.commit();
|
||||
}
|
||||
});
|
||||
|
||||
return module;
|
||||
}
|
||||
|
||||
|
||||
@@ -78,11 +78,16 @@ public class EclipseEmlTest extends IdeaTestCase {
|
||||
|
||||
final EclipseClasspathStorageProvider.EclipseClasspathConverter converter =
|
||||
new EclipseClasspathStorageProvider.EclipseClasspathConverter(module);
|
||||
ModifiableRootModel rootModel = ModuleRootManager.getInstance(module).getModifiableModel();
|
||||
final ModifiableRootModel rootModel = ModuleRootManager.getInstance(module).getModifiableModel();
|
||||
|
||||
final Element classpathElement = JDOMUtil.loadDocument(new String(FileUtil.loadFileText(new File(path, EclipseXml.DOT_CLASSPATH_EXT)))).getRootElement();
|
||||
converter.getClasspath(rootModel, classpathElement);
|
||||
rootModel.commit();
|
||||
ApplicationManager.getApplication().runWriteAction(new Runnable() {
|
||||
public void run() {
|
||||
rootModel.commit();
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
checkModule(path, module);
|
||||
}
|
||||
@@ -114,4 +119,4 @@ public class EclipseEmlTest extends IdeaTestCase {
|
||||
doTest("/test", getProject());
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -96,7 +96,12 @@ public class EclipseImlTest extends IdeaTestCase {
|
||||
classpathReader.init(rootModel);
|
||||
classpathReader
|
||||
.readClasspath(rootModel, new ArrayList<String>(), new ArrayList<String>(), new HashSet<String>(), new HashSet<String>(), null, classpathElement);
|
||||
rootModel.commit();
|
||||
ApplicationManager.getApplication().runWriteAction(new Runnable() {
|
||||
public void run() {
|
||||
rootModel.commit();
|
||||
}
|
||||
});
|
||||
|
||||
final RootModelImpl model = (RootModelImpl)ModuleRootManager.getInstance(module).getModifiableModel();
|
||||
final Element actualImlElement = new Element("root");
|
||||
model.writeExternal(actualImlElement);
|
||||
|
||||
@@ -20,6 +20,7 @@
|
||||
*/
|
||||
package org.jetbrains.idea.eclipse;
|
||||
|
||||
import com.intellij.openapi.application.ApplicationManager;
|
||||
import com.intellij.openapi.module.Module;
|
||||
import com.intellij.openapi.project.Project;
|
||||
import com.intellij.openapi.roots.JavadocOrderRootType;
|
||||
@@ -32,22 +33,27 @@ import com.intellij.openapi.vfs.VirtualFileManager;
|
||||
|
||||
public class EclipseLibrariesModificationsTest extends EclipseVarsTest {
|
||||
|
||||
private void doTestCreate(String[] classRoots, String[] sourceRoots) throws Exception {
|
||||
private void doTestCreate(final String[] classRoots, final String[] sourceRoots) throws Exception {
|
||||
final Project project = getProject();
|
||||
final String path = project.getBaseDir().getPath() + "/test";
|
||||
final Module module = EclipseClasspathTest.setUpModule(path, project);
|
||||
final ModifiableRootModel model = ModuleRootManager.getInstance(module).getModifiableModel();
|
||||
final String parentUrl = VirtualFileManager.constructUrl(JarFileSystem.PROTOCOL, model.getContentRoots()[0].getParent().getPath());
|
||||
final Library library = model.getModuleLibraryTable().createLibrary("created");
|
||||
final Library.ModifiableModel libModifiableModel = library.getModifiableModel();
|
||||
for (String classRoot : classRoots) {
|
||||
libModifiableModel.addRoot(parentUrl + classRoot, OrderRootType.CLASSES);
|
||||
}
|
||||
for (String sourceRoot : sourceRoots) {
|
||||
libModifiableModel.addRoot(parentUrl + sourceRoot, OrderRootType.SOURCES);
|
||||
}
|
||||
libModifiableModel.commit();
|
||||
model.commit();
|
||||
ApplicationManager.getApplication().runWriteAction(new Runnable() {
|
||||
public void run() {
|
||||
final ModifiableRootModel model = ModuleRootManager.getInstance(module).getModifiableModel();
|
||||
final String parentUrl = VirtualFileManager.constructUrl(JarFileSystem.PROTOCOL, model.getContentRoots()[0].getParent().getPath());
|
||||
final Library library = model.getModuleLibraryTable().createLibrary("created");
|
||||
final Library.ModifiableModel libModifiableModel = library.getModifiableModel();
|
||||
for (String classRoot : classRoots) {
|
||||
libModifiableModel.addRoot(parentUrl + classRoot, OrderRootType.CLASSES);
|
||||
}
|
||||
for (String sourceRoot : sourceRoots) {
|
||||
libModifiableModel.addRoot(parentUrl + sourceRoot, OrderRootType.SOURCES);
|
||||
}
|
||||
libModifiableModel.commit();
|
||||
model.commit();
|
||||
}
|
||||
});
|
||||
|
||||
EclipseClasspathTest.checkModule(project.getBaseDir().getPath() + "/expected", module);
|
||||
}
|
||||
|
||||
@@ -152,39 +158,44 @@ public class EclipseLibrariesModificationsTest extends EclipseVarsTest {
|
||||
new String[]{});
|
||||
}
|
||||
|
||||
private void doTestExisting(String[] classRoots, String[] sourceRoots, String[] javadocs) throws Exception {
|
||||
private void doTestExisting(final String[] classRoots, final String[] sourceRoots, final String[] javadocs) throws Exception {
|
||||
final Project project = getProject();
|
||||
final String path = project.getBaseDir().getPath() + "/test";
|
||||
final Module module = EclipseClasspathTest.setUpModule(path, project);
|
||||
final ModifiableRootModel model = ModuleRootManager.getInstance(module).getModifiableModel();
|
||||
final String parentUrl = VirtualFileManager.constructUrl(JarFileSystem.PROTOCOL, model.getContentRoots()[0].getParent().getPath());
|
||||
final Library library = model.getModuleLibraryTable().getLibraryByName("test.jar");
|
||||
final Library.ModifiableModel libModifiableModel = library.getModifiableModel();
|
||||
final String[] oldClsRoots = libModifiableModel.getUrls(OrderRootType.CLASSES);
|
||||
for (String oldClsRoot : oldClsRoots) {
|
||||
libModifiableModel.removeRoot(oldClsRoot, OrderRootType.CLASSES);
|
||||
}
|
||||
ApplicationManager.getApplication().runWriteAction(new Runnable() {
|
||||
public void run() {
|
||||
final ModifiableRootModel model = ModuleRootManager.getInstance(module).getModifiableModel();
|
||||
final String parentUrl = VirtualFileManager.constructUrl(JarFileSystem.PROTOCOL, model.getContentRoots()[0].getParent().getPath());
|
||||
final Library library = model.getModuleLibraryTable().getLibraryByName("test.jar");
|
||||
final Library.ModifiableModel libModifiableModel = library.getModifiableModel();
|
||||
final String[] oldClsRoots = libModifiableModel.getUrls(OrderRootType.CLASSES);
|
||||
for (String oldClsRoot : oldClsRoots) {
|
||||
libModifiableModel.removeRoot(oldClsRoot, OrderRootType.CLASSES);
|
||||
}
|
||||
|
||||
final String[] oldSrcRoots = libModifiableModel.getUrls(OrderRootType.SOURCES);
|
||||
for (String oldSrcRoot : oldSrcRoots) {
|
||||
libModifiableModel.removeRoot(oldSrcRoot, OrderRootType.SOURCES);
|
||||
}
|
||||
final String[] oldSrcRoots = libModifiableModel.getUrls(OrderRootType.SOURCES);
|
||||
for (String oldSrcRoot : oldSrcRoots) {
|
||||
libModifiableModel.removeRoot(oldSrcRoot, OrderRootType.SOURCES);
|
||||
}
|
||||
|
||||
final String[] oldJdcRoots = libModifiableModel.getUrls(JavadocOrderRootType.getInstance());
|
||||
for (String oldJavadocRoot : oldJdcRoots) {
|
||||
libModifiableModel.removeRoot(oldJavadocRoot, JavadocOrderRootType.getInstance());
|
||||
}
|
||||
for (String classRoot : classRoots) {
|
||||
libModifiableModel.addRoot(parentUrl + classRoot, OrderRootType.CLASSES);
|
||||
}
|
||||
for (String sourceRoot : sourceRoots) {
|
||||
libModifiableModel.addRoot(parentUrl + sourceRoot, OrderRootType.SOURCES);
|
||||
}
|
||||
for (String javadocRoot : javadocs) {
|
||||
libModifiableModel.addRoot(parentUrl + javadocRoot, JavadocOrderRootType.getInstance());
|
||||
}
|
||||
libModifiableModel.commit();
|
||||
model.commit();
|
||||
}
|
||||
});
|
||||
|
||||
final String[] oldJdcRoots = libModifiableModel.getUrls(JavadocOrderRootType.getInstance());
|
||||
for (String oldJavadocRoot : oldJdcRoots) {
|
||||
libModifiableModel.removeRoot(oldJavadocRoot, JavadocOrderRootType.getInstance());
|
||||
}
|
||||
for (String classRoot : classRoots) {
|
||||
libModifiableModel.addRoot(parentUrl + classRoot, OrderRootType.CLASSES);
|
||||
}
|
||||
for (String sourceRoot : sourceRoots) {
|
||||
libModifiableModel.addRoot(parentUrl + sourceRoot, OrderRootType.SOURCES);
|
||||
}
|
||||
for (String javadocRoot : javadocs) {
|
||||
libModifiableModel.addRoot(parentUrl + javadocRoot, JavadocOrderRootType.getInstance());
|
||||
}
|
||||
libModifiableModel.commit();
|
||||
model.commit();
|
||||
EclipseClasspathTest.checkModule(project.getBaseDir().getPath() + "/expected", module);
|
||||
EclipseEmlTest.checkModule(project.getBaseDir().getPath() + "/expected", module);
|
||||
}
|
||||
@@ -193,4 +204,4 @@ public class EclipseLibrariesModificationsTest extends EclipseVarsTest {
|
||||
protected String getRelativeTestPath() {
|
||||
return "modification";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -22,6 +22,7 @@ import com.intellij.openapi.vfs.VirtualFile;
|
||||
import com.intellij.testFramework.fixtures.IdeaProjectTestFixture;
|
||||
import com.intellij.testFramework.fixtures.IdeaTestFixtureFactory;
|
||||
import com.intellij.testFramework.fixtures.TestFixtureBuilder;
|
||||
import com.intellij.util.ui.UIUtil;
|
||||
import git4idea.GitUtil;
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
@@ -48,7 +49,17 @@ public class GitUpperDirectorySearchTest {
|
||||
|
||||
@After
|
||||
public void tearDown() throws Exception {
|
||||
myProjectFixture.tearDown();
|
||||
UIUtil.invokeAndWaitIfNeeded(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
try {
|
||||
myProjectFixture.tearDown();
|
||||
}
|
||||
catch (Exception e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
@@ -64,6 +64,7 @@ import com.intellij.util.PathsList;
|
||||
import com.intellij.util.SmartList;
|
||||
import com.intellij.util.cls.ClsFormatException;
|
||||
import com.intellij.util.containers.ContainerUtil;
|
||||
import com.intellij.util.ui.UIUtil;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
import org.jetbrains.groovy.compiler.rt.CompilerMessage;
|
||||
@@ -75,6 +76,7 @@ import org.jetbrains.plugins.groovy.lang.psi.GroovyFile;
|
||||
import org.jetbrains.plugins.groovy.lang.psi.GroovyFileBase;
|
||||
import org.jetbrains.plugins.groovy.util.GroovyUtils;
|
||||
|
||||
import javax.swing.*;
|
||||
import java.io.*;
|
||||
import java.nio.charset.Charset;
|
||||
import java.util.*;
|
||||
@@ -95,6 +97,7 @@ public abstract class GroovyCompilerBase implements TranslatingCompiler {
|
||||
boolean forStubs,
|
||||
VirtualFile outputDir,
|
||||
OutputSink sink, boolean tests) {
|
||||
//assert !ApplicationManager.getApplication().isDispatchThread();
|
||||
final Sdk sdk = ModuleRootManager.getInstance(module).getSdk();
|
||||
assert sdk != null; //verified before
|
||||
SdkType sdkType = sdk.getSdkType();
|
||||
@@ -177,7 +180,13 @@ public abstract class GroovyCompilerBase implements TranslatingCompiler {
|
||||
processHandler = new GroovycOSProcessHandler(compileContext, commandLine.createProcess(), commandLine.getCommandLineString());
|
||||
|
||||
processHandler.startNotify();
|
||||
processHandler.waitFor();
|
||||
// tests run in awt
|
||||
while (!processHandler.waitFor(100)) {
|
||||
if (SwingUtilities.isEventDispatchThread()) {
|
||||
UIUtil.dispatchAllInvocationEvents();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
final List<VirtualFile> toRecompile = new ArrayList<VirtualFile>();
|
||||
Set<File> toRecompileFiles = processHandler.getToRecompileFiles();
|
||||
@@ -194,7 +203,8 @@ public abstract class GroovyCompilerBase implements TranslatingCompiler {
|
||||
|
||||
final String url = compilerMessage.getUrl();
|
||||
|
||||
compileContext.addMessage(category, compilerMessage.getMessage(), VfsUtil.pathToUrl(FileUtil.toSystemIndependentName(url)), compilerMessage.getLineNum(),
|
||||
compileContext.addMessage(category, compilerMessage.getMessage(), VfsUtil.pathToUrl(FileUtil.toSystemIndependentName(url)),
|
||||
compilerMessage.getLineNum(),
|
||||
compilerMessage.getColumnNum());
|
||||
}
|
||||
|
||||
@@ -219,7 +229,8 @@ public abstract class GroovyCompilerBase implements TranslatingCompiler {
|
||||
}
|
||||
addStubsToCompileScope(outputPaths, compileContext, module);
|
||||
outputItems = Collections.emptyList();
|
||||
} else {
|
||||
}
|
||||
else {
|
||||
final ProgressIndicator indicator = ProgressManager.getInstance().getProgressIndicator();
|
||||
if (indicator != null) {
|
||||
indicator.setText("Updating caches...");
|
||||
|
||||
@@ -26,8 +26,9 @@ import com.intellij.testFramework.fixtures.LightCodeInsightFixtureTestCase
|
||||
import org.jetbrains.annotations.NotNull
|
||||
import org.jetbrains.annotations.Nullable
|
||||
import org.jetbrains.plugins.groovy.util.TestUtils
|
||||
import com.intellij.openapi.command.CommandProcessor
|
||||
|
||||
/**
|
||||
/**
|
||||
* @author Maxim.Medvedev
|
||||
*/
|
||||
public class GroovyClassNameCompletionTest extends LightCodeInsightFixtureTestCase {
|
||||
@@ -54,8 +55,13 @@ public class GroovyClassNameCompletionTest extends LightCodeInsightFixtureTestCa
|
||||
public void doTest(boolean force) throws Exception {
|
||||
addClassToProject("a", "FooBar");
|
||||
myFixture.configureByFile(getTestName(false) + ".groovy");
|
||||
myFixture.complete(CompletionType.CLASS_NAME);
|
||||
if (force) forceCompletion();
|
||||
CommandProcessor.getInstance().executeCommand(new Runnable(){
|
||||
@Override
|
||||
void run() {
|
||||
myFixture.complete(CompletionType.CLASS_NAME);
|
||||
if (force) forceCompletion();
|
||||
}
|
||||
},"xxx", this);
|
||||
myFixture.checkResultByFile(getTestName(false) + "_after.groovy");
|
||||
}
|
||||
|
||||
|
||||
@@ -16,8 +16,6 @@ import com.intellij.execution.runners.ExecutionEnvironment;
|
||||
import com.intellij.execution.runners.ProgramRunner;
|
||||
import com.intellij.execution.ui.RunContentDescriptor;
|
||||
import com.intellij.openapi.Disposable;
|
||||
import com.intellij.openapi.application.ApplicationManager;
|
||||
import com.intellij.openapi.application.ModalityState;
|
||||
import com.intellij.openapi.application.PluginPathManager;
|
||||
import com.intellij.openapi.application.Result;
|
||||
import com.intellij.openapi.command.WriteCommandAction;
|
||||
@@ -42,9 +40,11 @@ import com.intellij.testFramework.fixtures.TempDirTestFixture;
|
||||
import com.intellij.testFramework.fixtures.impl.TempDirTestFixtureImpl;
|
||||
import com.intellij.util.ObjectUtils;
|
||||
import com.intellij.util.concurrency.Semaphore;
|
||||
import com.intellij.util.ui.UIUtil;
|
||||
import org.jetbrains.plugins.groovy.config.GroovyConfigUtils;
|
||||
import org.jetbrains.plugins.groovy.util.GroovyUtils;
|
||||
|
||||
import javax.swing.*;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
@@ -89,9 +89,19 @@ public abstract class GroovyCompilerTestCase extends JavaCodeInsightFixtureTestC
|
||||
|
||||
@Override
|
||||
protected void tearDown() throws Exception {
|
||||
myMainOutput.tearDown();
|
||||
myMainOutput = null;
|
||||
super.tearDown();
|
||||
UIUtil.invokeAndWaitIfNeeded(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
try {
|
||||
myMainOutput.tearDown();
|
||||
myMainOutput = null;
|
||||
GroovyCompilerTestCase.super.tearDown();
|
||||
}
|
||||
catch (Exception e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
protected void setupTestSources() {
|
||||
@@ -150,7 +160,7 @@ public abstract class GroovyCompilerTestCase extends JavaCodeInsightFixtureTestC
|
||||
}
|
||||
|
||||
protected static void setFileText(final PsiFile file, final String barText) throws IOException {
|
||||
Runnable runnable = new Runnable() {
|
||||
UIUtil.invokeAndWaitIfNeeded(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
try {
|
||||
@@ -160,9 +170,7 @@ public abstract class GroovyCompilerTestCase extends JavaCodeInsightFixtureTestC
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
};
|
||||
ApplicationManager.getApplication().invokeAndWait(runnable, ModalityState.NON_MODAL);
|
||||
|
||||
});
|
||||
}
|
||||
|
||||
protected void setFileName(final PsiFile bar, final String name) {
|
||||
@@ -178,8 +186,24 @@ public abstract class GroovyCompilerTestCase extends JavaCodeInsightFixtureTestC
|
||||
final Semaphore semaphore = new Semaphore();
|
||||
semaphore.down();
|
||||
final ErrorReportingCallback callback = new ErrorReportingCallback(semaphore);
|
||||
CompilerManager.getInstance(getProject()).make(callback);
|
||||
semaphore.waitFor();
|
||||
UIUtil.invokeAndWaitIfNeeded(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
try {
|
||||
CompilerManager.getInstance(getProject()).make(callback);
|
||||
}
|
||||
catch (Exception e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
//tests run in awt
|
||||
while (!semaphore.waitFor(100)) {
|
||||
if (SwingUtilities.isEventDispatchThread()) {
|
||||
UIUtil.dispatchAllInvocationEvents();
|
||||
}
|
||||
}
|
||||
callback.throwException();
|
||||
return callback.getMessages();
|
||||
}
|
||||
|
||||
@@ -16,6 +16,7 @@
|
||||
package org.jetbrains.plugins.groovy.intentions;
|
||||
|
||||
import com.intellij.codeInsight.intention.IntentionAction;
|
||||
import com.intellij.openapi.application.ApplicationManager;
|
||||
import com.intellij.psi.PsiClass;
|
||||
import com.intellij.psi.PsiElement;
|
||||
import com.intellij.psi.util.PsiTreeUtil;
|
||||
@@ -78,9 +79,15 @@ public class ConvertMapToClassTest extends GrIntentionTestCase {
|
||||
final GrTypeDefinition foo = ConvertMapToClassIntention.createClass(getProject(), map.getNamedArguments(), "", "Foo");
|
||||
myFixture.addFileToProject(getTestName(true) + "/Foo.groovy", foo.getContainingFile().getText());
|
||||
final PsiClass psiClass = myFixture.findClass("Foo");
|
||||
ConvertMapToClassIntention.replaceMapWithClass(getProject(), map, psiClass, ConvertMapToClassIntention.checkForReturnFromMethod(map),
|
||||
ConvertMapToClassIntention.checkForVariableDeclaration(map),
|
||||
ConvertMapToClassIntention.checkForMethodParameter(map));
|
||||
ApplicationManager.getApplication().runWriteAction(new Runnable() {
|
||||
public void run() {
|
||||
ConvertMapToClassIntention
|
||||
.replaceMapWithClass(getProject(), map, psiClass, ConvertMapToClassIntention.checkForReturnFromMethod(map),
|
||||
ConvertMapToClassIntention.checkForVariableDeclaration(map),
|
||||
ConvertMapToClassIntention.checkForMethodParameter(map));
|
||||
}
|
||||
});
|
||||
|
||||
myFixture.checkResultByFile(getTestName(true) + "/Foo.groovy", getTestName(true) + "/Expected.groovy", true);
|
||||
myFixture.checkResultByFile(getTestName(true) + "/Test_after.groovy", true);
|
||||
}
|
||||
|
||||
@@ -4,10 +4,10 @@
|
||||
*/
|
||||
package org.jetbrains.plugins.groovy.lang;
|
||||
|
||||
|
||||
import com.intellij.testFramework.fixtures.LightCodeInsightFixtureTestCase
|
||||
import org.jetbrains.plugins.groovy.codeInspection.control.GroovyConstantIfStatementInspection.ConstantIfStatementVisitor
|
||||
import org.jetbrains.plugins.groovy.codeInspection.control.GroovyConstantIfStatementInspection
|
||||
import org.jetbrains.plugins.groovy.codeInspection.gpath.GroovySetterCallCanBePropertyAccessInspection;
|
||||
import org.jetbrains.plugins.groovy.codeInspection.gpath.GroovySetterCallCanBePropertyAccessInspection
|
||||
|
||||
/**
|
||||
* @author peter
|
||||
@@ -21,8 +21,7 @@ public class GroovyFixesTest extends LightCodeInsightFixtureTestCase {
|
||||
aaa
|
||||
}""")
|
||||
myFixture.launchAction(myFixture.findSingleIntention("Suppress for statement"))
|
||||
myFixture.checkResult """
|
||||
//noinspection GroovyConstantIfStatement
|
||||
myFixture.checkResult """//noinspection GroovyConstantIfStatement
|
||||
if (true) {
|
||||
aaa
|
||||
}"""
|
||||
@@ -43,4 +42,4 @@ if (true) {
|
||||
assertEmpty myFixture.filterAvailableIntentions("Change to Groovy-style property reference")
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -12,7 +12,6 @@ import org.jetbrains.plugins.groovy.CompositeCompletionData;
|
||||
import org.jetbrains.plugins.groovy.lang.psi.api.statements.GrVariable;
|
||||
import org.jetbrains.plugins.groovy.util.TestUtils;
|
||||
|
||||
import javax.swing.*;
|
||||
import java.util.Collections;
|
||||
import java.util.Comparator;
|
||||
import java.util.List;
|
||||
@@ -90,9 +89,4 @@ public abstract class CompletionTestBase extends JavaCodeInsightFixtureTestCase
|
||||
protected boolean addReferenceVariants() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void invokeTestRunnable(Runnable runnable) throws Exception {
|
||||
SwingUtilities.invokeAndWait(runnable);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package org.jetbrains.plugins.groovy.lang.overriding;
|
||||
|
||||
|
||||
import com.intellij.openapi.application.ApplicationManager
|
||||
import com.intellij.psi.JavaPsiFacade
|
||||
import com.intellij.psi.PsiClassOwner
|
||||
import com.intellij.psi.PsiMethod
|
||||
@@ -68,7 +69,12 @@ class Test {
|
||||
private def generateImplementation(PsiMethod method) {
|
||||
GrTypeDefinition clazz = ((PsiClassOwner) myFixture.file).classes[0]
|
||||
GroovyOverrideImplementUtil.generateImplementation myFixture.editor, myFixture.file, clazz, method, PsiSubstitutor.EMPTY
|
||||
PostprocessReformattingAspect.getInstance(getProject()).doPostponedFormatting()
|
||||
ApplicationManager.getApplication().runWriteAction(new Runnable(){
|
||||
@Override
|
||||
void run() {
|
||||
PostprocessReformattingAspect.getInstance(getProject()).doPostponedFormatting()
|
||||
}
|
||||
});
|
||||
myFixture.editor.selectionModel.removeSelection()
|
||||
}
|
||||
|
||||
|
||||
@@ -2,6 +2,7 @@ package org.jetbrains.plugins.groovy.lang.surroundWith;
|
||||
|
||||
import com.intellij.codeInsight.generation.surroundWith.SurroundWithHandler;
|
||||
import com.intellij.lang.surroundWith.Surrounder;
|
||||
import com.intellij.openapi.application.ApplicationManager;
|
||||
import com.intellij.psi.impl.source.PostprocessReformattingAspect;
|
||||
import org.jetbrains.plugins.groovy.LightGroovyTestCase;
|
||||
import org.jetbrains.plugins.groovy.util.TestUtils;
|
||||
@@ -13,14 +14,19 @@ import java.util.List;
|
||||
* @author peter
|
||||
*/
|
||||
public abstract class SurroundTestCase extends LightGroovyTestCase {
|
||||
protected void doTest(Surrounder surrounder) throws Exception {
|
||||
protected void doTest(final Surrounder surrounder) throws Exception {
|
||||
final List<String> data = TestUtils.readInput(getTestDataPath() + "/" + getTestName(true) + ".test");
|
||||
final String fileText = data.get(0);
|
||||
myFixture.configureByText("a.groovy", fileText);
|
||||
|
||||
SurroundWithHandler.invoke(getProject(), myFixture.getEditor(), myFixture.getFile(), surrounder);
|
||||
PostprocessReformattingAspect.getInstance(getProject()).doPostponedFormatting();
|
||||
PsiUtil.reformatCode(myFixture.getFile());
|
||||
ApplicationManager.getApplication().runWriteAction(new Runnable() {
|
||||
public void run() {
|
||||
SurroundWithHandler.invoke(getProject(), myFixture.getEditor(), myFixture.getFile(), surrounder);
|
||||
PostprocessReformattingAspect.getInstance(getProject()).doPostponedFormatting();
|
||||
PsiUtil.reformatCode(myFixture.getFile());
|
||||
}
|
||||
});
|
||||
|
||||
assertEquals(data.get(1), myFixture.getFile().getText().trim());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -16,6 +16,7 @@
|
||||
|
||||
package org.jetbrains.plugins.groovy.refactoring.move;
|
||||
|
||||
import com.intellij.openapi.application.ApplicationManager;
|
||||
import com.intellij.openapi.fileEditor.FileDocumentManager;
|
||||
import com.intellij.openapi.vfs.VirtualFile;
|
||||
import com.intellij.psi.PsiElement;
|
||||
@@ -140,8 +141,12 @@ public class GroovyMoveMembersTest extends LightCodeInsightFixtureTestCase {
|
||||
final MockMoveMembersOptions options = new MockMoveMembersOptions(targetClass.getQualifiedName(), memberSet);
|
||||
options.setMemberVisibility(null);
|
||||
new MoveMembersProcessor(myFixture.getProject(), null, options).run();
|
||||
PostprocessReformattingAspect.getInstance(getProject()).doPostponedFormatting();
|
||||
FileDocumentManager.getInstance().saveAllDocuments();
|
||||
ApplicationManager.getApplication().runWriteAction(new Runnable() {
|
||||
public void run() {
|
||||
PostprocessReformattingAspect.getInstance(getProject()).doPostponedFormatting();
|
||||
FileDocumentManager.getInstance().saveAllDocuments();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
class MockMoveMembersOptions implements MoveMembersOptions {
|
||||
|
||||
@@ -20,6 +20,7 @@ import com.intellij.compiler.CompilerManagerImpl;
|
||||
import com.intellij.compiler.CompilerWorkspaceConfiguration;
|
||||
import com.intellij.compiler.impl.ModuleCompileScope;
|
||||
import com.intellij.compiler.impl.TranslatingCompilerFilesMonitor;
|
||||
import com.intellij.openapi.application.ApplicationManager;
|
||||
import com.intellij.openapi.compiler.*;
|
||||
import com.intellij.openapi.module.Module;
|
||||
import com.intellij.openapi.module.ModuleManager;
|
||||
@@ -38,6 +39,7 @@ import com.intellij.openapi.vfs.VfsUtil;
|
||||
import com.intellij.openapi.vfs.VirtualFile;
|
||||
import com.intellij.util.ArrayUtil;
|
||||
import com.intellij.util.PathUtil;
|
||||
import org.jetbrains.annotations.NonNls;
|
||||
import org.jetbrains.idea.maven.execution.*;
|
||||
import org.jetbrains.idea.maven.model.MavenArtifact;
|
||||
import org.jetbrains.idea.maven.project.MavenArtifactDownloader;
|
||||
@@ -113,7 +115,7 @@ public abstract class MavenImportingTestCase extends MavenTestCase {
|
||||
doAssertContentFolders(getContentRoot(moduleName), isSource, isTest, expected);
|
||||
}
|
||||
|
||||
private void doAssertContentFolders(ContentEntry e, boolean isSource, boolean isTest, String... expected) {
|
||||
private static void doAssertContentFolders(ContentEntry e, boolean isSource, boolean isTest, String... expected) {
|
||||
List<String> actual = new ArrayList<String>();
|
||||
for (ContentFolder f : isSource ? e.getSourceFolders() : e.getExcludeFolders()) {
|
||||
if (isSource && (isTest != ((SourceFolder)f).isTestSource())) continue;
|
||||
@@ -140,7 +142,7 @@ public abstract class MavenImportingTestCase extends MavenTestCase {
|
||||
assertEquals(testOutput, getAbsolutePath(e.getCompilerOutputUrlForTests()));
|
||||
}
|
||||
|
||||
private String getAbsolutePath(String path) {
|
||||
private static String getAbsolutePath(String path) {
|
||||
path = VfsUtil.urlToPath(path);
|
||||
path = PathUtil.getCanonicalPath(path);
|
||||
return FileUtil.toSystemIndependentName(path);
|
||||
@@ -320,7 +322,7 @@ public abstract class MavenImportingTestCase extends MavenTestCase {
|
||||
return ModuleRootManager.getInstance(getModule(module));
|
||||
}
|
||||
|
||||
protected void importProject(String xml) throws IOException {
|
||||
protected void importProject(@NonNls String xml) throws IOException {
|
||||
createProjectPom(xml);
|
||||
importProject();
|
||||
}
|
||||
@@ -454,15 +456,20 @@ public abstract class MavenImportingTestCase extends MavenTestCase {
|
||||
}
|
||||
}
|
||||
|
||||
protected Sdk setupJdkForModule(String moduleName) {
|
||||
ModifiableRootModel m = ModuleRootManager.getInstance(getModule(moduleName)).getModifiableModel();
|
||||
Sdk sdk = createJdk("Java 1.5");
|
||||
m.setSdk(sdk);
|
||||
m.commit();
|
||||
protected Sdk setupJdkForModule(final String moduleName) {
|
||||
final Sdk sdk = createJdk("Java 1.5");
|
||||
ApplicationManager.getApplication().runWriteAction(new Runnable() {
|
||||
public void run() {
|
||||
final ModifiableRootModel m = ModuleRootManager.getInstance(getModule(moduleName)).getModifiableModel();
|
||||
m.setSdk(sdk);
|
||||
m.commit();
|
||||
}
|
||||
});
|
||||
|
||||
return sdk;
|
||||
}
|
||||
|
||||
protected Sdk createJdk(String versionName) {
|
||||
protected static Sdk createJdk(String versionName) {
|
||||
return JavaSdkImpl.getMockJdk17(versionName);
|
||||
}
|
||||
|
||||
@@ -491,7 +498,7 @@ public abstract class MavenImportingTestCase extends MavenTestCase {
|
||||
});
|
||||
}
|
||||
|
||||
private String collectMessages(CompileContext compileContext, CompilerMessageCategory messageType) {
|
||||
private static String collectMessages(CompileContext compileContext, CompilerMessageCategory messageType) {
|
||||
String result = "";
|
||||
for (CompilerMessage each : compileContext.getMessages(messageType)) {
|
||||
VirtualFile file = each.getVirtualFile();
|
||||
@@ -500,7 +507,7 @@ public abstract class MavenImportingTestCase extends MavenTestCase {
|
||||
return result;
|
||||
}
|
||||
|
||||
protected AtomicInteger configConfirmationForYesAnswer() {
|
||||
protected static AtomicInteger configConfirmationForYesAnswer() {
|
||||
final AtomicInteger counter = new AtomicInteger();
|
||||
Messages.setTestDialog(new TestDialog() {
|
||||
@Override
|
||||
@@ -512,7 +519,7 @@ public abstract class MavenImportingTestCase extends MavenTestCase {
|
||||
return counter;
|
||||
}
|
||||
|
||||
protected AtomicInteger configConfirmationForNoAnswer() {
|
||||
protected static AtomicInteger configConfirmationForNoAnswer() {
|
||||
final AtomicInteger counter = new AtomicInteger();
|
||||
Messages.setTestDialog(new TestDialog() {
|
||||
@Override
|
||||
|
||||
@@ -15,10 +15,12 @@
|
||||
*/
|
||||
package org.jetbrains.idea.maven;
|
||||
|
||||
import com.intellij.compiler.CompilerWorkspaceConfiguration;
|
||||
import com.intellij.openapi.application.ApplicationInfo;
|
||||
import com.intellij.openapi.application.ApplicationManager;
|
||||
import com.intellij.openapi.application.Result;
|
||||
import com.intellij.openapi.application.WriteAction;
|
||||
import com.intellij.openapi.command.WriteCommandAction;
|
||||
import com.intellij.openapi.module.Module;
|
||||
import com.intellij.openapi.module.ModuleManager;
|
||||
import com.intellij.openapi.module.ModuleType;
|
||||
@@ -34,6 +36,8 @@ import com.intellij.openapi.vfs.VirtualFile;
|
||||
import com.intellij.testFramework.UsefulTestCase;
|
||||
import com.intellij.testFramework.fixtures.IdeaProjectTestFixture;
|
||||
import com.intellij.testFramework.fixtures.IdeaTestFixtureFactory;
|
||||
import org.intellij.lang.annotations.Language;
|
||||
import org.jetbrains.annotations.NonNls;
|
||||
import org.jetbrains.idea.maven.project.*;
|
||||
import org.jetbrains.idea.maven.utils.MavenProgressIndicator;
|
||||
|
||||
@@ -63,6 +67,7 @@ public abstract class MavenTestCase extends UsefulTestCase {
|
||||
|
||||
protected VirtualFile myProjectPom;
|
||||
protected List<VirtualFile> myAllPoms = new ArrayList<VirtualFile>();
|
||||
private boolean myCompileInBackground;
|
||||
|
||||
@Override
|
||||
protected void setUp() throws Exception {
|
||||
@@ -97,9 +102,11 @@ public abstract class MavenTestCase extends UsefulTestCase {
|
||||
}
|
||||
}
|
||||
});
|
||||
myCompileInBackground = CompilerWorkspaceConfiguration.getInstance(myProject).COMPILE_IN_BACKGROUND;
|
||||
CompilerWorkspaceConfiguration.getInstance(myProject).COMPILE_IN_BACKGROUND = false;
|
||||
}
|
||||
|
||||
private void ensureTempDirCreated() {
|
||||
private static void ensureTempDirCreated() {
|
||||
if (ourTempDir != null) return;
|
||||
|
||||
ourTempDir = new File(FileUtil.getTempDirectory(), "mavenTests");
|
||||
@@ -120,6 +127,8 @@ public abstract class MavenTestCase extends UsefulTestCase {
|
||||
|
||||
@Override
|
||||
protected void tearDown() throws Exception {
|
||||
CompilerWorkspaceConfiguration.getInstance(myProject).COMPILE_IN_BACKGROUND = myCompileInBackground;
|
||||
|
||||
myProject = null;
|
||||
tearDownFixtures();
|
||||
if (!FileUtil.delete(myDir)) {
|
||||
@@ -188,10 +197,10 @@ public abstract class MavenTestCase extends UsefulTestCase {
|
||||
}
|
||||
|
||||
protected boolean runInWriteAction() {
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
protected String getRoot() {
|
||||
protected static String getRoot() {
|
||||
if (SystemInfo.isWindows) return "c:";
|
||||
return "";
|
||||
}
|
||||
@@ -235,7 +244,7 @@ public abstract class MavenTestCase extends UsefulTestCase {
|
||||
return pathFromBasedir(myProjectRoot, relPath);
|
||||
}
|
||||
|
||||
protected String pathFromBasedir(VirtualFile root, String relPath) {
|
||||
protected static String pathFromBasedir(VirtualFile root, String relPath) {
|
||||
return FileUtil.toSystemIndependentName(root.getPath() + "/" + relPath);
|
||||
}
|
||||
|
||||
@@ -243,7 +252,7 @@ public abstract class MavenTestCase extends UsefulTestCase {
|
||||
return updateSettingsXmlFully(createSettingsXmlContent(content));
|
||||
}
|
||||
|
||||
protected VirtualFile updateSettingsXmlFully(String content) throws IOException {
|
||||
protected VirtualFile updateSettingsXmlFully(@NonNls @Language("XML") String content) throws IOException {
|
||||
File ioFile = new File(myDir, "settings.xml");
|
||||
ioFile.createNewFile();
|
||||
VirtualFile f = LocalFileSystem.getInstance().refreshAndFindFileByIoFile(ioFile);
|
||||
@@ -253,11 +262,16 @@ public abstract class MavenTestCase extends UsefulTestCase {
|
||||
}
|
||||
|
||||
protected void deleteSettingsXml() throws IOException {
|
||||
VirtualFile f = LocalFileSystem.getInstance().refreshAndFindFileByIoFile(new File(myDir, "settings.xml"));
|
||||
if (f != null) f.delete(this);
|
||||
new WriteCommandAction.Simple(myProject) {
|
||||
@Override
|
||||
protected void run() throws Throwable {
|
||||
VirtualFile f = LocalFileSystem.getInstance().refreshAndFindFileByIoFile(new File(myDir, "settings.xml"));
|
||||
if (f != null) f.delete(this);
|
||||
}
|
||||
}.execute().throwException();
|
||||
}
|
||||
|
||||
private String createSettingsXmlContent(String content) {
|
||||
private static String createSettingsXmlContent(String content) {
|
||||
String mirror = System.getProperty("idea.maven.test.mirror",
|
||||
"http://maven.labs.intellij.net:8081/nexus/content/groups/public/");
|
||||
return "<settings>" +
|
||||
@@ -280,16 +294,21 @@ public abstract class MavenTestCase extends UsefulTestCase {
|
||||
return createModule(name, StdModuleTypes.JAVA);
|
||||
}
|
||||
|
||||
protected Module createModule(String name, ModuleType type) throws IOException {
|
||||
VirtualFile f = createProjectSubFile(name + "/" + name + ".iml");
|
||||
Module module = ModuleManager.getInstance(myProject).newModule(f.getPath(), type);
|
||||
ModifiableRootModel model = ModuleRootManager.getInstance(module).getModifiableModel();
|
||||
model.addContentEntry(f.getParent());
|
||||
model.commit();
|
||||
return module;
|
||||
protected Module createModule(final String name, final ModuleType type) throws IOException {
|
||||
return new WriteCommandAction<Module>(myProject) {
|
||||
@Override
|
||||
protected void run(Result<Module> moduleResult) throws Throwable {
|
||||
VirtualFile f = createProjectSubFile(name + "/" + name + ".iml");
|
||||
Module module = ModuleManager.getInstance(myProject).newModule(f.getPath(), type);
|
||||
ModifiableRootModel model = ModuleRootManager.getInstance(module).getModifiableModel();
|
||||
model.addContentEntry(f.getParent());
|
||||
model.commit();
|
||||
moduleResult.setResult(module);
|
||||
}
|
||||
}.execute().getResultObject();
|
||||
}
|
||||
|
||||
protected VirtualFile createProjectPom(String xml) throws IOException {
|
||||
protected VirtualFile createProjectPom(@NonNls String xml) throws IOException {
|
||||
return myProjectPom = createPomFile(myProjectRoot, xml);
|
||||
}
|
||||
|
||||
@@ -297,17 +316,24 @@ public abstract class MavenTestCase extends UsefulTestCase {
|
||||
return createPomFile(createProjectSubDir(relativePath), xml);
|
||||
}
|
||||
|
||||
protected VirtualFile createPomFile(VirtualFile dir, String xml) throws IOException {
|
||||
protected VirtualFile createPomFile(final VirtualFile dir, String xml) throws IOException {
|
||||
VirtualFile f = dir.findChild("pom.xml");
|
||||
if (f == null) {
|
||||
f = dir.createChildData(null, "pom.xml");
|
||||
f = new WriteAction<VirtualFile>() {
|
||||
@Override
|
||||
protected void run(Result<VirtualFile> result) throws Throwable {
|
||||
VirtualFile res = dir.createChildData(null, "pom.xml");
|
||||
result.setResult(res);
|
||||
}
|
||||
}.execute().getResultObject();
|
||||
myAllPoms.add(f);
|
||||
}
|
||||
setFileContent(f, createPomXml(xml));
|
||||
return f;
|
||||
}
|
||||
|
||||
protected String createPomXml(String xml) {
|
||||
@NonNls @Language(value="XML")
|
||||
protected static String createPomXml(@NonNls @Language(value="XML", prefix="<xml>", suffix="</xml>") String xml) {
|
||||
return "<?xml version=\"1.0\"?>" +
|
||||
"<project xmlns=\"http://maven.apache.org/POM/4.0.0\"" +
|
||||
" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"" +
|
||||
@@ -345,16 +371,22 @@ public abstract class MavenTestCase extends UsefulTestCase {
|
||||
return createProfilesFile(createProjectSubDir(relativePath), content);
|
||||
}
|
||||
|
||||
private VirtualFile createProfilesFile(VirtualFile dir, String content) throws IOException {
|
||||
private VirtualFile createProfilesFile(final VirtualFile dir, String content) throws IOException {
|
||||
VirtualFile f = dir.findChild("profiles.xml");
|
||||
if (f == null) {
|
||||
f = dir.createChildData(null, "profiles.xml");
|
||||
f = new WriteAction<VirtualFile>() {
|
||||
@Override
|
||||
protected void run(Result<VirtualFile> result) throws Throwable {
|
||||
VirtualFile res = dir.createChildData(null, "profiles.xml");
|
||||
result.setResult(res);
|
||||
}
|
||||
}.execute().getResultObject();
|
||||
}
|
||||
setFileContent(f, content);
|
||||
return f;
|
||||
}
|
||||
|
||||
private String createValidProfiles(String xml, boolean oldStyle) {
|
||||
private static String createValidProfiles(String xml, boolean oldStyle) {
|
||||
if (oldStyle) {
|
||||
return "<?xml version=\"1.0\"?>" +
|
||||
"<profiles>" +
|
||||
@@ -370,8 +402,13 @@ public abstract class MavenTestCase extends UsefulTestCase {
|
||||
}
|
||||
|
||||
protected void deleteProfilesXml() throws IOException {
|
||||
VirtualFile f = myProjectRoot.findChild("profiles.xml");
|
||||
if (f != null) f.delete(this);
|
||||
new WriteCommandAction.Simple(myProject) {
|
||||
@Override
|
||||
protected void run() throws Throwable {
|
||||
VirtualFile f = myProjectRoot.findChild("profiles.xml");
|
||||
if (f != null) f.delete(this);
|
||||
}
|
||||
}.execute().throwException();
|
||||
}
|
||||
|
||||
protected void createStdProjectFolders() {
|
||||
@@ -406,11 +443,11 @@ public abstract class MavenTestCase extends UsefulTestCase {
|
||||
return file;
|
||||
}
|
||||
|
||||
private void setFileContent(VirtualFile file, String content) throws IOException {
|
||||
private static void setFileContent(VirtualFile file, String content) throws IOException {
|
||||
file.setBinaryContent(content.getBytes(), file.getModificationStamp() + 4000, file.getTimeStamp() + 4000);
|
||||
}
|
||||
|
||||
protected void assertPathEquals(String expected, String actual) {
|
||||
protected static void assertPathEquals(String expected, String actual) {
|
||||
if (expected != null) expected = FileUtil.toSystemIndependentName(expected);
|
||||
if (actual != null) actual = FileUtil.toSystemIndependentName(actual);
|
||||
assertEquals(expected, actual);
|
||||
@@ -428,7 +465,7 @@ public abstract class MavenTestCase extends UsefulTestCase {
|
||||
assertUnorderedElementsAreEqual(Arrays.asList(actual), expected);
|
||||
}
|
||||
|
||||
protected <T, U> void assertUnorderedElementsAreEqual(Collection<U> actual, T... expected) {
|
||||
protected static <T, U> void assertUnorderedElementsAreEqual(Collection<U> actual, T... expected) {
|
||||
String s = "\nexpected: " + Arrays.asList(expected) + "\nactual: " + new ArrayList<U>(actual);
|
||||
assertEquals(s, expected.length, actual.size());
|
||||
|
||||
@@ -444,7 +481,7 @@ public abstract class MavenTestCase extends UsefulTestCase {
|
||||
}
|
||||
}
|
||||
|
||||
protected <T, U> void assertOrderedElementsAreEqual(Collection<U> actual, T... expected) {
|
||||
protected static <T, U> void assertOrderedElementsAreEqual(Collection<U> actual, T... expected) {
|
||||
String s = "\nexpected: " + Arrays.asList(expected) + "\nactual: " + new ArrayList<U>(actual);
|
||||
assertEquals(s, expected.length, actual.size());
|
||||
|
||||
@@ -456,12 +493,12 @@ public abstract class MavenTestCase extends UsefulTestCase {
|
||||
}
|
||||
}
|
||||
|
||||
protected <T> void assertContain(List<? extends T> actual, T... expected) {
|
||||
protected static <T> void assertContain(List<? extends T> actual, T... expected) {
|
||||
List<T> expectedList = Arrays.asList(expected);
|
||||
assertTrue("expected: " + expectedList + "\n" + "actual: " + actual.toString(), actual.containsAll(expectedList));
|
||||
}
|
||||
|
||||
protected <T> void assertDoNotContain(List<T> actual, T... expected) {
|
||||
protected static <T> void assertDoNotContain(List<T> actual, T... expected) {
|
||||
List<T> actualCopy = new ArrayList<T>(actual);
|
||||
actualCopy.removeAll(Arrays.asList(expected));
|
||||
assertTrue(actual.toString(), actualCopy.size() == actual.size());
|
||||
@@ -493,7 +530,7 @@ public abstract class MavenTestCase extends UsefulTestCase {
|
||||
System.out.println(toPrint);
|
||||
}
|
||||
|
||||
private String getTestMavenHome() {
|
||||
private static String getTestMavenHome() {
|
||||
return System.getProperty("idea.maven.test.home");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -17,6 +17,8 @@ package org.jetbrains.idea.maven.compiler;
|
||||
|
||||
import com.intellij.compiler.CompilerConfiguration;
|
||||
import com.intellij.compiler.CompilerConfigurationImpl;
|
||||
import com.intellij.openapi.application.ApplicationManager;
|
||||
import com.intellij.openapi.command.WriteCommandAction;
|
||||
import com.intellij.openapi.roots.CompilerModuleExtension;
|
||||
import com.intellij.openapi.roots.ModifiableRootModel;
|
||||
import com.intellij.openapi.roots.ModuleRootManager;
|
||||
@@ -164,7 +166,7 @@ public class ResourceCopyingTest extends MavenImportingTestCase {
|
||||
}
|
||||
|
||||
public void testDeletingFilesThatWasCopiedAndThenDeleted() throws Exception {
|
||||
VirtualFile file = createProjectSubFile("res/file.properties");
|
||||
final VirtualFile file = createProjectSubFile("res/file.properties");
|
||||
|
||||
importProject("<groupId>test</groupId>" +
|
||||
"<artifactId>project</artifactId>" +
|
||||
@@ -181,7 +183,13 @@ public class ResourceCopyingTest extends MavenImportingTestCase {
|
||||
compileModules("project");
|
||||
assertCopied("target/classes/file.properties");
|
||||
|
||||
file.delete(this);
|
||||
new WriteCommandAction.Simple(myProject) {
|
||||
@Override
|
||||
protected void run() throws Throwable {
|
||||
file.delete(this);
|
||||
}
|
||||
}.execute().throwException();
|
||||
|
||||
|
||||
compileModules("project");
|
||||
assertNotCopied("target/classes/file.properties");
|
||||
@@ -326,7 +334,13 @@ public class ResourceCopyingTest extends MavenImportingTestCase {
|
||||
|
||||
compileModules("project");
|
||||
assertCopied("target/classes/file.properties");
|
||||
myProjectPom.getParent().findFileByRelativePath("target").delete(this);
|
||||
new WriteCommandAction.Simple(myProject) {
|
||||
@Override
|
||||
protected void run() throws Throwable {
|
||||
myProjectPom.getParent().findFileByRelativePath("target").delete(this);
|
||||
}
|
||||
}.execute().throwException();
|
||||
|
||||
|
||||
compileModules("project");
|
||||
assertCopied("target/classes/file.properties");
|
||||
@@ -342,12 +356,17 @@ public class ResourceCopyingTest extends MavenImportingTestCase {
|
||||
"<artifactId>project</artifactId>" +
|
||||
"<version>1</version>");
|
||||
|
||||
MavenRootModelAdapter adapter = new MavenRootModelAdapter(myProjectsTree.findProject(myProjectPom),
|
||||
getModule("project"),
|
||||
new MavenDefaultModifiableModelsProvider(myProject));
|
||||
adapter.addSourceFolder(myProjectRoot.findFileByRelativePath("src/main/resources").getPath(), false);
|
||||
adapter.addSourceFolder(myProjectRoot.findFileByRelativePath("src/main/ideaRes").getPath(), false);
|
||||
adapter.getRootModel().commit();
|
||||
ApplicationManager.getApplication().runWriteAction(new Runnable() {
|
||||
public void run() {
|
||||
MavenRootModelAdapter adapter = new MavenRootModelAdapter(myProjectsTree.findProject(myProjectPom),
|
||||
getModule("project"),
|
||||
new MavenDefaultModifiableModelsProvider(myProject));
|
||||
adapter.addSourceFolder(myProjectRoot.findFileByRelativePath("src/main/resources").getPath(), false);
|
||||
adapter.addSourceFolder(myProjectRoot.findFileByRelativePath("src/main/ideaRes").getPath(), false);
|
||||
adapter.getRootModel().commit();
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
assertSources("project", "src/main/resources", "src/main/ideaRes");
|
||||
|
||||
@@ -455,7 +474,13 @@ public class ResourceCopyingTest extends MavenImportingTestCase {
|
||||
"</build>");
|
||||
importProject();
|
||||
|
||||
setModulesOutput(myProjectRoot.createChildDirectory(this, "output"), "project", "m1", "m2");
|
||||
new WriteCommandAction.Simple(myProject) {
|
||||
@Override
|
||||
protected void run() throws Throwable {
|
||||
setModulesOutput(myProjectRoot.createChildDirectory(this, "output"), "project", "m1", "m2");
|
||||
}
|
||||
}.execute().throwException();
|
||||
|
||||
|
||||
compileModules("project", "m1", "m2");
|
||||
assertCopied("output/file.xxx");
|
||||
@@ -470,13 +495,17 @@ public class ResourceCopyingTest extends MavenImportingTestCase {
|
||||
assertCopied("output/file.xxx");
|
||||
}
|
||||
|
||||
private void setModulesOutput(VirtualFile output, String... moduleNames) {
|
||||
for (String each : moduleNames) {
|
||||
ModifiableRootModel model = ModuleRootManager.getInstance(getModule(each)).getModifiableModel();
|
||||
model.getModuleExtension(CompilerModuleExtension.class).setCompilerOutputPath(output);
|
||||
model.getModuleExtension(CompilerModuleExtension.class).setCompilerOutputPathForTests(output);
|
||||
model.commit();
|
||||
}
|
||||
private void setModulesOutput(final VirtualFile output, final String... moduleNames) {
|
||||
ApplicationManager.getApplication().runWriteAction(new Runnable() {
|
||||
public void run() {
|
||||
for (String each : moduleNames) {
|
||||
ModifiableRootModel model = ModuleRootManager.getInstance(getModule(each)).getModifiableModel();
|
||||
model.getModuleExtension(CompilerModuleExtension.class).setCompilerOutputPath(output);
|
||||
model.getModuleExtension(CompilerModuleExtension.class).setCompilerOutputPathForTests(output);
|
||||
model.commit();
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public void testWebResources() throws Exception {
|
||||
@@ -575,4 +604,4 @@ public class ResourceCopyingTest extends MavenImportingTestCase {
|
||||
private void assertNotCopied(String path) {
|
||||
assertNull(myProjectPom.getParent().findFileByRelativePath(path));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -16,6 +16,7 @@
|
||||
package org.jetbrains.idea.maven.compiler;
|
||||
|
||||
import com.intellij.compiler.CompilerConfiguration;
|
||||
import com.intellij.openapi.application.ApplicationManager;
|
||||
import com.intellij.openapi.fileTypes.FileTypeManager;
|
||||
import com.intellij.openapi.fileTypes.StdFileTypes;
|
||||
import com.intellij.openapi.vfs.VfsUtil;
|
||||
@@ -229,12 +230,17 @@ public class ResourceFilteringTest extends MavenImportingTestCase {
|
||||
" </resources>" +
|
||||
"</build>");
|
||||
|
||||
MavenRootModelAdapter adapter = new MavenRootModelAdapter(myProjectsTree.findProject(myProjectPom),
|
||||
getModule("project"),
|
||||
new MavenDefaultModifiableModelsProvider(myProject));
|
||||
adapter.addSourceFolder(myProjectRoot.findFileByRelativePath("src/main/resources").getPath(), false);
|
||||
adapter.addSourceFolder(myProjectRoot.findFileByRelativePath("src/main/ideaRes").getPath(), false);
|
||||
adapter.getRootModel().commit();
|
||||
ApplicationManager.getApplication().runWriteAction(new Runnable() {
|
||||
public void run() {
|
||||
MavenRootModelAdapter adapter = new MavenRootModelAdapter(myProjectsTree.findProject(myProjectPom),
|
||||
getModule("project"),
|
||||
new MavenDefaultModifiableModelsProvider(myProject));
|
||||
adapter.addSourceFolder(myProjectRoot.findFileByRelativePath("src/main/resources").getPath(), false);
|
||||
adapter.addSourceFolder(myProjectRoot.findFileByRelativePath("src/main/ideaRes").getPath(), false);
|
||||
adapter.getRootModel().commit();
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
assertSources("project", "src/main/resources", "src/main/ideaRes");
|
||||
|
||||
@@ -866,7 +872,7 @@ public class ResourceFilteringTest extends MavenImportingTestCase {
|
||||
assertResult(myProjectPom, relativePath, content);
|
||||
}
|
||||
|
||||
private void assertResult(VirtualFile pomFile, String relativePath, String content) throws IOException {
|
||||
private static void assertResult(VirtualFile pomFile, String relativePath, String content) throws IOException {
|
||||
VirtualFile file = pomFile.getParent().findFileByRelativePath(relativePath);
|
||||
assertNotNull("file not found: " + relativePath, file);
|
||||
assertEquals(content, VfsUtil.loadText(file));
|
||||
|
||||
@@ -15,6 +15,7 @@
|
||||
*/
|
||||
package org.jetbrains.idea.maven.dom;
|
||||
|
||||
import com.intellij.openapi.application.ApplicationManager;
|
||||
import com.intellij.openapi.command.CommandProcessor;
|
||||
import com.intellij.openapi.editor.Document;
|
||||
import com.intellij.openapi.fileEditor.FileDocumentManager;
|
||||
@@ -49,13 +50,17 @@ public class MavenModelReadingAndWritingTest extends MavenImportingTestCase {
|
||||
CommandProcessor.getInstance().executeCommand(myProject, new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
MavenDomProjectModel model = getDomModel();
|
||||
ApplicationManager.getApplication().runWriteAction(new Runnable() {
|
||||
public void run() {
|
||||
MavenDomProjectModel model = getDomModel();
|
||||
|
||||
model.getGroupId().setStringValue("foo");
|
||||
model.getArtifactId().setStringValue("bar");
|
||||
model.getVersion().setStringValue("baz");
|
||||
model.getGroupId().setStringValue("foo");
|
||||
model.getArtifactId().setStringValue("bar");
|
||||
model.getVersion().setStringValue("baz");
|
||||
|
||||
formatAndSaveProjectPomDocument();
|
||||
formatAndSaveProjectPomDocument();
|
||||
}
|
||||
});
|
||||
}
|
||||
}, null, null);
|
||||
|
||||
@@ -74,14 +79,18 @@ public class MavenModelReadingAndWritingTest extends MavenImportingTestCase {
|
||||
CommandProcessor.getInstance().executeCommand(myProject, new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
MavenDomProjectModel model = getDomModel();
|
||||
ApplicationManager.getApplication().runWriteAction(new Runnable() {
|
||||
public void run() {
|
||||
MavenDomProjectModel model = getDomModel();
|
||||
|
||||
MavenDomDependency d = model.getDependencies().addDependency();
|
||||
d.getGroupId().setStringValue("group");
|
||||
d.getArtifactId().setStringValue("artifact");
|
||||
d.getVersion().setStringValue("version");
|
||||
MavenDomDependency d = model.getDependencies().addDependency();
|
||||
d.getGroupId().setStringValue("group");
|
||||
d.getArtifactId().setStringValue("artifact");
|
||||
d.getVersion().setStringValue("version");
|
||||
|
||||
formatAndSaveProjectPomDocument();
|
||||
formatAndSaveProjectPomDocument();
|
||||
}
|
||||
});
|
||||
}
|
||||
}, null, null);
|
||||
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user