Skip to content
Snippets Groups Projects
Commit cdac18a8 authored by Simon Barner's avatar Simon Barner
Browse files

- AnnotationUtils:

  - Add getAnnotation(IModelElement, Class<T> clazz, boolean)  variant that lets the caller control if the potential instantiation of an annotation should be wrapped into a command.
  - The original getAnnotation(IModelElement, Class<T> clazz) variant still exists and still defaults to wrapping the instantiation into a command
- AnalysisMigrationProvider / SafetySpecToAnnotationMigrationProvider: Use the new method to prevent the creation of a command in order to prevent the use of the IPersistencyService during the migration (workaround for the annotation-related aspect of #2010)
refs 2010,2172
parent cb3b5ac0
No related branches found
No related tags found
No related merge requests found
...@@ -86,15 +86,7 @@ public class AnnotationUtils { ...@@ -86,15 +86,7 @@ public class AnnotationUtils {
} }
final T newAnnotation = (T)EcoreUtil.create(eClass); final T newAnnotation = (T)EcoreUtil.create(eClass);
ITopLevelElement modelContext = modelElement.getSpecifications().add(newAnnotation);
IPersistencyService.INSTANCE.getTopLevelElementFor(modelElement);
modelContext.runAsCommand(new Runnable() {
@Override
public void run() {
modelElement.getSpecifications().add(newAnnotation);
}
});
return newAnnotation; return newAnnotation;
} }
...@@ -106,11 +98,37 @@ public class AnnotationUtils { ...@@ -106,11 +98,37 @@ public class AnnotationUtils {
*/ */
public static <T extends IAnnotatedSpecification> T getAnnotation(IModelElement modelElement, public static <T extends IAnnotatedSpecification> T getAnnotation(IModelElement modelElement,
Class<T> clazz) { Class<T> clazz) {
return getAnnotation(modelElement, clazz, false);
}
/**
* 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, Class<T> clazz, boolean wrapIntoCommand) {
EClass eClass = getEClassForClass(clazz); final EClass eClass = getEClassForClass(clazz);
if(eClass != null) { if(eClass != null) {
// Retrieve (potentially create) annotation if(wrapIntoCommand) {
ITopLevelElement modelContext =
IPersistencyService.INSTANCE.getTopLevelElementFor(modelElement);
modelContext.runAsCommand(new Runnable() {
@Override
public void run() {
// Create annotation (wrapped into command)
getAnnotation(modelElement, eClass);
}
});
}
// Retrieve annotation / create if the creation does not need to be wrapped into a
// command
return getAnnotation(modelElement, eClass); return getAnnotation(modelElement, eClass);
} }
......
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