Skip to content

Commit

Permalink
137: EdeltaInterpreterRuntimeException file
Browse files Browse the repository at this point in the history
  • Loading branch information
LorenzoBettini committed Apr 19, 2020
1 parent 917969a commit e355573
Show file tree
Hide file tree
Showing 13 changed files with 45 additions and 41 deletions.
Expand Up @@ -4,7 +4,7 @@ import com.google.inject.Inject
import edelta.edelta.EdeltaEcoreQualifiedReference
import edelta.edelta.EdeltaEcoreReferenceExpression
import edelta.edelta.EdeltaProgram
import edelta.interpreter.EdeltaSafeInterpreter.EdeltaInterpreterRuntimeException
import edelta.interpreter.EdeltaInterpreterRuntimeException
import edelta.resource.EdeltaDerivedStateComputer.EdeltaDerivedStateAdapter
import edelta.tests.additional.TestableEdeltaDerivedStateComputer
import org.eclipse.emf.common.notify.impl.AdapterImpl
Expand Down
Expand Up @@ -2,7 +2,7 @@ package edelta.tests

import com.google.inject.Inject
import edelta.interpreter.EdeltaInterpreterHelper
import edelta.interpreter.EdeltaSafeInterpreter
import edelta.interpreter.EdeltaInterpreterRuntimeException
import edelta.lib.AbstractEdelta
import edelta.tests.additional.MyCustomEdelta
import edelta.tests.additional.MyCustomEdeltaThatCannotBeLoadedAtRuntime
Expand Down Expand Up @@ -106,7 +106,7 @@ class EdeltaInterpreterHelperTest extends EdeltaAbstractTest {
'''.parse.useAsClauses.head => [
interpreterHelper.safeInstantiate(javaReflectAccess, it, other).class
]
].isInstanceOf(EdeltaSafeInterpreter.EdeltaInterpreterRuntimeException)
].isInstanceOf(EdeltaInterpreterRuntimeException)
.hasMessageContaining('''The type '«MyCustomEdeltaThatCannotBeLoadedAtRuntime.name»' has been resolved but cannot be loaded by the interpreter''')
}
}
Expand Up @@ -6,7 +6,7 @@ import edelta.edelta.EdeltaPackage
import edelta.edelta.EdeltaProgram
import edelta.interpreter.EdeltaInterpreter
import edelta.interpreter.EdeltaInterpreter.EdeltaInterpreterWrapperException
import edelta.interpreter.EdeltaSafeInterpreter
import edelta.interpreter.EdeltaInterpreterRuntimeException
import edelta.interpreter.IEdeltaInterpreter
import edelta.tests.additional.MyCustomEdeltaThatCannotBeLoadedAtRuntime
import edelta.tests.additional.MyCustomException
Expand Down Expand Up @@ -146,7 +146,7 @@ class EdeltaInterpreterTest extends EdeltaAbstractTest {
my.aMethod()
}
'''.assertAfterInterpretationOfEdeltaModifyEcoreOperation(false) [ /* will not get here */ ]
].isInstanceOf(EdeltaSafeInterpreter.EdeltaInterpreterRuntimeException)
].isInstanceOf(EdeltaInterpreterRuntimeException)
.hasMessageContaining('''The type '«MyCustomEdeltaThatCannotBeLoadedAtRuntime.name»' has been resolved but cannot be loaded by the interpreter''')
}

Expand Down
Expand Up @@ -2,14 +2,14 @@ package edelta.tests

import com.google.inject.Inject
import com.google.inject.Injector
import edelta.interpreter.EdeltaInterpreterRuntimeException
import edelta.interpreter.EdeltaSafeInterpreter
import org.eclipse.xtext.testing.InjectWith
import org.eclipse.xtext.testing.XtextRunner
import org.junit.Test
import org.junit.runner.RunWith

import static org.junit.Assert.*
import edelta.interpreter.EdeltaSafeInterpreter.EdeltaInterpreterRuntimeException

