Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bug 573296 - [Passage] rework EMF migration facilities, part 10 #767

Merged
merged 2 commits into from
May 3, 2021
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 8 additions & 12 deletions bundles/org.eclipse.passage.lic.emf/META-INF/MANIFEST.MF
Original file line number Diff line number Diff line change
Expand Up @@ -11,18 +11,8 @@ Require-Bundle: org.eclipse.emf.ecore.xmi;bundle-version="0.0.0",
org.eclipse.osgi;bundle-version="0.0.0",
org.eclipse.passage.lic.base;bundle-version="0.0.0"
Export-Package: org.eclipse.passage.lic.emf,
org.eclipse.passage.lic.emf.ecore.util;
x-friends:="org.eclipse.passage.lic.features.migration,
org.eclipse.passage.lic.emf.edit;x-internal:=true,
org.eclipse.passage.lic.internal.emf.i18n;x-internal:=true,
org.eclipse.passage.lic.features.migration.tests,
org.eclipse.passage.lic.licenses.migration,
org.eclipse.passage.lic.licenses.migration.tests,
org.eclipse.passage.lic.products.migration,
org.eclipse.passage.lic.products.migration.tests,
org.eclipse.passage.lic.users.migration,
org.eclipse.passage.lic.users.migration.tests",
org.eclipse.passage.lic.emf.meta,
org.eclipse.passage.lic.emf.migration,
org.eclipse.passage.lic.emf.resource,
org.eclipse.passage.lic.emf.validation,
org.eclipse.passage.lic.emf.xmi,
Expand All @@ -31,5 +21,11 @@ Export-Package: org.eclipse.passage.lic.emf,
org.eclipse.passage.lbc.base,
org.eclipse.passage.lbc.base.tests,
org.eclipse.passage.lic.net",
org.eclipse.passage.lic.internal.emf.i18n;x-internal:=true
org.eclipse.passage.lic.internal.emf.i18n;x-internal:=true,
org.eclipse.passage.lic.internal.emf.migration;
x-friends:="org.eclipse.passage.lic.features.model,
org.eclipse.passage.lic.keys.model,
org.eclipse.passage.lic.licenses.model,
org.eclipse.passage.lic.products.model,
org.eclipse.passage.lic.users.model"
Bundle-ActivationPolicy: lazy

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
/*******************************************************************************
* Copyright (c) 2021 ArSysOp
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License 2.0 which is available at
* https://www.eclipse.org/legal/epl-2.0/.
*
* SPDX-License-Identifier: EPL-2.0
*
* Contributors:
* ArSysOp - initial API and implementation
*******************************************************************************/
package org.eclipse.passage.lic.emf.migration;

import java.util.Iterator;
import java.util.Objects;
import java.util.Optional;

import org.eclipse.emf.ecore.EObject;
import org.eclipse.emf.ecore.util.FeatureMap;
import org.eclipse.emf.ecore.util.FeatureMap.Entry;

