Bug 233843 - Genmodel should allow to configure how Interface and Implementation names of classes are computed
Summary: Genmodel should allow to configure how Interface and Implementation names of ...
Status: VERIFIED FIXED
Alias: None
Product: EMF
Classification: Modeling
Component: Tools (show other bugs)
Version: unspecified   Edit
Hardware: PC Mac OS X - Carbon (unsup.)
: P3 enhancement (vote)
Target Milestone: Past   Edit
Assignee: Dave Steinberg CLA
QA Contact:
URL:
Whiteboard:
Keywords: contributed
: 147380 (view as bug list)
Depends on:
Blocks:
 
Reported: 2008-05-25 07:41 EDT by Thomas Schindl CLA
Modified: 2009-06-25 02:58 EDT (History)
11 users (show)

See Also:
Ed.Merks: galileo+


Attachments
patch (29.36 KB, patch)
2008-05-25 09:44 EDT, Thomas Schindl CLA
davidms: iplog+
Details | Diff
My first cut at improving the patch (31.38 KB, patch)
2008-08-25 21:50 EDT, Dave Steinberg CLA
no flags Details | Diff
Patch take 2 (67.78 KB, patch)
2008-08-25 23:27 EDT, Dave Steinberg CLA
no flags Details | Diff
Patch take 3 (79.75 KB, patch)
2008-08-25 23:59 EDT, Dave Steinberg CLA
no flags Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Thomas Schindl CLA 2008-05-25 07:41:14 EDT
Eclipse-Projects but also other companies have codeing guidelines where e.g. the interface name always starts with an "I" and the real implementation doesn't contain an "Impl" but is simply the name of the class.
Comment 1 Ed Merks CLA 2008-05-25 08:04:27 EDT
I'll mark it as an enhancement request.
Comment 2 Thomas Schindl CLA 2008-05-25 09:44:39 EDT
Created attachment 101878 [details]
patch
Comment 3 Dave Steinberg CLA 2008-05-26 21:25:55 EDT
I'd really like to do this in EMF 2.5.  I'm not a big fan of the "I" pattern, but I do think we should support it for those who are.

Notice that we don't treat all classes equally.  Many, such as the item provider implementations don't get the "Impl" suffix, since there's no type-specific interface that they're implementing.  I think I like Tom's approach, which doesn't affect those ones, but it would be more general and flexible if we provided another attribute for them.  

The patch doesn't apply the class name pattern to the resource and resource factory implementation.  I haven't checked exhaustively to ensure everything else is correct.
Comment 4 Ed Merks CLA 2008-05-27 07:27:44 EDT
I can't stand the I naming convention.  I think it's ridiculous that we deal with things like IFile everywhere and never see a File. The human readable name is internal and the butchered name is the API.  But hey, that's just  my opinion.

This is clearly an API change and needs to wait.  I know Kenn generates resource interfaces but we don't, so we should coordinate that properly.  I don't really want to anticipate yet more ways that folks might want to butcher their names.  Someone who wants that can help provide it the way Tom has.
Comment 5 Dave Steinberg CLA 2008-07-20 21:23:46 EDT
*** Bug 147380 has been marked as a duplicate of this bug. ***
Comment 6 Thomas Schindl CLA 2008-08-07 12:19:18 EDT
Dave is there something I can do to bring this forward the earlier in the release cycle we get this in the better we can test and make 100% sure nothing gets broken. If you instruct me where to look at for things that you think have to be changed I can work on it.
Comment 7 Dave Steinberg CLA 2008-08-07 14:17:09 EDT
Tom, I think it just needs for me to look carefully.  I can't conjure a list of things off the top of my head, unfortunately.  That's more Ed's style.  ;-)

Given that we'll be building M1 tomorrow, are you comfortable with it being in M2?
Comment 8 Thomas Schindl CLA 2008-08-08 02:53:58 EDT
Dave, M2 is fine for me. Maybe we need this feature for e4 where the workbench model is created with EMF and then we can ensure that the interfaces start with an I (though I'm also not a favorite) if we still want that to happen. I've CC'ed Boris and Eric who are working with me on this e4 topic.
Comment 9 Dave Steinberg CLA 2008-08-25 21:50:17 EDT
Created attachment 110877 [details]
My first cut at improving the patch

Here's a first cut at improving the patch, just so you can see that I'm working on this.  ;-)

I started with Tom's patch and found and addressed a bunch of issues.

1. Fixed problems with supppressed interfaces and/or metadata. For example, suppresing interfaces caused some names to go back to the basic, unaltered names, but others not. I made it consistent: the patterns are only used when interfaces aren't suppressed.
2. Introduced some new API to get at the basic names, unaltered by an interface name pattern: GenBaseImpl.getInterfaceName(), GenPackage.getFactoryName(), and GenPackage.getBasicPackageName().
3. Included resource and resource factory. They also use the class naming pattern. I think it would be nicer if they also switched to the basic name when interfaces are suppressed, but I think it's too late for that kind of change.
4. Added the new GenModel attributes to GenModelImpl.reconcileSettings() so they'll carry over when a model is reloaded.
5. Changed category for the attributes (Model Feature -> Model) and improved (hopefully?) their descriptions.
6. Fixed a previously existing problem with GenPackageImpl.getQualifiedEFactoryInstanceAccessor() and getQualifiedEFactoryInternalInstanceAccessor(). I noticed that the former was doing unneccessary casting when both interfaces and metadata are suppressed.

