Merge remote-tracking branch 'origin/master'

This commit is contained in:
irengrig
2014-10-07 11:42:00 +02:00
8 changed files with 72 additions and 30 deletions
@@ -1,5 +1,5 @@
/*
* Copyright 2000-2013 JetBrains s.r.o.
* Copyright 2000-2014 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -237,7 +237,7 @@ public class ArrangementAtomMatchConditionComponent implements ArrangementUiComp
@NotNull
@Override
public ArrangementAtomMatchCondition getMatchCondition() {
if (Boolean.valueOf(myInverted) == myCondition.getValue()) {
if (Boolean.valueOf(myInverted).equals(myCondition.getValue())) {
if (myOppositeCondition == null) {
myOppositeCondition = new ArrangementAtomMatchCondition(myCondition.getType(), !myInverted);
}
@@ -1,5 +1,5 @@
/*
* Copyright 2000-2013 JetBrains s.r.o.
* Copyright 2000-2014 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -21,6 +21,7 @@ import com.intellij.concurrency.JobLauncher;
import com.intellij.injected.editor.DocumentWindow;
import com.intellij.lang.Language;
import com.intellij.lang.injection.InjectedLanguageManager;
import com.intellij.openapi.application.ApplicationManager;
import com.intellij.openapi.diagnostic.Logger;
import com.intellij.openapi.editor.Document;
import com.intellij.openapi.editor.Editor;
@@ -145,6 +146,7 @@ public class InjectedGeneralHighlightingPass extends GeneralHighlightingPass imp
private Set<PsiFile> getInjectedPsiFiles(@NotNull final List<PsiElement> elements1,
@NotNull final List<PsiElement> elements2,
@NotNull final ProgressIndicator progress) {
ApplicationManager.getApplication().assertReadAccessAllowed();
final Set<PsiFile> outInjected = new THashSet<PsiFile>();
List<DocumentWindow> injected = InjectedLanguageUtil.getCachedInjectedDocuments(myFile);
@@ -16,6 +16,7 @@
package com.intellij.concurrency;
import com.intellij.openapi.application.ApplicationManager;
import com.intellij.openapi.application.ex.ApplicationManagerEx;
import com.intellij.openapi.progress.ProcessCanceledException;
import com.intellij.openapi.progress.ProgressIndicator;
import com.intellij.openapi.progress.ProgressManager;
@@ -129,19 +130,30 @@ public class JobLauncherImpl extends JobLauncher {
if (things.size() <= 1 || JobSchedulerImpl.CORES_COUNT <= CORES_FORK_THRESHOLD) {
final AtomicBoolean result = new AtomicBoolean(true);
ProgressManager.getInstance().executeProcessUnderProgress(new Runnable() {
Runnable runnable = new Runnable() {
@Override
public void run() {
//noinspection ForLoopReplaceableByForEach
for (int i = 0; i < things.size(); i++) {
T thing = things.get(i);
if (!thingProcessor.process(thing)) {
result.set(false);
break;
ProgressManager.getInstance().executeProcessUnderProgress(new Runnable() {
@Override
public void run() {
//noinspection ForLoopReplaceableByForEach
for (int i = 0; i < things.size(); i++) {
T thing = things.get(i);
if (!thingProcessor.process(thing)) {
result.set(false);
break;
}
}
}
}
}, wrapper);
}
}, wrapper);
};
if (runInReadAction) {
if (!ApplicationManagerEx.getApplicationEx().tryRunReadAction(runnable)) return false;
}
else {
runnable.run();
}
return result.get();
}
@@ -263,7 +263,7 @@ public class CacheUpdateRunner extends DumbModeTask {
try {
final FileContent fileContent = myQueue.take(myInnerIndicator);
if (fileContent == null) {
myFinished.set(Boolean.TRUE);
myFinished.set(true);
return;
}
@@ -295,6 +295,7 @@ public class CacheUpdateRunner extends DumbModeTask {
@Override
public void run() {
if (myProcessInReadAction) {
// in wait methods we don't want to deadlock by grabbing write lock (or having it in queue) and trying to run read action in separate thread
if (!ApplicationManagerEx.getApplicationEx().tryRunReadAction(action)) {
throw new ProcessCanceledException();
}
@@ -14,12 +14,10 @@
* limitations under the License.
*/
import com.intellij.openapi.util.EmptyRunnable;
import com.intellij.psi.impl.DocumentCommitThread;
import com.intellij.testFramework.LightPlatformTestCase;
import com.intellij.util.ui.UIUtil;
import com.intellij.testFramework.UsefulTestCase;
import junit.framework.TestCase;
import sun.awt.AWTAutoShutdown;
import javax.swing.*;
/**
* This is should be first test in all tests so we can measure how long tests are starting up.
@@ -28,18 +26,20 @@ import sun.awt.AWTAutoShutdown;
@SuppressWarnings("JUnitTestClassNamingConvention")
public class _FirstInSuiteTest extends TestCase {
public void testNothing() throws Exception {
SwingUtilities.invokeAndWait(new Runnable() {
@Override
public void run() {
System.out.println("EDT is "+Thread.currentThread());
}
});
// in tests EDT inexplicably shuts down sometimes during the first access,
// which leads to nasty problems in ApplicationImpl which assumes there is only one EDT.
// so we try to forcibly terminate EDT here to urge JVM to re-spawn new shiny permanent EDT-1
UIUtil.invokeAndWaitIfNeeded(EmptyRunnable.getInstance());
final Thread mainThread = Thread.currentThread();
UIUtil.invokeAndWaitIfNeeded(new Runnable() {
UsefulTestCase.replaceIdeEventQueueSafely();
SwingUtilities.invokeAndWait(new Runnable() {
@Override
public void run() {
AWTAutoShutdown.getInstance().notifyThreadBusy(mainThread);
LightPlatformTestCase.initApplication();
DocumentCommitThread.getInstance();
Thread.currentThread().interrupt(); // exit current EDT, ignore all queued events since they are in a wrong thread by now
System.out.println("EDT is "+Thread.currentThread());
}
});
}
@@ -110,6 +110,7 @@ import java.io.File;
import java.io.IOException;
import java.io.PrintStream;
import java.util.*;
import java.util.concurrent.atomic.AtomicReference;
import static com.intellij.openapi.roots.ModuleRootModificationUtil.updateModel;
@@ -666,8 +667,9 @@ public abstract class LightPlatformTestCase extends UsefulTestCase implements Da
return;
}
final Throwable[] throwables = new Throwable[1];
final AtomicReference<Throwable> throwable = new AtomicReference<Throwable>();
replaceIdeEventQueueSafely();
SwingUtilities.invokeAndWait(new Runnable() {
@Override
public void run() {
@@ -675,8 +677,8 @@ public abstract class LightPlatformTestCase extends UsefulTestCase implements Da
ourTestThread = Thread.currentThread();
startRunAndTear();
}
catch (Throwable throwable) {
throwables[0] = throwable;
catch (Throwable e) {
throwable.set(e);
}
finally {
ourTestThread = null;
@@ -694,8 +696,8 @@ public abstract class LightPlatformTestCase extends UsefulTestCase implements Da
}
});
if (throwables[0] != null) {
throw throwables[0];
if (throwable.get() != null) {
throw throwable.get();
}
// just to make sure all deferred Runnables to finish
@@ -599,6 +599,7 @@ public abstract class PlatformTestCase extends UsefulTestCase implements DataPro
public void runBare() throws Throwable {
if (!shouldRunTest()) return;
replaceIdeEventQueueSafely();
try {
runBareImpl();
}
@@ -17,6 +17,7 @@ package com.intellij.testFramework;
import com.intellij.codeInsight.CodeInsightSettings;
import com.intellij.diagnostic.PerformanceWatcher;
import com.intellij.ide.IdeEventQueue;
import com.intellij.mock.MockApplication;
import com.intellij.openapi.Disposable;
import com.intellij.openapi.application.Application;
@@ -57,6 +58,7 @@ import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.junit.Assert;
import javax.swing.*;
import javax.swing.Timer;
import java.awt.*;
import java.io.File;
@@ -72,6 +74,7 @@ import java.util.List;
import java.util.concurrent.DelayQueue;
import java.util.concurrent.Delayed;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicReference;
import java.util.regex.Pattern;
/**
@@ -335,11 +338,32 @@ public abstract class UsefulTestCase extends TestCase {
super.runBare();
}
public static void replaceIdeEventQueueSafely() throws InterruptedException, InvocationTargetException {
if (Toolkit.getDefaultToolkit().getSystemEventQueue() instanceof IdeEventQueue) {
return;
}
if (SwingUtilities.isEventDispatchThread()) {
throw new RuntimeException("must not call under EDT");
}
// in JDK 1.6 java.awt.EventQueue.push() causes slow painful death of current EDT
// so we have to wait through its agony to termination
SwingUtilities.invokeAndWait(new Runnable() {
@Override
public void run() {
IdeEventQueue.getInstance();
}
});
SwingUtilities.invokeAndWait(EmptyRunnable.getInstance());
SwingUtilities.invokeAndWait(EmptyRunnable.getInstance());
}
@Override
public void runBare() throws Throwable {
if (!shouldRunTest()) return;
if (runInDispatchThread()) {
replaceIdeEventQueueSafely();
final Throwable[] exception = {null};
UIUtil.invokeAndWaitIfNeeded(new Runnable() {
@Override