@RunWith(XtextRunner)
@InjectWith(EdeltaInjectorProviderDerivedStateComputerWithoutInterpreter)
Expand Down Expand Up @@ -60,7 +60,7 @@ class EdeltaSafeInterpreterTest extends EdeltaInterpreterTest {
def void testEdeltaInterpreterRuntimeExceptionIsThrown() {
'''
import org.eclipse.emf.ecore.EClass
import edelta.interpreter.EdeltaSafeInterpreter.EdeltaInterpreterRuntimeException
import edelta.interpreter.EdeltaInterpreterRuntimeException
metamodel "foo"
Expand Down
Expand Up @@ -6,7 +6,7 @@
import org.eclipse.emf.common.notify.Notification;
import org.eclipse.emf.ecore.util.EContentAdapter;

import edelta.interpreter.EdeltaSafeInterpreter.EdeltaInterpreterRuntimeException;
import edelta.interpreter.EdeltaInterpreterRuntimeException;

/**
* Used in tests to make sure that the original imported Ecore models are not
Expand Down
Expand Up @@ -5,7 +5,7 @@
import edelta.edelta.EdeltaEcoreQualifiedReference;
import edelta.edelta.EdeltaEcoreReferenceExpression;
import edelta.edelta.EdeltaProgram;
import edelta.interpreter.EdeltaSafeInterpreter;
import edelta.interpreter.EdeltaInterpreterRuntimeException;
import edelta.resource.EdeltaDerivedStateComputer;
import edelta.tests.EdeltaAbstractTest;
import edelta.tests.EdeltaInjectorProviderTestableDerivedStateComputer;
Expand Down Expand Up @@ -424,7 +424,7 @@ public void testContentAdapter() {
EClassifier _head = IterableExtensions.<EClassifier>head(IterableExtensions.<EPackage>head(program.getMetamodels()).getEClassifiers());
_head.setName("bar");
};
Assertions.assertThatThrownBy(_function).isInstanceOf(EdeltaSafeInterpreter.EdeltaInterpreterRuntimeException.class).hasMessageContaining("Unexpected notification");
Assertions.assertThatThrownBy(_function).isInstanceOf(EdeltaInterpreterRuntimeException.class).hasMessageContaining("Unexpected notification");
}

@Test
Expand Down
Expand Up @@ -3,7 +3,7 @@
import com.google.inject.Inject;
import edelta.edelta.EdeltaUseAs;
import edelta.interpreter.EdeltaInterpreterHelper;
import edelta.interpreter.EdeltaSafeInterpreter;
import edelta.interpreter.EdeltaInterpreterRuntimeException;
import edelta.lib.AbstractEdelta;
import edelta.tests.EdeltaAbstractTest;
import edelta.tests.EdeltaInjectorProviderForJavaReflectAccess;
Expand Down Expand Up @@ -142,7 +142,7 @@ public void testSafeInstantiateOfValidUseAsButNotFoundAtRuntime() {
};
ObjectExtensions.<EdeltaUseAs>operator_doubleArrow(_head, _function_1);
};
AbstractThrowableAssert<?, ? extends Throwable> _isInstanceOf = Assertions.assertThatThrownBy(_function).isInstanceOf(EdeltaSafeInterpreter.EdeltaInterpreterRuntimeException.class);
AbstractThrowableAssert<?, ? extends Throwable> _isInstanceOf = Assertions.assertThatThrownBy(_function).isInstanceOf(EdeltaInterpreterRuntimeException.class);
StringConcatenation _builder = new StringConcatenation();
_builder.append("The type \'");
String _name = MyCustomEdeltaThatCannotBeLoadedAtRuntime.class.getName();
Expand Down
Expand Up @@ -6,7 +6,7 @@
import edelta.edelta.EdeltaPackage;
import edelta.edelta.EdeltaProgram;
import edelta.interpreter.EdeltaInterpreter;
import edelta.interpreter.EdeltaSafeInterpreter;
import edelta.interpreter.EdeltaInterpreterRuntimeException;
import edelta.interpreter.IEdeltaInterpreter;
import edelta.tests.EdeltaAbstractTest;
import edelta.tests.EdeltaInjectorProviderDerivedStateComputerWithoutInterpreter;
Expand Down Expand Up @@ -212,7 +212,7 @@ public void testCreateEClassAndCallOperationFromUseAsButNotFoundAtRuntime() {
};
this.assertAfterInterpretationOfEdeltaModifyEcoreOperation(_builder, false, _function_1);
};
AbstractThrowableAssert<?, ? extends Throwable> _isInstanceOf = Assertions.assertThatThrownBy(_function).isInstanceOf(EdeltaSafeInterpreter.EdeltaInterpreterRuntimeException.class);
AbstractThrowableAssert<?, ? extends Throwable> _isInstanceOf = Assertions.assertThatThrownBy(_function).isInstanceOf(EdeltaInterpreterRuntimeException.class);
StringConcatenation _builder = new StringConcatenation();
_builder.append("The type \'");
String _name = MyCustomEdeltaThatCannotBeLoadedAtRuntime.class.getName();
Expand Down
Expand Up @@ -2,6 +2,7 @@

import com.google.inject.Inject;
import com.google.inject.Injector;
import edelta.interpreter.EdeltaInterpreterRuntimeException;
import edelta.interpreter.EdeltaSafeInterpreter;
import edelta.interpreter.IEdeltaInterpreter;
import edelta.tests.EdeltaInjectorProviderDerivedStateComputerWithoutInterpreter;
Expand Down Expand Up @@ -83,12 +84,12 @@ public void testCreateEClassAndCallOperationFromUseAsReferringToUnknownType() {
this.assertAfterInterpretationOfEdeltaModifyEcoreOperation(_builder, false, _function);
}

@Test(expected = EdeltaSafeInterpreter.EdeltaInterpreterRuntimeException.class)
@Test(expected = EdeltaInterpreterRuntimeException.class)
public void testEdeltaInterpreterRuntimeExceptionIsThrown() {
StringConcatenation _builder = new StringConcatenation();
_builder.append("import org.eclipse.emf.ecore.EClass");
_builder.newLine();
_builder.append("import edelta.interpreter.EdeltaSafeInterpreter.EdeltaInterpreterRuntimeException");
_builder.append("import edelta.interpreter.EdeltaInterpreterRuntimeException");
_builder.newLine();
_builder.newLine();
_builder.append("metamodel \"foo\"");
Expand Down
Expand Up @@ -149,17 +149,20 @@ private void evaluateModifyEcoreOperation(final EdeltaModifyEcoreOperation op,
if (result == null) {
addTimeoutWarning(op);
} else {
Throwable resultException = result.getException();
if (resultException != null) {
throw new EdeltaInterpreterWrapperException
((Exception) resultException);
}
handleResultException(result.getException());
}
} finally {
ePackage.eAdapters().remove(cacheCleaner);
}
}

private void handleResultException(Throwable resultException) {
if (resultException != null) {
throw new EdeltaInterpreterWrapperException
((Exception) resultException);
}
}

private boolean addTimeoutWarning(final EdeltaModifyEcoreOperation op) {
return op.eResource().getWarnings().add(
new EObjectDiagnosticImpl(Severity.WARNING,
Expand Down
Expand Up @@ -11,7 +11,6 @@
import com.google.inject.Singleton;

import edelta.edelta.EdeltaUseAs;
import edelta.interpreter.EdeltaSafeInterpreter.EdeltaInterpreterRuntimeException;
import edelta.lib.AbstractEdelta;

/**
Expand Down
@@ -0,0 +1,20 @@
package edelta.interpreter;

/**
* Subclasses of this exception will always be rethrown by the safe interpreter.
*
* @author Lorenzo Bettini
*
*/
public class EdeltaInterpreterRuntimeException extends RuntimeException {

private static final long serialVersionUID = 1L;

/**
* @param message
*/
public EdeltaInterpreterRuntimeException(String message) {
super(message);
}

}
Expand Up @@ -19,25 +19,6 @@ public class EdeltaSafeInterpreter extends EdeltaInterpreter {

private static final Logger LOG = Logger.getLogger(EdeltaSafeInterpreter.class);

/**
* Subclasses of this exception will always be rethrown by the safe interpreter.
*
* @author Lorenzo Bettini
*
*/
public static class EdeltaInterpreterRuntimeException extends RuntimeException {

private static final long serialVersionUID = 1L;

/**
* @param message
*/
public EdeltaInterpreterRuntimeException(String message) {
super(message);
}

}

@Override
@SuppressWarnings("all") // avoid warning for nested try block
public void evaluateModifyEcoreOperations(EdeltaProgram program,
Expand Down

0 comments on commit e355573

Please sign in to comment.