Skip to content
Snippets Groups Projects
Commit 83f54de5 authored by Alexander Diewald's avatar Alexander Diewald
Browse files

TransformationUtils: Simplify createTransformedObjectFor's logic

parent 21eb5699
No related branches found
No related tags found
1 merge request!463620
......@@ -11,5 +11,5 @@ KernelModelElementUtils.java 56c86fe9afb23053f50d7279809afd2a5bb10eba GREEN
LoggingUtils.java 0e0aa5d466d80ea29cfc7e91178b23a5cdd4ddf7 GREEN
PrototypesUtils.java ec75bed75cfc5103f1f38e3a29df86f729428775 GREEN
ResourceUtils.java 698c7db34acb4f1a258a1953e6afcca9823763a8 GREEN
TransformationUtils.java 495891fae79b99c103cf61f607792dd1e48a5307 GREEN
TransformationUtils.java 552d3a9d56d34450be781af828efe0b8aa5d359e YELLOW
UniqueIDUtils.java 665955b1790c1bd1c2087e23114da920bfec2265 GREEN
......@@ -15,6 +15,8 @@
+--------------------------------------------------------------------------*/
package org.fortiss.tooling.kernel.utils;
import static org.eclipse.core.runtime.Assert.isNotNull;
import java.util.List;
import org.eclipse.emf.ecore.EObject;
......@@ -45,31 +47,28 @@ public final class TransformationUtils {
* if no transformation chain could be found or none of the
* possible chains succeeded.
*/
@SuppressWarnings("unchecked")
public static <T extends Object> T createTransformedObjectFor(final EObject sourceElement,
final Class<T> targetClass, ITransformationContext context)
throws ChainTransformationFailedException {
List<TransformationProviderChain> chainList = ITransformationService.getInstance()
.getTransformationProviderChain(sourceElement.getClass(), targetClass, context);
ChainTransformationFailedException e = null;
if(!chainList.isEmpty()) {
Object executableObject = null;
for(TransformationProviderChain chain : chainList) {
try {
// For the moment, we use the first chain.
// For the moment, we use the first chain that successfully completes.
// Alternatives need an interpretation of the context, which
// we do not use at the moment.
executableObject = chain.transform(sourceElement, context);
e = null;
break;
@SuppressWarnings("unchecked") T executableObject =
(T)chain.transform(sourceElement, context);
isNotNull(executableObject, "The resulting object of the transformation" +
" of the object " + sourceElement + " to " +
targetClass.getSimpleName() + "is null, but did not fail. Please" +
" ensure correct operation of all involved TransformationProviders.");
return executableObject;
} catch(ChainTransformationFailedException ctfe) {
// fall through
e = ctfe;
}
}
if(e == null && executableObject != null) {
return (T)executableObject;
}
}
throw new NoTransformationChainFound(sourceElement, targetClass);
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment