diff --git a/org.fortiss.tooling.base.ui/src/org/fortiss/tooling/base/ui/utils/ContextMenuUtils.java b/org.fortiss.tooling.base.ui/src/org/fortiss/tooling/base/ui/utils/ContextMenuUtils.java index ebe9cdc0b96aeaed0852b52f7fa09ad1bd7fc42b..c14d461a933c0dd260c54193cfa156eac95aec63 100644 --- a/org.fortiss.tooling.base.ui/src/org/fortiss/tooling/base/ui/utils/ContextMenuUtils.java +++ b/org.fortiss.tooling.base.ui/src/org/fortiss/tooling/base/ui/utils/ContextMenuUtils.java @@ -16,6 +16,7 @@ package org.fortiss.tooling.base.ui.utils; import static org.fortiss.tooling.base.utils.LayoutModelElementFactory.createPoint; +import static org.fortiss.tooling.ext.reuse.utils.ReuseLibraryUtilsBasics.getNameOfFirstRelatedLibrary; import static org.fortiss.tooling.ext.reuse.utils.ReuseLibraryUtilsBasics.isCorrectReuseElement; import java.util.ArrayList; @@ -90,7 +91,8 @@ public final class ContextMenuUtils { }); if(isCorrectReuseElement(prototypeCopy)) { - // TODO 4323: add library name to item name + String libraryName = getNameOfFirstRelatedLibrary(prototypeCopy); + menuItem.setText("[" + libraryName + "] " + p.getName()); reuseMenu.getItems().add(menuItem); } else { newMenu.getItems().add(menuItem); 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 0037e17bc479904365d87a17f6aebae128fcc1e4..7e4e034ed11530b6239780988b172304ba046198 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 b651b31f6d94ff98a8f965440d662bfc4655c31b GREEN +ReuseLibraryUtilsBasics.java c5206709acec88ef1281a270472bc4cc1a8f7436 YELLOW ReuseLibraryUtilsManipulation.java 77a646db5a63ba7c61664dbcaf34a9036003fde5 GREEN diff --git a/org.fortiss.tooling.ext.reuse/src/org/fortiss/tooling/ext/reuse/utils/ReuseLibraryUtilsBasics.java b/org.fortiss.tooling.ext.reuse/src/org/fortiss/tooling/ext/reuse/utils/ReuseLibraryUtilsBasics.java index b651b31f6d94ff98a8f965440d662bfc4655c31b..c5206709acec88ef1281a270472bc4cc1a8f7436 100644 --- a/org.fortiss.tooling.ext.reuse/src/org/fortiss/tooling/ext/reuse/utils/ReuseLibraryUtilsBasics.java +++ b/org.fortiss.tooling.ext.reuse/src/org/fortiss/tooling/ext/reuse/utils/ReuseLibraryUtilsBasics.java @@ -53,13 +53,14 @@ public class ReuseLibraryUtilsBasics { /** * Returns whether the given element can be used as reuse element. * - * @param element The element that should be checked + * @param element + * The element that should be checked * @return True if the given element can be used as reuse element otherwise * false */ public static boolean hasReusePossibility(EObject element) { - for (Class<? extends EObject> cls : getReuseElementClasses()) { - if (cls.isInstance(element)) { + for(Class<? extends EObject> cls : getReuseElementClasses()) { + if(cls.isInstance(element)) { return true; } } @@ -70,19 +71,21 @@ public class ReuseLibraryUtilsBasics { * Returns whether the given element is a reuse element and has at least one * valid link to a {@link ReuseLibrary}. * - * @param element The element that should be checked + * @param element + * The element that should be checked * @return True if the given element is a reuse element, otherwise false */ public static boolean isCorrectReuseElement(EObject element) { // first, check if it is a (possible) reuse element in general - if (hasReusePossibility(element)) { + if(hasReusePossibility(element)) { // second, check if it has a library reference // (only then it is an actual (active) reuse element) - if (element instanceof IModelElement) { - for (IModelElementSpecification spec : ((IModelElement) element).getSpecifications()) { - if (spec instanceof ReuseElementSpec) { - String libID = ((ReuseElementSpec) spec).getSourceLibUUID(); - if (libID != null && !libID.isEmpty()) { + if(element instanceof IModelElement) { + for(IModelElementSpecification spec : ((IModelElement)element) + .getSpecifications()) { + if(spec instanceof ReuseElementSpec) { + String libID = ((ReuseElementSpec)spec).getSourceLibUUID(); + if(libID != null && !libID.isEmpty()) { return true; } } @@ -96,7 +99,8 @@ public class ReuseLibraryUtilsBasics { * Returns whether the given element is a reuse element and has at least one * valid link to a {@link ReuseLibrary} OR is a {@link ReuseLibrary} itself. * - * @param element The element that should be checked + * @param element + * The element that should be checked * @return True if the given element is a reuse element OR a reuse library, * otherwise false */ @@ -104,10 +108,47 @@ public class ReuseLibraryUtilsBasics { return (element instanceof ReuseLibrary) || isCorrectReuseElement(element); } + /** + * Returns display name and UUID of the first {@link ReuseLibrary} that is related to the + * given reuse element. If this is not the case, an empty {@link String} will be returned. This + * method is perfect for reuse elements within reuse libraries, because they have definitely + * only one connected/related library. + * + * @param element + * The reuse element whose library's name is searched + * @return Display name as string (with UUID!) or empty string + */ + public static String getIDNameOfFirstRelatedLibrary(EObject element) { + ReuseLibrary library = getFirstSourceLibraryOfElement(element); + if(library != null) { + return getLibraryIDName(library); + } + return ""; + } + + /** + * Returns display name of the first {@link ReuseLibrary} that is related to the given reuse + * element. If this is not the case, an empty {@link String} will be returned. This method is + * perfect for reuse elements within reuse libraries, because they have definitely only one + * connected/related library. + * + * @param element + * The reuse element whose library's name is searched + * @return Display name as string or empty string + */ + public static String getNameOfFirstRelatedLibrary(EObject element) { + ReuseLibrary library = getFirstSourceLibraryOfElement(element); + if(library != null) { + return library.getName(); + } + return ""; + } + /** * Returns display name of given {@link ReuseLibrary} (name and UUID). * - * @param library The target reuse library + * @param library + * The target reuse library * @return Display name as string */ public static String getLibraryIDName(ReuseLibrary library) { @@ -118,8 +159,10 @@ public class ReuseLibraryUtilsBasics { * Returns the current format for displaying name and UUID of * {@link ReuseLibrary}s. * - * @param libraryUUID The UUID of the target library - * @param libraryName The name of the target library + * @param libraryUUID + * The UUID of the target library + * @param libraryName + * The name of the target library * @return Formatted string */ public static String getLibraryIDNameFormat(String libraryUUID, String libraryName) { @@ -131,17 +174,18 @@ public class ReuseLibraryUtilsBasics { * {@link ReuseLibrary}), independent of the type as long as its class was * registered for reuse. * - * @param element The target reuse element + * @param element + * The target reuse element * @return Name as string */ public static String getReuseElementName(EObject element) { - if (element instanceof ReuseLibrary) { - return ((ReuseLibrary) element).getName(); + if(element instanceof ReuseLibrary) { + return ((ReuseLibrary)element).getName(); } String name = IReuseProviderService.getInstance().getReuseElementName(element); - if (name == null) { - if (element instanceof INamedElement) { - name = ((INamedElement) element).getName(); + if(name == null) { + if(element instanceof INamedElement) { + name = ((INamedElement)element).getName(); } else { name = element.toString(); } @@ -153,13 +197,15 @@ public class ReuseLibraryUtilsBasics { * Sets the name of the given reuse element (or {@link ReuseLibrary}), * independent of the type as long as its class was registered for reuse. * - * @param element The target reuse element - * @param name The new name + * @param element + * The target reuse element + * @param name + * The new name * @return True if action was successful, otherwise false */ public static boolean setReuseElementName(EObject element, String name) { - if (element instanceof ReuseLibrary) { - ((ReuseLibrary) element).setName(name); + if(element instanceof ReuseLibrary) { + ((ReuseLibrary)element).setName(name); return true; } return IReuseProviderService.getInstance().setReuseElementName(element, name); @@ -169,18 +215,19 @@ public class ReuseLibraryUtilsBasics { * Returns the comment of the given reuse element (or {@link ReuseLibrary}), * independent of the type as long as its class was registered for reuse. * - * @param element The target reuse element + * @param element + * The target reuse element * @return The requested comment as string */ public static String getReuseElementComment(EObject element) { String comment = null; - if (element instanceof ReuseLibrary) { - comment = ((ReuseLibrary) element).getComment(); + if(element instanceof ReuseLibrary) { + comment = ((ReuseLibrary)element).getComment(); } else { comment = IReuseProviderService.getInstance().getReuseElementComment(element); - if (comment == null) { - if (element instanceof INamedCommentedElement) { - comment = ((INamedCommentedElement) element).getComment(); + if(comment == null) { + if(element instanceof INamedCommentedElement) { + comment = ((INamedCommentedElement)element).getComment(); } } } @@ -191,13 +238,15 @@ public class ReuseLibraryUtilsBasics { * Sets the comment of the given reuse element (or {@link ReuseLibrary}), * independent of the type as long as its class was registered for reuse. * - * @param element The target reuse element - * @param comment The new comment + * @param element + * The target reuse element + * @param comment + * The new comment * @return True if action was successful, otherwise false */ public static boolean setReuseElementComment(EObject element, String comment) { - if (element instanceof ReuseLibrary) { - ((ReuseLibrary) element).setComment(comment); + if(element instanceof ReuseLibrary) { + ((ReuseLibrary)element).setComment(comment); return true; } return IReuseProviderService.getInstance().setReuseElementComment(element, comment); @@ -213,12 +262,13 @@ public class ReuseLibraryUtilsBasics { * {@link ReuseElementSpec}s and thus multiple UUIDs, because they could have * been added to several {@link ReuseLibrary}s. * - * @param element The target reuse element + * @param element + * The target reuse element * @return The requested UUID as string (or empty string) */ public static String getFirstReuseElementUUID(EObject element) { List<String> allUUIDs = getAllReuseElementUUID(element); - if (allUUIDs != null && !allUUIDs.isEmpty()) { + if(allUUIDs != null && !allUUIDs.isEmpty()) { // get(0) is safe due to check above return allUUIDs.get(0); } @@ -233,19 +283,18 @@ public class ReuseLibraryUtilsBasics { * {@link ReuseElementSpec}s and thus multiple UUIDs, because they could have * been added to several {@link ReuseLibrary}s. * - * @param element The target reuse element + * @param element + * The target reuse element * @return The requested UUID as string (or empty string) */ public static List<String> getAllReuseElementUUID(EObject element) { List<String> allUUIDs = new ArrayList<>(); - if (element instanceof ReuseLibrary) { - allUUIDs.add(((ReuseLibrary) element).getLibraryUUID()); + if(element instanceof ReuseLibrary) { + allUUIDs.add(((ReuseLibrary)element).getLibraryUUID()); } else { - if (element instanceof IModelElement) { - List<ReuseElementSpec> specs = getAllReuseSpecs((IModelElement) element); - for (ReuseElementSpec spec : specs) { - allUUIDs.add(spec.getElementUUID()); - } + List<ReuseElementSpec> specs = getAllReuseSpecs(element); + for(ReuseElementSpec spec : specs) { + allUUIDs.add(spec.getElementUUID()); } } return allUUIDs; @@ -257,18 +306,18 @@ public class ReuseLibraryUtilsBasics { * {@link ReuseLibrary}. If such a {@link ReuseElementSpec} does not exist, an * empty {@link String} will be returned. * - * @param element The target reuse element - * @param library The reuse library to which the reuse UUID of the element - * should belong + * @param element + * The target reuse element + * @param library + * The reuse library to which the reuse UUID of the element + * should belong * @return The requested UUID as string (or empty string) */ public static String getReuseElementUUIDForLibrary(EObject element, ReuseLibrary library) { - if (element instanceof IModelElement) { - List<ReuseElementSpec> specs = getAllReuseSpecs((IModelElement) element); - for (ReuseElementSpec spec : specs) { - if (spec.getSourceLibUUID().equals(library.getLibraryUUID())) { - return spec.getElementUUID(); - } + List<ReuseElementSpec> specs = getAllReuseSpecs(element); + for(ReuseElementSpec spec : specs) { + if(spec.getSourceLibUUID().equals(library.getLibraryUUID())) { + return spec.getElementUUID(); } } return ""; @@ -279,19 +328,20 @@ public class ReuseLibraryUtilsBasics { * a specific (given) {@link ReuseLibrary}. If it cannot be found, an empty * {@link String} will be returned. * - * @param element The target reuse element - * @param sourceLibrary The library of the original reuse element for the hash + * @param element + * The target reuse element + * @param sourceLibrary + * The library of the original reuse element for the hash * @return The requested hash code as string (or empty string) */ - public static String getReuseElementHashForLibrary(EObject element, ReuseLibrary sourceLibrary) { + public static String getReuseElementHashForLibrary(EObject element, + ReuseLibrary sourceLibrary) { String libraryUuid = sourceLibrary.getLibraryUUID(); - if (element instanceof IModelElement) { - List<ReuseElementSpec> specs = getAllReuseSpecs((IModelElement) element); - for (ReuseElementSpec spec : specs) { - String referenceLibraryUuid = spec.getSourceLibUUID(); - if (referenceLibraryUuid.equals(libraryUuid)) { - return spec.getElementHash(); - } + List<ReuseElementSpec> specs = getAllReuseSpecs(element); + for(ReuseElementSpec spec : specs) { + String referenceLibraryUuid = spec.getSourceLibUUID(); + if(referenceLibraryUuid.equals(libraryUuid)) { + return spec.getElementHash(); } } return ""; @@ -302,16 +352,15 @@ public class ReuseLibraryUtilsBasics { * {@link ZonedDateTime} as long as it has (already) a {@link ReuseElementSpec}. * If this is not the case, null will be returned. * - * @param element The target reuse element + * @param element + * The target reuse element * @return The requested (update) date (or null) */ public static ZonedDateTime getReuseElementLastUpdate(EObject element) { - if (element instanceof IModelElement) { - List<ReuseElementSpec> specs = getAllReuseSpecs((IModelElement) element); - if (specs != null && !specs.isEmpty()) { - // get(0) is safe due to check above - return specs.get(0).getLastUpdate(); - } + List<ReuseElementSpec> specs = getAllReuseSpecs(element); + if(specs != null && !specs.isEmpty()) { + // get(0) is safe due to check above + return specs.get(0).getLastUpdate(); } return null; } @@ -321,9 +370,11 @@ public class ReuseLibraryUtilsBasics { * {@link String} as long as it has (already) a {@link ReuseElementSpec}. If * this is not the case, an empty {@link String} will be returned. * - * @param element The target reuse element - * @param forDisplay If it should be the format for user display or the one that - * is internally used + * @param element + * The target reuse element + * @param forDisplay + * If it should be the format for user display or the one that + * is internally used * @return The requested (update) date as string (or empty string) */ public static String getReuseElementLastUpdateString(EObject element, boolean forDisplay) { @@ -335,18 +386,19 @@ public class ReuseLibraryUtilsBasics { * Returns the given {@link ZonedDateTime} as formatted {@link String} as long * as it is valid, otherwise an empty {@link String} will be returned. * - * @param date The date - * @param forDisplay If it should be the format for user display or the one that - * is internally used + * @param date + * The date + * @param forDisplay + * If it should be the format for user display or the one that + * is internally used * @return The requested date as string (or empty string) */ public static String getDateAsString(ZonedDateTime date, boolean forDisplay) { - if (date != null) { - if (forDisplay) { + if(date != null) { + if(forDisplay) { return DISPLAY_REUSE_DATE_FORMATTER.format(date); - } else { - return INTERNAL_REUSE_DATE_FORMATTER.format(date); } + return INTERNAL_REUSE_DATE_FORMATTER.format(date); } return ""; } @@ -355,14 +407,14 @@ public class ReuseLibraryUtilsBasics { * Sets the Last Update Date of the given reuse element with the given {link * Date} as long as it has (already) a {@link ReuseElementSpec}. * - * @param element The target reuse element - * @param newDate The new (update) date + * @param element + * The target reuse element + * @param newDate + * The new (update) date */ public static void setReuseElementLastUpdate(EObject element, ZonedDateTime newDate) { - if (element instanceof IModelElement) { - for (ReuseElementSpec spec : getAllReuseSpecs((IModelElement) element)) { - spec.setLastUpdate(newDate); - } + for(ReuseElementSpec spec : getAllReuseSpecs(element)) { + spec.setLastUpdate(newDate); } } @@ -370,7 +422,8 @@ public class ReuseLibraryUtilsBasics { * Sets the Last Update Date of the given reuse element with the current {link * ZonedDateTime} as long as it has (already) a {@link ReuseElementSpec}. * - * @param element The target reuse element + * @param element + * The target reuse element */ public static void setReuseElementLastUpdateNow(EObject element) { setReuseElementLastUpdate(element, ZonedDateTime.now()); @@ -380,32 +433,49 @@ public class ReuseLibraryUtilsBasics { * Returns all {@link ReuseElementSpec}s of the given element to a * {@link ReuseLibrary}. If none exist, an empty list will be returned. * - * @param element The target reuse element + * @param element + * The target reuse element * @return A list of all found reuse specifications (or empty list) */ - public static List<ReuseElementSpec> getAllReuseSpecs(IModelElement element) { + public static List<ReuseElementSpec> getAllReuseSpecs(EObject element) { List<ReuseElementSpec> specs = new ArrayList<>(); - for (IModelElementSpecification spec : element.getSpecifications()) { - if (spec instanceof ReuseElementSpec) { - // (cast is safe due to instance check) - specs.add((ReuseElementSpec) spec); + if(element instanceof IModelElement) { + for(IModelElementSpecification spec : ((IModelElement)element).getSpecifications()) { + if(spec instanceof ReuseElementSpec) { + // (cast is safe due to instance check) + specs.add((ReuseElementSpec)spec); + } } } return specs; } + /** + * Returns the first {@link ReuseElementSpec}s of the given element to a + * {@link ReuseLibrary}. If none exist, null will be returned. + * + * @param element + * The target reuse element + * @return The first reuse element specification (or null) + */ + public static ReuseElementSpec getFirstReuseSpecs(EObject element) { + List<ReuseElementSpec> specs = getAllReuseSpecs(element); + if(!specs.isEmpty()) { + // get(0) safe due to empty check above + return specs.get(0); + } + return null; + } + /** * Returns the number of all {@link ReuseElementSpec}s of the given element. * - * @param element The target reuse element + * @param element + * The target reuse element * @return Number of all found reuse specifications */ public static int getNumberOfContainedReuseSpecs(EObject element) { - if (element instanceof IModelElement) { - return getAllReuseSpecs((IModelElement) element).size(); - } else { - return 0; - } + return getAllReuseSpecs(element).size(); } /** @@ -413,24 +483,26 @@ public class ReuseLibraryUtilsBasics { * that is linked with the given reuse element inside a library. If none could * be found, null will be returned. * - * @param projectElement The reuse element inside a project from which the reuse - * specification should be selected - * @param libraryElement The reuse element inside a library + * @param projectElement + * The reuse element inside a project from which the reuse + * specification should be selected + * @param libraryElement + * The reuse element inside a library * @return The found/matched reuse specification (or null) */ - public static ReuseElementSpec getReuseSpecLinkedToThisLibraryElement(IModelElement projectElement, - IModelElement libraryElement) { + public static ReuseElementSpec getReuseSpecLinkedToThisLibraryElement( + IModelElement projectElement, IModelElement libraryElement) { List<ReuseElementSpec> projectSpecs = getAllReuseSpecs(projectElement); List<ReuseElementSpec> librarySpecs = getAllReuseSpecs(libraryElement); // elements in library must have only a single specification - if (librarySpecs.size() == 1) { + if(librarySpecs.size() == 1) { // get(0) is safe due to size check above ReuseElementSpec librarySpec = librarySpecs.get(0); - for (ReuseElementSpec specToBeChecked : projectSpecs) { + for(ReuseElementSpec specToBeChecked : projectSpecs) { // both UUIDs (of element and library) must be identical - if (specToBeChecked.getSourceLibUUID().equals(librarySpec.getSourceLibUUID()) - && specToBeChecked.getElementUUID().equals(librarySpec.getElementUUID())) { + if(specToBeChecked.getSourceLibUUID().equals(librarySpec.getSourceLibUUID()) && + specToBeChecked.getElementUUID().equals(librarySpec.getElementUUID())) { return specToBeChecked; } } @@ -457,12 +529,13 @@ public class ReuseLibraryUtilsBasics { * or file name is not correct (as long as it is in the reuse directory and has * the right UUID)! * - * @param libraryUUID The UUID of the requested reuse library + * @param libraryUUID + * The UUID of the requested reuse library * @return The requested reuse library (or null) */ public static ReuseLibrary getLocalReuseLibraryByID(String libraryUUID) { - for (ReuseLibrary library : getAllLocalReuseLibraries()) { - if (libraryUUID.equals(library.getLibraryUUID())) { + for(ReuseLibrary library : getAllLocalReuseLibraries()) { + if(libraryUUID.equals(library.getLibraryUUID())) { return library; } } @@ -477,17 +550,15 @@ public class ReuseLibraryUtilsBasics { * because it does not fetch all libraries - only the one of the first {link * ReuseElementSpec}. * - * @param element The target reuse element + * @param element + * The target reuse element * @return The requested reuse library (or null) */ public static ReuseLibrary getFirstSourceLibraryOfElement(EObject element) { - if (element instanceof IModelElement) { - List<ReuseElementSpec> specList = getAllReuseSpecs((IModelElement) element); - if (specList != null && !specList.isEmpty()) { - // get(0) is safe due to check above - String libraryUUID = specList.get(0).getSourceLibUUID(); - return getLocalReuseLibraryByID(libraryUUID); - } + ReuseElementSpec spec = getFirstReuseSpecs(element); + if(spec != null) { + String libraryUUID = spec.getSourceLibUUID(); + return getLocalReuseLibraryByID(libraryUUID); } return null; } @@ -497,19 +568,18 @@ public class ReuseLibraryUtilsBasics { * library in the {link ReuseElementSpec}s of the given reuse element. If no * {link ReuseElementSpec} exists, the return will be an empty list. * - * @param element The target reuse element + * @param element + * The target reuse element * @return All found reuse libraries for the given element (or empty list) */ public static List<ReuseLibrary> getAllSourceLibrariesOfElement(EObject element) { List<ReuseLibrary> foundLibraries = new ArrayList<>(); - if (element instanceof IModelElement) { - List<ReuseElementSpec> reuseSpecs = getAllReuseSpecs((IModelElement) element); - for (ReuseElementSpec reuseSpec : reuseSpecs) { - String libraryUUID = reuseSpec.getSourceLibUUID(); - ReuseLibrary sourceLibrary = getLocalReuseLibraryByID(libraryUUID); - if (sourceLibrary != null) { - foundLibraries.add(sourceLibrary); - } + List<ReuseElementSpec> reuseSpecs = getAllReuseSpecs(element); + for(ReuseElementSpec reuseSpec : reuseSpecs) { + String libraryUUID = reuseSpec.getSourceLibUUID(); + ReuseLibrary sourceLibrary = getLocalReuseLibraryByID(libraryUUID); + if(sourceLibrary != null) { + foundLibraries.add(sourceLibrary); } } return foundLibraries; @@ -520,16 +590,19 @@ public class ReuseLibraryUtilsBasics { * referenced by the given {@link ReuseElementSpec}. Returns null if it could * not be found. * - * @param library The target reuse library - * @param elementUUID The UUID string of the requested element + * @param library + * The target reuse library + * @param elementUUID + * The UUID string of the requested element * @return The requested reuse element (or null) */ public static EObject getElementInsideLibrary(ReuseLibrary library, String elementUUID) { // find original element inside the library by identical UUID - for (EObject libraryElement : library.getReuseElementList()) { - for (IModelElementSpecification spec : ((IModelElement) libraryElement).getSpecifications()) { - if (spec instanceof ReuseElementSpec) { - if (((ReuseElementSpec) spec).getElementUUID().equals(elementUUID)) { + for(EObject libraryElement : library.getReuseElementList()) { + for(IModelElementSpecification spec : ((IModelElement)libraryElement) + .getSpecifications()) { + if(spec instanceof ReuseElementSpec) { + if(((ReuseElementSpec)spec).getElementUUID().equals(elementUUID)) { return libraryElement; } } @@ -543,14 +616,15 @@ public class ReuseLibraryUtilsBasics { * (e.g. an external stored function inside a code specification of a * component). If nothing was found, an empty list is returned. * - * @param element The target reuse element + * @param element + * The target reuse element * @return A list of external elements referencing the target reuse element (or * empty list) */ public static List<EObject> getExternalReferencesOfElement(EObject element) { List<EObject> references = new ArrayList<>(); - for (Class<? extends EObject> referenceClass : getPossibleExternalReferenceClasses()) { - for (EObject reference : getChildrenWithType(element, referenceClass)) { + for(Class<? extends EObject> referenceClass : getPossibleExternalReferenceClasses()) { + for(EObject reference : getChildrenWithType(element, referenceClass)) { references.add(reference); } } @@ -565,8 +639,9 @@ public class ReuseLibraryUtilsBasics { * {@link EObject} was reused based on the origin (i.e., the hash codes are * identical), an empty list will be returned. * - * @param element The element whose reuse origin(s) should be checked for - * updates + * @param element + * The element whose reuse origin(s) should be checked for + * updates * @return List of elements that are reuse origins and were updated in the * meantime */ @@ -575,14 +650,15 @@ public class ReuseLibraryUtilsBasics { List<ReuseLibrary> foundLibraries = getAllSourceLibrariesOfElement(element); - for (ReuseLibrary sourceLibrary : foundLibraries) { + for(ReuseLibrary sourceLibrary : foundLibraries) { String uuid = getReuseElementUUIDForLibrary(element, sourceLibrary); EObject originElementInLib = getElementInsideLibrary(sourceLibrary, uuid); String storedHashForThisLibrary = getReuseElementHashForLibrary(element, sourceLibrary); - String currentHashForThisLibrary = getReuseElementHashForLibrary(originElementInLib, sourceLibrary); + String currentHashForThisLibrary = + getReuseElementHashForLibrary(originElementInLib, sourceLibrary); // if hashes are valid but different, the origin was updated - if (!storedHashForThisLibrary.isEmpty() && !currentHashForThisLibrary.isEmpty()) { - if (!storedHashForThisLibrary.equals(currentHashForThisLibrary)) { + if(!storedHashForThisLibrary.isEmpty() && !currentHashForThisLibrary.isEmpty()) { + if(!storedHashForThisLibrary.equals(currentHashForThisLibrary)) { updatedOrigins.add(originElementInLib); } }