Bug 191504 - Use a factoryMethod in a EcoreEnvironment constructor
Summary: Use a factoryMethod in a EcoreEnvironment constructor
Status: CLOSED FIXED
Alias: None
Product: OCL
Classification: Modeling
Component: Core (show other bugs)
Version: 1.1.0   Edit
Hardware: PC Windows XP
: P3 enhancement (vote)
Target Milestone: M4   Edit
Assignee: Adolfo Sanchez-Barbudo Herrera CLA
QA Contact:
URL:
Whiteboard:
Keywords: contributed
Depends on:
Blocks: 211185
  Show dependency tree
 
Reported: 2007-06-07 11:35 EDT by Adolfo Sanchez-Barbudo Herrera CLA
Modified: 2013-05-17 15:24 EDT (History)
2 users (show)

See Also:


Attachments
Patch for resolve the bug in Ecore & UML implementations (3.15 KB, patch)
2007-11-28 04:42 EST, Adolfo Sanchez-Barbudo Herrera CLA
wayne.beaton: iplog+
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Adolfo Sanchez-Barbudo Herrera CLA 2007-06-07 11:35:54 EDT
In the EcoreEnvironment( Registry, Resource) contructor, typeResolver would be better created via a factory method:

protected EcoreEnvironment(EPackage.Registry reg, Resource resource) {
      this(reg);
		
      typeResolver = createTypeResolver(resource);	
}


the factoryMethod:

protected TypeResolver<EClassifier, EOperation, EStructuralFeature> createTypeResolver(Resource resource) {
		return new TypeResolverImpl(this, resource);
	}
Comment 1 Adolfo Sanchez-Barbudo Herrera CLA 2007-11-28 04:42:24 EST
Created attachment 83954 [details]
Patch for resolve the bug in Ecore & UML implementations
Comment 2 Ed Willink CLA 2007-11-29 16:23:04 EST
[EcoreEnvironment offers three constructors. Only two of these allow the TypeResolverImpl to be overridden in derived environments. Overriding is essential to support an alternate policy for resolution of orphan types as required by QVT.]

AbstractTypeResolverImpl(env) redirects to AbstractTypeResolverImpl(env, null)
so it would make sense if createTypeResolver() was changed to createTypeResolver(resource).

Suggest deprecated rewrite of existing method to redirect

protected TypeResolver<...> createTypeResolver() {
	return createTypeResolver(null); 
}

and new overrideable

protected TypeResolver<...> createTypeResolver(Resource resource) {
	return new TypeResolverImpl(this, resource); 
}

so that derivations need only override the new method to affect all 3 construction paths.
Comment 3 Christian Damus CLA 2007-11-29 19:01:23 EST
Committed Adolfo's patch with the changes suggested by Ed.
Additionally removed the lazy initialization of the type resolver in the accessor because it is now always created on construction.
Existing clients that overrode the original createTypeResolver() method should see no change in behaviour, except that it is created now on construction, instead of lazily.
Comment 4 Ed Willink CLA 2007-11-30 02:44:53 EST
Ta.

Just a suggestion: It looks as if the typeResolver member and all bar the createTypeResolver implementation could be promoted to AbstractEnvironment.
Comment 5 Adolfo Sanchez-Barbudo Herrera CLA 2007-12-03 08:49:09 EST
Yes, perhaps the TypeResolver should be promoted to AbstractEnvironment, but since the creation of the resolver depends on a specific implementation, an abstract method should be defined in the AbstractEnvironment, so UML & Ecore implementation should override it.

P.D: Why am i "assigned to" in the bug ? -> lol





Comment 6 Christian Damus CLA 2007-12-06 11:25:05 EST
Adolfo, you are the assignee because that is part of the process in the Modeling project (and, I think, Eclipse generally) for attributing contributions to non-committers.  One of these days, people like Ed will be seeing themselves assigned bugs that were long since committed and resolved, that they contributed.

I can't create a new abstract method in the AbstractEnvironment class because that is an incompatible API change, and I wouldn't be able to provide a useful implementation.
Comment 7 Christian Damus CLA 2007-12-06 13:48:54 EST
Fixed in the MDT OCL 1.2.0 I200712061132 build.
Comment 8 Nick Boldt CLA 2008-01-28 16:39:23 EST
Move to verified as per bug 206558.
Comment 9 Ed Willink CLA 2011-05-27 02:38:41 EDT
Closing after over a year in verified state.
Comment 10 Ed Willink CLA 2011-05-27 02:41:11 EDT
Closing after over a year in verified state.