Commit 923eba9d authored by Alexander Diewald's avatar Alexander Diewald
Browse files

Merge branch '3846' into 'master'

3846

See merge request !70
parents 8126b729 8f91fad1
......@@ -8,9 +8,9 @@
</classpathentry>
<classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/>
<classpathentry exported="true" kind="lib" path="lib/apache-commons/commons-lang-2.6.jar"/>
<classpathentry exported="true" kind="lib" path="lib/apache-commons/commons-lang3-3.7.jar" sourcepath="lib/apache-commons/commons-lang3-3.7-sources.jar">
<classpathentry exported="true" kind="lib" path="lib/apache-commons/commons-lang3-3.9.jar" sourcepath="lib/apache-commons/commons-lang3-3.9-sources.jar">
<attributes>
<attribute name="javadoc_location" value="jar:platform:/resource/org.fortiss.tooling.common/lib/apache-commons/commons-lang3-3.7-javadoc.jar!/"/>
<attribute name="javadoc_location" value="jar:platform:/resource/org.fortiss.tooling.common/lib/apache-commons/commons-lang3-3.9-javadoc.jar!/"/>
</attributes>
</classpathentry>
<classpathentry exported="true" kind="lib" path="lib/apache-commons/commons-io-2.4.jar" sourcepath="lib/apache-commons/commons-io-2.4-sources.jar"/>
......
......@@ -10,7 +10,7 @@ Bundle-ActivationPolicy: lazy
Bundle-RequiredExecutionEnvironment: JavaSE-11
Bundle-ClassPath: .,
lib/apache-commons/commons-lang-2.6.jar,
lib/apache-commons/commons-lang3-3.7.jar,
lib/apache-commons/commons-lang3-3.9.jar,
lib/apache-commons/commons-io-2.4.jar,
lib/org.conqat.ide.commons.jar,
lib/opencsv-2.3.jar
......
......@@ -8,6 +8,6 @@ bin.includes = .,\
lib/apache-commons/commons-lang-2.6.jar,\
lib/apache-commons/commons-io-2.4.jar,\
lib/opencsv-2.3.jar,\
lib/apache-commons/commons-lang3-3.7.jar,\
lib/apache-commons/commons-lang3-3.9.jar,\
lib/apache-commons/LICENSE.txt
src.includes = lib/
EMFTypeMap.java b6c39465568f0edbfbd5c90400a4f519c042d423 GREEN
EMFTypeToTypeMap.java 294abe02e7af4ad751d8760b6c6286a3c1f6d73f GREEN
EMFTypeToTypeSetMap.java d131702e4f04ef8d8a2c70113dce2c628ce65c3d GREEN
EMFTypeMap.java ad1c6ecba7fbb2dff0d72ea12cd5040abe52364f GREEN
EMFTypeToTypeMap.java 792b6f10042562983b192cfe2a2547221391e701 GREEN
EMFTypeToTypeSetMap.java e7572738d19c81fd507bc8ca88a3408058d88bf0 GREEN
TypeSet.java e18e66236b223eaf4c22037459779b421a0c2703 GREEN
......@@ -15,42 +15,24 @@
+--------------------------------------------------------------------------*/
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) {
......
......@@ -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 af30c39f36db02322c0a805bfc67ffeeb157c52b GREEN
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,8 +312,8 @@ public class EcoreUtils {
}
/**
* Returns a list of all parent {@link EObject}s that satisfy the given {@link Predicate}. If none
* are found, an empty list is returned.
* 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
* The {@link EObject} from which the "upwards" search shall begin.
......@@ -747,4 +753,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());
}
}
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