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

- Add and register {@link RemoveDuplicatedAnnotationsMigrationProvider} that...

- Add and register {@link RemoveDuplicatedAnnotationsMigrationProvider} that removes duplicated {@link IAnnotatedSpecification}s from a model. These have been observed for a couple of models and might indicate an internal problem.
parent 713a25a7
No related branches found
No related tags found
No related merge requests found
......@@ -31,13 +31,14 @@
uri="http://www.fortiss.org/tooling/base/model/base"
class="org.fortiss.tooling.base.model.base.BasePackage"/>
</extension>
<extension
point="org.fortiss.tooling.kernel.migrationProvider">
<migrationProvider
migrationProvider="org.fortiss.tooling.base.migration.IDMigrationProvider">
<objectClass
objectClass="org.fortiss.tooling.kernel.extension.data.ITopLevelElement">
</objectClass>
<extension point="org.fortiss.tooling.kernel.migrationProvider">
<migrationProvider migrationProvider="org.fortiss.tooling.base.migration.IDMigrationProvider">
<objectClass objectClass="org.fortiss.tooling.kernel.extension.data.ITopLevelElement"/>
</migrationProvider>
<migrationProvider migrationProvider="org.fortiss.tooling.base.migration.RemoveDuplicatedAnnotationsMigrationProvider">
<objectClass objectClass="org.fortiss.tooling.kernel.extension.data.ITopLevelElement"/>
</migrationProvider>
</extension>
</plugin>
/*--------------------------------------------------------------------------+
$Id$
| |
| Copyright 2013 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.base.migration;
import static org.fortiss.tooling.kernel.utils.EcoreUtils.getChildrenWithType;
import static org.fortiss.tooling.kernel.utils.EcoreUtils.pickInstanceOf;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;
import org.eclipse.emf.common.util.URI;
import org.eclipse.emf.ecore.EObject;
import org.eclipse.emf.ecore.xml.type.AnyType;
import org.fortiss.tooling.base.ToolingBaseActivator;
import org.fortiss.tooling.base.model.element.IAnnotatedSpecification;
import org.fortiss.tooling.base.model.element.IModelElement;
import org.fortiss.tooling.kernel.extension.IMigrationProvider;
import org.fortiss.tooling.kernel.extension.data.ITopLevelElement;
import org.fortiss.tooling.kernel.utils.LoggingUtils;
/**
* {@link RemoveDuplicatedAnnotationsMigrationProvider} that removes duplicated
* {@link IAnnotatedSpecification}s from a model. These have been observed for a couple of models
* and might indicate an internal problem.
*
* @author barner
* @author $Author$
* @version $Rev$
* @ConQAT.Rating YELLOW Hash: DEC2C0FC12FAE018A4BBE90AE21CEBF1
*/
public class RemoveDuplicatedAnnotationsMigrationProvider implements IMigrationProvider {
/** {@inheritDoc} */
@Override
public boolean needMigration(ITopLevelElement topLevelElement,
Map<EObject, AnyType> unknownFeatures) {
return doInternal(topLevelElement, false);
}
/**
* Internal helper method to implement {@link #needMigration(ITopLevelElement, Map)} and
* {@link #migrate(ITopLevelElement, Map)}.
*
* @param topLevelElement
* The {@link ITopLevelElement} to be analyse / migrated.
* @param migrate
* Flag whether to work in migration mode
*
* @return In analysis mode, whether migration is required. Don't care in migration mode.
*/
private boolean doInternal(ITopLevelElement topLevelElement, boolean migrate) {
Set<Class<? extends IAnnotatedSpecification>> observedAnnotationClasses =
new HashSet<Class<? extends IAnnotatedSpecification>>();
for(IModelElement modelElement : getChildrenWithType(topLevelElement.getRootModelElement(),
IModelElement.class)) {
observedAnnotationClasses.clear();
for(IAnnotatedSpecification annotation : pickInstanceOf(IAnnotatedSpecification.class,
modelElement.getSpecifications())) {
Class<? extends IAnnotatedSpecification> annotationClass = annotation.getClass();
if(observedAnnotationClasses.contains(annotationClass)) {
if(migrate) {
modelElement.getSpecifications().remove(annotation);
} else {
return true;
}
}
observedAnnotationClasses.add(annotation.getClass());
}
}
return false;
}
/** {@inheritDoc} */
@Override
public void migrate(ITopLevelElement topLevelElement, Map<EObject, AnyType> unknownFeatures) {
doInternal(topLevelElement, true);
URI uri = topLevelElement.getRootModelElement().eResource().getURI();
LoggingUtils.error(ToolingBaseActivator.getDefault(),
"Duplicate annotations have been removed from \"" + uri.lastSegment() +
"\". Please report this incident since it indicates an internal problem.");
}
}
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