diff --git a/org.fortiss.tooling.ext.reuse/META-INF/MANIFEST.MF b/org.fortiss.tooling.ext.reuse/META-INF/MANIFEST.MF index 082b17dd9e961e9a54b1cc35a97275b0fafd298f..0746ecb0f9bfb547cbf8e2b62532e384121ccf99 100644 --- a/org.fortiss.tooling.ext.reuse/META-INF/MANIFEST.MF +++ b/org.fortiss.tooling.ext.reuse/META-INF/MANIFEST.MF @@ -13,7 +13,8 @@ Bundle-Activator: org.fortiss.tooling.ext.reuse.ToolingReuseActivator Require-Bundle: org.eclipse.core.runtime, org.eclipse.emf.ecore;visibility:=reexport, org.fortiss.tooling.base;visibility:=reexport, - org.fortiss.tooling.kernel;visibility:=reexport + org.fortiss.tooling.kernel;visibility:=reexport, + org.fortiss.tooling.ext.variability;bundle-version="2.24.0" Export-Package: org.fortiss.tooling.ext.reuse.model, org.fortiss.tooling.ext.reuse.model.impl, org.fortiss.tooling.ext.reuse.model.util, diff --git a/org.fortiss.tooling.ext.reuse/src/org/fortiss/tooling/ext/reuse/service/.ratings b/org.fortiss.tooling.ext.reuse/src/org/fortiss/tooling/ext/reuse/service/.ratings index c9104c7da5e8d32fc8798717e420277b8668a631..f8540890c8d392bcc33f3ca89394f4c9a6f113e0 100644 --- a/org.fortiss.tooling.ext.reuse/src/org/fortiss/tooling/ext/reuse/service/.ratings +++ b/org.fortiss.tooling.ext.reuse/src/org/fortiss/tooling/ext/reuse/service/.ratings @@ -1,5 +1,5 @@ -IReuseProvider.java 51dd0df5954bff99b80244cae94403300c4aadb1 GREEN -IReuseProviderService.java 6cf3ef4f67ab7515a1a78df2448439e8d6d97737 GREEN +IReuseProvider.java 18d293f7f1f072883188f16fb6eeb52c8d6042cf GREEN +IReuseProviderService.java bcc70de0bb8d39c330e3a25d884abc7092dc1b7e GREEN LayoutedReuseProviderBase.java b0e4ce3cda818b0723ec37b925a4c4c3d0c41909 GREEN -ReuseProviderBase.java 0ee51474bda060f3d326094397bc0a7fd7247152 GREEN -ReuseProviderService.java 748eea63e16d286f1738aa7091219dc63e7ad16e GREEN +ReuseProviderBase.java ac47f5ecafed0bdef6ef5183c7194aa756f723fd GREEN +ReuseProviderService.java c4ef33283002d6dac6167f9c6c8f71d2c2ce39d1 GREEN diff --git a/org.fortiss.tooling.ext.reuse/src/org/fortiss/tooling/ext/reuse/service/IReuseProvider.java b/org.fortiss.tooling.ext.reuse/src/org/fortiss/tooling/ext/reuse/service/IReuseProvider.java index 51dd0df5954bff99b80244cae94403300c4aadb1..18d293f7f1f072883188f16fb6eeb52c8d6042cf 100644 --- a/org.fortiss.tooling.ext.reuse/src/org/fortiss/tooling/ext/reuse/service/IReuseProvider.java +++ b/org.fortiss.tooling.ext.reuse/src/org/fortiss/tooling/ext/reuse/service/IReuseProvider.java @@ -1,5 +1,5 @@ /*-------------------------------------------------------------------------+ -| Copyright 2021 fortiss GmbH | +| Copyright 2023 fortiss GmbH | | | | Licensed under the Apache License, Version 2.0 (the "License"); | | you may not use this file except in compliance with the License. | @@ -26,19 +26,32 @@ import org.fortiss.tooling.kernel.service.base.IEObjectAware; * * @author bergemann * - * @param <T> The subclass of {@link EObject} for which this provider shall be + * @param <T> + * The subclass of {@link EObject} for which this provider shall be * invoked. */ public interface IReuseProvider<T extends EObject> extends IEObjectAware<T> { + /** + * Prepares the given <T> for its storage in a reuse library. This might e.g. include cleaning + * it from attributes that are not needed anymore when "exported" into a library. + * + * @param element + * The <T> that should be prepared. + * @return True if preparation was successful, otherwise false. + */ + public boolean prepareReuseElementForLibrary(T element); + /** * Updates the first given <T>, which is a reuse element, based on the second * given <T>. The update is a replacement of the old element with the new one, * while also all references in depending elements are updated/replaced. * - * @param elementToBeUpdated The <T> that should be updated/replaced. - * @param newElement The <T> with which the first one should be replaced - * (updated). + * @param elementToBeUpdated + * The <T> that should be updated/replaced. + * @param newElement + * The <T> with which the first one should be replaced + * (updated). * @return True if update was successful, otherwise false */ public boolean updateReuseElement(T elementToBeUpdated, T newElement); @@ -46,8 +59,10 @@ public interface IReuseProvider<T extends EObject> extends IEObjectAware<T> { /** * Sets the name of the given <T> used for reuse with the given {@link String}. * - * @param reuseElement The <T> whose name should be set. - * @param name The {@link String} for the name. + * @param reuseElement + * The <T> whose name should be set. + * @param name + * The {@link String} for the name. * @return True if update was successful, otherwise false */ public boolean setReuseElementName(T reuseElement, String name); @@ -55,7 +70,8 @@ public interface IReuseProvider<T extends EObject> extends IEObjectAware<T> { /** * Gets the name of the given <T> used for reuse. * - * @param reuseElement The <T> whose name is requested. + * @param reuseElement + * The <T> whose name is requested. * @return The name as {@link String}. */ public String getReuseElementName(T reuseElement); @@ -64,8 +80,10 @@ public interface IReuseProvider<T extends EObject> extends IEObjectAware<T> { * Sets the comment of the given <T> used for reuse with the given * {@link String}. * - * @param reuseElement The <T> whose name should be set. - * @param comment The {@link String} for the comment. + * @param reuseElement + * The <T> whose name should be set. + * @param comment + * The {@link String} for the comment. * @return True if update was successful, otherwise false */ public boolean setReuseElementComment(T reuseElement, String comment); @@ -73,7 +91,8 @@ public interface IReuseProvider<T extends EObject> extends IEObjectAware<T> { /** * Gets the comment of the given <T>} used for reuse. * - * @param reuseElement The <T> whose name is requested. + * @param reuseElement + * The <T> whose name is requested. * @return The comment as {@link String}. */ public String getReuseElementComment(T reuseElement); diff --git a/org.fortiss.tooling.ext.reuse/src/org/fortiss/tooling/ext/reuse/service/IReuseProviderService.java b/org.fortiss.tooling.ext.reuse/src/org/fortiss/tooling/ext/reuse/service/IReuseProviderService.java index 6cf3ef4f67ab7515a1a78df2448439e8d6d97737..bcc70de0bb8d39c330e3a25d884abc7092dc1b7e 100644 --- a/org.fortiss.tooling.ext.reuse/src/org/fortiss/tooling/ext/reuse/service/IReuseProviderService.java +++ b/org.fortiss.tooling.ext.reuse/src/org/fortiss/tooling/ext/reuse/service/IReuseProviderService.java @@ -1,5 +1,5 @@ /*-------------------------------------------------------------------------+ -| Copyright 2021 fortiss GmbH | +| Copyright 2023 fortiss GmbH | | | | Licensed under the Apache License, Version 2.0 (the "License"); | | you may not use this file except in compliance with the License. | @@ -36,7 +36,7 @@ public interface IReuseProviderService extends IIntrospectiveKernelService { /** * Retrieves the singleton instance of {@link ReuseProviderService}. * - * @return The singleton instance of this service + * @return The singleton instance of this service. */ public static IReuseProviderService getInstance() { return ReuseProviderService.getInstance(); @@ -45,23 +45,38 @@ public interface IReuseProviderService extends IIntrospectiveKernelService { /** * Registers the given {@link IReuseProvider} in this service. * - * @param provider The {@link IReuseProvider} to register. - * @param cls The subclass of {@link EObject} the given provider shall be - * used for. + * @param provider + * The {@link IReuseProvider} to register. + * @param cls + * The subclass of {@link EObject} the given provider shall be + * used for. */ public <T extends EObject> void registerReuseProvider(IReuseProvider<T> provider, Class<T> cls); + /** + * Prepares the given reuse element as {@link EObject} for storage in a reuse library. This + * might include e.g. cleaning the reuse element from all attributes that are not needed anymore + * when "exported" into a library. + * + * @param reuseElement + * The reuse element that should be prepared. + * @return True if preparation was successful, otherwise false. + */ + public boolean prepareReuseElementForLibrary(EObject reuseElement); + /** * Updates the first given {@link EObject}, which is a reuse element, based on * the second given {@link EObject}. The update is a replacement of the old * element with the new one, while also all references in depending elements are * updated/replaced. * - * @param elementToBeUpdated The {@link EObject} that should be - * updated/replaced. - * @param newElement The {@link EObject} with which the first one should - * be replaced (updated). - * @return True if update was successful, otherwise false + * @param elementToBeUpdated + * The {@link EObject} that should be + * updated/replaced. + * @param newElement + * The {@link EObject} with which the first one should + * be replaced (updated). + * @return True if update was successful, otherwise false. */ public boolean updateReuseElement(EObject elementToBeUpdated, EObject newElement); @@ -69,16 +84,19 @@ public interface IReuseProviderService extends IIntrospectiveKernelService { * Sets the name of the given {@link EObject} used for reuse with the given * {@link String}. * - * @param reuseElement The {@link EObject} whose name should be set. - * @param name The {@link String} for the name. - * @return True if update was successful, otherwise false + * @param reuseElement + * The {@link EObject} whose name should be set. + * @param name + * The {@link String} for the name. + * @return True if update was successful, otherwise false. */ public boolean setReuseElementName(EObject reuseElement, String name); /** * Gets the name of the given {@link EObject} used for reuse. * - * @param reuseElement The {@link EObject} whose name is requested. + * @param reuseElement + * The {@link EObject} whose name is requested. * @return The name as {@link String}. */ public String getReuseElementName(EObject reuseElement); @@ -87,16 +105,19 @@ public interface IReuseProviderService extends IIntrospectiveKernelService { * Sets the comment of the given {@link EObject} used for reuse with the given * {@link String}. * - * @param reuseElement The {@link EObject} whose name should be set. - * @param comment The {@link String} for the comment. - * @return True if update was successful, otherwise false + * @param reuseElement + * The {@link EObject} whose name should be set. + * @param comment + * The {@link String} for the comment. + * @return True if update was successful, otherwise false. */ public boolean setReuseElementComment(EObject reuseElement, String comment); /** * Gets the comment of the given {@link EObject} used for reuse. * - * @param reuseElement The {@link EObject} whose name is requested. + * @param reuseElement + * The {@link EObject} whose name is requested. * @return The comment as {@link String}. */ public String getReuseElementComment(EObject reuseElement); diff --git a/org.fortiss.tooling.ext.reuse/src/org/fortiss/tooling/ext/reuse/service/ReuseProviderBase.java b/org.fortiss.tooling.ext.reuse/src/org/fortiss/tooling/ext/reuse/service/ReuseProviderBase.java index 0ee51474bda060f3d326094397bc0a7fd7247152..ac47f5ecafed0bdef6ef5183c7194aa756f723fd 100644 --- a/org.fortiss.tooling.ext.reuse/src/org/fortiss/tooling/ext/reuse/service/ReuseProviderBase.java +++ b/org.fortiss.tooling.ext.reuse/src/org/fortiss/tooling/ext/reuse/service/ReuseProviderBase.java @@ -1,5 +1,5 @@ /*-------------------------------------------------------------------------+ -| Copyright 2021 fortiss GmbH | +| Copyright 2023 fortiss GmbH | | | | Licensed under the Apache License, Version 2.0 (the "License"); | | you may not use this file except in compliance with the License. | @@ -16,12 +16,17 @@ package org.fortiss.tooling.ext.reuse.service; import static org.eclipse.emf.ecore.util.EcoreUtil.replace; +import static org.fortiss.tooling.ext.variability.util.VariabilityUtils.getOptVarPointSpecification; import static org.fortiss.tooling.kernel.utils.EcoreUtils.replaceEObjectReferences; import java.util.ArrayList; import java.util.List; import org.eclipse.emf.ecore.EObject; +import org.fortiss.tooling.base.model.element.IHierarchicElement; +import org.fortiss.tooling.base.model.element.IHierarchicElementContainer; +import org.fortiss.tooling.base.model.element.IModelElement; +import org.fortiss.tooling.ext.variability.model.OptionalVariationPointSpecification; import org.fortiss.tooling.kernel.model.INamedCommentedElement; import org.fortiss.tooling.kernel.model.INamedElement; @@ -31,11 +36,21 @@ import org.fortiss.tooling.kernel.model.INamedElement; * * @author bergemann * - * @param <T> The subclass of {@link EObject} for which this provider base shall + * @param <T> + * The subclass of {@link EObject} for which this provider base shall * be extended. */ public class ReuseProviderBase<T extends EObject> implements IReuseProvider<T> { + /** {@inheritDoc} */ + @Override + public boolean prepareReuseElementForLibrary(T reuseElement) { + if(reuseElement instanceof IModelElement) { + removeVariabilitySpecifications((IModelElement)reuseElement); + } + return true; + } + /** {@inheritDoc} */ @Override public boolean updateReuseElement(T elementToBeUpdated, T newElement) { @@ -47,8 +62,8 @@ public class ReuseProviderBase<T extends EObject> implements IReuseProvider<T> { /** {@inheritDoc} */ @Override public boolean setReuseElementName(T reuseElement, String name) { - if (reuseElement instanceof INamedElement) { - ((INamedElement) reuseElement).setName(name); + if(reuseElement instanceof INamedElement) { + ((INamedElement)reuseElement).setName(name); return true; } return false; @@ -57,8 +72,8 @@ public class ReuseProviderBase<T extends EObject> implements IReuseProvider<T> { /** {@inheritDoc} */ @Override public String getReuseElementName(T reuseElement) { - if (reuseElement instanceof INamedElement) { - return ((INamedElement) reuseElement).getName(); + if(reuseElement instanceof INamedElement) { + return ((INamedElement)reuseElement).getName(); } return null; } @@ -66,8 +81,8 @@ public class ReuseProviderBase<T extends EObject> implements IReuseProvider<T> { /** {@inheritDoc} */ @Override public boolean setReuseElementComment(T reuseElement, String comment) { - if (reuseElement instanceof INamedCommentedElement) { - ((INamedCommentedElement) reuseElement).setComment(comment); + if(reuseElement instanceof INamedCommentedElement) { + ((INamedCommentedElement)reuseElement).setComment(comment); return true; } return false; @@ -76,8 +91,8 @@ public class ReuseProviderBase<T extends EObject> implements IReuseProvider<T> { /** {@inheritDoc} */ @Override public String getReuseElementComment(T reuseElement) { - if (reuseElement instanceof INamedCommentedElement) { - return ((INamedCommentedElement) reuseElement).getComment(); + if(reuseElement instanceof INamedCommentedElement) { + return ((INamedCommentedElement)reuseElement).getComment(); } return null; } @@ -85,8 +100,28 @@ public class ReuseProviderBase<T extends EObject> implements IReuseProvider<T> { /** {@inheritDoc} */ @Override public List<Class<? extends EObject>> getPossibleExternalReferenceClasses() { - // can only be specified for specific elements (if wanted) --> here only empty + // Can only be specified for specific elements (if wanted) --> here only empty. return new ArrayList<Class<? extends EObject>>(); } + /** + * Removes unnecessary variability specifications from the given element and from all of its + * contained elements. The method is recursion-based! + */ + private void removeVariabilitySpecifications(IModelElement nextElement) { + // Removal. + OptionalVariationPointSpecification unnecessarySpec = + getOptVarPointSpecification(nextElement); + if(unnecessarySpec != null) { + nextElement.getSpecifications().remove(unnecessarySpec); + } + + // Recursion. + if(nextElement instanceof IHierarchicElementContainer) { + for(IHierarchicElement elem : ((IHierarchicElementContainer)nextElement) + .getContainedElements()) { + removeVariabilitySpecifications(elem); + } + } + } } diff --git a/org.fortiss.tooling.ext.reuse/src/org/fortiss/tooling/ext/reuse/service/ReuseProviderService.java b/org.fortiss.tooling.ext.reuse/src/org/fortiss/tooling/ext/reuse/service/ReuseProviderService.java index 748eea63e16d286f1738aa7091219dc63e7ad16e..c4ef33283002d6dac6167f9c6c8f71d2c2ce39d1 100644 --- a/org.fortiss.tooling.ext.reuse/src/org/fortiss/tooling/ext/reuse/service/ReuseProviderService.java +++ b/org.fortiss.tooling.ext.reuse/src/org/fortiss/tooling/ext/reuse/service/ReuseProviderService.java @@ -1,5 +1,5 @@ /*-------------------------------------------------------------------------+ -| Copyright 2021 fortiss GmbH | +| Copyright 2023 fortiss GmbH | | | | Licensed under the Apache License, Version 2.0 (the "License"); | | you may not use this file except in compliance with the License. | @@ -45,7 +45,8 @@ public class ReuseProviderService extends EObjectAwareServiceBase<IReuseProvider * List of {@link EObject} {@link Class}es that might exist inside reuse * elements as external references. */ - private static List<Class<? extends EObject>> possibleExternalReferenceClasses = new ArrayList<>(); + private static List<Class<? extends EObject>> possibleExternalReferenceClasses = + new ArrayList<>(); /** * Returns the singleton instance of {@link ReuseProviderService}. @@ -79,22 +80,30 @@ public class ReuseProviderService extends EObjectAwareServiceBase<IReuseProvider /** {@inheritDoc} */ @SuppressWarnings("unchecked") @Override - public <T extends EObject> void registerReuseProvider(IReuseProvider<T> provider, Class<T> cls) { - addHandler(cls, (IReuseProvider<EObject>) provider); - if (!reuseElementClasses.contains(cls)) { + public <T extends EObject> void registerReuseProvider(IReuseProvider<T> provider, + Class<T> cls) { + addHandler(cls, (IReuseProvider<EObject>)provider); + if(!reuseElementClasses.contains(cls)) { reuseElementClasses.add(cls); } possibleExternalReferenceClasses.addAll(provider.getPossibleExternalReferenceClasses()); } + /** {@inheritDoc} */ + @Override + public boolean prepareReuseElementForLibrary(EObject reuseElement) { + IReuseProvider<EObject> provider = getReuseProvider(reuseElement); + if(provider != null) { + return provider.prepareReuseElementForLibrary(reuseElement); + } + return false; + } + /** {@inheritDoc} */ @Override public boolean updateReuseElement(EObject elemToBeUpdated, EObject newElem) { - List<IReuseProvider<EObject>> registeredHandlers = getRegisteredHandlers(elemToBeUpdated.getClass()); - // there should only be one handler registered per class for the reuse case - if (registeredHandlers != null && registeredHandlers.size() == 1) { - // get(0) is safe due to size check above - IReuseProvider<EObject> provider = registeredHandlers.get(0); + IReuseProvider<EObject> provider = getReuseProvider(elemToBeUpdated); + if(provider != null) { return provider.updateReuseElement(elemToBeUpdated, newElem); } return false; @@ -103,11 +112,8 @@ public class ReuseProviderService extends EObjectAwareServiceBase<IReuseProvider /** {@inheritDoc} */ @Override public boolean setReuseElementName(EObject reuseElement, String name) { - List<IReuseProvider<EObject>> registeredHandlers = getRegisteredHandlers(reuseElement.getClass()); - // there should only be one handler registered per class for the reuse case - if (registeredHandlers != null && registeredHandlers.size() == 1) { - // get(0) is safe due to size check above - IReuseProvider<EObject> provider = registeredHandlers.get(0); + IReuseProvider<EObject> provider = getReuseProvider(reuseElement); + if(provider != null) { return provider.setReuseElementName(reuseElement, name); } return false; @@ -116,11 +122,8 @@ public class ReuseProviderService extends EObjectAwareServiceBase<IReuseProvider /** {@inheritDoc} */ @Override public String getReuseElementName(EObject reuseElement) { - List<IReuseProvider<EObject>> registeredHandlers = getRegisteredHandlers(reuseElement.getClass()); - // there should only be one handler registered per class for the reuse case - if (registeredHandlers != null && registeredHandlers.size() == 1) { - // get(0) is safe due to size check above - IReuseProvider<EObject> provider = registeredHandlers.get(0); + IReuseProvider<EObject> provider = getReuseProvider(reuseElement); + if(provider != null) { return provider.getReuseElementName(reuseElement); } return null; @@ -129,11 +132,8 @@ public class ReuseProviderService extends EObjectAwareServiceBase<IReuseProvider /** {@inheritDoc} */ @Override public boolean setReuseElementComment(EObject reuseElement, String comment) { - List<IReuseProvider<EObject>> registeredHandlers = getRegisteredHandlers(reuseElement.getClass()); - // there should only be one handler registered per class for the reuse case - if (registeredHandlers != null && registeredHandlers.size() == 1) { - // get(0) is safe due to size check above - IReuseProvider<EObject> provider = registeredHandlers.get(0); + IReuseProvider<EObject> provider = getReuseProvider(reuseElement); + if(provider != null) { return provider.setReuseElementComment(reuseElement, comment); } return false; @@ -142,11 +142,8 @@ public class ReuseProviderService extends EObjectAwareServiceBase<IReuseProvider /** {@inheritDoc} */ @Override public String getReuseElementComment(EObject reuseElement) { - List<IReuseProvider<EObject>> registeredHandlers = getRegisteredHandlers(reuseElement.getClass()); - // there should only be one handler registered per class for the reuse case - if (registeredHandlers != null && registeredHandlers.size() == 1) { - // get(0) is safe due to size check above - IReuseProvider<EObject> provider = registeredHandlers.get(0); + IReuseProvider<EObject> provider = getReuseProvider(reuseElement); + if(provider != null) { return provider.getReuseElementComment(reuseElement); } return null; @@ -187,4 +184,19 @@ public class ReuseProviderService extends EObjectAwareServiceBase<IReuseProvider public void startService() { IKernelIntrospectionSystemService.getInstance().registerService(this); } -} \ No newline at end of file + + /** + * Returns the reuse provider/handler for the class of the given element. If none can be found, + * null is returned. + */ + private IReuseProvider<EObject> getReuseProvider(EObject element) { + List<IReuseProvider<EObject>> registeredHandlers = + getRegisteredHandlers(element.getClass()); + // There should only be one handler registered per class for the reuse case. + if(registeredHandlers != null && registeredHandlers.size() == 1) { + // get(0) is safe due to size check above. + return registeredHandlers.get(0); + } + return null; + } +} diff --git a/org.fortiss.tooling.ext.reuse/src/org/fortiss/tooling/ext/reuse/utils/.ratings b/org.fortiss.tooling.ext.reuse/src/org/fortiss/tooling/ext/reuse/utils/.ratings index a833b1ee79e3a02b318cf0995364da436d7cb010..057c46b39ea433f028a245341f79595924c76f94 100644 --- a/org.fortiss.tooling.ext.reuse/src/org/fortiss/tooling/ext/reuse/utils/.ratings +++ b/org.fortiss.tooling.ext.reuse/src/org/fortiss/tooling/ext/reuse/utils/.ratings @@ -1,3 +1,3 @@ ReuseLibraryModelElementFactory.java 4ee3eb7449e212643992a3dec6cfb8f4278efb70 GREEN ReuseLibraryUtilsBasics.java 1d60936f98bd09e1ba1715192f5263f89b4942fe GREEN -ReuseLibraryUtilsManipulation.java 77a646db5a63ba7c61664dbcaf34a9036003fde5 GREEN +ReuseLibraryUtilsManipulation.java fbb36279eb20cb46a4f2b79fed33dd5395d6da3e GREEN diff --git a/org.fortiss.tooling.ext.reuse/src/org/fortiss/tooling/ext/reuse/utils/ReuseLibraryUtilsManipulation.java b/org.fortiss.tooling.ext.reuse/src/org/fortiss/tooling/ext/reuse/utils/ReuseLibraryUtilsManipulation.java index 77a646db5a63ba7c61664dbcaf34a9036003fde5..fbb36279eb20cb46a4f2b79fed33dd5395d6da3e 100644 --- a/org.fortiss.tooling.ext.reuse/src/org/fortiss/tooling/ext/reuse/utils/ReuseLibraryUtilsManipulation.java +++ b/org.fortiss.tooling.ext.reuse/src/org/fortiss/tooling/ext/reuse/utils/ReuseLibraryUtilsManipulation.java @@ -1,5 +1,5 @@ /*-------------------------------------------------------------------------+ -| Copyright 2022 fortiss GmbH | +| Copyright 2023 fortiss GmbH | | | | Licensed under the Apache License, Version 2.0 (the "License"); | | you may not use this file except in compliance with the License. | @@ -22,6 +22,16 @@ import static org.fortiss.tooling.ext.reuse.storage.ReuseLibraryStorageManager.d import static org.fortiss.tooling.ext.reuse.storage.ReuseLibraryStorageManager.saveReuseLibrary; import static org.fortiss.tooling.ext.reuse.utils.ReuseLibraryModelElementFactory.createReuseElementSpec; import static org.fortiss.tooling.ext.reuse.utils.ReuseLibraryModelElementFactory.createReuseLibrary; +import static org.fortiss.tooling.ext.reuse.utils.ReuseLibraryUtilsBasics.getAllReuseSpecs; +import static org.fortiss.tooling.ext.reuse.utils.ReuseLibraryUtilsBasics.getDateAsString; +import static org.fortiss.tooling.ext.reuse.utils.ReuseLibraryUtilsBasics.getFirstReuseElementUUID; +import static org.fortiss.tooling.ext.reuse.utils.ReuseLibraryUtilsBasics.getFirstSourceLibraryOfElement; +import static org.fortiss.tooling.ext.reuse.utils.ReuseLibraryUtilsBasics.getReuseElementName; +import static org.fortiss.tooling.ext.reuse.utils.ReuseLibraryUtilsBasics.getReuseElementUUIDForLibrary; +import static org.fortiss.tooling.ext.reuse.utils.ReuseLibraryUtilsBasics.getReuseSpecLinkedToThisLibraryElement; +import static org.fortiss.tooling.ext.reuse.utils.ReuseLibraryUtilsBasics.setReuseElementComment; +import static org.fortiss.tooling.ext.reuse.utils.ReuseLibraryUtilsBasics.setReuseElementLastUpdateNow; +import static org.fortiss.tooling.ext.reuse.utils.ReuseLibraryUtilsBasics.setReuseElementName; import static org.fortiss.tooling.kernel.utils.EcoreUtils.copy; import static org.fortiss.tooling.kernel.utils.EcoreUtils.getAllReferencesSetting; import static org.fortiss.tooling.kernel.utils.EcoreUtils.replaceEObjectReferences; @@ -62,11 +72,12 @@ public class ReuseLibraryUtilsManipulation { * Fixes the IDs of the model containing the given {@link EObject}, since * updating reuse elements can produce duplicated IDs. * - * @param element A reuse element of the model + * @param element + * A reuse element of the model */ public static void fixIDs(EObject element) { EObject root = element; - while (root.eContainer() != null) { + while(root.eContainer() != null) { root = root.eContainer(); } removeDuplicateIds(root); @@ -79,14 +90,16 @@ public class ReuseLibraryUtilsManipulation { * changes between reuse elements with the same origin. Returns null if given * element is invalid (e.g. not a reuse element). * - * @param element The element of which a hash code should be created - * @param modifyDate The date of the last update/modification of the given - * element + * @param element + * The element of which a hash code should be created + * @param modifyDate + * The date of the last update/modification of the given + * element * @return String of the created hash code integer (or null for an invalid * input) */ public static String createReuseHashAsString(EObject element, ZonedDateTime modifyDate) { - if (element != null && modifyDate != null) { + if(element != null && modifyDate != null) { // hashCode() does not change through element differences caused by simple // changes like name or new ports, etc. // Therefore, we are currently modifying the hash with the date of the last @@ -94,8 +107,7 @@ public class ReuseLibraryUtilsManipulation { // e.g. if the original reuse element in the library was updated by someone else // in the meantime). int hash = element.hashCode(); - String hashString = String.valueOf(hash) + "__" - + ReuseLibraryUtilsBasics.getDateAsString(modifyDate, false); + String hashString = String.valueOf(hash) + "__" + getDateAsString(modifyDate, false); return hashString; } return null; @@ -112,24 +124,27 @@ public class ReuseLibraryUtilsManipulation { * compare() method that returns 0 if both given {@link IConnector}s are * matching, otherwise +/-1. * - * @param target The target element (e.g. the replaced - * element) - * @param source The source element (e.g. the replacing - * element) - * @param connectorMatchComparator A comparator that will return 0 with - * compare() if both given {@link IConnector}s - * are matching + * @param target + * The target element (e.g. the replaced + * element) + * @param source + * The source element (e.g. the replacing + * element) + * @param connectorMatchComparator + * A comparator that will return 0 with + * compare() if both given {@link IConnector}s + * are matching */ - public static void removeNonMatchingConnections(IHierarchicElement target, IHierarchicElement source, - Comparator<IConnector> connectorMatchComparator) { + public static void removeNonMatchingConnections(IHierarchicElement target, + IHierarchicElement source, Comparator<IConnector> connectorMatchComparator) { IConnector matchedConnector = null; - for (IConnector targetConnector : target.getConnectors()) { + for(IConnector targetConnector : target.getConnectors()) { // check if a matching connector can be found boolean saveConnections = false; - for (IConnector sourceConnector : source.getConnectors()) { + for(IConnector sourceConnector : source.getConnectors()) { // matching is done via custom compare method (individual comparators possible) - if (connectorMatchComparator.compare(targetConnector, sourceConnector) == 0) { + if(connectorMatchComparator.compare(targetConnector, sourceConnector) == 0) { matchedConnector = sourceConnector; saveConnections = true; replaceEObjectReferences(targetConnector, matchedConnector); @@ -139,27 +154,27 @@ public class ReuseLibraryUtilsManipulation { // remove all connections or replace one end of them if a match was found List<IConnection> connectionsToBeRemoved = new ArrayList<IConnection>(); - for (IConnection incoming : targetConnector.getIncoming()) { - if (saveConnections) { + for(IConnection incoming : targetConnector.getIncoming()) { + if(saveConnections) { incoming.setTarget(matchedConnector); } else { connectionsToBeRemoved.add(incoming); } } - for (IConnection outgoing : targetConnector.getOutgoing()) { - if (saveConnections) { + for(IConnection outgoing : targetConnector.getOutgoing()) { + if(saveConnections) { outgoing.setSource(matchedConnector); } else { connectionsToBeRemoved.add(outgoing); } } - for (IConnection connection : connectionsToBeRemoved) { + for(IConnection connection : connectionsToBeRemoved) { delete(connection); } // delete all external references - if (!saveConnections) { - for (Setting setting : getAllReferencesSetting(targetConnector)) { + if(!saveConnections) { + for(Setting setting : getAllReferencesSetting(targetConnector)) { delete(setting.getEObject()); } } @@ -169,46 +184,54 @@ public class ReuseLibraryUtilsManipulation { /** * Setups a given reuse element for its placement inside a {@link ReuseLibrary}. * - * @param element The target reuse element - * @param connectingSpec The reuse specification used as link/trace/reference + * @param element + * The target reuse element + * @param connectingSpec + * The reuse specification used as link/trace/reference */ - public static void setupElementForLibrary(IModelElement element, ReuseElementSpec connectingSpec) { - // currently, it is needed that only the original specification for this library - // should exist (and also only the newest one) -> remove all others - for (ReuseElementSpec spec : ReuseLibraryUtilsBasics.getAllReuseSpecs(element)) { - if (!(connectingSpec.getElementUUID().equals(spec.getElementUUID()) - && connectingSpec.getLastUpdate().equals(spec.getLastUpdate()))) { + public static void setupElementForLibrary(IModelElement element, + ReuseElementSpec connectingSpec) { + // Currently, it is needed that only the original specification for this library + // should exist (and also only the newest one) -> remove all others. + for(ReuseElementSpec spec : getAllReuseSpecs(element)) { + if(!(connectingSpec.getElementUUID().equals(spec.getElementUUID()) && + connectingSpec.getLastUpdate().equals(spec.getLastUpdate()))) { element.getSpecifications().remove(spec); } } + // Execute all other more specific preparations (type dependent). + IReuseProviderService.getInstance().prepareReuseElementForLibrary(element); } /** * Creates a reuse element based on a given {@link EObject} for its placement * inside a {@link ReuseLibrary}. * - * @param originalElement The original element that should be used as base for - * the new reuse element - * @param library The reuse library in which the new reuse element - * should be added (later) - * @param saveName The name of the new reuse element with which it should - * be saved in the library + * @param originalElement + * The original element that should be used as base for + * the new reuse element + * @param library + * The reuse library in which the new reuse element + * should be added (later) + * @param saveName + * The name of the new reuse element with which it should + * be saved in the library * * @return The created reuse element for the library */ - public static EObject createElementForLibrary(EObject originalElement, ReuseLibrary library, String saveName) { + public static EObject createElementForLibrary(EObject originalElement, ReuseLibrary library, + String saveName) { // add to the original element a reuse reference to the new library // (cast is safe: elements within the ReuseElementList are always IModelElement // by design) - ReuseElementSpec spec = ReuseLibraryUtilsManipulation.addReuseSpecToElement((IModelElement) originalElement, - library); + ReuseElementSpec spec = addReuseSpecToElement((IModelElement)originalElement, library); spec.setElementName(saveName); - ReuseLibraryUtilsManipulation.fixIDs(originalElement); + fixIDs(originalElement); // copy, because origin should still exist further (but change name of copy) EObject newElementForLibrary = copy(originalElement); - ReuseLibraryUtilsBasics.setReuseElementName(newElementForLibrary, saveName); - setupElementForLibrary((IModelElement) newElementForLibrary, spec); + setReuseElementName(newElementForLibrary, saveName); + setupElementForLibrary((IModelElement)newElementForLibrary, spec); return newElementForLibrary; } @@ -217,11 +240,14 @@ public class ReuseLibraryUtilsManipulation { * Adds a {@link ReuseElementSpec} to the given element pointing to the given * {@link ReuseLibrary} (as source). * - * @param element The target reuse element - * @param library The connected reuse library + * @param element + * The target reuse element + * @param library + * The connected reuse library * @return The created reuse specification */ - public static ReuseElementSpec addReuseSpecToElement(IModelElement element, ReuseLibrary library) { + public static ReuseElementSpec addReuseSpecToElement(IModelElement element, + ReuseLibrary library) { ReuseElementSpec spec = createReuseElementSpec(element, library); element.getSpecifications().add(spec); return spec; @@ -230,12 +256,15 @@ public class ReuseLibraryUtilsManipulation { /** * Adds a given element to the given {@link ReuseLibrary}. * - * @param element The reuse element that should be added - * @param library The target reuse library + * @param element + * The reuse element that should be added + * @param library + * The target reuse library * @throws IOException * @throws CoreException */ - public static void addElementToLibrary(EObject element, ReuseLibrary library) throws IOException, CoreException { + public static void addElementToLibrary(EObject element, ReuseLibrary library) + throws IOException, CoreException { library.getReuseElementList().add(element); saveReuseLibrary(library); } @@ -244,15 +273,15 @@ public class ReuseLibraryUtilsManipulation { * Creates a new {@link ReuseLibrary} with the given name. If no name is * received, the default library name will be used. * - * @param libraryName The name of the new reuse library + * @param libraryName + * The name of the new reuse library * @return The requested reuse library */ public static ReuseLibrary createAndAddReuseLibrary(String libraryName) { - if (libraryName == null || libraryName.equals("")) { + if(libraryName == null || libraryName.equals("")) { return createReuseLibrary(); - } else { - return createReuseLibrary(libraryName); } + return createReuseLibrary(libraryName); } /** @@ -261,15 +290,19 @@ public class ReuseLibraryUtilsManipulation { * given name in the end). The {@link ReuseElementSpec} references the original * element (with its library). * - * @param originalElementInLibrary The target reuse element inside a reuse - * library that should be replace by the new - * reuse element - * @param newElement The new reuse element which is the - * replacement of the current element in the - * given library - * @param referencingSpec The reuse specification that points to the - * original reuse element in the library - * @param newName The new name of the element after replacement + * @param originalElementInLibrary + * The target reuse element inside a reuse + * library that should be replace by the new + * reuse element + * @param newElement + * The new reuse element which is the + * replacement of the current element in the + * given library + * @param referencingSpec + * The reuse specification that points to the + * original reuse element in the library + * @param newName + * The new name of the element after replacement */ public static void replaceElementInLibrary(EObject originalElementInLibrary, EObject newElement, ReuseElementSpec referencingSpec, String newName) { @@ -278,11 +311,11 @@ public class ReuseLibraryUtilsManipulation { ZonedDateTime now = ZonedDateTime.now(); referencingSpec.setLastUpdate(now); referencingSpec.setElementName(newName); - referencingSpec.setElementHash(ReuseLibraryUtilsManipulation.createReuseHashAsString(newElement, now)); + referencingSpec.setElementHash(createReuseHashAsString(newElement, now)); EObject newLibraryElement = copy(newElement); - ReuseLibraryUtilsBasics.setReuseElementName(newLibraryElement, newName); - setupElementForLibrary((IModelElement) newLibraryElement, referencingSpec); + setReuseElementName(newLibraryElement, newName); + setupElementForLibrary((IModelElement)newLibraryElement, referencingSpec); replace(originalElementInLibrary, newLibraryElement); } @@ -293,54 +326,59 @@ public class ReuseLibraryUtilsManipulation { * the given name in the end). Returns the new element in the project if the * replacement/update was successful, otherwise null. * - * @param elementInProject The new reuse element which is the - * replacement of the current element in the - * given library - * @param originalElementInLibrary The target reuse element inside a reuse - * library that should be replace by the new - * reuse element - * @param newName The new name of the element after - * replacement - * @param overrideAdditionalReferences Flag whether all other possibly existing - * references in the (old) project element - * should be overridden/deleted (true) or if - * they should be kept (false) + * @param elementInProject + * The new reuse element which is the + * replacement of the current element in the + * given library + * @param originalElementInLibrary + * The target reuse element inside a reuse + * library that should be replace by the new + * reuse element + * @param newName + * The new name of the element after + * replacement + * @param keepAdditionalReferences + * Flag whether all other possibly existing + * references in the (old) project element + * should be overridden/deleted (false) or if + * they should be kept (true) * * @return The new element in the project if the replacement/update was * successful, otherwise null. */ - public static EObject replaceElementInProject(EObject elementInProject, EObject originalElementInLibrary, - String newName, boolean keepAdditionalReferences) { - if (originalElementInLibrary instanceof IModelElement && elementInProject instanceof IModelElement) { - IModelElement sourceElement = copy((IModelElement) originalElementInLibrary); - IModelElement modelElementInProject = (IModelElement) elementInProject; + public static EObject replaceElementInProject(EObject elementInProject, + EObject originalElementInLibrary, String newName, boolean keepAdditionalReferences) { + if(originalElementInLibrary instanceof IModelElement && + elementInProject instanceof IModelElement) { + IModelElement sourceElement = copy((IModelElement)originalElementInLibrary); + IModelElement modelElementInProject = (IModelElement)elementInProject; // first, the information of the reference and the new element // needs to be updated and set up - List<ReuseElementSpec> specs = ReuseLibraryUtilsBasics.getAllReuseSpecs(sourceElement); + List<ReuseElementSpec> specs = getAllReuseSpecs(sourceElement); ZonedDateTime now = ZonedDateTime.now(); - if (specs.size() == 1) { + if(specs.size() == 1) { // get(0) is safe due to size check specs.get(0).setLastUpdate(now); } else { return null; } - ReuseLibraryUtilsBasics.setReuseElementName(sourceElement, newName); + setReuseElementName(sourceElement, newName); // if additional references should not be overridden but kept, they need to be // saved/added in the source element (otherwise they will be overridden anyway) - if (keepAdditionalReferences) { - List<ReuseElementSpec> oldSpecs = ReuseLibraryUtilsBasics.getAllReuseSpecs(modelElementInProject); + if(keepAdditionalReferences) { + List<ReuseElementSpec> oldSpecs = getAllReuseSpecs(modelElementInProject); // remove the specification of the current update/replacement (only additional // ones added) - ReuseElementSpec mainSpec = ReuseLibraryUtilsBasics - .getReuseSpecLinkedToThisLibraryElement(modelElementInProject, sourceElement); + ReuseElementSpec mainSpec = getReuseSpecLinkedToThisLibraryElement( + modelElementInProject, sourceElement); oldSpecs.remove(mainSpec); sourceElement.getSpecifications().addAll(oldSpecs); } - boolean success = IReuseProviderService.getInstance().updateReuseElement(modelElementInProject, - sourceElement); - if (success) { + boolean success = IReuseProviderService.getInstance() + .updateReuseElement(modelElementInProject, sourceElement); + if(success) { return sourceElement; } } @@ -350,16 +388,17 @@ public class ReuseLibraryUtilsManipulation { /** * Deletes the given {@link ReuseLibrary}. * - * @param library The target reuse library that should be deleted + * @param library + * The target reuse library that should be deleted */ public static void deleteReuseLibrary(ReuseLibrary library) { // currently, everything is based only on the reuse folder/file structure, which // is why it is enough to just delete the local folder try { deleteReuseLibraryFolder(library); - } catch (CoreException e) { + } catch(CoreException e) { error(getDefault(), "Error during deleting reuse library folder", e); - showError("Cannot delete reuse library: " + ReuseLibraryUtilsBasics.getReuseElementName(library)); + showError("Cannot delete reuse library: " + getReuseElementName(library)); } } @@ -367,32 +406,35 @@ public class ReuseLibraryUtilsManipulation { * Deletes the given reuse element by deleting its entry in the local file of * the given {@link ReuseLibrary} (if it exists there). * - * @param element The target reuse element that should be deleted - * @param sourceLibrary The reuse library in which the deletion should happen + * @param element + * The target reuse element that should be deleted + * @param sourceLibrary + * The reuse library in which the deletion should happen */ - public static void deleteReuseElementInLibraryFile(EObject element, ReuseLibrary sourceLibrary) { + public static void deleteReuseElementInLibraryFile(EObject element, + ReuseLibrary sourceLibrary) { // the objects might not be the same anymore, which is why we need to identify // the correct object via the reuse UUID EObject correctLibraryElement = null; EList<EObject> libraryElementList = sourceLibrary.getReuseElementList(); - for (EObject libraryElement : libraryElementList) { - if (ReuseLibraryUtilsBasics.getFirstReuseElementUUID(libraryElement) - .equals(ReuseLibraryUtilsBasics.getReuseElementUUIDForLibrary(element, sourceLibrary))) { + for(EObject libraryElement : libraryElementList) { + if(getFirstReuseElementUUID(libraryElement) + .equals(getReuseElementUUIDForLibrary(element, sourceLibrary))) { correctLibraryElement = libraryElement; break; } } - if (correctLibraryElement == null) { + if(correctLibraryElement == null) { return; } libraryElementList.remove(correctLibraryElement); try { saveReuseLibrary(sourceLibrary); - } catch (IOException | CoreException e) { + } catch(IOException | CoreException e) { error(getDefault(), "Error during removing reuse element from reuse library", e); - showError("Cannot remove reuse element: " + ReuseLibraryUtilsBasics.getReuseElementName(element) - + " from this reuse library: " + ReuseLibraryUtilsBasics.getReuseElementName(sourceLibrary)); + showError("Cannot remove reuse element: " + getReuseElementName(element) + + " from this reuse library: " + getReuseElementName(sourceLibrary)); } } @@ -401,11 +443,12 @@ public class ReuseLibraryUtilsManipulation { * the {@link ReuseLibrary} that is mentioned as first (or only) source library * for this reuse element (in its {link ReuseElementSpec}s). * - * @param element The target reuse element that should be deleted + * @param element + * The target reuse element that should be deleted */ public static void deleteReuseElementInLibraryFile(EObject element) { - ReuseLibrary sourceLibrary = ReuseLibraryUtilsBasics.getFirstSourceLibraryOfElement(element); - if (sourceLibrary != null) { + ReuseLibrary sourceLibrary = getFirstSourceLibraryOfElement(element); + if(sourceLibrary != null) { deleteReuseElementInLibraryFile(element, sourceLibrary); } } @@ -417,71 +460,73 @@ public class ReuseLibraryUtilsManipulation { * {@link ReuseLibrary} is where the reuse element will be updated with the new * name. * - * @param element The target reuse element that should be updated - * @param newName The new name as string - * @param sourceLibrary The reuse library in which the update should happen + * @param element + * The target reuse element that should be updated + * @param newName + * The new name as string + * @param sourceLibrary + * The reuse library in which the update should happen */ - public static void updateReuseElementFileWithName(EObject element, String newName, ReuseLibrary sourceLibrary) { - if (element == null || newName == null || newName.isBlank()) { + public static void updateReuseElementFileWithName(EObject element, String newName, + ReuseLibrary sourceLibrary) { + if(element == null || newName == null || newName.isBlank()) { return; } boolean modifiedLibrary = false; ReuseLibrary libraryForDeletion = null; String errorObject = ""; - if (element instanceof ReuseLibrary) { + if(element instanceof ReuseLibrary) { // since the folder and file names of a reuse library contain the library name // (beside its UUID), the easiest way to rename it is to save it as new library // (where only the name is changed, not UUID, etc.) and delete its previous // library folder (save and deletion are done at the end of this method) - sourceLibrary = (ReuseLibrary) element; + sourceLibrary = (ReuseLibrary)element; // copy, because origin should still exist further for deletion libraryForDeletion = copy(sourceLibrary); - ReuseLibraryUtilsBasics.setReuseElementName(sourceLibrary, newName); - for (EObject libraryElement : sourceLibrary.getReuseElementList()) { + setReuseElementName(sourceLibrary, newName); + for(EObject libraryElement : sourceLibrary.getReuseElementList()) { // cast is safe: elements within the ReuseElementList are always IModelElement // by design - List<ReuseElementSpec> specList = ReuseLibraryUtilsBasics - .getAllReuseSpecs((IModelElement) libraryElement); - for (ReuseElementSpec reuseSpec : specList) { + List<ReuseElementSpec> specList = getAllReuseSpecs(libraryElement); + for(ReuseElementSpec reuseSpec : specList) { reuseSpec.setSourceLibName(newName); } } - errorObject = "reuse library '" + ReuseLibraryUtilsBasics.getReuseElementName(sourceLibrary) + "'"; + errorObject = "reuse library '" + getReuseElementName(sourceLibrary) + "'"; modifiedLibrary = true; } else { // the objects might not be the same anymore, which is why we need to identify // the correct object via the reuse UUID - for (EObject libraryElement : sourceLibrary.getReuseElementList()) { - if (ReuseLibraryUtilsBasics.getFirstReuseElementUUID(libraryElement) - .equals(ReuseLibraryUtilsBasics.getReuseElementUUIDForLibrary(element, sourceLibrary))) { - ReuseLibraryUtilsBasics.setReuseElementName(libraryElement, newName); + for(EObject libraryElement : sourceLibrary.getReuseElementList()) { + if(getFirstReuseElementUUID(libraryElement) + .equals(getReuseElementUUIDForLibrary(element, sourceLibrary))) { + setReuseElementName(libraryElement, newName); // cast is safe: elements within the ReuseElementList are always IModelElement // by design - List<ReuseElementSpec> specList = ReuseLibraryUtilsBasics - .getAllReuseSpecs((IModelElement) libraryElement); - for (ReuseElementSpec reuseSpec : specList) { + List<ReuseElementSpec> specList = getAllReuseSpecs(libraryElement); + for(ReuseElementSpec reuseSpec : specList) { reuseSpec.setElementName(newName); } - ReuseLibraryUtilsBasics.setReuseElementLastUpdateNow(libraryElement); + setReuseElementLastUpdateNow(libraryElement); - errorObject = "reuse element '" + ReuseLibraryUtilsBasics.getReuseElementName(libraryElement) - + "' in reuse library '" + ReuseLibraryUtilsBasics.getReuseElementName(sourceLibrary) + "'"; + errorObject = "reuse element '" + getReuseElementName(libraryElement) + + "' in reuse library '" + getReuseElementName(sourceLibrary) + "'"; modifiedLibrary = true; break; } } } - if (modifiedLibrary) { + if(modifiedLibrary) { try { saveReuseLibrary(sourceLibrary); - if (libraryForDeletion != null) { + if(libraryForDeletion != null) { deleteReuseLibraryFolder(libraryForDeletion); } - } catch (IOException | CoreException e) { + } catch(IOException | CoreException e) { error(getDefault(), "Error during renaming " + errorObject, e); showError("Cannot rename " + errorObject); } @@ -495,15 +540,17 @@ public class ReuseLibraryUtilsManipulation { * {@link ReuseLibrary}, which is mentioned in its {link ReuseElementSpec}s, is * where the reuse element will be updated with the new name. * - * @param element The target reuse element that should be updated - * @param newName The new name as string + * @param element + * The target reuse element that should be updated + * @param newName + * The new name as string */ public static void updateReuseElementFileWithName(EObject element, String newName) { - if (element instanceof ReuseLibrary) { + if(element instanceof ReuseLibrary) { updateReuseElementFileWithName(element, newName, null); } else { - ReuseLibrary sourceLibrary = ReuseLibraryUtilsBasics.getFirstSourceLibraryOfElement(element); - if (sourceLibrary != null) { + ReuseLibrary sourceLibrary = getFirstSourceLibraryOfElement(element); + if(sourceLibrary != null) { updateReuseElementFileWithName(element, newName, sourceLibrary); } } @@ -516,42 +563,45 @@ public class ReuseLibraryUtilsManipulation { * {@link ReuseLibrary} is where the reuse element will be updated with the new * comment. * - * @param element The target reuse element that should be updated - * @param newComment The new comment as string - * @param sourceLibrary The reuse library in which the update should happen + * @param element + * The target reuse element that should be updated + * @param newComment + * The new comment as string + * @param sourceLibrary + * The reuse library in which the update should happen */ public static void updateReuseElementFileWithComment(EObject element, String newComment, ReuseLibrary sourceLibrary) { boolean modifiedLibrary = false; String errorObject = ""; - if (element instanceof ReuseLibrary) { - sourceLibrary = (ReuseLibrary) element; - ReuseLibraryUtilsBasics.setReuseElementComment(sourceLibrary, newComment); + if(element instanceof ReuseLibrary) { + sourceLibrary = (ReuseLibrary)element; + setReuseElementComment(sourceLibrary, newComment); - errorObject = "reuse library '" + ReuseLibraryUtilsBasics.getReuseElementName(sourceLibrary) + "'"; + errorObject = "reuse library '" + getReuseElementName(sourceLibrary) + "'"; modifiedLibrary = true; } else { // the objects might not be the same anymore, which is why we need to identify // the correct object via the reuse UUID EList<EObject> libraryElementList = sourceLibrary.getReuseElementList(); - for (EObject libraryElement : libraryElementList) { - if (ReuseLibraryUtilsBasics.getFirstReuseElementUUID(libraryElement) - .equals(ReuseLibraryUtilsBasics.getReuseElementUUIDForLibrary(element, sourceLibrary))) { - ReuseLibraryUtilsBasics.setReuseElementComment(libraryElement, newComment); - ReuseLibraryUtilsBasics.setReuseElementLastUpdateNow(libraryElement); - - errorObject = "reuse element '" + ReuseLibraryUtilsBasics.getReuseElementName(libraryElement) - + "' in reuse library '" + ReuseLibraryUtilsBasics.getReuseElementName(sourceLibrary) + "'"; + for(EObject libraryElement : libraryElementList) { + if(getFirstReuseElementUUID(libraryElement) + .equals(getReuseElementUUIDForLibrary(element, sourceLibrary))) { + setReuseElementComment(libraryElement, newComment); + setReuseElementLastUpdateNow(libraryElement); + + errorObject = "reuse element '" + getReuseElementName(libraryElement) + + "' in reuse library '" + getReuseElementName(sourceLibrary) + "'"; modifiedLibrary = true; break; } } } - if (modifiedLibrary) { + if(modifiedLibrary) { try { saveReuseLibrary(sourceLibrary); - } catch (IOException | CoreException e) { + } catch(IOException | CoreException e) { error(getDefault(), "Error during modifying " + errorObject, e); showError("Cannot modify " + errorObject); } @@ -565,15 +615,17 @@ public class ReuseLibraryUtilsManipulation { * {@link ReuseLibrary}, which is mentioned in its {link ReuseElementSpec}s, is * where the reuse element will be updated with the new comment. * - * @param element The target reuse element that should be updated - * @param newComment The new comment as string + * @param element + * The target reuse element that should be updated + * @param newComment + * The new comment as string */ public static void updateReuseElementFileWithComment(EObject element, String newComment) { - if (element instanceof ReuseLibrary) { + if(element instanceof ReuseLibrary) { updateReuseElementFileWithComment(element, newComment, null); } else { - ReuseLibrary sourceLibrary = ReuseLibraryUtilsBasics.getFirstSourceLibraryOfElement(element); - if (sourceLibrary != null) { + ReuseLibrary sourceLibrary = getFirstSourceLibraryOfElement(element); + if(sourceLibrary != null) { updateReuseElementFileWithComment(element, newComment, sourceLibrary); } }