Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorFlorian Noyrit2016-08-09 10:25:50 +0000
committerGerrit Code Review @ Eclipse.org2016-08-28 15:46:41 +0000
commit7310db0b3b2e8ee805fedf4bfd16baf438c89332 (patch)
tree3dadff6a067e8d8bcbf837d8277dfac7749aef27 /plugins/infra/core/org.eclipse.papyrus.infra.core
parent7851474fe5f33de156c797942945a3e9c97cb0a8 (diff)
downloadorg.eclipse.papyrus-7310db0b3b2e8ee805fedf4bfd16baf438c89332.tar.gz
org.eclipse.papyrus-7310db0b3b2e8ee805fedf4bfd16baf438c89332.tar.xz
org.eclipse.papyrus-7310db0b3b2e8ee805fedf4bfd16baf438c89332.zip
Bug 443799 - Fix potential bugs identified by FindBugs in oep.infra.*
Bug 499554 - Oxygen release version number moved to 3.0.0. Change-Id: I8e112db7175a5b89eb9b37973639627a6c29e007
Diffstat (limited to 'plugins/infra/core/org.eclipse.papyrus.infra.core')
-rw-r--r--plugins/infra/core/org.eclipse.papyrus.infra.core/src/org/eclipse/papyrus/infra/core/internal/language/DefaultLanguageProvider.java15
-rw-r--r--plugins/infra/core/org.eclipse.papyrus.infra.core/src/org/eclipse/papyrus/infra/core/modelsetquery/impl/ModelSetQueryAdapterSizeMatters.java31
-rw-r--r--plugins/infra/core/org.eclipse.papyrus.infra.core/src/org/eclipse/papyrus/infra/core/modelsetquery/impl/ModelSetQueryAdapterTimeMatters.java10
-rw-r--r--plugins/infra/core/org.eclipse.papyrus.infra.core/src/org/eclipse/papyrus/infra/core/resource/ModelSet.java21
-rw-r--r--plugins/infra/core/org.eclipse.papyrus.infra.core/src/org/eclipse/papyrus/infra/core/resource/sasheditor/SashModel.java11
-rw-r--r--plugins/infra/core/org.eclipse.papyrus.infra.core/src/org/eclipse/papyrus/infra/core/services/internal/ErrorServiceTypeEntry.java212
6 files changed, 149 insertions, 151 deletions
diff --git a/plugins/infra/core/org.eclipse.papyrus.infra.core/src/org/eclipse/papyrus/infra/core/internal/language/DefaultLanguageProvider.java b/plugins/infra/core/org.eclipse.papyrus.infra.core/src/org/eclipse/papyrus/infra/core/internal/language/DefaultLanguageProvider.java
index eb3924c8b84..0d4378cc001 100644
--- a/plugins/infra/core/org.eclipse.papyrus.infra.core/src/org/eclipse/papyrus/infra/core/internal/language/DefaultLanguageProvider.java
+++ b/plugins/infra/core/org.eclipse.papyrus.infra.core/src/org/eclipse/papyrus/infra/core/internal/language/DefaultLanguageProvider.java
@@ -163,12 +163,15 @@ public class DefaultLanguageProvider implements ILanguageProvider {
} else if (modelURI.isFile()) {
String baseName = modelURI.lastSegment();
File directory = new File(modelURI.trimSegments(1).toFileString());
- for (File next : directory.listFiles()) {
- if (next.isFile()) {
- IPath nextPath = new Path(directory.getPath()).append(next.getName());
- String name = nextPath.removeFileExtension().lastSegment();
- if (name.equals(baseName)) {
- result.add(URI.createPlatformResourceURI(nextPath.toString(), true));
+ File[] listFiles = directory.listFiles();
+ if (listFiles != null) {
+ for (File next : listFiles) {
+ if (next.isFile()) {
+ IPath nextPath = new Path(directory.getPath()).append(next.getName());
+ String name = nextPath.removeFileExtension().lastSegment();
+ if (name.equals(baseName)) {
+ result.add(URI.createPlatformResourceURI(nextPath.toString(), true));
+ }
}
}
}
diff --git a/plugins/infra/core/org.eclipse.papyrus.infra.core/src/org/eclipse/papyrus/infra/core/modelsetquery/impl/ModelSetQueryAdapterSizeMatters.java b/plugins/infra/core/org.eclipse.papyrus.infra.core/src/org/eclipse/papyrus/infra/core/modelsetquery/impl/ModelSetQueryAdapterSizeMatters.java
index addd286eed6..1eec11a2f7c 100644
--- a/plugins/infra/core/org.eclipse.papyrus.infra.core/src/org/eclipse/papyrus/infra/core/modelsetquery/impl/ModelSetQueryAdapterSizeMatters.java
+++ b/plugins/infra/core/org.eclipse.papyrus.infra.core/src/org/eclipse/papyrus/infra/core/modelsetquery/impl/ModelSetQueryAdapterSizeMatters.java
@@ -76,8 +76,7 @@ public class ModelSetQueryAdapterSizeMatters extends EContentAdapter implements
}
private void addSubTypes(EClass eClassifier) {
- for (EClass superType : eClassifier.getESuperTypes())
- {
+ for (EClass superType : eClassifier.getESuperTypes()) {
addSubType(superType, eClassifier);
addSubTypes(superType);
}
@@ -85,19 +84,16 @@ public class ModelSetQueryAdapterSizeMatters extends EContentAdapter implements
protected void addSubType(EClass superType, EClassifier eClassifier) {
Collection<EClassifier> result = subTypes.get(superType);
- if (result == null)
- {
+ if (result == null) {
result = new HashSet<EClassifier>();
subTypes.put(superType, result);
}
result.add(eClassifier);
}
- private void putObjectInMap(EClassifier eClassifier, EObject obj)
- {
+ private void putObjectInMap(EClassifier eClassifier, EObject obj) {
Collection<EObject> result = cache.get(eClassifier);
- if (result == null)
- {
+ if (result == null) {
result = new HashSet<EObject>();
cache.put(eClassifier, result);
}
@@ -125,22 +121,24 @@ public class ModelSetQueryAdapterSizeMatters extends EContentAdapter implements
Set<EClassifier> alreadyComputed = new HashSet<EClassifier>();
Stack<EClassifier> types = new Stack<EClassifier>();
types.push(type);
- while (!types.isEmpty())
- {
+ while (!types.isEmpty()) {
EClassifier top = types.pop();
alreadyComputed.add(top);
// add instances to the buffer
Collection<EObject> c = cache.get(top);
- if (c != null)
- {
+ if (c != null) {
buffer.addAll(c);
}
// compute sub types
Collection<EClassifier> c2 = subTypes.get(top);
- if (c2 != null && !alreadyComputed.contains(c2))
- {
- types.addAll(c2);
+ if (c2 != null) {
+ for (EClassifier eClassifier : c2) {
+ if (eClassifier != null && !alreadyComputed.contains(eClassifier)) {
+ types.add(eClassifier);
+ }
+ }
}
+
}
return buffer;
}
@@ -161,8 +159,7 @@ public class ModelSetQueryAdapterSizeMatters extends EContentAdapter implements
*/
@Override
public void addEntriesInCache(EClassifier type, HashSet<EObject> list) {
- for (EObject e : list)
- {
+ for (EObject e : list) {
addObjectInCache(e);
}
}
diff --git a/plugins/infra/core/org.eclipse.papyrus.infra.core/src/org/eclipse/papyrus/infra/core/modelsetquery/impl/ModelSetQueryAdapterTimeMatters.java b/plugins/infra/core/org.eclipse.papyrus.infra.core/src/org/eclipse/papyrus/infra/core/modelsetquery/impl/ModelSetQueryAdapterTimeMatters.java
index 064291c59a1..53e20365439 100644
--- a/plugins/infra/core/org.eclipse.papyrus.infra.core/src/org/eclipse/papyrus/infra/core/modelsetquery/impl/ModelSetQueryAdapterTimeMatters.java
+++ b/plugins/infra/core/org.eclipse.papyrus.infra.core/src/org/eclipse/papyrus/infra/core/modelsetquery/impl/ModelSetQueryAdapterTimeMatters.java
@@ -73,8 +73,7 @@ public class ModelSetQueryAdapterTimeMatters extends EContentAdapter implements
private void putObjectInCache(EClassifier eClassifier, EObject newObj) {
Collection<EObject> listOfClassifiers = cache.get(eClassifier);
- if (listOfClassifiers == null)
- {
+ if (listOfClassifiers == null) {
listOfClassifiers = new HashSet<EObject>();
cache.put(eClassifier, listOfClassifiers);
}
@@ -96,10 +95,6 @@ public class ModelSetQueryAdapterTimeMatters extends EContentAdapter implements
if (listOfClassifiers != null) {
listOfClassifiers.remove(newObj);
}
- if (listOfClassifiers.isEmpty())
- {
- cache.remove(eClassifier);
- }
}
@Override
@@ -124,8 +119,7 @@ public class ModelSetQueryAdapterTimeMatters extends EContentAdapter implements
*/
@Override
public void addEntriesInCache(EClassifier type, HashSet<EObject> list) {
- for (EObject e : list)
- {
+ for (EObject e : list) {
addObjectInCache(e);
}
}
diff --git a/plugins/infra/core/org.eclipse.papyrus.infra.core/src/org/eclipse/papyrus/infra/core/resource/ModelSet.java b/plugins/infra/core/org.eclipse.papyrus.infra.core/src/org/eclipse/papyrus/infra/core/resource/ModelSet.java
index bb7c9abc4b3..85a7c146bca 100644
--- a/plugins/infra/core/org.eclipse.papyrus.infra.core/src/org/eclipse/papyrus/infra/core/resource/ModelSet.java
+++ b/plugins/infra/core/org.eclipse.papyrus.infra.core/src/org/eclipse/papyrus/infra/core/resource/ModelSet.java
@@ -634,23 +634,26 @@ public class ModelSet extends ResourceSetImpl {
*
* @param modelIdentifiers
* The model to import from the specified IFile.
- * @param file
- * The IFile used to import the model.
+ * @param uri
+ * The URI used to import the model.
* @throws ModelException
* If an error occur during import.
*/
public void importModels(ModelIdentifiers modelIdentifiers, URI uri) throws ModelException {
- URI toImport = uri.trimFileExtension();
- // Walk all registered models
- for (String modelId : modelIdentifiers) {
- IModel model = getModel(modelId);
+ if (uri != null) {
+ URI toImport = uri.trimFileExtension();
+ // Walk all registered models
+ for (String modelId : modelIdentifiers) {
+ IModel model = getModel(modelId);
+
+ // Load models using the default path
+ model.importModel(toImport);
- // Load models using the default path
- model.importModel(toImport);
- if (uri != null) {
model.setModelURI(uriWithoutExtension);
}
+ } else {
+ throw new ModelException("URI used to import the model is null");
}
}
diff --git a/plugins/infra/core/org.eclipse.papyrus.infra.core/src/org/eclipse/papyrus/infra/core/resource/sasheditor/SashModel.java b/plugins/infra/core/org.eclipse.papyrus.infra.core/src/org/eclipse/papyrus/infra/core/resource/sasheditor/SashModel.java
index 82483db1073..d513de07d25 100644
--- a/plugins/infra/core/org.eclipse.papyrus.infra.core/src/org/eclipse/papyrus/infra/core/resource/sasheditor/SashModel.java
+++ b/plugins/infra/core/org.eclipse.papyrus.infra.core/src/org/eclipse/papyrus/infra/core/resource/sasheditor/SashModel.java
@@ -248,7 +248,7 @@ public class SashModel extends EMFLogicalModel implements IModel {
}
/**
- * Intantiates the sash resource template on the given URI.
+ * Instantiates the sash resource template on the given URI.
*
* @param sashResourceURI
* the new sash resource URI
@@ -258,8 +258,13 @@ public class SashModel extends EMFLogicalModel implements IModel {
*/
void intantiateTemplate(URI sashResourceURI) throws IOException {
try (OutputStream output = getModelManager().getURIConverter().createOutputStream(sashResourceURI)) {
- URL template = Activator.getDefault().getBundle().getEntry("templates/model.sash"); //$NON-NLS-1$
- Resources.copy(template, output);
+ String path = "templates/model.sash"; //$NON-NLS-1$
+ URL template = Activator.getDefault().getBundle().getEntry(path);
+ if (template != null) {
+ Resources.copy(template, output);
+ } else {
+ throw new IOException("Sash template URL is null for: " + path);
+ }
}
}
diff --git a/plugins/infra/core/org.eclipse.papyrus.infra.core/src/org/eclipse/papyrus/infra/core/services/internal/ErrorServiceTypeEntry.java b/plugins/infra/core/org.eclipse.papyrus.infra.core/src/org/eclipse/papyrus/infra/core/services/internal/ErrorServiceTypeEntry.java
index b2973a87196..99e10e95d6a 100644
--- a/plugins/infra/core/org.eclipse.papyrus.infra.core/src/org/eclipse/papyrus/infra/core/services/internal/ErrorServiceTypeEntry.java
+++ b/plugins/infra/core/org.eclipse.papyrus.infra.core/src/org/eclipse/papyrus/infra/core/services/internal/ErrorServiceTypeEntry.java
@@ -1,108 +1,104 @@
-/*****************************************************************************
- * Copyright (c) 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
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * Cedric Dumoulin Cedric.dumoulin@lifl.fr - Initial API and implementation
- *
- *****************************************************************************/
-package org.eclipse.papyrus.infra.core.services.internal;
-
-import org.eclipse.papyrus.infra.core.services.BadStateException;
-import org.eclipse.papyrus.infra.core.services.ServiceDescriptor;
-import org.eclipse.papyrus.infra.core.services.ServiceException;
-import org.eclipse.papyrus.infra.core.services.ServiceState;
-import org.eclipse.papyrus.infra.core.services.ServicesRegistry;
-
-/**
- * A service entry used for faulty services. In this implementation, methods do
- * nothings or throw an error.
- *
- *
- * @author cedric dumoulin
- *
- */
-public class ErrorServiceTypeEntry extends ServiceTypeEntry {
-
- /**
- * The original service descriptor.
- */
- private ServiceDescriptor descriptor;
-
- /**
- *
- * Constructor.
- *
- * @param descriptor
- */
- public ErrorServiceTypeEntry(ServiceDescriptor descriptor) {
- super(descriptor);
- }
-
- /**
- *
- * @see org.eclipse.papyrus.infra.core.services.internal.ServiceTypeEntry#getServiceInstance()
- *
- * @return
- * @throws ServiceException
- */
- @Override
- public Object getServiceInstance() throws ServiceException {
- throw new BadStateException("Service has not started.", ServiceState.error, descriptor); //$NON-NLS-1$
- }
-
- /**
- *
- * @see org.eclipse.papyrus.infra.core.services.internal.ServiceTypeEntry#createService()
- *
- * @throws ServiceException
- */
- @Override
- public void createService() throws ServiceException {
- // do nothing
-
- }
-
- /**
- *
- * @see org.eclipse.papyrus.infra.core.services.internal.ServiceTypeEntry#initService(ServicesRegistry)
- *
- * @param servicesRegistry
- * @throws ServiceException
- */
- @Override
- public void initService(ServicesRegistry servicesRegistry) throws ServiceException {
- // do nothing
-
- }
-
- /**
- *
- * @see org.eclipse.papyrus.infra.core.services.internal.ServiceTypeEntry#startService()
- *
- * @throws ServiceException
- */
- @Override
- public void startService() throws ServiceException {
- // do nothing
-
- }
-
- /**
- *
- * @see org.eclipse.papyrus.infra.core.services.internal.ServiceTypeEntry#disposeService()
- *
- * @throws ServiceException
- */
- @Override
- public void disposeService() throws ServiceException {
- // do nothing
-
- }
-
-}
+/*****************************************************************************
+ * Copyright (c) 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
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Cedric Dumoulin Cedric.dumoulin@lifl.fr - Initial API and implementation
+ *
+ *****************************************************************************/
+package org.eclipse.papyrus.infra.core.services.internal;
+
+import org.eclipse.papyrus.infra.core.services.BadStateException;
+import org.eclipse.papyrus.infra.core.services.ServiceDescriptor;
+import org.eclipse.papyrus.infra.core.services.ServiceException;
+import org.eclipse.papyrus.infra.core.services.ServiceState;
+import org.eclipse.papyrus.infra.core.services.ServicesRegistry;
+
+/**
+ * A service entry used for faulty services. In this implementation, methods do
+ * nothings or throw an error.
+ *
+ *
+ * @author cedric dumoulin
+ *
+ */
+public class ErrorServiceTypeEntry extends ServiceTypeEntry {
+
+
+ /**
+ *
+ * Constructor.
+ *
+ * @param descriptor
+ */
+ public ErrorServiceTypeEntry(ServiceDescriptor descriptor) {
+ super(descriptor);
+ }
+
+ /**
+ *
+ * @see org.eclipse.papyrus.infra.core.services.internal.ServiceTypeEntry#getServiceInstance()
+ *
+ * @return
+ * @throws ServiceException
+ */
+ @Override
+ public Object getServiceInstance() throws ServiceException {
+ throw new BadStateException("Service has not started.", ServiceState.error, serviceDescriptor); //$NON-NLS-1$
+ }
+
+ /**
+ *
+ * @see org.eclipse.papyrus.infra.core.services.internal.ServiceTypeEntry#createService()
+ *
+ * @throws ServiceException
+ */
+ @Override
+ public void createService() throws ServiceException {
+ // do nothing
+
+ }
+
+ /**
+ *
+ * @see org.eclipse.papyrus.infra.core.services.internal.ServiceTypeEntry#initService(ServicesRegistry)
+ *
+ * @param servicesRegistry
+ * @throws ServiceException
+ */
+ @Override
+ public void initService(ServicesRegistry servicesRegistry) throws ServiceException {
+ // do nothing
+
+ }
+
+ /**
+ *
+ * @see org.eclipse.papyrus.infra.core.services.internal.ServiceTypeEntry#startService()
+ *
+ * @throws ServiceException
+ */
+ @Override
+ public void startService() throws ServiceException {
+ // do nothing
+
+ }
+
+ /**
+ *
+ * @see org.eclipse.papyrus.infra.core.services.internal.ServiceTypeEntry#disposeService()
+ *
+ * @throws ServiceException
+ */
+ @Override
+ public void disposeService() throws ServiceException {
+ // do nothing
+
+ }
+
+}

Back to the top