diff options
author | Benoit Maggi | 2015-11-17 15:53:14 +0000 |
---|---|---|
committer | Gerrit Code Review @ Eclipse.org | 2015-11-19 09:42:37 +0000 |
commit | eef75a8d8c26905b729a48a971a87816fdd4f091 (patch) | |
tree | d683398e4d93350937f2ce1b1b859c78505d62af /plugins/uml/tools/org.eclipse.papyrus.uml.tools.utils/src/org | |
parent | e94966c15cb3959b8770c7800fad129ad8a8dab5 (diff) | |
download | org.eclipse.papyrus-eef75a8d8c26905b729a48a971a87816fdd4f091.tar.gz org.eclipse.papyrus-eef75a8d8c26905b729a48a971a87816fdd4f091.tar.xz org.eclipse.papyrus-eef75a8d8c26905b729a48a971a87816fdd4f091.zip |
Bug 482366 - NPE while opening Model with InstanceSpecifications
- check if the name is not null before the append
- also check that the instance is not null
- add //$NON-NLS-1$
Change-Id: Idc2e75a75689255f365841c20cacf6d9768eb4fc
Signed-off-by: Benoit Maggi <benoit.maggi@cea.fr>
Diffstat (limited to 'plugins/uml/tools/org.eclipse.papyrus.uml.tools.utils/src/org')
-rw-r--r-- | plugins/uml/tools/org.eclipse.papyrus.uml.tools.utils/src/org/eclipse/papyrus/uml/tools/utils/InstanceSpecificationUtil.java | 171 |
1 files changed, 86 insertions, 85 deletions
diff --git a/plugins/uml/tools/org.eclipse.papyrus.uml.tools.utils/src/org/eclipse/papyrus/uml/tools/utils/InstanceSpecificationUtil.java b/plugins/uml/tools/org.eclipse.papyrus.uml.tools.utils/src/org/eclipse/papyrus/uml/tools/utils/InstanceSpecificationUtil.java index 04bbd99628b..505c672897f 100644 --- a/plugins/uml/tools/org.eclipse.papyrus.uml.tools.utils/src/org/eclipse/papyrus/uml/tools/utils/InstanceSpecificationUtil.java +++ b/plugins/uml/tools/org.eclipse.papyrus.uml.tools.utils/src/org/eclipse/papyrus/uml/tools/utils/InstanceSpecificationUtil.java @@ -1,85 +1,86 @@ -/*****************************************************************************
- * Copyright (c) 2010 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:
- * Patrick Tessier (CEA LIST) Patrick.tessier@cea.fr - Initial API and implementation
- */
-package org.eclipse.papyrus.uml.tools.utils;
-
-import java.util.Collection;
-import java.util.Iterator;
-
-import org.eclipse.uml2.uml.Classifier;
-import org.eclipse.uml2.uml.InstanceSpecification;
-
-/**
- * util class to display name of instancespecification
- *
- */
-public class InstanceSpecificationUtil {
-
- /**
- * return the custom label of the operation, given UML2 specification and a custom style.
- *
- * @param style
- * the integer representing the style of the label
- *
- * @return the string corresponding to the label of the operation
- */
- public static String getCustomLabel(InstanceSpecification instance, Collection<String> maskValues) {
- StringBuffer buffer = new StringBuffer();
-
- // name
- if (maskValues.contains(ICustomAppearance.DISP_NAME)) {
- buffer.append(NamedElementUtil.getName(instance));
- }
-
- // classifier
- if (maskValues.contains(ICustomAppearance.DISP_TYPE)) {
- if (!getTypesAsString(instance).equals("")) {
- buffer.append(": ");
- buffer.append(getTypesAsString(instance));
- }
- }
-
- // Workaround: empty label leads to invalid layout.
- // FIXME: Fix the layout instead
- if (buffer.length() == 0) {
- buffer.append(" "); // Add a whitespace to avoid layout issues
- }
- //
-
- return buffer.toString();
- }
-
- /**
- * Returns the list of classifier for an instance specification as a string
- *
- * @return a string containing all classifier separated by commas
- */
- private static String getTypesAsString(InstanceSpecification instance) {
- StringBuffer typeString = new StringBuffer();
- Iterator<Classifier> classifierIterator = instance.getClassifiers().iterator();
- boolean firstParameter = true;
- while (classifierIterator.hasNext()) {
- Classifier classifier = classifierIterator.next();
-
- // get the label for this Classifier
- String classifierName = NamedElementUtil.getName(classifier);
- if (!classifierName.trim().equals("")) {
- if (!firstParameter) {
- typeString.append(", ");
- }
- typeString.append(classifierName);
- firstParameter = false;
- }
- }
- return typeString.toString();
- }
-}
+/***************************************************************************** + * Copyright (c) 2010 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: + * Patrick Tessier (CEA LIST) Patrick.tessier@cea.fr - Initial API and implementation + */ +package org.eclipse.papyrus.uml.tools.utils; + +import java.util.Collection; +import java.util.Iterator; + +import org.eclipse.uml2.uml.Classifier; +import org.eclipse.uml2.uml.InstanceSpecification; + +/** + * util class to display name of instancespecification + * + */ +public class InstanceSpecificationUtil { + + /** + * return the custom label of the operation, given UML2 specification and a custom style. + * + * @param style + * the integer representing the style of the label + * + * @return the string corresponding to the label of the operation + */ + public static String getCustomLabel(InstanceSpecification instance, Collection<String> maskValues) { + StringBuffer buffer = new StringBuffer(); + + // name + if (maskValues.contains(ICustomAppearance.DISP_NAME)) { + buffer.append(NamedElementUtil.getName(instance)); + } + + // classifier + if (maskValues.contains(ICustomAppearance.DISP_TYPE)) { + if (!getTypesAsString(instance).equals("")) { + buffer.append(": "); + buffer.append(getTypesAsString(instance)); + } + } + + // Workaround: empty label leads to invalid layout. + // FIXME: Fix the layout instead + if (buffer.length() == 0) { + buffer.append(" "); // Add a whitespace to avoid layout issues + } + // + + return buffer.toString(); + } + + /** + * Returns the list of classifier for an instance specification as a string + * + * @return a string containing all classifier separated by commas + */ + private static String getTypesAsString(InstanceSpecification instance) { + StringBuffer typeString = new StringBuffer(); + if (instance != null){ + Iterator<Classifier> classifierIterator = instance.getClassifiers().iterator(); + boolean firstParameter = true; + while (classifierIterator.hasNext()) { + Classifier classifier = classifierIterator.next(); + // get the label for this Classifier + String classifierName = NamedElementUtil.getName(classifier); + if (classifierName!= null && !"".equals(classifierName.trim())) { //$NON-NLS-1$ + if (!firstParameter) { + typeString.append(", "); + } + typeString.append(classifierName); + firstParameter = false; + } + } + } + return typeString.toString(); + } +} |