Skip to content
Snippets Groups Projects
Commit 3c5208a6 authored by Alexander Diewald's avatar Alexander Diewald
Browse files

Merge branch '3846' of https://git.fortiss.org/af3/kernel.git into 3846

parents 45731c46 f426985b
No related branches found
No related tags found
No related merge requests found
EMFTypeMap.java b6c39465568f0edbfbd5c90400a4f519c042d423 GREEN
EMFTypeToTypeMap.java 294abe02e7af4ad751d8760b6c6286a3c1f6d73f GREEN
EMFTypeToTypeSetMap.java d131702e4f04ef8d8a2c70113dce2c628ce65c3d GREEN
EMFTypeMap.java 99a70a6c5db0cb283a1e0614f4f455422047e14d YELLOW
EMFTypeToTypeMap.java 792b6f10042562983b192cfe2a2547221391e701 YELLOW
EMFTypeToTypeSetMap.java e7572738d19c81fd507bc8ca88a3408058d88bf0 YELLOW
TypeSet.java e18e66236b223eaf4c22037459779b421a0c2703 GREEN
......@@ -15,47 +15,29 @@
+--------------------------------------------------------------------------*/
package org.fortiss.tooling.kernel.service.types;
import static org.fortiss.tooling.kernel.utils.EcoreUtils.getInterfaceType;
import java.util.Comparator;
import java.util.TreeMap;
import org.eclipse.emf.ecore.EClass;
import org.eclipse.emf.ecore.EObject;
/**
* Base class to map an EMF type to a target type. For a given {@link EClass} {@code Foo}, the
* map considers the generated interface class {@code Foo} and the corresponding implementation
* class {@code FooImpl} identical.
*/
public class EMFTypeMap<S, T> extends TreeMap<Class<? extends S>, T> {
/**
* Suffix used by EMF to denote implementation classes of the Java interfaces corresponding
* to EClasses.
*/
private static final String IMPL_CLASS_SUFFIX = "Impl";
public class EMFTypeMap<S extends EObject, T> extends TreeMap<Class<? extends S>, T> {
/** Constructor. */
public EMFTypeMap() {
super(new Comparator<Class<? extends S>>() {
@SuppressWarnings("unchecked")
private Class<? extends S> getInterfaceType(Class<? extends S> c) {
final String className = c.getSimpleName();
if(className.endsWith(IMPL_CLASS_SUFFIX)) {
final String ifaceName =
className.substring(0, className.length() - IMPL_CLASS_SUFFIX.length());
for(Class<?> iFace : c.getInterfaces()) {
if(iFace.getSimpleName().equals(ifaceName)) {
return (Class<? extends S>)iFace;
}
}
}
return c;
}
/** {@inheritDoc} */
@Override
public int compare(Class<? extends S> c1, Class<? extends S> c2) {
Class<? extends S> i1 = getInterfaceType(c1);
Class<? extends S> i2 = getInterfaceType(c2);
Class<? extends S> i2 = getInterfaceType(c1);
if(i1 == i2) {
return 0;
......
......@@ -15,7 +15,9 @@
+--------------------------------------------------------------------------*/
package org.fortiss.tooling.kernel.service.types;
import org.eclipse.emf.ecore.EObject;
/** Maps a given EMF type to another type. */
public class EMFTypeToTypeMap<S, T> extends EMFTypeMap<S, Class<? extends T>> {
public class EMFTypeToTypeMap<S extends EObject, T> extends EMFTypeMap<S, Class<? extends T>> {
// Nothing to do
}
......@@ -23,8 +23,10 @@ import java.util.Collection;
import java.util.Set;
import java.util.function.Predicate;
import org.eclipse.emf.ecore.EObject;
/** Maps a given EMF type to a {@link Set} of types. */
public class EMFTypeToTypeSetMap<S, T> extends EMFTypeMap<S, TypeSet<T>> {
public class EMFTypeToTypeSetMap<S extends EObject, T> extends EMFTypeMap<S, TypeSet<T>> {
/** Adds the given {@code targetType} to the mapped types of the given {@code sourceType}. */
public void addTypeSetEntry(Class<? extends S> sourceType, Class<? extends T> targetType) {
......
......@@ -2,7 +2,7 @@ CompositionUtils.java 34c0a191bd0fb4176c94b4d61abb5c88a679d5e8 GREEN
ConstraintsUtils.java 0f8be020f2ca4bb08931c32452163c04a28e30ce GREEN
EMFResourceUtils.java 979d0e1f4f66a2b3e715d2da0ebef6493f547fd7 GREEN
EcoreSerializerBase.java 0a0c2969d793d2e68094c55c8f7b0a662ef6e5d5 GREEN
EcoreUtils.java 95ee8d9c99ea5369ea788f517ebc8dc6f864f4ac GREEN
EcoreUtils.java 36a464aeda8c9e4f658bf7305f70892052d83096 YELLOW
ExtensionPointUtils.java 7ce63242b49eb9a7cd4eaadd223f5ebce1dfd75b GREEN
HierarchicalNameComparator.java 6face1b673126701a0721af48ead2f9766c17d46 GREEN
IdentifierUtils.java fff43dc4e84cdd89c3ece4f5d9d89aec4b0749c2 GREEN
......
......@@ -77,6 +77,12 @@ public class EcoreUtils {
private static final Notification refreshNotification =
new NotificationImpl(EVENT_TYPE_COUNT + 1, null, null);
/**
* Suffix used by EMF to denote implementation classes of the Java interfaces corresponding
* to EClasses.
*/
private static final String IMPL_CLASS_SUFFIX = "Impl";
/**
* Same as org.fortiss.tooling.kernel.utils.JavaUtils.convertList(Class<T>, List<S>) but with
* {@link EList} instead of {@link List}.
......@@ -306,7 +312,8 @@ public class EcoreUtils {
}
/**
* Returns a list of all parent {@link EObject}s that satisfy the given {@link Predicate}. If none
* Returns a list of all parent {@link EObject}s that satisfy the given {@link Predicate}. If
* none
* are found, an empty list is returned.
*
* @param child
......@@ -747,4 +754,37 @@ public class EcoreUtils {
public static <T> EList<T> collectToEList(Stream<T> s) {
return new BasicEList<T>(s.collect(Collectors.toList()));
}
/**
* Returns the interface type of the EMF class that can be either the interface itself or its
* implementation class.
*
* @param c
* interface or impl class.
* @return interface class.
*/
@SuppressWarnings("unchecked")
public static <T extends EObject> Class<T> getInterfaceType(Class<? extends T> c) {
final String className = c.getSimpleName();
if(className.endsWith(IMPL_CLASS_SUFFIX)) {
final String ifaceName =
className.substring(0, className.length() - IMPL_CLASS_SUFFIX.length());
for(Class<?> iFace : c.getInterfaces()) {
if(iFace.getSimpleName().equals(ifaceName)) {
return (Class<T>)iFace;
}
}
}
return (Class<T>)c;
}
/**
* Returns the interface type of the given EMF object.
*
* @return interface class.
*/
@SuppressWarnings("unchecked")
public static <S extends EObject> Class<? super S> getInterfaceType(S instance) {
return (Class<? super S>)getInterfaceType(instance.getClass());
}
}
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