From dbc038b44bcbb890ae256d15eb09eb285512f020 Mon Sep 17 00:00:00 2001 From: Camille Letavernier Date: Thu, 21 Aug 2014 13:43:07 +0200 Subject: [Code style] Apply clean-up and formatter on Main plug-ins --- .../infra/emf/utils/BusinessModelResolver.java | 8 +- .../infra/emf/utils/EClassNameComparator.java | 8 +- .../papyrus/infra/emf/utils/EMFContants.java | 8 +- .../papyrus/infra/emf/utils/EMFFileUtil.java | 23 +- .../eclipse/papyrus/infra/emf/utils/EMFHelper.java | 433 ++++++++++----------- .../infra/emf/utils/EMFStringValueConverter.java | 146 +++---- .../infra/emf/utils/ENamedElementComparator.java | 6 +- .../papyrus/infra/emf/utils/HistoryUtil.java | 8 +- .../papyrus/infra/emf/utils/ProviderHelper.java | 10 +- .../papyrus/infra/emf/utils/ResourceUtils.java | 52 +-- .../emf/utils/ServiceRegistryAdapterFactory.java | 10 +- .../infra/emf/utils/ServiceUtilsForEObject.java | 10 +- .../infra/emf/utils/ServiceUtilsForHandlers.java | 50 +-- .../utils/ServiceUtilsForIEvaluationContext.java | 48 +-- .../infra/emf/utils/ServiceUtilsForResource.java | 26 +- .../ServiceUtilsForResourceInitializerService.java | 20 +- .../emf/utils/ServiceUtilsForResourceSet.java | 10 +- .../infra/emf/utils/ServiceUtilsForSelection.java | 16 +- .../infra/emf/utils/TextReferencesHelper.java | 106 ++--- .../infra/emf/utils/TransactionalUnsetter.java | 18 +- 20 files changed, 508 insertions(+), 508 deletions(-) (limited to 'plugins/infra/emf/org.eclipse.papyrus.infra.emf/src/org/eclipse/papyrus/infra/emf/utils') diff --git a/plugins/infra/emf/org.eclipse.papyrus.infra.emf/src/org/eclipse/papyrus/infra/emf/utils/BusinessModelResolver.java b/plugins/infra/emf/org.eclipse.papyrus.infra.emf/src/org/eclipse/papyrus/infra/emf/utils/BusinessModelResolver.java index eb840db7f3b..1aa4fce087c 100644 --- a/plugins/infra/emf/org.eclipse.papyrus.infra.emf/src/org/eclipse/papyrus/infra/emf/utils/BusinessModelResolver.java +++ b/plugins/infra/emf/org.eclipse.papyrus.infra.emf/src/org/eclipse/papyrus/infra/emf/utils/BusinessModelResolver.java @@ -1,7 +1,7 @@ /***************************************************************************** * Copyright (c) 2008 CEA LIST. * - * + * * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -22,8 +22,8 @@ package org.eclipse.papyrus.infra.emf.utils; * already registered : gef.EditPart TODO Use extensions to register additional * resolvers. */ -//Refactoring 0.10: This class has been moved from infra.core to infra.emf. -//It should be re-implemented as a Service. +// Refactoring 0.10: This class has been moved from infra.core to infra.emf. +// It should be re-implemented as a Service. public class BusinessModelResolver { /** @@ -39,7 +39,7 @@ public class BusinessModelResolver { * Get the business object associated to this object, if any. This method * navigate throw the object if the object is an graphical artefact or a * diagram artifact. - * + * * @param object * @return Object */ diff --git a/plugins/infra/emf/org.eclipse.papyrus.infra.emf/src/org/eclipse/papyrus/infra/emf/utils/EClassNameComparator.java b/plugins/infra/emf/org.eclipse.papyrus.infra.emf/src/org/eclipse/papyrus/infra/emf/utils/EClassNameComparator.java index 0d559144ede..d8d4217066d 100644 --- a/plugins/infra/emf/org.eclipse.papyrus.infra.emf/src/org/eclipse/papyrus/infra/emf/utils/EClassNameComparator.java +++ b/plugins/infra/emf/org.eclipse.papyrus.infra.emf/src/org/eclipse/papyrus/infra/emf/utils/EClassNameComparator.java @@ -1,6 +1,6 @@ /***************************************************************************** * Copyright (c) 2011 CEA LIST. - * + * * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -18,14 +18,14 @@ import org.eclipse.emf.ecore.EClass; /** * A class for comparing EClasses by name - * + * * @author Camille Letavernier - * + * */ public class EClassNameComparator implements Comparator { public int compare(EClass class1, EClass class2) { - if(class1 == null) { + if (class1 == null) { return class2 == null ? 0 : -1; } diff --git a/plugins/infra/emf/org.eclipse.papyrus.infra.emf/src/org/eclipse/papyrus/infra/emf/utils/EMFContants.java b/plugins/infra/emf/org.eclipse.papyrus.infra.emf/src/org/eclipse/papyrus/infra/emf/utils/EMFContants.java index 68545151410..18c0a6310d7 100644 --- a/plugins/infra/emf/org.eclipse.papyrus.infra.emf/src/org/eclipse/papyrus/infra/emf/utils/EMFContants.java +++ b/plugins/infra/emf/org.eclipse.papyrus.infra.emf/src/org/eclipse/papyrus/infra/emf/utils/EMFContants.java @@ -1,7 +1,7 @@ /***************************************************************************** * Copyright (c) 2013 CEA LIST. * - * + * * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -15,15 +15,15 @@ package org.eclipse.papyrus.infra.emf.utils; /** * Thyis class defines some useful constants for EMF - * + * * @author vl222926 - * + * */ public class EMFContants { private EMFContants() { - //to prevent instanciation + // to prevent instanciation } public static final String ESTRING = "EString"; diff --git a/plugins/infra/emf/org.eclipse.papyrus.infra.emf/src/org/eclipse/papyrus/infra/emf/utils/EMFFileUtil.java b/plugins/infra/emf/org.eclipse.papyrus.infra.emf/src/org/eclipse/papyrus/infra/emf/utils/EMFFileUtil.java index b66b1cadeb2..cc95ad412b7 100644 --- a/plugins/infra/emf/org.eclipse.papyrus.infra.emf/src/org/eclipse/papyrus/infra/emf/utils/EMFFileUtil.java +++ b/plugins/infra/emf/org.eclipse.papyrus.infra.emf/src/org/eclipse/papyrus/infra/emf/utils/EMFFileUtil.java @@ -1,7 +1,7 @@ /***************************************************************************** * Copyright (c) 2014 CEA LIST. * - * + * * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -15,7 +15,6 @@ package org.eclipse.papyrus.infra.emf.utils; import java.io.File; import org.eclipse.core.resources.IFile; -import org.eclipse.core.resources.IWorkspace; import org.eclipse.core.resources.IWorkspaceRoot; import org.eclipse.core.resources.ResourcesPlugin; import org.eclipse.core.runtime.IPath; @@ -30,12 +29,13 @@ public class EMFFileUtil { * Returns the path to the IFile (Encoded) * * @param file + * * @return */ - public static String getPath(IFile file) { + public static String getPath(IFile file) { URI uri = URI.createPlatformResourceURI(file.getFullPath().toString(), true); - - //ToString, toPlatformString + + // ToString, toPlatformString return uri.toString(); } @@ -45,17 +45,18 @@ public class EMFFileUtil { * relative to the workspace root. * * @param location + * * @return */ public static IFile getIFile(String location) { URI uri = URI.createURI(location); IWorkspaceRoot workspace = ResourcesPlugin.getWorkspace().getRoot(); - - //Search the file in the workspace - if (uri.isPlatform()){ + + // Search the file in the workspace + if (uri.isPlatform()) { Path workspacePath = new Path(uri.toPlatformString(true)); return workspace.getFile(workspacePath); - } else { //Then search it on the disk + } else { // Then search it on the disk Path absolutePath = new Path(URI.decode(location)); return workspace.getFileForLocation(absolutePath); } @@ -67,11 +68,12 @@ public class EMFFileUtil { * relative to the workspace root. * * @param location + * * @return */ public static File getFile(String location) { IFile iFile = getIFile(location); - if(iFile == null || !iFile.exists()) { + if (iFile == null || !iFile.exists()) { return new File(location); } @@ -83,6 +85,7 @@ public class EMFFileUtil { * The location is relative to the workspace root. * * @param location + * * @return */ public static File getWorkspaceFile(String location) { diff --git a/plugins/infra/emf/org.eclipse.papyrus.infra.emf/src/org/eclipse/papyrus/infra/emf/utils/EMFHelper.java b/plugins/infra/emf/org.eclipse.papyrus.infra.emf/src/org/eclipse/papyrus/infra/emf/utils/EMFHelper.java index 4e579760b83..214bda7c03b 100644 --- a/plugins/infra/emf/org.eclipse.papyrus.infra.emf/src/org/eclipse/papyrus/infra/emf/utils/EMFHelper.java +++ b/plugins/infra/emf/org.eclipse.papyrus.infra.emf/src/org/eclipse/papyrus/infra/emf/utils/EMFHelper.java @@ -1,6 +1,6 @@ /***************************************************************************** * Copyright (c) 2010, 2014 CEA LIST and others. - * + * * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -15,7 +15,7 @@ * Christian W. Damus (CEA) - bug 408491 * Christian W. Damus (CEA) - bug 432813 * Christian W. Damus (CEA) - bug 422257 - * + * *****************************************************************************/ package org.eclipse.papyrus.infra.emf.utils; @@ -65,25 +65,25 @@ import com.google.common.collect.Iterables; /** * A Helper class for manipulating EMF Objects - * + * * @author Camille Letavernier */ -//TODO : Check implementations. Most of them are old and don't always match the specification +// TODO : Check implementations. Most of them are old and don't always match the specification public class EMFHelper { /** * Returns the EClass corresponding to the given nsUri and className - * + * * @param nsUri - * The NSURI of the EClass' EPackage + * The NSURI of the EClass' EPackage * @param className - * The EClass' name + * The EClass' name * @return * The EClass instance, or null if the EClass couldn't be found */ public static EClass getEClass(final String nsUri, final String className) { EPackage ePackage = EPackage.Registry.INSTANCE.getEPackage(nsUri); - if(ePackage == null) { + if (ePackage == null) { Activator.log.warn("Cannot find an EPackage matching the nsURI " + nsUri); //$NON-NLS-1$ return null; } @@ -92,21 +92,21 @@ public class EMFHelper { /** * Return the EClass corresponding to the given EPackage and className - * + * * @param metamodel - * The EClass' EPackage + * The EClass' EPackage * @param className - * The EClass' name + * The EClass' name * @return * The EClass instance, or null if the EClass couldn't be found */ public static EClass getEClass(final EPackage metamodel, final String className) { EClassifier classifier = metamodel.getEClassifier(className); - if(classifier == null) { + if (classifier == null) { Activator.log.warn("Classifier " + className + " not found in metamodel " + metamodel.getName() + " (" + metamodel.getNsURI() + ")"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ } - if(classifier instanceof EClass) { - return (EClass)classifier; + if (classifier instanceof EClass) { + return (EClass) classifier; } else { Activator.log.warn("Classifier " + className + " in " + metamodel.getName() + " (" + metamodel.getNsURI() + ") is not an EClass"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ } @@ -116,13 +116,13 @@ public class EMFHelper { /** * Tests if an Object is an instance of the given EClass - * + * * @param element - * The EObject to test + * The EObject to test * @param className - * The name of the EClass + * The name of the EClass * @param metamodel - * The EPackage owning the EClass + * The EPackage owning the EClass * @return * True if the EObject is an instance of the EClass, or of one of the EClass' subtypes */ @@ -130,7 +130,7 @@ public class EMFHelper { EClassifier theClass = metamodel.getEClassifier(className); - if(theClass == null) { + if (theClass == null) { String message = String.format("Class %s not found in metamodel: %s (%s)", className, metamodel.getName(), metamodel.getNsURI());//$NON-NLS-1$ Activator.log.warn(message); return false; @@ -144,25 +144,25 @@ public class EMFHelper { * Tests if an Object is an instance of the given EClass * * @param element - * The EObject to test + * The EObject to test * @param className - * The name of the EClass + * The name of the EClass * @param metamodel - * The URI of the EPackage owning the EClass + * The URI of the EPackage owning the EClass * @return * True if the EObject is an instance of the EClass, or of one of the EClass' subtypes */ public static boolean isInstance(EObject selectedItem, String className, String nsUri) { EClass actualEClass = selectedItem.eClass(); - //Exact match - if(isExactMatch(actualEClass, className, nsUri)) { + // Exact match + if (isExactMatch(actualEClass, className, nsUri)) { return true; } List allSuperTypes = actualEClass.getEAllSuperTypes(); - for(EClass eClass : allSuperTypes) { - if(isExactMatch(eClass, className, nsUri)) { + for (EClass eClass : allSuperTypes) { + if (isExactMatch(eClass, className, nsUri)) { return true; } } @@ -174,7 +174,7 @@ public class EMFHelper { * Tests whether the given EClass has the given className and belongs to the EPackage represented by nsUri * * @param eClass - * The EClass to test + * The EClass to test * @param className * * @param nsUri @@ -188,24 +188,24 @@ public class EMFHelper { /** * Tests if the given eClass is a Subclass of fromClass * Also returns true when eClass == fromClass - * + * * @param eClass * @param fromClass * @return * true if eClass is a subclass of fromClass */ public static boolean isSubclass(final EClass eClass, final EClass fromClass) { - //Everything is an EObject - if(eClass != null && fromClass == EcorePackage.eINSTANCE.getEObject()) { + // Everything is an EObject + if (eClass != null && fromClass == EcorePackage.eINSTANCE.getEObject()) { return true; } - if(eClass == fromClass) { + if (eClass == fromClass) { return true; } List superTypes = eClass.getEAllSuperTypes(); - if(superTypes.contains(fromClass)) { + if (superTypes.contains(fromClass)) { return true; } @@ -216,27 +216,27 @@ public class EMFHelper { * Returns the EObject corresponding to the input object * Tests if the input is an EObject, or if it is Adaptable * to an EObject - * + * * @param source * @return An EObject corresponding to the input source, or null * if the EObject could not be resolved */ public static EObject getEObject(final Object source) { - //Support for EMF 0.2 CustomizedTree: The TreeElements are EObjects, and do not implement IAdatapble. - //FIXME: Use an AdapterFactory instead, to remove the dependency to EMF Facet 0.2 + // Support for EMF 0.2 CustomizedTree: The TreeElements are EObjects, and do not implement IAdatapble. + // FIXME: Use an AdapterFactory instead, to remove the dependency to EMF Facet 0.2 Object resolved = CustomizedContentProviderUtils.resolve(source); - if(resolved != source && isEMFModelElement(resolved)) { - return (EObject)resolved; + if (resolved != source && isEMFModelElement(resolved)) { + return (EObject) resolved; } - //General case - if(isEMFModelElement(source)) { - return (EObject)source; - } else if(source instanceof IAdaptable) { - EObject eObject = (EObject)((IAdaptable)source).getAdapter(EObject.class); - if(eObject == null) { //EMF Facet 0.1 - eObject = (EObject)((IAdaptable)source).getAdapter(EReference.class); + // General case + if (isEMFModelElement(source)) { + return (EObject) source; + } else if (source instanceof IAdaptable) { + EObject eObject = (EObject) ((IAdaptable) source).getAdapter(EObject.class); + if (eObject == null) { // EMF Facet 0.1 + eObject = (EObject) ((IAdaptable) source).getAdapter(EReference.class); } return asEMFModelElement(eObject); // in case the adapter is a CDOResource } @@ -251,11 +251,11 @@ public class EMFHelper { * where objects are {@code EObject}s but shouldn't be treated as * "model content". But, a minimum requirement is that the {@code object} is * an {@link EObject}. - * + * * @param object - * an object + * an object * @return whether it is "model content" - * + * * @see EMFHelper#asEMFModelElement(Object) */ public static boolean isEMFModelElement(Object object) { @@ -264,22 +264,22 @@ public class EMFHelper { /** * Casts an {@code object} as an EMF model element, if appropriate. - * + * * @param object - * an object + * an object * @return the object as an EMF model element, or {@code null} if it is not * an EMF model element - * + * * @see #isEMFModelElement(Object) */ public static EObject asEMFModelElement(Object object) { - return isEMFModelElement(object) ? (EObject)object : null; + return isEMFModelElement(object) ? (EObject) object : null; } /** * Retrieve the EditingDomain for the given source object. The object is first * resolved to an EObject through #getEObject when possible. - * + * * @param source * @return * The source object's editing domain, or null if it couldn't be found @@ -290,18 +290,18 @@ public class EMFHelper { /** * Retrieve the EditingDomain for the given source EObject - * + * * @param source * @return * The source eObject's editing domain, or null if it couldn't be found */ public static EditingDomain resolveEditingDomain(final EObject source) { EditingDomain domain = AdapterFactoryEditingDomain.getEditingDomainFor(source); - if(domain == null) { + if (domain == null) { try { domain = ServiceUtilsForActionHandlers.getInstance().getTransactionalEditingDomain(); } catch (ServiceException e) { - //Ignore: We cannot find the domain + // Ignore: We cannot find the domain } } return domain; @@ -310,10 +310,10 @@ public class EMFHelper { /** * Return the eClassifier' qualified name. The qualified name is obtained by the concatenation * of its package hierarchy with the class name, separated by the given separator - * + * * @param eClassifier * @param separator - * The separator used between each package name + * The separator used between each package name * @return * The EClassifier' qualified name */ @@ -324,15 +324,15 @@ public class EMFHelper { /** * Return the ePackage's qualified name. The qualified name is obtained by the concatenation * of its superPackage hierarchy with the ePackage name, separated by the given separator - * + * * @param ePackage * @param separator - * The separator used between each package name + * The separator used between each package name * @return * The EPackage's qualified name */ public static String getQualifiedName(final EPackage ePackage, final String separator) { - if(ePackage.getESuperPackage() == null) { + if (ePackage.getESuperPackage() == null) { return ePackage.getName(); } return getQualifiedName(ePackage.getESuperPackage(), separator) + separator + ePackage.getName(); @@ -342,27 +342,27 @@ public class EMFHelper { /** * Loads and returns the first EObject at the given URI. * The EObject is loaded in the given resourceSet. - * + * * @param resourceSet - * The ResourceSet in which the model will be loaded + * The ResourceSet in which the model will be loaded * @param uri - * The URI describing the location of the model to load + * The URI describing the location of the model to load * @return * The first EObject located at the given URI * @throws IOException - * When the URI cannot be loaded + * When the URI cannot be loaded */ public static EObject loadEMFModel(ResourceSet resourceSet, final URI uri) throws IOException { assert resourceSet != null : "null resourceSet"; //$NON-NLS-1$ - if(resourceSet == null) { + if (resourceSet == null) { Activator.log.warn("Created a new resourceSet to load an EMF model in " + Activator.log.getCallerMethod()); //$NON-NLS-1$ resourceSet = new ResourceSetImpl(); } try { Resource resource = resourceSet.getResource(uri, true); - if(resource != null) { - if(!resource.getContents().isEmpty()) { + if (resource != null) { + if (!resource.getContents().isEmpty()) { return resource.getContents().get(0); } } @@ -384,14 +384,14 @@ public class EMFHelper { *
  • removing all adapters from all resources
  • *
  • removing all adapters from the resource set
  • * - * + * * @param resourceSet - * the resource set to purge + * the resource set to purge */ public static void unload(ResourceSet resourceSet) { List resources = ImmutableList.copyOf(resourceSet.getResources()); resourceSet.getResources().clear(); - for(Resource next : resources) { + for (Resource next : resources) { next.unload(); next.eAdapters().clear(); } @@ -401,7 +401,7 @@ public class EMFHelper { // want to leak in BasicExtendedMetaData instances attached to static EPackages) // Works around EMF bug 433108 EPackage.Registry packageRegistry = resourceSet.getPackageRegistry(); - if(packageRegistry != null) { + if (packageRegistry != null) { packageRegistry.clear(); } } @@ -409,17 +409,17 @@ public class EMFHelper { /** * Return the root package containing the given package, or the package * itself if it is already the root - * + * * @param ePackage * @return * The Root package */ public static EPackage getRootPackage(final EPackage ePackage) { - if(ePackage == null) { + if (ePackage == null) { return null; } - if(ePackage.getESuperPackage() == null) { + if (ePackage.getESuperPackage() == null) { return ePackage; } return getRootPackage(ePackage.getESuperPackage()); @@ -429,16 +429,16 @@ public class EMFHelper { /** * Return the list of EClasses that are subtypes * of the given EClass - * + * * @param type * @param concreteClassesOnly - * If true, only Concrete EClasses will be returned. Abstract and Interface EClasses will be filtered + * If true, only Concrete EClasses will be returned. Abstract and Interface EClasses will be filtered * @return * The list of EClasses implementing or extending the given EClass */ public static List getSubclassesOf(final EClass type, final boolean concreteClassesOnly) { Set result = new LinkedHashSet(); - if(!concreteClassesOnly || (!type.isAbstract() && !type.isInterface())) { + if (!concreteClassesOnly || (!type.isAbstract() && !type.isInterface())) { result.add(type); } @@ -450,22 +450,22 @@ public class EMFHelper { /** * Return the list of EClasses that are sub types * of the given EClass - * + * * @param type * @param concreteClassesOnly - * If true, only Concrete EClasses will be returned. Abstract and Interface EClasses will be filtered + * If true, only Concrete EClasses will be returned. Abstract and Interface EClasses will be filtered * @param packagesToBrowse - * The EPackages in which the EClasses should be retrieved + * The EPackages in which the EClasses should be retrieved * @return * The list of EClasses implementing or extending the given EClass */ public static List getSubclassesOf(final EClass type, final boolean concreteClassesOnly, Collection packagesToBrowse) { Set result = new LinkedHashSet(); - if(!concreteClassesOnly || (!type.isAbstract() && !type.isInterface())) { + if (!concreteClassesOnly || (!type.isAbstract() && !type.isInterface())) { result.add(type); } - for(EPackage ePackage : packagesToBrowse) { + for (EPackage ePackage : packagesToBrowse) { getSubclassesOf(type, ePackage, result, concreteClassesOnly); } @@ -474,28 +474,28 @@ public class EMFHelper { /** * Return the list of EClasses that are sub types of the given EClass - * + * * @param type * @param concreteClassesOnly - * If true, only Concrete EClasses will be returned. Abstract and Interface EClasses will be filtered + * If true, only Concrete EClasses will be returned. Abstract and Interface EClasses will be filtered * @param browseAllRegisteredPackages - * If true, all registered EPackages will be navigated to retrieve the matching EClasses. Otherwise, - * only the current EPackage will be used. + * If true, all registered EPackages will be navigated to retrieve the matching EClasses. Otherwise, + * only the current EPackage will be used. * @return * The list of EClasses implementing or extending the given EClass */ public static List getSubclassesOf(final EClass type, final boolean concreteClassesOnly, final boolean browseAllRegisteredPackages) { - //If the current package is a dynamic package, it may not be registered (?). Add it directly + // If the current package is a dynamic package, it may not be registered (?). Add it directly EPackage currentPackage = getRootPackage(type.getEPackage()); Set allPackages = new LinkedHashSet(); allPackages.add(currentPackage); - if(browseAllRegisteredPackages) { - //FIXME // WARNING: This loop will load all EPackages. The first call is expensive. + if (browseAllRegisteredPackages) { + // FIXME // WARNING: This loop will load all EPackages. The first call is expensive. Set allUris = new HashSet(EPackage.Registry.INSTANCE.keySet()); - for(String nsURI : allUris) { + for (String nsURI : allUris) { allPackages.add(EPackage.Registry.INSTANCE.getEPackage(nsURI)); } } @@ -504,18 +504,18 @@ public class EMFHelper { } private static void getSubclassesOf(final EClass type, final EPackage fromPackage, final Set result, final boolean concreteClassesOnly) { - for(EClassifier classifier : fromPackage.getEClassifiers()) { - if(classifier instanceof EClass) { - EClass eClass = (EClass)classifier; - if(eClass.getEAllSuperTypes().contains(type)) { - if(!concreteClassesOnly || (!eClass.isAbstract() && !eClass.isInterface())) { + for (EClassifier classifier : fromPackage.getEClassifiers()) { + if (classifier instanceof EClass) { + EClass eClass = (EClass) classifier; + if (eClass.getEAllSuperTypes().contains(type)) { + if (!concreteClassesOnly || (!eClass.isAbstract() && !eClass.isInterface())) { result.add(eClass); } } } } - for(EPackage subPackage : fromPackage.getESubpackages()) { + for (EPackage subPackage : fromPackage.getESubpackages()) { getSubclassesOf(type, subPackage, result, concreteClassesOnly); } } @@ -523,7 +523,7 @@ public class EMFHelper { /** * Tests if an EObject is read only on any {@linkplain ReadOnlyAxis axis}. * Delegates to the EObject's editing domain if it can be found - * + * * @param eObject * @return * True if the EObject is read only on any axis @@ -536,9 +536,9 @@ public class EMFHelper { /** * Tests if an EObject is read only on any of the specified {@code axes}. * Delegates to the EObject's editing domain if it can be found - * + * * @param axes - * a set if orthogonal axes of read-only-ness to consider. May be empty, but that would not be especially useful + * a set if orthogonal axes of read-only-ness to consider. May be empty, but that would not be especially useful * @param eObject * @return * True if the EObject is read only on any of the given {@code axes} @@ -551,7 +551,7 @@ public class EMFHelper { /** * Tests if an EObject is read only on any {@linkplain ReadOnlyAxis axis}. * Delegates to the given editing domain if it isn't null - * + * * @param eObject * @param domain * @return @@ -564,26 +564,26 @@ public class EMFHelper { /** * Tests if an EObject is read only on any of the specified {@code axes}. * Delegates to the given editing domain if it isn't null - * + * * @param axes - * a set if orthogonal axes of read-only-ness to consider. May be empty, but that would not be especially useful + * a set if orthogonal axes of read-only-ness to consider. May be empty, but that would not be especially useful * @param eObject - * + * * @param domain * @return * True if the EObject is read only */ public static boolean isReadOnly(Set axes, final EObject eObject, final EditingDomain domain) { - if(domain != null) { + if (domain != null) { Object handler = PlatformHelper.getAdapter(domain, IReadOnlyHandler.class); - if(handler instanceof IReadOnlyHandler2) { - return ((IReadOnlyHandler2)handler).isReadOnly(axes, eObject).get(); - } else if(handler instanceof IReadOnlyHandler) { + if (handler instanceof IReadOnlyHandler2) { + return ((IReadOnlyHandler2) handler).isReadOnly(axes, eObject).get(); + } else if (handler instanceof IReadOnlyHandler) { // these handlers only deal with permission-based read-only-ness - return axes.contains(ReadOnlyAxis.PERMISSION) && ((IReadOnlyHandler)handler).isReadOnly(eObject).get(); + return axes.contains(ReadOnlyAxis.PERMISSION) && ((IReadOnlyHandler) handler).isReadOnly(eObject).get(); } - if(eObject.eResource() != null) { + if (eObject.eResource() != null) { return domain.isReadOnly(eObject.eResource()); } } @@ -593,7 +593,7 @@ public class EMFHelper { /** * Tests if the Resource is read only on any {@linkplain ReadOnlyAxis axis}. * Delegates to the given editing domain if it isn't null - * + * * @param resource * @param domain * @return @@ -606,26 +606,26 @@ public class EMFHelper { /** * Tests if the Resource is read only on any of the given {@code axes}. * Delegates to the given editing domain if it isn't null - * + * * @param axes - * a set if orthogonal axes of read-only-ness to consider. May be empty, but that would not be especially useful + * a set if orthogonal axes of read-only-ness to consider. May be empty, but that would not be especially useful * @param resource * @param domain * @return * True if the Resource is read only on any of the given {@code axes} */ public static boolean isReadOnly(Set axes, final Resource resource, final EditingDomain domain) { - if(resource == null) { + if (resource == null) { return false; } - if(domain != null && resource.getURI() != null) { + if (domain != null && resource.getURI() != null) { Object handler = PlatformHelper.getAdapter(domain, IReadOnlyHandler.class); - if(handler instanceof IReadOnlyHandler2) { - return ((IReadOnlyHandler2)handler).anyReadOnly(axes, new URI[]{ resource.getURI() }).get(); - } else if(handler instanceof IReadOnlyHandler) { + if (handler instanceof IReadOnlyHandler2) { + return ((IReadOnlyHandler2) handler).anyReadOnly(axes, new URI[] { resource.getURI() }).get(); + } else if (handler instanceof IReadOnlyHandler) { // these handlers only deal with permission-based read-only-ness - return axes.contains(ReadOnlyAxis.PERMISSION) && ((IReadOnlyHandler)handler).anyReadOnly(new URI[]{ resource.getURI() }).get(); + return axes.contains(ReadOnlyAxis.PERMISSION) && ((IReadOnlyHandler) handler).anyReadOnly(new URI[] { resource.getURI() }).get(); } return domain.isReadOnly(resource); } @@ -633,12 +633,12 @@ public class EMFHelper { // no editing domain : use file system attribute ResourceSet resourceSet = resource.getResourceSet(); - if(resourceSet == null) { + if (resourceSet == null) { return false; } Map attributes = resourceSet.getURIConverter().getAttributes(resource.getURI(), null); - Boolean readOnly = (Boolean)attributes.get(URIConverter.ATTRIBUTE_READ_ONLY); + Boolean readOnly = (Boolean) attributes.get(URIConverter.ATTRIBUTE_READ_ONLY); return readOnly == null ? false : readOnly; } @@ -646,11 +646,11 @@ public class EMFHelper { /** * Tests if an object that is read only could possibly be made writable by some means (file system attributes, team provider hook, database * permissions, etc.) - * + * * @param eObject - * an object that is assumed to be read-only + * an object that is assumed to be read-only * @param domain - * the editing domain context of the {@link eObject} + * the editing domain context of the {@link eObject} * @return * whether the {@code eObject} could be made writable */ @@ -661,21 +661,21 @@ public class EMFHelper { /** * Tests if an object that is read only could possibly be made writable according to any of * the specified {@code axes} of read-only-ness. - * + * * @param axes - * a set if orthogonal axes of read-only-ness to consider. May be empty, but that would not be especially useful + * a set if orthogonal axes of read-only-ness to consider. May be empty, but that would not be especially useful * @param eObject - * an object that is assumed to be read-only + * an object that is assumed to be read-only * @param domain - * the editing domain context of the {@link eObject} + * the editing domain context of the {@link eObject} * @return * whether the {@code eObject} could be made writable */ public static boolean canMakeWritable(Set axes, final EObject eObject, final EditingDomain domain) { - if(domain != null) { + if (domain != null) { Object handler = PlatformHelper.getAdapter(domain, IReadOnlyHandler.class); - if(handler instanceof IReadOnlyHandler2) { - return ((IReadOnlyHandler2)handler).canMakeWritable(axes, eObject).or(false); + if (handler instanceof IReadOnlyHandler2) { + return ((IReadOnlyHandler2) handler).canMakeWritable(axes, eObject).or(false); } } return false; @@ -684,11 +684,11 @@ public class EMFHelper { /** * Tests if a resource that is read only could possibly be made writable by some means (file system attributes, team provider hook, database * permissions, etc.) - * + * * @param resource - * a resource that is assumed to be read-only + * a resource that is assumed to be read-only * @param domain - * the editing domain context of the {@link resource} + * the editing domain context of the {@link resource} * @return * whether the {@code resource} could be made writable */ @@ -699,21 +699,21 @@ public class EMFHelper { /** * Tests if a resource that is read only could possibly be made writable according to any of * the specified {@code axes} of read-only-ness. - * + * * @param axes - * a set if orthogonal axes of read-only-ness to consider. May be empty, but that would not be especially useful + * a set if orthogonal axes of read-only-ness to consider. May be empty, but that would not be especially useful * @param resource - * a resource that is assumed to be read-only + * a resource that is assumed to be read-only * @param domain - * the editing domain context of the {@link resource} + * the editing domain context of the {@link resource} * @return * whether the {@code resource} could be made writable */ public static boolean canMakeWritable(Set axes, final Resource resource, final EditingDomain domain) { - if(domain != null) { + if (domain != null) { Object handler = PlatformHelper.getAdapter(domain, IReadOnlyHandler.class); - if(handler instanceof IReadOnlyHandler2) { - return ((IReadOnlyHandler2)handler).canMakeWritable(axes, new URI[]{ resource.getURI() }).or(false); + if (handler instanceof IReadOnlyHandler2) { + return ((IReadOnlyHandler2) handler).canMakeWritable(axes, new URI[] { resource.getURI() }).or(false); } } return false; @@ -722,48 +722,48 @@ public class EMFHelper { /** * Tests if the given EStructuralFeature is required (ie. should always * have a value) - * + * * A feature is required if at least of one the following conditions if * true : - * + * * - It has a defaultValue * - Its lowerBound is at least 1 * - It is an enumeration (Enumerations always have a default value) * - It is a Java primitive type, and is not marked as Unsettable - * + * * @param feature - * the feature to test + * the feature to test * @return * true if the feature is required, false otherwise */ public static boolean isRequired(final EStructuralFeature feature) { - //EEnums are always required, as an EEnum always has a default value - if(feature.getEType() instanceof EEnum) { + // EEnums are always required, as an EEnum always has a default value + if (feature.getEType() instanceof EEnum) { return true; } - //At least one value means it is required - if(feature.getLowerBound() >= 1) { + // At least one value means it is required + if (feature.getLowerBound() >= 1) { return true; } - //Java primitive types cannot have a null value - //if the feature is not specifically marked as unsettable, then it is required - if(feature.getEType().getInstanceClass().isPrimitive() && !feature.isUnsettable()) { + // Java primitive types cannot have a null value + // if the feature is not specifically marked as unsettable, then it is required + if (feature.getEType().getInstanceClass().isPrimitive() && !feature.isUnsettable()) { return true; } - //If there is a default value, there is always a value - if(feature.getDefaultValueLiteral() != null) { + // If there is a default value, there is always a value + if (feature.getDefaultValueLiteral() != null) { return true; } - return false; //The property if not required + return false; // The property if not required } /** * Returns all objects of type T contained in the resource - * + * * @param resource * @param type * @return @@ -772,9 +772,9 @@ public class EMFHelper { TreeIterator iterator = resource.getAllContents(); Set result = new LinkedHashSet(); - while(iterator.hasNext()) { + while (iterator.hasNext()) { EObject element = iterator.next(); - if(type.isInstance(element)) { + if (type.isInstance(element)) { result.add(type.cast(element)); } } @@ -784,17 +784,17 @@ public class EMFHelper { /** * Returns all the EPackages and nested EPackages contained in this resource - * + * * @param resource * @return */ public static Set getAllEPackages(final Resource resource) { Set result = new LinkedHashSet(); - for(EObject rootElement : resource.getContents()) { - if(rootElement instanceof EPackage) { - result.add((EPackage)rootElement); - result.addAll(getAllNestedPackages((EPackage)rootElement)); + for (EObject rootElement : resource.getContents()) { + if (rootElement instanceof EPackage) { + result.add((EPackage) rootElement); + result.addAll(getAllNestedPackages((EPackage) rootElement)); } } @@ -804,14 +804,14 @@ public class EMFHelper { /** * Returns all packages nested in the given EPackage (recursively). Does not * include the base EPackage. - * + * * @param basePackage * @return */ public static Set getAllNestedPackages(EPackage basePackage) { Set result = new LinkedHashSet(); - for(EPackage nestedPackage : basePackage.getESubpackages()) { + for (EPackage nestedPackage : basePackage.getESubpackages()) { result.add(nestedPackage); result.addAll(getAllNestedPackages(nestedPackage)); } @@ -820,18 +820,18 @@ public class EMFHelper { } /** - * + * * @param resource - * a resource - * + * a resource + * * @return * the list of the metamodels known by the resource */ public static Set getMetamodels(final Resource resource) { Set metamodels = new HashSet(); - if(resource != null) { + if (resource != null) { final List contents = new ArrayList(resource.getContents()); - for(final EObject current : contents) { + for (final EObject current : contents) { metamodels.add(current.eClass().getEPackage()); } } @@ -839,17 +839,17 @@ public class EMFHelper { } /** - * + * * Returns the XMI ID of the given {@link EObject} or null if it cannot be resolved. - * + * * @param object - * Object which we seek the XMI ID of. + * Object which we seek the XMI ID of. * @return object's XMI ID, null if not applicable. */ public static final String getXMIID(final EObject object) { String objectID = null; - if(object != null && object.eResource() instanceof XMIResource) { - objectID = ((XMIResource)object.eResource()).getID(object); + if (object != null && object.eResource() instanceof XMIResource) { + objectID = ((XMIResource) object.eResource()).getID(object); } return objectID; } @@ -858,10 +858,10 @@ public class EMFHelper { /** * Gets the usages. - * + * * @param source - * the source - * + * the source + * * @return the usages or null if there is no usages */ public static Collection getUsages(EObject source) { @@ -876,11 +876,11 @@ public class EMFHelper { * Test if the used element is referenced by other elements than the known * referencer (except its container). It ignores references from an other meta-model. * - * + * * @param usedObject - * the used object + * the used object * @param knownReferencer - * the known referencer + * the known referencer * @return true if the known referencer is the only referencer. */ public static boolean isOnlyUsage(EObject usedObject, EObject knownReferencer) { @@ -889,9 +889,9 @@ public class EMFHelper { // Retrieve the list of elements referencing the usedObject. Set crossReferences = new HashSet(); - for(Setting setting : getUsages(usedObject)) { + for (Setting setting : getUsages(usedObject)) { EObject eObj = setting.getEObject(); - if(eObj.eClass().getEPackage().equals(mmPackage)) { + if (eObj.eClass().getEPackage().equals(mmPackage)) { crossReferences.add(eObj); } } @@ -903,7 +903,7 @@ public class EMFHelper { // If no referencer remains in the list, the known element is the only // usage. - if(crossReferences.isEmpty()) { + if (crossReferences.isEmpty()) { isUsed = true; } @@ -911,32 +911,32 @@ public class EMFHelper { } /** - * + * * @param superType - * an eclassifier + * an eclassifier * @param subType - * another eClassifier + * another eClassifier * @return * true if the 2nd {@link EClassifier} is a subtype of the first one */ public static boolean isSuperType(final EClassifier superType, final EClassifier subType) { - if(superType == subType) { + if (superType == subType) { return true; } - if(superType instanceof EClass && subType instanceof EClass) { + if (superType instanceof EClass && subType instanceof EClass) { // special case because isSuperTypeOf doesn't handle it - if(superType == EcorePackage.eINSTANCE.getEObject()) { + if (superType == EcorePackage.eINSTANCE.getEObject()) { return true; } - EClass superTypeEClass = (EClass)superType; - EClass subTypeEClass = (EClass)subType; + EClass superTypeEClass = (EClass) superType; + EClass subTypeEClass = (EClass) subType; return superTypeEClass.isSuperTypeOf(subTypeEClass); } - //manage EDtataType - if(superType == EcorePackage.eINSTANCE.getEDataType() && subType instanceof EDataType) { + // manage EDtataType + if (superType == EcorePackage.eINSTANCE.getEDataType() && subType instanceof EDataType) { return true; } @@ -945,13 +945,13 @@ public class EMFHelper { /** * Computes the path from the root EObject to the given element, as a List of EObjects - * + * * @param element * @return */ public static List getContainmentPath(EObject element) { List result; - if(element.eContainer() == null) { + if (element.eContainer() == null) { result = new LinkedList(); result.add(element); return result; @@ -977,14 +977,14 @@ public class EMFHelper { ResourceSet sourceResourceSet = getResourceSet(element); ResourceSet loadingContext = getResourceSet(contextElement); - if(sourceResourceSet == loadingContext || loadingContext == null) { + if (sourceResourceSet == loadingContext || loadingContext == null) { return element; } URI sourceURI = EcoreUtil.getURI(element); EObject result = loadingContext.getEObject(sourceURI, true); - return (T)result; + return (T) result; } /** @@ -998,18 +998,17 @@ public class EMFHelper { } /** - * Best-effort loads a resource, returning the first root element of the requested {@code type}. Unlike the - * {@link #loadChecked(ResourceSet, URI, Class) loadChecked} method, this will never throw an exception. - * + * Best-effort loads a resource, returning the first root element of the requested {@code type}. Unlike the {@link #loadChecked(ResourceSet, URI, Class) loadChecked} method, this will never throw an exception. + * * @param rset - * a resource set in which to load the resource + * a resource set in which to load the resource * @param uri - * the URI of the resource to load + * the URI of the resource to load * @param type - * the type of root element to retrieve - * + * the type of root element to retrieve + * * @return the requested root element, or {@code null} if the resource does not contain such an element or could not be loaded - * + * * @see #loadChecked(ResourceSet, URI, Class) */ public static T load(ResourceSet rset, URI uri, Class type) { @@ -1022,7 +1021,7 @@ public class EMFHelper { // Maybe it was partially loaded? If so, try again Resource res = rset.getResource(uri, false); - if((res != null) && res.isLoaded()) { + if ((res != null) && res.isLoaded()) { result = Iterables.getFirst(Iterables.filter(res.getContents(), type), null); } } @@ -1032,29 +1031,29 @@ public class EMFHelper { /** * Best-effort loads a resource, returning the first root element of the requested {@code type}. - * + * * @param rset - * a resource set in which to load the resource + * a resource set in which to load the resource * @param uri - * the URI of the resource to load + * the URI of the resource to load * @param type - * the type of root element to retrieve - * + * the type of root element to retrieve + * * @return the requested root element, or {@code null} if the resource does not contain such an element or could not be loaded * @throws IOException - * on an I/O problem in loading the resource + * on an I/O problem in loading the resource * @throw RuntimeException on any other unforeseen (usually programming error) problem - * + * * @see #load(ResourceSet, URI, Class) */ public static T loadChecked(ResourceSet rset, URI uri, Class type) throws IOException { try { return Iterables.getFirst(Iterables.filter(rset.getResource(uri, true).getContents(), type), null); } catch (WrappedException e) { - if(e.exception() instanceof IOException) { - throw (IOException)e.exception(); - } else if(e.exception() instanceof RuntimeException) { - throw (RuntimeException)e.exception(); + if (e.exception() instanceof IOException) { + throw (IOException) e.exception(); + } else if (e.exception() instanceof RuntimeException) { + throw (RuntimeException) e.exception(); } else { throw e; } diff --git a/plugins/infra/emf/org.eclipse.papyrus.infra.emf/src/org/eclipse/papyrus/infra/emf/utils/EMFStringValueConverter.java b/plugins/infra/emf/org.eclipse.papyrus.infra.emf/src/org/eclipse/papyrus/infra/emf/utils/EMFStringValueConverter.java index 5f659d15f18..29e082e9e46 100644 --- a/plugins/infra/emf/org.eclipse.papyrus.infra.emf/src/org/eclipse/papyrus/infra/emf/utils/EMFStringValueConverter.java +++ b/plugins/infra/emf/org.eclipse.papyrus.infra.emf/src/org/eclipse/papyrus/infra/emf/utils/EMFStringValueConverter.java @@ -1,7 +1,7 @@ /***************************************************************************** * Copyright (c) 2013 CEA LIST. * - * + * * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -36,11 +36,11 @@ import org.eclipse.papyrus.infra.tools.util.TypesConstants; /** * Value solver for EMF - * + * * WARNING : incomplete implementations - * + * * @author vl222926 - * + * */ public class EMFStringValueConverter extends AbstractStringValueConverter { @@ -58,11 +58,11 @@ public class EMFStringValueConverter extends AbstractStringValueConverter { protected final String multiValueSeparator; /** - * + * * Constructor. - * + * * @param resolutionContext - * the context used for the resolution of the string + * the context used for the resolution of the string */ public EMFStringValueConverter(final EObject resolutionContext, final String multiValueSeparator) { this.resolutionContext = resolutionContext; @@ -71,7 +71,7 @@ public class EMFStringValueConverter extends AbstractStringValueConverter { /** - * + * * @return * the context to use for the resolution */ @@ -80,36 +80,36 @@ public class EMFStringValueConverter extends AbstractStringValueConverter { } /** - * + * * @see org.eclipse.ui.services.IDisposable#dispose() - * + * */ public void dispose() { this.resolutionContext = null; } /** - * + * * @param resolutionContext - * the table context + * the table context * @param feature - * the feature + * the feature * @param valueAsString - * the pasted string for this feature + * the pasted string for this feature * @return * the value for the pasted string or null if not found */ @Override protected ConvertedValueContainer doDeduceValueFromString(final Object feature, final String valueAsString) { final EClassifier featureType = getFeatureType(feature); - if(feature instanceof EStructuralFeature) { + if (feature instanceof EStructuralFeature) { return deduceValueFromString(feature, featureType, valueAsString); } return null; } /** - * + * * @param feature * @param featureType * @param valueAsString @@ -117,53 +117,53 @@ public class EMFStringValueConverter extends AbstractStringValueConverter { */ protected ConvertedValueContainer deduceValueFromString(final Object feature, final EClassifier featureType, final String valueAsString) { ConvertedValueContainer realValue = null; - // if(feature instanceof EStructuralFeature) { + // if(feature instanceof EStructuralFeature) { final int upperbound = getFeatureUpperBound(feature); boolean isMany = (upperbound > 1 || upperbound == -1); - if(featureType instanceof EDataType) { - if(featureType instanceof EEnum) { - realValue = deduceEEnumLiteralValue((EEnum)featureType, isMany, valueAsString); + if (featureType instanceof EDataType) { + if (featureType instanceof EEnum) { + realValue = deduceEEnumLiteralValue((EEnum) featureType, isMany, valueAsString); } final String typeName = featureType.getName(); - if(TypesConstants.STRING.equals(typeName) || EMFContants.ESTRING.equals(typeName)) { + if (TypesConstants.STRING.equals(typeName) || EMFContants.ESTRING.equals(typeName)) { realValue = deduceStringValue(isMany, valueAsString); - } else if(EMFContants.EBOOLEAN.equals(typeName) || TypesConstants.BOOLEAN.equals(typeName)) { + } else if (EMFContants.EBOOLEAN.equals(typeName) || TypesConstants.BOOLEAN.equals(typeName)) { realValue = deduceBooleanValue(isMany, valueAsString); - } else if(EMFContants.EINT.equals(typeName) || TypesConstants.INTEGER.equals(typeName)) { + } else if (EMFContants.EINT.equals(typeName) || TypesConstants.INTEGER.equals(typeName)) { realValue = deduceIntValue(isMany, valueAsString); - } else if(EMFContants.EDOUBLE.equals(typeName)) { + } else if (EMFContants.EDOUBLE.equals(typeName)) { realValue = deduceDoubleValue(isMany, valueAsString); } - } else if(featureType instanceof EClass) { - realValue = deduceEObjectValue((EObject)getResolutionContext(), feature, (EClass)featureType, isMany, valueAsString); + } else if (featureType instanceof EClass) { + realValue = deduceEObjectValue(getResolutionContext(), feature, (EClass) featureType, isMany, valueAsString); } return realValue; } protected int getFeatureUpperBound(final Object feature) { - return ((EStructuralFeature)feature).getUpperBound(); + return ((EStructuralFeature) feature).getUpperBound(); } /** - * + * * @param resolutionContext - * the context used for the resolution + * the context used for the resolution * @param feature - * the feature + * the feature * @param featureType - * the type of the feature + * the type of the feature * @param isMany - * true if the feature isMany + * true if the feature isMany * @param valueAsString - * the string value to resolve + * the string value to resolve * @return * a value container referencing the eobject represented by the string * @throws StringValueSolverException */ protected ConvertedValueContainer deduceEObjectValue(EObject resolutionContext, Object feature, EClass featureType, boolean isMany, String valueAsString) { - if(valueAsString == null || valueAsString.equals("")) { + if (valueAsString == null || valueAsString.equals("")) { return new ConvertedValueContainer(null, Status.OK_STATUS); } final IStatus status = new Status(IStatus.ERROR, Activator.PLUGIN_ID, NLS.bind(THE_STRING_VALUE_X_CANT_BE_RESOLVED, valueAsString)); @@ -171,16 +171,16 @@ public class EMFStringValueConverter extends AbstractStringValueConverter { } /** - * + * * @param feature - * an object representing a feature + * an object representing a feature * @return * the type of the feature */ protected EClassifier getFeatureType(final Object feature) { final EClassifier featureType; - if(feature instanceof EStructuralFeature) { - return ((EStructuralFeature)feature).getEType(); + if (feature instanceof EStructuralFeature) { + return ((EStructuralFeature) feature).getEType(); } else { featureType = null; } @@ -188,13 +188,13 @@ public class EMFStringValueConverter extends AbstractStringValueConverter { } /** - * + * * @param eenum - * the enumeration + * the enumeration * @param isMany - * true if the feature is many + * true if the feature is many * @param valueAsString - * the value to convert + * the value to convert * @return * the converted value */ @@ -202,23 +202,23 @@ public class EMFStringValueConverter extends AbstractStringValueConverter { ConvertedValueContainer returnedValue = null; IStatus iStatus = Status.OK_STATUS; final Collection unresolvedValues = new ArrayList(); - if(isMany) { + if (isMany) { final Collection values = new ArrayList(); - for(final String str : valueAsString.split(this.multiValueSeparator)) { + for (final String str : valueAsString.split(this.multiValueSeparator)) { final EEnumLiteral literal = eenum.getEEnumLiteral(str); - if(literal != null) { + if (literal != null) { values.add(literal); } else { unresolvedValues.add(str); } } - if(!unresolvedValues.isEmpty()) { + if (!unresolvedValues.isEmpty()) { iStatus = new StringValueConverterStatus(IStatus.ERROR, Activator.PLUGIN_ID, NLS.bind(SOME_STRING_ARE_NOT_VALID_TO_CREATE_X, EMFContants.EENUM_LITERAL), unresolvedValues); } returnedValue = new MultiConvertedValueContainer(values, iStatus); } else { final EEnumLiteral literal = eenum.getEEnumLiteral(valueAsString); - if(literal != null) { + if (literal != null) { returnedValue = new ConvertedValueContainer(literal, iStatus); } else { unresolvedValues.add(valueAsString); @@ -230,11 +230,11 @@ public class EMFStringValueConverter extends AbstractStringValueConverter { } /** - * + * * @param isMany - * true if the feature isMany + * true if the feature isMany * @param valueAsString - * the value to parse + * the value to parse * @return * the result of the parsing */ @@ -242,21 +242,21 @@ public class EMFStringValueConverter extends AbstractStringValueConverter { ConvertedValueContainer returnedValue = null; IStatus iStatus = Status.OK_STATUS; final Collection unresolvedValues = new ArrayList(); - if(isMany) { + if (isMany) { final Collection values = new ArrayList(); - for(final String str : valueAsString.split(this.multiValueSeparator)) { - if(BooleanHelper.isBoolean(str)) { + for (final String str : valueAsString.split(this.multiValueSeparator)) { + if (BooleanHelper.isBoolean(str)) { values.add(Boolean.valueOf(valueAsString)); } else { unresolvedValues.add(str); } } - if(!unresolvedValues.isEmpty()) { + if (!unresolvedValues.isEmpty()) { iStatus = new StringValueConverterStatus(IStatus.ERROR, Activator.PLUGIN_ID, NLS.bind(SOME_STRING_ARE_NOT_VALID_TO_CREATE_X, TypesConstants.BOOLEAN), unresolvedValues); } returnedValue = new MultiConvertedValueContainer(values, iStatus); } else { - if(BooleanHelper.isBoolean(valueAsString)) { + if (BooleanHelper.isBoolean(valueAsString)) { returnedValue = new ConvertedValueContainer(Boolean.valueOf(valueAsString), iStatus); } else { unresolvedValues.add(valueAsString); @@ -268,11 +268,11 @@ public class EMFStringValueConverter extends AbstractStringValueConverter { } /** - * + * * @param isMany - * true if the feature isMany + * true if the feature isMany * @param valueAsString - * the value to parse + * the value to parse * @return * the result of the parsing */ @@ -280,17 +280,17 @@ public class EMFStringValueConverter extends AbstractStringValueConverter { ConvertedValueContainer returnedValue = null; IStatus iStatus = Status.OK_STATUS; final Collection unresolvedValues = new ArrayList(); - if(isMany) { + if (isMany) { final Collection values = new ArrayList(); - for(final String str : valueAsString.split(this.multiValueSeparator)) { + for (final String str : valueAsString.split(this.multiValueSeparator)) { final Double value = Double.valueOf(str); - if(value != null) { + if (value != null) { values.add(value); } else { unresolvedValues.add(str); } } - if(!unresolvedValues.isEmpty()) { + if (!unresolvedValues.isEmpty()) { iStatus = new StringValueConverterStatus(IStatus.ERROR, Activator.PLUGIN_ID, NLS.bind(SOME_STRING_ARE_NOT_VALID_TO_CREATE_X, TypesConstants.DOUBLE), unresolvedValues); } returnedValue = new MultiConvertedValueContainer(values, iStatus); @@ -307,11 +307,11 @@ public class EMFStringValueConverter extends AbstractStringValueConverter { } /** - * + * * @param isMany - * true if the feature isMany + * true if the feature isMany * @param valueAsString - * the value to parse + * the value to parse * @return * the result of the parsing */ @@ -319,16 +319,16 @@ public class EMFStringValueConverter extends AbstractStringValueConverter { ConvertedValueContainer returnedValue = null; IStatus iStatus = Status.OK_STATUS; final Collection unresolvedValues = new ArrayList(); - if(isMany) { + if (isMany) { final Collection values = new ArrayList(); - for(final String str : valueAsString.split(this.multiValueSeparator)) { + for (final String str : valueAsString.split(this.multiValueSeparator)) { try { values.add(Integer.valueOf(str)); } catch (final NumberFormatException e) { unresolvedValues.add(str); } } - if(!unresolvedValues.isEmpty()) { + if (!unresolvedValues.isEmpty()) { iStatus = new StringValueConverterStatus(IStatus.ERROR, Activator.PLUGIN_ID, NLS.bind(SOME_STRING_ARE_NOT_VALID_TO_CREATE_X, TypesConstants.INTEGER), unresolvedValues); } returnedValue = new MultiConvertedValueContainer(values, iStatus); @@ -346,20 +346,20 @@ public class EMFStringValueConverter extends AbstractStringValueConverter { /** - * + * * @param isMany - * true if the feature is many + * true if the feature is many * @param valueAsString - * the value as string + * the value as string * @return * the value container with the real value(s) */ protected ConvertedValueContainer deduceStringValue(final boolean isMany, final String valueAsString) { ConvertedValueContainer returnedValue = null; final IStatus iStatus = Status.OK_STATUS; - if(isMany) { + if (isMany) { final Collection values = new ArrayList(); - for(final String str : valueAsString.split(this.multiValueSeparator)) { + for (final String str : valueAsString.split(this.multiValueSeparator)) { values.add(str); } returnedValue = new MultiConvertedValueContainer(values, iStatus); diff --git a/plugins/infra/emf/org.eclipse.papyrus.infra.emf/src/org/eclipse/papyrus/infra/emf/utils/ENamedElementComparator.java b/plugins/infra/emf/org.eclipse.papyrus.infra.emf/src/org/eclipse/papyrus/infra/emf/utils/ENamedElementComparator.java index f2928885c13..36bb8a4ea08 100644 --- a/plugins/infra/emf/org.eclipse.papyrus.infra.emf/src/org/eclipse/papyrus/infra/emf/utils/ENamedElementComparator.java +++ b/plugins/infra/emf/org.eclipse.papyrus.infra.emf/src/org/eclipse/papyrus/infra/emf/utils/ENamedElementComparator.java @@ -1,7 +1,7 @@ /***************************************************************************** * Copyright (c) 2012 CEA LIST. * - * + * * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -19,14 +19,14 @@ import java.util.Comparator; import org.eclipse.emf.ecore.ENamedElement; /** - * + * * A comparator for ENamedElement * */ public class ENamedElementComparator implements Comparator { public int compare(final ENamedElement namedElement1, final ENamedElement namedElement2) { - if(namedElement1 == null) { + if (namedElement1 == null) { return namedElement2 == null ? 0 : -1; } diff --git a/plugins/infra/emf/org.eclipse.papyrus.infra.emf/src/org/eclipse/papyrus/infra/emf/utils/HistoryUtil.java b/plugins/infra/emf/org.eclipse.papyrus.infra.emf/src/org/eclipse/papyrus/infra/emf/utils/HistoryUtil.java index 50d10a12b9f..eedc0a505b2 100644 --- a/plugins/infra/emf/org.eclipse.papyrus.infra.emf/src/org/eclipse/papyrus/infra/emf/utils/HistoryUtil.java +++ b/plugins/infra/emf/org.eclipse.papyrus.infra.emf/src/org/eclipse/papyrus/infra/emf/utils/HistoryUtil.java @@ -1,6 +1,6 @@ /***************************************************************************** * Copyright (c) 2011 CEA LIST. - * + * * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -19,7 +19,7 @@ public class HistoryUtil { /** * Returns a String identifying the History of selected values for the given object/feature - * + * * @param editedObject * @param feature * @return @@ -31,14 +31,14 @@ public class HistoryUtil { /** * Returns a String identifying the History of selected values for the given object/feature, * and prepends the given prefix - * + * * @param editedObject * @param feature * @return */ public static String getHistoryID(EObject editedObject, EStructuralFeature feature, String prefix) { // return String.format("history_%s:%s:%s", feature.getEType().getEPackage().getName(), feature.getEType().getName(), feature.getName()); //$NON-NLS-1$ - if(editedObject.eResource() == null) { + if (editedObject.eResource() == null) { return String.format("history_%s_%s:%s", prefix, EMFHelper.getQualifiedName(feature.getEType(), ":"), feature.getName()); //$NON-NLS-1$ //$NON-NLS-2$ } diff --git a/plugins/infra/emf/org.eclipse.papyrus.infra.emf/src/org/eclipse/papyrus/infra/emf/utils/ProviderHelper.java b/plugins/infra/emf/org.eclipse.papyrus.infra.emf/src/org/eclipse/papyrus/infra/emf/utils/ProviderHelper.java index d3d919225bd..52df1d82b23 100644 --- a/plugins/infra/emf/org.eclipse.papyrus.infra.emf/src/org/eclipse/papyrus/infra/emf/utils/ProviderHelper.java +++ b/plugins/infra/emf/org.eclipse.papyrus.infra.emf/src/org/eclipse/papyrus/infra/emf/utils/ProviderHelper.java @@ -1,6 +1,6 @@ /***************************************************************************** * Copyright (c) 2012 CEA LIST. - * + * * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -29,9 +29,9 @@ public class ProviderHelper { * Encapsulates the given content provider in a higher-level content provider * The returned provider uses two different strategies to display and search * elements, and adds a pattern filter and an History - * + * * @param provider - * The ContentProvider to encapsulate + * The ContentProvider to encapsulate * @return */ public static EMFGraphicalContentProvider encapsulateProvider(ITreeContentProvider provider, ResourceSet resourceSet, String historyId) { @@ -47,9 +47,9 @@ public class ProviderHelper { * Encapsulates the given content provider in a higher-level content provider * The returned provider uses two different strategies to display and search * elements, and adds a pattern filter and an History - * + * * @param provider - * The ContentProvider to encapsulate + * The ContentProvider to encapsulate * @return */ public static EMFGraphicalContentProvider encapsulateProvider(ITreeContentProvider provider, EObject editedEObject, EStructuralFeature feature) { diff --git a/plugins/infra/emf/org.eclipse.papyrus.infra.emf/src/org/eclipse/papyrus/infra/emf/utils/ResourceUtils.java b/plugins/infra/emf/org.eclipse.papyrus.infra.emf/src/org/eclipse/papyrus/infra/emf/utils/ResourceUtils.java index 26e1818e66b..94bfe86cc3e 100644 --- a/plugins/infra/emf/org.eclipse.papyrus.infra.emf/src/org/eclipse/papyrus/infra/emf/utils/ResourceUtils.java +++ b/plugins/infra/emf/org.eclipse.papyrus.infra.emf/src/org/eclipse/papyrus/infra/emf/utils/ResourceUtils.java @@ -1,7 +1,7 @@ /***************************************************************************** * Copyright (c) 2012 CEA LIST. * - * + * * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -28,31 +28,32 @@ import org.eclipse.emf.common.util.URI; import org.eclipse.emf.ecore.EObject; import org.eclipse.emf.ecore.resource.Resource; import org.eclipse.emf.ecore.xmi.XMIResource; +import org.eclipse.emf.ecore.xmi.XMLResource; /** - * + * * This class provides methods for EMF Resource - * + * */ public class ResourceUtils { private ResourceUtils() { - //to prevent instanciation + // to prevent instanciation } /** - * + * * @param resource - * an EMF resource + * an EMF resource * @return * the IFile corresponding to this resource, or null if not found */ public static IFile getFile(final Resource resource) { - if(resource != null) { + if (resource != null) { URI uri = resource.getURI(); uri = resource.getResourceSet().getURIConverter().normalize(uri); - if(uri.isPlatformResource()) { - String uriPlatformString = uri.toPlatformString(true) ; + if (uri.isPlatformResource()) { + String uriPlatformString = uri.toPlatformString(true); return ResourcesPlugin.getWorkspace().getRoot().getFile(new Path(uriPlatformString)); } } @@ -60,18 +61,18 @@ public class ResourceUtils { } /** - * - * + * + * * @param resource - * a resource + * a resource * @return * a collection with all existing id in the resource - * + * */ public static Collection getAllResourceIds(final XMIResource resource) { final Set ids = new HashSet(); final Iterator iterator = resource.getAllContents(); - while(iterator.hasNext()) { + while (iterator.hasNext()) { final EObject current = iterator.next(); final String id = resource.getID(current); Assert.isNotNull(id); @@ -80,28 +81,29 @@ public class ResourceUtils { } return ids; } - - + + /** * Default options to save emf files used in Papyrus + * * @return */ public static Map getSaveOptions() { Map saveOptions = new HashMap(); // default save options. - saveOptions.put(XMIResource.OPTION_DECLARE_XML, Boolean.TRUE); - saveOptions.put(XMIResource.OPTION_PROCESS_DANGLING_HREF, XMIResource.OPTION_PROCESS_DANGLING_HREF_DISCARD); - saveOptions.put(XMIResource.OPTION_SCHEMA_LOCATION, Boolean.TRUE); + saveOptions.put(XMLResource.OPTION_DECLARE_XML, Boolean.TRUE); + saveOptions.put(XMLResource.OPTION_PROCESS_DANGLING_HREF, XMLResource.OPTION_PROCESS_DANGLING_HREF_DISCARD); + saveOptions.put(XMLResource.OPTION_SCHEMA_LOCATION, Boolean.TRUE); saveOptions.put(XMIResource.OPTION_USE_XMI_TYPE, Boolean.TRUE); - saveOptions.put(XMIResource.OPTION_SAVE_TYPE_INFORMATION, Boolean.TRUE); - saveOptions.put(XMIResource.OPTION_SKIP_ESCAPE_URI, Boolean.FALSE); - saveOptions.put(XMIResource.OPTION_ENCODING, "UTF-8"); + saveOptions.put(XMLResource.OPTION_SAVE_TYPE_INFORMATION, Boolean.TRUE); + saveOptions.put(XMLResource.OPTION_SKIP_ESCAPE_URI, Boolean.FALSE); + saveOptions.put(XMLResource.OPTION_ENCODING, "UTF-8"); - //see bug 397987: [Core][Save] The referenced plugin models are saved using relative path - saveOptions.put(XMIResource.OPTION_URI_HANDLER, new org.eclipse.emf.ecore.xmi.impl.URIHandlerImpl.PlatformSchemeAware()); + // see bug 397987: [Core][Save] The referenced plugin models are saved using relative path + saveOptions.put(XMLResource.OPTION_URI_HANDLER, new org.eclipse.emf.ecore.xmi.impl.URIHandlerImpl.PlatformSchemeAware()); return saveOptions; } - + } diff --git a/plugins/infra/emf/org.eclipse.papyrus.infra.emf/src/org/eclipse/papyrus/infra/emf/utils/ServiceRegistryAdapterFactory.java b/plugins/infra/emf/org.eclipse.papyrus.infra.emf/src/org/eclipse/papyrus/infra/emf/utils/ServiceRegistryAdapterFactory.java index 1f610c57d5a..e9d8e12815d 100644 --- a/plugins/infra/emf/org.eclipse.papyrus.infra.emf/src/org/eclipse/papyrus/infra/emf/utils/ServiceRegistryAdapterFactory.java +++ b/plugins/infra/emf/org.eclipse.papyrus.infra.emf/src/org/eclipse/papyrus/infra/emf/utils/ServiceRegistryAdapterFactory.java @@ -1,7 +1,7 @@ /***************************************************************************** * Copyright (c) 2012, 2014 Cedric Dumoulin, CEA, and others. * - * + * * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -20,11 +20,11 @@ import org.eclipse.papyrus.infra.core.services.ServicesRegistry; /** * This AdapterFactory is used to attach a reference on the ServiceRegiqtry to an EMF ResourceSet. - * + * * This adapterFactory is not a real factory: no adapter is created. - * + * * @author cedric dumoulin - * + * * @deprecated Since 1.0, the {@link ModelSetServiceFactory} class associates the model-set with its service registry. */ @Deprecated @@ -48,7 +48,7 @@ public class ServiceRegistryAdapterFactory extends AdapterFactoryImpl { } /** - * + * * @return the associated {@link ServicesRegistry} */ public ServicesRegistry getServicesRegistry() { diff --git a/plugins/infra/emf/org.eclipse.papyrus.infra.emf/src/org/eclipse/papyrus/infra/emf/utils/ServiceUtilsForEObject.java b/plugins/infra/emf/org.eclipse.papyrus.infra.emf/src/org/eclipse/papyrus/infra/emf/utils/ServiceUtilsForEObject.java index 3a6dba8b718..385496d15ac 100644 --- a/plugins/infra/emf/org.eclipse.papyrus.infra.emf/src/org/eclipse/papyrus/infra/emf/utils/ServiceUtilsForEObject.java +++ b/plugins/infra/emf/org.eclipse.papyrus.infra.emf/src/org/eclipse/papyrus/infra/emf/utils/ServiceUtilsForEObject.java @@ -1,6 +1,6 @@ /***************************************************************************** * Copyright (c) 2012 CEA LIST. - * + * * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -18,9 +18,9 @@ import org.eclipse.papyrus.infra.core.utils.AbstractServiceUtils; /** * A ServiceUtils instance for manipulating Papyrus services on an EObject - * + * * @author Camille Letavernier - * + * */ public class ServiceUtilsForEObject extends AbstractServiceUtils { @@ -31,12 +31,12 @@ public class ServiceUtilsForEObject extends AbstractServiceUtils { } private ServiceUtilsForEObject() { - //Singleton + // Singleton } @Override public ServicesRegistry getServiceRegistry(EObject from) throws ServiceException { - if(from == null) { + if (from == null) { throw new ServiceException("The selected EObject must not be null"); //$NON-NLS-1$ } diff --git a/plugins/infra/emf/org.eclipse.papyrus.infra.emf/src/org/eclipse/papyrus/infra/emf/utils/ServiceUtilsForHandlers.java b/plugins/infra/emf/org.eclipse.papyrus.infra.emf/src/org/eclipse/papyrus/infra/emf/utils/ServiceUtilsForHandlers.java index 158a3ca08b4..b3068b03106 100644 --- a/plugins/infra/emf/org.eclipse.papyrus.infra.emf/src/org/eclipse/papyrus/infra/emf/utils/ServiceUtilsForHandlers.java +++ b/plugins/infra/emf/org.eclipse.papyrus.infra.emf/src/org/eclipse/papyrus/infra/emf/utils/ServiceUtilsForHandlers.java @@ -1,6 +1,6 @@ /***************************************************************************** * Copyright (c) 2012 CEA LIST. - * + * * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -24,18 +24,18 @@ import org.eclipse.ui.IWorkbenchPartSite; /** * ServicesUtils based on the Handler's ExecutionEvent - * + * * It first tests the current selection, then the IWorkbenchPart on which the handler is executed. * The IWorkbenchPart is expected to be adaptable to a ServiceRegistry. - * + * * @author Camille Letavernier - * + * * @see ServiceUtilsForSelection */ public class ServiceUtilsForHandlers extends AbstractServiceUtils { private ServiceUtilsForHandlers() { - //Singleton + // Singleton } @Override @@ -43,23 +43,23 @@ public class ServiceUtilsForHandlers extends AbstractServiceUtils { private ServiceUtilsForIEvaluationContext() { - //Singleton + // Singleton } /** - * + * * @see org.eclipse.papyrus.infra.core.utils.AbstractServiceUtils#getServiceRegistry(java.lang.Object) * * @param from @@ -49,20 +49,20 @@ public class ServiceUtilsForIEvaluationContext extends AbstractServiceUtils - * To work properly, the EObject should be associated to a {@link Resource}, itself registered in a {@link ResourceSet}. - * Also, the {@code ServicesRegistry} should be associated to the {@code ResourceSet}. - * Normally, this is automatically done thanks to the {@link ModelSetServiceFactory} service. - * If you access this class from a service, you can ensure that the latter service is started by letting your service - * depend on the org.eclipse.papyrus.infra.core.editor.ModelSetServiceFactory. + * To work properly, the EObject should be associated to a {@link Resource}, itself registered in a {@link ResourceSet}. Also, the {@code ServicesRegistry} should be associated to the {@code ResourceSet}. Normally, this is automatically done thanks to the + * {@link ModelSetServiceFactory} service. If you access this class from a service, you can ensure that the latter service is started by letting your service depend on the org.eclipse.papyrus.infra.core.editor.ModelSetServiceFactory. *

    - * + * * @author cedric dumoulin - * + * */ public class ServiceUtilsForResource extends AbstractServiceUtils { @@ -43,7 +39,7 @@ public class ServiceUtilsForResource extends AbstractServiceUtils { /** * Get the singleton instance of the class. - * + * * @return */ public static final ServiceUtilsForResource getInstance() { @@ -52,16 +48,16 @@ public class ServiceUtilsForResource extends AbstractServiceUtils { /** * Get the {@link ServicesRegistry} from a {@link Resource}. - * + * * @param from - * The {@link Resource} from which we want the associated {@link ServicesRegistry}. + * The {@link Resource} from which we want the associated {@link ServicesRegistry}. * @return * @throws ServiceException - * If there is no {@link ServicesRegistry} associated to the {@link ResourceSet} owning the {@link Resource}. + * If there is no {@link ServicesRegistry} associated to the {@link ResourceSet} owning the {@link Resource}. */ @Override public ServicesRegistry getServiceRegistry(Resource from) throws ServiceException { - if(from == null) { + if (from == null) { throw new ServiceNotFoundException("Can't find the ResourceSet needed retrieve the ServiceRegistry."); //$NON-NLS-1$ } return ServiceUtilsForResourceSet.getInstance().getServiceRegistry(from.getResourceSet()); diff --git a/plugins/infra/emf/org.eclipse.papyrus.infra.emf/src/org/eclipse/papyrus/infra/emf/utils/ServiceUtilsForResourceInitializerService.java b/plugins/infra/emf/org.eclipse.papyrus.infra.emf/src/org/eclipse/papyrus/infra/emf/utils/ServiceUtilsForResourceInitializerService.java index 8ac0f6edafa..a3a98b5a0fe 100644 --- a/plugins/infra/emf/org.eclipse.papyrus.infra.emf/src/org/eclipse/papyrus/infra/emf/utils/ServiceUtilsForResourceInitializerService.java +++ b/plugins/infra/emf/org.eclipse.papyrus.infra.emf/src/org/eclipse/papyrus/infra/emf/utils/ServiceUtilsForResourceInitializerService.java @@ -1,7 +1,7 @@ /***************************************************************************** * Copyright (c) 2012, 2014 Cedric Dumoulin, CEA, and others. * - * + * * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -26,13 +26,13 @@ import org.eclipse.papyrus.infra.core.utils.ServiceUtils; * This service register inside the ResourceSet an AdapterFactory referencing the ServiceRegistry. * This will allows to get the ServicesRegistry from any EMF object (see {@link ServiceUtilsForResource}. * The AdapterFactory can't provide Adapters. It is only used to hold a reference on the ServiceRegistry. - * + * * This service depends on the ModelSet service. - * - * + * + * * @see ServiceRegistryAdapterFactory * @see ServiceUtilsForResource - * + * * @author cedric dumoulin * * @deprecated Since 1.0, the {@link ModelSetServiceFactory} class associates the model-set with its service registry @@ -42,15 +42,15 @@ import org.eclipse.papyrus.infra.core.utils.ServiceUtils; public class ServiceUtilsForResourceInitializerService implements IService { ServicesRegistry servicesRegistry; - + /** * Associate the service registry with the resource set if the resource set wasn't created by the registry. */ public void init(ServicesRegistry servicesRegistry) throws ServiceException { - + this.servicesRegistry = servicesRegistry; ModelSet modelSet = ServiceUtils.getInstance().getModelSet(servicesRegistry); - + ModelSetServiceFactory.setServiceRegistry(modelSet, servicesRegistry); } @@ -64,11 +64,11 @@ public class ServiceUtilsForResourceInitializerService implements IService { public void disposeService() throws ServiceException { try { ModelSet modelSet = ServiceUtils.getInstance().getModelSet(servicesRegistry); - + ModelSetServiceFactory.setServiceRegistry(modelSet, null); } catch (BadStateException e) { // ModelSet is already disposed. Do nothing } } - + } diff --git a/plugins/infra/emf/org.eclipse.papyrus.infra.emf/src/org/eclipse/papyrus/infra/emf/utils/ServiceUtilsForResourceSet.java b/plugins/infra/emf/org.eclipse.papyrus.infra.emf/src/org/eclipse/papyrus/infra/emf/utils/ServiceUtilsForResourceSet.java index ba444e61ddc..fe12044b226 100644 --- a/plugins/infra/emf/org.eclipse.papyrus.infra.emf/src/org/eclipse/papyrus/infra/emf/utils/ServiceUtilsForResourceSet.java +++ b/plugins/infra/emf/org.eclipse.papyrus.infra.emf/src/org/eclipse/papyrus/infra/emf/utils/ServiceUtilsForResourceSet.java @@ -1,6 +1,6 @@ /***************************************************************************** * Copyright (c) 2013, 2014 CEA LIST and others. - * + * * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -9,7 +9,7 @@ * Contributors: * Camille Letavernier (CEA LIST) camille.letavernier@cea.fr - Initial API and implementation * Christian W. Damus (CEA) - bug 431953 (pre-requisite refactoring of ModelSet service start-up) - * + * *****************************************************************************/ package org.eclipse.papyrus.infra.emf.utils; @@ -24,7 +24,7 @@ import org.eclipse.papyrus.infra.core.utils.AbstractServiceUtils; public class ServiceUtilsForResourceSet extends AbstractServiceUtils { private ServiceUtilsForResourceSet() { - //Singleton + // Singleton } private static ServiceUtilsForResourceSet instance = new ServiceUtilsForResourceSet(); @@ -35,12 +35,12 @@ public class ServiceUtilsForResourceSet extends AbstractServiceUtils { private ServiceUtilsForSelection() { - //Singleton + // Singleton } private static ServiceUtilsForSelection instance = new ServiceUtilsForSelection(); @@ -41,13 +41,13 @@ public class ServiceUtilsForSelection extends AbstractServiceUtils { @Override public ServicesRegistry getServiceRegistry(ISelection from) throws ServiceException { - if(from instanceof IStructuredSelection) { - IStructuredSelection selection = (IStructuredSelection)from; + if (from instanceof IStructuredSelection) { + IStructuredSelection selection = (IStructuredSelection) from; Iterator selectionIterator = selection.iterator(); - while(selectionIterator.hasNext()) { + while (selectionIterator.hasNext()) { Object selectedElement = selectionIterator.next(); EObject selectedEObject = EMFHelper.getEObject(selectedElement); - if(selectedEObject != null) { + if (selectedEObject != null) { return ServiceUtilsForEObject.getInstance().getServiceRegistry(selectedEObject); } } diff --git a/plugins/infra/emf/org.eclipse.papyrus.infra.emf/src/org/eclipse/papyrus/infra/emf/utils/TextReferencesHelper.java b/plugins/infra/emf/org.eclipse.papyrus.infra.emf/src/org/eclipse/papyrus/infra/emf/utils/TextReferencesHelper.java index ece95494ed2..c7c783ea587 100644 --- a/plugins/infra/emf/org.eclipse.papyrus.infra.emf/src/org/eclipse/papyrus/infra/emf/utils/TextReferencesHelper.java +++ b/plugins/infra/emf/org.eclipse.papyrus.infra.emf/src/org/eclipse/papyrus/infra/emf/utils/TextReferencesHelper.java @@ -1,7 +1,7 @@ /***************************************************************************** * Copyright (c) 2013 CEA LIST. * - * + * * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -25,44 +25,44 @@ import org.eclipse.papyrus.infra.emf.Activator; /** * An abstract helper to replace references to EObjects (represented by their URI) with a label (related to this EObject). - * + * * It is typically used to introduce dynamic references to object's labels in free text areas (e.g. in a description) - * + * * The reference can be introduced with {@link #insertReference(EObject, String, int)} - * + * * The parsed string can be retrieved with {@link #replaceReferences(String)} - * + * * @author Camille Letavernier - * + * */ public abstract class TextReferencesHelper { - public static final String URI_CHARS = "[^#]"; //Almost everything is allowed in a URI. It's simpler to exclude the fragment separator + public static final String URI_CHARS = "[^#]"; // Almost everything is allowed in a URI. It's simpler to exclude the fragment separator - public static final String FRAGMENT_CHARS = "[-A-Za-z0-9_/]"; //In Papyrus this is sufficient. Do we need a more complex expression? + public static final String FRAGMENT_CHARS = "[-A-Za-z0-9_/]"; // In Papyrus this is sufficient. Do we need a more complex expression? - public static final String URI_REGEX = String.format("%s*#%s+", URI_CHARS, FRAGMENT_CHARS); //The base uri is optional. The fragment is required. + public static final String URI_REGEX = String.format("%s*#%s+", URI_CHARS, FRAGMENT_CHARS); // The base uri is optional. The fragment is required. - public static String UNKNOWN_ELEMENT = "UNKNOWN"; //Replacement text for unknown elements + public static String UNKNOWN_ELEMENT = "UNKNOWN"; // Replacement text for unknown elements - public static String PROXY_ELEMENT = "PROXY"; //Replacement text for proxy elements + public static String PROXY_ELEMENT = "PROXY"; // Replacement text for proxy elements protected Resource baseResource; protected ResourceSet resourceSet; protected TextReferencesHelper() { - //Empty + // Empty } /** - * + * * @param baseResource - * The resource against which the link uris will be resolved + * The resource against which the link uris will be resolved */ protected TextReferencesHelper(Resource baseResource) { - if(baseResource != null) { + if (baseResource != null) { this.baseResource = baseResource; this.resourceSet = baseResource.getResourceSet(); } @@ -70,22 +70,22 @@ public abstract class TextReferencesHelper { /** * Parses the specified text, and replace all references with their replacement String - * + * * @param text * @return - * + * * @see {@link #getReplacement(EObject, String)} */ public String replaceReferences(String text) { - if(text == null) { + if (text == null) { return null; } - if("".equals(text)) { + if ("".equals(text)) { return text; } - //Javadoc-like @link tag + // Javadoc-like @link tag String replaceRegex = String.format("\\{@link (%s)(\\|([^}]*))?\\}", URI_REGEX); Pattern pattern = Pattern.compile(replaceRegex); @@ -93,9 +93,9 @@ public abstract class TextReferencesHelper { String newText = text; - while(matcher.find()) { - String uriToReplace = matcher.group(1); //0 is the full pattern (e.g. {link myUri#myFragment}, 1 is the first group (e.g. myUri#myFragment) - String cachedValue = matcher.group(3); //group 2 is |CachedValue, group 3 is CachedValue + while (matcher.find()) { + String uriToReplace = matcher.group(1); // 0 is the full pattern (e.g. {link myUri#myFragment}, 1 is the first group (e.g. myUri#myFragment) + String cachedValue = matcher.group(3); // group 2 is |CachedValue, group 3 is CachedValue String replacement = decorate(getReplacement(uriToReplace, cachedValue)); @@ -108,50 +108,50 @@ public abstract class TextReferencesHelper { /** * Insert a reference to the given element in the specified text, at the specified position - * + * * @param toElement - * The element to reference + * The element to reference * @param inText - * The text in which the reference must be inserted + * The text in which the reference must be inserted * @param atPosition - * The position at which the reference must be inserted. 0 is the beginning, while text.length() is the end. For all "invalid" indexes (<0 - * and > length()), the reference will be inserted at the end of the string + * The position at which the reference must be inserted. 0 is the beginning, while text.length() is the end. For all "invalid" indexes (<0 + * and > length()), the reference will be inserted at the end of the string * @return * The text containing the new reference */ public String insertReference(EObject toElement, String inText, int atPosition) { String result = inText; - if(inText == null) { - return null; //No change + if (inText == null) { + return null; // No change } - if(toElement == null) { - return inText; //No change + if (toElement == null) { + return inText; // No change } - //Use a Javadoc-like @link tag + // Use a Javadoc-like @link tag URI elementURI = EcoreUtil.getURI(toElement); - if(baseResource != null) { + if (baseResource != null) { URI baseURI = baseResource.getURI(); - if(baseURI != null) { + if (baseURI != null) { elementURI = elementURI.deresolve(baseURI); } } - String reference = "{@link " + elementURI + "}"; //The URI is already encoded + String reference = "{@link " + elementURI + "}"; // The URI is already encoded - if(atPosition == 0) { - return reference + result; //At the beginning + if (atPosition == 0) { + return reference + result; // At the beginning } - if(atPosition < 0 || atPosition >= inText.length()) { - result += reference; //Insert at the end + if (atPosition < 0 || atPosition >= inText.length()) { + result += reference; // Insert at the end } else { - //Hello, world - //The whitespace is the character at position 6. Insert the reference at position 7 to add it after the whitespace - //It will result in Hello, world - result = inText.substring(0, atPosition); //Include the "afterPosition" character - result += reference; //Add the reference - result += inText.substring(atPosition, inText.length()); //Complete the string (Exclude the afterPosition character, as it has already been copied in the first part of the result string) + // Hello, world + // The whitespace is the character at position 6. Insert the reference at position 7 to add it after the whitespace + // It will result in Hello, world + result = inText.substring(0, atPosition); // Include the "afterPosition" character + result += reference; // Add the reference + result += inText.substring(atPosition, inText.length()); // Complete the string (Exclude the afterPosition character, as it has already been copied in the first part of the result string) } return result; @@ -160,7 +160,7 @@ public abstract class TextReferencesHelper { /** * Adds a (text) decoration to the replacement string. * This can be used for e.g. html-based texts, to add tags around the replaced string - * + * * The default implementation does nothing. */ protected String decorate(String text) { @@ -170,11 +170,11 @@ public abstract class TextReferencesHelper { protected String getReplacement(String uriToReplace, String cachedValue) { String uri, fragment; - if(baseResource == null || resourceSet == null || baseResource.getURI() == null) { + if (baseResource == null || resourceSet == null || baseResource.getURI() == null) { return UNKNOWN_ELEMENT; } - if(uriToReplace.contains("#")) { + if (uriToReplace.contains("#")) { uri = uriToReplace.substring(0, uriToReplace.indexOf('#')); fragment = uriToReplace.substring(uriToReplace.indexOf('#') + 1, uriToReplace.length()); } else { @@ -187,11 +187,11 @@ public abstract class TextReferencesHelper { resourceURI = baseResource.getURI(); - targetURI = URI.createURI(uri); //The URI must already be encoded + targetURI = URI.createURI(uri); // The URI must already be encoded targetURI = targetURI.resolve(resourceURI); - if(targetURI == null) { + if (targetURI == null) { return UNKNOWN_ELEMENT; } @@ -205,8 +205,8 @@ public abstract class TextReferencesHelper { EObject targetElement = resourceSet.getEObject(uriToReplace, true); return getReplacement(targetElement, cachedValue); } catch (Exception ex) { - //Log the error? If it happens once, it will happen many times (after each refresh). The UNKNOWN keyword may be enough. - //This error happens when the reference is broken (e.g. an element has been deleted). This is a "normal" behavior + // Log the error? If it happens once, it will happen many times (after each refresh). The UNKNOWN keyword may be enough. + // This error happens when the reference is broken (e.g. an element has been deleted). This is a "normal" behavior Activator.log.debug("An error occurred while loading the following URI: " + uriToReplace + ". The reference cannot be replaced"); //$NON-NLS-1$ //$NON-NLS-2$ } diff --git a/plugins/infra/emf/org.eclipse.papyrus.infra.emf/src/org/eclipse/papyrus/infra/emf/utils/TransactionalUnsetter.java b/plugins/infra/emf/org.eclipse.papyrus.infra.emf/src/org/eclipse/papyrus/infra/emf/utils/TransactionalUnsetter.java index 1d4ab1791a6..6fcca922d2c 100644 --- a/plugins/infra/emf/org.eclipse.papyrus.infra.emf/src/org/eclipse/papyrus/infra/emf/utils/TransactionalUnsetter.java +++ b/plugins/infra/emf/org.eclipse.papyrus.infra.emf/src/org/eclipse/papyrus/infra/emf/utils/TransactionalUnsetter.java @@ -1,7 +1,7 @@ /***************************************************************************** * Copyright (c) 2012 CEA LIST. * - * + * * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -20,9 +20,9 @@ import org.eclipse.emf.transaction.TransactionalEditingDomain; import org.eclipse.papyrus.infra.emf.commands.UnsetCommand; /** - * + * * This class allows to do unset on a feature using a command - * + * */ public class TransactionalUnsetter { @@ -39,17 +39,17 @@ public class TransactionalUnsetter { private final TransactionalEditingDomain domain; /** - * + * * Constructor. - * + * * @param source - * the eobject to modify + * the eobject to modify * @param feature - * the feature on which we want to do an unset + * the feature on which we want to do an unset */ public TransactionalUnsetter(final EObject source, final EStructuralFeature feature) { - domain = (TransactionalEditingDomain)EMFHelper.resolveEditingDomain(source); - cmd = new UnsetCommand((TransactionalEditingDomain)domain, source, feature); + domain = (TransactionalEditingDomain) EMFHelper.resolveEditingDomain(source); + cmd = new UnsetCommand(domain, source, feature); } /** -- cgit v1.2.3