本文整理汇总了Java中com.intellij.openapi.util.ThrowableComputable类的典型用法代码示例。如果您正苦于以下问题:Java ThrowableComputable类的具体用法?Java ThrowableComputable怎么用?Java ThrowableComputable使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
ThrowableComputable类属于com.intellij.openapi.util包,在下文中一共展示了ThrowableComputable类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: VcsLogHashMapImpl
import com.intellij.openapi.util.ThrowableComputable; //导入依赖的package包/类
public VcsLogHashMapImpl(@NotNull Project project, @NotNull Map<VirtualFile, VcsLogProvider> logProviders) throws IOException {
cleanupOldNaming(project, logProviders);
String logId = calcLogId(project, logProviders);
final File mapFile = new File(LOG_CACHE_APP_DIR, logId + "." + VERSION);
if (!mapFile.exists()) {
IOUtil.deleteAllFilesStartingWith(new File(LOG_CACHE_APP_DIR, logId));
}
Disposer.register(project, this);
myPersistentEnumerator = IOUtil.openCleanOrResetBroken(new ThrowableComputable<PersistentEnumerator<Hash>, IOException>() {
@Override
public PersistentEnumerator<Hash> compute() throws IOException {
return new PersistentEnumerator<Hash>(mapFile, new MyHashKeyDescriptor(), Page.PAGE_SIZE);
}
}, mapFile);
}
示例2: doActionAndRestoreEncoding
import com.intellij.openapi.util.ThrowableComputable; //导入依赖的package包/类
public static <E extends Throwable> VirtualFile doActionAndRestoreEncoding(@NotNull VirtualFile fileBefore,
@NotNull ThrowableComputable<VirtualFile, E> action) throws E {
EncodingRegistry registry = getInstance();
Charset charsetBefore = registry.getEncoding(fileBefore, true);
VirtualFile fileAfter = null;
try {
fileAfter = action.compute();
return fileAfter;
}
finally {
if (fileAfter != null) {
Charset actual = registry.getEncoding(fileAfter, true);
if (!Comparing.equal(actual, charsetBefore)) {
registry.setEncoding(fileAfter, charsetBefore);
}
}
}
}
示例3: runTest
import com.intellij.openapi.util.ThrowableComputable; //导入依赖的package包/类
@Override
protected void runTest() throws Throwable {
if (isRunInWriteAction()) {
WriteCommandAction.runWriteCommandAction(getProject(), new ThrowableComputable<Void, Throwable>() {
@Override
public Void compute() throws Throwable {
doRunTest();
return null;
}
});
}
else {
new WriteCommandAction.Simple(getProject()){
@Override
protected void run() throws Throwable {
doRunTest();
}
}.performCommand();
}
}
示例4: copy
import com.intellij.openapi.util.ThrowableComputable; //导入依赖的package包/类
@Override
public VirtualFile copy(final Object requestor, @NotNull final VirtualFile newParent, @NotNull final String copyName) throws IOException {
if (getFileSystem() != newParent.getFileSystem()) {
throw new IOException(VfsBundle.message("file.copy.error", newParent.getPresentableUrl()));
}
if (!newParent.isDirectory()) {
throw new IOException(VfsBundle.message("file.copy.target.must.be.directory"));
}
return EncodingRegistry.doActionAndRestoreEncoding(this, new ThrowableComputable<VirtualFile, IOException>() {
@Override
public VirtualFile compute() throws IOException {
return ourPersistence.copyFile(requestor, VirtualFileSystemEntry.this, newParent, copyName);
}
});
}
示例5: testProgressVsReadAction
import com.intellij.openapi.util.ThrowableComputable; //导入依赖的package包/类
public void testProgressVsReadAction() throws Throwable {
ProgressManager.getInstance().runProcessWithProgressSynchronously((ThrowableComputable<Void, Exception>)() -> {
try {
assertFalse(ApplicationManager.getApplication().isReadAccessAllowed());
assertFalse(ApplicationManager.getApplication().isDispatchThread());
for (int i=0; i<100;i++) {
SwingUtilities.invokeLater(() -> ApplicationManager.getApplication().runWriteAction(() -> {
TimeoutUtil.sleep(20);
}));
ApplicationManager.getApplication().runReadAction(() -> {
TimeoutUtil.sleep(20);
});
}
}
catch (Exception e) {
exception = e;
}
return null;
}, "cc", false, getProject());
if (exception != null) throw exception;
}
示例6: commitModule
import com.intellij.openapi.util.ThrowableComputable; //导入依赖的package包/类
@Nullable
public Module commitModule(@NotNull final Project project, @Nullable final ModifiableModuleModel model) {
if (canCreateModule()) {
if (myName == null) {
myName = project.getName();
}
if (myModuleFilePath == null) {
myModuleFilePath = project.getBaseDir().getPath() + File.separator + myName + ModuleFileType.DOT_DEFAULT_EXTENSION;
}
try {
return ApplicationManager.getApplication().runWriteAction(new ThrowableComputable<Module, Exception>() {
@Override
public Module compute() throws Exception {
return createAndCommitIfNeeded(project, model, true);
}
});
}
catch (Exception ex) {
LOG.warn(ex);
Messages.showErrorDialog(IdeBundle.message("error.adding.module.to.project", ex.getMessage()), IdeBundle.message("title.add.module"));
}
}
return null;
}
示例7: loadMessagesInModalTask
import com.intellij.openapi.util.ThrowableComputable; //导入依赖的package包/类
private void loadMessagesInModalTask(@NotNull Project project) {
try {
myMessagesForRoots =
ProgressManager.getInstance().runProcessWithProgressSynchronously(new ThrowableComputable<Map<VirtualFile,String>, VcsException>() {
@Override
public Map<VirtualFile, String> compute() throws VcsException {
return getLastCommitMessages();
}
}, "Reading commit message...", false, project);
}
catch (VcsException e) {
Messages.showErrorDialog(getComponent(), "Couldn't load commit message of the commit to amend.\n" + e.getMessage(),
"Commit Message not Loaded");
log.info(e);
}
}
示例8: test
import com.intellij.openapi.util.ThrowableComputable; //导入依赖的package包/类
private void test() {
myTestURL = getCurrentUrlText();
boolean testResult = ProgressManager.getInstance().runProcessWithProgressSynchronously(new ThrowableComputable<Boolean, RuntimeException>() {
@Override
public Boolean compute() {
return test(myTestURL);
}
}, DvcsBundle.message("clone.testing", myTestURL), true, myProject);
if (testResult) {
Messages.showInfoMessage(myTestButton, DvcsBundle.message("clone.test.success.message", myTestURL),
DvcsBundle.getString("clone.test.connection.title"));
myTestResult = Boolean.TRUE;
}
else {
myTestResult = Boolean.FALSE;
}
updateButtons();
}
示例9: VcsBackgroundableComputable
import com.intellij.openapi.util.ThrowableComputable; //导入依赖的package包/类
private VcsBackgroundableComputable(final Project project, final String title,
final String errorTitle,
final ThrowableComputable<T, VcsException> backgroundable,
final Consumer<T> awtSuccessContinuation,
final Runnable awtErrorContinuation,
final BackgroundableActionEnabledHandler handler,
final Object actionParameter) {
super(project, title, true, BackgroundFromStartOption.getInstance());
myErrorTitle = errorTitle;
myBackgroundable = backgroundable;
myAwtSuccessContinuation = awtSuccessContinuation;
myAwtErrorContinuation = awtErrorContinuation;
myProject = project;
myHandler = handler;
myActionParameter = actionParameter;
}
示例10: createAndRun
import com.intellij.openapi.util.ThrowableComputable; //导入依赖的package包/类
private static <T> void createAndRun(final Project project, @Nullable final VcsBackgroundableActions actionKey,
@Nullable final Object actionParameter,
final String title,
final String errorTitle,
final ThrowableComputable<T, VcsException> backgroundable,
@Nullable final Consumer<T> awtSuccessContinuation,
@Nullable final Runnable awtErrorContinuation, final boolean silent) {
final ProjectLevelVcsManagerImpl vcsManager = (ProjectLevelVcsManagerImpl) ProjectLevelVcsManager.getInstance(project);
final BackgroundableActionEnabledHandler handler;
if (actionKey != null) {
handler = vcsManager.getBackgroundableActionHandler(actionKey);
// fo not start same action twice
if (handler.isInProgress(actionParameter)) return;
} else {
handler = null;
}
final VcsBackgroundableComputable<T> backgroundableComputable =
new VcsBackgroundableComputable<T>(project, title, errorTitle, backgroundable, awtSuccessContinuation, awtErrorContinuation,
handler, actionParameter);
backgroundableComputable.setSilent(silent);
if (handler != null) {
handler.register(actionParameter);
}
ProgressManager.getInstance().run(backgroundableComputable);
}
示例11: VcsHistoryProviderBackgroundableProxy
import com.intellij.openapi.util.ThrowableComputable; //导入依赖的package包/类
public VcsHistoryProviderBackgroundableProxy(final AbstractVcs vcs, final VcsHistoryProvider delegate, DiffProvider diffProvider) {
myDelegate = delegate;
myProject = vcs.getProject();
myConfiguration = VcsConfiguration.getInstance(myProject);
myCachesHistory = myDelegate instanceof VcsCacheableHistorySessionFactory;
myDiffProvider = diffProvider;
myVcsHistoryCache = ProjectLevelVcsManager.getInstance(myProject).getVcsHistoryCache();
myType = vcs.getType();
myHistoryComputerFactory = new HistoryComputerFactory() {
@Override
public ThrowableComputable<VcsHistorySession, VcsException> create(FilePath filePath,
Consumer<VcsHistorySession> consumer,
VcsKey vcsKey) {
if (myCachesHistory) {
return new CachingHistoryComputer(filePath, consumer, vcsKey);
} else {
return new SimpelHistoryComputer(filePath, consumer);
}
}
};
}
示例12: createSessionFor
import com.intellij.openapi.util.ThrowableComputable; //导入依赖的package包/类
public void createSessionFor(final VcsKey vcsKey, final FilePath filePath, final Consumer<VcsHistorySession> continuation,
@Nullable VcsBackgroundableActions actionKey,
final boolean silent,
@Nullable final Consumer<VcsHistorySession> backgroundSpecialization) {
final ThrowableComputable<VcsHistorySession, VcsException> throwableComputable =
myHistoryComputerFactory.create(filePath, backgroundSpecialization, vcsKey);
final VcsBackgroundableActions resultingActionKey = actionKey == null ? VcsBackgroundableActions.CREATE_HISTORY_SESSION : actionKey;
final Object key = VcsBackgroundableActions.keyFrom(filePath);
if (silent) {
VcsBackgroundableComputable.createAndRunSilent(myProject, resultingActionKey, key, VcsBundle.message("loading.file.history.progress"),
throwableComputable, continuation);
} else {
VcsBackgroundableComputable.createAndRun(myProject, resultingActionKey, key, VcsBundle.message("loading.file.history.progress"),
VcsBundle.message("message.title.could.not.load.file.history"), throwableComputable, continuation, null);
}
}
示例13: acquire
import com.intellij.openapi.util.ThrowableComputable; //导入依赖的package包/类
private EntryPoint acquire(final RunningInfo port) throws Exception {
EntryPoint result = RemoteUtil.executeWithClassLoader(new ThrowableComputable<EntryPoint, Exception>() {
@Override
public EntryPoint compute() throws Exception {
Registry registry = LocateRegistry.getRegistry("localhost", port.port);
Remote remote = ObjectUtils.assertNotNull(registry.lookup(port.name));
if (Remote.class.isAssignableFrom(myValueClass)) {
EntryPoint entryPoint = narrowImpl(remote, myValueClass);
if (entryPoint == null) return null;
return RemoteUtil.substituteClassLoader(entryPoint, myValueClass.getClassLoader());
}
else {
return RemoteUtil.castToLocal(remote, myValueClass);
}
}
}, getClass().getClassLoader()); // should be the loader of client plugin
// init hard ref that will keep it from DGC and thus preventing from System.exit
port.entryPointHardRef = result;
return result;
}
示例14: getComputable
import com.intellij.openapi.util.ThrowableComputable; //导入依赖的package包/类
@NotNull
private static ThrowableComputable<PersistentHashMap<String, Record>, IOException> getComputable(final File file) {
return new ThrowableComputable<PersistentHashMap<String, Record>, IOException>() {
@Override
public PersistentHashMap<String, Record> compute() throws IOException {
return new PersistentHashMap<String, Record>(file, new EnumeratorStringDescriptor(), new DataExternalizer<Record>() {
@Override
public void save(@NotNull DataOutput out, Record value) throws IOException {
out.writeInt(value.magnitude);
out.writeLong(value.date.getTime());
}
@Override
public Record read(@NotNull DataInput in) throws IOException {
return new Record(in.readInt(), new Date(in.readLong()));
}
});
}
};
}
示例15: checkedCreateDirectoryIfMissing
import com.intellij.openapi.util.ThrowableComputable; //导入依赖的package包/类
/**
* Creates a directory for the given file and returns the VirtualFile object.
*
* @return virtual file object for the given path. It can never be null.
*/
@NotNull
public static VirtualFile checkedCreateDirectoryIfMissing(final @NotNull File directory) throws IOException {
return WriteCommandAction.runWriteCommandAction(null, new ThrowableComputable<VirtualFile, IOException>() {
@Override
public VirtualFile compute() throws IOException {
VirtualFile dir = VfsUtil.createDirectoryIfMissing(directory.getAbsolutePath());
if (dir == null) {
throw new IOException("Unable to create " + directory.getAbsolutePath());
}
else {
return dir;
}
}
});
}