Home » Modeling » OCL » Re: EMF Validation OCLParser EcoreEnvironment.findPackage and empty packages.
Re: EMF Validation OCLParser EcoreEnvironment.findPackage and empty packages. [message #45956] |
Wed, 05 December 2007 08:47  |
Eclipse User |
|
|
|
Originally posted by: cdamus.ca.ibm.com
Hi, Loïc,
This is really an OCL question, hence I am replying to that newsgroup.
The EcoreEnvironment tries to be more robust. If it can't find the
referenced package by the nesting structure, then it attempts to find an
EPackage whose nsPrefix matches what EMF produces by default (being simply
a dot-separated list of the package names). For example, in resolving
a::b::c, if the "a" package can't be found, the environment tries looking
for a package whose nsPrefix is a.b.c.
Another thing you can do is to initialize your EcoreEnvironment with a
default package, specifying the root package that isn't registered. Then,
package name references that are relative to this root package (or even
absolute names, I think) should be registered.
Otherwise, if a package cannot be found, I don't see how OCL can assume that
the reason is an empty root package that isn't registered, and proceed by
looking up the child. It can easily get entirely the wrong package.
Perhaps you should follow this enhancement request:
https://bugs.eclipse.org/bugs/show_bug.cgi?id=142856
and maybe even contribute a patch!
Cheers,
Christian
Loïc Quéran wrote:
> Empty packages are not generated by EMF. See
> http://dev.eclipse.org/newslists/news.eclipse.tools.emf/msg1 1984.html
> for an explanation on this.
>
> org.eclipse.ocl.ecore.EcoreEnvironment.findPackage(List<String >
> packageNames, EPackage.Registry registry) explicitely searches root
> level packages (line 558):
>
> // only consider root-level packages when searching by name
> if ((ePackage.getESuperPackage() == null)
> && EcoreForeignMethods.isNamed(name, ePackage))
> {
> ...
> }
>
> Packages which are not generated won't be registered, hence won't be
> found.
>
> Unless I miss something, EMF Validation will not parse OCL files
> correctly if the "target" ecore's top level package is empty.
>
> Have I missed something ? Shouldn't the EcoreEnvironment algorithm be
> somewhat more robust ?
>
> Loïc
|
|
| |
Re: EMF Validation OCLParser EcoreEnvironment.findPackage and empty packages. [message #46059 is a reply to message #45956] |
Wed, 05 December 2007 12:11   |
Eclipse User |
|
|
|
Hi Christian,
My suggestion is below:
Cheers,
Loïc
Christian W. Damus a écrit :
> Hi, Loïc,
>
> This is really an OCL question, hence I am replying to that newsgroup.
>
> The EcoreEnvironment tries to be more robust. If it can't find the
> referenced package by the nesting structure, then it attempts to find an
> EPackage whose nsPrefix matches what EMF produces by default (being simply
> a dot-separated list of the package names). For example, in resolving
> a::b::c, if the "a" package can't be found, the environment tries looking
> for a package whose nsPrefix is a.b.c.
>
> Another thing you can do is to initialize your EcoreEnvironment with a
> default package, specifying the root package that isn't registered. Then,
> package name references that are relative to this root package (or even
> absolute names, I think) should be registered.
>
> Otherwise, if a package cannot be found, I don't see how OCL can assume that
> the reason is an empty root package that isn't registered, and proceed by
> looking up the child. It can easily get entirely the wrong package.
>
> Perhaps you should follow this enhancement request:
>
> https://bugs.eclipse.org/bugs/show_bug.cgi?id=142856
>
> and maybe even contribute a patch!
static public EPackage findPackage(List<String> packageNames,
EPackage.Registry registry) {
if (packageNames.isEmpty()) {
return null;
}
if (OCL_PACKAGES.containsKey(packageNames)) {
return OCL_PACKAGES.get(packageNames);
}
// Use a bottom up strategy to avoid ungenerated top-level packages.
String packageName = packageNames.get(packageNames.size() - 1);
boolean isRightPackage = false;
for (Object next : registry.values()) {
if (next instanceof EPackage) {
EPackage ePackage = (EPackage) next;
if (EcoreForeignMethods.isNamed(packageName, ePackage))
{
isRightPackage = isPackageInHierarchy(ePackage,
packageNames.subList(0, packageNames.size() - 1));
}
if (isRightPackage) return ePackage;
}
}
return findPackageByNSPrefix(packageNames, registry);
}
/** Returns true if given EPackage's super packages have names that
match the names in packageNames, false otherwise.
* Name matching is delegated to {@link
EcoreForeignMethods#isNamed(String, org.eclipse.emf.ecore.ENamedElement)}.
* @param ePackage A standard EMF EPackage.
* @param packageNames A list of package names, example ["org",
"eclipse", "ocl"]
* @return As specified above.
*/
protected static boolean isPackageInHierarchy(EPackage ePackage,
List<String> packageNames)
{
if (ePackage != null && packageNames != null && packageNames.size()
> 0)
{
String fullyQualifiedPackageName = null;
for(EClassifier classifier : ePackage.getEClassifiers())
{
fullyQualifiedPackageName =
classifier.getInstanceClass().getPackage().getName();
break;
}
if (fullyQualifiedPackageName != null)
{
StringTokenizer tokenizer = new
StringTokenizer(fullyQualifiedPackageName, ".");
boolean hasFailed = false;
for (String packageName : packageNames)
{
if (tokenizer.hasMoreTokens())
{
hasFailed = !OCLParser.equalName(packageName,
tokenizer.nextToken());
}
else
{
hasFailed = true;
}
if (hasFailed) return false;
}
return true;
}
}
return false;
}
>
> Cheers,
>
> Christian
>
> Loïc Quéran wrote:
>
>> Empty packages are not generated by EMF. See
>> http://dev.eclipse.org/newslists/news.eclipse.tools.emf/msg1 1984.html
>> for an explanation on this.
>>
>> org.eclipse.ocl.ecore.EcoreEnvironment.findPackage(List<String >
>> packageNames, EPackage.Registry registry) explicitely searches root
>> level packages (line 558):
>>
>> // only consider root-level packages when searching by name
>> if ((ePackage.getESuperPackage() == null)
>> && EcoreForeignMethods.isNamed(name, ePackage))
>> {
>> ...
>> }
>>
>> Packages which are not generated won't be registered, hence won't be
>> found.
>>
>> Unless I miss something, EMF Validation will not parse OCL files
>> correctly if the "target" ecore's top level package is empty.
>>
>> Have I missed something ? Shouldn't the EcoreEnvironment algorithm be
>> somewhat more robust ?
>>
>> Loïc
>
|
|
|
Re: EMF Validation OCLParser EcoreEnvironment.findPackage and empty packages. [message #46089 is a reply to message #46059] |
Wed, 05 December 2007 12:41   |
Eclipse User |
|
|
|
Originally posted by: cdamus.ca.ibm.com
Hi, Loïc,
This looks intriguing. Would you mind raising an enhancement request
https://bugs.eclipse.org/bugs/enter_bug.cgi?product=MDT& version=1.1.0&component=OCL&severity=enhancement
and attaching your patch? This ensures that we get the proper attribution
and IP tracking required by Eclipse. Then, we can take a closer look.
Thanks,
Christian
Loïc Quéran wrote:
> Hi Christian,
>
> My suggestion is below:
>
> Cheers,
>
> Loïc
>
-----8<-----
>
> static public EPackage findPackage(List<String> packageNames,
> EPackage.Registry registry) {
> if (packageNames.isEmpty()) {
> return null;
> }
>
> if (OCL_PACKAGES.containsKey(packageNames)) {
> return OCL_PACKAGES.get(packageNames);
> }
>
> // Use a bottom up strategy to avoid ungenerated top-level packages.
> String packageName = packageNames.get(packageNames.size() - 1);
> boolean isRightPackage = false;
> for (Object next : registry.values()) {
> if (next instanceof EPackage) {
> EPackage ePackage = (EPackage) next;
> if (EcoreForeignMethods.isNamed(packageName, ePackage))
> {
> isRightPackage = isPackageInHierarchy(ePackage,
> packageNames.subList(0, packageNames.size() - 1));
> }
> if (isRightPackage) return ePackage;
> }
> }
>
> return findPackageByNSPrefix(packageNames, registry);
> }
>
>
>
>
>
> /** Returns true if given EPackage's super packages have names that
> match the names in packageNames, false otherwise.
> * Name matching is delegated to {@link
> EcoreForeignMethods#isNamed(String, org.eclipse.emf.ecore.ENamedElement)}.
> * @param ePackage A standard EMF EPackage.
> * @param packageNames A list of package names, example ["org",
> "eclipse", "ocl"]
> * @return As specified above.
> */
> protected static boolean isPackageInHierarchy(EPackage ePackage,
> List<String> packageNames)
> {
> if (ePackage != null && packageNames != null && packageNames.size()
> > 0)
> {
> String fullyQualifiedPackageName = null;
> for(EClassifier classifier : ePackage.getEClassifiers())
> {
> fullyQualifiedPackageName =
> classifier.getInstanceClass().getPackage().getName();
> break;
> }
> if (fullyQualifiedPackageName != null)
> {
> StringTokenizer tokenizer = new
> StringTokenizer(fullyQualifiedPackageName, ".");
> boolean hasFailed = false;
> for (String packageName : packageNames)
> {
> if (tokenizer.hasMoreTokens())
> {
> hasFailed = !OCLParser.equalName(packageName,
> tokenizer.nextToken());
> }
> else
> {
> hasFailed = true;
> }
> if (hasFailed) return false;
> }
> return true;
> }
> }
> return false;
> }
>
----->8-----
|
|
|
Re: EMF Validation OCLParser EcoreEnvironment.findPackage and empty packages. [message #46118 is a reply to message #46089] |
Thu, 06 December 2007 03:44  |
Eclipse User |
|
|
|
Hi Christian,
https://bugs.eclipse.org/bugs/show_bug.cgi?id=212120
Intriguing is ... intriguing !
Cheers,
Loïc
Christian W. Damus a écrit :
> Hi, Loïc,
>
> This looks intriguing. Would you mind raising an enhancement request
>
> https://bugs.eclipse.org/bugs/enter_bug.cgi?product=MDT& version=1.1.0&component=OCL&severity=enhancement
>
> and attaching your patch? This ensures that we get the proper attribution
> and IP tracking required by Eclipse. Then, we can take a closer look.
>
> Thanks,
>
> Christian
>
>
> Loïc Quéran wrote:
>
>> Hi Christian,
>>
>> My suggestion is below:
>>
>> Cheers,
>>
>> Loïc
>>
>
> -----8<-----
>
>> static public EPackage findPackage(List<String> packageNames,
>> EPackage.Registry registry) {
>> if (packageNames.isEmpty()) {
>> return null;
>> }
>>
>> if (OCL_PACKAGES.containsKey(packageNames)) {
>> return OCL_PACKAGES.get(packageNames);
>> }
>>
>> // Use a bottom up strategy to avoid ungenerated top-level packages.
>> String packageName = packageNames.get(packageNames.size() - 1);
>> boolean isRightPackage = false;
>> for (Object next : registry.values()) {
>> if (next instanceof EPackage) {
>> EPackage ePackage = (EPackage) next;
>> if (EcoreForeignMethods.isNamed(packageName, ePackage))
>> {
>> isRightPackage = isPackageInHierarchy(ePackage,
>> packageNames.subList(0, packageNames.size() - 1));
>> }
>> if (isRightPackage) return ePackage;
>> }
>> }
>>
>> return findPackageByNSPrefix(packageNames, registry);
>> }
>>
>>
>>
>>
>>
>> /** Returns true if given EPackage's super packages have names that
>> match the names in packageNames, false otherwise.
>> * Name matching is delegated to {@link
>> EcoreForeignMethods#isNamed(String, org.eclipse.emf.ecore.ENamedElement)}.
>> * @param ePackage A standard EMF EPackage.
>> * @param packageNames A list of package names, example ["org",
>> "eclipse", "ocl"]
>> * @return As specified above.
>> */
>> protected static boolean isPackageInHierarchy(EPackage ePackage,
>> List<String> packageNames)
>> {
>> if (ePackage != null && packageNames != null && packageNames.size()
>> > 0)
>> {
>> String fullyQualifiedPackageName = null;
>> for(EClassifier classifier : ePackage.getEClassifiers())
>> {
>> fullyQualifiedPackageName =
>> classifier.getInstanceClass().getPackage().getName();
>> break;
>> }
>> if (fullyQualifiedPackageName != null)
>> {
>> StringTokenizer tokenizer = new
>> StringTokenizer(fullyQualifiedPackageName, ".");
>> boolean hasFailed = false;
>> for (String packageName : packageNames)
>> {
>> if (tokenizer.hasMoreTokens())
>> {
>> hasFailed = !OCLParser.equalName(packageName,
>> tokenizer.nextToken());
>> }
>> else
>> {
>> hasFailed = true;
>> }
>> if (hasFailed) return false;
>> }
>> return true;
>> }
>> }
>> return false;
>> }
>>
>
> ----->8-----
|
|
|
Goto Forum:
Current Time: Thu May 08 20:46:17 EDT 2025
Powered by FUDForum. Page generated in 0.03902 seconds
|