Skip to content
Snippets Groups Projects
Commit ee2dba57 authored by Andreas Bayha's avatar Andreas Bayha
Browse files

Merge remote-tracking branch 'origin/master' into 4191


Signed-off-by: default avatarAndreas Bayha <bayha@fortiss.org>
parents 54c55ec4 bd11cf2d
No related branches found
No related tags found
1 merge request!167Set getAllReferencesSetting to public for TaskReuseProvider
AllChainTransformationsFailedException.java 6ed750cd9e9f58ecaf479c928840f90134d91b7e GREEN
ChainTransformationFailedException.java a85fc087751bdf2c46d4ca0ff25e5369a18899a0 GREEN
TransformationFailedException.java b79fdca068089c973d8a06161dc3a3bbb6e0635e GREEN
/*-------------------------------------------------------------------------+
| Copyright 2021 fortiss GmbH |
| |
| Licensed under the Apache License, Version 2.0 (the "License"); |
| you may not use this file except in compliance with the License. |
| You may obtain a copy of the License at |
| |
| http://www.apache.org/licenses/LICENSE-2.0 |
| |
| Unless required by applicable law or agreed to in writing, software |
| distributed under the License is distributed on an "AS IS" BASIS, |
| WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| See the License for the specific language governing permissions and |
| limitations under the License. |
+--------------------------------------------------------------------------*/
package org.fortiss.tooling.kernel.extension.exception;
import java.util.List;
import org.eclipse.emf.ecore.EObject;
import org.fortiss.tooling.kernel.extension.data.ITransformationContext;
import org.fortiss.tooling.kernel.utils.TransformationUtils;
/**
* An exception thrown by
* {@link TransformationUtils#createTransformedObjectFor(EObject, Class, ITransformationContext)}
* if all chain transformations fail, keeping track of all exceptions thrown by each failed
* provider.
*
* @author muntean
*/
public class AllChainTransformationsFailedException extends ChainTransformationFailedException {
/** Number of tabs initially used when returning the exception's message. */
private final int INITIAL_TABS = 0;
/** Stores the {@link ChainTransformationFailedException}s thrown by each failed provider. */
private final List<ChainTransformationFailedException> exceptionList;
/** Constructor. */
public AllChainTransformationsFailedException(
List<ChainTransformationFailedException> exceptionList) {
super(null, null, null, null);
this.exceptionList = exceptionList;
}
/** {@inheritDoc} */
@Override
public String getMessage() {
return getMessage(INITIAL_TABS);
}
/**
* Recursive method iterating through the caught {@link TransformationFailedException}s
* backtracking to the source of the error by examining the cause of the exceptions.
*
* @param counter
* Number of tabs used in the current recursive step.
* @return Message expressing the failed provider + cause.
*/
private String getMessage(int counter) {
String msg = "";
String tabs = addTabs(counter);
for(TransformationFailedException ctfe : this.exceptionList) {
msg += tabs + "Failed Provider:\n";
msg += tabs + ctfe.getFailedProvider().getClass().getSimpleName() + "\n";
// Here, the cause is either a...
// ... ChainTransformationsFailedException or an
// ... AllChainTransformationsFailedException.
TransformationFailedException cause = (TransformationFailedException)ctfe.getCause();
if(cause != null) {
msg += tabs + "Cause:\n";
if(cause instanceof AllChainTransformationsFailedException)
msg += ((AllChainTransformationsFailedException)cause).getMessage(counter + 1) +
"\n";
else
msg += tabs + cause.getMessage() + "\n";
}
}
return msg;
}
/** Returns a string with as many tabs as specified by the parameter. */
private String addTabs(int counter) {
String msg = "";
for(int i = 0; i < counter; i++) {
msg += "\t";
}
return msg;
}
/** Returns the list {@link ChainTransformationFailedException}s. */
public List<ChainTransformationFailedException> getExceptionList() {
return exceptionList;
}
}
......@@ -11,5 +11,5 @@ KernelServiceBasedModelListenerBase.java 8d916509ae75f7118ce72564ee715c46556fb70
LoggingUtils.java 0e0aa5d466d80ea29cfc7e91178b23a5cdd4ddf7 GREEN
PrototypesUtils.java ec75bed75cfc5103f1f38e3a29df86f729428775 GREEN
ResourceUtils.java 1388e642ceeead4c8852e7ae39c6d57a362d4845 GREEN
TransformationUtils.java 552d3a9d56d34450be781af828efe0b8aa5d359e GREEN
TransformationUtils.java a060ec8a20c53a3c4996dd2628d194181e7d9ec3 GREEN
UniqueIDUtils.java 665955b1790c1bd1c2087e23114da920bfec2265 GREEN
......@@ -17,11 +17,13 @@ package org.fortiss.tooling.kernel.utils;
import static org.eclipse.core.runtime.Assert.isNotNull;
import java.util.ArrayList;
import java.util.List;
import org.eclipse.emf.ecore.EObject;
import org.fortiss.tooling.kernel.extension.data.ITransformationContext;
import org.fortiss.tooling.kernel.extension.data.TransformationProviderChain;
import org.fortiss.tooling.kernel.extension.exception.AllChainTransformationsFailedException;
import org.fortiss.tooling.kernel.extension.exception.ChainTransformationFailedException;
import org.fortiss.tooling.kernel.service.ITransformationService;
......@@ -52,6 +54,8 @@ public final class TransformationUtils {
throws ChainTransformationFailedException {
List<TransformationProviderChain> chainList = ITransformationService.getInstance()
.getTransformationProviderChain(sourceElement.getClass(), targetClass, context);
// Stores the ChainTransformationFailedExceptions thrown by each failed provider.
List<ChainTransformationFailedException> exceptionList = new ArrayList<>();
if(!chainList.isEmpty()) {
for(TransformationProviderChain chain : chainList) {
try {
......@@ -66,11 +70,14 @@ public final class TransformationUtils {
" ensure correct operation of all involved TransformationProviders.");
return executableObject;
} catch(ChainTransformationFailedException ctfe) {
// fall through
exceptionList.add(ctfe);
}
}
}
throw new NoTransformationChainFound(sourceElement, targetClass);
if(exceptionList.isEmpty())
throw new NoTransformationChainFound(sourceElement, targetClass);
throw new AllChainTransformationsFailedException(exceptionList);
}
/** Exception thrown when no transformation chain was found. */
......
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