svn commit: r13246 - branches/gsoc2007/b00__1/model-euml/src/org/argouml/model/euml/UMLUtil.java

[email protected]
Newsgroups gmane.comp.lang.uml.argouml.cvs
Message-ID <[email protected]>
Author: b00__1
Date: 2007-08-05 05:21:44-0700
New Revision: 13246

Modified:
   branches/gsoc2007/b00__1/model-euml/src/org/argouml/model/euml/UMLUtil.java

Log:
Add a description method for UML elements

Modified: branches/gsoc2007/b00__1/model-euml/src/org/argouml/model/euml/UMLUtil.java
Url: http://argouml.tigris.org/source/browse/argouml/branches/gsoc2007/b00__1/model-euml/src/org/argouml/model/euml/UMLUtil.java?view=diff&rev=13246&p1=branches/gsoc2007/b00__1/model-euml/src/org/argouml/model/euml/UMLUtil.java&p2=branches/gsoc2007/b00__1/model-euml/src/org/argouml/model/euml/UMLUtil.java&r1=13245&r2=13246
==============================================================================
--- branches/gsoc2007/b00__1/model-euml/src/org/argouml/model/euml/UMLUtil.java	(original)
+++ branches/gsoc2007/b00__1/model-euml/src/org/argouml/model/euml/UMLUtil.java	2007-08-05 05:21:44-0700
@@ -34,6 +34,7 @@
 import org.eclipse.uml2.uml.Association;
 import org.eclipse.uml2.uml.AssociationClass;
 import org.eclipse.uml2.uml.Element;
+import org.eclipse.uml2.uml.NamedElement;
 import org.eclipse.uml2.uml.Operation;
 import org.eclipse.uml2.uml.Property;
 import org.eclipse.uml2.uml.Type;
@@ -117,5 +118,43 @@
         }
         return null;
     }
+    
+    /**
+     * Returns information about an Object.
+     * <p>
+     * If it's an Element it returns its metaclass name, and if it's a
+     * NamedElement it appends its name.
+     * 
+     * @param o
+     *                The object
+     * @return the String description
+     */
+    public static String toString(Object o) {
+        if (o == null) {
+            return "null"; //$NON-NLS-1$
+        }
+        if (!(o instanceof Element)) {
+            return o.toString();
+        }
+        
+        StringBuilder sb = new StringBuilder("'"); //$NON-NLS-1$
+        boolean named = false;
+        
+        if (o instanceof NamedElement && ((NamedElement) o).getName() != null
+                && !((NamedElement) o).getName().equals("")) { //$NON-NLS-1$
+            named = true;
+            sb.append(((NamedElement) o).getName() + " ["); //$NON-NLS-1$
+        }
+        
+        sb.append(((Element) o).eClass().getName());
+        
+        if (named) {
+            sb.append("]"); //$NON-NLS-1$
+        }
+        
+        sb.append("'"); //$NON-NLS-1$
+        
+        return sb.toString();
+    }
 
 }
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.