/**
* @since 2.0
*/
public final class ApplyFeatureMap {

private final FeatureMap features;
private final EFeatureRoutes routes;

public ApplyFeatureMap(FeatureMap features, EFeatureRoutes routes) {
Objects.requireNonNull(features, "ApplyFeatureMap::features"); //$NON-NLS-1$
Objects.requireNonNull(routes, "ApplyFeatureMap::routes"); //$NON-NLS-1$
this.features = features;
this.routes = routes;
}

public void apply(EObject object) {
for (Iterator<Entry> iterator = features.iterator(); iterator.hasNext();) {
Entry entry = iterator.next();
Optional.of(entry.getEStructuralFeature().getName())//
.flatMap(routes)//
.ifPresent(f -> object.eSet(f, entry.getValue()));
}
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
/*******************************************************************************
* Copyright (c) 2021 ArSysOp
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License 2.0 which is available at
* https://www.eclipse.org/legal/epl-2.0/.
*
* SPDX-License-Identifier: EPL-2.0
*
* Contributors:
* ArSysOp - initial API and implementation
*******************************************************************************/
package org.eclipse.passage.lic.emf.migration;

import java.util.Optional;
import java.util.function.Function;

import org.eclipse.emf.ecore.EStructuralFeature;

/**
* @since 2.0
*/
public interface EFeatureRoutes extends Function<String, Optional<EStructuralFeature>> {

void add(String found, EStructuralFeature destination);

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
/*******************************************************************************
* Copyright (c) 2021 ArSysOp
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License 2.0 which is available at
* https://www.eclipse.org/legal/epl-2.0/.
*
* SPDX-License-Identifier: EPL-2.0
*
* Contributors:
* ArSysOp - initial API and implementation
*******************************************************************************/
package org.eclipse.passage.lic.emf.migration;

import java.util.HashMap;
import java.util.Map;
import java.util.Optional;

import org.eclipse.emf.ecore.EStructuralFeature;

/**
*
* @since 2.0
*
*/
public final class SimpleFeatureRoutes implements EFeatureRoutes {

private final Map<String, EStructuralFeature> map;

public SimpleFeatureRoutes() {
map = new HashMap<>();
}

@Override
public Optional<EStructuralFeature> apply(String found) {
return Optional.ofNullable(map.get(found));
}

@Override
public void add(String found, EStructuralFeature destination) {
map.put(found, destination);
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
/*******************************************************************************
* Copyright (c) 2021 ArSysOp
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License 2.0 which is available at
* https://www.eclipse.org/legal/epl-2.0/.
*
* SPDX-License-Identifier: EPL-2.0
*
* Contributors:
* ArSysOp - initial API and implementation
*******************************************************************************/
package org.eclipse.passage.lic.internal.emf.migration;

import java.util.HashMap;
import java.util.Map;

import org.eclipse.emf.ecore.EClass;
import org.eclipse.emf.ecore.EClassifier;
import org.eclipse.emf.ecore.EPackage;
import org.eclipse.emf.ecore.util.EcoreUtil;

/**
* @since 2.0
*/
public final class DelegateClassifiers {

private final String uri;

public DelegateClassifiers(String uri) {
this.uri = uri;
}

public void delegate(EPackage delegate, Iterable<String> classifierNames) {
DelegatingEPackage delegating = new DelegateEPackage().apply(uri);
Map<EClass, EClass> delegated = new HashMap<>();
for (String name : classifierNames) {
EClassifier eClassifier = delegate.getEClassifier(name);
if (eClassifier instanceof EClass) {
EClass eClass = (EClass) eClassifier;
EClass key = EcoreUtil.copy(eClass);
delegated.put(key, eClass);
}
}
delegating.getEClassifiers().addAll(delegated.keySet());
delegating.getDelegatingEFactory().addEClassDelegate(delegate.getEFactoryInstance(), delegated);
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
package org.eclipse.passage.lic.internal.emf.migration;

import java.util.HashMap;
import java.util.Map;
import java.util.function.Function;

import org.eclipse.emf.common.util.EList;
import org.eclipse.emf.ecore.EClass;
import org.eclipse.emf.ecore.EClassifier;
import org.eclipse.emf.ecore.EPackage;
import org.eclipse.emf.ecore.util.EcoreUtil;

/**
* @since 2.0
*/
public final class DelegateEPackage implements Function<String, DelegatingEPackage> {

@Override
public DelegatingEPackage apply(String nsUri) {
EPackage existing = EPackage.Registry.INSTANCE.getEPackage(nsUri);
if (existing instanceof DelegatingEPackage) {
return (DelegatingEPackage) existing;
} else {
DelegatingEPackage delegating = new DelegatingEPackage(nsUri);
if (existing != null) {
Map<EClass, EClass> wrapped = new HashMap<>();
EList<EClassifier> classifiers = existing.getEClassifiers();
for (EClassifier eClassifier : classifiers) {
if (eClassifier instanceof EClass) {
EClass eClass = (EClass) eClassifier;
EClass key = EcoreUtil.copy(eClass);
wrapped.put(key, eClass);
}
}
delegating.getEClassifiers().addAll(wrapped.keySet());
DelegatingEFactory factory = delegating.getDelegatingEFactory();
factory.addEClassDelegate(existing.getEFactoryInstance(), wrapped);
}
EPackage.Registry.INSTANCE.put(nsUri, delegating);
return delegating;
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
* Contributors:
* ArSysOp - initial API and implementation
*******************************************************************************/
package org.eclipse.passage.lic.emf.ecore.util;
package org.eclipse.passage.lic.internal.emf.migration;

import java.util.HashMap;
import java.util.Map;
Expand All @@ -25,7 +25,7 @@
import org.eclipse.passage.lic.emf.QualifiedNames;
import org.eclipse.passage.lic.emf.SimpleQualifiedNames;

public class DelegatingEFactory extends EFactoryImpl {
final class DelegatingEFactory extends EFactoryImpl {

public final Map<String, EClass> eClassMap = new HashMap<>();
public final Map<String, EDataType> eDataTypeMap = new HashMap<>();
Expand All @@ -34,11 +34,11 @@ public class DelegatingEFactory extends EFactoryImpl {

private final QualifiedNames names;

public DelegatingEFactory() {
DelegatingEFactory() {
names = new SimpleQualifiedNames();
}

public void addEClassDelegate(EFactory factory, Map<EClass, EClass> eClasses) {
void addEClassDelegate(EFactory factory, Map<EClass, EClass> eClasses) {
Set<Entry<EClass, EClass>> entrySet = eClasses.entrySet();
for (Entry<EClass, EClass> entry : entrySet) {
String key = names.caseEClass(entry.getKey());
Expand All @@ -47,7 +47,7 @@ public void addEClassDelegate(EFactory factory, Map<EClass, EClass> eClasses) {
}
}

public void addEDataTypeDelegate(EFactory factory, Map<EDataType, EDataType> eDataTypes) {
void addEDataTypeDelegate(EFactory factory, Map<EDataType, EDataType> eDataTypes) {
Set<Entry<EDataType, EDataType>> entrySet = eDataTypes.entrySet();
for (Entry<EDataType, EDataType> entry : entrySet) {
String key = names.caseEDataType(entry.getKey());
Expand Down Expand Up @@ -86,19 +86,19 @@ public String convertToString(EDataType eDataType, Object objectValue) {
return super.convertToString(eDataType, objectValue);
}

protected EFactory resolveDelegate(EClass eClass) {
private EFactory resolveDelegate(EClass eClass) {
return eClassFactories.get(names.caseEClass(eClass));
}

protected EFactory resolveDelegate(EDataType eDataType) {
private EFactory resolveDelegate(EDataType eDataType) {
return eDataTypeFactories.get(names.caseEDataType(eDataType));
}

protected EClass resolveEClass(EClass eClass) {
private EClass resolveEClass(EClass eClass) {
return eClassMap.get(names.caseEClass(eClass));
}

protected EDataType resolveEDataType(EDataType eDataType) {
private EDataType resolveEDataType(EDataType eDataType) {
return eDataTypeMap.get(names.caseEDataType(eDataType));
}

Expand Down
Loading