I've done some more hunting to catch more uses of interface names inside other names (e.g. <Interface>StackFrame, get<PackageInterface>Package, etc.), which don't really work so nicely with non-default interface names, and replacing them by the basic name (using the new APIs mentioned above). I'm still testing that and should have a new patch tomorrow morning.

I'm still not thrilled with the descriptions, so any input there would be appreciated. Also, I wish the properties appeared next to each other, but alas, alphabetical ordering strikes again.

I really don't like the name getBasicPackageName(), but unfortunately getPackageName() is already taken...and it does exactly the same thing as getName().  Rage!  So, again, better ideas would be appreciated. My other ideas, which I liked even less, were getSimplePackageName(), getPackageUnsplitName() (as in, when the interface/implementation split is disabled).
Comment 10 Dave Steinberg CLA 2008-08-25 23:27:35 EDT
Created attachment 110884 [details]
Patch take 2

Here's my second take. I've switched all the questionable uses of GenPackage.getPackageInterfaceName() and getFactoryInterfaceName() that I could find to getBasicPackageName() and getFactoryName(). I also introduced getUncapPackageName() and getUncapFactoryName() and deprecated getUncapPackageInterfaceName() and getUncapFactoryInterfaceName(), switching all uses of them over to the new ones.

This definitely seems better to me.

In addition to the name/description issues I mentioned in the previous comment, there's still another thing I'm considering. One more patch to come...
Comment 11 Dave Steinberg CLA 2008-08-25 23:59:00 EDT
Created attachment 110885 [details]
Patch take 3

Here's one last refinement tonight. It's just a small change: I cleared the default values for interfaceNamePattern and classNamePattern (they were "{0}" and "{0}Impl"), and made GenBaseImpl.getInterfaceName() and getClassName() use those patterns by default if none are specified.

I think this approach makes things a little nicer looking, initially, and a little more resilliant.  I prefer not to have weird patterns like that staring new users in the face. Also, if someone clears these properties (and doesn't know about the magic reset button), they can still generate working code, which is nice. The other approach is a little more straightforward, though, so if someone prefers it, I'm not totally committed.
Comment 12 Dave Steinberg CLA 2008-08-26 00:01:26 EDT
Oh, for people who don't like to read lots of comments, just go ahead and look at my last patch, and take note of the last two paragraphs of comment 9.  ;-)
Comment 13 Ed Merks CLA 2008-08-27 13:58:14 EDT
Dave,

It looks good.
Comment 14 Dave Steinberg CLA 2008-08-27 14:37:55 EDT
Ed,

Thanks, but any comments on my naming/description questions (comment 9)?  Any preference regarding the default values for interfaceNamePattern and classNamePattern (comment 11)?
Comment 15 Dave Steinberg CLA 2008-08-27 16:01:59 EDT
Based on feedback I received from Ed, I'm planning to change the descriptions to these:

  Pattern for deriving interface names from model element names ("{0}" by default)
  Pattern for deriving class names from model element names ("{0}Impl" by default)
  
Also, I'm going to change the method name getBasicPackageName() to getEffectivePackageName().

I'll commit this before the end of the week.  I'm going to be away for the next two weeks, and I promised this would be in M2.

Any comments, Tom?
Comment 16 Thomas Schindl CLA 2008-08-27 16:12:30 EDT
I didn't had time to take a look because I'm so loaded with work, sorry.
Comment 17 Dave Steinberg CLA 2008-08-27 16:28:45 EDT
No problem Tom! We all know how that feels.

I think I'll go ahead and commit the patch this week and if you find any issues when you try to start using it, we can address them then.
Comment 18 Thomas Schindl CLA 2008-08-27 16:39:48 EDT
+1, I'll give it a spin when the changes are in
Comment 19 Dave Steinberg CLA 2008-08-29 14:34:58 EDT
The enhancement is in CVS for EMF 2.5.

In the end, I decided to stick with getBasicPackageName(), since the existing "effective" methods all seem to refer to what's in effect when taking GenModel properties into consideration, and this is the *opposite* of that.  The basic package name is just the package prefix with "Package" appended.  Depending on GenModel.suppressInterfaces, GenModel.suppressEMFMetaData, and GenModel.interfaceNamePattern, it might be changed to something else.
Comment 20 Nick Boldt CLA 2008-09-02 20:14:55 EDT
Fix available in HEAD: 2.5.0.I200809021800.
Comment 21 Dave Steinberg CLA 2009-06-25 02:58:01 EDT
Fix available in HEAD: 2.5.0 (R200906151043).