Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
Bug 232734 - defining toString as an operation gives multiple toString implimentations
Summary: defining toString as an operation gives multiple toString implimentations
Status: VERIFIED FIXED
Alias: None
Product: EMF
Classification: Modeling
Component: Core (show other bugs)
Version: 2.4.0   Edit
Hardware: PC Linux
: P3 normal (vote)
Target Milestone: ---   Edit
Assignee: Dave Steinberg CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks: 204200
  Show dependency tree
 
Reported: 2008-05-19 05:01 EDT by gary s thompson CLA
Modified: 2008-05-20 13:47 EDT (History)
2 users (show)

See Also:


Attachments
Guard the generation of the toString method. (3.74 KB, patch)
2008-05-20 09:01 EDT, Ed Merks CLA
no flags Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description gary s thompson CLA 2008-05-19 05:01:36 EDT
If a toString operation is defined in eCore as an operation the resulting generated java class contains two toString operations. On each subsequent run of the generator a further toString method is generated on top of those already present. The extra toString operations have the form produced by the emf toString template as shown below.

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @model annotation="http://www.eclipse.org/emf/2002/GenModel body='java.lang.String result = null;\n\n\n\nreturn result;'"
	 * @generated
	 */ 
	public  String toString(){
		java.lang.String result = null;
		
		
		
		return result;
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */ 
	public  String toString(){
		if (eIsProxy()) return super.toString();

		StringBuffer result = new StringBuffer(super.toString());
		result.append(" (value: ");
		result.append(value);
		result.append(')');
		return result.toString();
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */ 
	public  String toString(){
		if (eIsProxy()) return super.toString();

		StringBuffer result = new StringBuffer(super.toString());
		result.append(" (value: ");
		result.append(value);
		result.append(')');
		return result.toString();
	}

	/**
	 * <!-- begin-user-doc -->
	 * <!-- end-user-doc -->
	 * @generated
	 */ 
	public  String toString(){
... etc
Comment 1 Ed Merks CLA 2008-05-20 09:01:56 EDT
Created attachment 101030 [details]
Guard the generation of the toString method.
Comment 2 Ed Merks CLA 2008-05-20 09:03:09 EDT
The best way to fix this is to add a guard.  Does this look okay?
Comment 3 Dave Steinberg CLA 2008-05-20 10:33:44 EDT
This looks good to me. 
Comment 4 Ed Merks CLA 2008-05-20 10:42:01 EDT
A fix has been committed to CVS for 2.4.  (Kenn, this affects your compiled Class.java.)
Comment 5 Nick Boldt CLA 2008-05-20 13:47:21 EDT
Fix available in HEAD: 2.4.0RC1 (S200805201049).