mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
some DumbService utility methods to make it less painful to deal with unexpected dumbness
This commit is contained in:
@@ -1959,8 +1959,7 @@ public class CompileDriver {
|
||||
finally {
|
||||
CompilerUtil.refreshIOFiles(filesToRefresh);
|
||||
if (!generatedFiles.isEmpty()) {
|
||||
DumbService.getInstance(myProject).waitForSmartMode();
|
||||
List<VirtualFile> vFiles = ApplicationManager.getApplication().runReadAction(new Computable<List<VirtualFile>>() {
|
||||
List<VirtualFile> vFiles = DumbService.getInstance(myProject).runReadActionInSmartMode(new Computable<List<VirtualFile>>() {
|
||||
public List<VirtualFile> compute() {
|
||||
final ArrayList<VirtualFile> vFiles = new ArrayList<VirtualFile>(generatedFiles.size());
|
||||
for (File generatedFile : generatedFiles) {
|
||||
@@ -2162,8 +2161,7 @@ public class CompileDriver {
|
||||
final List<FileProcessingCompiler.ProcessingItem> toProcess = new ArrayList<FileProcessingCompiler.ProcessingItem>();
|
||||
final Set<String> allUrls = new HashSet<String>();
|
||||
final IOException[] ex = {null};
|
||||
DumbService.getInstance(myProject).waitForSmartMode();
|
||||
ApplicationManager.getApplication().runReadAction(new Runnable() {
|
||||
DumbService.getInstance(myProject).runReadActionInSmartMode(new Runnable() {
|
||||
public void run() {
|
||||
try {
|
||||
for (FileProcessingCompiler.ProcessingItem item : items) {
|
||||
|
||||
+1
-2
@@ -64,11 +64,10 @@ public class FileProcessingCompilerAdapterTask implements CompileTask{
|
||||
final List<FileProcessingCompiler.ProcessingItem> toProcess = new ArrayList<FileProcessingCompiler.ProcessingItem>();
|
||||
final Ref<IOException> ex = new Ref<IOException>(null);
|
||||
|
||||
DumbService.getInstance(project).waitForSmartMode();
|
||||
|
||||
final FileProcessingCompilerStateCache cache = CompilerCacheManager.getInstance(project).getFileProcessingCompilerCache(myCompiler);
|
||||
final boolean isMake = context.isMake();
|
||||
ApplicationManager.getApplication().runReadAction(new Runnable() {
|
||||
DumbService.getInstance(project).runReadActionInSmartMode(new Runnable() {
|
||||
public void run() {
|
||||
try {
|
||||
for (FileProcessingCompiler.ProcessingItem item : items) {
|
||||
|
||||
@@ -186,9 +186,8 @@ public class GenericCompilerRunner {
|
||||
final List<GenericCompilerProcessingItem<Item, SourceState, OutputState>> toProcess = new ArrayList<GenericCompilerProcessingItem<Item,SourceState,OutputState>>();
|
||||
final THashSet<Key> keySet = new THashSet<Key>(new SourceItemHashingStrategy<Key>(compiler));
|
||||
final Ref<IOException> exception = Ref.create(null);
|
||||
DumbService.getInstance(myProject).waitForSmartMode();
|
||||
final Map<Item, SourceState> sourceStates = new HashMap<Item,SourceState>();
|
||||
ApplicationManager.getApplication().runReadAction(new Runnable() {
|
||||
DumbService.getInstance(myProject).runReadActionInSmartMode(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
try {
|
||||
|
||||
+1
-4
@@ -24,7 +24,6 @@ import com.intellij.compiler.classParsing.FieldInfo;
|
||||
import com.intellij.compiler.impl.ExitException;
|
||||
import com.intellij.compiler.impl.ExitStatus;
|
||||
import com.intellij.lang.StdLanguages;
|
||||
import com.intellij.openapi.application.ApplicationManager;
|
||||
import com.intellij.openapi.compiler.CompileContext;
|
||||
import com.intellij.openapi.diagnostic.Logger;
|
||||
import com.intellij.openapi.progress.ProcessCanceledException;
|
||||
@@ -73,9 +72,7 @@ public class ChangedConstantsDependencyProcessor {
|
||||
public void run() throws CacheCorruptedException, ExitException {
|
||||
final Ref<CacheCorruptedException> _ex = new Ref<CacheCorruptedException>();
|
||||
final Ref<ExitException> exitException = new Ref<ExitException>(null);
|
||||
DumbService.getInstance(myProject).waitForSmartMode(); // ensure running in smart mode
|
||||
|
||||
ApplicationManager.getApplication().runReadAction(new Runnable() {
|
||||
DumbService.getInstance(myProject).runReadActionInSmartMode(new Runnable() {
|
||||
public void run() {
|
||||
try {
|
||||
final String qName = myDependencyCache.resolve(myQName);
|
||||
|
||||
+4
-4
@@ -151,12 +151,12 @@ public class ArtifactsCompilerInstance extends GenericCompilerInstance<ArtifactB
|
||||
return Collections.emptyList();
|
||||
}
|
||||
|
||||
DumbService.getInstance(getProject()).waitForSmartMode();
|
||||
new ReadAction() {
|
||||
protected void run(final Result result) {
|
||||
DumbService.getInstance(getProject()).runReadActionInSmartMode(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
collectItems(artifact, outputPath);
|
||||
}
|
||||
}.execute();
|
||||
});
|
||||
return new ArrayList<ArtifactCompilerCompileItem>(myBuilderContext.getProcessingItems());
|
||||
}
|
||||
|
||||
|
||||
@@ -19,7 +19,10 @@ import com.intellij.openapi.Disposable;
|
||||
import com.intellij.openapi.application.ApplicationManager;
|
||||
import com.intellij.openapi.application.ModalityState;
|
||||
import com.intellij.openapi.components.ServiceManager;
|
||||
import com.intellij.openapi.diagnostic.Logger;
|
||||
import com.intellij.openapi.util.Computable;
|
||||
import com.intellij.openapi.util.NotNullLazyKey;
|
||||
import com.intellij.openapi.util.Ref;
|
||||
import com.intellij.util.messages.Topic;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
@@ -39,6 +42,7 @@ import java.util.List;
|
||||
* @author peter
|
||||
*/
|
||||
public abstract class DumbService {
|
||||
private static final Logger LOG = Logger.getInstance("#com.intellij.openapi.project.DumbService");
|
||||
|
||||
/**
|
||||
* @see com.intellij.openapi.project.Project#getMessageBus()
|
||||
@@ -62,6 +66,47 @@ public abstract class DumbService {
|
||||
public abstract void runWhenSmart(Runnable runnable);
|
||||
|
||||
public abstract void waitForSmartMode();
|
||||
|
||||
public <T> T runReadActionInSmartMode(final Computable<T> r) {
|
||||
final Ref<T> result = new Ref<T>();
|
||||
runReadActionInSmartMode(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
result.set(r.compute());
|
||||
}
|
||||
});
|
||||
return result.get();
|
||||
}
|
||||
|
||||
public void runReadActionInSmartMode(final Runnable r) {
|
||||
while (true) {
|
||||
waitForSmartMode();
|
||||
boolean success = ApplicationManager.getApplication().runReadAction(new Computable<Boolean>() {
|
||||
@Override
|
||||
public Boolean compute() {
|
||||
if (isDumb()) {
|
||||
return false;
|
||||
}
|
||||
r.run();
|
||||
return true;
|
||||
}
|
||||
});
|
||||
if (success) break;
|
||||
}
|
||||
}
|
||||
|
||||
public void repeatUntilPassesInSmartMode(final Runnable r) {
|
||||
while (true) {
|
||||
waitForSmartMode();
|
||||
try {
|
||||
r.run();
|
||||
return;
|
||||
}
|
||||
catch (IndexNotReadyException e) {
|
||||
LOG.info(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Invoke the runnable later on EventDispatchThread AND when IDEA isn't in dumb mode
|
||||
|
||||
+1
-3
@@ -72,9 +72,7 @@ public abstract class AnnotationBasedInstrumentingCompiler implements ClassInstr
|
||||
final Set<InstrumentationItem> result = new HashSet<InstrumentationItem>();
|
||||
final PsiSearchHelper searchHelper = PsiSearchHelper.SERVICE.getInstance(context.getProject());
|
||||
|
||||
DumbService.getInstance(project).waitForSmartMode();
|
||||
|
||||
ApplicationManager.getApplication().runReadAction(new Runnable() {
|
||||
DumbService.getInstance(project).runReadActionInSmartMode(new Runnable() {
|
||||
public void run() {
|
||||
final String[] names = getAnnotationNames(project);
|
||||
for (String name : names) {
|
||||
|
||||
Reference in New Issue
Block a user