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

Merge branch '4008' into 'master'

Test case generator for DSE problems

See merge request !117
parents c1f3be54 f0a18f2f
No related branches found
No related tags found
1 merge request!117Test case generator for DSE problems
AngleUtils.java 462551eae71738ff51f92c9906bff9a21a375d2b GREEN
AnnotationUtils.java 197ceb5f39af6b96eb8f7025e3fe3b1b39c35d42 GREEN
AnnotationUtils.java 357a9f40ee658d3ed60428e12ef35cad64f5cc53 GREEN
BaseMathUtils.java 90712a1560f5b4cb9b7873a148303c970ded756d GREEN
BaseModelElementUtils.java b8775b7a462efc168cf79a017aa3377a782d10f6 GREEN
DimensionUtils.java 0dc67f9de11a84e6e4c6e1eb627817dee91ff30a GREEN
......
......@@ -17,7 +17,6 @@ package org.fortiss.tooling.base.utils;
import static org.fortiss.tooling.base.utils.BaseMathUtils.convertNumber;
import static org.fortiss.tooling.kernel.utils.EcoreUtils.getChildrenWithType;
import static org.fortiss.tooling.kernel.utils.EcoreUtils.getEClassForClass;
import static org.fortiss.tooling.kernel.utils.EcoreUtils.getParentsWithType;
import static org.fortiss.tooling.kernel.utils.EcoreUtils.pickFirstInstanceOf;
import static org.fortiss.tooling.kernel.utils.EcoreUtils.pickInstanceOf;
......@@ -30,10 +29,8 @@ import java.util.stream.DoubleStream;
import org.eclipse.emf.common.util.BasicEList;
import org.eclipse.emf.common.util.EList;
import org.eclipse.emf.ecore.EClass;
import org.eclipse.emf.ecore.EClassifier;
import org.eclipse.emf.ecore.EObject;
import org.eclipse.emf.ecore.util.EcoreUtil;
import org.fortiss.tooling.base.ToolingBaseActivator;
import org.fortiss.tooling.base.annotation.AnnotationEntry;
import org.fortiss.tooling.base.annotation.AnnotationValueService;
......@@ -51,8 +48,6 @@ import org.fortiss.tooling.base.annotation.valueprovider.IAnnotationValueProvide
import org.fortiss.tooling.base.compose.HierarchicElementCompositorBase;
import org.fortiss.tooling.base.model.element.IAnnotatedSpecification;
import org.fortiss.tooling.base.model.element.IModelElement;
import org.fortiss.tooling.kernel.extension.data.ITopLevelElement;
import org.fortiss.tooling.kernel.service.IPersistencyService;
/**
* Utility methods for dealing with {@link IAnnotatedSpecification}s.
......@@ -60,31 +55,6 @@ import org.fortiss.tooling.kernel.service.IPersistencyService;
* @author diewald
*/
public class AnnotationUtils {
/**
* Returns the annotation of the particular {@code clazz} from a given {@code modelElement}.
*/
private static <T extends IAnnotatedSpecification> T
getAnnotationInternal(final IModelElement modelElement, Class<T> clazz) {
return pickFirstInstanceOf(clazz, modelElement.getSpecifications());
}
/**
* Creates an annotation of a particular {@code eClass} and adds it the specification list of
* the {@code modelElement}.
*/
@SuppressWarnings("unchecked")
private static <T extends IAnnotatedSpecification> void
createAnnotationInternal(final IModelElement modelElement, Class<T> clazz) {
final EClass eClass = getEClassForClass(clazz);
if(eClass == null) {
return;
}
final T newAnnotation = (T)EcoreUtil.create(eClass);
modelElement.getSpecifications().add(newAnnotation);
}
/**
* Returns the value of type {@code U} specified for the given {@link IModelElement} by the
......@@ -104,6 +74,18 @@ public class AnnotationUtils {
return value;
}
/**
* Sets the value of type {@code U} for the given annotation {@code clazz} in the specification
* list of the given {@link IModelElement}.
*/
public static <T extends IAnnotatedSpecification, U> void setAnnotationValue(
IModelElement modelElement, Class<T> clazz, U value) throws Exception {
IAnnotationValueProvider<T> annValProvider =
getAnnotationValueProvider(modelElement, clazz);
T annotation = getAnnotation(modelElement, clazz);
annValProvider.setAnnotationValue(value, annotation);
}
/**
* Predicate if for the given {@link IModelElement}, an annotation of the given {@code type} has
* been registered.
......@@ -114,59 +96,10 @@ public class AnnotationUtils {
return as.getAnnotationEntry(modelElement).getSpecification(type) != null;
}
/**
* <p>
* Returns the annotation of a given {@code Class<T>} from a given {@code modelElement}. If the
* annotation does not exist yet, it is created and added to the specification list of the
* {@code modelElement}.
* </p>
*
* <p>
* <b>Note: </b>The access to the model is wrapped into a command in order to allow for
* transparent creation of the annotation object from other contexts (e.g., GUI). If this is not
* desirable, use the {@link #getAnnotation(IModelElement, Class, boolean)} variant of this
* method.
* </p>
*/
public static <T extends IAnnotatedSpecification> T getAnnotation(IModelElement modelElement,
Class<T> clazz) {
return getAnnotation(modelElement, clazz, true);
}
/**
* Returns the annotation of a given {@code Class<T>} from a given {@code modelElement}. If the
* annotation does not exist yet, it is created and added to the specification list of the
* {@code modelElement}. Depending on the caller's choice, the model modification is wrapped
* into a command.
*/
public static <T extends IAnnotatedSpecification> T getAnnotation(
final IModelElement modelElement, final Class<T> clazz, boolean wrapIntoCommand) {
T annotation = getAnnotationInternal(modelElement, clazz);
if(annotation != null) {
return annotation;
}
if(wrapIntoCommand) {
ITopLevelElement modelContext =
IPersistencyService.getInstance().getTopLevelElementFor(modelElement);
modelContext.runAsCommand(() -> {
// TODO (see #2228 / #2208) Keep this code that ensures that non-existing
// annotations are lazily instantiated until #2228 is resolved. It should be
// noted that each time an annotation is constructed from this context, an
// undo/redo command will be created that is not comprehensible for the user
// (see #2208).
createAnnotationInternal(modelElement, clazz);
});
} else {
// Create if the creation does not need to be wrapped into a command.
createAnnotationInternal(modelElement, clazz);
}
// Return new annotation (be it created in a command, or directly). This will return null in
// case the creation of the new annotation was not successful.
return getAnnotationInternal(modelElement, clazz);
/** Returns the annotation of a given {@code Class<T>} from a given {@code modelElement}. */
public static <T extends IAnnotatedSpecification> T
getAnnotation(final IModelElement modelElement, final Class<T> clazz) {
return pickFirstInstanceOf(clazz, modelElement.getSpecifications());
}
/**
......@@ -317,7 +250,6 @@ public class AnnotationUtils {
as.instantiateAnnotations(child);
}
}
/**
* Compact method to determine whether an {@link IModelElement} requires its annotations to be
* instantiated.
......
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