diff --git a/org.fortiss.tooling.common/.classpath b/org.fortiss.tooling.common/.classpath index c045661bf74792e8081e793bf298d629169c5e3e..817ca66fb22528b19dc115c42bc100440a725169 100644 --- a/org.fortiss.tooling.common/.classpath +++ b/org.fortiss.tooling.common/.classpath @@ -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"/> diff --git a/org.fortiss.tooling.common/META-INF/MANIFEST.MF b/org.fortiss.tooling.common/META-INF/MANIFEST.MF index a09e592dbafb4ee44ef797ade6f48f3d3e302424..dfea4aa5f4b6632d93ea32ec457849094e521a8f 100644 --- a/org.fortiss.tooling.common/META-INF/MANIFEST.MF +++ b/org.fortiss.tooling.common/META-INF/MANIFEST.MF @@ -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 diff --git a/org.fortiss.tooling.common/build.properties b/org.fortiss.tooling.common/build.properties index cff8dcb95edca35c858c420caaba57e2e483b980..63bf2bed7895879bd0c1f1e545480584a87684c9 100644 --- a/org.fortiss.tooling.common/build.properties +++ b/org.fortiss.tooling.common/build.properties @@ -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/ diff --git a/org.fortiss.tooling.common/lib/apache-commons/commons-lang3-3.7-javadoc.jar b/org.fortiss.tooling.common/lib/apache-commons/commons-lang3-3.7-javadoc.jar deleted file mode 100644 index f16817a442855cbd44bbc3eb0392a0e61d288dea..0000000000000000000000000000000000000000 Binary files a/org.fortiss.tooling.common/lib/apache-commons/commons-lang3-3.7-javadoc.jar and /dev/null differ diff --git a/org.fortiss.tooling.common/lib/apache-commons/commons-lang3-3.7-sources.jar b/org.fortiss.tooling.common/lib/apache-commons/commons-lang3-3.7-sources.jar deleted file mode 100644 index a83c661a87db03d3f24bd440fde6d7fa6211e6fb..0000000000000000000000000000000000000000 Binary files a/org.fortiss.tooling.common/lib/apache-commons/commons-lang3-3.7-sources.jar and /dev/null differ diff --git a/org.fortiss.tooling.common/lib/apache-commons/commons-lang3-3.7.jar b/org.fortiss.tooling.common/lib/apache-commons/commons-lang3-3.7.jar deleted file mode 100644 index f37ded60fe6d78afa7758866c089b6296503868f..0000000000000000000000000000000000000000 Binary files a/org.fortiss.tooling.common/lib/apache-commons/commons-lang3-3.7.jar and /dev/null differ diff --git a/org.fortiss.tooling.common/lib/apache-commons/commons-lang3-3.9-javadoc.jar b/org.fortiss.tooling.common/lib/apache-commons/commons-lang3-3.9-javadoc.jar new file mode 100644 index 0000000000000000000000000000000000000000..b1d89ecdc3e1ae32e82109724dbefd4b286ad27d Binary files /dev/null and b/org.fortiss.tooling.common/lib/apache-commons/commons-lang3-3.9-javadoc.jar differ diff --git a/org.fortiss.tooling.common/lib/apache-commons/commons-lang3-3.9-sources.jar b/org.fortiss.tooling.common/lib/apache-commons/commons-lang3-3.9-sources.jar new file mode 100644 index 0000000000000000000000000000000000000000..78ea8e4cdd30f0218a90a168653424d504d3acdc Binary files /dev/null and b/org.fortiss.tooling.common/lib/apache-commons/commons-lang3-3.9-sources.jar differ diff --git a/org.fortiss.tooling.common/lib/apache-commons/commons-lang3-3.9.jar b/org.fortiss.tooling.common/lib/apache-commons/commons-lang3-3.9.jar new file mode 100644 index 0000000000000000000000000000000000000000..0d896939269b3bf1ce6208a872db1fcabe40e0df Binary files /dev/null and b/org.fortiss.tooling.common/lib/apache-commons/commons-lang3-3.9.jar differ diff --git a/org.fortiss.tooling.kernel/src/org/fortiss/tooling/kernel/service/types/.ratings b/org.fortiss.tooling.kernel/src/org/fortiss/tooling/kernel/service/types/.ratings index abd9b93500271c14d2d69255ad99564476ccb34c..aa16fda52c876f4da32c2940d179b10bf42d5dff 100644 --- a/org.fortiss.tooling.kernel/src/org/fortiss/tooling/kernel/service/types/.ratings +++ b/org.fortiss.tooling.kernel/src/org/fortiss/tooling/kernel/service/types/.ratings @@ -1,4 +1,4 @@ -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 diff --git a/org.fortiss.tooling.kernel/src/org/fortiss/tooling/kernel/service/types/EMFTypeMap.java b/org.fortiss.tooling.kernel/src/org/fortiss/tooling/kernel/service/types/EMFTypeMap.java index b6c39465568f0edbfbd5c90400a4f519c042d423..ad1c6ecba7fbb2dff0d72ea12cd5040abe52364f 100644 --- a/org.fortiss.tooling.kernel/src/org/fortiss/tooling/kernel/service/types/EMFTypeMap.java +++ b/org.fortiss.tooling.kernel/src/org/fortiss/tooling/kernel/service/types/EMFTypeMap.java @@ -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) { diff --git a/org.fortiss.tooling.kernel/src/org/fortiss/tooling/kernel/service/types/EMFTypeToTypeMap.java b/org.fortiss.tooling.kernel/src/org/fortiss/tooling/kernel/service/types/EMFTypeToTypeMap.java index 294abe02e7af4ad751d8760b6c6286a3c1f6d73f..792b6f10042562983b192cfe2a2547221391e701 100644 --- a/org.fortiss.tooling.kernel/src/org/fortiss/tooling/kernel/service/types/EMFTypeToTypeMap.java +++ b/org.fortiss.tooling.kernel/src/org/fortiss/tooling/kernel/service/types/EMFTypeToTypeMap.java @@ -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 } diff --git a/org.fortiss.tooling.kernel/src/org/fortiss/tooling/kernel/service/types/EMFTypeToTypeSetMap.java b/org.fortiss.tooling.kernel/src/org/fortiss/tooling/kernel/service/types/EMFTypeToTypeSetMap.java index d131702e4f04ef8d8a2c70113dce2c628ce65c3d..e7572738d19c81fd507bc8ca88a3408058d88bf0 100644 --- a/org.fortiss.tooling.kernel/src/org/fortiss/tooling/kernel/service/types/EMFTypeToTypeSetMap.java +++ b/org.fortiss.tooling.kernel/src/org/fortiss/tooling/kernel/service/types/EMFTypeToTypeSetMap.java @@ -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) { diff --git a/org.fortiss.tooling.kernel/src/org/fortiss/tooling/kernel/utils/.ratings b/org.fortiss.tooling.kernel/src/org/fortiss/tooling/kernel/utils/.ratings index f61486976ec968eb451c6149467be9a38b3b296b..7557efeba58edcb57ab4a164d3f82de02ecd9f89 100644 --- a/org.fortiss.tooling.kernel/src/org/fortiss/tooling/kernel/utils/.ratings +++ b/org.fortiss.tooling.kernel/src/org/fortiss/tooling/kernel/utils/.ratings @@ -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 diff --git a/org.fortiss.tooling.kernel/src/org/fortiss/tooling/kernel/utils/EcoreUtils.java b/org.fortiss.tooling.kernel/src/org/fortiss/tooling/kernel/utils/EcoreUtils.java index 95ee8d9c99ea5369ea788f517ebc8dc6f864f4ac..af30c39f36db02322c0a805bfc67ffeeb157c52b 100644 --- a/org.fortiss.tooling.kernel/src/org/fortiss/tooling/kernel/utils/EcoreUtils.java +++ b/org.fortiss.tooling.kernel/src/org/fortiss/tooling/kernel/utils/EcoreUtils.java @@ -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()); + } }