Skip to content
Snippets Groups Projects
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
No related branches found
No related tags found
No related merge requests found
Showing
with 59 additions and 34 deletions
...@@ -8,9 +8,9 @@ ...@@ -8,9 +8,9 @@
</classpathentry> </classpathentry>
<classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/> <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-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> <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> </attributes>
</classpathentry> </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"/> <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 ...@@ -10,7 +10,7 @@ Bundle-ActivationPolicy: lazy
Bundle-RequiredExecutionEnvironment: JavaSE-11 Bundle-RequiredExecutionEnvironment: JavaSE-11
Bundle-ClassPath: ., Bundle-ClassPath: .,
lib/apache-commons/commons-lang-2.6.jar, 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/apache-commons/commons-io-2.4.jar,
lib/org.conqat.ide.commons.jar, lib/org.conqat.ide.commons.jar,
lib/opencsv-2.3.jar lib/opencsv-2.3.jar
......
...@@ -8,6 +8,6 @@ bin.includes = .,\ ...@@ -8,6 +8,6 @@ bin.includes = .,\
lib/apache-commons/commons-lang-2.6.jar,\ lib/apache-commons/commons-lang-2.6.jar,\
lib/apache-commons/commons-io-2.4.jar,\ lib/apache-commons/commons-io-2.4.jar,\
lib/opencsv-2.3.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 lib/apache-commons/LICENSE.txt
src.includes = lib/ src.includes = lib/
File deleted
File deleted
File deleted
File added
File added
File added
EMFTypeMap.java b6c39465568f0edbfbd5c90400a4f519c042d423 GREEN EMFTypeMap.java ad1c6ecba7fbb2dff0d72ea12cd5040abe52364f GREEN
EMFTypeToTypeMap.java 294abe02e7af4ad751d8760b6c6286a3c1f6d73f GREEN EMFTypeToTypeMap.java 792b6f10042562983b192cfe2a2547221391e701 GREEN
EMFTypeToTypeSetMap.java d131702e4f04ef8d8a2c70113dce2c628ce65c3d GREEN EMFTypeToTypeSetMap.java e7572738d19c81fd507bc8ca88a3408058d88bf0 GREEN
TypeSet.java e18e66236b223eaf4c22037459779b421a0c2703 GREEN TypeSet.java e18e66236b223eaf4c22037459779b421a0c2703 GREEN
...@@ -15,42 +15,24 @@ ...@@ -15,42 +15,24 @@
+--------------------------------------------------------------------------*/ +--------------------------------------------------------------------------*/
package org.fortiss.tooling.kernel.service.types; package org.fortiss.tooling.kernel.service.types;
import static org.fortiss.tooling.kernel.utils.EcoreUtils.getInterfaceType;
import java.util.Comparator; import java.util.Comparator;
import java.util.TreeMap; import java.util.TreeMap;
import org.eclipse.emf.ecore.EClass; 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 * 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 * map considers the generated interface class {@code Foo} and the corresponding implementation
* class {@code FooImpl} identical. * class {@code FooImpl} identical.
*/ */
public class EMFTypeMap<S, T> extends TreeMap<Class<? extends S>, T> { public class EMFTypeMap<S extends EObject, 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";
/** Constructor. */ /** Constructor. */
public EMFTypeMap() { public EMFTypeMap() {
super(new Comparator<Class<? extends S>>() { 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} */ /** {@inheritDoc} */
@Override @Override
public int compare(Class<? extends S> c1, Class<? extends S> c2) { public int compare(Class<? extends S> c1, Class<? extends S> c2) {
......
...@@ -15,7 +15,9 @@ ...@@ -15,7 +15,9 @@
+--------------------------------------------------------------------------*/ +--------------------------------------------------------------------------*/
package org.fortiss.tooling.kernel.service.types; package org.fortiss.tooling.kernel.service.types;
import org.eclipse.emf.ecore.EObject;
/** Maps a given EMF type to another type. */ /** 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 // Nothing to do
} }
...@@ -23,8 +23,10 @@ import java.util.Collection; ...@@ -23,8 +23,10 @@ import java.util.Collection;
import java.util.Set; import java.util.Set;
import java.util.function.Predicate; import java.util.function.Predicate;
import org.eclipse.emf.ecore.EObject;
/** Maps a given EMF type to a {@link Set} of types. */ /** 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}. */ /** 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) { public void addTypeSetEntry(Class<? extends S> sourceType, Class<? extends T> targetType) {
......
...@@ -2,7 +2,7 @@ CompositionUtils.java 34c0a191bd0fb4176c94b4d61abb5c88a679d5e8 GREEN ...@@ -2,7 +2,7 @@ CompositionUtils.java 34c0a191bd0fb4176c94b4d61abb5c88a679d5e8 GREEN
ConstraintsUtils.java 0f8be020f2ca4bb08931c32452163c04a28e30ce GREEN ConstraintsUtils.java 0f8be020f2ca4bb08931c32452163c04a28e30ce GREEN
EMFResourceUtils.java 979d0e1f4f66a2b3e715d2da0ebef6493f547fd7 GREEN EMFResourceUtils.java 979d0e1f4f66a2b3e715d2da0ebef6493f547fd7 GREEN
EcoreSerializerBase.java 0a0c2969d793d2e68094c55c8f7b0a662ef6e5d5 GREEN EcoreSerializerBase.java 0a0c2969d793d2e68094c55c8f7b0a662ef6e5d5 GREEN
EcoreUtils.java 95ee8d9c99ea5369ea788f517ebc8dc6f864f4ac GREEN EcoreUtils.java af30c39f36db02322c0a805bfc67ffeeb157c52b GREEN
ExtensionPointUtils.java 7ce63242b49eb9a7cd4eaadd223f5ebce1dfd75b GREEN ExtensionPointUtils.java 7ce63242b49eb9a7cd4eaadd223f5ebce1dfd75b GREEN
HierarchicalNameComparator.java 6face1b673126701a0721af48ead2f9766c17d46 GREEN HierarchicalNameComparator.java 6face1b673126701a0721af48ead2f9766c17d46 GREEN
IdentifierUtils.java fff43dc4e84cdd89c3ece4f5d9d89aec4b0749c2 GREEN IdentifierUtils.java fff43dc4e84cdd89c3ece4f5d9d89aec4b0749c2 GREEN
......
...@@ -77,6 +77,12 @@ public class EcoreUtils { ...@@ -77,6 +77,12 @@ public class EcoreUtils {
private static final Notification refreshNotification = private static final Notification refreshNotification =
new NotificationImpl(EVENT_TYPE_COUNT + 1, null, null); 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 * Same as org.fortiss.tooling.kernel.utils.JavaUtils.convertList(Class<T>, List<S>) but with
* {@link EList} instead of {@link List}. * {@link EList} instead of {@link List}.
...@@ -306,8 +312,8 @@ public class EcoreUtils { ...@@ -306,8 +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
* are found, an empty list is returned. * none are found, an empty list is returned.
* *
* @param child * @param child
* The {@link EObject} from which the "upwards" search shall begin. * The {@link EObject} from which the "upwards" search shall begin.
...@@ -747,4 +753,37 @@ public class EcoreUtils { ...@@ -747,4 +753,37 @@ public class EcoreUtils {
public static <T> EList<T> collectToEList(Stream<T> s) { public static <T> EList<T> collectToEList(Stream<T> s) {
return new BasicEList<T>(s.collect(Collectors.toList())); 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