Commit 6829438f authored by Alexander Diewald's avatar Alexander Diewald

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

parents a0c8df3a 270f598a
AnnotationEntry.java 928240a722fb5177da232619266c0d0dadcfa151 GREEN
AnnotationValueService.java 19906a1c7a2a33897651a0d7e207c4e5a285d2ff GREEN
IAnnotationValueService.java 50cea844f4b4ff3308ec1286ba8aadf253d2f3b1 GREEN
AnnotationValueService.java 01fc46fb381854b16ce78779217ffc7c29036c14 GREEN
IAnnotationValueService.java 81ff274a7b2d4c58e7b8485db857eb83f99710d0 GREEN
......@@ -156,8 +156,10 @@ public class AnnotationValueService
* Prepares the {@link AnnotationEntry} for a given {@link IModelElement} and ensures that all
* {@link IAnnotatedSpecification}s are instantiated.
*/
private void prepareAnnotationEntry(final IModelElement element, AnnotationEntry entry,
final List<IAnnotationValueProvider<IAnnotatedSpecification>> registeredHandlers) {
private void prepareAnnotationEntry(final IModelElement element, AnnotationEntry entry) {
final List<IAnnotationValueProvider<IAnnotatedSpecification>> registeredHandlers =
getRegisteredHandlers(element.getClass());
for(IAnnotationValueProvider<IAnnotatedSpecification> annotationProvider : registeredHandlers) {
IAnnotatedSpecification annotatedSpecification = EcoreUtils.pickFirstInstanceOf(
......@@ -214,14 +216,16 @@ public class AnnotationValueService
getAnnotationEntry(element, false);
}
/**
* Predicate if for the given {@link IModelElement}, {@link #getAnnotationEntry(IModelElement)}
* will actually instantiate an annotation, i.e. modify the model.
*/
private boolean requiresAnnotationInstantiation(final IModelElement element,
final List<IAnnotationValueProvider<IAnnotatedSpecification>> registeredHandlers) {
for(IAnnotationValueProvider<IAnnotatedSpecification> annotationProvider : registeredHandlers) {
/** {@inheritDoc} */
@Override
public boolean requiresAnnotationInstantiation(final IModelElement element) {
final List<IAnnotationValueProvider<IAnnotatedSpecification>> registeredHandlers =
getRegisteredHandlers(element.getClass());
if(registeredHandlers == null) {
return false;
}
for(IAnnotationValueProvider<IAnnotatedSpecification> annotationProvider : registeredHandlers) {
IAnnotatedSpecification annotatedSpecification = pickFirstInstanceOf(
annotationProvider.getAnnotationClazz(), element.getSpecifications());
......@@ -252,30 +256,24 @@ public class AnnotationValueService
return null;
}
final List<IAnnotationValueProvider<IAnnotatedSpecification>> registeredHandlers =
getRegisteredHandlers(element.getClass());
final AnnotationEntry result = new AnnotationEntry(element);
if(registeredHandlers != null && !registeredHandlers.isEmpty()) {
final ITopLevelElement modelContext =
IPersistencyService.getInstance().getTopLevelElementFor(element);
// Wrap instantiation of new annotation into command if this method is invoked from the
// GUI context, i.e. from getAnnotationEntry(final IModelElement element), but only if
// prepareAnnotationEntry() would actually modify the underlying model, and a model
// context is available.
if(requiresAnnotationInstantiation(element, registeredHandlers) &&
modelContext != null) {
modelContext.runAsCommand(new Runnable() {
@Override
public void run() {
prepareAnnotationEntry(element, result, registeredHandlers);
}
});
} else {
prepareAnnotationEntry(element, result, registeredHandlers);
}
// Wrap instantiation of new annotation into command if this method is invoked from the
// GUI context, i.e. from getAnnotationEntry(final IModelElement element), but only if
// prepareAnnotationEntry() would actually modify the underlying model, and a model
// context is available.
final ITopLevelElement modelContext =
IPersistencyService.getInstance().getTopLevelElementFor(element);
if(requiresAnnotationInstantiation(element) && modelContext != null) {
modelContext.runAsCommand(new Runnable() {
@Override
public void run() {
prepareAnnotationEntry(element, result);
}
});
} else {
prepareAnnotationEntry(element, result);
}
// Only put element into AnnotationEntry <-> IModelElement cache if method is invoked from
......
......@@ -58,4 +58,12 @@ public interface IAnnotationValueService {
* </p>
*/
void instantiateAnnotations(IModelElement element);
/**
* Predicate if the given {@link IModelElement} is missing some of the {@link AnnotationEntry}s
* corresponding to the {@link IAnnotatedSpecification}s declared for its type.
* Calling {@link #getAnnotationEntry(IModelElement)} will actually instantiate an annotation,
* i.e. modify the model.
*/
boolean requiresAnnotationInstantiation(final IModelElement element);
}
AddMissingAnnotationsMigrationProvider.java ebc5b9348b61ffb23493942949ecccf1c1fa2ae1 GREEN
AddMissingAnnotationsMigrationProvider.java 283f11372ce778a26362d0c83dcffdea3290b4df GREEN
RemoveDuplicatedAnnotationsMigrationProvider.java 6920909f8f211b9c5b5990644b5abcd8c4abaa3a GREEN
RemoveOutdatedAnnotationInstanceMigrationProvider.java 245530d6026f9ff29ffc577983d9de03ae5e75e5 GREEN
......@@ -17,10 +17,13 @@ package org.fortiss.tooling.base.migration;
import static java.util.Collections.emptyMap;
import static org.fortiss.tooling.base.utils.AnnotationUtils.instantiateAnnotationsRecursive;
import static org.fortiss.tooling.base.utils.AnnotationUtils.requiresAnnotationInstantiation;
import static org.fortiss.tooling.kernel.utils.EcoreUtils.getFirstChildWith;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Map;
import java.util.function.Predicate;
import org.eclipse.emf.ecore.EObject;
import org.eclipse.emf.ecore.xml.type.AnyType;
......@@ -45,7 +48,19 @@ public class AddMissingAnnotationsMigrationProvider implements IMigrationProvide
if(migratedProjects.contains(modelElement)) {
return false;
}
return true;
Predicate<EObject> annotationTest = eObj -> {
if(eObj instanceof IModelElement &&
requiresAnnotationInstantiation((IModelElement)eObj)) {
return true;
}
return false;
};
if(getFirstChildWith(modelElement.getRootModelElement(), annotationTest) != null) {
return true;
}
return false;
}
/** {@inheritDoc} */
......
AngleUtils.java 462551eae71738ff51f92c9906bff9a21a375d2b GREEN
AnnotationUtils.java d97bf564f04487c2628a4ab03f93726bc2de8678 GREEN
AnnotationUtils.java 197ceb5f39af6b96eb8f7025e3fe3b1b39c35d42 GREEN
BaseMathUtils.java 65f6c39b641cba3c984a38f42b1bbf7dbf3287a3 GREEN
BaseModelElementUtils.java b8775b7a462efc168cf79a017aa3377a782d10f6 GREEN
ConstraintsBaseUtils.java bba938b43756ce6f35c338f6cef21c3ab5d49a9d GREEN
DimensionUtils.java 0dc67f9de11a84e6e4c6e1eb627817dee91ff30a GREEN
EllipseLayoutUtils.java 5c3a0126fdca5d5b4fb441694747e1cb0f49cd9f GREEN
LayoutDataUtils.java 5739dd16f0212e8f94927c0a0f51503390f2be69 GREEN
LayoutModelElementAdapter.java d81dfc551baa832f2761b4804760dcd8f57b7c5b YELLOW
LayoutModelElementFactory.java c49fca2de5a8cb7502fb28cc2b7e64a272df11b0 GREEN
MigrationUtils.java ab9d8682233313c21c6a52b8b03e1c796aacd29c GREEN
OffsetOrientationUtils.java 913cebbac2a5628bdd08b4df669b9412d6e07d94 GREEN
......
......@@ -316,6 +316,13 @@ public class AnnotationUtils {
for(IModelElement child : getChildrenWithType(element, IModelElement.class)) {
as.instantiateAnnotations(child);
}
}
/**
* Compact method to determine whether an {@link IModelElement} requires its annotations to be
* instantiated.
*/
public static boolean requiresAnnotationInstantiation(IModelElement element) {
return IAnnotationValueService.getInstance().requiresAnnotationInstantiation(element);
}
}
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment