From 4f940aea1f04093cdc23d2f70bd66a329d49fb6d Mon Sep 17 00:00:00 2001 From: Pierre-Charles David Date: Thu, 4 Apr 2024 15:56:44 +0200 Subject: [PATCH 1/4] [146] Remove Guava dependency in oes.common Bug: https://github.com/eclipse-sirius/sirius-desktop/issues/146 Signed-off-by: Pierre-Charles David --- .../META-INF/MANIFEST.MF | 3 +- .../editing/FileStatusPrecommitListener.java | 73 +++++++------ .../interpreter/IInterpreterContextUtils.java | 8 +- .../interpreter/JavaExtensionsManager.java | 103 ++++++------------ .../tools/api/interpreter/VariableType.java | 28 +++-- .../tools/api/profiler/ProfilerTask.java | 11 +- .../api/resource/ResourceMigrationMarker.java | 7 +- .../tools/api/resource/ResourceSetSync.java | 42 +++---- .../common/tools/api/util/EclipseUtil.java | 16 ++- .../common/tools/api/util/EqualityHelper.java | 11 +- .../interpreter/BundleClassLoading.java | 21 ++-- .../interpreter/DefaultConverter.java | 14 +-- .../DefaultInterpreterProvider.java | 11 +- .../interpreter/FeatureInterpreter.java | 24 ++-- .../interpreter/MonomorphicService.java | 10 +- .../interpreter/PolymorphicService.java | 27 ++--- .../interpreter/ServiceInterpreter.java | 19 ++-- 17 files changed, 182 insertions(+), 246 deletions(-) diff --git a/plugins/org.eclipse.sirius.common/META-INF/MANIFEST.MF b/plugins/org.eclipse.sirius.common/META-INF/MANIFEST.MF index 931b9ed15a..3423d2cdcb 100644 --- a/plugins/org.eclipse.sirius.common/META-INF/MANIFEST.MF +++ b/plugins/org.eclipse.sirius.common/META-INF/MANIFEST.MF @@ -5,8 +5,7 @@ Bundle-SymbolicName: org.eclipse.sirius.common;singleton:=true Bundle-Version: 7.4.3.qualifier Bundle-Vendor: %providerName Require-Bundle: org.eclipse.sirius.ecore.extender;bundle-version="2.0.0", - org.eclipse.emf.workspace;bundle-version="1.5.1", - com.google.guava;bundle-version="27.0" + org.eclipse.emf.workspace;bundle-version="1.5.1" Export-Package: org.eclipse.sirius.common.tools;version="3.0.0", org.eclipse.sirius.common.tools.api.constant;version="2.0.4", org.eclipse.sirius.common.tools.api.contentassist;version="2.1.0", diff --git a/plugins/org.eclipse.sirius.common/src/org/eclipse/sirius/common/tools/api/editing/FileStatusPrecommitListener.java b/plugins/org.eclipse.sirius.common/src/org/eclipse/sirius/common/tools/api/editing/FileStatusPrecommitListener.java index 312dc59e53..f88244fc9a 100644 --- a/plugins/org.eclipse.sirius.common/src/org/eclipse/sirius/common/tools/api/editing/FileStatusPrecommitListener.java +++ b/plugins/org.eclipse.sirius.common/src/org/eclipse/sirius/common/tools/api/editing/FileStatusPrecommitListener.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2007, 2011 THALES GLOBAL SERVICES. + * Copyright (c) 2007, 2024 THALES GLOBAL SERVICES and others. * This program and the accompanying materials * are made available under the terms of the Eclipse Public License 2.0 * which accompanies this distribution, and is available at @@ -13,6 +13,7 @@ package org.eclipse.sirius.common.tools.api.editing; import java.util.ArrayList; +import java.util.HashSet; import java.util.Iterator; import java.util.LinkedHashSet; import java.util.Set; @@ -39,10 +40,6 @@ import org.eclipse.sirius.common.tools.api.resource.FileModificationValidatorProvider; import org.eclipse.sirius.common.tools.api.resource.IFileModificationValidator; -import com.google.common.collect.BiMap; -import com.google.common.collect.HashBiMap; -import com.google.common.collect.Iterables; - /** * ResourceSetListener responsible for asking for file edit validation before * commits. @@ -59,7 +56,6 @@ public class FileStatusPrecommitListener extends ResourceSetListenerImpl { * Create a new listener. */ public FileStatusPrecommitListener() { - super(); fileModificationValidators = FileModificationValidatorProvider.INSTANCE.getFileModificationValidator(); } @@ -73,45 +69,22 @@ public boolean isAggregatePrecommitListener() { return true; } - /** - * {@inheritDoc} - */ @Override public Command transactionAboutToCommit(final ResourceSetChangeEvent event) throws RollbackException { - final boolean defensiveEditValidation = Platform.getPreferencesService().getBoolean("org.eclipse.sirius.common.ui", CommonPreferencesConstants.PREF_DEFENSIVE_EDIT_VALIDATION, true, null); //$NON-NLS-1$ - final Command cmd = super.transactionAboutToCommit(event); + boolean defensiveEditValidation = Platform.getPreferencesService().getBoolean("org.eclipse.sirius.common.ui", CommonPreferencesConstants.PREF_DEFENSIVE_EDIT_VALIDATION, true, null); //$NON-NLS-1$ + Command cmd = super.transactionAboutToCommit(event); if (defensiveEditValidation) { - final Set changedRes = new LinkedHashSet<>(); - if (!event.getTransaction().isReadOnly()) { - for (org.eclipse.emf.common.notify.Notification notif : Iterables.filter(event.getNotifications(), org.eclipse.emf.common.notify.Notification.class)) { - if (notif.getNotifier() instanceof EObject) { - final Resource res = ((EObject) notif.getNotifier()).eResource(); - if (resourceChange(res, notif)) { - changedRes.add(res); - } - } - } - } - - final BiMap files2Validate = HashBiMap.create(); - final Iterator it = changedRes.iterator(); - while (it.hasNext()) { - final Resource nextResource = it.next(); - final IFile file = WorkspaceSynchronizer.getFile(nextResource); - if (file != null && file.isReadOnly()) { - files2Validate.put(file, nextResource); - } - } - - if (!files2Validate.isEmpty()) { + Set changedRes = getModifiedResources(event); + Set filesToValidate = getFilesToValidate(changedRes); + if (!filesToValidate.isEmpty()) { final RollbackException cancelException = new RollbackException(new Status(IStatus.CANCEL, DslCommonPlugin.PLUGIN_ID, Messages.FileStatusPrecommitListener_fileModificationValidationStatus)); final MultiStatus status = new MultiStatus(DslCommonPlugin.PLUGIN_ID, IStatus.ERROR, Messages.FileStatusPrecommitListener_fileModificationValidationStatus, cancelException); if (fileModificationValidators.isEmpty()) { // No extension found, use the default process. - status.add(ResourcesPlugin.getWorkspace().validateEdit(files2Validate.keySet().toArray(new IFile[files2Validate.size()]), IWorkspace.VALIDATE_PROMPT)); + status.add(ResourcesPlugin.getWorkspace().validateEdit(filesToValidate.toArray(new IFile[filesToValidate.size()]), IWorkspace.VALIDATE_PROMPT)); } else { for (final IFileModificationValidator fileModificationValidator : fileModificationValidators) { - final IStatus validationStatus = fileModificationValidator.validateEdit(files2Validate.keySet()); + final IStatus validationStatus = fileModificationValidator.validateEdit(filesToValidate); if (validationStatus != null) { status.add(validationStatus); } @@ -126,6 +99,34 @@ public Command transactionAboutToCommit(final ResourceSetChangeEvent event) thro return cmd; } + private Set getModifiedResources(ResourceSetChangeEvent event) { + Set changedRes = new LinkedHashSet<>(); + if (!event.getTransaction().isReadOnly()) { + for (Notification notif : event.getNotifications()) { + if (notif.getNotifier() instanceof EObject eObject) { + Resource res = eObject.eResource(); + if (resourceChange(res, notif)) { + changedRes.add(res); + } + } + } + } + return changedRes; + } + + private Set getFilesToValidate(Set changedRes) { + Set filesToValidate = new HashSet<>(); + Iterator it = changedRes.iterator(); + while (it.hasNext()) { + Resource nextResource = it.next(); + IFile file = WorkspaceSynchronizer.getFile(nextResource); + if (file != null && file.isReadOnly()) { + filesToValidate.add(file); + } + } + return filesToValidate; + } + /** * Check if the notification is a resource change. * diff --git a/plugins/org.eclipse.sirius.common/src/org/eclipse/sirius/common/tools/api/interpreter/IInterpreterContextUtils.java b/plugins/org.eclipse.sirius.common/src/org/eclipse/sirius/common/tools/api/interpreter/IInterpreterContextUtils.java index ea4b7ca197..7f045b62bb 100644 --- a/plugins/org.eclipse.sirius.common/src/org/eclipse/sirius/common/tools/api/interpreter/IInterpreterContextUtils.java +++ b/plugins/org.eclipse.sirius.common/src/org/eclipse/sirius/common/tools/api/interpreter/IInterpreterContextUtils.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2015, 2017 Obeo. + * Copyright (c) 2015, 2024 Obeo. * This program and the accompanying materials * are made available under the terms of the Eclipse Public License 2.0 * which accompanies this distribution, and is available at @@ -24,8 +24,6 @@ import org.eclipse.sirius.ecore.extender.business.api.accessor.EcoreMetamodelDescriptor; import org.eclipse.sirius.ecore.extender.business.api.accessor.MetamodelDescriptor; -import com.google.common.collect.Sets; - /** * Utility methods for working with IInterpreterContexts. * @@ -115,8 +113,8 @@ private static void collectProjectName(Resource eResource, Set projectsO * otherwise. */ public static boolean haveSameScopeDefinition(IInterpreterContext a, IInterpreterContext b) { - Set aDependencies = Sets.newLinkedHashSet(a.getDependencies()); - Set bDependencies = Sets.newLinkedHashSet(b.getDependencies()); + Set aDependencies = new LinkedHashSet<>(a.getDependencies()); + Set bDependencies = new LinkedHashSet<>(b.getDependencies()); Set aNSURI = collectNSUris(a); Set bNSURI = collectNSUris(b); Set aProjects = collectProjectsOrPlugins(a); diff --git a/plugins/org.eclipse.sirius.common/src/org/eclipse/sirius/common/tools/api/interpreter/JavaExtensionsManager.java b/plugins/org.eclipse.sirius.common/src/org/eclipse/sirius/common/tools/api/interpreter/JavaExtensionsManager.java index 0e225e81e2..084d789b7d 100644 --- a/plugins/org.eclipse.sirius.common/src/org/eclipse/sirius/common/tools/api/interpreter/JavaExtensionsManager.java +++ b/plugins/org.eclipse.sirius.common/src/org/eclipse/sirius/common/tools/api/interpreter/JavaExtensionsManager.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2013, 2017 Obeo. + * Copyright (c) 2013, 2024 Obeo. * This program and the accompanying materials * are made available under the terms of the Eclipse Public License 2.0 * which accompanies this distribution, and is available at @@ -12,14 +12,13 @@ *******************************************************************************/ package org.eclipse.sirius.common.tools.api.interpreter; -import java.lang.reflect.InvocationTargetException; -import java.lang.reflect.Method; import java.net.MalformedURLException; import java.net.URL; import java.util.ArrayList; import java.util.Arrays; import java.util.Collection; import java.util.Collections; +import java.util.HashMap; import java.util.HashSet; import java.util.LinkedHashMap; import java.util.LinkedHashSet; @@ -46,10 +45,6 @@ import org.eclipse.sirius.common.tools.internal.interpreter.BundleClassLoading; import org.eclipse.sirius.common.tools.internal.interpreter.ClassLoadingService; -import com.google.common.collect.HashMultimap; -import com.google.common.collect.ImmutableList; -import com.google.common.collect.Multimap; - /** * The {@link JavaExtensionsManager} load and maintains {@link Class} instances * based on the current search scope (of projects and/or plugins) and the @@ -75,14 +70,14 @@ public final class JavaExtensionsManager { */ private Set viewpointProjects = new LinkedHashSet<>(); - private final Set imports = new LinkedHashSet(); + private final Set imports = new LinkedHashSet<>(); /** * These are the imports which are registered as * "not having been loaded so far", waiting for a change of scope or a * recompilation which would make them loadable. */ - private final Set couldNotBeLoaded = new LinkedHashSet(); + private final Set couldNotBeLoaded = new LinkedHashSet<>(); private final Map> loadedClasses = new LinkedHashMap<>(); @@ -96,21 +91,17 @@ public final class JavaExtensionsManager { private boolean shouldLoadEPackages = true; - private ClasspathChangeCallback onWorkspaceChange = new ClasspathChangeCallback() { - - @Override - public void classpathChanged(Set updatedProjects) { - /* - * we get a notification if something in the classpath we used so - * far has changed. - */ - if (viewpointPlugins.size() > 0 || viewpointProjects.size() > 0) { - reload(); - } + private ClasspathChangeCallback onWorkspaceChange = updatedProjects -> { + /* + * we get a notification if something in the classpath we used so + * far has changed. + */ + if (viewpointPlugins.size() > 0 || viewpointProjects.size() > 0) { + reload(); } }; - private Multimap lastDeclarerIDsToEPackages = HashMultimap.create(); + private Map> lastDeclarerIDsToEPackages = new HashMap<>(); /** * through this field we keep track fo the EPackage declarers which were @@ -250,7 +241,7 @@ public synchronized void reloadIfNeeded() { } private void reloadEPackages() { - Multimap newDeclarations = HashMultimap.create(); + Map> newDeclarations = new HashMap<>(); Set newDeclarersAsBundles = new LinkedHashSet<>(); Collection ecoreDeclarationSources = this.classLoading.findEcoreDeclarations(this.viewpointProjects, this.viewpointPlugins); Collection workspaceDeclarations = new ArrayList<>(); @@ -265,10 +256,10 @@ private void reloadEPackages() { */ EPackage pak = EPackage.Registry.INSTANCE.getEPackage(ePackageDeclaration.getNsURI()); if (pak != null) { - newDeclarations.put(declarer.getSymbolicName(), pak); + newDeclarations.putIfAbsent(declarer.getSymbolicName(), new ArrayList<>()); + newDeclarations.get(declarer.getSymbolicName()).add(pak); } } - } else { /* * we keep that for later as we need to initialize a specific @@ -278,7 +269,7 @@ private void reloadEPackages() { workspaceDeclarations.add(declarer); } } - if (workspaceDeclarations.size() > 0) { + if (!workspaceDeclarations.isEmpty()) { /* * this resourceset is being used to load the genmodel instances * from the workspace. It is setup with uri mappings so that other @@ -286,9 +277,7 @@ private void reloadEPackages() { * targetplatform. */ ResourceSetImpl set = new ResourceSetImpl(); - computePlatformURIMap(set); - /* * the EPackage definition comes from a workspace project, right now * we don't explicitely and fully support this use case where the @@ -312,31 +301,35 @@ private void reloadEPackages() { if (!StringUtil.isEmpty(nsURI)) { EPackage loaded = ecorePackages.get(nsURI); if (loaded != null) { - newDeclarations.put(nsURI, loaded); + newDeclarations.putIfAbsent(nsURI, new ArrayList<>()); + newDeclarations.get(nsURI).add(loaded); } } } } } - /* * cleaning up previously registered EPackage which are not accessible * any more. */ boolean firstRun = lastDeclarerIDsInBundles == null; if (!firstRun) { - for (Entry entry : lastDeclarerIDsToEPackages.entries()) { - boolean changedType = lastDeclarerIDsInBundles.contains(entry.getKey()) != newDeclarersAsBundles.contains(entry.getKey()); - if (changedType) { - unloadedEPackage(entry.getValue()); + for (Entry> entry : lastDeclarerIDsToEPackages.entrySet()) { + for (EPackage ePackage : entry.getValue()) { + boolean changedType = lastDeclarerIDsInBundles.contains(entry.getKey()) != newDeclarersAsBundles.contains(entry.getKey()); + if (changedType) { + unloadedEPackage(ePackage); + } } } } - for (Entry entry : newDeclarations.entries()) { - boolean changedType = firstRun || lastDeclarerIDsInBundles.contains(entry.getKey()) != newDeclarersAsBundles.contains(entry.getKey()); - if (changedType) { - loadedEPackage(entry.getValue()); + for (Entry> entry : newDeclarations.entrySet()) { + for (EPackage ePackage : entry.getValue()) { + boolean changedType = firstRun || lastDeclarerIDsInBundles.contains(entry.getKey()) != newDeclarersAsBundles.contains(entry.getKey()); + if (changedType) { + loadedEPackage(ePackage); + } } } @@ -346,37 +339,9 @@ private void reloadEPackages() { } private void computePlatformURIMap(ResourceSetImpl set) { - Map result = null; - /* - * We invoke computePlatformURIMap by reflection to keep being - * compatible with EMF 2.8 and still leverage the new capabilities - * regarding target platforms introduced in EMF 2.9. - */ - try { - Method computePlatformURIMap = EcorePlugin.class.getMethod("computePlatformURIMap", Boolean.TYPE); //$NON-NLS-1$ - result = (Map) computePlatformURIMap.invoke(null, true); - } catch (NoSuchMethodException e) { - /* - * result is still null, we'll call the old method. - */ - } catch (IllegalAccessException e) { - /* - * result is still null, we'll call the old method. - */ - } catch (IllegalArgumentException e) { - /* - * result is still null, we'll call the old method. - */ - } catch (InvocationTargetException e) { - /* - * result is still null, we'll call the old method. - */ - } - if (result == null) { - result = EcorePlugin.computePlatformURIMap(); - } - if (result != null) { - set.getURIConverter().getURIMap().putAll(result); + Map uriMap = EcorePlugin.computePlatformURIMap(true); + if (uriMap != null) { + set.getURIConverter().getURIMap().putAll(uriMap); } } @@ -489,7 +454,7 @@ public synchronized void removeImport(String classQualifiedName) { * @return the current list of class qualified name used as Java Extensions. */ public synchronized Collection getImports() { - return ImmutableList.copyOf(this.imports); + return List.copyOf(this.imports); } /** diff --git a/plugins/org.eclipse.sirius.common/src/org/eclipse/sirius/common/tools/api/interpreter/VariableType.java b/plugins/org.eclipse.sirius.common/src/org/eclipse/sirius/common/tools/api/interpreter/VariableType.java index 8cf2818aa2..d7a117afa6 100644 --- a/plugins/org.eclipse.sirius.common/src/org/eclipse/sirius/common/tools/api/interpreter/VariableType.java +++ b/plugins/org.eclipse.sirius.common/src/org/eclipse/sirius/common/tools/api/interpreter/VariableType.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2015, 2022 Obeo. + * Copyright (c) 2015, 2024 Obeo. * This program and the accompanying materials * are made available under the terms of the Eclipse Public License 2.0 * which accompanies this distribution, and is available at @@ -12,7 +12,9 @@ *******************************************************************************/ package org.eclipse.sirius.common.tools.api.interpreter; +import java.util.ArrayList; import java.util.Collection; +import java.util.HashSet; import java.util.Iterator; import java.util.LinkedHashSet; import java.util.List; @@ -22,11 +24,6 @@ import org.eclipse.emf.ecore.EClassifier; import org.eclipse.emf.ecore.EPackage; -import com.google.common.base.Joiner; -import com.google.common.collect.Iterators; -import com.google.common.collect.Lists; -import com.google.common.collect.Sets; - /** * A class representing the type of a variable in a Viewpoint Specification * model. @@ -43,7 +40,7 @@ public final class VariableType { */ public static final VariableType ANY_EOBJECT = fromString(TypeName.EOBJECT_TYPENAME.getCompleteName()); - private List types = Lists.newArrayListWithExpectedSize(2); + private List types = new ArrayList<>(); private VariableType() { @@ -192,7 +189,8 @@ public TypeName getCommonType(Collection availableEPackages) { while (typeNameIt.hasNext() && commonSuperTypes.size() > 0) { TypeName type = typeNameIt.next(); Set nextTypeSuperTypes = getAllSuperTypes(type, availableEPackages); - commonSuperTypes = Sets.intersection(commonSuperTypes, nextTypeSuperTypes); + commonSuperTypes = new HashSet<>(commonSuperTypes); + commonSuperTypes.retainAll(nextTypeSuperTypes); } if (commonSuperTypes.size() > 0) { @@ -207,11 +205,11 @@ public TypeName getCommonType(Collection availableEPackages) { private Set getAllSuperTypes(TypeName type, Collection collection) { Set allSuperTypes = new LinkedHashSet<>(); - Iterator it = Iterators.filter(type.search(collection).iterator(), EClass.class); - while (it.hasNext()) { - EClass curEClass = it.next(); - allSuperTypes.add(curEClass); - allSuperTypes.addAll(curEClass.getEAllSuperTypes()); + for (EClassifier eClassifier : type.search(collection)) { + if (eClassifier instanceof EClass curEClass) { + allSuperTypes.add(curEClass); + allSuperTypes.addAll(curEClass.getEAllSuperTypes()); + } } return allSuperTypes; } @@ -223,7 +221,7 @@ private Set getAllSuperTypes(TypeName type, Collection collect * @return true if the type has an actual definition. */ public boolean hasDefinition() { - return types.size() > 0; + return !types.isEmpty(); } /** @@ -237,6 +235,6 @@ public Collection getPossibleTypes() { @Override public String toString() { - return "[" + Joiner.on(',').join(this.types) + "]"; //$NON-NLS-1$ //$NON-NLS-2$ + return "[" + String.join(",", this.types.stream().map(TypeName::toString).toList()) + "]"; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ } } diff --git a/plugins/org.eclipse.sirius.common/src/org/eclipse/sirius/common/tools/api/profiler/ProfilerTask.java b/plugins/org.eclipse.sirius.common/src/org/eclipse/sirius/common/tools/api/profiler/ProfilerTask.java index 4fbd1bb9ff..2baaf32247 100644 --- a/plugins/org.eclipse.sirius.common/src/org/eclipse/sirius/common/tools/api/profiler/ProfilerTask.java +++ b/plugins/org.eclipse.sirius.common/src/org/eclipse/sirius/common/tools/api/profiler/ProfilerTask.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2007, 2009 THALES GLOBAL SERVICES. + * Copyright (c) 2007, 2024 THALES GLOBAL SERVICES and others. * This program and the accompanying materials * are made available under the terms of the Eclipse Public License 2.0 * which accompanies this distribution, and is available at @@ -12,7 +12,7 @@ *******************************************************************************/ package org.eclipse.sirius.common.tools.api.profiler; -import com.google.common.base.Objects; +import java.util.Objects; /** * Represents a task. @@ -142,10 +142,9 @@ public boolean equals(Object obj) { boolean result = false; if (this == obj) { result = true; - } else if (obj instanceof ProfilerTask) { - ProfilerTask that = (ProfilerTask) obj; - result = Objects.equal(this.name, that.name) && Objects.equal(this.category, that.category) && Objects.equal(this.categoryImage, that.categoryImage) - && Objects.equal(this.taskImage, that.taskImage); + } else if (obj instanceof ProfilerTask that) { + result = Objects.equals(this.name, that.name) && Objects.equals(this.category, that.category) && Objects.equals(this.categoryImage, that.categoryImage) + && Objects.equals(this.taskImage, that.taskImage); } return result; } diff --git a/plugins/org.eclipse.sirius.common/src/org/eclipse/sirius/common/tools/api/resource/ResourceMigrationMarker.java b/plugins/org.eclipse.sirius.common/src/org/eclipse/sirius/common/tools/api/resource/ResourceMigrationMarker.java index 982d23569a..fcc89ea10f 100644 --- a/plugins/org.eclipse.sirius.common/src/org/eclipse/sirius/common/tools/api/resource/ResourceMigrationMarker.java +++ b/plugins/org.eclipse.sirius.common/src/org/eclipse/sirius/common/tools/api/resource/ResourceMigrationMarker.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2014, 2016 Obeo. + * Copyright (c) 2014, 2024 Obeo. * This program and the accompanying materials * are made available under the terms of the Eclipse Public License 2.0 * which accompanies this distribution, and is available at @@ -18,9 +18,6 @@ import org.eclipse.emf.common.notify.impl.AdapterImpl; import org.eclipse.emf.ecore.resource.Resource; -import com.google.common.base.Predicates; -import com.google.common.collect.Iterators; - /** * Utility class used to mark a {@link Resource} as having been migrated. A * {@link Resource} having such a marker *might* have been processed by a @@ -70,6 +67,6 @@ public static void clearMigrationMarker(Resource res) { * @return true if the {@link Resource} has a migration marker. */ public static boolean hasMigrationMarker(Resource res) { - return Iterators.any(res.eAdapters().iterator(), Predicates.instanceOf(ResourceMigrationMarker.class)); + return res.eAdapters().stream().anyMatch(ResourceMigrationMarker.class::isInstance); } } diff --git a/plugins/org.eclipse.sirius.common/src/org/eclipse/sirius/common/tools/api/resource/ResourceSetSync.java b/plugins/org.eclipse.sirius.common/src/org/eclipse/sirius/common/tools/api/resource/ResourceSetSync.java index efc2919cc1..8e5f11a46a 100644 --- a/plugins/org.eclipse.sirius.common/src/org/eclipse/sirius/common/tools/api/resource/ResourceSetSync.java +++ b/plugins/org.eclipse.sirius.common/src/org/eclipse/sirius/common/tools/api/resource/ResourceSetSync.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2007, 2019 THALES GLOBAL SERVICES and others. + * Copyright (c) 2007, 2024 THALES GLOBAL SERVICES and others. * This program and the accompanying materials * are made available under the terms of the Eclipse Public License 2.0 * which accompanies this distribution, and is available at @@ -18,7 +18,6 @@ import java.util.Collection; import java.util.Collections; import java.util.HashMap; -import java.util.Iterator; import java.util.LinkedHashSet; import java.util.List; import java.util.Map; @@ -50,10 +49,6 @@ import org.eclipse.sirius.common.tools.api.query.NotificationQuery; import org.eclipse.sirius.common.tools.internal.resource.WorkspaceBackend; -import com.google.common.collect.Iterables; -import com.google.common.collect.Iterators; -import com.google.common.collect.Lists; - /** * A new implementation of a common synchronizer for the EMF Resource with * external events (like, for instance, workspace). You can attach the @@ -148,19 +143,16 @@ private ResourceSetSync() { fileModificationValidators = FileModificationValidatorProvider.INSTANCE.getFileModificationValidator(); } - /** - * {@inheritDoc} - */ @Override public void resourceSetChanged(final ResourceSetChangeEvent event) { Collection changes = new ArrayList<>(); - for (Notification notif : Iterables.filter(event.getNotifications(), Notification.class)) { + for (Notification notif : event.getNotifications()) { if (!isCustom(notif)) { notifyChanged(notif, changes); } if (notif.getNotifier() instanceof ResourceSet) { - if (notif.getEventType() == Notification.ADD && notif.getNewValue() instanceof Resource) { - newResourceOnTheResourceSet((Resource) notif.getNewValue(), changes); + if (notif.getEventType() == Notification.ADD && notif.getNewValue() instanceof Resource resource) { + newResourceOnTheResourceSet(resource, changes); } else if (notif.getEventType() == Notification.REMOVE && notif.getOldValue() instanceof Resource) { removeResource((Resource) notif.getNewValue()); } @@ -211,13 +203,13 @@ public static Optional getResourceSetSync(final TransactionalEd } private static ResourceSetSync getResourceSetSync(final ResourceSet resourceSet) { - if (resourceSet != null) { - Iterator it = Iterators.filter(resourceSet.eAdapters().iterator(), MarkerAdapter.class); - if (it.hasNext()) { - return it.next().getSync(); - } - } - return null; + return Optional.ofNullable(resourceSet).stream() + .flatMap(rs -> rs.eAdapters().stream()) + .filter(MarkerAdapter.class::isInstance) + .map(MarkerAdapter.class::cast) + .findFirst() + .map(MarkerAdapter::getSync) + .orElse(null); } /** @@ -288,9 +280,8 @@ public static void uninstallResourceSetSync(final TransactionalEditingDomain dom final ResourceSetSync sync = ResourceSetSync.getResourceSetSync(domain.getResourceSet()); if (sync != null) { sync.uninstall(); - for (MarkerAdapter adapter : Lists.newArrayList(Iterables.filter(domain.getResourceSet().eAdapters(), MarkerAdapter.class))) { - domain.getResourceSet().eAdapters().remove(adapter); - } + List markerAdapters = domain.getResourceSet().eAdapters().stream().filter(MarkerAdapter.class::isInstance).map(MarkerAdapter.class::cast).toList(); + domain.getResourceSet().eAdapters().removeAll(markerAdapters); domain.removeResourceSetListener(sync); } } @@ -341,13 +332,12 @@ private void removeResource(Resource newValue) { */ public void notifyChanged(final Notification notification, Collection changes) { final Object notifier = notification.getNotifier(); - if (notifier instanceof EObject && !notification.isTouch() && !new NotificationQuery(notification).isTransientNotification()) { - final Resource resource = ((EObject) notifier).eResource(); + if (notifier instanceof EObject eObject && !notification.isTouch() && !new NotificationQuery(notification).isTransientNotification()) { + final Resource resource = eObject.eResource(); if (resource != null) { handleResourceChange(resource, changes); } - } else if (notifier instanceof Resource) { - final Resource res = (Resource) notifier; + } else if (notifier instanceof Resource res) { if (notification.getFeatureID(null) == Resource.RESOURCE__IS_MODIFIED && !res.isModified()) { resourceNewStatus(res, ResourceStatus.SYNC, changes); } else if (res.isModified() && notification.getFeatureID(null) == Resource.RESOURCE__CONTENTS) { diff --git a/plugins/org.eclipse.sirius.common/src/org/eclipse/sirius/common/tools/api/util/EclipseUtil.java b/plugins/org.eclipse.sirius.common/src/org/eclipse/sirius/common/tools/api/util/EclipseUtil.java index af762ce34f..24ca337ad0 100644 --- a/plugins/org.eclipse.sirius.common/src/org/eclipse/sirius/common/tools/api/util/EclipseUtil.java +++ b/plugins/org.eclipse.sirius.common/src/org/eclipse/sirius/common/tools/api/util/EclipseUtil.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2007, 2017 THALES GLOBAL SERVICES. + * Copyright (c) 2007, 2024 THALES GLOBAL SERVICES and others. * This program and the accompanying materials * are made available under the terms of the Eclipse Public License 2.0 * which accompanies this distribution, and is available at @@ -19,6 +19,7 @@ import java.util.List; import java.util.Map; import java.util.Optional; +import java.util.function.Predicate; import org.eclipse.core.resources.IFile; import org.eclipse.core.resources.IResource; @@ -35,9 +36,6 @@ import org.eclipse.sirius.common.tools.DslCommonPlugin; import org.eclipse.sirius.common.tools.Messages; -import com.google.common.base.Predicate; -import com.google.common.base.Predicates; - /** * This class is should contains useful static functions related to Eclipse * platform. @@ -79,7 +77,7 @@ private static IExtension[] getExtensions(final String extensionId) { * @return a List of clazz instance */ public static List getExtensionPlugins(final Class clazz, final String extensionId, final String attribute) { - return EclipseUtil.getExtensionPlugins(clazz, extensionId, attribute, null, Predicates. alwaysTrue()); + return EclipseUtil.getExtensionPlugins(clazz, extensionId, attribute, null, s -> true); } /** @@ -102,7 +100,7 @@ public static List getExtensionPlugins(final Class clazz, final String * @since 0.9.0 */ public static List getExtensionPlugins(final Class clazz, final String extensionId, final String executableAttribute, final String attributeName, final String exceptedAttributeValue) { - return EclipseUtil.getExtensionPlugins(clazz, extensionId, executableAttribute, attributeName, Predicates.equalTo(exceptedAttributeValue)); + return EclipseUtil.getExtensionPlugins(clazz, extensionId, executableAttribute, attributeName, Predicate.isEqual(exceptedAttributeValue)); } /** @@ -126,7 +124,7 @@ public static List getExtensionPlugins(final Class clazz, final String */ private static List getExtensionPlugins(final Class clazz, final String extensionId, final String executableAttribute, final String attributeName, final Predicate attributeValuePredicate) { - final List contributors = new ArrayList(); + final List contributors = new ArrayList<>(); if (EMFPlugin.IS_ECLIPSE_RUNNING) { final IExtension[] extensions = EclipseUtil.getExtensions(extensionId); for (final IExtension ext : extensions) { @@ -181,7 +179,7 @@ public static Map> getExtensionPluginsByKey(Class c final IConfigurationElement[] ce = ext.getConfigurationElements(); for (IConfigurationElement element : ce) { - if (EclipseUtil.checkAttribute(element, keyAttributeName, Predicates. alwaysTrue())) { + if (EclipseUtil.checkAttribute(element, keyAttributeName, s -> true)) { Object obj; try { obj = element.createExecutableExtension(executableAttribute); @@ -226,7 +224,7 @@ public static Map> getExtensionPluginsByKey(Class c private static boolean checkAttribute(final IConfigurationElement element, final String attributeName, final Predicate exceptedAttributeValue) { if (attributeName != null) { final String namedAttribute = element.getAttribute(attributeName); - return namedAttribute != null && (exceptedAttributeValue == null || exceptedAttributeValue.apply(namedAttribute)); + return namedAttribute != null && (exceptedAttributeValue == null || exceptedAttributeValue.test(namedAttribute)); } return true; } diff --git a/plugins/org.eclipse.sirius.common/src/org/eclipse/sirius/common/tools/api/util/EqualityHelper.java b/plugins/org.eclipse.sirius.common/src/org/eclipse/sirius/common/tools/api/util/EqualityHelper.java index 80ed950f09..8e98566398 100644 --- a/plugins/org.eclipse.sirius.common/src/org/eclipse/sirius/common/tools/api/util/EqualityHelper.java +++ b/plugins/org.eclipse.sirius.common/src/org/eclipse/sirius/common/tools/api/util/EqualityHelper.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2009, 2019 THALES GLOBAL SERVICES. + * Copyright (c) 2009, 2024 THALES GLOBAL SERVICES and others. * This program and the accompanying materials * are made available under the terms of the Eclipse Public License 2.0 * which accompanies this distribution, and is available at @@ -15,6 +15,7 @@ import java.util.Collection; import java.util.Iterator; import java.util.Map; +import java.util.Objects; import java.util.concurrent.ConcurrentHashMap; import org.eclipse.emf.common.util.URI; @@ -24,8 +25,6 @@ import org.eclipse.emf.ecore.InternalEObject; import org.eclipse.emf.ecore.resource.Resource; -import com.google.common.base.Objects; - /** * An helper to check EObject equality.
* It extends and override EcoreUtil.EqualityHelper so that equals methods ignore EAttribute that are ID=true. @@ -55,8 +54,8 @@ protected boolean haveEqualAttribute(EObject eObject1, EObject eObject2, EAttrib * the EObject to find * @return true if the collection contains the object, false otherwise */ - public static boolean contains(final Collection collection, final EObject eObj) { - for (final EObject object : collection) { + public static boolean contains(Collection collection, EObject eObj) { + for (EObject object : collection) { if (EqualityHelper.areEquals(object, eObj)) { return true; } @@ -94,7 +93,7 @@ public static void remove(final Collection collection, final * false */ public static boolean areEquals(EObject eObj1, EObject eObj2) { - if (Objects.equal(eObj1, eObj2)) { + if (Objects.equals(eObj1, eObj2)) { return true; } return haveSameURIFragment(eObj1, eObj2); diff --git a/plugins/org.eclipse.sirius.common/src/org/eclipse/sirius/common/tools/internal/interpreter/BundleClassLoading.java b/plugins/org.eclipse.sirius.common/src/org/eclipse/sirius/common/tools/internal/interpreter/BundleClassLoading.java index 5fc3fd3ba6..60f10f4cd9 100644 --- a/plugins/org.eclipse.sirius.common/src/org/eclipse/sirius/common/tools/internal/interpreter/BundleClassLoading.java +++ b/plugins/org.eclipse.sirius.common/src/org/eclipse/sirius/common/tools/internal/interpreter/BundleClassLoading.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2015 Obeo. + * Copyright (c) 2015, 2024 Obeo. * This program and the accompanying materials * are made available under the terms of the Eclipse Public License 2.0 * which accompanies this distribution, and is available at @@ -15,8 +15,11 @@ import java.text.MessageFormat; import java.util.ArrayList; import java.util.Collection; +import java.util.HashMap; import java.util.Iterator; import java.util.LinkedHashSet; +import java.util.List; +import java.util.Map; import java.util.Set; import org.eclipse.core.runtime.IConfigurationElement; @@ -36,10 +39,6 @@ import org.osgi.framework.wiring.BundleWire; import org.osgi.framework.wiring.BundleWiring; -import com.google.common.collect.HashMultimap; -import com.google.common.collect.Iterables; -import com.google.common.collect.Multimap; - /** * A {@link ClassLoading} implementation which look for a class in a list of * OSGi bundles. @@ -114,7 +113,10 @@ public Collection findEcoreDe Set analyzed = new LinkedHashSet<>(); Set bundlesIDependOn = new LinkedHashSet<>(); - for (String currentBundle : Iterables.concat(plugins, projects)) { + for (String currentBundle : plugins) { + addDependencies(currentBundle, analyzed, bundlesIDependOn); + } + for (String currentBundle : projects) { addDependencies(currentBundle, analyzed, bundlesIDependOn); } @@ -133,7 +135,7 @@ protected Collection getEPack Collection result = new ArrayList<>(); if (EMFPlugin.IS_ECLIPSE_RUNNING) { final IExtensionRegistry reg = Platform.getExtensionRegistry(); - Multimap contributions = HashMultimap.create(); + Map> contributions = new HashMap<>(); final IExtensionPoint ep = reg.getExtensionPoint(EMF_GENERATED_PACKAGE_EXTENSIONPOINT); for (final IExtension ext : ep.getExtensions()) { final IConfigurationElement[] ce = ext.getConfigurationElements(); @@ -146,7 +148,8 @@ protected Collection getEPack String genModel = element.getAttribute("genModel"); //$NON-NLS-1$ if (nsURI != null && className != null) { - contributions.put(contributorName, new EPackageDeclaration(nsURI, className, genModel)); + contributions.putIfAbsent(contributorName, new ArrayList<>()); + contributions.get(contributorName).add(new EPackageDeclaration(nsURI, className, genModel)); } else { DslCommonPlugin.getDefault().warning(MessageFormat.format(Messages.BundleClassLoading_ignoredEPackageDeclaration, contributorName), new IllegalArgumentException()); } @@ -157,7 +160,7 @@ protected Collection getEPack for (String contributor : contributions.keySet()) { Collection declarations = contributions.get(contributor); - if (declarations.size() > 0) { + if (!declarations.isEmpty()) { result.add(new EPackageLoadingCallback.EPackageDeclarationSource(contributor, declarations, true)); } } diff --git a/plugins/org.eclipse.sirius.common/src/org/eclipse/sirius/common/tools/internal/interpreter/DefaultConverter.java b/plugins/org.eclipse.sirius.common/src/org/eclipse/sirius/common/tools/internal/interpreter/DefaultConverter.java index d8b497528f..0766609191 100644 --- a/plugins/org.eclipse.sirius.common/src/org/eclipse/sirius/common/tools/internal/interpreter/DefaultConverter.java +++ b/plugins/org.eclipse.sirius.common/src/org/eclipse/sirius/common/tools/internal/interpreter/DefaultConverter.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2019 Obeo. + * Copyright (c) 2019, 2024 Obeo. * This program and the accompanying materials * are made available under the terms of the Eclipse Public License 2.0 * which accompanies this distribution, and is available at @@ -13,17 +13,16 @@ package org.eclipse.sirius.common.tools.internal.interpreter; +import java.util.Arrays; import java.util.Collection; import java.util.Collections; +import java.util.List; import java.util.Optional; import java.util.OptionalInt; import org.eclipse.emf.ecore.EObject; import org.eclipse.sirius.common.tools.api.interpreter.IConverter; -import com.google.common.collect.Iterables; -import com.google.common.collect.Lists; - /** * The default implementation of type conversion for interpreters. It should be the one used for all implementations * unless there are good reasons to do otherwise to ensure consistency between the various languages. @@ -87,12 +86,13 @@ public OptionalInt toInt(Object rawValue) { @Override public Optional> toEObjectCollection(Object rawValue) { final Collection result; - if (rawValue instanceof Collection) { - result = Lists.newArrayList(Iterables.filter((Collection) rawValue, EObject.class)); + if (rawValue instanceof Collection values) { + result = values.stream().filter(EObject.class::isInstance).map(EObject.class::cast).toList(); } else if (rawValue instanceof EObject) { result = Collections.singleton((EObject) rawValue); } else if (rawValue != null && rawValue.getClass().isArray()) { - result = Lists.newArrayList(Iterables.filter(Lists.newArrayList((Object[]) rawValue), EObject.class)); + List values = Arrays.asList((Object[]) rawValue); + result = values.stream().filter(EObject.class::isInstance).map(EObject.class::cast).toList(); } else { result = Collections.emptySet(); } diff --git a/plugins/org.eclipse.sirius.common/src/org/eclipse/sirius/common/tools/internal/interpreter/DefaultInterpreterProvider.java b/plugins/org.eclipse.sirius.common/src/org/eclipse/sirius/common/tools/internal/interpreter/DefaultInterpreterProvider.java index 7a054d7d1b..51400b1d11 100644 --- a/plugins/org.eclipse.sirius.common/src/org/eclipse/sirius/common/tools/internal/interpreter/DefaultInterpreterProvider.java +++ b/plugins/org.eclipse.sirius.common/src/org/eclipse/sirius/common/tools/internal/interpreter/DefaultInterpreterProvider.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2007, 2019 THALES GLOBAL SERVICES and others. + * Copyright (c) 2007, 2024 THALES GLOBAL SERVICES and others. * This program and the accompanying materials * are made available under the terms of the Eclipse Public License 2.0 * which accompanies this distribution, and is available at @@ -14,6 +14,7 @@ import java.util.Collection; import java.util.Collections; +import java.util.LinkedHashSet; import java.util.Map; import org.eclipse.emf.ecore.EObject; @@ -29,8 +30,6 @@ import org.eclipse.sirius.ecore.extender.business.api.accessor.MetamodelDescriptor; import org.eclipse.sirius.ecore.extender.business.api.accessor.ModelAccessor; -import com.google.common.collect.Sets; - /** * A minimal implementation of {@link IInterpreter} which only handles litteral integers, booleans and strings. It is * used as a fallback/default implementation when interpreting an expression the none of the available interpreters can @@ -113,8 +112,8 @@ public EObject evaluateEObject(final EObject context, final String expression) t @Override public Integer evaluateInteger(final EObject context, final String expression) throws EvaluationException { try { - return new Integer(expression); - } catch (final NumberFormatException nfe) { + return Integer.valueOf(expression); + } catch (NumberFormatException nfe) { return null; } } @@ -181,7 +180,7 @@ public void removeImport(String dependency) { @Override public Collection validateExpression(IInterpreterContext context, String expression) { - return Sets.newLinkedHashSet(); + return new LinkedHashSet<>(); } @Override diff --git a/plugins/org.eclipse.sirius.common/src/org/eclipse/sirius/common/tools/internal/interpreter/FeatureInterpreter.java b/plugins/org.eclipse.sirius.common/src/org/eclipse/sirius/common/tools/internal/interpreter/FeatureInterpreter.java index 8c02dddc77..38dd2404b0 100644 --- a/plugins/org.eclipse.sirius.common/src/org/eclipse/sirius/common/tools/internal/interpreter/FeatureInterpreter.java +++ b/plugins/org.eclipse.sirius.common/src/org/eclipse/sirius/common/tools/internal/interpreter/FeatureInterpreter.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2013, 2016 THALES GLOBAL SERVICES and others. + * Copyright (c) 2013, 2024 THALES GLOBAL SERVICES and others. * This program and the accompanying materials * are made available under the terms of the Eclipse Public License 2.0 * which accompanies this distribution, and is available at @@ -13,7 +13,8 @@ package org.eclipse.sirius.common.tools.internal.interpreter; import java.text.MessageFormat; -import java.util.Iterator; +import java.util.ArrayList; +import java.util.Collection; import java.util.LinkedHashSet; import java.util.Set; @@ -33,9 +34,6 @@ import org.eclipse.sirius.common.tools.api.interpreter.ValidationResult; import org.eclipse.sirius.common.tools.api.interpreter.VariableType; -import com.google.common.collect.Iterators; -import com.google.common.collect.Lists; - /** * A specialized interpreter which only supports direct access to a named * feature (or pseudo-feature) of the context element. @@ -89,7 +87,9 @@ public Object evaluate(EObject target, String expression) throws EvaluationExcep } else if (E_CONTENTS_FEATURE_NAME.equals(featureName)) { result = target.eContents(); } else if (E_ALL_CONTENTS_FEATURE_NAME.equals(featureName)) { - result = Lists.newArrayList(target.eAllContents()); + var objects = new ArrayList<>(); + target.eAllContents().forEachRemaining(objects::add); + result = objects; } else if (E_CLASS_FEATURE_NAME.equals(featureName)) { result = targetEClass; } else if (E_CROSS_REFERENCES_FEATURE_NAME.equals(featureName)) { @@ -115,11 +115,15 @@ public ValidationResult analyzeExpression(IInterpreterContext context, String ex if (!isDefaultFeatureName(featureName)) { Set possibleReturnTypes = new LinkedHashSet<>(); for (TypeName typeName : targetType.getPossibleTypes()) { - Iterator possibleEClasses = Iterators.filter(typeName.search(context.getAvailableEPackages()).iterator(), EClass.class); + Collection classifiers = typeName.search(context.getAvailableEPackages()); boolean foundAtLeastOneValid = false; - while (!foundAtLeastOneValid && possibleEClasses.hasNext()) { - EClass cur = possibleEClasses.next(); - foundAtLeastOneValid = hasFeatureNameAndCollectReturnTypes(cur, featureName, possibleReturnTypes); + for (EClassifier eClassifier : classifiers) { + if (eClassifier instanceof EClass cur) { + foundAtLeastOneValid = hasFeatureNameAndCollectReturnTypes(cur, featureName, possibleReturnTypes); + } + if (foundAtLeastOneValid) { + break; + } } if (!foundAtLeastOneValid) { interpreterStatus.addStatus(InterpreterStatusFactory.createInterpreterStatus(context, IInterpreterStatus.ERROR, diff --git a/plugins/org.eclipse.sirius.common/src/org/eclipse/sirius/common/tools/internal/interpreter/MonomorphicService.java b/plugins/org.eclipse.sirius.common/src/org/eclipse/sirius/common/tools/internal/interpreter/MonomorphicService.java index 459d60ce37..957f150fa0 100644 --- a/plugins/org.eclipse.sirius.common/src/org/eclipse/sirius/common/tools/internal/interpreter/MonomorphicService.java +++ b/plugins/org.eclipse.sirius.common/src/org/eclipse/sirius/common/tools/internal/interpreter/MonomorphicService.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2013, 2017 THALES GLOBAL SERVICES and others. + * Copyright (c) 2013, 2024 THALES GLOBAL SERVICES and others. * This program and the accompanying materials * are made available under the terms of the Eclipse Public License 2.0 * which accompanies this distribution, and is available at @@ -24,8 +24,6 @@ import org.eclipse.sirius.common.tools.Messages; import org.eclipse.sirius.common.tools.api.interpreter.EvaluationException; -import com.google.common.base.Preconditions; - /** * A service which correspond exactly to a single Java method. * @@ -46,7 +44,9 @@ class MonomorphicService implements IMonomorphicService { MonomorphicService(Object serviceInstance, Method serviceMethod) { this.serviceInstance = Objects.requireNonNull(serviceInstance); this.serviceMethod = Objects.requireNonNull(serviceMethod); - Preconditions.checkArgument(ServiceInterpreter.isValidServiceMethod(serviceMethod)); + if (!ServiceInterpreter.isValidServiceMethod(serviceMethod)) { + throw new IllegalArgumentException(); + } } @Override @@ -80,7 +80,7 @@ public Object call(Object[] target) throws EvaluationException { /* * These exceptions indicate problems in the method invocation * itself, i.e. our service invocation logic is broken and tries to - * call inaccesible or incompatible methods. + * call inaccessible or incompatible methods. */ fail(e); } catch (InvocationTargetException e) { diff --git a/plugins/org.eclipse.sirius.common/src/org/eclipse/sirius/common/tools/internal/interpreter/PolymorphicService.java b/plugins/org.eclipse.sirius.common/src/org/eclipse/sirius/common/tools/internal/interpreter/PolymorphicService.java index 3c06ee9712..e9685e2948 100644 --- a/plugins/org.eclipse.sirius.common/src/org/eclipse/sirius/common/tools/internal/interpreter/PolymorphicService.java +++ b/plugins/org.eclipse.sirius.common/src/org/eclipse/sirius/common/tools/internal/interpreter/PolymorphicService.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2013, 2017 THALES GLOBAL SERVICES. + * Copyright (c) 2013, 2024 THALES GLOBAL SERVICES and others. * This program and the accompanying materials * are made available under the terms of the Eclipse Public License 2.0 * which accompanies this distribution, and is available at @@ -24,11 +24,6 @@ import org.eclipse.sirius.common.tools.Messages; import org.eclipse.sirius.common.tools.api.interpreter.EvaluationException; -import com.google.common.base.Preconditions; -import com.google.common.base.Predicate; -import com.google.common.collect.Iterables; -import com.google.common.collect.Lists; - /** * A service which corresponds to more than one Java method. Which of the methods will actually be invoked will depend * on the target object. @@ -51,18 +46,20 @@ public String getName() { public void addImplementer(MonomorphicService svc) { Objects.requireNonNull(svc); - Preconditions.checkArgument(name.equals(svc.getName())); + if (!name.equals(svc.getName())) { + throw new IllegalArgumentException(); + } implementers.add(svc); } @Override public boolean appliesTo(Object[] target) { - return Iterables.any(implementers, getCompatibilityChecker(target)); + return implementers.stream().anyMatch(svc -> svc.appliesTo(target)); } @Override public Object call(Object[] target) throws EvaluationException { - List candidates = Lists.newArrayList(Iterables.filter(implementers, getCompatibilityChecker(target))); + List candidates = implementers.stream().filter(svc -> svc.appliesTo(target)).toList(); if (!candidates.isEmpty()) { return candidates.get(0).call(target); } else { @@ -70,16 +67,6 @@ public Object call(Object[] target) throws EvaluationException { } } - private Predicate getCompatibilityChecker(final Object[] target) { - Predicate isCompatible = new Predicate() { - @Override - public boolean apply(IMonomorphicService svc) { - return svc.appliesTo(target); - } - }; - return isCompatible; - } - @Override public String toString() { return MessageFormat.format(Messages.PolymorphicService_toString, getName(), implementers.size()); @@ -92,7 +79,7 @@ public Set getImplementers() { @Override public Collection getImplementations() { - Collection result = new ArrayList(); + Collection result = new ArrayList<>(); for (IMonomorphicService svc : this.implementers) { result.addAll(svc.getImplementations()); } diff --git a/plugins/org.eclipse.sirius.common/src/org/eclipse/sirius/common/tools/internal/interpreter/ServiceInterpreter.java b/plugins/org.eclipse.sirius.common/src/org/eclipse/sirius/common/tools/internal/interpreter/ServiceInterpreter.java index b7fd8f8145..843c86ff3e 100644 --- a/plugins/org.eclipse.sirius.common/src/org/eclipse/sirius/common/tools/internal/interpreter/ServiceInterpreter.java +++ b/plugins/org.eclipse.sirius.common/src/org/eclipse/sirius/common/tools/internal/interpreter/ServiceInterpreter.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2013-2019 THALES GLOBAL SERVICES and others. + * Copyright (c) 2013, 2024 THALES GLOBAL SERVICES and others. * This program and the accompanying materials * are made available under the terms of the Eclipse Public License 2.0 * which accompanies this distribution, and is available at @@ -15,9 +15,11 @@ import java.lang.reflect.Method; import java.lang.reflect.Modifier; import java.text.MessageFormat; +import java.util.ArrayList; import java.util.Collection; import java.util.Collections; import java.util.HashMap; +import java.util.List; import java.util.Map; import java.util.Optional; import java.util.regex.Pattern; @@ -34,9 +36,6 @@ import org.eclipse.sirius.common.tools.api.interpreter.JavaExtensionsManager; import org.eclipse.sirius.common.tools.api.interpreter.ValidationResult; -import com.google.common.collect.HashMultimap; -import com.google.common.collect.Multimap; - /** * A specialized interpreter which can only directly invoke Java service methods. * @@ -63,7 +62,7 @@ public class ServiceInterpreter extends VariableInterpreter implements IJavaAwar /** * Used to retrieve the services instances we create so that we can un-register those. */ - private final Multimap qualifiedNameToServices = HashMultimap.create(); + private final Map> qualifiedNameToServices = new HashMap<>(); private final JavaExtensionsManager javaExtensions = JavaExtensionsManager.createManagerWithOverride(); @@ -74,7 +73,7 @@ public void unloaded(String qualifiedName, Class clazz) { for (PolymorphicService service : qualifiedNameToServices.get(qualifiedName)) { services.remove(service.getName()); } - qualifiedNameToServices.removeAll(qualifiedName); + qualifiedNameToServices.remove(qualifiedName); } @Override @@ -129,7 +128,6 @@ public Object evaluate(EObject target, String expression) throws EvaluationExcep String serviceCall = expression.substring(PREFIX.length()).trim(); Optional receiverVariableName = getReceiverVariableName(serviceCall); EObject receiver = target; - String serviceName = serviceCall; if (receiverVariableName.isPresent()) { serviceCall = serviceCall.substring(receiverVariableName.get().length() + 1); Object objectReceiver = evaluateVariable(target, receiverVariableName.get().trim()); @@ -141,7 +139,7 @@ public Object evaluate(EObject target, String expression) throws EvaluationExcep } } int indexOfParenthesis = serviceCall.indexOf("("); //$NON-NLS-1$ - serviceName = serviceCall.substring(0, indexOfParenthesis == -1 ? serviceCall.length() : indexOfParenthesis); + String serviceName = serviceCall.substring(0, indexOfParenthesis == -1 ? serviceCall.length() : indexOfParenthesis); Object[] parameters = new Object[] { receiver }; @@ -211,7 +209,8 @@ private void registerService(String qualifiedName, MonomorphicService service) { if (!services.containsKey(name)) { PolymorphicService newService = new PolymorphicService(name); services.put(name, newService); - qualifiedNameToServices.put(qualifiedName, newService); + qualifiedNameToServices.putIfAbsent(qualifiedName, new ArrayList<>()); + qualifiedNameToServices.get(qualifiedName).add(newService); } services.get(name).addImplementer(service); } @@ -280,7 +279,7 @@ public Map getServices() { */ javaExtensions.reloadIfNeeded(); - return new HashMap(services); + return new HashMap<>(services); } @Override From b0b2344975900ec5b619ece82de977890678ab3b Mon Sep 17 00:00:00 2001 From: Pierre-Charles David Date: Fri, 5 Apr 2024 18:00:21 +0200 Subject: [PATCH 2/4] [146] Remove Guava dependency in oes.ecore.extender Bug: https://github.com/eclipse-sirius/sirius-desktop/issues/146 Signed-off-by: Pierre-Charles David --- .../META-INF/MANIFEST.MF | 3 +- .../accessor/CompositeMetamodelExtender.java | 33 ++++++------ .../accessor/EcoreMetamodelDescriptor.java | 23 ++------ .../ecore/EcoreIntrinsicExtender.java | 52 +++++++++++-------- .../accessor/ecore/PackageRegistryIndex.java | 36 ++++++++----- .../AbstractPermissionAuthority.java | 17 +++--- .../ecore/extender/tool/api/ModelUtils.java | 10 ++-- .../tool/internal/ReferencesResolver.java | 24 +++------ 8 files changed, 91 insertions(+), 107 deletions(-) diff --git a/plugins/org.eclipse.sirius.ecore.extender/META-INF/MANIFEST.MF b/plugins/org.eclipse.sirius.ecore.extender/META-INF/MANIFEST.MF index 92b0946bfb..6c6128f7db 100644 --- a/plugins/org.eclipse.sirius.ecore.extender/META-INF/MANIFEST.MF +++ b/plugins/org.eclipse.sirius.ecore.extender/META-INF/MANIFEST.MF @@ -6,8 +6,7 @@ Bundle-Version: 7.4.3.qualifier Bundle-Vendor: %providerName Require-Bundle: org.eclipse.core.runtime;bundle-version="3.8.0", org.eclipse.emf.ecore.xmi;bundle-version="2.8.1", - org.eclipse.emf.edit;bundle-version="2.8.0", - com.google.guava;bundle-version="27.0" + org.eclipse.emf.edit;bundle-version="2.8.0" Export-Package: org.eclipse.sirius.ecore.extender.business.api.accessor;version="3.0.0", org.eclipse.sirius.ecore.extender.business.api.accessor.exception;version="3.0.0", org.eclipse.sirius.ecore.extender.business.api.permission;version="2.0.4", diff --git a/plugins/org.eclipse.sirius.ecore.extender/src/org/eclipse/sirius/ecore/extender/business/api/accessor/CompositeMetamodelExtender.java b/plugins/org.eclipse.sirius.ecore.extender/src/org/eclipse/sirius/ecore/extender/business/api/accessor/CompositeMetamodelExtender.java index 9c8e679750..fb92ef6699 100644 --- a/plugins/org.eclipse.sirius.ecore.extender/src/org/eclipse/sirius/ecore/extender/business/api/accessor/CompositeMetamodelExtender.java +++ b/plugins/org.eclipse.sirius.ecore.extender/src/org/eclipse/sirius/ecore/extender/business/api/accessor/CompositeMetamodelExtender.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2007, 2010 THALES GLOBAL SERVICES. + * Copyright (c) 2007, 2024 THALES GLOBAL SERVICES and others. * This program and the accompanying materials * are made available under the terms of the Eclipse Public License 2.0 * which accompanies this distribution, and is available at @@ -18,6 +18,9 @@ import java.util.Iterator; import java.util.LinkedHashSet; import java.util.List; +import java.util.Spliterator; +import java.util.Spliterators; +import java.util.stream.StreamSupport; import org.eclipse.emf.common.util.AbstractTreeIterator; import org.eclipse.emf.common.util.TreeIterator; @@ -27,10 +30,6 @@ import org.eclipse.sirius.ecore.extender.business.internal.common.ExtenderDescriptor; import org.eclipse.sirius.ext.emf.EReferencePredicate; -import com.google.common.base.Predicate; -import com.google.common.collect.Iterables; -import com.google.common.collect.Iterators; - /** * Aggregate more {@link IMetamodelExtender}'s using a priority system. * @@ -185,6 +184,7 @@ public String eContainingFeatureName(final EObject instance) { return null; } + @Override public Iterator eContents(final EObject root) { final List> iterators = new ArrayList<>(); @@ -195,11 +195,12 @@ public Iterator eContents(final EObject root) { } } if (!iterators.isEmpty()) { - return Iterators.concat(iterators.iterator()); + return iterators.stream() + .flatMap(iterator -> StreamSupport.stream(Spliterators.spliteratorUnknownSize(iterator, Spliterator.ORDERED), false)) + .iterator(); } return Collections. emptyList().iterator(); } - /** * Check whether the given instance should block the eAllContent browsing or * not. @@ -238,7 +239,7 @@ public EObject eDelete(EObject objectToRemove, ECrossReferenceAdapter xref, ERef @Override public Collection eRemoveInverseCrossReferences(EObject eObject, ECrossReferenceAdapter xref, EReferencePredicate isReferencesToIgnorePredicate) { - Collection impactedEObjects = new LinkedHashSet(); + Collection impactedEObjects = new LinkedHashSet<>(); for (final IMetamodelExtender extender : getActivatedExtenders()) { impactedEObjects.addAll(extender.eRemoveInverseCrossReferences(eObject, xref, isReferencesToIgnorePredicate)); } @@ -336,7 +337,9 @@ public Iterator getContributedAttributeNames(final EObject next) { for (final IMetamodelExtender extender : getActivatedExtenders()) { iterators.add(extender.getContributedAttributeNames(next)); } - return Iterators.concat(iterators.iterator()); + return iterators.stream() + .flatMap(iterator -> StreamSupport.stream(Spliterators.spliteratorUnknownSize(iterator, Spliterator.ORDERED), false)) + .iterator(); } @Override @@ -345,8 +348,9 @@ public Iterator getContributedReferenceNames(final EObject instance) { for (final IMetamodelExtender extender : getActivatedExtenders()) { iterators.add(extender.getContributedReferenceNames(instance)); } - return Iterators.concat(iterators.iterator()); - + return iterators.stream() + .flatMap(iterator -> StreamSupport.stream(Spliterators.spliteratorUnknownSize(iterator, Spliterator.ORDERED), false)) + .iterator(); } @Override @@ -477,12 +481,7 @@ public void deactivate() { */ protected synchronized Iterable getActivatedExtenders() { if (activeExtenders == null) { - activeExtenders = Iterables.filter(extenders, new Predicate() { - @Override - public boolean apply(IMetamodelExtender extender) { - return extender.isActive(); - } - }); + activeExtenders = () -> extenders.stream().filter(IMetamodelExtender::isActive).iterator(); } return activeExtenders; } diff --git a/plugins/org.eclipse.sirius.ecore.extender/src/org/eclipse/sirius/ecore/extender/business/api/accessor/EcoreMetamodelDescriptor.java b/plugins/org.eclipse.sirius.ecore.extender/src/org/eclipse/sirius/ecore/extender/business/api/accessor/EcoreMetamodelDescriptor.java index 12d7183d3b..b3976a2272 100644 --- a/plugins/org.eclipse.sirius.ecore.extender/src/org/eclipse/sirius/ecore/extender/business/api/accessor/EcoreMetamodelDescriptor.java +++ b/plugins/org.eclipse.sirius.ecore.extender/src/org/eclipse/sirius/ecore/extender/business/api/accessor/EcoreMetamodelDescriptor.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2007, 2012 THALES GLOBAL SERVICES. + * Copyright (c) 2007, 2024 THALES GLOBAL SERVICES and others. * This program and the accompanying materials * are made available under the terms of the Eclipse Public License 2.0 * which accompanies this distribution, and is available at @@ -12,11 +12,11 @@ *******************************************************************************/ package org.eclipse.sirius.ecore.extender.business.api.accessor; +import java.util.Objects; + import org.eclipse.emf.ecore.EPackage; import org.eclipse.emf.ecore.resource.Resource; -import com.google.common.base.Objects; - /** * A descriptors for EPackages. * @@ -75,11 +75,6 @@ private boolean isInPlugin(final EPackage package1) { return false; } - /** - * {@inheritDoc} - * - * @see java.lang.Object#hashCode() - */ @Override public int hashCode() { final int prime = 31; @@ -89,25 +84,17 @@ public int hashCode() { return result; } - /** - * {@inheritDoc} - * - * @see java.lang.Object#equals(java.lang.Object) - */ // CHECKSTYLE:OFF @Override public boolean equals(Object obj) { - if (this == obj) { return true; } if (obj == null || getClass() != obj.getClass()) { return false; } - - final EcoreMetamodelDescriptor other = (EcoreMetamodelDescriptor) obj; - - return ePackage == other.ePackage && Objects.equal(nsURI, other.nsURI); + EcoreMetamodelDescriptor other = (EcoreMetamodelDescriptor) obj; + return ePackage == other.ePackage && Objects.equals(nsURI, other.nsURI); // CHECKSTYLE:ON } } diff --git a/plugins/org.eclipse.sirius.ecore.extender/src/org/eclipse/sirius/ecore/extender/business/internal/accessor/ecore/EcoreIntrinsicExtender.java b/plugins/org.eclipse.sirius.ecore.extender/src/org/eclipse/sirius/ecore/extender/business/internal/accessor/ecore/EcoreIntrinsicExtender.java index 3491d791bf..f3ebd99bcb 100644 --- a/plugins/org.eclipse.sirius.ecore.extender/src/org/eclipse/sirius/ecore/extender/business/internal/accessor/ecore/EcoreIntrinsicExtender.java +++ b/plugins/org.eclipse.sirius.ecore.extender/src/org/eclipse/sirius/ecore/extender/business/internal/accessor/ecore/EcoreIntrinsicExtender.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2007, 2011 THALES GLOBAL SERVICES. + * Copyright (c) 2007, 2024 THALES GLOBAL SERVICES. * This program and the accompanying materials * are made available under the terms of the Eclipse Public License 2.0 * which accompanies this distribution, and is available at @@ -15,12 +15,17 @@ import java.util.ArrayList; import java.util.Collection; import java.util.Collections; +import java.util.HashMap; import java.util.Iterator; import java.util.LinkedHashSet; +import java.util.List; +import java.util.Map; +import java.util.stream.Stream; import org.eclipse.emf.common.util.URI; import org.eclipse.emf.ecore.EAttribute; import org.eclipse.emf.ecore.EClass; +import org.eclipse.emf.ecore.EClassifier; import org.eclipse.emf.ecore.EDataType; import org.eclipse.emf.ecore.EEnum; import org.eclipse.emf.ecore.EEnumLiteral; @@ -39,13 +44,6 @@ import org.eclipse.sirius.ecore.extender.business.api.accessor.MetamodelDescriptor; import org.eclipse.sirius.ext.emf.EReferencePredicate; -import com.google.common.base.Predicates; -import com.google.common.collect.HashMultimap; -import com.google.common.collect.Iterables; -import com.google.common.collect.Iterators; -import com.google.common.collect.Multimap; -import com.google.common.collect.Sets; - /** * This metamodel Extender accesses the intrinsic data of an EObject. * @@ -58,9 +56,9 @@ public class EcoreIntrinsicExtender extends AbstractMetamodelExtender { private static final String AQL_SEPARATOR = "::"; //$NON-NLS-1$ - private static PackageRegistryIndex platformIndex = new PackageRegistryIndex(EPackage.Registry.INSTANCE, Predicates. alwaysTrue()); + private static PackageRegistryIndex platformIndex = new PackageRegistryIndex(EPackage.Registry.INSTANCE, p -> true); - private Multimap viewpointIndex = HashMultimap.create(); + private Map> viewpointIndex = new HashMap<>(); private Collection lastDescriptors; @@ -377,12 +375,19 @@ public void init(final ResourceSet set) { } private void addTypesToSiriusIndex(final EPackage value) { - for (EClass cur : Iterables.filter(value.getEClassifiers(), EClass.class)) { - viewpointIndex.put(cur.getName(), cur); - viewpointIndex.put(value.getName() + EcoreIntrinsicExtender.SEPARATOR + cur.getName(), cur); - viewpointIndex.put(value.getName() + EcoreIntrinsicExtender.AQL_SEPARATOR + cur.getName(), cur); + for (EClassifier eClassifier : value.getEClassifiers()) { + if (eClassifier instanceof EClass cur) { + addToIndex(cur.getName(), cur); + addToIndex(value.getName() + EcoreIntrinsicExtender.SEPARATOR + cur.getName(), cur); + addToIndex(value.getName() + EcoreIntrinsicExtender.AQL_SEPARATOR + cur.getName(), cur); + } } } + + private void addToIndex(String key, EClass eClass) { + viewpointIndex.putIfAbsent(key, new ArrayList<>()); + viewpointIndex.get(key).add(eClass); + } @Override public boolean isExtension(final EObject next) { @@ -390,7 +395,7 @@ public boolean isExtension(final EObject next) { } private Iterator getEClassesFromName(final String name) { - return Iterators.concat(viewpointIndex.get(name).iterator(), platformIndex.getEClassesFromName(name).iterator()); + return Stream.concat(viewpointIndex.getOrDefault(name, List.of()).stream(), platformIndex.getEClassesFromName(name).stream()).iterator(); } private EClass findFirstEClassFromName(final String name) { @@ -400,7 +405,7 @@ private EClass findFirstEClassFromName(final String name) { } return null; } - + /** * Create a new instance. * @@ -439,21 +444,22 @@ public boolean preventFromBrowsing(final EObject root) { @Override public void updateMetamodels(final Collection metamodelDescriptors) { - final Collection metamodelDescriptorsCopy = Sets.newLinkedHashSet(metamodelDescriptors); + final Collection metamodelDescriptorsCopy = new LinkedHashSet<>(metamodelDescriptors); if (lastDescriptors != null) { metamodelDescriptorsCopy.removeAll(lastDescriptors); } final Iterator it = metamodelDescriptorsCopy.iterator(); while (it.hasNext()) { final Object obj = it.next(); - if (obj instanceof EcoreMetamodelDescriptor) { - final EPackage pak = ((EcoreMetamodelDescriptor) obj).resolve(); + if (obj instanceof EcoreMetamodelDescriptor descriptor) { + final EPackage pak = descriptor.resolve(); if (pak != null) { addTypesToSiriusIndex(pak); - Iterator subPack = Iterators.filter(pak.eAllContents(), EPackage.class); - while (subPack.hasNext()) { - addTypesToSiriusIndex(subPack.next()); - } + pak.eAllContents().forEachRemaining(eObject -> { + if (eObject instanceof EPackage subPack) { + addTypesToSiriusIndex(subPack); + } + }); } } diff --git a/plugins/org.eclipse.sirius.ecore.extender/src/org/eclipse/sirius/ecore/extender/business/internal/accessor/ecore/PackageRegistryIndex.java b/plugins/org.eclipse.sirius.ecore.extender/src/org/eclipse/sirius/ecore/extender/business/internal/accessor/ecore/PackageRegistryIndex.java index 5953111a3b..661e57414d 100644 --- a/plugins/org.eclipse.sirius.ecore.extender/src/org/eclipse/sirius/ecore/extender/business/internal/accessor/ecore/PackageRegistryIndex.java +++ b/plugins/org.eclipse.sirius.ecore.extender/src/org/eclipse/sirius/ecore/extender/business/internal/accessor/ecore/PackageRegistryIndex.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2009, 2010 THALES GLOBAL SERVICES. + * Copyright (c) 2009, 2024 THALES GLOBAL SERVICES and others. * This program and the accompanying materials * are made available under the terms of the Eclipse Public License 2.0 * which accompanies this distribution, and is available at @@ -14,15 +14,15 @@ import java.util.ArrayList; import java.util.Collection; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.function.Predicate; import org.eclipse.emf.ecore.EClass; +import org.eclipse.emf.ecore.EClassifier; import org.eclipse.emf.ecore.EPackage; -import com.google.common.base.Predicate; -import com.google.common.collect.HashMultimap; -import com.google.common.collect.Iterables; -import com.google.common.collect.Multimap; - /** * Index for all EClasses defined in a package registry. * @@ -37,7 +37,7 @@ public class PackageRegistryIndex { private final Predicate packageFilter; - private final Multimap index = HashMultimap.create(); + private final Map> index = new HashMap<>(); private boolean initializedDescriptors; @@ -99,22 +99,30 @@ private void indexTypesFromRegistry(boolean descriptors) { * @return all the indexed classes with a matching name. */ public Collection getEClassesFromName(String name) { - Collection result = index.get(name); + Collection result = index.getOrDefault(name, List.of()); if (Boolean.valueOf(System.getProperty("org.eclipse.sirius.enableUnsafeOptimisations", "false")) && result.isEmpty() && !initializedDescriptors) { //$NON-NLS-1$ //$NON-NLS-2$ indexTypesFromRegistry(true); initializedDescriptors = true; - result = index.get(name); + result = index.getOrDefault(name, List.of()); } return result; } private void indexTypesFrom(EPackage value) { - if (packageFilter.apply(value)) { - for (EClass cur : Iterables.filter(value.getEClassifiers(), EClass.class)) { - index.put(cur.getName(), cur); - index.put(value.getName() + SEPARATOR + cur.getName(), cur); - index.put(value.getName() + AQL_SEPARATOR + cur.getName(), cur); + if (packageFilter.test(value)) { + for (EClassifier classifier : value.getEClassifiers()) { + if (classifier instanceof EClass cur) { + addToIndex(cur.getName(), cur); + addToIndex(value.getName() + SEPARATOR + cur.getName(), cur); + addToIndex(value.getName() + AQL_SEPARATOR + cur.getName(), cur); + } } } } + + private void addToIndex(String key, EClass eClass) { + index.putIfAbsent(key, new ArrayList<>()); + index.get(key).add(eClass); + } + } diff --git a/plugins/org.eclipse.sirius.ecore.extender/src/org/eclipse/sirius/ecore/extender/business/internal/permission/AbstractPermissionAuthority.java b/plugins/org.eclipse.sirius.ecore.extender/src/org/eclipse/sirius/ecore/extender/business/internal/permission/AbstractPermissionAuthority.java index 48d9b28402..efa9c56d6b 100644 --- a/plugins/org.eclipse.sirius.ecore.extender/src/org/eclipse/sirius/ecore/extender/business/internal/permission/AbstractPermissionAuthority.java +++ b/plugins/org.eclipse.sirius.ecore.extender/src/org/eclipse/sirius/ecore/extender/business/internal/permission/AbstractPermissionAuthority.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2009, 2024 THALES GLOBAL SERVICES. + * Copyright (c) 2009, 2024 THALES GLOBAL SERVICES and others. * This program and the accompanying materials * are made available under the terms of the Eclipse Public License 2.0 * which accompanies this distribution, and is available at @@ -15,17 +15,15 @@ import java.util.Collections; import java.util.List; import java.util.Objects; -import java.util.concurrent.ConcurrentMap; +import java.util.Set; +import java.util.WeakHashMap; import java.util.concurrent.CopyOnWriteArrayList; -import java.util.stream.Collectors; import org.eclipse.emf.ecore.EObject; import org.eclipse.emf.ecore.resource.ResourceSet; import org.eclipse.sirius.ecore.extender.business.api.permission.IAuthorityListener; import org.eclipse.sirius.ecore.extender.business.api.permission.IPermissionAuthority; -import com.google.common.collect.MapMaker; - /** * A basic permission authority which will manage a list of listeners. * @@ -40,7 +38,7 @@ public abstract class AbstractPermissionAuthority implements IPermissionAuthorit protected List listeners = new CopyOnWriteArrayList(); /** the locked objects. */ - protected ConcurrentMap lockedObjects = new MapMaker().concurrencyLevel(4).weakKeys().makeMap(); + protected Set lockedObjects = Collections.newSetFromMap(new WeakHashMap()); /** * Check if an object is locked or not. @@ -50,7 +48,7 @@ public abstract class AbstractPermissionAuthority implements IPermissionAuthorit * @return true if is locked, false otherwise */ protected boolean isLocked(final EObject eObject) { - return lockedObjects.containsKey(eObject); + return lockedObjects.contains(eObject); } /** @@ -60,7 +58,7 @@ protected boolean isLocked(final EObject eObject) { * the locked instance */ protected void storeAsLockedAndNotify(final EObject eObject) { - lockedObjects.put(eObject, true); + lockedObjects.add(eObject); for (IAuthorityListener listener : listeners) { listener.notifyIsLocked(eObject); } @@ -68,8 +66,7 @@ protected void storeAsLockedAndNotify(final EObject eObject) { @Override public List getLockedObjects() { - List lockedEObjects = lockedObjects.keySet().stream().filter(EObject.class::isInstance).map(EObject.class::cast).collect(Collectors.toList()); - return Collections.unmodifiableList(lockedEObjects); + return lockedObjects.stream().filter(EObject.class::isInstance).map(EObject.class::cast).toList(); } /** diff --git a/plugins/org.eclipse.sirius.ecore.extender/src/org/eclipse/sirius/ecore/extender/tool/api/ModelUtils.java b/plugins/org.eclipse.sirius.ecore.extender/src/org/eclipse/sirius/ecore/extender/tool/api/ModelUtils.java index d577d9e7dc..d528b16719 100644 --- a/plugins/org.eclipse.sirius.ecore.extender/src/org/eclipse/sirius/ecore/extender/tool/api/ModelUtils.java +++ b/plugins/org.eclipse.sirius.ecore.extender/src/org/eclipse/sirius/ecore/extender/tool/api/ModelUtils.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2006, 2011 Obeo. + * Copyright (c) 2006, 2024 Obeo. * This program and the accompanying materials * are made available under the terms of the Eclipse Public License 2.0 * which accompanies this distribution, and is available at @@ -49,8 +49,6 @@ import org.eclipse.sirius.ecore.extender.tool.internal.ReferencesResolver; import org.eclipse.sirius.ext.emf.EReferencePredicate; -import com.google.common.collect.Iterators; - /** * Utility class for model loading/saving and serialization. * @@ -506,12 +504,12 @@ public static void resolveAll(final Resource res, boolean recursive) { if (res != null && res.getResourceSet() != null) { cachedIDsResources = ModelUtils.cachedEObjectIDs(res.getResourceSet()); } - List resourcesBeforeResolveAll = new ArrayList(res.getResourceSet().getResources()); + List resourcesBeforeResolveAll = new ArrayList<>(res.getResourceSet().getResources()); EcoreUtil.resolveAll(res); if (recursive) { - List resourcesAfterResolveAll = new ArrayList(res.getResourceSet().getResources()); + List resourcesAfterResolveAll = new ArrayList<>(res.getResourceSet().getResources()); // Remove the known resources - Iterators.removeAll(resourcesAfterResolveAll.iterator(), resourcesBeforeResolveAll); + resourcesAfterResolveAll.removeAll(resourcesBeforeResolveAll); for (Resource resource : resourcesAfterResolveAll) { resolveAll(resource, recursive); } diff --git a/plugins/org.eclipse.sirius.ecore.extender/src/org/eclipse/sirius/ecore/extender/tool/internal/ReferencesResolver.java b/plugins/org.eclipse.sirius.ecore.extender/src/org/eclipse/sirius/ecore/extender/tool/internal/ReferencesResolver.java index f2f8f99fd3..7b32237081 100644 --- a/plugins/org.eclipse.sirius.ecore.extender/src/org/eclipse/sirius/ecore/extender/tool/internal/ReferencesResolver.java +++ b/plugins/org.eclipse.sirius.ecore.extender/src/org/eclipse/sirius/ecore/extender/tool/internal/ReferencesResolver.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2010 THALES GLOBAL SERVICES. + * Copyright (c) 2010, 2024 THALES GLOBAL SERVICES and others. * This program and the accompanying materials * are made available under the terms of the Eclipse Public License 2.0 * which accompanies this distribution, and is available at @@ -17,6 +17,7 @@ import java.util.Iterator; import java.util.LinkedList; import java.util.List; +import java.util.function.Predicate; import org.eclipse.core.runtime.IProgressMonitor; import org.eclipse.emf.ecore.EObject; @@ -29,9 +30,6 @@ import org.eclipse.sirius.ecore.extender.business.internal.Messages; import org.eclipse.sirius.ext.emf.EReferencePredicate; -import com.google.common.base.Predicate; -import com.google.common.collect.Iterators; - /** * Class responsible for resolving some references. * @@ -52,13 +50,8 @@ public class ReferencesResolver { * @param set * resource set to resolve. */ - public ReferencesResolver(ResourceSet set, final EReferencePredicate filter) { - this.filter = new Predicate() { - @Override - public boolean apply(EReference input) { - return filter.apply(input); - } - }; + public ReferencesResolver(ResourceSet set, EReferencePredicate filter) { + this.filter = filter::apply; this.set = set; } @@ -97,10 +90,7 @@ private void doResolveAll(Resource resource) { } private void resolveCrossReferences(EObject eObject) { - Iterator it = Iterators.filter(eObject.eClass().getEAllReferences().iterator(), filter); - while (it.hasNext()) { - eObject.eGet(it.next()); - } + eObject.eClass().getEAllReferences().stream().filter(filter).forEach(eObject::eGet); } /** @@ -116,12 +106,12 @@ public static List prepareResolveAll(final ResourceSet set, final IPer if (authority != null) { authority.setListening(false); } - final List cachedIdsResources = new LinkedList(); + final List cachedIdsResources = new LinkedList<>(); Iterator iterResources = set.getResources().iterator(); while (iterResources.hasNext()) { final Resource resource = iterResources.next(); if (resource instanceof ResourceImpl && ((ResourceImpl) resource).getIntrinsicIDToEObjectMap() == null) { - ((ResourceImpl) resource).setIntrinsicIDToEObjectMap(new HashMap()); + ((ResourceImpl) resource).setIntrinsicIDToEObjectMap(new HashMap<>()); cachedIdsResources.add(resource); } } From 062c30b2ec777669ae1cc91aa728a493e136827b Mon Sep 17 00:00:00 2001 From: Pierre-Charles David Date: Fri, 5 Apr 2024 18:26:48 +0200 Subject: [PATCH 3/4] [146] Remove usage of com.google.common.base.Objects Bug: https://github.com/eclipse-sirius/sirius-desktop/issues/146 Signed-off-by: Pierre-Charles David --- .../sequence/business/api/util/Pair.java | 20 ++++---------- .../operation/SetMessageRangeOperation.java | 16 +++++------ .../SynchronizedStatusPostCommitListener.java | 7 +++-- .../AbstractSemanticFormatDataKey.java | 27 +++---------------- .../helper/task/DropinForNodeTaskCommand.java | 8 +++--- .../metamodel/helper/StyleHelper.java | 9 +++---- .../sync/DDiagramElementSynchronizer.java | 6 ++--- .../AbstractSequenceSiriusDiagramTests.java | 19 +++++++------ .../tools/api/color/VisualBindingManager.java | 18 ++++++------- .../common/item/AnalysisResourceItemImpl.java | 7 +++-- 10 files changed, 51 insertions(+), 86 deletions(-) diff --git a/plugins/org.eclipse.sirius.diagram.sequence/src/org/eclipse/sirius/diagram/sequence/business/api/util/Pair.java b/plugins/org.eclipse.sirius.diagram.sequence/src/org/eclipse/sirius/diagram/sequence/business/api/util/Pair.java index 13cfe5ed9f..de118c24aa 100644 --- a/plugins/org.eclipse.sirius.diagram.sequence/src/org/eclipse/sirius/diagram/sequence/business/api/util/Pair.java +++ b/plugins/org.eclipse.sirius.diagram.sequence/src/org/eclipse/sirius/diagram/sequence/business/api/util/Pair.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2010, 2021 THALES GLOBAL SERVICES. + * Copyright (c) 2010, 2024 THALES GLOBAL SERVICES and others. * This program and the accompanying materials * are made available under the terms of the Eclipse Public License 2.0 * which accompanies this distribution, and is available at @@ -12,7 +12,7 @@ *******************************************************************************/ package org.eclipse.sirius.diagram.sequence.business.api.util; -import com.google.common.base.Objects; +import java.util.Objects; /** * Generic helper class to hold two elements of the same type. In some @@ -62,32 +62,22 @@ public T second() { return second; } - /** - * {@inheritDoc} - */ @Override public int hashCode() { - return Objects.hashCode(first, second); + return Objects.hash(first, second); } - /** - * {@inheritDoc} - */ @Override public boolean equals(Object obj) { boolean result = false; if (this == obj) { result = true; - } else if (obj instanceof Pair) { - Pair that = (Pair) obj; - result = Objects.equal(this.first, that.first) && Objects.equal(this.second, that.second); + } else if (obj instanceof Pair that) { + result = Objects.equals(this.first, that.first) && Objects.equals(this.second, that.second); } return result; } - /** - * {@inheritDoc} - */ @Override public String toString() { return "<" + String.valueOf(first) + ", " + String.valueOf(second) + ">"; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ diff --git a/plugins/org.eclipse.sirius.diagram.sequence/src/org/eclipse/sirius/diagram/sequence/business/internal/operation/SetMessageRangeOperation.java b/plugins/org.eclipse.sirius.diagram.sequence/src/org/eclipse/sirius/diagram/sequence/business/internal/operation/SetMessageRangeOperation.java index 3838b9a050..e7eea1452a 100644 --- a/plugins/org.eclipse.sirius.diagram.sequence/src/org/eclipse/sirius/diagram/sequence/business/internal/operation/SetMessageRangeOperation.java +++ b/plugins/org.eclipse.sirius.diagram.sequence/src/org/eclipse/sirius/diagram/sequence/business/internal/operation/SetMessageRangeOperation.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2010, 2021 THALES GLOBAL SERVICES and others. + * Copyright (c) 2010, 2024 THALES GLOBAL SERVICES and others. * This program and the accompanying materials * are made available under the terms of the Eclipse Public License 2.0 * which accompanies this distribution, and is available at @@ -12,6 +12,8 @@ *******************************************************************************/ package org.eclipse.sirius.diagram.sequence.business.internal.operation; +import java.util.Objects; + import org.eclipse.draw2d.geometry.Rectangle; import org.eclipse.gmf.runtime.notation.Edge; import org.eclipse.gmf.runtime.notation.View; @@ -21,8 +23,6 @@ import org.eclipse.sirius.diagram.sequence.tool.internal.Messages; import org.eclipse.sirius.diagram.ui.business.internal.operation.AbstractModelChangeOperation; -import com.google.common.base.Objects; - /** * An operation to set the vertical range of a sequence message. * @@ -102,12 +102,12 @@ public Void execute() { Edge currentMessage = message; currentMessage.setSource(source); - if (currentMessage.getElement() instanceof DEdge && source.getElement() instanceof EdgeTarget) { - ((DEdge) currentMessage.getElement()).setSourceNode((EdgeTarget) source.getElement()); + if (currentMessage.getElement() instanceof DEdge edge && source.getElement() instanceof EdgeTarget edgeTarget) { + edge.setSourceNode(edgeTarget); } currentMessage.setTarget(target); - if (currentMessage.getElement() instanceof DEdge && target.getElement() instanceof EdgeTarget) { - ((DEdge) currentMessage.getElement()).setTargetNode((EdgeTarget) target.getElement()); + if (currentMessage.getElement() instanceof DEdge edge && target.getElement() instanceof EdgeTarget edgeTarget) { + edge.setTargetNode(edgeTarget); } int srcTop = sourceBounds.getTop().y; @@ -132,7 +132,7 @@ public Void execute() { private boolean isMessageToSelf(Edge msg) { View src = msg.getSource(); View tgt = msg.getTarget(); - return Objects.equal(src, tgt) || Objects.equal(src.eContainer(), tgt) || Objects.equal(src, tgt.eContainer()); + return Objects.equals(src, tgt) || Objects.equals(src.eContainer(), tgt) || Objects.equals(src, tgt.eContainer()); } } diff --git a/plugins/org.eclipse.sirius.diagram.ui/src-diag/org/eclipse/sirius/diagram/ui/edit/internal/part/listener/SynchronizedStatusPostCommitListener.java b/plugins/org.eclipse.sirius.diagram.ui/src-diag/org/eclipse/sirius/diagram/ui/edit/internal/part/listener/SynchronizedStatusPostCommitListener.java index 3db5b4ccea..fe1b5c8195 100644 --- a/plugins/org.eclipse.sirius.diagram.ui/src-diag/org/eclipse/sirius/diagram/ui/edit/internal/part/listener/SynchronizedStatusPostCommitListener.java +++ b/plugins/org.eclipse.sirius.diagram.ui/src-diag/org/eclipse/sirius/diagram/ui/edit/internal/part/listener/SynchronizedStatusPostCommitListener.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2017 THALES GLOBAL SERVICES. + * Copyright (c) 2017, 2024 THALES GLOBAL SERVICES and others. * This program and the accompanying materials * are made available under the terms of the Eclipse Public License 2.0 * which accompanies this distribution, and is available at @@ -13,6 +13,7 @@ package org.eclipse.sirius.diagram.ui.edit.internal.part.listener; import java.util.Iterator; +import java.util.Objects; import org.eclipse.emf.common.notify.Notification; import org.eclipse.emf.ecore.EObject; @@ -26,8 +27,6 @@ import org.eclipse.sirius.diagram.ui.tools.internal.figure.SynchronizeStatusFigure; import org.eclipse.ui.PlatformUI; -import com.google.common.base.Objects; - /** * When the DDiagram synchronize state changes, this ResourceSet listener will update
* - the status bar
@@ -74,7 +73,7 @@ public void resourceSetChanged(ResourceSetChangeEvent event) { while (notifs.hasNext()) { Notification notif = notifs.next(); - if (Objects.equal(resolveSemanticElement, notif.getNotifier())) { + if (Objects.equals(resolveSemanticElement, notif.getNotifier())) { SynchronizeStatusFigure.updateNotification((DiagramRootEditPart) diagramEditor.getDiagramEditPart().getRoot()); break; } diff --git a/plugins/org.eclipse.sirius.diagram.ui/src-diag/org/eclipse/sirius/diagram/ui/tools/internal/format/semantic/AbstractSemanticFormatDataKey.java b/plugins/org.eclipse.sirius.diagram.ui/src-diag/org/eclipse/sirius/diagram/ui/tools/internal/format/semantic/AbstractSemanticFormatDataKey.java index 8040ea7f7a..ae08b534eb 100644 --- a/plugins/org.eclipse.sirius.diagram.ui/src-diag/org/eclipse/sirius/diagram/ui/tools/internal/format/semantic/AbstractSemanticFormatDataKey.java +++ b/plugins/org.eclipse.sirius.diagram.ui/src-diag/org/eclipse/sirius/diagram/ui/tools/internal/format/semantic/AbstractSemanticFormatDataKey.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2009, 2016 THALES GLOBAL SERVICES. + * Copyright (c) 2009, 2024 THALES GLOBAL SERVICES and others. * This program and the accompanying materials * are made available under the terms of the Eclipse Public License 2.0 * which accompanies this distribution, and is available at @@ -12,12 +12,12 @@ *******************************************************************************/ package org.eclipse.sirius.diagram.ui.tools.internal.format.semantic; +import java.util.Objects; + import org.eclipse.emf.ecore.EObject; import org.eclipse.emf.ecore.util.EcoreUtil; import org.eclipse.sirius.diagram.ui.tools.api.format.FormatDataKey; -import com.google.common.base.Objects; - /** * Common behavior for Semantic*FormatDataKey classes. * @@ -52,21 +52,11 @@ protected String getSemanticElementURIFragment() { return semanticElementURIFragment; } - /** - * {@inheritDoc} - * - * @see java.lang.Object#hashCode() - */ @Override public int hashCode() { - return Objects.hashCode(semanticElementURIFragment); + return Objects.hash(semanticElementURIFragment); } - /** - * {@inheritDoc} - * - * @see java.lang.Object#equals(java.lang.Object) - */ @Override public boolean equals(final Object obj) { boolean result = false; @@ -78,25 +68,16 @@ public boolean equals(final Object obj) { return result; } - /** - * {@inheritDoc} - */ @Override public String toString() { return "Key ID: " + getId(); //$NON-NLS-1$ } - /** - * {@inheritDoc} - */ @Override public String getId() { return getSemanticElementURIFragment(); } - /** - * {@inheritDoc} - */ @Override public int compareTo(final AbstractSemanticFormatDataKey o) { return getId().compareTo(o.getId()); diff --git a/plugins/org.eclipse.sirius.diagram/src/org/eclipse/sirius/diagram/business/internal/helper/task/DropinForNodeTaskCommand.java b/plugins/org.eclipse.sirius.diagram/src/org/eclipse/sirius/diagram/business/internal/helper/task/DropinForNodeTaskCommand.java index f3788e34b2..a87eacf2af 100644 --- a/plugins/org.eclipse.sirius.diagram/src/org/eclipse/sirius/diagram/business/internal/helper/task/DropinForNodeTaskCommand.java +++ b/plugins/org.eclipse.sirius.diagram/src/org/eclipse/sirius/diagram/business/internal/helper/task/DropinForNodeTaskCommand.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2009, 2021 THALES GLOBAL SERVICES. + * Copyright (c) 2009, 2024 THALES GLOBAL SERVICES and others. * This program and the accompanying materials * are made available under the terms of the Eclipse Public License 2.0 * which accompanies this distribution, and is available at @@ -12,6 +12,8 @@ *******************************************************************************/ package org.eclipse.sirius.diagram.business.internal.helper.task; +import java.util.Objects; + import org.eclipse.emf.ecore.EObject; import org.eclipse.sirius.business.api.helper.task.AbstractCommandTask; import org.eclipse.sirius.common.tools.api.interpreter.IInterpreter; @@ -30,8 +32,6 @@ import org.eclipse.sirius.diagram.tools.api.Messages; import org.eclipse.sirius.tools.api.SiriusPlugin; -import com.google.common.base.Objects; - /** * Default command for dropin node. * @@ -120,7 +120,7 @@ private void handleDNodeListCase(DDiagram parentDiagram) { } else if (abstractDNode instanceof DNode) { ((DNodeList) target).getOwnedBorderedNodes().add((DNode) abstractDNode); } - if (!Objects.equal(abstractDNode, droppedDiagramElement)) { + if (!Objects.equals(abstractDNode, droppedDiagramElement)) { if (moveEdges) { DnDTasksOperations.moveEdges(target, semanticContainer, droppedDiagramElement, abstractDNode); } diff --git a/plugins/org.eclipse.sirius.diagram/src/org/eclipse/sirius/diagram/business/internal/metamodel/helper/StyleHelper.java b/plugins/org.eclipse.sirius.diagram/src/org/eclipse/sirius/diagram/business/internal/metamodel/helper/StyleHelper.java index 0f3c41cf09..d8bf6890fa 100644 --- a/plugins/org.eclipse.sirius.diagram/src/org/eclipse/sirius/diagram/business/internal/metamodel/helper/StyleHelper.java +++ b/plugins/org.eclipse.sirius.diagram/src/org/eclipse/sirius/diagram/business/internal/metamodel/helper/StyleHelper.java @@ -13,6 +13,7 @@ package org.eclipse.sirius.diagram.business.internal.metamodel.helper; import java.util.List; +import java.util.Objects; import org.eclipse.core.runtime.Platform; import org.eclipse.core.runtime.preferences.IPreferencesService; @@ -104,8 +105,6 @@ import org.eclipse.sirius.viewpoint.description.style.LabelStyleDescription; import org.eclipse.sirius.viewpoint.description.style.StyleDescription; -import com.google.common.base.Objects; - /** * This helper class contains utility methods to create and update (refresh) concrete style instances from a style * description. This helper modify sometimes the diagram element to which apply the style (width, height, ...). @@ -293,7 +292,7 @@ private void updateEdgeStyle(final EdgeStyleDescription edgeDescription, final E } catch (final EvaluationException e) { // silent. } - if (!Objects.equal(size, edgeStyle.getSize())) { + if (!Objects.equals(size, edgeStyle.getSize())) { edgeStyle.setSize(size); } } @@ -775,7 +774,7 @@ private void updateBorderedStyleFeatures(BorderedStyleDescription description, B && !style.getCustomFeatures().contains(DiagramPackage.Literals.BORDERED_STYLE__BORDER_SIZE.getName())) { try { Integer borderSize = interpreter.evaluateInteger(((AbstractDNode) style.eContainer()).getTarget(), description.getBorderSizeComputationExpression()); - if (!Objects.equal(borderSize, style.getBorderSize())) { + if (!Objects.equals(borderSize, style.getBorderSize())) { style.setBorderSize(borderSize); } } catch (final EvaluationException e) { @@ -962,7 +961,7 @@ private void updateWorkspaceImage(final WorkspaceImage image, final WorkspaceIma if (image.eContainer() instanceof DNode && description.getSizeComputationExpression() != null) { final DNode node = (DNode) image.eContainer(); Integer size = computeStyleSize(node.getTarget(), description); - if (Objects.equal(-1, size)) { + if (Objects.equals(-1, size)) { // real image size if (!size.equals(node.getHeight())) { node.setHeight(size); diff --git a/plugins/org.eclipse.sirius.diagram/src/org/eclipse/sirius/diagram/business/internal/sync/DDiagramElementSynchronizer.java b/plugins/org.eclipse.sirius.diagram/src/org/eclipse/sirius/diagram/business/internal/sync/DDiagramElementSynchronizer.java index bde000df4b..a833803b00 100644 --- a/plugins/org.eclipse.sirius.diagram/src/org/eclipse/sirius/diagram/business/internal/sync/DDiagramElementSynchronizer.java +++ b/plugins/org.eclipse.sirius.diagram/src/org/eclipse/sirius/diagram/business/internal/sync/DDiagramElementSynchronizer.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2007, 2021 THALES GLOBAL SERVICES and others. + * Copyright (c) 2007, 2024 THALES GLOBAL SERVICES and others. * This program and the accompanying materials * are made available under the terms of the Eclipse Public License 2.0 * which accompanies this distribution, and is available at @@ -18,6 +18,7 @@ import java.util.HashMap; import java.util.List; import java.util.Map; +import java.util.Objects; import java.util.Set; import org.eclipse.emf.common.util.BasicEList; @@ -93,7 +94,6 @@ import org.eclipse.sirius.viewpoint.description.style.StylePackage; import org.eclipse.sirius.viewpoint.description.style.TooltipStyleDescription; -import com.google.common.base.Objects; import com.google.common.collect.ImmutableSet; import com.google.common.collect.Iterables; @@ -596,7 +596,7 @@ private void refreshTooltip(final DDiagramElement elt, final TooltipStyleDescrip if (!StringUtil.isEmpty(style.getTooltipExpression())) { final String oldValue = elt.getTooltipText(); final String newValue = computeTooltip(elt, style); - if (!Objects.equal(newValue, oldValue)) { + if (!Objects.equals(newValue, oldValue)) { elt.setTooltipText(newValue); } } diff --git a/plugins/org.eclipse.sirius.tests.junit/src/org/eclipse/sirius/tests/unit/diagram/sequence/AbstractSequenceSiriusDiagramTests.java b/plugins/org.eclipse.sirius.tests.junit/src/org/eclipse/sirius/tests/unit/diagram/sequence/AbstractSequenceSiriusDiagramTests.java index d0cead5dfe..825d1b9cc1 100644 --- a/plugins/org.eclipse.sirius.tests.junit/src/org/eclipse/sirius/tests/unit/diagram/sequence/AbstractSequenceSiriusDiagramTests.java +++ b/plugins/org.eclipse.sirius.tests.junit/src/org/eclipse/sirius/tests/unit/diagram/sequence/AbstractSequenceSiriusDiagramTests.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2010, 2019 THALES GLOBAL SERVICES. + * Copyright (c) 2010, 2024 THALES GLOBAL SERVICES and others. * This program and the accompanying materials * are made available under the terms of the Eclipse Public License 2.0 * which accompanies this distribution, and is available at @@ -14,6 +14,7 @@ import java.io.IOException; import java.util.Collection; +import java.util.Objects; import org.eclipse.core.runtime.NullProgressMonitor; import org.eclipse.draw2d.Polyline; @@ -59,8 +60,6 @@ import org.eclipse.sirius.viewpoint.description.tool.AbstractToolDescription; import org.junit.Assert; -import com.google.common.base.Objects; - public abstract class AbstractSequenceSiriusDiagramTests extends SiriusDiagramTestCase { public static final String UNIT_DATA_ROOT = "/data/sequence/unit/"; @@ -216,7 +215,7 @@ protected Option getLifelineByName(SequenceDiagram sd, String name) { protected Option getLifelineByName(Collection lifelines, String name) { for (Lifeline lifeline : lifelines) { - if (Objects.equal(getLifelineSemanticName(lifeline), name)) { + if (Objects.equals(getLifelineSemanticName(lifeline), name)) { return Options.newSome(lifeline); } } @@ -238,7 +237,7 @@ protected Option getMessageByName(SequenceDiagram sd, String name) { protected Option getMessageByName(Collection messages, String name) { for (Message message : messages) { - if (Objects.equal(getMessageSemanticName(message), name)) { + if (Objects.equals(getMessageSemanticName(message), name)) { return Options.newSome(message); } } @@ -260,7 +259,7 @@ protected Option getInteractionUseByName(SequenceDiagram sd, Str protected Option getInteractionUseByName(Collection ius, String name) { for (InteractionUse iu : ius) { - if (Objects.equal(getInteractionUseSemanticName(iu), name)) { + if (Objects.equals(getInteractionUseSemanticName(iu), name)) { return Options.newSome(iu); } } @@ -282,7 +281,7 @@ protected Option getCombinedFragmentByName(SequenceDiagram sd, protected Option getCombinedFragmentByName(Collection cfs, String name) { for (CombinedFragment cf : cfs) { - if (Objects.equal(getCombinedFragmentSemanticName(cf), name)) { + if (Objects.equals(getCombinedFragmentSemanticName(cf), name)) { return Options.newSome(cf); } } @@ -304,7 +303,7 @@ protected Option getExecutionByName(SequenceDiagram sd, String name) protected Option getExecutionByName(Collection executions, String name) { for (Execution execution : executions) { - if (Objects.equal(getExecutionSemanticName(execution), name)) { + if (Objects.equals(getExecutionSemanticName(execution), name)) { return Options.newSome(execution); } } @@ -326,7 +325,7 @@ protected Option getStateByName(SequenceDiagram sd, String name) { protected Option getStateByName(Collection states, String name) { for (State state : states) { - if (Objects.equal(getStateSemanticName(state), name)) { + if (Objects.equals(getStateSemanticName(state), name)) { return Options.newSome(state); } } @@ -348,7 +347,7 @@ protected Option getOperandByName(SequenceDiagram sd, String name) { protected Option getOperandByName(Collection operands, String name) { for (Operand operand : operands) { - if (Objects.equal(getOperandSemanticName(operand), name)) { + if (Objects.equals(getOperandSemanticName(operand), name)) { return Options.newSome(operand); } } diff --git a/plugins/org.eclipse.sirius.ui/src/org/eclipse/sirius/ui/tools/api/color/VisualBindingManager.java b/plugins/org.eclipse.sirius.ui/src/org/eclipse/sirius/ui/tools/api/color/VisualBindingManager.java index e4416fdfb0..6cb3cd6061 100644 --- a/plugins/org.eclipse.sirius.ui/src/org/eclipse/sirius/ui/tools/api/color/VisualBindingManager.java +++ b/plugins/org.eclipse.sirius.ui/src/org/eclipse/sirius/ui/tools/api/color/VisualBindingManager.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2007, 2021 THALES GLOBAL SERVICES and others. + * Copyright (c) 2007, 2024 THALES GLOBAL SERVICES and others. * This program and the accompanying materials * are made available under the terms of the Eclipse Public License 2.0 * which accompanies this distribution, and is available at @@ -21,6 +21,7 @@ import java.util.List; import java.util.Map; import java.util.Map.Entry; +import java.util.Objects; import java.util.Set; import org.eclipse.emf.common.util.URI; @@ -48,8 +49,6 @@ import org.eclipse.swt.graphics.Resource; import org.eclipse.swt.widgets.Display; -import com.google.common.base.Objects; - /** * Take care of computing colors, font or size from integer values. Avoid memory leaks by properly caching and disposing * the corresponding SWT resources. @@ -511,7 +510,7 @@ private static final class PatternDescriptor { * @param backgroundColor * the background color * @param foregrounColor - * the forground color + * the foreground color */ PatternDescriptor(final int x, final int y, final int w, final int h, final Color backgroundColor, final Color foregrounColor) { this.x = x; @@ -527,10 +526,9 @@ public boolean equals(final Object obj) { final boolean result; if (this == obj) { result = true; - } else if (obj instanceof PatternDescriptor) { - final PatternDescriptor that = (PatternDescriptor) obj; + } else if (obj instanceof PatternDescriptor that) { final boolean sameCoordinates = this.x == that.x && this.y == that.y && this.h == that.h && this.w == that.w; - result = sameCoordinates && Objects.equal(this.backgroundColor, that.backgroundColor) && Objects.equal(this.foregroundColor, that.foregroundColor); + result = sameCoordinates && Objects.equals(this.backgroundColor, that.backgroundColor) && Objects.equals(this.foregroundColor, that.foregroundColor); } else { result = false; } @@ -539,7 +537,7 @@ public boolean equals(final Object obj) { @Override public int hashCode() { - return Objects.hashCode(this.x, this.y, this.w, this.h, this.foregroundColor, this.backgroundColor); + return Objects.hash(this.x, this.y, this.w, this.h, this.foregroundColor, this.backgroundColor); } public Pattern createPattern() { @@ -799,7 +797,7 @@ private static final class FontStyleDescriptor { @Override public int hashCode() { - return Objects.hashCode(name, format, size); + return Objects.hash(name, format, size); } @Override @@ -809,7 +807,7 @@ public boolean equals(final Object obj) { result = true; } else if (obj instanceof FontStyleDescriptor) { final FontStyleDescriptor that = (FontStyleDescriptor) obj; - result = Objects.equal(this.name, that.name) && Objects.equal(this.format, that.format) && this.size == that.size; + result = Objects.equals(this.name, that.name) && Objects.equals(this.format, that.format) && this.size == that.size; } else { result = false; } diff --git a/plugins/org.eclipse.sirius.ui/src/org/eclipse/sirius/ui/tools/internal/views/common/item/AnalysisResourceItemImpl.java b/plugins/org.eclipse.sirius.ui/src/org/eclipse/sirius/ui/tools/internal/views/common/item/AnalysisResourceItemImpl.java index e5ca50b869..6fe969db74 100644 --- a/plugins/org.eclipse.sirius.ui/src/org/eclipse/sirius/ui/tools/internal/views/common/item/AnalysisResourceItemImpl.java +++ b/plugins/org.eclipse.sirius.ui/src/org/eclipse/sirius/ui/tools/internal/views/common/item/AnalysisResourceItemImpl.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2009, 2015 THALES GLOBAL SERVICES and others. + * Copyright (c) 2009, 2024 THALES GLOBAL SERVICES and others. * This program and the accompanying materials * are made available under the terms of the Eclipse Public License 2.0 * which accompanies this distribution, and is available at @@ -16,6 +16,7 @@ import java.util.Collection; import java.util.Collections; import java.util.List; +import java.util.Objects; import org.eclipse.emf.ecore.resource.Resource; import org.eclipse.sirius.business.api.session.Session; @@ -27,8 +28,6 @@ import org.eclipse.sirius.viewpoint.provider.SiriusEditPlugin; import org.eclipse.swt.graphics.Image; -import com.google.common.base.Objects; - /** * Resource item wrapper class. * @@ -119,7 +118,7 @@ public boolean equals(Object obj) { result = true; } else if (obj instanceof AnalysisResourceItemImpl) { AnalysisResourceItemImpl other = (AnalysisResourceItemImpl) obj; - result = Objects.equal(parent, other.parent) && Objects.equal(resource, other.resource); + result = Objects.equals(parent, other.parent) && Objects.equals(resource, other.resource); } return result; } From b0144f4dba46c38257114c67701cff4ef4f590dc Mon Sep 17 00:00:00 2001 From: Pierre-Charles David Date: Fri, 5 Apr 2024 19:32:21 +0200 Subject: [PATCH 4/4] [146] Remove Guava dependency in oes.editor.diagram Bug: https://github.com/eclipse-sirius/sirius-desktop/issues/146 Signed-off-by: Pierre-Charles David --- .../META-INF/MANIFEST.MF | 3 +-- ...nCenteredSourceMappingsPropertySection.java | 10 +++------- ...nCenteredTargetMappingsPropertySection.java | 10 +++------- .../CreateViewMappingPropertySection.java | 14 +++++--------- ...opDescriptionContainersPropertySection.java | 18 ++++++++++-------- ...mentDescriptionMappingsPropertySection.java | 18 +++++++++++------- .../DirectEditLabelMappingPropertySection.java | 17 ++++++++++------- ...EdgeDescriptionMappingsPropertySection.java | 18 +++++++++++------- .../refactoring/DiagramRefactoringMenu.java | 14 +++----------- 9 files changed, 57 insertions(+), 65 deletions(-) diff --git a/plugins/org.eclipse.sirius.editor.diagram/META-INF/MANIFEST.MF b/plugins/org.eclipse.sirius.editor.diagram/META-INF/MANIFEST.MF index 253e80998b..8c0723a645 100644 --- a/plugins/org.eclipse.sirius.editor.diagram/META-INF/MANIFEST.MF +++ b/plugins/org.eclipse.sirius.editor.diagram/META-INF/MANIFEST.MF @@ -4,8 +4,7 @@ Bundle-Name: %pluginName Bundle-SymbolicName: org.eclipse.sirius.editor.diagram;singleton:=true Bundle-Version: 7.4.3.qualifier Bundle-Vendor: %providerName -Require-Bundle: com.google.guava;bundle-version="27.0", - org.eclipse.core.runtime;bundle-version="3.8.0", +Require-Bundle: org.eclipse.core.runtime;bundle-version="3.8.0", org.eclipse.emf.edit.ui;bundle-version="2.3.1", org.eclipse.sirius.common;bundle-version="7.4.3", org.eclipse.sirius.common.ui;bundle-version="7.4.3", diff --git a/plugins/org.eclipse.sirius.editor.diagram/src-gen/org/eclipse/sirius/diagram/editor/properties/sections/style/edgestyledescription/EdgeStyleDescriptionCenteredSourceMappingsPropertySection.java b/plugins/org.eclipse.sirius.editor.diagram/src-gen/org/eclipse/sirius/diagram/editor/properties/sections/style/edgestyledescription/EdgeStyleDescriptionCenteredSourceMappingsPropertySection.java index 89fd93445c..fc1fd7bc0a 100644 --- a/plugins/org.eclipse.sirius.editor.diagram/src-gen/org/eclipse/sirius/diagram/editor/properties/sections/style/edgestyledescription/EdgeStyleDescriptionCenteredSourceMappingsPropertySection.java +++ b/plugins/org.eclipse.sirius.editor.diagram/src-gen/org/eclipse/sirius/diagram/editor/properties/sections/style/edgestyledescription/EdgeStyleDescriptionCenteredSourceMappingsPropertySection.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2007, 2018 THALES GLOBAL SERVICES. + * Copyright (c) 2007, 2024 THALES GLOBAL SERVICES and others. * This program and the accompanying materials * are made available under the terms of the Eclipse Public License 2.0 * which accompanies this distribution, and is available at @@ -15,9 +15,9 @@ // Start of user code imports import java.util.ArrayList; -import java.util.Collection; import java.util.Iterator; import java.util.List; +import java.util.stream.Collectors; import org.eclipse.emf.common.util.EList; import org.eclipse.emf.ecore.EObject; @@ -36,9 +36,6 @@ import org.eclipse.swt.widgets.Composite; import org.eclipse.ui.views.properties.tabbed.TabbedPropertySheetPage; -import com.google.common.base.Predicates; -import com.google.common.collect.Collections2; - // End of user code imports /** @@ -153,8 +150,7 @@ private boolean isActivated() { protected List getChoiceOfValues(List currentValues) { List choiceOfValues = super.getChoiceOfValues(currentValues); removeUnrelatedMappings(choiceOfValues); - Collection collection = Collections2.filter(choiceOfValues, Predicates.instanceOf(AbstractNodeMapping.class)); - return new ArrayList(collection); + return choiceOfValues.stream().filter(AbstractNodeMapping.class::isInstance).collect(Collectors.toCollection(ArrayList::new)); } private void removeUnrelatedMappings(List choiceOfValues) { diff --git a/plugins/org.eclipse.sirius.editor.diagram/src-gen/org/eclipse/sirius/diagram/editor/properties/sections/style/edgestyledescription/EdgeStyleDescriptionCenteredTargetMappingsPropertySection.java b/plugins/org.eclipse.sirius.editor.diagram/src-gen/org/eclipse/sirius/diagram/editor/properties/sections/style/edgestyledescription/EdgeStyleDescriptionCenteredTargetMappingsPropertySection.java index e5db5f2b00..e560d14542 100644 --- a/plugins/org.eclipse.sirius.editor.diagram/src-gen/org/eclipse/sirius/diagram/editor/properties/sections/style/edgestyledescription/EdgeStyleDescriptionCenteredTargetMappingsPropertySection.java +++ b/plugins/org.eclipse.sirius.editor.diagram/src-gen/org/eclipse/sirius/diagram/editor/properties/sections/style/edgestyledescription/EdgeStyleDescriptionCenteredTargetMappingsPropertySection.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2007, 2018 THALES GLOBAL SERVICES. + * Copyright (c) 2007, 2024 THALES GLOBAL SERVICES. * This program and the accompanying materials * are made available under the terms of the Eclipse Public License 2.0 * which accompanies this distribution, and is available at @@ -15,9 +15,9 @@ // Start of user code imports import java.util.ArrayList; -import java.util.Collection; import java.util.Iterator; import java.util.List; +import java.util.stream.Collectors; import org.eclipse.emf.common.util.EList; import org.eclipse.emf.ecore.EObject; @@ -36,9 +36,6 @@ import org.eclipse.swt.widgets.Composite; import org.eclipse.ui.views.properties.tabbed.TabbedPropertySheetPage; -import com.google.common.base.Predicates; -import com.google.common.collect.Collections2; - // End of user code imports /** @@ -153,8 +150,7 @@ private boolean isActivated() { protected List getChoiceOfValues(List currentValues) { List choiceOfValues = super.getChoiceOfValues(currentValues); removeUnrelatedMappings(choiceOfValues); - Collection collection = Collections2.filter(choiceOfValues, Predicates.instanceOf(AbstractNodeMapping.class)); - return new ArrayList(collection); + return choiceOfValues.stream().filter(AbstractNodeMapping.class::isInstance).collect(Collectors.toCollection(ArrayList::new)); } private void removeUnrelatedMappings(List choiceOfValues) { diff --git a/plugins/org.eclipse.sirius.editor.diagram/src-gen/org/eclipse/sirius/diagram/editor/properties/sections/tool/createview/CreateViewMappingPropertySection.java b/plugins/org.eclipse.sirius.editor.diagram/src-gen/org/eclipse/sirius/diagram/editor/properties/sections/tool/createview/CreateViewMappingPropertySection.java index 07963ff645..fc4c9850c2 100644 --- a/plugins/org.eclipse.sirius.editor.diagram/src-gen/org/eclipse/sirius/diagram/editor/properties/sections/tool/createview/CreateViewMappingPropertySection.java +++ b/plugins/org.eclipse.sirius.editor.diagram/src-gen/org/eclipse/sirius/diagram/editor/properties/sections/tool/createview/CreateViewMappingPropertySection.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2007, 2018 THALES GLOBAL SERVICES. + * Copyright (c) 2007, 2024 THALES GLOBAL SERVICES and others. * This program and the accompanying materials * are made available under the terms of the Eclipse Public License 2.0 * which accompanies this distribution, and is available at @@ -17,6 +17,7 @@ import java.util.ArrayList; import java.util.Collections; import java.util.List; +import java.util.function.Predicate; import org.eclipse.emf.ecore.EReference; import org.eclipse.emf.ecore.EStructuralFeature; @@ -35,11 +36,6 @@ import org.eclipse.swt.widgets.Composite; import org.eclipse.ui.views.properties.tabbed.TabbedPropertySheetPage; -import com.google.common.base.Predicate; -import com.google.common.base.Predicates; -import com.google.common.collect.Iterables; -import com.google.common.collect.Lists; - // End of user code imports /** @@ -129,11 +125,11 @@ protected List getChoiceOfValues() { // Start of user code choice of values if (!values.isEmpty()) { - Predicate predicate = Predicates.or(Predicates.instanceOf(EdgeMapping.class), Predicates.instanceOf(EdgeMappingImport.class)); + Predicate predicate = object -> object instanceof EdgeMapping || object instanceof EdgeMappingImport; if (eObject instanceof CreateEdgeView) { - values = Lists.newArrayList(Iterables.filter(values, predicate)); + values = values.stream().filter(predicate).toList(); } else if (eObject instanceof CreateView) { - values = Lists.newArrayList(Iterables.filter(values, Predicates.not(predicate))); + values = values.stream().filter(Predicate.not(predicate)).toList(); } } // End of user code choice of values diff --git a/plugins/org.eclipse.sirius.editor.diagram/src/org/eclipse/sirius/diagram/editor/properties/sections/tool/containerdropdescription/ContainerDropDescriptionContainersPropertySection.java b/plugins/org.eclipse.sirius.editor.diagram/src/org/eclipse/sirius/diagram/editor/properties/sections/tool/containerdropdescription/ContainerDropDescriptionContainersPropertySection.java index 2149facac6..92b400bb92 100644 --- a/plugins/org.eclipse.sirius.editor.diagram/src/org/eclipse/sirius/diagram/editor/properties/sections/tool/containerdropdescription/ContainerDropDescriptionContainersPropertySection.java +++ b/plugins/org.eclipse.sirius.editor.diagram/src/org/eclipse/sirius/diagram/editor/properties/sections/tool/containerdropdescription/ContainerDropDescriptionContainersPropertySection.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2007 - 2010 THALES GLOBAL SERVICES. + * Copyright (c) 2007, 2024 THALES GLOBAL SERVICES and others. * This program and the accompanying materials * are made available under the terms of the Eclipse Public License 2.0 * which accompanies this distribution, and is available at @@ -12,6 +12,8 @@ *******************************************************************************/ package org.eclipse.sirius.diagram.editor.properties.sections.tool.containerdropdescription; +import java.util.ArrayList; + // Start of user code imports import java.util.Iterator; @@ -35,10 +37,6 @@ import org.eclipse.swt.widgets.Composite; import org.eclipse.ui.views.properties.tabbed.TabbedPropertySheetPage; -import com.google.common.collect.Iterators; -import com.google.common.collect.Lists; -import com.google.common.collect.UnmodifiableIterator; - // End of user code imports /** @@ -106,9 +104,13 @@ protected boolean getSortChoice() { */ @Override protected List getChoiceOfValues() { - UnmodifiableIterator filter = Iterators.filter(eObject.eResource().getResourceSet().getAllContents(), - DragAndDropTargetDescription.class); - return Lists.newArrayList(filter); + List result = new ArrayList<>(); + eObject.eResource().getResourceSet().getAllContents().forEachRemaining(notifier -> { + if (notifier instanceof DragAndDropTargetDescription dndTarget) { + result.add(dndTarget); + } + }); + return result; } /** diff --git a/plugins/org.eclipse.sirius.editor.diagram/src/org/eclipse/sirius/diagram/editor/properties/sections/tool/deleteelementdescription/DeleteElementDescriptionMappingsPropertySection.java b/plugins/org.eclipse.sirius.editor.diagram/src/org/eclipse/sirius/diagram/editor/properties/sections/tool/deleteelementdescription/DeleteElementDescriptionMappingsPropertySection.java index 360d064e3e..400684fa3b 100644 --- a/plugins/org.eclipse.sirius.editor.diagram/src/org/eclipse/sirius/diagram/editor/properties/sections/tool/deleteelementdescription/DeleteElementDescriptionMappingsPropertySection.java +++ b/plugins/org.eclipse.sirius.editor.diagram/src/org/eclipse/sirius/diagram/editor/properties/sections/tool/deleteelementdescription/DeleteElementDescriptionMappingsPropertySection.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2007 - 2010 THALES GLOBAL SERVICES. + * Copyright (c) 2007, 2024 THALES GLOBAL SERVICES and others. * This program and the accompanying materials * are made available under the terms of the Eclipse Public License 2.0 * which accompanies this distribution, and is available at @@ -12,6 +12,8 @@ *******************************************************************************/ package org.eclipse.sirius.diagram.editor.properties.sections.tool.deleteelementdescription; +import java.util.ArrayList; + // Start of user code imports import java.util.Iterator; @@ -25,6 +27,7 @@ import org.eclipse.emf.edit.domain.IEditingDomainProvider; import org.eclipse.sirius.diagram.description.DescriptionPackage; import org.eclipse.sirius.diagram.description.DiagramElementMapping; +import org.eclipse.sirius.diagram.description.DragAndDropTargetDescription; import org.eclipse.sirius.diagram.description.tool.DeleteElementDescription; import org.eclipse.sirius.editor.editorPlugin.SiriusEditor; import org.eclipse.sirius.editor.properties.sections.common.AbstractEditorDialogWithListPropertySection; @@ -35,10 +38,6 @@ import org.eclipse.swt.widgets.Composite; import org.eclipse.ui.views.properties.tabbed.TabbedPropertySheetPage; -import com.google.common.collect.Iterators; -import com.google.common.collect.Lists; -import com.google.common.collect.UnmodifiableIterator; - // End of user code imports /** @@ -106,8 +105,13 @@ protected boolean getSortChoice() { */ @Override protected List getChoiceOfValues() { - UnmodifiableIterator filter = Iterators.filter(eObject.eResource().getResourceSet().getAllContents(), DiagramElementMapping.class); - return Lists.newArrayList(filter); + List result = new ArrayList<>(); + eObject.eResource().getResourceSet().getAllContents().forEachRemaining(notifier -> { + if (notifier instanceof DiagramElementMapping mapping) { + result.add(mapping); + } + }); + return result; } /** diff --git a/plugins/org.eclipse.sirius.editor.diagram/src/org/eclipse/sirius/diagram/editor/properties/sections/tool/directeditlabel/DirectEditLabelMappingPropertySection.java b/plugins/org.eclipse.sirius.editor.diagram/src/org/eclipse/sirius/diagram/editor/properties/sections/tool/directeditlabel/DirectEditLabelMappingPropertySection.java index 4e2ce40b6c..9a565fce77 100644 --- a/plugins/org.eclipse.sirius.editor.diagram/src/org/eclipse/sirius/diagram/editor/properties/sections/tool/directeditlabel/DirectEditLabelMappingPropertySection.java +++ b/plugins/org.eclipse.sirius.editor.diagram/src/org/eclipse/sirius/diagram/editor/properties/sections/tool/directeditlabel/DirectEditLabelMappingPropertySection.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2007 - 2010 THALES GLOBAL SERVICES. + * Copyright (c) 2007, 2024 THALES GLOBAL SERVICES and others. * This program and the accompanying materials * are made available under the terms of the Eclipse Public License 2.0 * which accompanies this distribution, and is available at @@ -12,6 +12,8 @@ *******************************************************************************/ package org.eclipse.sirius.diagram.editor.properties.sections.tool.directeditlabel; +import java.util.ArrayList; + // Start of user code imports import java.util.Iterator; @@ -35,10 +37,6 @@ import org.eclipse.swt.widgets.Composite; import org.eclipse.ui.views.properties.tabbed.TabbedPropertySheetPage; -import com.google.common.collect.Iterators; -import com.google.common.collect.Lists; -import com.google.common.collect.UnmodifiableIterator; - // End of user code imports /** @@ -135,8 +133,13 @@ protected boolean getSortChoice() { */ @Override protected List getChoiceOfValues() { - UnmodifiableIterator filter = Iterators.filter(eObject.eResource().getResourceSet().getAllContents(), DiagramElementMapping.class); - return Lists.newArrayList(filter); + List result = new ArrayList<>(); + eObject.eResource().getResourceSet().getAllContents().forEachRemaining(notifier -> { + if (notifier instanceof DiagramElementMapping mapping) { + result.add(mapping); + } + }); + return result; } /** diff --git a/plugins/org.eclipse.sirius.editor.diagram/src/org/eclipse/sirius/diagram/editor/properties/sections/tool/reconnectedgedescription/ReconnectEdgeDescriptionMappingsPropertySection.java b/plugins/org.eclipse.sirius.editor.diagram/src/org/eclipse/sirius/diagram/editor/properties/sections/tool/reconnectedgedescription/ReconnectEdgeDescriptionMappingsPropertySection.java index 380743822e..d7f898c5f0 100644 --- a/plugins/org.eclipse.sirius.editor.diagram/src/org/eclipse/sirius/diagram/editor/properties/sections/tool/reconnectedgedescription/ReconnectEdgeDescriptionMappingsPropertySection.java +++ b/plugins/org.eclipse.sirius.editor.diagram/src/org/eclipse/sirius/diagram/editor/properties/sections/tool/reconnectedgedescription/ReconnectEdgeDescriptionMappingsPropertySection.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2007 - 2010 THALES GLOBAL SERVICES. + * Copyright (c) 2007, 2024 THALES GLOBAL SERVICES and others. * This program and the accompanying materials * are made available under the terms of the Eclipse Public License 2.0 * which accompanies this distribution, and is available at @@ -12,6 +12,8 @@ *******************************************************************************/ package org.eclipse.sirius.diagram.editor.properties.sections.tool.reconnectedgedescription; +import java.util.ArrayList; + // Start of user code imports import java.util.Iterator; @@ -26,6 +28,7 @@ import org.eclipse.emf.edit.domain.EditingDomain; import org.eclipse.emf.edit.domain.IEditingDomainProvider; import org.eclipse.sirius.diagram.description.DescriptionPackage; +import org.eclipse.sirius.diagram.description.DiagramElementMapping; import org.eclipse.sirius.diagram.description.EdgeMapping; import org.eclipse.sirius.diagram.description.tool.ReconnectEdgeDescription; import org.eclipse.sirius.editor.editorPlugin.SiriusEditor; @@ -37,10 +40,6 @@ import org.eclipse.swt.widgets.Composite; import org.eclipse.ui.views.properties.tabbed.TabbedPropertySheetPage; -import com.google.common.collect.Iterators; -import com.google.common.collect.Lists; -import com.google.common.collect.UnmodifiableIterator; - // End of user code imports /** @@ -108,8 +107,13 @@ protected boolean getSortChoice() { */ @Override protected List getChoiceOfValues() { - UnmodifiableIterator filter = Iterators.filter(eObject.eResource().getResourceSet().getAllContents(), EdgeMapping.class); - return Lists.newArrayList(filter); + List result = new ArrayList<>(); + eObject.eResource().getResourceSet().getAllContents().forEachRemaining(notifier -> { + if (notifier instanceof EdgeMapping mapping) { + result.add(mapping); + } + }); + return result; } /** diff --git a/plugins/org.eclipse.sirius.editor.diagram/src/org/eclipse/sirius/diagram/editor/tools/internal/menu/refactoring/DiagramRefactoringMenu.java b/plugins/org.eclipse.sirius.editor.diagram/src/org/eclipse/sirius/diagram/editor/tools/internal/menu/refactoring/DiagramRefactoringMenu.java index efadfcb463..01a68a8084 100644 --- a/plugins/org.eclipse.sirius.editor.diagram/src/org/eclipse/sirius/diagram/editor/tools/internal/menu/refactoring/DiagramRefactoringMenu.java +++ b/plugins/org.eclipse.sirius.editor.diagram/src/org/eclipse/sirius/diagram/editor/tools/internal/menu/refactoring/DiagramRefactoringMenu.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2009, 2015 THALES GLOBAL SERVICES and others. + * Copyright (c) 2009, 2024 THALES GLOBAL SERVICES and others. * This program and the accompanying materials * are made available under the terms of the Eclipse Public License 2.0 * which accompanies this distribution, and is available at @@ -15,6 +15,7 @@ import java.util.Collection; import java.util.LinkedHashSet; import java.util.Set; +import java.util.stream.Collectors; import org.eclipse.emf.edit.command.CommandParameter; import org.eclipse.jface.viewers.ISelection; @@ -24,14 +25,10 @@ import org.eclipse.sirius.editor.tools.internal.menu.refactoring.RefactoringMenu; import org.eclipse.ui.IEditorPart; -import com.google.common.base.Predicate; -import com.google.common.collect.Sets; - /** * The menu for the refactoring actions. * * @author cbrun - * */ public class DiagramRefactoringMenu extends AbstractMenuBuilder { @Override @@ -58,12 +55,7 @@ private Collection generateRefactoringActions(final ISelection selection, final allActions.add(new EdgeMappingRefactoringAction(editor, selection)); // We only add to the menu the actions that have a valid selection - return Sets.filter(allActions, new Predicate() { - - public boolean apply(AbstractEObjectRefactoringAction candidateAction) { - return candidateAction.isSelectionValid(); - } - }); + return allActions.stream().filter(AbstractEObjectRefactoringAction::isSelectionValid).collect(Collectors.toSet()); } @Override