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

Obsoleted by RemoveDeprecatedArtifactsMigrationProviderBase.

refs 3120,3368
parent 0a8eac6b
No related branches found
No related tags found
No related merge requests found
......@@ -5,6 +5,5 @@ ElementCompositorBase.java 8667281b2e5988b11390cf77deab5d118f297ab1 GREEN
MultiViolationConstraintCheckerBase.java e2f17f02fae75a17e955d48734ed043323f26f04 GREEN
PrototypeProviderBase.java 62de3ea391ecb515883490517aa2e94ab812d91b GREEN
RemoveDeprecatedArtifactsMigrationProviderBase.java 48ded3c14cd7f3fe567c820eebf46c40214cf304 YELLOW
RemoveUnknownFeatureMigrationProviderBase.java 0ffeb1f02a3f7476abcb467ebe07d3c5d5561b86 GREEN
TransformationContextChainBase.java b5195a9bde6d50268dda80fed993477d7a4447ee GREEN
TransformationProviderBase.java 0c3d114c6a3d854f74630417c05dd889ed02acdf GREEN
/*-------------------------------------------------------------------------+
| Copyright 2015 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.base;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import org.eclipse.emf.ecore.EClass;
import org.eclipse.emf.ecore.EObject;
import org.eclipse.emf.ecore.EStructuralFeature;
import org.eclipse.emf.ecore.util.FeatureMap;
import org.eclipse.emf.ecore.xml.type.AnyType;
import org.fortiss.tooling.kernel.extension.IMigrationProvider;
import org.fortiss.tooling.kernel.extension.data.ITopLevelElement;
/**
* Base class for {@link IMigrationProvider}s to selectively remove unknown features from a model.
*
* @author barner
*/
public abstract class RemoveUnknownFeatureMigrationProviderBase implements IMigrationProvider { // NO_UCD
// Migrators are retired after a release, but this base class should be available when needed.
// See https://af3-developer.fortiss.org/projects/autofocus3/wiki/Model_Migration
/** Type of container previously owning the known unknown feature. */
protected Class<?> containerType;
/**
* {@link EClass} representing how {@code anyType} references the unknown feature
* (e.g., {@link org.eclipse.emf.ecore.EcorePackage.Literals#EREFERENCE} or
* {@link org.eclipse.emf.ecore.EcorePackage.Literals#EATTRIBUTE}).
*/
private EClass fieldType;
/** Name of field of {@code anyType} that is used to reference the unknown feature. */
private String fieldName;
/** Class name of unknown feature to be removed. */
private String className;
/** Constructs a new {@link RemoveUnknownFeatureMigrationProviderBase}. */
protected RemoveUnknownFeatureMigrationProviderBase(Class<?> containerType, EClass fieldType,
final String fieldName, final String className) {
this.containerType = containerType;
this.fieldType = fieldType;
this.fieldName = fieldName;
this.className = className;
}
/** {@inheritDoc} */
@Override
public boolean needMigration(ITopLevelElement modelElement,
Map<EObject, AnyType> unknownFeatures) {
return doInternal(unknownFeatures, false);
}
/** {@inheritDoc} */
@Override
public void migrate(ITopLevelElement modelElement, Map<EObject, AnyType> unknownFeatures) {
doInternal(unknownFeatures, true);
}
/**
* Helper method to implement {@link #needMigration(ITopLevelElement, Map)} and
* {@link #migrate(ITopLevelElement, Map)}.
*
* @param unknownFeatures
* Set of unknown features to be investigated / manipulated
*
* @param migrate
* If {@code true}, the respective unknown features are removed. Otherwise, the
* return value indicates, if the migration is required.
*
* @return {@code true} iff there are unknown features that should be / have been removed.
*/
private boolean doInternal(Map<EObject, AnyType> unknownFeatures, boolean migrate) {
boolean rval = false;
for(EObject object : unknownFeatures.keySet()) {
if(containerType.isAssignableFrom(object.eClass().getInstanceClass())) {
AnyType anyType = unknownFeatures.get(object);
FeatureMap featureMap = anyType.getMixed();
List<FeatureMap.Entry> toRemove = new ArrayList<FeatureMap.Entry>();
for(FeatureMap.Entry feature : featureMap) {
EStructuralFeature eStructuralFeature = feature.getEStructuralFeature();
if(eStructuralFeature.eClass().equals(fieldType) &&
eStructuralFeature.getName().equals(fieldName) &&
getUnknownEClassName(feature).equals(className)) {
if(migrate) {
toRemove.add(feature);
rval = true;
} else {
return true;
}
}
}
featureMap.removeAll(toRemove);
}
}
return rval;
}
/**
* Returns the name of an unknown {@link EClass} (i.e., that is not part of the meta-model (any
* more)) represented by a given {@link org.eclipse.emf.ecore.util.FeatureMap.Entry}.
*
* In case the {@link EClass} is not represented by {@link AnyType} (e.g., because the
* {@link EClass} is (still) part of the meta-model), {@code null} is returned.
*/
private String getUnknownEClassName(FeatureMap.Entry feature) {
if(feature.getValue() instanceof AnyType) {
AnyType type = (AnyType)feature.getValue();
return type.eClass().getName();
}
return null;
}
}
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