mirror of
https://github.com/sigmasternchen/xtext-core
synced 2025-03-15 08:18:55 +00:00
Merge pull request #1438 from eclipse/cd_eclipse_issue1389
[eclipse/xtext-eclipse#1389] fixed exception handing (revert to old b…
This commit is contained in:
commit
72b943a021
2 changed files with 74 additions and 1 deletions
|
@ -0,0 +1,72 @@
|
|||
/*******************************************************************************
|
||||
* Copyright (c) 2020 itemis AG (http://www.itemis.eu) and others.
|
||||
* This program and the accompanying materials are made available under the
|
||||
* terms of the Eclipse Public License 2.0 which is available at
|
||||
* http://www.eclipse.org/legal/epl-2.0.
|
||||
*
|
||||
* SPDX-License-Identifier: EPL-2.0
|
||||
*******************************************************************************/
|
||||
package org.eclipse.xtext.resource;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
import org.eclipse.core.runtime.OperationCanceledException;
|
||||
import org.eclipse.emf.common.util.WrappedException;
|
||||
import org.eclipse.xtext.service.OperationCanceledError;
|
||||
import org.eclipse.xtext.testlanguages.ReferenceGrammarTestLanguageStandaloneSetup;
|
||||
import org.eclipse.xtext.tests.AbstractXtextTests;
|
||||
import org.junit.Test;
|
||||
|
||||
import com.google.inject.Inject;
|
||||
|
||||
/**
|
||||
* @author Christian Dietrich - Initial contribution and API
|
||||
*/
|
||||
public class OutdatedStateManagerTest extends AbstractXtextTests {
|
||||
|
||||
@Inject
|
||||
private OutdatedStateManager outdatedStateManager;
|
||||
private XtextResource resource;
|
||||
|
||||
@Override
|
||||
public void setUp() throws Exception {
|
||||
super.setUp();
|
||||
with(ReferenceGrammarTestLanguageStandaloneSetup.class);
|
||||
injectMembers(this);
|
||||
resource = getResourceFromString("");
|
||||
}
|
||||
|
||||
@Test(expected = OperationCanceledException.class)
|
||||
public void testCancellation() {
|
||||
outdatedStateManager.exec((r) -> {
|
||||
throw new OperationCanceledException();
|
||||
}, resource);
|
||||
}
|
||||
|
||||
@Test(expected = OperationCanceledError.class)
|
||||
public void testCancellation2() {
|
||||
outdatedStateManager.exec((r) -> {
|
||||
throw new OperationCanceledError(null);
|
||||
}, resource);
|
||||
}
|
||||
|
||||
@Test(expected = NullPointerException.class)
|
||||
public void testNPE() {
|
||||
outdatedStateManager.exec((r) -> {
|
||||
throw new NullPointerException();
|
||||
}, resource);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testChecked() {
|
||||
try {
|
||||
outdatedStateManager.exec((r) -> {
|
||||
throw new IOException();
|
||||
}, resource);
|
||||
fail("Exception Expected");
|
||||
} catch (WrappedException e) {
|
||||
Throwable cause = e.getCause();
|
||||
assertTrue("wrong cause", cause instanceof IOException);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -13,6 +13,7 @@ import org.eclipse.emf.ecore.resource.ResourceSet;
|
|||
import org.eclipse.xtext.service.OperationCanceledError;
|
||||
import org.eclipse.xtext.service.OperationCanceledManager;
|
||||
import org.eclipse.xtext.util.CancelIndicator;
|
||||
import org.eclipse.xtext.util.Exceptions;
|
||||
import org.eclipse.xtext.util.concurrent.CancelableUnitOfWork;
|
||||
import org.eclipse.xtext.util.concurrent.IUnitOfWork;
|
||||
|
||||
|
@ -68,7 +69,7 @@ public class OutdatedStateManager {
|
|||
}
|
||||
return work.exec(param);
|
||||
} catch (Throwable e) {
|
||||
throw new RuntimeException(e);
|
||||
return Exceptions.throwUncheckedException(e);
|
||||
} finally {
|
||||
cancelationAllowed.set(wasCancelationAllowed);
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue