Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » EMF "Technology" (Ecore Tools, EMFatic, etc)  » How to create a copy of an EObject with non-null Resource
How to create a copy of an EObject with non-null Resource [message #122952] Sat, 24 May 2008 16:15 Go to next message
Lars Schneider is currently offline Lars SchneiderFriend
Messages: 50
Registered: July 2009
Member
Hi,
I have a little problem using EcoreUtil.copy(EObject) because the
eResource() of that copy returns null.

More precisely I want to copy the root of a model, change it and compare
it to the original with EMF Compare. I think the following code snippet
explains it best:

//...
EObject copy = EcoreUtil.copy(original);
Transformation trans = new Transformation(copy);
trans.transform(); // changes copy
MatchModel match = null;
try {
match = MatchService.doMatch(original, copy
Collections.<String, Object> emptyMap());
} catch (InterruptedException e) {
e.printStackTrace();
}
//...

The problem is that doMatch(...) ends up in a NullPointerException
because the resource of copy is null. Does anyone have an idea how to
solve this problem? I think I can either set the resource manually or
get another IMatchEngine implementation. But I don't know how to.
Lars
Re: How to create a copy of an EObject with non-null Resource [message #122955 is a reply to message #122952] Sat, 24 May 2008 16:28 Go to previous messageGo to next message
Lars Schneider is currently offline Lars SchneiderFriend
Messages: 50
Registered: July 2009
Member
I think this problem is better of in this newsgroup.

> Hi,
> I have a little problem using EcoreUtil.copy(EObject) because the
> eResource() of that copy returns null.
>
> More precisely I want to copy the root of a model, change it and compare
> it to the original with EMF Compare. I think the following code snippet
> explains it best:
>
> //...
> EObject copy = EcoreUtil.copy(original);
> Transformation trans = new Transformation(copy);
> trans.transform(); // changes copy
> MatchModel match = null;
> try {
> match = MatchService.doMatch(original, copy
> Collections.<String, Object> emptyMap());
> } catch (InterruptedException e) {
> e.printStackTrace();
> }
> //...
>
> The problem is that doMatch(...) ends up in a NullPointerException
> because the resource of copy is null. Does anyone have an idea how to
> solve this problem? I think I can either set the resource manually or
> get another IMatchEngine implementation. But I don't know how to.
> Lars
Re: How to create a copy of an EObject with non-null Resource [message #122958 is a reply to message #122955] Sat, 24 May 2008 16:39 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: merks.ca.ibm.com

Lars,

Ideally it would be tolerant of a null resource. You'd need to access
the resource set and create a new resource of the appropriate type to
contain the copy, i.e.,
original.eResource().getResourceSet().createResource(...).ge tContents().add(copy)...


Lars Schneider wrote:
> I think this problem is better of in this newsgroup.
>
>> Hi,
>> I have a little problem using EcoreUtil.copy(EObject) because the
>> eResource() of that copy returns null.
>>
>> More precisely I want to copy the root of a model, change it and
>> compare it to the original with EMF Compare. I think the following
>> code snippet explains it best:
>>
>> //...
>> EObject copy = EcoreUtil.copy(original);
>> Transformation trans = new Transformation(copy);
>> trans.transform(); // changes copy
>> MatchModel match = null;
>> try {
>> match = MatchService.doMatch(original, copy
>> Collections.<String, Object> emptyMap());
>> } catch (InterruptedException e) {
>> e.printStackTrace();
>> }
>> //...
>>
>> The problem is that doMatch(...) ends up in a NullPointerException
>> because the resource of copy is null. Does anyone have an idea how to
>> solve this problem? I think I can either set the resource manually or
>> get another IMatchEngine implementation. But I don't know how to.
>> Lars
Re: How to create a copy of an EObject with non-null Resource [message #122961 is a reply to message #122955] Sun, 25 May 2008 18:23 Go to previous messageGo to next message
Cedric Brun is currently offline Cedric BrunFriend
Messages: 431
Registered: July 2009
Senior Member
Hi Lars,

What EMF Compare build are you using ? The RC1 build should have fixed this
NPE (bug 230347 - see the release
notes :http://www.eclipse.org/modeling/emft/news/relnotes.php?proj ect=compare&version=0.8.0RC1 )

You should not have to provide your own match engine for such a thing :)

Cédric


Lars Schneider wrote:

> I think this problem is better of in this newsgroup.
>
>> Hi,
>> I have a little problem using EcoreUtil.copy(EObject) because the
>> eResource() of that copy returns null.
>>
>> More precisely I want to copy the root of a model, change it and compare
>> it to the original with EMF Compare. I think the following code snippet
>> explains it best:
>>
>> //...
>> EObject copy = EcoreUtil.copy(original);
>> Transformation trans = new Transformation(copy);
>> trans.transform(); // changes copy
>> MatchModel match = null;
>> try {
>> match = MatchService.doMatch(original, copy
>> Collections.<String, Object> emptyMap());
>> } catch (InterruptedException e) {
>> e.printStackTrace();
>> }
>> //...
>>
>> The problem is that doMatch(...) ends up in a NullPointerException
>> because the resource of copy is null. Does anyone have an idea how to
>> solve this problem? I think I can either set the resource manually or
>> get another IMatchEngine implementation. But I don't know how to.
>> Lars


http://cedric.brun.io news and articles on eclipse and eclipse modeling.
Re: How to create a copy of an EObject with non-null Resource [message #122963 is a reply to message #122961] Mon, 26 May 2008 07:22 Go to previous messageGo to next message
Laurent Goubet is currently offline Laurent GoubetFriend
Messages: 1902
Registered: July 2009
Senior Member
This is a multi-part message in MIME format.
--------------070501080608090002050601
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit

Lars,

As Cédric mentionned, the latest builds should be tolerant to null
resources, though since you're using EMF Compare you could also take a
look at ModelUtils#createResource() and ModelUtils#attachResource()
which we mainly use in our unit tests to copy EObjects and compare them
to one another.

Laurent Goubet
Obeo

Cédric brun a écrit :
> Hi Lars,
>
> What EMF Compare build are you using ? The RC1 build should have fixed this
> NPE (bug 230347 - see the release
> notes :http://www.eclipse.org/modeling/emft/news/relnotes.php?proj ect=compare&version=0.8.0RC1 )
>
> You should not have to provide your own match engine for such a thing :)
>
> Cédric
>
>
> Lars Schneider wrote:
>
>> I think this problem is better of in this newsgroup.
>>
>>> Hi,
>>> I have a little problem using EcoreUtil.copy(EObject) because the
>>> eResource() of that copy returns null.
>>>
>>> More precisely I want to copy the root of a model, change it and compare
>>> it to the original with EMF Compare. I think the following code snippet
>>> explains it best:
>>>
>>> //...
>>> EObject copy = EcoreUtil.copy(original);
>>> Transformation trans = new Transformation(copy);
>>> trans.transform(); // changes copy
>>> MatchModel match = null;
>>> try {
>>> match = MatchService.doMatch(original, copy
>>> Collections.<String, Object> emptyMap());
>>> } catch (InterruptedException e) {
>>> e.printStackTrace();
>>> }
>>> //...
>>>
>>> The problem is that doMatch(...) ends up in a NullPointerException
>>> because the resource of copy is null. Does anyone have an idea how to
>>> solve this problem? I think I can either set the resource manually or
>>> get another IMatchEngine implementation. But I don't know how to.
>>> Lars
>


--------------070501080608090002050601
Content-Type: text/x-vcard; charset=utf-8;
name="laurent_goubet.vcf"
Content-Transfer-Encoding: base64
Content-Disposition: attachment;
filename="laurent_goubet.vcf"

YmVnaW46dmNhcmQNCmZuOkxhdXJlbnQgR291YmV0DQpuOkdvdWJldDtMYXVy ZW50DQpvcmc6
PGEgaHJlZj0iaHR0cDovL3d3dy5vYmVvLmZyLyI+T2JlbzwvYT4NCmVtYWls O2ludGVybmV0
OmxhdXJlbnQuZ291YmV0QG9iZW8uZnINCnVybDpodHRwOi8vd3d3Lm9iZW8u ZnINCnZlcnNp
b246Mi4xDQplbmQ6dmNhcmQNCg0K
--------------070501080608090002050601--
Re: How to create a copy of an EObject with non-null Resource [message #122970 is a reply to message #122961] Tue, 27 May 2008 12:40 Go to previous messageGo to next message
Lars Schneider is currently offline Lars SchneiderFriend
Messages: 50
Registered: July 2009
Member
Hi Cédric,

I updated to 0.8.0RC1 and still get a NullPointerException.

java.lang.NullPointerException
at
org.eclipse.emf.compare.match.engine.GenericMatchEngine.filt erUnused(GenericMatchEngine.java:1094)
at
org.eclipse.emf.compare.match.engine.GenericMatchEngine.doMa tch(GenericMatchEngine.java:907)
at
org.eclipse.emf.compare.match.engine.GenericMatchEngine.mode lMatch(GenericMatchEngine.java:331)
at
org.eclipse.emf.compare.match.service.MatchService.doMatch(M atchService.java:174)

GenericMatchEngine.doMatch calls
result = doMatch(leftRoot.eResource(), rightRoot.eResource(), monitor);
in line 331 which is obviously null if rightRoot has a null Resource.


Cédric brun wrote:
> Hi Lars,
>
> What EMF Compare build are you using ? The RC1 build should have fixed this
> NPE (bug 230347 - see the release
> notes :http://www.eclipse.org/modeling/emft/news/relnotes.php?proj ect=compare&version=0.8.0RC1 )
>
> You should not have to provide your own match engine for such a thing :)
>
> Cédric
>
>
> Lars Schneider wrote:
>
>> I think this problem is better of in this newsgroup.
>>
>>> Hi,
>>> I have a little problem using EcoreUtil.copy(EObject) because the
>>> eResource() of that copy returns null.
>>>
>>> More precisely I want to copy the root of a model, change it and compare
>>> it to the original with EMF Compare. I think the following code snippet
>>> explains it best:
>>>
>>> //...
>>> EObject copy = EcoreUtil.copy(original);
>>> Transformation trans = new Transformation(copy);
>>> trans.transform(); // changes copy
>>> MatchModel match = null;
>>> try {
>>> match = MatchService.doMatch(original, copy
>>> Collections.<String, Object> emptyMap());
>>> } catch (InterruptedException e) {
>>> e.printStackTrace();
>>> }
>>> //...
>>>
>>> The problem is that doMatch(...) ends up in a NullPointerException
>>> because the resource of copy is null. Does anyone have an idea how to
>>> solve this problem? I think I can either set the resource manually or
>>> get another IMatchEngine implementation. But I don't know how to.
>>> Lars
>
Re: How to create a copy of an EObject with non-null Resource [message #122971 is a reply to message #122970] Tue, 27 May 2008 13:01 Go to previous messageGo to next message
Lars Schneider is currently offline Lars SchneiderFriend
Messages: 50
Registered: July 2009
Member
and also with a doContentMatch I get a NullPointerException

java.lang.NullPointerException
at
org.eclipse.emf.compare.match.engine.GenericMatchEngine.hasS ameUri(GenericMatchEngine.java:1174)
at
org.eclipse.emf.compare.match.engine.GenericMatchEngine.isSi milar(GenericMatchEngine.java:593)
at
org.eclipse.emf.compare.match.engine.GenericMatchEngine.cont entMatch(GenericMatchEngine.java:252)
at
org.eclipse.emf.compare.match.service.MatchService.doContent Match(MatchService.java:118)


Lars Schneider wrote:
> Hi Cédric,
>
> I updated to 0.8.0RC1 and still get a NullPointerException.
>
> java.lang.NullPointerException
> at
> org.eclipse.emf.compare.match.engine.GenericMatchEngine.filt erUnused(GenericMatchEngine.java:1094)
>
> at
> org.eclipse.emf.compare.match.engine.GenericMatchEngine.doMa tch(GenericMatchEngine.java:907)
>
> at
> org.eclipse.emf.compare.match.engine.GenericMatchEngine.mode lMatch(GenericMatchEngine.java:331)
>
> at
> org.eclipse.emf.compare.match.service.MatchService.doMatch(M atchService.java:174)
>
>
> GenericMatchEngine.doMatch calls
> result = doMatch(leftRoot.eResource(), rightRoot.eResource(), monitor);
> in line 331 which is obviously null if rightRoot has a null Resource.
>
>
> Cédric brun wrote:
>> Hi Lars,
>>
>> What EMF Compare build are you using ? The RC1 build should have fixed
>> this
>> NPE (bug 230347 - see the release
>> notes
>> :http://www.eclipse.org/modeling/emft/news/relnotes.php?proj ect=compare&version=0.8.0RC1
>> )
>>
>> You should not have to provide your own match engine for such a thing :)
>>
>> Cédric
>>
>>
>> Lars Schneider wrote:
>>
>>> I think this problem is better of in this newsgroup.
>>>
>>>> Hi,
>>>> I have a little problem using EcoreUtil.copy(EObject) because the
>>>> eResource() of that copy returns null.
>>>>
>>>> More precisely I want to copy the root of a model, change it and
>>>> compare
>>>> it to the original with EMF Compare. I think the following code snippet
>>>> explains it best:
>>>>
>>>> //...
>>>> EObject copy = EcoreUtil.copy(original);
>>>> Transformation trans = new Transformation(copy);
>>>> trans.transform(); // changes copy
>>>> MatchModel match = null;
>>>> try {
>>>> match = MatchService.doMatch(original, copy
>>>> Collections.<String, Object> emptyMap());
>>>> } catch (InterruptedException e) {
>>>> e.printStackTrace();
>>>> }
>>>> //...
>>>>
>>>> The problem is that doMatch(...) ends up in a NullPointerException
>>>> because the resource of copy is null. Does anyone have an idea how to
>>>> solve this problem? I think I can either set the resource manually or
>>>> get another IMatchEngine implementation. But I don't know how to.
>>>> Lars
>>
Re: How to create a copy of an EObject with non-null Resource [message #123005 is a reply to message #122971] Tue, 27 May 2008 13:21 Go to previous messageGo to next message
Laurent Goubet is currently offline Laurent GoubetFriend
Messages: 1902
Registered: July 2009
Senior Member
This is a multi-part message in MIME format.
--------------050408070907090603030501
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit

Lars,

Yup, GenericMatchEngine#modelMatch() does his work on the resource and
will fail if it is null, though contentMatch() shouldn't. What puzzles
me though is that GenericMatchEngine#hasSameURI() at ligne 1174 is :
if (obj1.eResource() != null && obj2.eResource() != null)

which means you're getting an NPE since one of the two compared objects
are null, not their resources... Could you provide us with the model
you're using as input? As a side note, did you take a look at
ModelUtils#attachResource() to see if it would solve the problem?

Laurent Goubet
Obeo

Lars Schneider a écrit :
> and also with a doContentMatch I get a NullPointerException
>
> java.lang.NullPointerException
> at
> org.eclipse.emf.compare.match.engine.GenericMatchEngine.hasS ameUri(GenericMatchEngine.java:1174)
>
> at
> org.eclipse.emf.compare.match.engine.GenericMatchEngine.isSi milar(GenericMatchEngine.java:593)
>
> at
> org.eclipse.emf.compare.match.engine.GenericMatchEngine.cont entMatch(GenericMatchEngine.java:252)
>
> at
> org.eclipse.emf.compare.match.service.MatchService.doContent Match(MatchService.java:118)
>
>
>
> Lars Schneider wrote:
>> Hi Cédric,
>>
>> I updated to 0.8.0RC1 and still get a NullPointerException.
>>
>> java.lang.NullPointerException
>> at
>> org.eclipse.emf.compare.match.engine.GenericMatchEngine.filt erUnused(GenericMatchEngine.java:1094)
>>
>> at
>> org.eclipse.emf.compare.match.engine.GenericMatchEngine.doMa tch(GenericMatchEngine.java:907)
>>
>> at
>> org.eclipse.emf.compare.match.engine.GenericMatchEngine.mode lMatch(GenericMatchEngine.java:331)
>>
>> at
>> org.eclipse.emf.compare.match.service.MatchService.doMatch(M atchService.java:174)
>>
>>
>> GenericMatchEngine.doMatch calls
>> result = doMatch(leftRoot.eResource(), rightRoot.eResource(), monitor);
>> in line 331 which is obviously null if rightRoot has a null Resource.
>>
>>
>> Cédric brun wrote:
>>> Hi Lars,
>>>
>>> What EMF Compare build are you using ? The RC1 build should have
>>> fixed this
>>> NPE (bug 230347 - see the release
>>> notes
>>> :http://www.eclipse.org/modeling/emft/news/relnotes.php?proj ect=compare&version=0.8.0RC1
>>> )
>>>
>>> You should not have to provide your own match engine for such a thing :)
>>>
>>> Cédric
>>>
>>>
>>> Lars Schneider wrote:
>>>
>>>> I think this problem is better of in this newsgroup.
>>>>
>>>>> Hi,
>>>>> I have a little problem using EcoreUtil.copy(EObject) because the
>>>>> eResource() of that copy returns null.
>>>>>
>>>>> More precisely I want to copy the root of a model, change it and
>>>>> compare
>>>>> it to the original with EMF Compare. I think the following code
>>>>> snippet
>>>>> explains it best:
>>>>>
>>>>> //...
>>>>> EObject copy = EcoreUtil.copy(original);
>>>>> Transformation trans = new Transformation(copy);
>>>>> trans.transform(); // changes copy
>>>>> MatchModel match = null;
>>>>> try {
>>>>> match = MatchService.doMatch(original, copy
>>>>> Collections.<String, Object> emptyMap());
>>>>> } catch (InterruptedException e) {
>>>>> e.printStackTrace();
>>>>> }
>>>>> //...
>>>>>
>>>>> The problem is that doMatch(...) ends up in a NullPointerException
>>>>> because the resource of copy is null. Does anyone have an idea how to
>>>>> solve this problem? I think I can either set the resource manually or
>>>>> get another IMatchEngine implementation. But I don't know how to.
>>>>> Lars
>>>


--------------050408070907090603030501
Content-Type: text/x-vcard; charset=utf-8;
name="laurent_goubet.vcf"
Content-Transfer-Encoding: base64
Content-Disposition: attachment;
filename="laurent_goubet.vcf"

YmVnaW46dmNhcmQNCmZuOkxhdXJlbnQgR291YmV0DQpuOkdvdWJldDtMYXVy ZW50DQpvcmc6
PGEgaHJlZj0iaHR0cDovL3d3dy5vYmVvLmZyLyI+T2JlbzwvYT4NCmVtYWls O2ludGVybmV0
OmxhdXJlbnQuZ291YmV0QG9iZW8uZnINCnVybDpodHRwOi8vd3d3Lm9iZW8u ZnINCnZlcnNp
b246Mi4xDQplbmQ6dmNhcmQNCg0K
--------------050408070907090603030501--
Re: How to create a copy of an EObject with non-null Resource [message #123045 is a reply to message #123005] Tue, 27 May 2008 20:27 Go to previous messageGo to next message
Lars Schneider is currently offline Lars SchneiderFriend
Messages: 50
Registered: July 2009
Member
It seems that I still have another version of GenericMatchEngine. My
Method hasSameURI looks like this:
private boolean hasSameUri(EObject obj1, EObject obj2) {
return
obj1.eResource().getURIFragment(obj1).equals(obj2.eResource( ).getURIFragment(obj2));
}

ModelUtils#attachResource() really solves the problem, so I can use
GenericMatchEngine#doMatch(). But there is another strange behavior.
I am using this snippet and it does NOT work because "diff" is partly wrong:

-- snip

EObject lRoot = null;
EObject rRoot = null;
try {
rRoot = ModelUtils.load(modelURI, resourceSet);
ModelUtils.attachResource(modelURI, rRoot);
lRoot = ModelUtils.load(modelURI, resourceSet);
ModelUtils.attachResource(modelURI, lRoot);
} catch (IOException e) {
e.printStackTrace();
}

Resource lResource = lRoot.eResource();
Resource rResource = rRoot.eResource();

Map<String, Object> options = Collections
.<String, Object> emptyMap();

MatchModel match = null;

try {
match = MatchService.doMatch(lRoot, rRoot, options);
//match = MatchService.doContentMatch(lRoot, rRoot, options);
//match = MatchService.doResourceMatch(lResource, rResource, options);
} catch (InterruptedException e) {
e.printStackTrace();
}
DiffModel diff = DiffService.doDiff(match);
ModelInputSnapshot snapshot = DiffFactory.eINSTANCE
.createModelInputSnapshot();
snapshot.setMatch(match);
snapshot.setDiff(diff);

CompareUI.openCompareDialog(
new ModelCompareEditorInput(modelInputSnapshot));

-- snap

But changing
match = MatchService.doMatch(lRoot, rRoot, options);
into
match = MatchService.doMatch(rRoot, lRoot, options);
WORKS!
Of course, the changings are the wrong way round. I am really desperate
because it depends on the right order.

I attached the model I am working with. It is unfortunately in german
but that shouldn't matter.
By the way I am testing the Hide Property Refactoring with class Konto
(account) and property saldo (balance).

match = MatchService.doMatch(lRoot, rRoot, options);
gets this diff:
Attribute visibility in saldo has changed from public to private

org.eclipse.uml2.uml.internal.impl.OperationImpl@12c662b (name:
getSaldo, visibility: public) (isLeaf: false, isStatic: false,
isAbstract: false, concurrency: sequential) (isQuery: false) has been
*removed*

org.eclipse.uml2.uml.internal.impl.OperationImpl@144f423 (name:
setSaldo, visibility: public) (isLeaf: false, isStatic: false,
isAbstract: false, concurrency: sequential) (isQuery: false) has been
*removed*

but they are *added*

whereas
match = MatchService.doMatch(rRoot, lRoot, options);
provides a correct diff:
Attribute visibility in saldo has changed from private to public

org.eclipse.uml2.uml.internal.impl.OperationImpl@847410 (name:
getSaldo, visibility: public) (isLeaf: false, isStatic: false,
isAbstract: false, concurrency: sequential) (isQuery: false) has been
removed

org.eclipse.uml2.uml.internal.impl.OperationImpl@12a6200 (name:
setSaldo, visibility: public) (isLeaf: false, isStatic: false,
isAbstract: false, concurrency: sequential) (isQuery: false) has been
removed

thanks for your patience,
lars

laurent Goubet wrote:
> Lars,
>
> Yup, GenericMatchEngine#modelMatch() does his work on the resource and
> will fail if it is null, though contentMatch() shouldn't. What puzzles
> me though is that GenericMatchEngine#hasSameURI() at ligne 1174 is :
> if (obj1.eResource() != null && obj2.eResource() != null)
>
> which means you're getting an NPE since one of the two compared objects
> are null, not their resources... Could you provide us with the model
> you're using as input? As a side note, did you take a look at
> ModelUtils#attachResource() to see if it would solve the problem?
>
> Laurent Goubet
> Obeo
>
> Lars Schneider a écrit :
>> and also with a doContentMatch I get a NullPointerException
>>
>> java.lang.NullPointerException
>> at
>> org.eclipse.emf.compare.match.engine.GenericMatchEngine.hasS ameUri(GenericMatchEngine.java:1174)
>>
>> at
>> org.eclipse.emf.compare.match.engine.GenericMatchEngine.isSi milar(GenericMatchEngine.java:593)
>>
>> at
>> org.eclipse.emf.compare.match.engine.GenericMatchEngine.cont entMatch(GenericMatchEngine.java:252)
>>
>> at
>> org.eclipse.emf.compare.match.service.MatchService.doContent Match(MatchService.java:118)
>>
>>
>>
>> Lars Schneider wrote:
>>> Hi Cédric,
>>>
>>> I updated to 0.8.0RC1 and still get a NullPointerException.
>>>
>>> java.lang.NullPointerException
>>> at
>>> org.eclipse.emf.compare.match.engine.GenericMatchEngine.filt erUnused(GenericMatchEngine.java:1094)
>>>
>>> at
>>> org.eclipse.emf.compare.match.engine.GenericMatchEngine.doMa tch(GenericMatchEngine.java:907)
>>>
>>> at
>>> org.eclipse.emf.compare.match.engine.GenericMatchEngine.mode lMatch(GenericMatchEngine.java:331)
>>>
>>> at
>>> org.eclipse.emf.compare.match.service.MatchService.doMatch(M atchService.java:174)
>>>
>>>
>>> GenericMatchEngine.doMatch calls
>>> result = doMatch(leftRoot.eResource(), rightRoot.eResource(), monitor);
>>> in line 331 which is obviously null if rightRoot has a null Resource.
>>>
>>>
>>> Cédric brun wrote:
>>>> Hi Lars,
>>>>
>>>> What EMF Compare build are you using ? The RC1 build should have
>>>> fixed this
>>>> NPE (bug 230347 - see the release
>>>> notes
>>>> :http://www.eclipse.org/modeling/emft/news/relnotes.php?proj ect=compare&version=0.8.0RC1
>>>> )
>>>>
>>>> You should not have to provide your own match engine for such a
>>>> thing :)
>>>>
>>>> Cédric
>>>>
>>>>
>>>> Lars Schneider wrote:
>>>>
>>>>> I think this problem is better of in this newsgroup.
>>>>>
>>>>>> Hi,
>>>>>> I have a little problem using EcoreUtil.copy(EObject) because the
>>>>>> eResource() of that copy returns null.
>>>>>>
>>>>>> More precisely I want to copy the root of a model, change it and
>>>>>> compare
>>>>>> it to the original with EMF Compare. I think the following code
>>>>>> snippet
>>>>>> explains it best:
>>>>>>
>>>>>> //...
>>>>>> EObject copy = EcoreUtil.copy(original);
>>>>>> Transformation trans = new Transformation(copy);
>>>>>> trans.transform(); // changes copy
>>>>>> MatchModel match = null;
>>>>>> try {
>>>>>> match = MatchService.doMatch(original, copy
>>>>>> Collections.<String, Object> emptyMap());
>>>>>> } catch (InterruptedException e) {
>>>>>> e.printStackTrace();
>>>>>> }
>>>>>> //...
>>>>>>
>>>>>> The problem is that doMatch(...) ends up in a NullPointerException
>>>>>> because the resource of copy is null. Does anyone have an idea how to
>>>>>> solve this problem? I think I can either set the resource manually or
>>>>>> get another IMatchEngine implementation. But I don't know how to.
>>>>>> Lars
>>>>
>
Re: How to create a copy of an EObject with non-null Resource [message #123058 is a reply to message #123045] Tue, 27 May 2008 20:28 Go to previous messageGo to next message
Lars Schneider is currently offline Lars SchneiderFriend
Messages: 50
Registered: July 2009
Member
This is a multi-part message in MIME format.
--------------000900080408050704040302
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit

sorry, here comes the attachment

Lars Schneider wrote:
> It seems that I still have another version of GenericMatchEngine. My
> Method hasSameURI looks like this:
> private boolean hasSameUri(EObject obj1, EObject obj2) {
> return
> obj1.eResource().getURIFragment(obj1).equals(obj2.eResource( ).getURIFragment(obj2));
>
> }
>
> ModelUtils#attachResource() really solves the problem, so I can use
> GenericMatchEngine#doMatch(). But there is another strange behavior.
> I am using this snippet and it does NOT work because "diff" is partly
> wrong:
>
> -- snip
>
> EObject lRoot = null;
> EObject rRoot = null;
> try {
> rRoot = ModelUtils.load(modelURI, resourceSet);
> ModelUtils.attachResource(modelURI, rRoot);
> lRoot = ModelUtils.load(modelURI, resourceSet);
> ModelUtils.attachResource(modelURI, lRoot);
> } catch (IOException e) {
> e.printStackTrace();
> }
>
> Resource lResource = lRoot.eResource();
> Resource rResource = rRoot.eResource();
>
> Map<String, Object> options = Collections
> .<String, Object> emptyMap();
>
> MatchModel match = null;
>
> try {
> match = MatchService.doMatch(lRoot, rRoot, options);
> //match = MatchService.doContentMatch(lRoot, rRoot, options);
> //match = MatchService.doResourceMatch(lResource, rResource, options);
> } catch (InterruptedException e) {
> e.printStackTrace();
> }
> DiffModel diff = DiffService.doDiff(match);
> ModelInputSnapshot snapshot = DiffFactory.eINSTANCE
> .createModelInputSnapshot();
> snapshot.setMatch(match);
> snapshot.setDiff(diff);
>
> CompareUI.openCompareDialog(
> new ModelCompareEditorInput(modelInputSnapshot));
>
> -- snap
>
> But changing
> match = MatchService.doMatch(lRoot, rRoot, options);
> into
> match = MatchService.doMatch(rRoot, lRoot, options);
> WORKS!
> Of course, the changings are the wrong way round. I am really desperate
> because it depends on the right order.
>
> I attached the model I am working with. It is unfortunately in german
> but that shouldn't matter.
> By the way I am testing the Hide Property Refactoring with class Konto
> (account) and property saldo (balance).
>
> match = MatchService.doMatch(lRoot, rRoot, options);
> gets this diff:
> Attribute visibility in saldo has changed from public to private
>
> org.eclipse.uml2.uml.internal.impl.OperationImpl@12c662b (name:
> getSaldo, visibility: public) (isLeaf: false, isStatic: false,
> isAbstract: false, concurrency: sequential) (isQuery: false) has been
> *removed*
>
> org.eclipse.uml2.uml.internal.impl.OperationImpl@144f423 (name:
> setSaldo, visibility: public) (isLeaf: false, isStatic: false,
> isAbstract: false, concurrency: sequential) (isQuery: false) has been
> *removed*
>
> but they are *added*
>
> whereas
> match = MatchService.doMatch(rRoot, lRoot, options);
> provides a correct diff:
> Attribute visibility in saldo has changed from private to public
>
> org.eclipse.uml2.uml.internal.impl.OperationImpl@847410 (name:
> getSaldo, visibility: public) (isLeaf: false, isStatic: false,
> isAbstract: false, concurrency: sequential) (isQuery: false) has been
> removed
>
> org.eclipse.uml2.uml.internal.impl.OperationImpl@12a6200 (name:
> setSaldo, visibility: public) (isLeaf: false, isStatic: false,
> isAbstract: false, concurrency: sequential) (isQuery: false) has been
> removed
>
> thanks for your patience,
> lars
>
> laurent Goubet wrote:
>> Lars,
>>
>> Yup, GenericMatchEngine#modelMatch() does his work on the resource and
>> will fail if it is null, though contentMatch() shouldn't. What puzzles
>> me though is that GenericMatchEngine#hasSameURI() at ligne 1174 is :
>> if (obj1.eResource() != null && obj2.eResource() != null)
>>
>> which means you're getting an NPE since one of the two compared
>> objects are null, not their resources... Could you provide us with the
>> model you're using as input? As a side note, did you take a look at
>> ModelUtils#attachResource() to see if it would solve the problem?
>>
>> Laurent Goubet
>> Obeo
>>
>> Lars Schneider a écrit :
>>> and also with a doContentMatch I get a NullPointerException
>>>
>>> java.lang.NullPointerException
>>> at
>>> org.eclipse.emf.compare.match.engine.GenericMatchEngine.hasS ameUri(GenericMatchEngine.java:1174)
>>>
>>> at
>>> org.eclipse.emf.compare.match.engine.GenericMatchEngine.isSi milar(GenericMatchEngine.java:593)
>>>
>>> at
>>> org.eclipse.emf.compare.match.engine.GenericMatchEngine.cont entMatch(GenericMatchEngine.java:252)
>>>
>>> at
>>> org.eclipse.emf.compare.match.service.MatchService.doContent Match(MatchService.java:118)
>>>
>>>
>>>
>>> Lars Schneider wrote:
>>>> Hi Cédric,
>>>>
>>>> I updated to 0.8.0RC1 and still get a NullPointerException.
>>>>
>>>> java.lang.NullPointerException
>>>> at
>>>> org.eclipse.emf.compare.match.engine.GenericMatchEngine.filt erUnused(GenericMatchEngine.java:1094)
>>>>
>>>> at
>>>> org.eclipse.emf.compare.match.engine.GenericMatchEngine.doMa tch(GenericMatchEngine.java:907)
>>>>
>>>> at
>>>> org.eclipse.emf.compare.match.engine.GenericMatchEngine.mode lMatch(GenericMatchEngine.java:331)
>>>>
>>>> at
>>>> org.eclipse.emf.compare.match.service.MatchService.doMatch(M atchService.java:174)
>>>>
>>>>
>>>> GenericMatchEngine.doMatch calls
>>>> result = doMatch(leftRoot.eResource(), rightRoot.eResource(), monitor);
>>>> in line 331 which is obviously null if rightRoot has a null Resource.
>>>>
>>>>
>>>> Cédric brun wrote:
>>>>> Hi Lars,
>>>>>
>>>>> What EMF Compare build are you using ? The RC1 build should have
>>>>> fixed this
>>>>> NPE (bug 230347 - see the release
>>>>> notes
>>>>> :http://www.eclipse.org/modeling/emft/news/relnotes.php?proj ect=compare&version=0.8.0RC1
>>>>> )
>>>>>
>>>>> You should not have to provide your own match engine for such a
>>>>> thing :)
>>>>>
>>>>> Cédric
>>>>>
>>>>>
>>>>> Lars Schneider wrote:
>>>>>
>>>>>> I think this problem is better of in this newsgroup.
>>>>>>
>>>>>>> Hi,
>>>>>>> I have a little problem using EcoreUtil.copy(EObject) because the
>>>>>>> eResource() of that copy returns null.
>>>>>>>
>>>>>>> More precisely I want to copy the root of a model, change it and
>>>>>>> compare
>>>>>>> it to the original with EMF Compare. I think the following code
>>>>>>> snippet
>>>>>>> explains it best:
>>>>>>>
>>>>>>> //...
>>>>>>> EObject copy = EcoreUtil.copy(original);
>>>>>>> Transformation trans = new Transformation(copy);
>>>>>>> trans.transform(); // changes copy
>>>>>>> MatchModel match = null;
>>>>>>> try {
>>>>>>> match = MatchService.doMatch(original, copy
>>>>>>> Collections.<String, Object> emptyMap());
>>>>>>> } catch (InterruptedException e) {
>>>>>>> e.printStackTrace();
>>>>>>> }
>>>>>>> //...
>>>>>>>
>>>>>>> The problem is that doMatch(...) ends up in a NullPointerException
>>>>>>> because the resource of copy is null. Does anyone have an idea
>>>>>>> how to
>>>>>>> solve this problem? I think I can either set the resource
>>>>>>> manually or
>>>>>>> get another IMatchEngine implementation. But I don't know how to.
>>>>>>> Lars
>>>>>
>>


--------------000900080408050704040302
Content-Type: text/xml;
name="BeispielDiagramm.uml"
Content-Transfer-Encoding: 7bit
Content-Disposition: inline;
filename="BeispielDiagramm.uml"

<?xml version="1.0" encoding="UTF-8"?>
<uml:Model xmi:version="2.1" xmlns:xmi="http://schema.omg.org/spec/XMI/2.1" xmlns:uml="http://www.eclipse.org/uml2/2.1.0/UML" xmi:id="_1gYToAiEEdy3Go1fIkI-Ow" name="Unser Beispiel">
<packagedElement xmi:type="uml:Package" xmi:id="_4vqTEAiEEdy3Go1fIkI-Ow" name="bank">
<packagedElement xmi:type="uml:Package" xmi:id="_ger0cAniEdy7h-Bku2skcw" name="kunde"/>
<packagedElement xmi:type="uml:Package" xmi:id="_nCUgkAniEdy7h-Bku2skcw" name="konto"/>
<packagedElement xmi:type="uml:Class" xmi:id="_8HvCIAiEEdy3Go1fIkI-Ow" name="Konto">
<ownedAttribute xmi:id="_MjqMkAiGEdy3Go1fIkI-Ow" name="saldo" visibility="public" type="_32KCwAiFEdy3Go1fIkI-Ow"/>
<ownedOperation xmi:id="_EQoTEA3vEdys69yIcYldpA" name="einzahlen"/>
<ownedOperation xmi:id="_EQoTEQ3vEdys69yIcYldpA" name="abheben"/>
</packagedElement>
<packagedElement xmi:type="uml:Class" xmi:id="_jDS30AiFEdy3Go1fIkI-Ow" name="SparKonto">
<generalization xmi:id="_RKb4gAiIEdyR7ahpixc--g" general="_8HvCIAiEEdy3Go1fIkI-Ow"/>
<ownedAttribute xmi:id="_ExyywAiGEdy3Go1fIkI-Ow" name="kontonummer" type="_22hxwAiFEdy3Go1fIkI-Ow"/>
</packagedElement>
<packagedElement xmi:type="uml:Class" xmi:id="_jYTegAiFEdy3Go1fIkI-Ow" name="GiroKonto">
<generalization xmi:id="_T2sqcAiIEdyR7ahpixc--g" general="_8HvCIAiEEdy3Go1fIkI-Ow"/>
<ownedAttribute xmi:id="_rQ94UBn_Ed2G-vAjw5_nJw" name="kontonummer" type="_22hxwAiFEdy3Go1fIkI-Ow"/>
<ownedOperation xmi:id="_CnOsUA3vEdys69yIcYldpA" name="ueberweisen"/>
</packagedElement>
<packagedElement xmi:type="uml:Class" xmi:id="_XKHqYAiFEdy3Go1fIkI-Ow" name="Kunde">
<ownedAttribute xmi:id="_izWLgAkuEdyUabkMjTLepg" name="" type="_X1CPoAiFEdy3Go1fIkI-Ow" isUnique="false">
<upperValue xmi:type="uml:LiteralUnlimitedNatural" xmi:id="_pZMeIAkuEdyUabkMjTLepg" value="1"/>
<defaultValue xmi:type="uml:LiteralString" xmi:id="_ki9H8AkuEdyUabkMjTLepg" value=""/>
</ownedAttribute>
</packagedElement>
<packagedElement xmi:type="uml:Class" xmi:id="_XX-gMAiFEdy3Go1fIkI-Ow" name="PrivatKunde">
<generalization xmi:id="_UdSwYAiIEdyR7ahpixc--g" general="_XKHqYAiFEdy3Go1fIkI-Ow"/>
</packagedElement>
<packagedElement xmi:type="uml:Class" xmi:id="_Xl_HAAiFEdy3Go1fIkI-Ow" name="GeschaeftsKunde">
<generalization xmi:id="_WrKWIAiIEdyR7ahpixc--g" general="_XKHqYAiFEdy3Go1fIkI-Ow"/>
</packagedElement>
<packagedElement xmi:type="uml:Class" xmi:id="_X1CPoAiFEdy3Go1fIkI-Ow" name="Adresse"/>
<packagedElement xmi:type="uml:PrimitiveType" xmi:id="_22hxwAiFEdy3Go1fIkI-Ow" name="int"/>
<packagedElement xmi:type="uml:PrimitiveType" xmi:id="_3vAR4AiFEdy3Go1fIkI-Ow" name="String"/>
<packagedElement xmi:type="uml:PrimitiveType" xmi:id="_32KCwAiFEdy3Go1fIkI-Ow" name="double"/>
<packagedElement xmi:type="uml:Association" xmi:id="_lsHFAA3nEdys69yIcYldpA" name="Kunde_Konto" memberEnd="_x6KWQA3nEdys69yIcYldpA _P4cH4A3oEdys69yIcYldpA">
<ownedEnd xmi:id="_x6KWQA3nEdys69yIcYldpA" name="kontoBesitzer" type="_XKHqYAiFEdy3Go1fIkI-Ow" association="_lsHFAA3nEdys69yIcYldpA"/>
<ownedEnd xmi:id="_P4cH4A3oEdys69yIcYldpA" name="konten" type="_8HvCIAiEEdy3Go1fIkI-Ow" association="_lsHFAA3nEdys69yIcYldpA">
<upperValue xmi:type="uml:LiteralUnlimitedNatural" xmi:id="_YNr7kA3oEdys69yIcYldpA" value="*"/>
<lowerValue xmi:type="uml:LiteralInteger" xmi:id="_Xp1noA3oEdys69yIcYldpA"/>
</ownedEnd>
</packagedElement>
<packagedElement xmi:type="uml:Association" xmi:id="_13aZgA3oEdys69yIcYldpA" name="Kunde_Adresse" memberEnd="_13aZgQ3oEdys69yIcYldpA _13aZgg3oEdys69yIcYldpA">
<ownedEnd xmi:id="_13aZgQ3oEdys69yIcYldpA" name="wohnhaftenKunden" type="_XKHqYAiFEdy3Go1fIkI-Ow" association="_13aZgA3oEdys69yIcYldpA">
<upperValue xmi:type="uml:LiteralUnlimitedNatural" xmi:id="_V5RzgA3pEdys69yIcYldpA" value="*"/>
<lowerValue xmi:type="uml:LiteralInteger" xmi:id="_VQZOkA3pEdys69yIcYldpA"/>
</ownedEnd>
<ownedEnd xmi:id="_13aZgg3oEdys69yIcYldpA" name="kundenAdressen" type="_X1CPoAiFEdy3Go1fIkI-Ow" association="_13aZgA3oEdys69yIcYldpA">
<upperValue xmi:type="uml:LiteralUnlimitedNatural" xmi:id="_13aZgw3oEdys69yIcYldpA" value="*"/>
<lowerValue xmi:type="uml:LiteralInteger" xmi:id="_13aZhA3oEdys69yIcYldpA" value="1"/>
</ownedEnd>
</packagedElement>
</packagedElement>
</uml:Model>

--------------000900080408050704040302--
Re: How to create a copy of an EObject with non-null Resource [message #123282 is a reply to message #123058] Wed, 28 May 2008 09:56 Go to previous messageGo to next message
Laurent Goubet is currently offline Laurent GoubetFriend
Messages: 1902
Registered: July 2009
Senior Member
This is a multi-part message in MIME format.
--------------000305010601080701030908
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit

This would seem like a problem in the DiffEngine, I'll test this with
your model ASAP. Though the fact your GenericMatchEngine is at an older
version puzzles me ... the build came 3 days after I commited these
changes ;(

Lars Schneider a écrit :
> sorry, here comes the attachment
>
> Lars Schneider wrote:
>> It seems that I still have another version of GenericMatchEngine. My
>> Method hasSameURI looks like this:
>> private boolean hasSameUri(EObject obj1, EObject obj2) {
>> return
>> obj1.eResource().getURIFragment(obj1).equals(obj2.eResource( ).getURIFragment(obj2));
>>
>> }
>>
>> ModelUtils#attachResource() really solves the problem, so I can use
>> GenericMatchEngine#doMatch(). But there is another strange behavior.
>> I am using this snippet and it does NOT work because "diff" is partly
>> wrong:
>>
>> -- snip
>>
>> EObject lRoot = null;
>> EObject rRoot = null;
>> try {
>> rRoot = ModelUtils.load(modelURI, resourceSet);
>> ModelUtils.attachResource(modelURI, rRoot);
>> lRoot = ModelUtils.load(modelURI, resourceSet);
>> ModelUtils.attachResource(modelURI, lRoot);
>> } catch (IOException e) {
>> e.printStackTrace();
>> }
>>
>> Resource lResource = lRoot.eResource();
>> Resource rResource = rRoot.eResource();
>>
>> Map<String, Object> options = Collections
>> .<String, Object> emptyMap();
>>
>> MatchModel match = null;
>>
>> try {
>> match = MatchService.doMatch(lRoot, rRoot, options);
>> //match = MatchService.doContentMatch(lRoot, rRoot, options);
>> //match = MatchService.doResourceMatch(lResource, rResource,
>> options);
>> } catch (InterruptedException e) {
>> e.printStackTrace();
>> }
>> DiffModel diff = DiffService.doDiff(match);
>> ModelInputSnapshot snapshot = DiffFactory.eINSTANCE
>> .createModelInputSnapshot();
>> snapshot.setMatch(match);
>> snapshot.setDiff(diff);
>>
>> CompareUI.openCompareDialog(
>> new ModelCompareEditorInput(modelInputSnapshot));
>>
>> -- snap
>>
>> But changing
>> match = MatchService.doMatch(lRoot, rRoot, options);
>> into
>> match = MatchService.doMatch(rRoot, lRoot, options);
>> WORKS!
>> Of course, the changings are the wrong way round. I am really
>> desperate because it depends on the right order.
>>
>> I attached the model I am working with. It is unfortunately in german
>> but that shouldn't matter.
>> By the way I am testing the Hide Property Refactoring with class Konto
>> (account) and property saldo (balance).
>>
>> match = MatchService.doMatch(lRoot, rRoot, options);
>> gets this diff:
>> Attribute visibility in saldo has changed from public to private
>>
>> org.eclipse.uml2.uml.internal.impl.OperationImpl@12c662b (name:
>> getSaldo, visibility: public) (isLeaf: false, isStatic: false,
>> isAbstract: false, concurrency: sequential) (isQuery: false) has been
>> *removed*
>>
>> org.eclipse.uml2.uml.internal.impl.OperationImpl@144f423 (name:
>> setSaldo, visibility: public) (isLeaf: false, isStatic: false,
>> isAbstract: false, concurrency: sequential) (isQuery: false) has been
>> *removed*
>>
>> but they are *added*
>>
>> whereas
>> match = MatchService.doMatch(rRoot, lRoot, options);
>> provides a correct diff:
>> Attribute visibility in saldo has changed from private to public
>>
>> org.eclipse.uml2.uml.internal.impl.OperationImpl@847410 (name:
>> getSaldo, visibility: public) (isLeaf: false, isStatic: false,
>> isAbstract: false, concurrency: sequential) (isQuery: false) has been
>> removed
>>
>> org.eclipse.uml2.uml.internal.impl.OperationImpl@12a6200 (name:
>> setSaldo, visibility: public) (isLeaf: false, isStatic: false,
>> isAbstract: false, concurrency: sequential) (isQuery: false) has been
>> removed
>>
>> thanks for your patience,
>> lars
>>
>> laurent Goubet wrote:
>>> Lars,
>>>
>>> Yup, GenericMatchEngine#modelMatch() does his work on the resource
>>> and will fail if it is null, though contentMatch() shouldn't. What
>>> puzzles me though is that GenericMatchEngine#hasSameURI() at ligne
>>> 1174 is :
>>> if (obj1.eResource() != null && obj2.eResource() != null)
>>>
>>> which means you're getting an NPE since one of the two compared
>>> objects are null, not their resources... Could you provide us with
>>> the model you're using as input? As a side note, did you take a look
>>> at ModelUtils#attachResource() to see if it would solve the problem?
>>>
>>> Laurent Goubet
>>> Obeo
>>>
>>> Lars Schneider a écrit :
>>>> and also with a doContentMatch I get a NullPointerException
>>>>
>>>> java.lang.NullPointerException
>>>> at
>>>> org.eclipse.emf.compare.match.engine.GenericMatchEngine.hasS ameUri(GenericMatchEngine.java:1174)
>>>>
>>>> at
>>>> org.eclipse.emf.compare.match.engine.GenericMatchEngine.isSi milar(GenericMatchEngine.java:593)
>>>>
>>>> at
>>>> org.eclipse.emf.compare.match.engine.GenericMatchEngine.cont entMatch(GenericMatchEngine.java:252)
>>>>
>>>> at
>>>> org.eclipse.emf.compare.match.service.MatchService.doContent Match(MatchService.java:118)
>>>>
>>>>
>>>>
>>>> Lars Schneider wrote:
>>>>> Hi Cédric,
>>>>>
>>>>> I updated to 0.8.0RC1 and still get a NullPointerException.
>>>>>
>>>>> java.lang.NullPointerException
>>>>> at
>>>>> org.eclipse.emf.compare.match.engine.GenericMatchEngine.filt erUnused(GenericMatchEngine.java:1094)
>>>>>
>>>>> at
>>>>> org.eclipse.emf.compare.match.engine.GenericMatchEngine.doMa tch(GenericMatchEngine.java:907)
>>>>>
>>>>> at
>>>>> org.eclipse.emf.compare.match.engine.GenericMatchEngine.mode lMatch(GenericMatchEngine.java:331)
>>>>>
>>>>> at
>>>>> org.eclipse.emf.compare.match.service.MatchService.doMatch(M atchService.java:174)
>>>>>
>>>>>
>>>>> GenericMatchEngine.doMatch calls
>>>>> result = doMatch(leftRoot.eResource(), rightRoot.eResource(),
>>>>> monitor);
>>>>> in line 331 which is obviously null if rightRoot has a null Resource.
>>>>>
>>>>>
>>>>> Cédric brun wrote:
>>>>>> Hi Lars,
>>>>>>
>>>>>> What EMF Compare build are you using ? The RC1 build should have
>>>>>> fixed this
>>>>>> NPE (bug 230347 - see the release
>>>>>> notes
>>>>>> :http://www.eclipse.org/modeling/emft/news/relnotes.php?proj ect=compare&version=0.8.0RC1
>>>>>> )
>>>>>>
>>>>>> You should not have to provide your own match engine for such a
>>>>>> thing :)
>>>>>>
>>>>>> Cédric
>>>>>>
>>>>>>
>>>>>> Lars Schneider wrote:
>>>>>>
>>>>>>> I think this problem is better of in this newsgroup.
>>>>>>>
>>>>>>>> Hi,
>>>>>>>> I have a little problem using EcoreUtil.copy(EObject) because the
>>>>>>>> eResource() of that copy returns null.
>>>>>>>>
>>>>>>>> More precisely I want to copy the root of a model, change it and
>>>>>>>> compare
>>>>>>>> it to the original with EMF Compare. I think the following code
>>>>>>>> snippet
>>>>>>>> explains it best:
>>>>>>>>
>>>>>>>> //...
>>>>>>>> EObject copy = EcoreUtil.copy(original);
>>>>>>>> Transformation trans = new Transformation(copy);
>>>>>>>> trans.transform(); // changes copy
>>>>>>>> MatchModel match = null;
>>>>>>>> try {
>>>>>>>> match = MatchService.doMatch(original, copy
>>>>>>>> Collections.<String, Object> emptyMap());
>>>>>>>> } catch (InterruptedException e) {
>>>>>>>> e.printStackTrace();
>>>>>>>> }
>>>>>>>> //...
>>>>>>>>
>>>>>>>> The problem is that doMatch(...) ends up in a NullPointerException
>>>>>>>> because the resource of copy is null. Does anyone have an idea
>>>>>>>> how to
>>>>>>>> solve this problem? I think I can either set the resource
>>>>>>>> manually or
>>>>>>>> get another IMatchEngine implementation. But I don't know how to.
>>>>>>>> Lars
>>>>>>
>>>
>


--------------000305010601080701030908
Content-Type: text/x-vcard; charset=utf-8;
name="laurent_goubet.vcf"
Content-Transfer-Encoding: base64
Content-Disposition: attachment;
filename="laurent_goubet.vcf"

YmVnaW46dmNhcmQNCmZuOkxhdXJlbnQgR291YmV0DQpuOkdvdWJldDtMYXVy ZW50DQpvcmc6
PGEgaHJlZj0iaHR0cDovL3d3dy5vYmVvLmZyLyI+T2JlbzwvYT4NCmVtYWls O2ludGVybmV0
OmxhdXJlbnQuZ291YmV0QG9iZW8uZnINCnVybDpodHRwOi8vd3d3Lm9iZW8u ZnINCnZlcnNp
b246Mi4xDQplbmQ6dmNhcmQNCg0K
--------------000305010601080701030908--
Re: How to create a copy of an EObject with non-null Resource [message #123375 is a reply to message #123282] Wed, 28 May 2008 12:25 Go to previous messageGo to next message
Laurent Goubet is currently offline Laurent GoubetFriend
Messages: 1902
Registered: July 2009
Senior Member
This is a multi-part message in MIME format.
--------------020602020701040309050601
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit

Lars,

Okay, just tried this via the UI ... and it worked as expected. Yet I
think your problem comes from the URI you use for your models. The
snippet you provided will never produce differences since you load the
same model twice without ever modifiying it, so I think you modified the
snippet for visibility ;).

The generic diff engine doesn't know which resource is the left model
and which is the right when computing additions/deletions. All we have
are the model URIs as can be retrieved via MatchModel#getLeftModel() and
MatchModel#getRightModel() (these are Strings instead of resources ...
AFAIK, this was because of legacy code). If you have the same URI for
both ... the diff engine will only see *removed* elements.

Something like this should work as you are expecting (I think you were
copying your models so the following will make use of EcoreUtil.copy()) :
try {
lRoot = ModelUtils.load(modelURI, resourceSet);
rRoot = EcoreUtil.copy(lRoot);
// This URI should use the same extension, other than that, it can
point to anything if this copy isn't meant to be saved
ModelUtils.attachResource(copyModelURI, rRoot);
} catch (IOException e) {
e.printStackTrace();
}

And a little update : EMF Compare 0.8RC2 has been built and the changes
to GenericMatchEngine should have made its way through this time. The
build should be promoted today.

Cheers,

Laurent Goubet
Obeo

laurent Goubet a écrit :
> This would seem like a problem in the DiffEngine, I'll test this with
> your model ASAP. Though the fact your GenericMatchEngine is at an older
> version puzzles me ... the build came 3 days after I commited these
> changes ;(
>
> Lars Schneider a écrit :
>> sorry, here comes the attachment
>>
>> Lars Schneider wrote:
>>> It seems that I still have another version of GenericMatchEngine. My
>>> Method hasSameURI looks like this:
>>> private boolean hasSameUri(EObject obj1, EObject obj2) {
>>> return
>>> obj1.eResource().getURIFragment(obj1).equals(obj2.eResource( ).getURIFragment(obj2));
>>>
>>> }
>>>
>>> ModelUtils#attachResource() really solves the problem, so I can use
>>> GenericMatchEngine#doMatch(). But there is another strange behavior.
>>> I am using this snippet and it does NOT work because "diff" is partly
>>> wrong:
>>>
>>> -- snip
>>>
>>> EObject lRoot = null;
>>> EObject rRoot = null;
>>> try {
>>> rRoot = ModelUtils.load(modelURI, resourceSet);
>>> ModelUtils.attachResource(modelURI, rRoot);
>>> lRoot = ModelUtils.load(modelURI, resourceSet);
>>> ModelUtils.attachResource(modelURI, lRoot);
>>> } catch (IOException e) {
>>> e.printStackTrace();
>>> }
>>>
>>> Resource lResource = lRoot.eResource();
>>> Resource rResource = rRoot.eResource();
>>>
>>> Map<String, Object> options = Collections
>>> .<String, Object> emptyMap();
>>>
>>> MatchModel match = null;
>>>
>>> try {
>>> match = MatchService.doMatch(lRoot, rRoot, options);
>>> //match = MatchService.doContentMatch(lRoot, rRoot, options);
>>> //match = MatchService.doResourceMatch(lResource, rResource,
>>> options);
>>> } catch (InterruptedException e) {
>>> e.printStackTrace();
>>> }
>>> DiffModel diff = DiffService.doDiff(match);
>>> ModelInputSnapshot snapshot = DiffFactory.eINSTANCE
>>> .createModelInputSnapshot();
>>> snapshot.setMatch(match);
>>> snapshot.setDiff(diff);
>>>
>>> CompareUI.openCompareDialog(
>>> new ModelCompareEditorInput(modelInputSnapshot));
>>>
>>> -- snap
>>>
>>> But changing
>>> match = MatchService.doMatch(lRoot, rRoot, options);
>>> into
>>> match = MatchService.doMatch(rRoot, lRoot, options);
>>> WORKS!
>>> Of course, the changings are the wrong way round. I am really
>>> desperate because it depends on the right order.
>>>
>>> I attached the model I am working with. It is unfortunately in german
>>> but that shouldn't matter.
>>> By the way I am testing the Hide Property Refactoring with class
>>> Konto (account) and property saldo (balance).
>>>
>>> match = MatchService.doMatch(lRoot, rRoot, options);
>>> gets this diff:
>>> Attribute visibility in saldo has changed from public to private
>>>
>>> org.eclipse.uml2.uml.internal.impl.OperationImpl@12c662b (name:
>>> getSaldo, visibility: public) (isLeaf: false, isStatic: false,
>>> isAbstract: false, concurrency: sequential) (isQuery: false) has been
>>> *removed*
>>>
>>> org.eclipse.uml2.uml.internal.impl.OperationImpl@144f423 (name:
>>> setSaldo, visibility: public) (isLeaf: false, isStatic: false,
>>> isAbstract: false, concurrency: sequential) (isQuery: false) has been
>>> *removed*
>>>
>>> but they are *added*
>>>
>>> whereas
>>> match = MatchService.doMatch(rRoot, lRoot, options);
>>> provides a correct diff:
>>> Attribute visibility in saldo has changed from private to public
>>>
>>> org.eclipse.uml2.uml.internal.impl.OperationImpl@847410 (name:
>>> getSaldo, visibility: public) (isLeaf: false, isStatic: false,
>>> isAbstract: false, concurrency: sequential) (isQuery: false) has been
>>> removed
>>>
>>> org.eclipse.uml2.uml.internal.impl.OperationImpl@12a6200 (name:
>>> setSaldo, visibility: public) (isLeaf: false, isStatic: false,
>>> isAbstract: false, concurrency: sequential) (isQuery: false) has been
>>> removed
>>>
>>> thanks for your patience,
>>> lars
>>>
>>> laurent Goubet wrote:
>>>> Lars,
>>>>
>>>> Yup, GenericMatchEngine#modelMatch() does his work on the resource
>>>> and will fail if it is null, though contentMatch() shouldn't. What
>>>> puzzles me though is that GenericMatchEngine#hasSameURI() at ligne
>>>> 1174 is :
>>>> if (obj1.eResource() != null && obj2.eResource() != null)
>>>>
>>>> which means you're getting an NPE since one of the two compared
>>>> objects are null, not their resources... Could you provide us with
>>>> the model you're using as input? As a side note, did you take a look
>>>> at ModelUtils#attachResource() to see if it would solve the problem?
>>>>
>>>> Laurent Goubet
>>>> Obeo
>>>>
>>>> Lars Schneider a écrit :
>>>>> and also with a doContentMatch I get a NullPointerException
>>>>>
>>>>> java.lang.NullPointerException
>>>>> at
>>>>> org.eclipse.emf.compare.match.engine.GenericMatchEngine.hasS ameUri(GenericMatchEngine.java:1174)
>>>>>
>>>>> at
>>>>> org.eclipse.emf.compare.match.engine.GenericMatchEngine.isSi milar(GenericMatchEngine.java:593)
>>>>>
>>>>> at
>>>>> org.eclipse.emf.compare.match.engine.GenericMatchEngine.cont entMatch(GenericMatchEngine.java:252)
>>>>>
>>>>> at
>>>>> org.eclipse.emf.compare.match.service.MatchService.doContent Match(MatchService.java:118)
>>>>>
>>>>>
>>>>>
>>>>> Lars Schneider wrote:
>>>>>> Hi Cédric,
>>>>>>
>>>>>> I updated to 0.8.0RC1 and still get a NullPointerException.
>>>>>>
>>>>>> java.lang.NullPointerException
>>>>>> at
>>>>>> org.eclipse.emf.compare.match.engine.GenericMatchEngine.filt erUnused(GenericMatchEngine.java:1094)
>>>>>>
>>>>>> at
>>>>>> org.eclipse.emf.compare.match.engine.GenericMatchEngine.doMa tch(GenericMatchEngine.java:907)
>>>>>>
>>>>>> at
>>>>>> org.eclipse.emf.compare.match.engine.GenericMatchEngine.mode lMatch(GenericMatchEngine.java:331)
>>>>>>
>>>>>> at
>>>>>> org.eclipse.emf.compare.match.service.MatchService.doMatch(M atchService.java:174)
>>>>>>
>>>>>>
>>>>>> GenericMatchEngine.doMatch calls
>>>>>> result = doMatch(leftRoot.eResource(), rightRoot.eResource(),
>>>>>> monitor);
>>>>>> in line 331 which is obviously null if rightRoot has a null Resource.
>>>>>>
>>>>>>
>>>>>> Cédric brun wrote:
>>>>>>> Hi Lars,
>>>>>>>
>>>>>>> What EMF Compare build are you using ? The RC1 build should have
>>>>>>> fixed this
>>>>>>> NPE (bug 230347 - see the release
>>>>>>> notes
>>>>>>> :http://www.eclipse.org/modeling/emft/news/relnotes.php?proj ect=compare&version=0.8.0RC1
>>>>>>> )
>>>>>>>
>>>>>>> You should not have to provide your own match engine for such a
>>>>>>> thing :)
>>>>>>>
>>>>>>> Cédric
>>>>>>>
>>>>>>>
>>>>>>> Lars Schneider wrote:
>>>>>>>
>>>>>>>> I think this problem is better of in this newsgroup.
>>>>>>>>
>>>>>>>>> Hi,
>>>>>>>>> I have a little problem using EcoreUtil.copy(EObject) because the
>>>>>>>>> eResource() of that copy returns null.
>>>>>>>>>
>>>>>>>>> More precisely I want to copy the root of a model, change it
>>>>>>>>> and compare
>>>>>>>>> it to the original with EMF Compare. I think the following code
>>>>>>>>> snippet
>>>>>>>>> explains it best:
>>>>>>>>>
>>>>>>>>> //...
>>>>>>>>> EObject copy = EcoreUtil.copy(original);
>>>>>>>>> Transformation trans = new Transformation(copy);
>>>>>>>>> trans.transform(); // changes copy
>>>>>>>>> MatchModel match = null;
>>>>>>>>> try {
>>>>>>>>> match = MatchService.doMatch(original, copy
>>>>>>>>> Collections.<String, Object> emptyMap());
>>>>>>>>> } catch (InterruptedException e) {
>>>>>>>>> e.printStackTrace();
>>>>>>>>> }
>>>>>>>>> //...
>>>>>>>>>
>>>>>>>>> The problem is that doMatch(...) ends up in a NullPointerException
>>>>>>>>> because the resource of copy is null. Does anyone have an idea
>>>>>>>>> how to
>>>>>>>>> solve this problem? I think I can either set the resource
>>>>>>>>> manually or
>>>>>>>>> get another IMatchEngine implementation. But I don't know how to.
>>>>>>>>> Lars
>>>>>>>
>>>>
>>
>


--------------020602020701040309050601
Content-Type: text/x-vcard; charset=utf-8;
name="laurent_goubet.vcf"
Content-Transfer-Encoding: base64
Content-Disposition: attachment;
filename="laurent_goubet.vcf"

YmVnaW46dmNhcmQNCmZuOkxhdXJlbnQgR291YmV0DQpuOkdvdWJldDtMYXVy ZW50DQpvcmc6
PGEgaHJlZj0iaHR0cDovL3d3dy5vYmVvLmZyLyI+T2JlbzwvYT4NCmVtYWls O2ludGVybmV0
OmxhdXJlbnQuZ291YmV0QG9iZW8uZnINCnVybDpodHRwOi8vd3d3Lm9iZW8u ZnINCnZlcnNp
b246Mi4xDQplbmQ6dmNhcmQNCg0K
--------------020602020701040309050601--
Re: How to create a copy of an EObject with non-null Resource [message #123388 is a reply to message #123375] Wed, 28 May 2008 13:02 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: merks.ca.ibm.com

Laurent,

Comments below.

laurent Goubet wrote:
> Lars,
>
> Okay, just tried this via the UI ... and it worked as expected. Yet I
> think your problem comes from the URI you use for your models. The
> snippet you provided will never produce differences since you load the
> same model twice without ever modifiying it, so I think you modified
> the snippet for visibility ;).
>
> The generic diff engine doesn't know which resource is the left model
> and which is the right when computing additions/deletions. All we have
> are the model URIs as can be retrieved via MatchModel#getLeftModel()
> and MatchModel#getRightModel() (these are Strings instead of resources
> ... AFAIK, this was because of legacy code). If you have the same URI
> for both ... the diff engine will only see *removed* elements.
I can see the BIDI defects now about the fact that the left model
appears on the right in the UI. :-P
>
> Something like this should work as you are expecting (I think you were
> copying your models so the following will make use of EcoreUtil.copy()) :
> try {
> lRoot = ModelUtils.load(modelURI, resourceSet);
> rRoot = EcoreUtil.copy(lRoot);
> // This URI should use the same extension, other than that, it can
> point to anything if this copy isn't meant to be saved
> ModelUtils.attachResource(copyModelURI, rRoot);
> } catch (IOException e) {
> e.printStackTrace();
> }
>
> And a little update : EMF Compare 0.8RC2 has been built and the
> changes to GenericMatchEngine should have made its way through this
> time. The build should be promoted today.
>
> Cheers,
>
> Laurent Goubet
> Obeo
>
> laurent Goubet a écrit :
>> This would seem like a problem in the DiffEngine, I'll test this with
>> your model ASAP. Though the fact your GenericMatchEngine is at an
>> older version puzzles me ... the build came 3 days after I commited
>> these changes ;(
>>
>> Lars Schneider a écrit :
>>> sorry, here comes the attachment
>>>
>>> Lars Schneider wrote:
>>>> It seems that I still have another version of GenericMatchEngine.
>>>> My Method hasSameURI looks like this:
>>>> private boolean hasSameUri(EObject obj1, EObject obj2) {
>>>> return
>>>> obj1.eResource().getURIFragment(obj1).equals(obj2.eResource( ).getURIFragment(obj2));
>>>>
>>>> }
>>>>
>>>> ModelUtils#attachResource() really solves the problem, so I can use
>>>> GenericMatchEngine#doMatch(). But there is another strange behavior.
>>>> I am using this snippet and it does NOT work because "diff" is
>>>> partly wrong:
>>>>
>>>> -- snip
>>>>
>>>> EObject lRoot = null;
>>>> EObject rRoot = null;
>>>> try {
>>>> rRoot = ModelUtils.load(modelURI, resourceSet);
>>>> ModelUtils.attachResource(modelURI, rRoot);
>>>> lRoot = ModelUtils.load(modelURI, resourceSet);
>>>> ModelUtils.attachResource(modelURI, lRoot);
>>>> } catch (IOException e) {
>>>> e.printStackTrace();
>>>> }
>>>>
>>>> Resource lResource = lRoot.eResource();
>>>> Resource rResource = rRoot.eResource();
>>>>
>>>> Map<String, Object> options = Collections
>>>> .<String, Object> emptyMap();
>>>>
>>>> MatchModel match = null;
>>>>
>>>> try {
>>>> match = MatchService.doMatch(lRoot, rRoot, options);
>>>> //match = MatchService.doContentMatch(lRoot, rRoot, options);
>>>> //match = MatchService.doResourceMatch(lResource, rResource,
>>>> options);
>>>> } catch (InterruptedException e) {
>>>> e.printStackTrace();
>>>> }
>>>> DiffModel diff = DiffService.doDiff(match);
>>>> ModelInputSnapshot snapshot = DiffFactory.eINSTANCE
>>>> .createModelInputSnapshot();
>>>> snapshot.setMatch(match);
>>>> snapshot.setDiff(diff);
>>>>
>>>> CompareUI.openCompareDialog(
>>>> new ModelCompareEditorInput(modelInputSnapshot));
>>>>
>>>> -- snap
>>>>
>>>> But changing
>>>> match = MatchService.doMatch(lRoot, rRoot, options);
>>>> into
>>>> match = MatchService.doMatch(rRoot, lRoot, options);
>>>> WORKS!
>>>> Of course, the changings are the wrong way round. I am really
>>>> desperate because it depends on the right order.
>>>>
>>>> I attached the model I am working with. It is unfortunately in
>>>> german but that shouldn't matter.
>>>> By the way I am testing the Hide Property Refactoring with class
>>>> Konto (account) and property saldo (balance).
>>>>
>>>> match = MatchService.doMatch(lRoot, rRoot, options);
>>>> gets this diff:
>>>> Attribute visibility in saldo has changed from public to private
>>>>
>>>> org.eclipse.uml2.uml.internal.impl.OperationImpl@12c662b (name:
>>>> getSaldo, visibility: public) (isLeaf: false, isStatic: false,
>>>> isAbstract: false, concurrency: sequential) (isQuery: false) has
>>>> been *removed*
>>>>
>>>> org.eclipse.uml2.uml.internal.impl.OperationImpl@144f423 (name:
>>>> setSaldo, visibility: public) (isLeaf: false, isStatic: false,
>>>> isAbstract: false, concurrency: sequential) (isQuery: false) has
>>>> been *removed*
>>>>
>>>> but they are *added*
>>>>
>>>> whereas
>>>> match = MatchService.doMatch(rRoot, lRoot, options);
>>>> provides a correct diff:
>>>> Attribute visibility in saldo has changed from private to public
>>>>
>>>> org.eclipse.uml2.uml.internal.impl.OperationImpl@847410 (name:
>>>> getSaldo, visibility: public) (isLeaf: false, isStatic: false,
>>>> isAbstract: false, concurrency: sequential) (isQuery: false) has
>>>> been removed
>>>>
>>>> org.eclipse.uml2.uml.internal.impl.OperationImpl@12a6200 (name:
>>>> setSaldo, visibility: public) (isLeaf: false, isStatic: false,
>>>> isAbstract: false, concurrency: sequential) (isQuery: false) has
>>>> been removed
>>>>
>>>> thanks for your patience,
>>>> lars
>>>>
>>>> laurent Goubet wrote:
>>>>> Lars,
>>>>>
>>>>> Yup, GenericMatchEngine#modelMatch() does his work on the resource
>>>>> and will fail if it is null, though contentMatch() shouldn't. What
>>>>> puzzles me though is that GenericMatchEngine#hasSameURI() at ligne
>>>>> 1174 is :
>>>>> if (obj1.eResource() != null && obj2.eResource() != null)
>>>>>
>>>>> which means you're getting an NPE since one of the two compared
>>>>> objects are null, not their resources... Could you provide us with
>>>>> the model you're using as input? As a side note, did you take a
>>>>> look at ModelUtils#attachResource() to see if it would solve the
>>>>> problem?
>>>>>
>>>>> Laurent Goubet
>>>>> Obeo
>>>>>
>>>>> Lars Schneider a écrit :
>>>>>> and also with a doContentMatch I get a NullPointerException
>>>>>>
>>>>>> java.lang.NullPointerException
>>>>>> at
>>>>>> org.eclipse.emf.compare.match.engine.GenericMatchEngine.hasS ameUri(GenericMatchEngine.java:1174)
>>>>>>
>>>>>> at
>>>>>> org.eclipse.emf.compare.match.engine.GenericMatchEngine.isSi milar(GenericMatchEngine.java:593)
>>>>>>
>>>>>> at
>>>>>> org.eclipse.emf.compare.match.engine.GenericMatchEngine.cont entMatch(GenericMatchEngine.java:252)
>>>>>>
>>>>>> at
>>>>>> org.eclipse.emf.compare.match.service.MatchService.doContent Match(MatchService.java:118)
>>>>>>
>>>>>>
>>>>>>
>>>>>> Lars Schneider wrote:
>>>>>>> Hi Cédric,
>>>>>>>
>>>>>>> I updated to 0.8.0RC1 and still get a NullPointerException.
>>>>>>>
>>>>>>> java.lang.NullPointerException
>>>>>>> at
>>>>>>> org.eclipse.emf.compare.match.engine.GenericMatchEngine.filt erUnused(GenericMatchEngine.java:1094)
>>>>>>>
>>>>>>> at
>>>>>>> org.eclipse.emf.compare.match.engine.GenericMatchEngine.doMa tch(GenericMatchEngine.java:907)
>>>>>>>
>>>>>>> at
>>>>>>> org.eclipse.emf.compare.match.engine.GenericMatchEngine.mode lMatch(GenericMatchEngine.java:331)
>>>>>>>
>>>>>>> at
>>>>>>> org.eclipse.emf.compare.match.service.MatchService.doMatch(M atchService.java:174)
>>>>>>>
>>>>>>>
>>>>>>> GenericMatchEngine.doMatch calls
>>>>>>> result = doMatch(leftRoot.eResource(), rightRoot.eResource(),
>>>>>>> monitor);
>>>>>>> in line 331 which is obviously null if rightRoot has a null
>>>>>>> Resource.
>>>>>>>
>>>>>>>
>>>>>>> Cédric brun wrote:
>>>>>>>> Hi Lars,
>>>>>>>>
>>>>>>>> What EMF Compare build are you using ? The RC1 build should
>>>>>>>> have fixed this
>>>>>>>> NPE (bug 230347 - see the release
>>>>>>>> notes
>>>>>>>> :http://www.eclipse.org/modeling/emft/news/relnotes.php?proj ect=compare&version=0.8.0RC1
>>>>>>>> )
>>>>>>>>
>>>>>>>> You should not have to provide your own match engine for such a
>>>>>>>> thing :)
>>>>>>>>
>>>>>>>> Cédric
>>>>>>>>
>>>>>>>>
>>>>>>>> Lars Schneider wrote:
>>>>>>>>
>>>>>>>>> I think this problem is better of in this newsgroup.
>>>>>>>>>
>>>>>>>>>> Hi,
>>>>>>>>>> I have a little problem using EcoreUtil.copy(EObject) because
>>>>>>>>>> the
>>>>>>>>>> eResource() of that copy returns null.
>>>>>>>>>>
>>>>>>>>>> More precisely I want to copy the root of a model, change it
>>>>>>>>>> and compare
>>>>>>>>>> it to the original with EMF Compare. I think the following
>>>>>>>>>> code snippet
>>>>>>>>>> explains it best:
>>>>>>>>>>
>>>>>>>>>> //...
>>>>>>>>>> EObject copy = EcoreUtil.copy(original);
>>>>>>>>>> Transformation trans = new Transformation(copy);
>>>>>>>>>> trans.transform(); // changes copy
>>>>>>>>>> MatchModel match = null;
>>>>>>>>>> try {
>>>>>>>>>> match = MatchService.doMatch(original, copy
>>>>>>>>>> Collections.<String, Object> emptyMap());
>>>>>>>>>> } catch (InterruptedException e) {
>>>>>>>>>> e.printStackTrace();
>>>>>>>>>> }
>>>>>>>>>> //...
>>>>>>>>>>
>>>>>>>>>> The problem is that doMatch(...) ends up in a
>>>>>>>>>> NullPointerException
>>>>>>>>>> because the resource of copy is null. Does anyone have an
>>>>>>>>>> idea how to
>>>>>>>>>> solve this problem? I think I can either set the resource
>>>>>>>>>> manually or
>>>>>>>>>> get another IMatchEngine implementation. But I don't know how
>>>>>>>>>> to.
>>>>>>>>>> Lars
>>>>>>>>
>>>>>
>>>
>>
>
Re: How to create a copy of an EObject with non-null Resource [message #123402 is a reply to message #123388] Wed, 28 May 2008 13:20 Go to previous messageGo to next message
Laurent Goubet is currently offline Laurent GoubetFriend
Messages: 1902
Registered: July 2009
Senior Member
This is a multi-part message in MIME format.
--------------020801030101010103000600
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit

Ed,

BIDI?

And no ... left appearing in the right also comes from a (discutable)
choice from our side ... and will be reverted back to normal as soon as
we come to https://bugs.eclipse.org/bugs/show_bug.cgi?id=232277 .

Laurent Goubet
Obeo

Ed Merks a écrit :
> Laurent,
>
> Comments below.
>
> laurent Goubet wrote:
>> Lars,
>>
>> Okay, just tried this via the UI ... and it worked as expected. Yet I
>> think your problem comes from the URI you use for your models. The
>> snippet you provided will never produce differences since you load the
>> same model twice without ever modifiying it, so I think you modified
>> the snippet for visibility ;).
>>
>> The generic diff engine doesn't know which resource is the left model
>> and which is the right when computing additions/deletions. All we have
>> are the model URIs as can be retrieved via MatchModel#getLeftModel()
>> and MatchModel#getRightModel() (these are Strings instead of resources
>> ... AFAIK, this was because of legacy code). If you have the same URI
>> for both ... the diff engine will only see *removed* elements.
> I can see the BIDI defects now about the fact that the left model
> appears on the right in the UI. :-P
>>
>> Something like this should work as you are expecting (I think you were
>> copying your models so the following will make use of EcoreUtil.copy()) :
>> try {
>> lRoot = ModelUtils.load(modelURI, resourceSet);
>> rRoot = EcoreUtil.copy(lRoot);
>> // This URI should use the same extension, other than that, it can
>> point to anything if this copy isn't meant to be saved
>> ModelUtils.attachResource(copyModelURI, rRoot);
>> } catch (IOException e) {
>> e.printStackTrace();
>> }
>>
>> And a little update : EMF Compare 0.8RC2 has been built and the
>> changes to GenericMatchEngine should have made its way through this
>> time. The build should be promoted today.
>>
>> Cheers,
>>
>> Laurent Goubet
>> Obeo
>>
>> laurent Goubet a écrit :
>>> This would seem like a problem in the DiffEngine, I'll test this with
>>> your model ASAP. Though the fact your GenericMatchEngine is at an
>>> older version puzzles me ... the build came 3 days after I commited
>>> these changes ;(
>>>
>>> Lars Schneider a écrit :
>>>> sorry, here comes the attachment
>>>>
>>>> Lars Schneider wrote:
>>>>> It seems that I still have another version of GenericMatchEngine.
>>>>> My Method hasSameURI looks like this:
>>>>> private boolean hasSameUri(EObject obj1, EObject obj2) {
>>>>> return
>>>>> obj1.eResource().getURIFragment(obj1).equals(obj2.eResource( ).getURIFragment(obj2));
>>>>>
>>>>> }
>>>>>
>>>>> ModelUtils#attachResource() really solves the problem, so I can use
>>>>> GenericMatchEngine#doMatch(). But there is another strange behavior.
>>>>> I am using this snippet and it does NOT work because "diff" is
>>>>> partly wrong:
>>>>>
>>>>> -- snip
>>>>>
>>>>> EObject lRoot = null;
>>>>> EObject rRoot = null;
>>>>> try {
>>>>> rRoot = ModelUtils.load(modelURI, resourceSet);
>>>>> ModelUtils.attachResource(modelURI, rRoot);
>>>>> lRoot = ModelUtils.load(modelURI, resourceSet);
>>>>> ModelUtils.attachResource(modelURI, lRoot);
>>>>> } catch (IOException e) {
>>>>> e.printStackTrace();
>>>>> }
>>>>>
>>>>> Resource lResource = lRoot.eResource();
>>>>> Resource rResource = rRoot.eResource();
>>>>>
>>>>> Map<String, Object> options = Collections
>>>>> .<String, Object> emptyMap();
>>>>>
>>>>> MatchModel match = null;
>>>>>
>>>>> try {
>>>>> match = MatchService.doMatch(lRoot, rRoot, options);
>>>>> //match = MatchService.doContentMatch(lRoot, rRoot, options);
>>>>> //match = MatchService.doResourceMatch(lResource, rResource,
>>>>> options);
>>>>> } catch (InterruptedException e) {
>>>>> e.printStackTrace();
>>>>> }
>>>>> DiffModel diff = DiffService.doDiff(match);
>>>>> ModelInputSnapshot snapshot = DiffFactory.eINSTANCE
>>>>> .createModelInputSnapshot();
>>>>> snapshot.setMatch(match);
>>>>> snapshot.setDiff(diff);
>>>>>
>>>>> CompareUI.openCompareDialog(
>>>>> new ModelCompareEditorInput(modelInputSnapshot));
>>>>>
>>>>> -- snap
>>>>>
>>>>> But changing
>>>>> match = MatchService.doMatch(lRoot, rRoot, options);
>>>>> into
>>>>> match = MatchService.doMatch(rRoot, lRoot, options);
>>>>> WORKS!
>>>>> Of course, the changings are the wrong way round. I am really
>>>>> desperate because it depends on the right order.
>>>>>
>>>>> I attached the model I am working with. It is unfortunately in
>>>>> german but that shouldn't matter.
>>>>> By the way I am testing the Hide Property Refactoring with class
>>>>> Konto (account) and property saldo (balance).
>>>>>
>>>>> match = MatchService.doMatch(lRoot, rRoot, options);
>>>>> gets this diff:
>>>>> Attribute visibility in saldo has changed from public to private
>>>>>
>>>>> org.eclipse.uml2.uml.internal.impl.OperationImpl@12c662b (name:
>>>>> getSaldo, visibility: public) (isLeaf: false, isStatic: false,
>>>>> isAbstract: false, concurrency: sequential) (isQuery: false) has
>>>>> been *removed*
>>>>>
>>>>> org.eclipse.uml2.uml.internal.impl.OperationImpl@144f423 (name:
>>>>> setSaldo, visibility: public) (isLeaf: false, isStatic: false,
>>>>> isAbstract: false, concurrency: sequential) (isQuery: false) has
>>>>> been *removed*
>>>>>
>>>>> but they are *added*
>>>>>
>>>>> whereas
>>>>> match = MatchService.doMatch(rRoot, lRoot, options);
>>>>> provides a correct diff:
>>>>> Attribute visibility in saldo has changed from private to public
>>>>>
>>>>> org.eclipse.uml2.uml.internal.impl.OperationImpl@847410 (name:
>>>>> getSaldo, visibility: public) (isLeaf: false, isStatic: false,
>>>>> isAbstract: false, concurrency: sequential) (isQuery: false) has
>>>>> been removed
>>>>>
>>>>> org.eclipse.uml2.uml.internal.impl.OperationImpl@12a6200 (name:
>>>>> setSaldo, visibility: public) (isLeaf: false, isStatic: false,
>>>>> isAbstract: false, concurrency: sequential) (isQuery: false) has
>>>>> been removed
>>>>>
>>>>> thanks for your patience,
>>>>> lars
>>>>>
>>>>> laurent Goubet wrote:
>>>>>> Lars,
>>>>>>
>>>>>> Yup, GenericMatchEngine#modelMatch() does his work on the resource
>>>>>> and will fail if it is null, though contentMatch() shouldn't. What
>>>>>> puzzles me though is that GenericMatchEngine#hasSameURI() at ligne
>>>>>> 1174 is :
>>>>>> if (obj1.eResource() != null && obj2.eResource() != null)
>>>>>>
>>>>>> which means you're getting an NPE since one of the two compared
>>>>>> objects are null, not their resources... Could you provide us with
>>>>>> the model you're using as input? As a side note, did you take a
>>>>>> look at ModelUtils#attachResource() to see if it would solve the
>>>>>> problem?
>>>>>>
>>>>>> Laurent Goubet
>>>>>> Obeo
>>>>>>
>>>>>> Lars Schneider a écrit :
>>>>>>> and also with a doContentMatch I get a NullPointerException
>>>>>>>
>>>>>>> java.lang.NullPointerException
>>>>>>> at
>>>>>>> org.eclipse.emf.compare.match.engine.GenericMatchEngine.hasS ameUri(GenericMatchEngine.java:1174)
>>>>>>>
>>>>>>> at
>>>>>>> org.eclipse.emf.compare.match.engine.GenericMatchEngine.isSi milar(GenericMatchEngine.java:593)
>>>>>>>
>>>>>>> at
>>>>>>> org.eclipse.emf.compare.match.engine.GenericMatchEngine.cont entMatch(GenericMatchEngine.java:252)
>>>>>>>
>>>>>>> at
>>>>>>> org.eclipse.emf.compare.match.service.MatchService.doContent Match(MatchService.java:118)
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>> Lars Schneider wrote:
>>>>>>>> Hi Cédric,
>>>>>>>>
>>>>>>>> I updated to 0.8.0RC1 and still get a NullPointerException.
>>>>>>>>
>>>>>>>> java.lang.NullPointerException
>>>>>>>> at
>>>>>>>> org.eclipse.emf.compare.match.engine.GenericMatchEngine.filt erUnused(GenericMatchEngine.java:1094)
>>>>>>>>
>>>>>>>> at
>>>>>>>> org.eclipse.emf.compare.match.engine.GenericMatchEngine.doMa tch(GenericMatchEngine.java:907)
>>>>>>>>
>>>>>>>> at
>>>>>>>> org.eclipse.emf.compare.match.engine.GenericMatchEngine.mode lMatch(GenericMatchEngine.java:331)
>>>>>>>>
>>>>>>>> at
>>>>>>>> org.eclipse.emf.compare.match.service.MatchService.doMatch(M atchService.java:174)
>>>>>>>>
>>>>>>>>
>>>>>>>> GenericMatchEngine.doMatch calls
>>>>>>>> result = doMatch(leftRoot.eResource(), rightRoot.eResource(),
>>>>>>>> monitor);
>>>>>>>> in line 331 which is obviously null if rightRoot has a null
>>>>>>>> Resource.
>>>>>>>>
>>>>>>>>
>>>>>>>> Cédric brun wrote:
>>>>>>>>> Hi Lars,
>>>>>>>>>
>>>>>>>>> What EMF Compare build are you using ? The RC1 build should
>>>>>>>>> have fixed this
>>>>>>>>> NPE (bug 230347 - see the release
>>>>>>>>> notes
>>>>>>>>> :http://www.eclipse.org/modeling/emft/news/relnotes.php?proj ect=compare&version=0.8.0RC1
>>>>>>>>> )
>>>>>>>>>
>>>>>>>>> You should not have to provide your own match engine for such a
>>>>>>>>> thing :)
>>>>>>>>>
>>>>>>>>> Cédric
>>>>>>>>>
>>>>>>>>>
>>>>>>>>> Lars Schneider wrote:
>>>>>>>>>
>>>>>>>>>> I think this problem is better of in this newsgroup.
>>>>>>>>>>
>>>>>>>>>>> Hi,
>>>>>>>>>>> I have a little problem using EcoreUtil.copy(EObject) because
>>>>>>>>>>> the
>>>>>>>>>>> eResource() of that copy returns null.
>>>>>>>>>>>
>>>>>>>>>>> More precisely I want to copy the root of a model, change it
>>>>>>>>>>> and compare
>>>>>>>>>>> it to the original with EMF Compare. I think the following
>>>>>>>>>>> code snippet
>>>>>>>>>>> explains it best:
>>>>>>>>>>>
>>>>>>>>>>> //...
>>>>>>>>>>> EObject copy = EcoreUtil.copy(original);
>>>>>>>>>>> Transformation trans = new Transformation(copy);
>>>>>>>>>>> trans.transform(); // changes copy
>>>>>>>>>>> MatchModel match = null;
>>>>>>>>>>> try {
>>>>>>>>>>> match = MatchService.doMatch(original, copy
>>>>>>>>>>> Collections.<String, Object> emptyMap());
>>>>>>>>>>> } catch (InterruptedException e) {
>>>>>>>>>>> e.printStackTrace();
>>>>>>>>>>> }
>>>>>>>>>>> //...
>>>>>>>>>>>
>>>>>>>>>>> The problem is that doMatch(...) ends up in a
>>>>>>>>>>> NullPointerException
>>>>>>>>>>> because the resource of copy is null. Does anyone have an
>>>>>>>>>>> idea how to
>>>>>>>>>>> solve this problem? I think I can either set the resource
>>>>>>>>>>> manually or
>>>>>>>>>>> get another IMatchEngine implementation. But I don't know how
>>>>>>>>>>> to.
>>>>>>>>>>> Lars
>>>>>>>>>
>>>>>>
>>>>
>>>
>>


--------------020801030101010103000600
Content-Type: text/x-vcard; charset=utf-8;
name="laurent_goubet.vcf"
Content-Transfer-Encoding: base64
Content-Disposition: attachment;
filename="laurent_goubet.vcf"

YmVnaW46dmNhcmQNCmZuOkxhdXJlbnQgR291YmV0DQpuOkdvdWJldDtMYXVy ZW50DQpvcmc6
PGEgaHJlZj0iaHR0cDovL3d3dy5vYmVvLmZyLyI+T2JlbzwvYT4NCmVtYWls O2ludGVybmV0
OmxhdXJlbnQuZ291YmV0QG9iZW8uZnINCnVybDpodHRwOi8vd3d3Lm9iZW8u ZnINCnZlcnNp
b246Mi4xDQplbmQ6dmNhcmQNCg0K
--------------020801030101010103000600--
Re: How to create a copy of an EObject with non-null Resource [message #123431 is a reply to message #123402] Wed, 28 May 2008 14:31 Go to previous message
Eclipse UserFriend
Originally posted by: merks.ca.ibm.com

This is a multi-part message in MIME format.
--------------010002060507070000070800
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit

Laurent,

Try running Eclipse with -dir rtl. It's even more fun if you use a
Hebrew or Arabic locale and have actual right to left characters it's
even more fun. And if you mix them all up, the fun in simply endless:

https://bugs.eclipse.org/bugs/show_bug.cgi?id=131711


laurent Goubet wrote:
> Ed,
>
> BIDI?
>
> And no ... left appearing in the right also comes from a (discutable)
> choice from our side ... and will be reverted back to normal as soon
> as we come to https://bugs.eclipse.org/bugs/show_bug.cgi?id=232277 .
>
> Laurent Goubet
> Obeo
>
> Ed Merks a écrit :
>> Laurent,
>>
>> Comments below.
>>
>> laurent Goubet wrote:
>>> Lars,
>>>
>>> Okay, just tried this via the UI ... and it worked as expected. Yet
>>> I think your problem comes from the URI you use for your models. The
>>> snippet you provided will never produce differences since you load
>>> the same model twice without ever modifiying it, so I think you
>>> modified the snippet for visibility ;).
>>>
>>> The generic diff engine doesn't know which resource is the left
>>> model and which is the right when computing additions/deletions. All
>>> we have are the model URIs as can be retrieved via
>>> MatchModel#getLeftModel() and MatchModel#getRightModel() (these are
>>> Strings instead of resources ... AFAIK, this was because of legacy
>>> code). If you have the same URI for both ... the diff engine will
>>> only see *removed* elements.
>> I can see the BIDI defects now about the fact that the left model
>> appears on the right in the UI. :-P
>>>
>>> Something like this should work as you are expecting (I think you
>>> were copying your models so the following will make use of
>>> EcoreUtil.copy()) :
>>> try {
>>> lRoot = ModelUtils.load(modelURI, resourceSet);
>>> rRoot = EcoreUtil.copy(lRoot);
>>> // This URI should use the same extension, other than that, it
>>> can point to anything if this copy isn't meant to be saved
>>> ModelUtils.attachResource(copyModelURI, rRoot);
>>> } catch (IOException e) {
>>> e.printStackTrace();
>>> }
>>>
>>> And a little update : EMF Compare 0.8RC2 has been built and the
>>> changes to GenericMatchEngine should have made its way through this
>>> time. The build should be promoted today.
>>>
>>> Cheers,
>>>
>>> Laurent Goubet
>>> Obeo
>>>
>>> laurent Goubet a écrit :
>>>> This would seem like a problem in the DiffEngine, I'll test this
>>>> with your model ASAP. Though the fact your GenericMatchEngine is at
>>>> an older version puzzles me ... the build came 3 days after I
>>>> commited these changes ;(
>>>>
>>>> Lars Schneider a écrit :
>>>>> sorry, here comes the attachment
>>>>>
>>>>> Lars Schneider wrote:
>>>>>> It seems that I still have another version of GenericMatchEngine.
>>>>>> My Method hasSameURI looks like this:
>>>>>> private boolean hasSameUri(EObject obj1, EObject obj2) {
>>>>>> return
>>>>>> obj1.eResource().getURIFragment(obj1).equals(obj2.eResource( ).getURIFragment(obj2));
>>>>>>
>>>>>> }
>>>>>>
>>>>>> ModelUtils#attachResource() really solves the problem, so I can
>>>>>> use GenericMatchEngine#doMatch(). But there is another strange
>>>>>> behavior.
>>>>>> I am using this snippet and it does NOT work because "diff" is
>>>>>> partly wrong:
>>>>>>
>>>>>> -- snip
>>>>>>
>>>>>> EObject lRoot = null;
>>>>>> EObject rRoot = null;
>>>>>> try {
>>>>>> rRoot = ModelUtils.load(modelURI, resourceSet);
>>>>>> ModelUtils.attachResource(modelURI, rRoot);
>>>>>> lRoot = ModelUtils.load(modelURI, resourceSet);
>>>>>> ModelUtils.attachResource(modelURI, lRoot);
>>>>>> } catch (IOException e) {
>>>>>> e.printStackTrace();
>>>>>> }
>>>>>>
>>>>>> Resource lResource = lRoot.eResource();
>>>>>> Resource rResource = rRoot.eResource();
>>>>>>
>>>>>> Map<String, Object> options = Collections
>>>>>> .<String, Object> emptyMap();
>>>>>>
>>>>>> MatchModel match = null;
>>>>>>
>>>>>> try {
>>>>>> match = MatchService.doMatch(lRoot, rRoot, options);
>>>>>> //match = MatchService.doContentMatch(lRoot, rRoot, options);
>>>>>> //match = MatchService.doResourceMatch(lResource, rResource,
>>>>>> options);
>>>>>> } catch (InterruptedException e) {
>>>>>> e.printStackTrace();
>>>>>> }
>>>>>> DiffModel diff = DiffService.doDiff(match);
>>>>>> ModelInputSnapshot snapshot = DiffFactory.eINSTANCE
>>>>>> .createModelInputSnapshot();
>>>>>> snapshot.setMatch(match);
>>>>>> snapshot.setDiff(diff);
>>>>>>
>>>>>> CompareUI.openCompareDialog(
>>>>>> new ModelCompareEditorInput(modelInputSnapshot));
>>>>>>
>>>>>> -- snap
>>>>>>
>>>>>> But changing
>>>>>> match = MatchService.doMatch(lRoot, rRoot, options);
>>>>>> into
>>>>>> match = MatchService.doMatch(rRoot, lRoot, options);
>>>>>> WORKS!
>>>>>> Of course, the changings are the wrong way round. I am really
>>>>>> desperate because it depends on the right order.
>>>>>>
>>>>>> I attached the model I am working with. It is unfortunately in
>>>>>> german but that shouldn't matter.
>>>>>> By the way I am testing the Hide Property Refactoring with class
>>>>>> Konto (account) and property saldo (balance).
>>>>>>
>>>>>> match = MatchService.doMatch(lRoot, rRoot, options);
>>>>>> gets this diff:
>>>>>> Attribute visibility in saldo has changed from public to private
>>>>>>
>>>>>> org.eclipse.uml2.uml.internal.impl.OperationImpl@12c662b
>>>>>> (name: getSaldo, visibility: public) (isLeaf: false, isStatic:
>>>>>> false, isAbstract: false, concurrency: sequential) (isQuery:
>>>>>> false) has been *removed*
>>>>>>
>>>>>> org.eclipse.uml2.uml.internal.impl.OperationImpl@144f423
>>>>>> (name: setSaldo, visibility: public) (isLeaf: false, isStatic:
>>>>>> false, isAbstract: false, concurrency: sequential) (isQuery:
>>>>>> false) has been *removed*
>>>>>>
>>>>>> but they are *added*
>>>>>>
>>>>>> whereas
>>>>>> match = MatchService.doMatch(rRoot, lRoot, options);
>>>>>> provides a correct diff:
>>>>>> Attribute visibility in saldo has changed from private to public
>>>>>>
>>>>>> org.eclipse.uml2.uml.internal.impl.OperationImpl@847410
>>>>>> (name: getSaldo, visibility: public) (isLeaf: false, isStatic:
>>>>>> false, isAbstract: false, concurrency: sequential) (isQuery:
>>>>>> false) has been removed
>>>>>>
>>>>>> org.eclipse.uml2.uml.internal.impl.OperationImpl@12a6200
>>>>>> (name: setSaldo, visibility: public) (isLeaf: false, isStatic:
>>>>>> false, isAbstract: false, concurrency: sequential) (isQuery:
>>>>>> false) has been removed
>>>>>>
>>>>>> thanks for your patience,
>>>>>> lars
>>>>>>
>>>>>> laurent Goubet wrote:
>>>>>>> Lars,
>>>>>>>
>>>>>>> Yup, GenericMatchEngine#modelMatch() does his work on the
>>>>>>> resource and will fail if it is null, though contentMatch()
>>>>>>> shouldn't. What puzzles me though is that
>>>>>>> GenericMatchEngine#hasSameURI() at ligne 1174 is :
>>>>>>> if (obj1.eResource() != null && obj2.eResource() != null)
>>>>>>>
>>>>>>> which means you're getting an NPE since one of the two compared
>>>>>>> objects are null, not their resources... Could you provide us
>>>>>>> with the model you're using as input? As a side note, did you
>>>>>>> take a look at ModelUtils#attachResource() to see if it would
>>>>>>> solve the problem?
>>>>>>>
>>>>>>> Laurent Goubet
>>>>>>> Obeo
>>>>>>>
>>>>>>> Lars Schneider a écrit :
>>>>>>>> and also with a doContentMatch I get a NullPointerException
>>>>>>>>
>>>>>>>> java.lang.NullPointerException
>>>>>>>> at
>>>>>>>> org.eclipse.emf.compare.match.engine.GenericMatchEngine.hasS ameUri(GenericMatchEngine.java:1174)
>>>>>>>>
>>>>>>>> at
>>>>>>>> org.eclipse.emf.compare.match.engine.GenericMatchEngine.isSi milar(GenericMatchEngine.java:593)
>>>>>>>>
>>>>>>>> at
>>>>>>>> org.eclipse.emf.compare.match.engine.GenericMatchEngine.cont entMatch(GenericMatchEngine.java:252)
>>>>>>>>
>>>>>>>> at
>>>>>>>> org.eclipse.emf.compare.match.service.MatchService.doContent Match(MatchService.java:118)
>>>>>>>>
>>>>>>>>
>>>>>>>>
>>>>>>>> Lars Schneider wrote:
>>>>>>>>> Hi Cédric,
>>>>>>>>>
>>>>>>>>> I updated to 0.8.0RC1 and still get a NullPointerException.
>>>>>>>>>
>>>>>>>>> java.lang.NullPointerException
>>>>>>>>> at
>>>>>>>>> org.eclipse.emf.compare.match.engine.GenericMatchEngine.filt erUnused(GenericMatchEngine.java:1094)
>>>>>>>>>
>>>>>>>>> at
>>>>>>>>> org.eclipse.emf.compare.match.engine.GenericMatchEngine.doMa tch(GenericMatchEngine.java:907)
>>>>>>>>>
>>>>>>>>> at
>>>>>>>>> org.eclipse.emf.compare.match.engine.GenericMatchEngine.mode lMatch(GenericMatchEngine.java:331)
>>>>>>>>>
>>>>>>>>> at
>>>>>>>>> org.eclipse.emf.compare.match.service.MatchService.doMatch(M atchService.java:174)
>>>>>>>>>
>>>>>>>>>
>>>>>>>>> GenericMatchEngine.doMatch calls
>>>>>>>>> result = doMatch(leftRoot.eResource(), rightRoot.eResource(),
>>>>>>>>> monitor);
>>>>>>>>> in line 331 which is obviously null if rightRoot has a null
>>>>>>>>> Resource.
>>>>>>>>>
>>>>>>>>>
>>>>>>>>> Cédric brun wrote:
>>>>>>>>>> Hi Lars,
>>>>>>>>>>
>>>>>>>>>> What EMF Compare build are you using ? The RC1 build should
>>>>>>>>>> have fixed this
>>>>>>>>>> NPE (bug 230347 - see the release
>>>>>>>>>> notes
>>>>>>>>>> :http://www.eclipse.org/modeling/emft/news/relnotes.php?proj ect=compare&version=0.8.0RC1
>>>>>>>>>> )
>>>>>>>>>>
>>>>>>>>>> You should not have to provide your own match engine for such
>>>>>>>>>> a thing :)
>>>>>>>>>>
>>>>>>>>>> Cédric
>>>>>>>>>>
>>>>>>>>>>
>>>>>>>>>> Lars Schneider wrote:
>>>>>>>>>>
>>>>>>>>>>> I think this problem is better of in this newsgroup.
>>>>>>>>>>>
>>>>>>>>>>>> Hi,
>>>>>>>>>>>> I have a little problem using EcoreUtil.copy(EObject)
>>>>>>>>>>>> because the
>>>>>>>>>>>> eResource() of that copy returns null.
>>>>>>>>>>>>
>>>>>>>>>>>> More precisely I want to copy the root of a model, change
>>>>>>>>>>>> it and compare
>>>>>>>>>>>> it to the original with EMF Compare. I think the following
>>>>>>>>>>>> code snippet
>>>>>>>>>>>> explains it best:
>>>>>>>>>>>>
>>>>>>>>>>>> //...
>>>>>>>>>>>> EObject copy = EcoreUtil.copy(original);
>>>>>>>>>>>> Transformation trans = new Transformation(copy);
>>>>>>>>>>>> trans.transform(); // changes copy
>>>>>>>>>>>> MatchModel match = null;
>>>>>>>>>>>> try {
>>>>>>>>>>>> match = MatchService.doMatch(original, copy
>>>>>>>>>>>> Collections.<String, Object> emptyMap());
>>>>>>>>>>>> } catch (InterruptedException e) {
>>>>>>>>>>>> e.printStackTrace();
>>>>>>>>>>>> }
>>>>>>>>>>>> //...
>>>>>>>>>>>>
>>>>>>>>>>>> The problem is that doMatch(...) ends up in a
>>>>>>>>>>>> NullPointerException
>>>>>>>>>>>> because the resource of copy is null. Does anyone have an
>>>>>>>>>>>> idea how to
>>>>>>>>>>>> solve this problem? I think I can either set the resource
>>>>>>>>>>>> manually or
>>>>>>>>>>>> get another IMatchEngine implementation. But I don't know
>>>>>>>>>>>> how to.
>>>>>>>>>>>> Lars
>>>>>>>>>>
>>>>>>>
>>>>>
>>>>
>>>
>


--------------010002060507070000070800
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: 8bit

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta content="text/html;charset=UTF-8" http-equiv="Content-Type">
</head>
<body bgcolor="#ffffff" text="#000000">
Laurent,<br>
<br>
Try running Eclipse with -dir rtl.   It's even more fun if you use a
Hebrew or Arabic locale and have actual right to left characters it's
even more fun.  And if you mix them all up, the fun in simply endless:<br>
<blockquote><a
href="https://bugs.eclipse.org/bugs/show_bug.cgi?id=131711">https://bugs.eclipse.org/bugs/show_bug.cgi?id=131711</a><br>
</blockquote>
<br>
laurent Goubet wrote:
<blockquote cite="mid:g1jm6t$1r2$1@build.eclipse.org" type="cite">Ed,
<br>
<br>
BIDI?
<br>
<br>
And no ... left appearing in the right also comes from a (discutable)
choice from our side ... and will be reverted back to normal as soon as
we come to <a class="moz-txt-link-freetext" href="https://bugs.eclipse.org/bugs/show_bug.cgi?id=232277">https://bugs.eclipse.org/bugs/show_bug.cgi?id=232277</a> .
<br>
<br>
Laurent Goubet
<br>
Obeo
<br>
<br>
Ed Merks a écrit :
<br>
<blockquote type="cite">Laurent,
<br>
<br>
Comments below.
<br>
<br>
laurent Goubet wrote:
<br>
<blockquote type="cite">Lars,
<br>
<br>
Okay, just tried this via the UI ... and it worked as expected. Yet I
think your problem comes from the URI you use for your models. The
snippet you provided will never produce differences since you load the
same model twice without ever modifiying it, so I think you modified
the snippet for visibility ;).
<br>
<br>
The generic diff engine doesn't know which resource is the left model
and which is the right when computing additions/deletions. All we have
are the model URIs as can be retrieved via MatchModel#getLeftModel()
and MatchModel#getRightModel() (these are Strings instead of resources
.... AFAIK, this was because of legacy code). If you have the same URI
for both ... the diff engine will only see *removed* elements.
<br>
</blockquote>
I can see the BIDI defects now about the fact that the left model
appears on the right in the UI. :-P
<br>
<blockquote type="cite"><br>
Something like this should work as you are expecting (I think you were
copying your models so the following will make use of EcoreUtil.copy())
:
<br>
try {
<br>
    lRoot = ModelUtils.load(modelURI, resourceSet);
<br>
    rRoot = EcoreUtil.copy(lRoot);
<br>
    // This URI should use the same extension, other than that, it can
point to anything if this copy isn't meant to be saved
<br>
    ModelUtils.attachResource(copyModelURI, rRoot);
<br>
} catch (IOException e) {
<br>
    e.printStackTrace();
<br>
}
<br>
<br>
And a little update : EMF Compare 0.8RC2 has been built and the changes
to GenericMatchEngine should have made its way through this time. The
build should be promoted today.
<br>
<br>
Cheers,
<br>
<br>
Laurent Goubet
<br>
Obeo
<br>
<br>
laurent Goubet a écrit :
<br>
<blockquote type="cite">This would seem like a problem in the
DiffEngine, I'll test this with your model ASAP. Though the fact your
GenericMatchEngine is at an older version puzzles me ... the build came
3 days after I commited these changes ;(
<br>
<br>
Lars Schneider a écrit :
<br>
<blockquote type="cite">sorry, here comes the attachment
<br>
<br>
Lars Schneider wrote:
<br>
<blockquote type="cite">It seems that I still have another
version of GenericMatchEngine. My Method hasSameURI looks like this:
<br>
private boolean hasSameUri(EObject obj1, EObject obj2) {
<br>
    return
obj1.eResource().getURIFragment(obj1).equals(obj2.eResource( ).getURIFragment(obj2));
<br>
}
<br>
<br>
ModelUtils#attachResource() really solves the problem, so I can use
GenericMatchEngine#doMatch(). But there is another strange behavior.
<br>
I am using this snippet and it does NOT work because "diff" is partly
wrong:
<br>
<br>
-- snip
<br>
<br>
EObject lRoot = null;
<br>
EObject rRoot = null;
<br>
try {
<br>
    rRoot = ModelUtils.load(modelURI, resourceSet);
<br>
    ModelUtils.attachResource(modelURI, rRoot);
<br>
    lRoot = ModelUtils.load(modelURI, resourceSet);
<br>
    ModelUtils.attachResource(modelURI, lRoot);
<br>
} catch (IOException e) {
<br>
    e.printStackTrace();
<br>
}
<br>
<br>
Resource lResource = lRoot.eResource();
<br>
Resource rResource = rRoot.eResource();
<br>
<br>
Map&lt;String, Object&gt; options = Collections
<br>
        .&lt;String, Object&gt; emptyMap();
<br>
<br>
MatchModel match = null;
<br>
<br>
try {
<br>
    match = MatchService.doMatch(lRoot, rRoot, options);
<br>
    //match = MatchService.doContentMatch(lRoot, rRoot, options);
<br>
    //match = MatchService.doResourceMatch(lResource, rResource,
options);
<br>
} catch (InterruptedException e) {
<br>
    e.printStackTrace();
<br>
}
<br>
DiffModel diff = DiffService.doDiff(match);
<br>
ModelInputSnapshot snapshot = DiffFactory.eINSTANCE
<br>
        .createModelInputSnapshot();
<br>
snapshot.setMatch(match);
<br>
snapshot.setDiff(diff);
<br>
<br>
CompareUI.openCompareDialog(
<br>
        new ModelCompareEditorInput(modelInputSnapshot));
<br>
<br>
-- snap
<br>
<br>
But changing
<br>
    match = MatchService.doMatch(lRoot, rRoot, options);
<br>
into
<br>
    match = MatchService.doMatch(rRoot, lRoot, options);
<br>
WORKS!
<br>
Of course, the changings are the wrong way round. I am really desperate
because it depends on the right order.
<br>
<br>
I attached the model I am working with. It is unfortunately in german
but that shouldn't matter.
<br>
By the way I am testing the Hide Property Refactoring with class Konto
(account) and property saldo (balance).
<br>
<br>
match = MatchService.doMatch(lRoot, rRoot, options);
<br>
gets this diff:
<br>
    Attribute visibility in saldo has changed from public to private
<br>
<br>
    org.eclipse.uml2.uml.internal.impl.OperationImpl@12c662b (name:
getSaldo, visibility: public) (isLeaf: false, isStatic: false,
isAbstract: false, concurrency: sequential) (isQuery: false) has been
*removed*
<br>
<br>
    org.eclipse.uml2.uml.internal.impl.OperationImpl@144f423 (name:
setSaldo, visibility: public) (isLeaf: false, isStatic: false,
isAbstract: false, concurrency: sequential) (isQuery: false) has been
*removed*
<br>
<br>
but they are *added*
<br>
<br>
whereas
<br>
match = MatchService.doMatch(rRoot, lRoot, options);
<br>
provides a correct diff:
<br>
    Attribute visibility in saldo has changed from private to public
<br>
<br>
    org.eclipse.uml2.uml.internal.impl.OperationImpl@847410 (name:
getSaldo, visibility: public) (isLeaf: false, isStatic: false,
isAbstract: false, concurrency: sequential) (isQuery: false) has been
removed
<br>
<br>
    org.eclipse.uml2.uml.internal.impl.OperationImpl@12a6200 (name:
setSaldo, visibility: public) (isLeaf: false, isStatic: false,
isAbstract: false, concurrency: sequential) (isQuery: false) has been
removed
<br>
<br>
thanks for your patience,
<br>
lars
<br>
<br>
laurent Goubet wrote:
<br>
<blockquote type="cite">Lars,
<br>
<br>
Yup, GenericMatchEngine#modelMatch() does his work on the resource and
will fail if it is null, though contentMatch() shouldn't. What puzzles
me though is that GenericMatchEngine#hasSameURI() at ligne 1174 is :
<br>
    if (obj1.eResource() != null &amp;&amp; obj2.eResource() != null)
<br>
<br>
which means you're getting an NPE since one of the two compared objects
are null, not their resources... Could you provide us with the model
you're using as input? As a side note, did you take a look at
ModelUtils#attachResource() to see if it would solve the problem?
<br>
<br>
Laurent Goubet
<br>
Obeo
<br>
<br>
Lars Schneider a écrit :
<br>
<blockquote type="cite">and also with a doContentMatch I
get a NullPointerException
<br>
<br>
java.lang.NullPointerException
<br>
        at
org.eclipse.emf.compare.match.engine.GenericMatchEngine.hasS ameUri(GenericMatchEngine.java:1174)
<br>
        at
org.eclipse.emf.compare.match.engine.GenericMatchEngine.isSi milar(GenericMatchEngine.java:593)
<br>
        at
org.eclipse.emf.compare.match.engine.GenericMatchEngine.cont entMatch(GenericMatchEngine.java:252)
<br>
        at
org.eclipse.emf.compare.match.service.MatchService.doContent Match(MatchService.java:118)
<br>
<br>
<br>
Lars Schneider wrote:
<br>
<blockquote type="cite">Hi Cédric,
<br>
<br>
I updated to 0.8.0RC1 and still get a NullPointerException.
<br>
<br>
java.lang.NullPointerException
<br>
        at
org.eclipse.emf.compare.match.engine.GenericMatchEngine.filt erUnused(GenericMatchEngine.java:1094)
<br>
        at
org.eclipse.emf.compare.match.engine.GenericMatchEngine.doMa tch(GenericMatchEngine.java:907)
<br>
        at
org.eclipse.emf.compare.match.engine.GenericMatchEngine.mode lMatch(GenericMatchEngine.java:331)
<br>
        at
org.eclipse.emf.compare.match.service.MatchService.doMatch(M atchService.java:174)
<br>
<br>
GenericMatchEngine.doMatch calls
<br>
result = doMatch(leftRoot.eResource(), rightRoot.eResource(), monitor);
<br>
in line 331 which is obviously null if rightRoot has a null Resource.
<br>
<br>
<br>
Cédric brun wrote:
<br>
<blockquote type="cite">Hi Lars,
<br>
<br>
What EMF Compare build are you using ? The RC1 build should have fixed
this
<br>
NPE (bug 230347 - see the release
<br>
notes
:<a class="moz-txt-link-freetext" href=" http://www.eclipse.org/modeling/emft/news/relnotes.php?proje ct=compare&version=0.8.0RC1"> http://www.eclipse.org/modeling/emft/news/relnotes.php?proje ct=compare&amp;version=0.8.0RC1</a> 
)
<br>
<br>
You should not have to provide your own match engine for such a thing
:)
<br>
<br>
Cédric
<br>
<br>
<br>
Lars Schneider wrote:
<br>
<br>
<blockquote type="cite">I think this problem is
better of in this newsgroup.
<br>
<br>
<blockquote type="cite">Hi,
<br>
I have a little problem using EcoreUtil.copy(EObject) because the
<br>
eResource() of that copy returns null.
<br>
<br>
More precisely I want to copy the root of a model, change it and
compare
<br>
it to the original with EMF Compare. I think the following code snippet
<br>
explains it best:
<br>
<br>
//...
<br>
  EObject copy = EcoreUtil.copy(original);
<br>
  Transformation trans = new Transformation(copy);
<br>
  trans.transform(); // changes copy
<br>
  MatchModel match = null;
<br>
  try {
<br>
    match = MatchService.doMatch(original, copy
<br>
                Collections.&lt;String, Object&gt; emptyMap());
<br>
  } catch (InterruptedException e) {
<br>
    e.printStackTrace();
<br>
  }
<br>
//...
<br>
<br>
The problem is that doMatch(...) ends up in a NullPointerException
<br>
because the resource of copy is null. Does anyone have an idea how to
<br>
solve this problem? I think I can either set the resource manually or
<br>
get another IMatchEngine implementation. But I don't know how to.
<br>
Lars
<br>
</blockquote>
</blockquote>
<br>
</blockquote>
</blockquote>
</blockquote>
<br>
</blockquote>
</blockquote>
<br>
</blockquote>
<br>
</blockquote>
<br>
</blockquote>
</blockquote>
<br>
</blockquote>
<br>
</body>
</html>

--------------010002060507070000070800--
Re: How to create a copy of an EObject with non-null Resource [message #618952 is a reply to message #122952] Sat, 24 May 2008 16:28 Go to previous message
Lars Schneider is currently offline Lars SchneiderFriend
Messages: 50
Registered: July 2009
Member
I think this problem is better of in this newsgroup.

> Hi,
> I have a little problem using EcoreUtil.copy(EObject) because the
> eResource() of that copy returns null.
>
> More precisely I want to copy the root of a model, change it and compare
> it to the original with EMF Compare. I think the following code snippet
> explains it best:
>
> //...
> EObject copy = EcoreUtil.copy(original);
> Transformation trans = new Transformation(copy);
> trans.transform(); // changes copy
> MatchModel match = null;
> try {
> match = MatchService.doMatch(original, copy
> Collections.<String, Object> emptyMap());
> } catch (InterruptedException e) {
> e.printStackTrace();
> }
> //...
>
> The problem is that doMatch(...) ends up in a NullPointerException
> because the resource of copy is null. Does anyone have an idea how to
> solve this problem? I think I can either set the resource manually or
> get another IMatchEngine implementation. But I don't know how to.
> Lars
Re: How to create a copy of an EObject with non-null Resource [message #618958 is a reply to message #122955] Sat, 24 May 2008 16:39 Go to previous message
Ed Merks is currently offline Ed MerksFriend
Messages: 33113
Registered: July 2009
Senior Member
Lars,

Ideally it would be tolerant of a null resource. You'd need to access
the resource set and create a new resource of the appropriate type to
contain the copy, i.e.,
original.eResource().getResourceSet().createResource(...).ge tContents().add(copy)...


Lars Schneider wrote:
> I think this problem is better of in this newsgroup.
>
>> Hi,
>> I have a little problem using EcoreUtil.copy(EObject) because the
>> eResource() of that copy returns null.
>>
>> More precisely I want to copy the root of a model, change it and
>> compare it to the original with EMF Compare. I think the following
>> code snippet explains it best:
>>
>> //...
>> EObject copy = EcoreUtil.copy(original);
>> Transformation trans = new Transformation(copy);
>> trans.transform(); // changes copy
>> MatchModel match = null;
>> try {
>> match = MatchService.doMatch(original, copy
>> Collections.<String, Object> emptyMap());
>> } catch (InterruptedException e) {
>> e.printStackTrace();
>> }
>> //...
>>
>> The problem is that doMatch(...) ends up in a NullPointerException
>> because the resource of copy is null. Does anyone have an idea how to
>> solve this problem? I think I can either set the resource manually or
>> get another IMatchEngine implementation. But I don't know how to.
>> Lars


Ed Merks
Professional Support: https://www.macromodeling.com/
Re: How to create a copy of an EObject with non-null Resource [message #618961 is a reply to message #122955] Sun, 25 May 2008 18:23 Go to previous message
Cedric Brun is currently offline Cedric BrunFriend
Messages: 431
Registered: July 2009
Senior Member
Hi Lars,

What EMF Compare build are you using ? The RC1 build should have fixed this
NPE (bug 230347 - see the release
notes :http://www.eclipse.org/modeling/emft/news/relnotes.php?proj ect=compare&version=0.8.0RC1 )

You should not have to provide your own match engine for such a thing :)

Cédric


Lars Schneider wrote:

> I think this problem is better of in this newsgroup.
>
>> Hi,
>> I have a little problem using EcoreUtil.copy(EObject) because the
>> eResource() of that copy returns null.
>>
>> More precisely I want to copy the root of a model, change it and compare
>> it to the original with EMF Compare. I think the following code snippet
>> explains it best:
>>
>> //...
>> EObject copy = EcoreUtil.copy(original);
>> Transformation trans = new Transformation(copy);
>> trans.transform(); // changes copy
>> MatchModel match = null;
>> try {
>> match = MatchService.doMatch(original, copy
>> Collections.<String, Object> emptyMap());
>> } catch (InterruptedException e) {
>> e.printStackTrace();
>> }
>> //...
>>
>> The problem is that doMatch(...) ends up in a NullPointerException
>> because the resource of copy is null. Does anyone have an idea how to
>> solve this problem? I think I can either set the resource manually or
>> get another IMatchEngine implementation. But I don't know how to.
>> Lars


http://cedric.brun.io news and articles on eclipse and eclipse modeling.
Re: How to create a copy of an EObject with non-null Resource [message #618963 is a reply to message #122961] Mon, 26 May 2008 07:22 Go to previous message
Laurent Goubet is currently offline Laurent GoubetFriend
Messages: 1902
Registered: July 2009
Senior Member
This is a multi-part message in MIME format.
--------------070501080608090002050601
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit

Lars,

As Cédric mentionned, the latest builds should be tolerant to null
resources, though since you're using EMF Compare you could also take a
look at ModelUtils#createResource() and ModelUtils#attachResource()
which we mainly use in our unit tests to copy EObjects and compare them
to one another.

Laurent Goubet
Obeo

Cédric brun a écrit :
> Hi Lars,
>
> What EMF Compare build are you using ? The RC1 build should have fixed this
> NPE (bug 230347 - see the release
> notes :http://www.eclipse.org/modeling/emft/news/relnotes.php?proj ect=compare&version=0.8.0RC1 )
>
> You should not have to provide your own match engine for such a thing :)
>
> Cédric
>
>
> Lars Schneider wrote:
>
>> I think this problem is better of in this newsgroup.
>>
>>> Hi,
>>> I have a little problem using EcoreUtil.copy(EObject) because the
>>> eResource() of that copy returns null.
>>>
>>> More precisely I want to copy the root of a model, change it and compare
>>> it to the original with EMF Compare. I think the following code snippet
>>> explains it best:
>>>
>>> //...
>>> EObject copy = EcoreUtil.copy(original);
>>> Transformation trans = new Transformation(copy);
>>> trans.transform(); // changes copy
>>> MatchModel match = null;
>>> try {
>>> match = MatchService.doMatch(original, copy
>>> Collections.<String, Object> emptyMap());
>>> } catch (InterruptedException e) {
>>> e.printStackTrace();
>>> }
>>> //...
>>>
>>> The problem is that doMatch(...) ends up in a NullPointerException
>>> because the resource of copy is null. Does anyone have an idea how to
>>> solve this problem? I think I can either set the resource manually or
>>> get another IMatchEngine implementation. But I don't know how to.
>>> Lars
>


--------------070501080608090002050601
Content-Type: text/x-vcard; charset=utf-8;
name="laurent_goubet.vcf"
Content-Transfer-Encoding: base64
Content-Disposition: attachment;
filename="laurent_goubet.vcf"

YmVnaW46dmNhcmQNCmZuOkxhdXJlbnQgR291YmV0DQpuOkdvdWJldDtMYXVy ZW50DQpvcmc6
PGEgaHJlZj0iaHR0cDovL3d3dy5vYmVvLmZyLyI+T2JlbzwvYT4NCmVtYWls O2ludGVybmV0
OmxhdXJlbnQuZ291YmV0QG9iZW8uZnINCnVybDpodHRwOi8vd3d3Lm9iZW8u ZnINCnZlcnNp
b246Mi4xDQplbmQ6dmNhcmQNCg0K
--------------070501080608090002050601--
Re: How to create a copy of an EObject with non-null Resource [message #618973 is a reply to message #122961] Tue, 27 May 2008 12:40 Go to previous message
Lars Schneider is currently offline Lars SchneiderFriend
Messages: 50
Registered: July 2009
Member
Hi Cédric,

I updated to 0.8.0RC1 and still get a NullPointerException.

java.lang.NullPointerException
at
org.eclipse.emf.compare.match.engine.GenericMatchEngine.filt erUnused(GenericMatchEngine.java:1094)
at
org.eclipse.emf.compare.match.engine.GenericMatchEngine.doMa tch(GenericMatchEngine.java:907)
at
org.eclipse.emf.compare.match.engine.GenericMatchEngine.mode lMatch(GenericMatchEngine.java:331)
at
org.eclipse.emf.compare.match.service.MatchService.doMatch(M atchService.java:174)

GenericMatchEngine.doMatch calls
result = doMatch(leftRoot.eResource(), rightRoot.eResource(), monitor);
in line 331 which is obviously null if rightRoot has a null Resource.


Cédric brun wrote:
> Hi Lars,
>
> What EMF Compare build are you using ? The RC1 build should have fixed this
> NPE (bug 230347 - see the release
> notes :http://www.eclipse.org/modeling/emft/news/relnotes.php?proj ect=compare&version=0.8.0RC1 )
>
> You should not have to provide your own match engine for such a thing :)
>
> Cédric
>
>
> Lars Schneider wrote:
>
>> I think this problem is better of in this newsgroup.
>>
>>> Hi,
>>> I have a little problem using EcoreUtil.copy(EObject) because the
>>> eResource() of that copy returns null.
>>>
>>> More precisely I want to copy the root of a model, change it and compare
>>> it to the original with EMF Compare. I think the following code snippet
>>> explains it best:
>>>
>>> //...
>>> EObject copy = EcoreUtil.copy(original);
>>> Transformation trans = new Transformation(copy);
>>> trans.transform(); // changes copy
>>> MatchModel match = null;
>>> try {
>>> match = MatchService.doMatch(original, copy
>>> Collections.<String, Object> emptyMap());
>>> } catch (InterruptedException e) {
>>> e.printStackTrace();
>>> }
>>> //...
>>>
>>> The problem is that doMatch(...) ends up in a NullPointerException
>>> because the resource of copy is null. Does anyone have an idea how to
>>> solve this problem? I think I can either set the resource manually or
>>> get another IMatchEngine implementation. But I don't know how to.
>>> Lars
>
Re: How to create a copy of an EObject with non-null Resource [message #618975 is a reply to message #122970] Tue, 27 May 2008 13:01 Go to previous message
Lars Schneider is currently offline Lars SchneiderFriend
Messages: 50
Registered: July 2009
Member
and also with a doContentMatch I get a NullPointerException

java.lang.NullPointerException
at
org.eclipse.emf.compare.match.engine.GenericMatchEngine.hasS ameUri(GenericMatchEngine.java:1174)
at
org.eclipse.emf.compare.match.engine.GenericMatchEngine.isSi milar(GenericMatchEngine.java:593)
at
org.eclipse.emf.compare.match.engine.GenericMatchEngine.cont entMatch(GenericMatchEngine.java:252)
at
org.eclipse.emf.compare.match.service.MatchService.doContent Match(MatchService.java:118)


Lars Schneider wrote:
> Hi Cédric,
>
> I updated to 0.8.0RC1 and still get a NullPointerException.
>
> java.lang.NullPointerException
> at
> org.eclipse.emf.compare.match.engine.GenericMatchEngine.filt erUnused(GenericMatchEngine.java:1094)
>
> at
> org.eclipse.emf.compare.match.engine.GenericMatchEngine.doMa tch(GenericMatchEngine.java:907)
>
> at
> org.eclipse.emf.compare.match.engine.GenericMatchEngine.mode lMatch(GenericMatchEngine.java:331)
>
> at
> org.eclipse.emf.compare.match.service.MatchService.doMatch(M atchService.java:174)
>
>
> GenericMatchEngine.doMatch calls
> result = doMatch(leftRoot.eResource(), rightRoot.eResource(), monitor);
> in line 331 which is obviously null if rightRoot has a null Resource.
>
>
> Cédric brun wrote:
>> Hi Lars,
>>
>> What EMF Compare build are you using ? The RC1 build should have fixed
>> this
>> NPE (bug 230347 - see the release
>> notes
>> :http://www.eclipse.org/modeling/emft/news/relnotes.php?proj ect=compare&version=0.8.0RC1
>> )
>>
>> You should not have to provide your own match engine for such a thing :)
>>
>> Cédric
>>
>>
>> Lars Schneider wrote:
>>
>>> I think this problem is better of in this newsgroup.
>>>
>>>> Hi,
>>>> I have a little problem using EcoreUtil.copy(EObject) because the
>>>> eResource() of that copy returns null.
>>>>
>>>> More precisely I want to copy the root of a model, change it and
>>>> compare
>>>> it to the original with EMF Compare. I think the following code snippet
>>>> explains it best:
>>>>
>>>> //...
>>>> EObject copy = EcoreUtil.copy(original);
>>>> Transformation trans = new Transformation(copy);
>>>> trans.transform(); // changes copy
>>>> MatchModel match = null;
>>>> try {
>>>> match = MatchService.doMatch(original, copy
>>>> Collections.<String, Object> emptyMap());
>>>> } catch (InterruptedException e) {
>>>> e.printStackTrace();
>>>> }
>>>> //...
>>>>
>>>> The problem is that doMatch(...) ends up in a NullPointerException
>>>> because the resource of copy is null. Does anyone have an idea how to
>>>> solve this problem? I think I can either set the resource manually or
>>>> get another IMatchEngine implementation. But I don't know how to.
>>>> Lars
>>
Re: How to create a copy of an EObject with non-null Resource [message #618981 is a reply to message #122971] Tue, 27 May 2008 13:21 Go to previous message
Laurent Goubet is currently offline Laurent GoubetFriend
Messages: 1902
Registered: July 2009
Senior Member
This is a multi-part message in MIME format.
--------------050408070907090603030501
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit

Lars,

Yup, GenericMatchEngine#modelMatch() does his work on the resource and
will fail if it is null, though contentMatch() shouldn't. What puzzles
me though is that GenericMatchEngine#hasSameURI() at ligne 1174 is :
if (obj1.eResource() != null && obj2.eResource() != null)

which means you're getting an NPE since one of the two compared objects
are null, not their resources... Could you provide us with the model
you're using as input? As a side note, did you take a look at
ModelUtils#attachResource() to see if it would solve the problem?

Laurent Goubet
Obeo

Lars Schneider a écrit :
> and also with a doContentMatch I get a NullPointerException
>
> java.lang.NullPointerException
> at
> org.eclipse.emf.compare.match.engine.GenericMatchEngine.hasS ameUri(GenericMatchEngine.java:1174)
>
> at
> org.eclipse.emf.compare.match.engine.GenericMatchEngine.isSi milar(GenericMatchEngine.java:593)
>
> at
> org.eclipse.emf.compare.match.engine.GenericMatchEngine.cont entMatch(GenericMatchEngine.java:252)
>
> at
> org.eclipse.emf.compare.match.service.MatchService.doContent Match(MatchService.java:118)
>
>
>
> Lars Schneider wrote:
>> Hi Cédric,
>>
>> I updated to 0.8.0RC1 and still get a NullPointerException.
>>
>> java.lang.NullPointerException
>> at
>> org.eclipse.emf.compare.match.engine.GenericMatchEngine.filt erUnused(GenericMatchEngine.java:1094)
>>
>> at
>> org.eclipse.emf.compare.match.engine.GenericMatchEngine.doMa tch(GenericMatchEngine.java:907)
>>
>> at
>> org.eclipse.emf.compare.match.engine.GenericMatchEngine.mode lMatch(GenericMatchEngine.java:331)
>>
>> at
>> org.eclipse.emf.compare.match.service.MatchService.doMatch(M atchService.java:174)
>>
>>
>> GenericMatchEngine.doMatch calls
>> result = doMatch(leftRoot.eResource(), rightRoot.eResource(), monitor);
>> in line 331 which is obviously null if rightRoot has a null Resource.
>>
>>
>> Cédric brun wrote:
>>> Hi Lars,
>>>
>>> What EMF Compare build are you using ? The RC1 build should have
>>> fixed this
>>> NPE (bug 230347 - see the release
>>> notes
>>> :http://www.eclipse.org/modeling/emft/news/relnotes.php?proj ect=compare&version=0.8.0RC1
>>> )
>>>
>>> You should not have to provide your own match engine for such a thing :)
>>>
>>> Cédric
>>>
>>>
>>> Lars Schneider wrote:
>>>
>>>> I think this problem is better of in this newsgroup.
>>>>
>>>>> Hi,
>>>>> I have a little problem using EcoreUtil.copy(EObject) because the
>>>>> eResource() of that copy returns null.
>>>>>
>>>>> More precisely I want to copy the root of a model, change it and
>>>>> compare
>>>>> it to the original with EMF Compare. I think the following code
>>>>> snippet
>>>>> explains it best:
>>>>>
>>>>> //...
>>>>> EObject copy = EcoreUtil.copy(original);
>>>>> Transformation trans = new Transformation(copy);
>>>>> trans.transform(); // changes copy
>>>>> MatchModel match = null;
>>>>> try {
>>>>> match = MatchService.doMatch(original, copy
>>>>> Collections.<String, Object> emptyMap());
>>>>> } catch (InterruptedException e) {
>>>>> e.printStackTrace();
>>>>> }
>>>>> //...
>>>>>
>>>>> The problem is that doMatch(...) ends up in a NullPointerException
>>>>> because the resource of copy is null. Does anyone have an idea how to
>>>>> solve this problem? I think I can either set the resource manually or
>>>>> get another IMatchEngine implementation. But I don't know how to.
>>>>> Lars
>>>


--------------050408070907090603030501
Content-Type: text/x-vcard; charset=utf-8;
name="laurent_goubet.vcf"
Content-Transfer-Encoding: base64
Content-Disposition: attachment;
filename="laurent_goubet.vcf"

YmVnaW46dmNhcmQNCmZuOkxhdXJlbnQgR291YmV0DQpuOkdvdWJldDtMYXVy ZW50DQpvcmc6
PGEgaHJlZj0iaHR0cDovL3d3dy5vYmVvLmZyLyI+T2JlbzwvYT4NCmVtYWls O2ludGVybmV0
OmxhdXJlbnQuZ291YmV0QG9iZW8uZnINCnVybDpodHRwOi8vd3d3Lm9iZW8u ZnINCnZlcnNp
b246Mi4xDQplbmQ6dmNhcmQNCg0K
--------------050408070907090603030501--
Re: How to create a copy of an EObject with non-null Resource [message #618992 is a reply to message #123005] Tue, 27 May 2008 20:27 Go to previous message
Lars Schneider is currently offline Lars SchneiderFriend
Messages: 50
Registered: July 2009
Member
It seems that I still have another version of GenericMatchEngine. My
Method hasSameURI looks like this:
private boolean hasSameUri(EObject obj1, EObject obj2) {
return
obj1.eResource().getURIFragment(obj1).equals(obj2.eResource( ).getURIFragment(obj2));
}

ModelUtils#attachResource() really solves the problem, so I can use
GenericMatchEngine#doMatch(). But there is another strange behavior.
I am using this snippet and it does NOT work because "diff" is partly wrong:

-- snip

EObject lRoot = null;
EObject rRoot = null;
try {
rRoot = ModelUtils.load(modelURI, resourceSet);
ModelUtils.attachResource(modelURI, rRoot);
lRoot = ModelUtils.load(modelURI, resourceSet);
ModelUtils.attachResource(modelURI, lRoot);
} catch (IOException e) {
e.printStackTrace();
}

Resource lResource = lRoot.eResource();
Resource rResource = rRoot.eResource();

Map<String, Object> options = Collections
.<String, Object> emptyMap();

MatchModel match = null;

try {
match = MatchService.doMatch(lRoot, rRoot, options);
//match = MatchService.doContentMatch(lRoot, rRoot, options);
//match = MatchService.doResourceMatch(lResource, rResource, options);
} catch (InterruptedException e) {
e.printStackTrace();
}
DiffModel diff = DiffService.doDiff(match);
ModelInputSnapshot snapshot = DiffFactory.eINSTANCE
.createModelInputSnapshot();
snapshot.setMatch(match);
snapshot.setDiff(diff);

CompareUI.openCompareDialog(
new ModelCompareEditorInput(modelInputSnapshot));

-- snap

But changing
match = MatchService.doMatch(lRoot, rRoot, options);
into
match = MatchService.doMatch(rRoot, lRoot, options);
WORKS!
Of course, the changings are the wrong way round. I am really desperate
because it depends on the right order.

I attached the model I am working with. It is unfortunately in german
but that shouldn't matter.
By the way I am testing the Hide Property Refactoring with class Konto
(account) and property saldo (balance).

match = MatchService.doMatch(lRoot, rRoot, options);
gets this diff:
Attribute visibility in saldo has changed from public to private

org.eclipse.uml2.uml.internal.impl.OperationImpl@12c662b (name:
getSaldo, visibility: public) (isLeaf: false, isStatic: false,
isAbstract: false, concurrency: sequential) (isQuery: false) has been
*removed*

org.eclipse.uml2.uml.internal.impl.OperationImpl@144f423 (name:
setSaldo, visibility: public) (isLeaf: false, isStatic: false,
isAbstract: false, concurrency: sequential) (isQuery: false) has been
*removed*

but they are *added*

whereas
match = MatchService.doMatch(rRoot, lRoot, options);
provides a correct diff:
Attribute visibility in saldo has changed from private to public

org.eclipse.uml2.uml.internal.impl.OperationImpl@847410 (name:
getSaldo, visibility: public) (isLeaf: false, isStatic: false,
isAbstract: false, concurrency: sequential) (isQuery: false) has been
removed

org.eclipse.uml2.uml.internal.impl.OperationImpl@12a6200 (name:
setSaldo, visibility: public) (isLeaf: false, isStatic: false,
isAbstract: false, concurrency: sequential) (isQuery: false) has been
removed

thanks for your patience,
lars

laurent Goubet wrote:
> Lars,
>
> Yup, GenericMatchEngine#modelMatch() does his work on the resource and
> will fail if it is null, though contentMatch() shouldn't. What puzzles
> me though is that GenericMatchEngine#hasSameURI() at ligne 1174 is :
> if (obj1.eResource() != null && obj2.eResource() != null)
>
> which means you're getting an NPE since one of the two compared objects
> are null, not their resources... Could you provide us with the model
> you're using as input? As a side note, did you take a look at
> ModelUtils#attachResource() to see if it would solve the problem?
>
> Laurent Goubet
> Obeo
>
> Lars Schneider a écrit :
>> and also with a doContentMatch I get a NullPointerException
>>
>> java.lang.NullPointerException
>> at
>> org.eclipse.emf.compare.match.engine.GenericMatchEngine.hasS ameUri(GenericMatchEngine.java:1174)
>>
>> at
>> org.eclipse.emf.compare.match.engine.GenericMatchEngine.isSi milar(GenericMatchEngine.java:593)
>>
>> at
>> org.eclipse.emf.compare.match.engine.GenericMatchEngine.cont entMatch(GenericMatchEngine.java:252)
>>
>> at
>> org.eclipse.emf.compare.match.service.MatchService.doContent Match(MatchService.java:118)
>>
>>
>>
>> Lars Schneider wrote:
>>> Hi Cédric,
>>>
>>> I updated to 0.8.0RC1 and still get a NullPointerException.
>>>
>>> java.lang.NullPointerException
>>> at
>>> org.eclipse.emf.compare.match.engine.GenericMatchEngine.filt erUnused(GenericMatchEngine.java:1094)
>>>
>>> at
>>> org.eclipse.emf.compare.match.engine.GenericMatchEngine.doMa tch(GenericMatchEngine.java:907)
>>>
>>> at
>>> org.eclipse.emf.compare.match.engine.GenericMatchEngine.mode lMatch(GenericMatchEngine.java:331)
>>>
>>> at
>>> org.eclipse.emf.compare.match.service.MatchService.doMatch(M atchService.java:174)
>>>
>>>
>>> GenericMatchEngine.doMatch calls
>>> result = doMatch(leftRoot.eResource(), rightRoot.eResource(), monitor);
>>> in line 331 which is obviously null if rightRoot has a null Resource.
>>>
>>>
>>> Cédric brun wrote:
>>>> Hi Lars,
>>>>
>>>> What EMF Compare build are you using ? The RC1 build should have
>>>> fixed this
>>>> NPE (bug 230347 - see the release
>>>> notes
>>>> :http://www.eclipse.org/modeling/emft/news/relnotes.php?proj ect=compare&version=0.8.0RC1
>>>> )
>>>>
>>>> You should not have to provide your own match engine for such a
>>>> thing :)
>>>>
>>>> Cédric
>>>>
>>>>
>>>> Lars Schneider wrote:
>>>>
>>>>> I think this problem is better of in this newsgroup.
>>>>>
>>>>>> Hi,
>>>>>> I have a little problem using EcoreUtil.copy(EObject) because the
>>>>>> eResource() of that copy returns null.
>>>>>>
>>>>>> More precisely I want to copy the root of a model, change it and
>>>>>> compare
>>>>>> it to the original with EMF Compare. I think the following code
>>>>>> snippet
>>>>>> explains it best:
>>>>>>
>>>>>> //...
>>>>>> EObject copy = EcoreUtil.copy(original);
>>>>>> Transformation trans = new Transformation(copy);
>>>>>> trans.transform(); // changes copy
>>>>>> MatchModel match = null;
>>>>>> try {
>>>>>> match = MatchService.doMatch(original, copy
>>>>>> Collections.<String, Object> emptyMap());
>>>>>> } catch (InterruptedException e) {
>>>>>> e.printStackTrace();
>>>>>> }
>>>>>> //...
>>>>>>
>>>>>> The problem is that doMatch(...) ends up in a NullPointerException
>>>>>> because the resource of copy is null. Does anyone have an idea how to
>>>>>> solve this problem? I think I can either set the resource manually or
>>>>>> get another IMatchEngine implementation. But I don't know how to.
>>>>>> Lars
>>>>
>
Re: How to create a copy of an EObject with non-null Resource [message #618994 is a reply to message #123045] Tue, 27 May 2008 20:28 Go to previous message
Lars Schneider is currently offline Lars SchneiderFriend
Messages: 50
Registered: July 2009
Member
This is a multi-part message in MIME format.
--------------000900080408050704040302
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit

sorry, here comes the attachment

Lars Schneider wrote:
> It seems that I still have another version of GenericMatchEngine. My
> Method hasSameURI looks like this:
> private boolean hasSameUri(EObject obj1, EObject obj2) {
> return
> obj1.eResource().getURIFragment(obj1).equals(obj2.eResource( ).getURIFragment(obj2));
>
> }
>
> ModelUtils#attachResource() really solves the problem, so I can use
> GenericMatchEngine#doMatch(). But there is another strange behavior.
> I am using this snippet and it does NOT work because "diff" is partly
> wrong:
>
> -- snip
>
> EObject lRoot = null;
> EObject rRoot = null;
> try {
> rRoot = ModelUtils.load(modelURI, resourceSet);
> ModelUtils.attachResource(modelURI, rRoot);
> lRoot = ModelUtils.load(modelURI, resourceSet);
> ModelUtils.attachResource(modelURI, lRoot);
> } catch (IOException e) {
> e.printStackTrace();
> }
>
> Resource lResource = lRoot.eResource();
> Resource rResource = rRoot.eResource();
>
> Map<String, Object> options = Collections
> .<String, Object> emptyMap();
>
> MatchModel match = null;
>
> try {
> match = MatchService.doMatch(lRoot, rRoot, options);
> //match = MatchService.doContentMatch(lRoot, rRoot, options);
> //match = MatchService.doResourceMatch(lResource, rResource, options);
> } catch (InterruptedException e) {
> e.printStackTrace();
> }
> DiffModel diff = DiffService.doDiff(match);
> ModelInputSnapshot snapshot = DiffFactory.eINSTANCE
> .createModelInputSnapshot();
> snapshot.setMatch(match);
> snapshot.setDiff(diff);
>
> CompareUI.openCompareDialog(
> new ModelCompareEditorInput(modelInputSnapshot));
>
> -- snap
>
> But changing
> match = MatchService.doMatch(lRoot, rRoot, options);
> into
> match = MatchService.doMatch(rRoot, lRoot, options);
> WORKS!
> Of course, the changings are the wrong way round. I am really desperate
> because it depends on the right order.
>
> I attached the model I am working with. It is unfortunately in german
> but that shouldn't matter.
> By the way I am testing the Hide Property Refactoring with class Konto
> (account) and property saldo (balance).
>
> match = MatchService.doMatch(lRoot, rRoot, options);
> gets this diff:
> Attribute visibility in saldo has changed from public to private
>
> org.eclipse.uml2.uml.internal.impl.OperationImpl@12c662b (name:
> getSaldo, visibility: public) (isLeaf: false, isStatic: false,
> isAbstract: false, concurrency: sequential) (isQuery: false) has been
> *removed*
>
> org.eclipse.uml2.uml.internal.impl.OperationImpl@144f423 (name:
> setSaldo, visibility: public) (isLeaf: false, isStatic: false,
> isAbstract: false, concurrency: sequential) (isQuery: false) has been
> *removed*
>
> but they are *added*
>
> whereas
> match = MatchService.doMatch(rRoot, lRoot, options);
> provides a correct diff:
> Attribute visibility in saldo has changed from private to public
>
> org.eclipse.uml2.uml.internal.impl.OperationImpl@847410 (name:
> getSaldo, visibility: public) (isLeaf: false, isStatic: false,
> isAbstract: false, concurrency: sequential) (isQuery: false) has been
> removed
>
> org.eclipse.uml2.uml.internal.impl.OperationImpl@12a6200 (name:
> setSaldo, visibility: public) (isLeaf: false, isStatic: false,
> isAbstract: false, concurrency: sequential) (isQuery: false) has been
> removed
>
> thanks for your patience,
> lars
>
> laurent Goubet wrote:
>> Lars,
>>
>> Yup, GenericMatchEngine#modelMatch() does his work on the resource and
>> will fail if it is null, though contentMatch() shouldn't. What puzzles
>> me though is that GenericMatchEngine#hasSameURI() at ligne 1174 is :
>> if (obj1.eResource() != null && obj2.eResource() != null)
>>
>> which means you're getting an NPE since one of the two compared
>> objects are null, not their resources... Could you provide us with the
>> model you're using as input? As a side note, did you take a look at
>> ModelUtils#attachResource() to see if it would solve the problem?
>>
>> Laurent Goubet
>> Obeo
>>
>> Lars Schneider a écrit :
>>> and also with a doContentMatch I get a NullPointerException
>>>
>>> java.lang.NullPointerException
>>> at
>>> org.eclipse.emf.compare.match.engine.GenericMatchEngine.hasS ameUri(GenericMatchEngine.java:1174)
>>>
>>> at
>>> org.eclipse.emf.compare.match.engine.GenericMatchEngine.isSi milar(GenericMatchEngine.java:593)
>>>
>>> at
>>> org.eclipse.emf.compare.match.engine.GenericMatchEngine.cont entMatch(GenericMatchEngine.java:252)
>>>
>>> at
>>> org.eclipse.emf.compare.match.service.MatchService.doContent Match(MatchService.java:118)
>>>
>>>
>>>
>>> Lars Schneider wrote:
>>>> Hi Cédric,
>>>>
>>>> I updated to 0.8.0RC1 and still get a NullPointerException.
>>>>
>>>> java.lang.NullPointerException
>>>> at
>>>> org.eclipse.emf.compare.match.engine.GenericMatchEngine.filt erUnused(GenericMatchEngine.java:1094)
>>>>
>>>> at
>>>> org.eclipse.emf.compare.match.engine.GenericMatchEngine.doMa tch(GenericMatchEngine.java:907)
>>>>
>>>> at
>>>> org.eclipse.emf.compare.match.engine.GenericMatchEngine.mode lMatch(GenericMatchEngine.java:331)
>>>>
>>>> at
>>>> org.eclipse.emf.compare.match.service.MatchService.doMatch(M atchService.java:174)
>>>>
>>>>
>>>> GenericMatchEngine.doMatch calls
>>>> result = doMatch(leftRoot.eResource(), rightRoot.eResource(), monitor);
>>>> in line 331 which is obviously null if rightRoot has a null Resource.
>>>>
>>>>
>>>> Cédric brun wrote:
>>>>> Hi Lars,
>>>>>
>>>>> What EMF Compare build are you using ? The RC1 build should have
>>>>> fixed this
>>>>> NPE (bug 230347 - see the release
>>>>> notes
>>>>> :http://www.eclipse.org/modeling/emft/news/relnotes.php?proj ect=compare&version=0.8.0RC1
>>>>> )
>>>>>
>>>>> You should not have to provide your own match engine for such a
>>>>> thing :)
>>>>>
>>>>> Cédric
>>>>>
>>>>>
>>>>> Lars Schneider wrote:
>>>>>
>>>>>> I think this problem is better of in this newsgroup.
>>>>>>
>>>>>>> Hi,
>>>>>>> I have a little problem using EcoreUtil.copy(EObject) because the
>>>>>>> eResource() of that copy returns null.
>>>>>>>
>>>>>>> More precisely I want to copy the root of a model, change it and
>>>>>>> compare
>>>>>>> it to the original with EMF Compare. I think the following code
>>>>>>> snippet
>>>>>>> explains it best:
>>>>>>>
>>>>>>> //...
>>>>>>> EObject copy = EcoreUtil.copy(original);
>>>>>>> Transformation trans = new Transformation(copy);
>>>>>>> trans.transform(); // changes copy
>>>>>>> MatchModel match = null;
>>>>>>> try {
>>>>>>> match = MatchService.doMatch(original, copy
>>>>>>> Collections.<String, Object> emptyMap());
>>>>>>> } catch (InterruptedException e) {
>>>>>>> e.printStackTrace();
>>>>>>> }
>>>>>>> //...
>>>>>>>
>>>>>>> The problem is that doMatch(...) ends up in a NullPointerException
>>>>>>> because the resource of copy is null. Does anyone have an idea
>>>>>>> how to
>>>>>>> solve this problem? I think I can either set the resource
>>>>>>> manually or
>>>>>>> get another IMatchEngine implementation. But I don't know how to.
>>>>>>> Lars
>>>>>
>>


--------------000900080408050704040302
Content-Type: text/xml;
name="BeispielDiagramm.uml"
Content-Transfer-Encoding: 7bit
Content-Disposition: inline;
filename="BeispielDiagramm.uml"

<?xml version="1.0" encoding="UTF-8"?>
<uml:Model xmi:version="2.1" xmlns:xmi="http://schema.omg.org/spec/XMI/2.1" xmlns:uml="http://www.eclipse.org/uml2/2.1.0/UML" xmi:id="_1gYToAiEEdy3Go1fIkI-Ow" name="Unser Beispiel">
<packagedElement xmi:type="uml:Package" xmi:id="_4vqTEAiEEdy3Go1fIkI-Ow" name="bank">
<packagedElement xmi:type="uml:Package" xmi:id="_ger0cAniEdy7h-Bku2skcw" name="kunde"/>
<packagedElement xmi:type="uml:Package" xmi:id="_nCUgkAniEdy7h-Bku2skcw" name="konto"/>
<packagedElement xmi:type="uml:Class" xmi:id="_8HvCIAiEEdy3Go1fIkI-Ow" name="Konto">
<ownedAttribute xmi:id="_MjqMkAiGEdy3Go1fIkI-Ow" name="saldo" visibility="public" type="_32KCwAiFEdy3Go1fIkI-Ow"/>
<ownedOperation xmi:id="_EQoTEA3vEdys69yIcYldpA" name="einzahlen"/>
<ownedOperation xmi:id="_EQoTEQ3vEdys69yIcYldpA" name="abheben"/>
</packagedElement>
<packagedElement xmi:type="uml:Class" xmi:id="_jDS30AiFEdy3Go1fIkI-Ow" name="SparKonto">
<generalization xmi:id="_RKb4gAiIEdyR7ahpixc--g" general="_8HvCIAiEEdy3Go1fIkI-Ow"/>
<ownedAttribute xmi:id="_ExyywAiGEdy3Go1fIkI-Ow" name="kontonummer" type="_22hxwAiFEdy3Go1fIkI-Ow"/>
</packagedElement>
<packagedElement xmi:type="uml:Class" xmi:id="_jYTegAiFEdy3Go1fIkI-Ow" name="GiroKonto">
<generalization xmi:id="_T2sqcAiIEdyR7ahpixc--g" general="_8HvCIAiEEdy3Go1fIkI-Ow"/>
<ownedAttribute xmi:id="_rQ94UBn_Ed2G-vAjw5_nJw" name="kontonummer" type="_22hxwAiFEdy3Go1fIkI-Ow"/>
<ownedOperation xmi:id="_CnOsUA3vEdys69yIcYldpA" name="ueberweisen"/>
</packagedElement>
<packagedElement xmi:type="uml:Class" xmi:id="_XKHqYAiFEdy3Go1fIkI-Ow" name="Kunde">
<ownedAttribute xmi:id="_izWLgAkuEdyUabkMjTLepg" name="" type="_X1CPoAiFEdy3Go1fIkI-Ow" isUnique="false">
<upperValue xmi:type="uml:LiteralUnlimitedNatural" xmi:id="_pZMeIAkuEdyUabkMjTLepg" value="1"/>
<defaultValue xmi:type="uml:LiteralString" xmi:id="_ki9H8AkuEdyUabkMjTLepg" value=""/>
</ownedAttribute>
</packagedElement>
<packagedElement xmi:type="uml:Class" xmi:id="_XX-gMAiFEdy3Go1fIkI-Ow" name="PrivatKunde">
<generalization xmi:id="_UdSwYAiIEdyR7ahpixc--g" general="_XKHqYAiFEdy3Go1fIkI-Ow"/>
</packagedElement>
<packagedElement xmi:type="uml:Class" xmi:id="_Xl_HAAiFEdy3Go1fIkI-Ow" name="GeschaeftsKunde">
<generalization xmi:id="_WrKWIAiIEdyR7ahpixc--g" general="_XKHqYAiFEdy3Go1fIkI-Ow"/>
</packagedElement>
<packagedElement xmi:type="uml:Class" xmi:id="_X1CPoAiFEdy3Go1fIkI-Ow" name="Adresse"/>
<packagedElement xmi:type="uml:PrimitiveType" xmi:id="_22hxwAiFEdy3Go1fIkI-Ow" name="int"/>
<packagedElement xmi:type="uml:PrimitiveType" xmi:id="_3vAR4AiFEdy3Go1fIkI-Ow" name="String"/>
<packagedElement xmi:type="uml:PrimitiveType" xmi:id="_32KCwAiFEdy3Go1fIkI-Ow" name="double"/>
<packagedElement xmi:type="uml:Association" xmi:id="_lsHFAA3nEdys69yIcYldpA" name="Kunde_Konto" memberEnd="_x6KWQA3nEdys69yIcYldpA _P4cH4A3oEdys69yIcYldpA">
<ownedEnd xmi:id="_x6KWQA3nEdys69yIcYldpA" name="kontoBesitzer" type="_XKHqYAiFEdy3Go1fIkI-Ow" association="_lsHFAA3nEdys69yIcYldpA"/>
<ownedEnd xmi:id="_P4cH4A3oEdys69yIcYldpA" name="konten" type="_8HvCIAiEEdy3Go1fIkI-Ow" association="_lsHFAA3nEdys69yIcYldpA">
<upperValue xmi:type="uml:LiteralUnlimitedNatural" xmi:id="_YNr7kA3oEdys69yIcYldpA" value="*"/>
<lowerValue xmi:type="uml:LiteralInteger" xmi:id="_Xp1noA3oEdys69yIcYldpA"/>
</ownedEnd>
</packagedElement>
<packagedElement xmi:type="uml:Association" xmi:id="_13aZgA3oEdys69yIcYldpA" name="Kunde_Adresse" memberEnd="_13aZgQ3oEdys69yIcYldpA _13aZgg3oEdys69yIcYldpA">
<ownedEnd xmi:id="_13aZgQ3oEdys69yIcYldpA" name="wohnhaftenKunden" type="_XKHqYAiFEdy3Go1fIkI-Ow" association="_13aZgA3oEdys69yIcYldpA">
<upperValue xmi:type="uml:LiteralUnlimitedNatural" xmi:id="_V5RzgA3pEdys69yIcYldpA" value="*"/>
<lowerValue xmi:type="uml:LiteralInteger" xmi:id="_VQZOkA3pEdys69yIcYldpA"/>
</ownedEnd>
<ownedEnd xmi:id="_13aZgg3oEdys69yIcYldpA" name="kundenAdressen" type="_X1CPoAiFEdy3Go1fIkI-Ow" association="_13aZgA3oEdys69yIcYldpA">
<upperValue xmi:type="uml:LiteralUnlimitedNatural" xmi:id="_13aZgw3oEdys69yIcYldpA" value="*"/>
<lowerValue xmi:type="uml:LiteralInteger" xmi:id="_13aZhA3oEdys69yIcYldpA" value="1"/>
</ownedEnd>
</packagedElement>
</packagedElement>
</uml:Model>

--------------000900080408050704040302--
Re: How to create a copy of an EObject with non-null Resource [message #619010 is a reply to message #123058] Wed, 28 May 2008 09:56 Go to previous message
Laurent Goubet is currently offline Laurent GoubetFriend
Messages: 1902
Registered: July 2009
Senior Member
This is a multi-part message in MIME format.
--------------000305010601080701030908
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit

This would seem like a problem in the DiffEngine, I'll test this with
your model ASAP. Though the fact your GenericMatchEngine is at an older
version puzzles me ... the build came 3 days after I commited these
changes ;(

Lars Schneider a écrit :
> sorry, here comes the attachment
>
> Lars Schneider wrote:
>> It seems that I still have another version of GenericMatchEngine. My
>> Method hasSameURI looks like this:
>> private boolean hasSameUri(EObject obj1, EObject obj2) {
>> return
>> obj1.eResource().getURIFragment(obj1).equals(obj2.eResource( ).getURIFragment(obj2));
>>
>> }
>>
>> ModelUtils#attachResource() really solves the problem, so I can use
>> GenericMatchEngine#doMatch(). But there is another strange behavior.
>> I am using this snippet and it does NOT work because "diff" is partly
>> wrong:
>>
>> -- snip
>>
>> EObject lRoot = null;
>> EObject rRoot = null;
>> try {
>> rRoot = ModelUtils.load(modelURI, resourceSet);
>> ModelUtils.attachResource(modelURI, rRoot);
>> lRoot = ModelUtils.load(modelURI, resourceSet);
>> ModelUtils.attachResource(modelURI, lRoot);
>> } catch (IOException e) {
>> e.printStackTrace();
>> }
>>
>> Resource lResource = lRoot.eResource();
>> Resource rResource = rRoot.eResource();
>>
>> Map<String, Object> options = Collections
>> .<String, Object> emptyMap();
>>
>> MatchModel match = null;
>>
>> try {
>> match = MatchService.doMatch(lRoot, rRoot, options);
>> //match = MatchService.doContentMatch(lRoot, rRoot, options);
>> //match = MatchService.doResourceMatch(lResource, rResource,
>> options);
>> } catch (InterruptedException e) {
>> e.printStackTrace();
>> }
>> DiffModel diff = DiffService.doDiff(match);
>> ModelInputSnapshot snapshot = DiffFactory.eINSTANCE
>> .createModelInputSnapshot();
>> snapshot.setMatch(match);
>> snapshot.setDiff(diff);
>>
>> CompareUI.openCompareDialog(
>> new ModelCompareEditorInput(modelInputSnapshot));
>>
>> -- snap
>>
>> But changing
>> match = MatchService.doMatch(lRoot, rRoot, options);
>> into
>> match = MatchService.doMatch(rRoot, lRoot, options);
>> WORKS!
>> Of course, the changings are the wrong way round. I am really
>> desperate because it depends on the right order.
>>
>> I attached the model I am working with. It is unfortunately in german
>> but that shouldn't matter.
>> By the way I am testing the Hide Property Refactoring with class Konto
>> (account) and property saldo (balance).
>>
>> match = MatchService.doMatch(lRoot, rRoot, options);
>> gets this diff:
>> Attribute visibility in saldo has changed from public to private
>>
>> org.eclipse.uml2.uml.internal.impl.OperationImpl@12c662b (name:
>> getSaldo, visibility: public) (isLeaf: false, isStatic: false,
>> isAbstract: false, concurrency: sequential) (isQuery: false) has been
>> *removed*
>>
>> org.eclipse.uml2.uml.internal.impl.OperationImpl@144f423 (name:
>> setSaldo, visibility: public) (isLeaf: false, isStatic: false,
>> isAbstract: false, concurrency: sequential) (isQuery: false) has been
>> *removed*
>>
>> but they are *added*
>>
>> whereas
>> match = MatchService.doMatch(rRoot, lRoot, options);
>> provides a correct diff:
>> Attribute visibility in saldo has changed from private to public
>>
>> org.eclipse.uml2.uml.internal.impl.OperationImpl@847410 (name:
>> getSaldo, visibility: public) (isLeaf: false, isStatic: false,
>> isAbstract: false, concurrency: sequential) (isQuery: false) has been
>> removed
>>
>> org.eclipse.uml2.uml.internal.impl.OperationImpl@12a6200 (name:
>> setSaldo, visibility: public) (isLeaf: false, isStatic: false,
>> isAbstract: false, concurrency: sequential) (isQuery: false) has been
>> removed
>>
>> thanks for your patience,
>> lars
>>
>> laurent Goubet wrote:
>>> Lars,
>>>
>>> Yup, GenericMatchEngine#modelMatch() does his work on the resource
>>> and will fail if it is null, though contentMatch() shouldn't. What
>>> puzzles me though is that GenericMatchEngine#hasSameURI() at ligne
>>> 1174 is :
>>> if (obj1.eResource() != null && obj2.eResource() != null)
>>>
>>> which means you're getting an NPE since one of the two compared
>>> objects are null, not their resources... Could you provide us with
>>> the model you're using as input? As a side note, did you take a look
>>> at ModelUtils#attachResource() to see if it would solve the problem?
>>>
>>> Laurent Goubet
>>> Obeo
>>>
>>> Lars Schneider a écrit :
>>>> and also with a doContentMatch I get a NullPointerException
>>>>
>>>> java.lang.NullPointerException
>>>> at
>>>> org.eclipse.emf.compare.match.engine.GenericMatchEngine.hasS ameUri(GenericMatchEngine.java:1174)
>>>>
>>>> at
>>>> org.eclipse.emf.compare.match.engine.GenericMatchEngine.isSi milar(GenericMatchEngine.java:593)
>>>>
>>>> at
>>>> org.eclipse.emf.compare.match.engine.GenericMatchEngine.cont entMatch(GenericMatchEngine.java:252)
>>>>
>>>> at
>>>> org.eclipse.emf.compare.match.service.MatchService.doContent Match(MatchService.java:118)
>>>>
>>>>
>>>>
>>>> Lars Schneider wrote:
>>>>> Hi Cédric,
>>>>>
>>>>> I updated to 0.8.0RC1 and still get a NullPointerException.
>>>>>
>>>>> java.lang.NullPointerException
>>>>> at
>>>>> org.eclipse.emf.compare.match.engine.GenericMatchEngine.filt erUnused(GenericMatchEngine.java:1094)
>>>>>
>>>>> at
>>>>> org.eclipse.emf.compare.match.engine.GenericMatchEngine.doMa tch(GenericMatchEngine.java:907)
>>>>>
>>>>> at
>>>>> org.eclipse.emf.compare.match.engine.GenericMatchEngine.mode lMatch(GenericMatchEngine.java:331)
>>>>>
>>>>> at
>>>>> org.eclipse.emf.compare.match.service.MatchService.doMatch(M atchService.java:174)
>>>>>
>>>>>
>>>>> GenericMatchEngine.doMatch calls
>>>>> result = doMatch(leftRoot.eResource(), rightRoot.eResource(),
>>>>> monitor);
>>>>> in line 331 which is obviously null if rightRoot has a null Resource.
>>>>>
>>>>>
>>>>> Cédric brun wrote:
>>>>>> Hi Lars,
>>>>>>
>>>>>> What EMF Compare build are you using ? The RC1 build should have
>>>>>> fixed this
>>>>>> NPE (bug 230347 - see the release
>>>>>> notes
>>>>>> :http://www.eclipse.org/modeling/emft/news/relnotes.php?proj ect=compare&version=0.8.0RC1
>>>>>> )
>>>>>>
>>>>>> You should not have to provide your own match engine for such a
>>>>>> thing :)
>>>>>>
>>>>>> Cédric
>>>>>>
>>>>>>
>>>>>> Lars Schneider wrote:
>>>>>>
>>>>>>> I think this problem is better of in this newsgroup.
>>>>>>>
>>>>>>>> Hi,
>>>>>>>> I have a little problem using EcoreUtil.copy(EObject) because the
>>>>>>>> eResource() of that copy returns null.
>>>>>>>>
>>>>>>>> More precisely I want to copy the root of a model, change it and
>>>>>>>> compare
>>>>>>>> it to the original with EMF Compare. I think the following code
>>>>>>>> snippet
>>>>>>>> explains it best:
>>>>>>>>
>>>>>>>> //...
>>>>>>>> EObject copy = EcoreUtil.copy(original);
>>>>>>>> Transformation trans = new Transformation(copy);
>>>>>>>> trans.transform(); // changes copy
>>>>>>>> MatchModel match = null;
>>>>>>>> try {
>>>>>>>> match = MatchService.doMatch(original, copy
>>>>>>>> Collections.<String, Object> emptyMap());
>>>>>>>> } catch (InterruptedException e) {
>>>>>>>> e.printStackTrace();
>>>>>>>> }
>>>>>>>> //...
>>>>>>>>
>>>>>>>> The problem is that doMatch(...) ends up in a NullPointerException
>>>>>>>> because the resource of copy is null. Does anyone have an idea
>>>>>>>> how to
>>>>>>>> solve this problem? I think I can either set the resource
>>>>>>>> manually or
>>>>>>>> get another IMatchEngine implementation. But I don't know how to.
>>>>>>>> Lars
>>>>>>
>>>
>


--------------000305010601080701030908
Content-Type: text/x-vcard; charset=utf-8;
name="laurent_goubet.vcf"
Content-Transfer-Encoding: base64
Content-Disposition: attachment;
filename="laurent_goubet.vcf"

YmVnaW46dmNhcmQNCmZuOkxhdXJlbnQgR291YmV0DQpuOkdvdWJldDtMYXVy ZW50DQpvcmc6
PGEgaHJlZj0iaHR0cDovL3d3dy5vYmVvLmZyLyI+T2JlbzwvYT4NCmVtYWls O2ludGVybmV0
OmxhdXJlbnQuZ291YmV0QG9iZW8uZnINCnVybDpodHRwOi8vd3d3Lm9iZW8u ZnINCnZlcnNp
b246Mi4xDQplbmQ6dmNhcmQNCg0K
--------------000305010601080701030908--
Re: How to create a copy of an EObject with non-null Resource [message #619031 is a reply to message #123282] Wed, 28 May 2008 12:25 Go to previous message
Laurent Goubet is currently offline Laurent GoubetFriend
Messages: 1902
Registered: July 2009
Senior Member
This is a multi-part message in MIME format.
--------------020602020701040309050601
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit

Lars,

Okay, just tried this via the UI ... and it worked as expected. Yet I
think your problem comes from the URI you use for your models. The
snippet you provided will never produce differences since you load the
same model twice without ever modifiying it, so I think you modified the
snippet for visibility ;).

The generic diff engine doesn't know which resource is the left model
and which is the right when computing additions/deletions. All we have
are the model URIs as can be retrieved via MatchModel#getLeftModel() and
MatchModel#getRightModel() (these are Strings instead of resources ...
AFAIK, this was because of legacy code). If you have the same URI for
both ... the diff engine will only see *removed* elements.

Something like this should work as you are expecting (I think you were
copying your models so the following will make use of EcoreUtil.copy()) :
try {
lRoot = ModelUtils.load(modelURI, resourceSet);
rRoot = EcoreUtil.copy(lRoot);
// This URI should use the same extension, other than that, it can
point to anything if this copy isn't meant to be saved
ModelUtils.attachResource(copyModelURI, rRoot);
} catch (IOException e) {
e.printStackTrace();
}

And a little update : EMF Compare 0.8RC2 has been built and the changes
to GenericMatchEngine should have made its way through this time. The
build should be promoted today.

Cheers,

Laurent Goubet
Obeo

laurent Goubet a écrit :
> This would seem like a problem in the DiffEngine, I'll test this with
> your model ASAP. Though the fact your GenericMatchEngine is at an older
> version puzzles me ... the build came 3 days after I commited these
> changes ;(
>
> Lars Schneider a écrit :
>> sorry, here comes the attachment
>>
>> Lars Schneider wrote:
>>> It seems that I still have another version of GenericMatchEngine. My
>>> Method hasSameURI looks like this:
>>> private boolean hasSameUri(EObject obj1, EObject obj2) {
>>> return
>>> obj1.eResource().getURIFragment(obj1).equals(obj2.eResource( ).getURIFragment(obj2));
>>>
>>> }
>>>
>>> ModelUtils#attachResource() really solves the problem, so I can use
>>> GenericMatchEngine#doMatch(). But there is another strange behavior.
>>> I am using this snippet and it does NOT work because "diff" is partly
>>> wrong:
>>>
>>> -- snip
>>>
>>> EObject lRoot = null;
>>> EObject rRoot = null;
>>> try {
>>> rRoot = ModelUtils.load(modelURI, resourceSet);
>>> ModelUtils.attachResource(modelURI, rRoot);
>>> lRoot = ModelUtils.load(modelURI, resourceSet);
>>> ModelUtils.attachResource(modelURI, lRoot);
>>> } catch (IOException e) {
>>> e.printStackTrace();
>>> }
>>>
>>> Resource lResource = lRoot.eResource();
>>> Resource rResource = rRoot.eResource();
>>>
>>> Map<String, Object> options = Collections
>>> .<String, Object> emptyMap();
>>>
>>> MatchModel match = null;
>>>
>>> try {
>>> match = MatchService.doMatch(lRoot, rRoot, options);
>>> //match = MatchService.doContentMatch(lRoot, rRoot, options);
>>> //match = MatchService.doResourceMatch(lResource, rResource,
>>> options);
>>> } catch (InterruptedException e) {
>>> e.printStackTrace();
>>> }
>>> DiffModel diff = DiffService.doDiff(match);
>>> ModelInputSnapshot snapshot = DiffFactory.eINSTANCE
>>> .createModelInputSnapshot();
>>> snapshot.setMatch(match);
>>> snapshot.setDiff(diff);
>>>
>>> CompareUI.openCompareDialog(
>>> new ModelCompareEditorInput(modelInputSnapshot));
>>>
>>> -- snap
>>>
>>> But changing
>>> match = MatchService.doMatch(lRoot, rRoot, options);
>>> into
>>> match = MatchService.doMatch(rRoot, lRoot, options);
>>> WORKS!
>>> Of course, the changings are the wrong way round. I am really
>>> desperate because it depends on the right order.
>>>
>>> I attached the model I am working with. It is unfortunately in german
>>> but that shouldn't matter.
>>> By the way I am testing the Hide Property Refactoring with class
>>> Konto (account) and property saldo (balance).
>>>
>>> match = MatchService.doMatch(lRoot, rRoot, options);
>>> gets this diff:
>>> Attribute visibility in saldo has changed from public to private
>>>
>>> org.eclipse.uml2.uml.internal.impl.OperationImpl@12c662b (name:
>>> getSaldo, visibility: public) (isLeaf: false, isStatic: false,
>>> isAbstract: false, concurrency: sequential) (isQuery: false) has been
>>> *removed*
>>>
>>> org.eclipse.uml2.uml.internal.impl.OperationImpl@144f423 (name:
>>> setSaldo, visibility: public) (isLeaf: false, isStatic: false,
>>> isAbstract: false, concurrency: sequential) (isQuery: false) has been
>>> *removed*
>>>
>>> but they are *added*
>>>
>>> whereas
>>> match = MatchService.doMatch(rRoot, lRoot, options);
>>> provides a correct diff:
>>> Attribute visibility in saldo has changed from private to public
>>>
>>> org.eclipse.uml2.uml.internal.impl.OperationImpl@847410 (name:
>>> getSaldo, visibility: public) (isLeaf: false, isStatic: false,
>>> isAbstract: false, concurrency: sequential) (isQuery: false) has been
>>> removed
>>>
>>> org.eclipse.uml2.uml.internal.impl.OperationImpl@12a6200 (name:
>>> setSaldo, visibility: public) (isLeaf: false, isStatic: false,
>>> isAbstract: false, concurrency: sequential) (isQuery: false) has been
>>> removed
>>>
>>> thanks for your patience,
>>> lars
>>>
>>> laurent Goubet wrote:
>>>> Lars,
>>>>
>>>> Yup, GenericMatchEngine#modelMatch() does his work on the resource
>>>> and will fail if it is null, though contentMatch() shouldn't. What
>>>> puzzles me though is that GenericMatchEngine#hasSameURI() at ligne
>>>> 1174 is :
>>>> if (obj1.eResource() != null && obj2.eResource() != null)
>>>>
>>>> which means you're getting an NPE since one of the two compared
>>>> objects are null, not their resources... Could you provide us with
>>>> the model you're using as input? As a side note, did you take a look
>>>> at ModelUtils#attachResource() to see if it would solve the problem?
>>>>
>>>> Laurent Goubet
>>>> Obeo
>>>>
>>>> Lars Schneider a écrit :
>>>>> and also with a doContentMatch I get a NullPointerException
>>>>>
>>>>> java.lang.NullPointerException
>>>>> at
>>>>> org.eclipse.emf.compare.match.engine.GenericMatchEngine.hasS ameUri(GenericMatchEngine.java:1174)
>>>>>
>>>>> at
>>>>> org.eclipse.emf.compare.match.engine.GenericMatchEngine.isSi milar(GenericMatchEngine.java:593)
>>>>>
>>>>> at
>>>>> org.eclipse.emf.compare.match.engine.GenericMatchEngine.cont entMatch(GenericMatchEngine.java:252)
>>>>>
>>>>> at
>>>>> org.eclipse.emf.compare.match.service.MatchService.doContent Match(MatchService.java:118)
>>>>>
>>>>>
>>>>>
>>>>> Lars Schneider wrote:
>>>>>> Hi Cédric,
>>>>>>
>>>>>> I updated to 0.8.0RC1 and still get a NullPointerException.
>>>>>>
>>>>>> java.lang.NullPointerException
>>>>>> at
>>>>>> org.eclipse.emf.compare.match.engine.GenericMatchEngine.filt erUnused(GenericMatchEngine.java:1094)
>>>>>>
>>>>>> at
>>>>>> org.eclipse.emf.compare.match.engine.GenericMatchEngine.doMa tch(GenericMatchEngine.java:907)
>>>>>>
>>>>>> at
>>>>>> org.eclipse.emf.compare.match.engine.GenericMatchEngine.mode lMatch(GenericMatchEngine.java:331)
>>>>>>
>>>>>> at
>>>>>> org.eclipse.emf.compare.match.service.MatchService.doMatch(M atchService.java:174)
>>>>>>
>>>>>>
>>>>>> GenericMatchEngine.doMatch calls
>>>>>> result = doMatch(leftRoot.eResource(), rightRoot.eResource(),
>>>>>> monitor);
>>>>>> in line 331 which is obviously null if rightRoot has a null Resource.
>>>>>>
>>>>>>
>>>>>> Cédric brun wrote:
>>>>>>> Hi Lars,
>>>>>>>
>>>>>>> What EMF Compare build are you using ? The RC1 build should have
>>>>>>> fixed this
>>>>>>> NPE (bug 230347 - see the release
>>>>>>> notes
>>>>>>> :http://www.eclipse.org/modeling/emft/news/relnotes.php?proj ect=compare&version=0.8.0RC1
>>>>>>> )
>>>>>>>
>>>>>>> You should not have to provide your own match engine for such a
>>>>>>> thing :)
>>>>>>>
>>>>>>> Cédric
>>>>>>>
>>>>>>>
>>>>>>> Lars Schneider wrote:
>>>>>>>
>>>>>>>> I think this problem is better of in this newsgroup.
>>>>>>>>
>>>>>>>>> Hi,
>>>>>>>>> I have a little problem using EcoreUtil.copy(EObject) because the
>>>>>>>>> eResource() of that copy returns null.
>>>>>>>>>
>>>>>>>>> More precisely I want to copy the root of a model, change it
>>>>>>>>> and compare
>>>>>>>>> it to the original with EMF Compare. I think the following code
>>>>>>>>> snippet
>>>>>>>>> explains it best:
>>>>>>>>>
>>>>>>>>> //...
>>>>>>>>> EObject copy = EcoreUtil.copy(original);
>>>>>>>>> Transformation trans = new Transformation(copy);
>>>>>>>>> trans.transform(); // changes copy
>>>>>>>>> MatchModel match = null;
>>>>>>>>> try {
>>>>>>>>> match = MatchService.doMatch(original, copy
>>>>>>>>> Collections.<String, Object> emptyMap());
>>>>>>>>> } catch (InterruptedException e) {
>>>>>>>>> e.printStackTrace();
>>>>>>>>> }
>>>>>>>>> //...
>>>>>>>>>
>>>>>>>>> The problem is that doMatch(...) ends up in a NullPointerException
>>>>>>>>> because the resource of copy is null. Does anyone have an idea
>>>>>>>>> how to
>>>>>>>>> solve this problem? I think I can either set the resource
>>>>>>>>> manually or
>>>>>>>>> get another IMatchEngine implementation. But I don't know how to.
>>>>>>>>> Lars
>>>>>>>
>>>>
>>
>


--------------020602020701040309050601
Content-Type: text/x-vcard; charset=utf-8;
name="laurent_goubet.vcf"
Content-Transfer-Encoding: base64
Content-Disposition: attachment;
filename="laurent_goubet.vcf"

YmVnaW46dmNhcmQNCmZuOkxhdXJlbnQgR291YmV0DQpuOkdvdWJldDtMYXVy ZW50DQpvcmc6
PGEgaHJlZj0iaHR0cDovL3d3dy5vYmVvLmZyLyI+T2JlbzwvYT4NCmVtYWls O2ludGVybmV0
OmxhdXJlbnQuZ291YmV0QG9iZW8uZnINCnVybDpodHRwOi8vd3d3Lm9iZW8u ZnINCnZlcnNp
b246Mi4xDQplbmQ6dmNhcmQNCg0K
--------------020602020701040309050601--
Re: How to create a copy of an EObject with non-null Resource [message #619035 is a reply to message #123375] Wed, 28 May 2008 13:02 Go to previous message
Ed Merks is currently offline Ed MerksFriend
Messages: 33113
Registered: July 2009
Senior Member
Laurent,

Comments below.

laurent Goubet wrote:
> Lars,
>
> Okay, just tried this via the UI ... and it worked as expected. Yet I
> think your problem comes from the URI you use for your models. The
> snippet you provided will never produce differences since you load the
> same model twice without ever modifiying it, so I think you modified
> the snippet for visibility ;).
>
> The generic diff engine doesn't know which resource is the left model
> and which is the right when computing additions/deletions. All we have
> are the model URIs as can be retrieved via MatchModel#getLeftModel()
> and MatchModel#getRightModel() (these are Strings instead of resources
> ... AFAIK, this was because of legacy code). If you have the same URI
> for both ... the diff engine will only see *removed* elements.
I can see the BIDI defects now about the fact that the left model
appears on the right in the UI. :-P
>
> Something like this should work as you are expecting (I think you were
> copying your models so the following will make use of EcoreUtil.copy()) :
> try {
> lRoot = ModelUtils.load(modelURI, resourceSet);
> rRoot = EcoreUtil.copy(lRoot);
> // This URI should use the same extension, other than that, it can
> point to anything if this copy isn't meant to be saved
> ModelUtils.attachResource(copyModelURI, rRoot);
> } catch (IOException e) {
> e.printStackTrace();
> }
>
> And a little update : EMF Compare 0.8RC2 has been built and the
> changes to GenericMatchEngine should have made its way through this
> time. The build should be promoted today.
>
> Cheers,
>
> Laurent Goubet
> Obeo
>
> laurent Goubet a écrit :
>> This would seem like a problem in the DiffEngine, I'll test this with
>> your model ASAP. Though the fact your GenericMatchEngine is at an
>> older version puzzles me ... the build came 3 days after I commited
>> these changes ;(
>>
>> Lars Schneider a écrit :
>>> sorry, here comes the attachment
>>>
>>> Lars Schneider wrote:
>>>> It seems that I still have another version of GenericMatchEngine.
>>>> My Method hasSameURI looks like this:
>>>> private boolean hasSameUri(EObject obj1, EObject obj2) {
>>>> return
>>>> obj1.eResource().getURIFragment(obj1).equals(obj2.eResource( ).getURIFragment(obj2));
>>>>
>>>> }
>>>>
>>>> ModelUtils#attachResource() really solves the problem, so I can use
>>>> GenericMatchEngine#doMatch(). But there is another strange behavior.
>>>> I am using this snippet and it does NOT work because "diff" is
>>>> partly wrong:
>>>>
>>>> -- snip
>>>>
>>>> EObject lRoot = null;
>>>> EObject rRoot = null;
>>>> try {
>>>> rRoot = ModelUtils.load(modelURI, resourceSet);
>>>> ModelUtils.attachResource(modelURI, rRoot);
>>>> lRoot = ModelUtils.load(modelURI, resourceSet);
>>>> ModelUtils.attachResource(modelURI, lRoot);
>>>> } catch (IOException e) {
>>>> e.printStackTrace();
>>>> }
>>>>
>>>> Resource lResource = lRoot.eResource();
>>>> Resource rResource = rRoot.eResource();
>>>>
>>>> Map<String, Object> options = Collections
>>>> .<String, Object> emptyMap();
>>>>
>>>> MatchModel match = null;
>>>>
>>>> try {
>>>> match = MatchService.doMatch(lRoot, rRoot, options);
>>>> //match = MatchService.doContentMatch(lRoot, rRoot, options);
>>>> //match = MatchService.doResourceMatch(lResource, rResource,
>>>> options);
>>>> } catch (InterruptedException e) {
>>>> e.printStackTrace();
>>>> }
>>>> DiffModel diff = DiffService.doDiff(match);
>>>> ModelInputSnapshot snapshot = DiffFactory.eINSTANCE
>>>> .createModelInputSnapshot();
>>>> snapshot.setMatch(match);
>>>> snapshot.setDiff(diff);
>>>>
>>>> CompareUI.openCompareDialog(
>>>> new ModelCompareEditorInput(modelInputSnapshot));
>>>>
>>>> -- snap
>>>>
>>>> But changing
>>>> match = MatchService.doMatch(lRoot, rRoot, options);
>>>> into
>>>> match = MatchService.doMatch(rRoot, lRoot, options);
>>>> WORKS!
>>>> Of course, the changings are the wrong way round. I am really
>>>> desperate because it depends on the right order.
>>>>
>>>> I attached the model I am working with. It is unfortunately in
>>>> german but that shouldn't matter.
>>>> By the way I am testing the Hide Property Refactoring with class
>>>> Konto (account) and property saldo (balance).
>>>>
>>>> match = MatchService.doMatch(lRoot, rRoot, options);
>>>> gets this diff:
>>>> Attribute visibility in saldo has changed from public to private
>>>>
>>>> org.eclipse.uml2.uml.internal.impl.OperationImpl@12c662b (name:
>>>> getSaldo, visibility: public) (isLeaf: false, isStatic: false,
>>>> isAbstract: false, concurrency: sequential) (isQuery: false) has
>>>> been *removed*
>>>>
>>>> org.eclipse.uml2.uml.internal.impl.OperationImpl@144f423 (name:
>>>> setSaldo, visibility: public) (isLeaf: false, isStatic: false,
>>>> isAbstract: false, concurrency: sequential) (isQuery: false) has
>>>> been *removed*
>>>>
>>>> but they are *added*
>>>>
>>>> whereas
>>>> match = MatchService.doMatch(rRoot, lRoot, options);
>>>> provides a correct diff:
>>>> Attribute visibility in saldo has changed from private to public
>>>>
>>>> org.eclipse.uml2.uml.internal.impl.OperationImpl@847410 (name:
>>>> getSaldo, visibility: public) (isLeaf: false, isStatic: false,
>>>> isAbstract: false, concurrency: sequential) (isQuery: false) has
>>>> been removed
>>>>
>>>> org.eclipse.uml2.uml.internal.impl.OperationImpl@12a6200 (name:
>>>> setSaldo, visibility: public) (isLeaf: false, isStatic: false,
>>>> isAbstract: false, concurrency: sequential) (isQuery: false) has
>>>> been removed
>>>>
>>>> thanks for your patience,
>>>> lars
>>>>
>>>> laurent Goubet wrote:
>>>>> Lars,
>>>>>
>>>>> Yup, GenericMatchEngine#modelMatch() does his work on the resource
>>>>> and will fail if it is null, though contentMatch() shouldn't. What
>>>>> puzzles me though is that GenericMatchEngine#hasSameURI() at ligne
>>>>> 1174 is :
>>>>> if (obj1.eResource() != null && obj2.eResource() != null)
>>>>>
>>>>> which means you're getting an NPE since one of the two compared
>>>>> objects are null, not their resources... Could you provide us with
>>>>> the model you're using as input? As a side note, did you take a
>>>>> look at ModelUtils#attachResource() to see if it would solve the
>>>>> problem?
>>>>>
>>>>> Laurent Goubet
>>>>> Obeo
>>>>>
>>>>> Lars Schneider a écrit :
>>>>>> and also with a doContentMatch I get a NullPointerException
>>>>>>
>>>>>> java.lang.NullPointerException
>>>>>> at
>>>>>> org.eclipse.emf.compare.match.engine.GenericMatchEngine.hasS ameUri(GenericMatchEngine.java:1174)
>>>>>>
>>>>>> at
>>>>>> org.eclipse.emf.compare.match.engine.GenericMatchEngine.isSi milar(GenericMatchEngine.java:593)
>>>>>>
>>>>>> at
>>>>>> org.eclipse.emf.compare.match.engine.GenericMatchEngine.cont entMatch(GenericMatchEngine.java:252)
>>>>>>
>>>>>> at
>>>>>> org.eclipse.emf.compare.match.service.MatchService.doContent Match(MatchService.java:118)
>>>>>>
>>>>>>
>>>>>>
>>>>>> Lars Schneider wrote:
>>>>>>> Hi Cédric,
>>>>>>>
>>>>>>> I updated to 0.8.0RC1 and still get a NullPointerException.
>>>>>>>
>>>>>>> java.lang.NullPointerException
>>>>>>> at
>>>>>>> org.eclipse.emf.compare.match.engine.GenericMatchEngine.filt erUnused(GenericMatchEngine.java:1094)
>>>>>>>
>>>>>>> at
>>>>>>> org.eclipse.emf.compare.match.engine.GenericMatchEngine.doMa tch(GenericMatchEngine.java:907)
>>>>>>>
>>>>>>> at
>>>>>>> org.eclipse.emf.compare.match.engine.GenericMatchEngine.mode lMatch(GenericMatchEngine.java:331)
>>>>>>>
>>>>>>> at
>>>>>>> org.eclipse.emf.compare.match.service.MatchService.doMatch(M atchService.java:174)
>>>>>>>
>>>>>>>
>>>>>>> GenericMatchEngine.doMatch calls
>>>>>>> result = doMatch(leftRoot.eResource(), rightRoot.eResource(),
>>>>>>> monitor);
>>>>>>> in line 331 which is obviously null if rightRoot has a null
>>>>>>> Resource.
>>>>>>>
>>>>>>>
>>>>>>> Cédric brun wrote:
>>>>>>>> Hi Lars,
>>>>>>>>
>>>>>>>> What EMF Compare build are you using ? The RC1 build should
>>>>>>>> have fixed this
>>>>>>>> NPE (bug 230347 - see the release
>>>>>>>> notes
>>>>>>>> :http://www.eclipse.org/modeling/emft/news/relnotes.php?proj ect=compare&version=0.8.0RC1
>>>>>>>> )
>>>>>>>>
>>>>>>>> You should not have to provide your own match engine for such a
>>>>>>>> thing :)
>>>>>>>>
>>>>>>>> Cédric
>>>>>>>>
>>>>>>>>
>>>>>>>> Lars Schneider wrote:
>>>>>>>>
>>>>>>>>> I think this problem is better of in this newsgroup.
>>>>>>>>>
>>>>>>>>>> Hi,
>>>>>>>>>> I have a little problem using EcoreUtil.copy(EObject) because
>>>>>>>>>> the
>>>>>>>>>> eResource() of that copy returns null.
>>>>>>>>>>
>>>>>>>>>> More precisely I want to copy the root of a model, change it
>>>>>>>>>> and compare
>>>>>>>>>> it to the original with EMF Compare. I think the following
>>>>>>>>>> code snippet
>>>>>>>>>> explains it best:
>>>>>>>>>>
>>>>>>>>>> //...
>>>>>>>>>> EObject copy = EcoreUtil.copy(original);
>>>>>>>>>> Transformation trans = new Transformation(copy);
>>>>>>>>>> trans.transform(); // changes copy
>>>>>>>>>> MatchModel match = null;
>>>>>>>>>> try {
>>>>>>>>>> match = MatchService.doMatch(original, copy
>>>>>>>>>> Collections.<String, Object> emptyMap());
>>>>>>>>>> } catch (InterruptedException e) {
>>>>>>>>>> e.printStackTrace();
>>>>>>>>>> }
>>>>>>>>>> //...
>>>>>>>>>>
>>>>>>>>>> The problem is that doMatch(...) ends up in a
>>>>>>>>>> NullPointerException
>>>>>>>>>> because the resource of copy is null. Does anyone have an
>>>>>>>>>> idea how to
>>>>>>>>>> solve this problem? I think I can either set the resource
>>>>>>>>>> manually or
>>>>>>>>>> get another IMatchEngine implementation. But I don't know how
>>>>>>>>>> to.
>>>>>>>>>> Lars
>>>>>>>>
>>>>>
>>>
>>
>


Ed Merks
Professional Support: https://www.macromodeling.com/
Re: How to create a copy of an EObject with non-null Resource [message #619038 is a reply to message #123388] Wed, 28 May 2008 13:20 Go to previous message
Laurent Goubet is currently offline Laurent GoubetFriend
Messages: 1902
Registered: July 2009
Senior Member
This is a multi-part message in MIME format.
--------------020801030101010103000600
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit

Ed,

BIDI?

And no ... left appearing in the right also comes from a (discutable)
choice from our side ... and will be reverted back to normal as soon as
we come to https://bugs.eclipse.org/bugs/show_bug.cgi?id=232277 .

Laurent Goubet
Obeo

Ed Merks a écrit :
> Laurent,
>
> Comments below.
>
> laurent Goubet wrote:
>> Lars,
>>
>> Okay, just tried this via the UI ... and it worked as expected. Yet I
>> think your problem comes from the URI you use for your models. The
>> snippet you provided will never produce differences since you load the
>> same model twice without ever modifiying it, so I think you modified
>> the snippet for visibility ;).
>>
>> The generic diff engine doesn't know which resource is the left model
>> and which is the right when computing additions/deletions. All we have
>> are the model URIs as can be retrieved via MatchModel#getLeftModel()
>> and MatchModel#getRightModel() (these are Strings instead of resources
>> ... AFAIK, this was because of legacy code). If you have the same URI
>> for both ... the diff engine will only see *removed* elements.
> I can see the BIDI defects now about the fact that the left model
> appears on the right in the UI. :-P
>>
>> Something like this should work as you are expecting (I think you were
>> copying your models so the following will make use of EcoreUtil.copy()) :
>> try {
>> lRoot = ModelUtils.load(modelURI, resourceSet);
>> rRoot = EcoreUtil.copy(lRoot);
>> // This URI should use the same extension, other than that, it can
>> point to anything if this copy isn't meant to be saved
>> ModelUtils.attachResource(copyModelURI, rRoot);
>> } catch (IOException e) {
>> e.printStackTrace();
>> }
>>
>> And a little update : EMF Compare 0.8RC2 has been built and the
>> changes to GenericMatchEngine should have made its way through this
>> time. The build should be promoted today.
>>
>> Cheers,
>>
>> Laurent Goubet
>> Obeo
>>
>> laurent Goubet a écrit :
>>> This would seem like a problem in the DiffEngine, I'll test this with
>>> your model ASAP. Though the fact your GenericMatchEngine is at an
>>> older version puzzles me ... the build came 3 days after I commited
>>> these changes ;(
>>>
>>> Lars Schneider a écrit :
>>>> sorry, here comes the attachment
>>>>
>>>> Lars Schneider wrote:
>>>>> It seems that I still have another version of GenericMatchEngine.
>>>>> My Method hasSameURI looks like this:
>>>>> private boolean hasSameUri(EObject obj1, EObject obj2) {
>>>>> return
>>>>> obj1.eResource().getURIFragment(obj1).equals(obj2.eResource( ).getURIFragment(obj2));
>>>>>
>>>>> }
>>>>>
>>>>> ModelUtils#attachResource() really solves the problem, so I can use
>>>>> GenericMatchEngine#doMatch(). But there is another strange behavior.
>>>>> I am using this snippet and it does NOT work because "diff" is
>>>>> partly wrong:
>>>>>
>>>>> -- snip
>>>>>
>>>>> EObject lRoot = null;
>>>>> EObject rRoot = null;
>>>>> try {
>>>>> rRoot = ModelUtils.load(modelURI, resourceSet);
>>>>> ModelUtils.attachResource(modelURI, rRoot);
>>>>> lRoot = ModelUtils.load(modelURI, resourceSet);
>>>>> ModelUtils.attachResource(modelURI, lRoot);
>>>>> } catch (IOException e) {
>>>>> e.printStackTrace();
>>>>> }
>>>>>
>>>>> Resource lResource = lRoot.eResource();
>>>>> Resource rResource = rRoot.eResource();
>>>>>
>>>>> Map<String, Object> options = Collections
>>>>> .<String, Object> emptyMap();
>>>>>
>>>>> MatchModel match = null;
>>>>>
>>>>> try {
>>>>> match = MatchService.doMatch(lRoot, rRoot, options);
>>>>> //match = MatchService.doContentMatch(lRoot, rRoot, options);
>>>>> //match = MatchService.doResourceMatch(lResource, rResource,
>>>>> options);
>>>>> } catch (InterruptedException e) {
>>>>> e.printStackTrace();
>>>>> }
>>>>> DiffModel diff = DiffService.doDiff(match);
>>>>> ModelInputSnapshot snapshot = DiffFactory.eINSTANCE
>>>>> .createModelInputSnapshot();
>>>>> snapshot.setMatch(match);
>>>>> snapshot.setDiff(diff);
>>>>>
>>>>> CompareUI.openCompareDialog(
>>>>> new ModelCompareEditorInput(modelInputSnapshot));
>>>>>
>>>>> -- snap
>>>>>
>>>>> But changing
>>>>> match = MatchService.doMatch(lRoot, rRoot, options);
>>>>> into
>>>>> match = MatchService.doMatch(rRoot, lRoot, options);
>>>>> WORKS!
>>>>> Of course, the changings are the wrong way round. I am really
>>>>> desperate because it depends on the right order.
>>>>>
>>>>> I attached the model I am working with. It is unfortunately in
>>>>> german but that shouldn't matter.
>>>>> By the way I am testing the Hide Property Refactoring with class
>>>>> Konto (account) and property saldo (balance).
>>>>>
>>>>> match = MatchService.doMatch(lRoot, rRoot, options);
>>>>> gets this diff:
>>>>> Attribute visibility in saldo has changed from public to private
>>>>>
>>>>> org.eclipse.uml2.uml.internal.impl.OperationImpl@12c662b (name:
>>>>> getSaldo, visibility: public) (isLeaf: false, isStatic: false,
>>>>> isAbstract: false, concurrency: sequential) (isQuery: false) has
>>>>> been *removed*
>>>>>
>>>>> org.eclipse.uml2.uml.internal.impl.OperationImpl@144f423 (name:
>>>>> setSaldo, visibility: public) (isLeaf: false, isStatic: false,
>>>>> isAbstract: false, concurrency: sequential) (isQuery: false) has
>>>>> been *removed*
>>>>>
>>>>> but they are *added*
>>>>>
>>>>> whereas
>>>>> match = MatchService.doMatch(rRoot, lRoot, options);
>>>>> provides a correct diff:
>>>>> Attribute visibility in saldo has changed from private to public
>>>>>
>>>>> org.eclipse.uml2.uml.internal.impl.OperationImpl@847410 (name:
>>>>> getSaldo, visibility: public) (isLeaf: false, isStatic: false,
>>>>> isAbstract: false, concurrency: sequential) (isQuery: false) has
>>>>> been removed
>>>>>
>>>>> org.eclipse.uml2.uml.internal.impl.OperationImpl@12a6200 (name:
>>>>> setSaldo, visibility: public) (isLeaf: false, isStatic: false,
>>>>> isAbstract: false, concurrency: sequential) (isQuery: false) has
>>>>> been removed
>>>>>
>>>>> thanks for your patience,
>>>>> lars
>>>>>
>>>>> laurent Goubet wrote:
>>>>>> Lars,
>>>>>>
>>>>>> Yup, GenericMatchEngine#modelMatch() does his work on the resource
>>>>>> and will fail if it is null, though contentMatch() shouldn't. What
>>>>>> puzzles me though is that GenericMatchEngine#hasSameURI() at ligne
>>>>>> 1174 is :
>>>>>> if (obj1.eResource() != null && obj2.eResource() != null)
>>>>>>
>>>>>> which means you're getting an NPE since one of the two compared
>>>>>> objects are null, not their resources... Could you provide us with
>>>>>> the model you're using as input? As a side note, did you take a
>>>>>> look at ModelUtils#attachResource() to see if it would solve the
>>>>>> problem?
>>>>>>
>>>>>> Laurent Goubet
>>>>>> Obeo
>>>>>>
>>>>>> Lars Schneider a écrit :
>>>>>>> and also with a doContentMatch I get a NullPointerException
>>>>>>>
>>>>>>> java.lang.NullPointerException
>>>>>>> at
>>>>>>> org.eclipse.emf.compare.match.engine.GenericMatchEngine.hasS ameUri(GenericMatchEngine.java:1174)
>>>>>>>
>>>>>>> at
>>>>>>> org.eclipse.emf.compare.match.engine.GenericMatchEngine.isSi milar(GenericMatchEngine.java:593)
>>>>>>>
>>>>>>> at
>>>>>>> org.eclipse.emf.compare.match.engine.GenericMatchEngine.cont entMatch(GenericMatchEngine.java:252)
>>>>>>>
>>>>>>> at
>>>>>>> org.eclipse.emf.compare.match.service.MatchService.doContent Match(MatchService.java:118)
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>> Lars Schneider wrote:
>>>>>>>> Hi Cédric,
>>>>>>>>
>>>>>>>> I updated to 0.8.0RC1 and still get a NullPointerException.
>>>>>>>>
>>>>>>>> java.lang.NullPointerException
>>>>>>>> at
>>>>>>>> org.eclipse.emf.compare.match.engine.GenericMatchEngine.filt erUnused(GenericMatchEngine.java:1094)
>>>>>>>>
>>>>>>>> at
>>>>>>>> org.eclipse.emf.compare.match.engine.GenericMatchEngine.doMa tch(GenericMatchEngine.java:907)
>>>>>>>>
>>>>>>>> at
>>>>>>>> org.eclipse.emf.compare.match.engine.GenericMatchEngine.mode lMatch(GenericMatchEngine.java:331)
>>>>>>>>
>>>>>>>> at
>>>>>>>> org.eclipse.emf.compare.match.service.MatchService.doMatch(M atchService.java:174)
>>>>>>>>
>>>>>>>>
>>>>>>>> GenericMatchEngine.doMatch calls
>>>>>>>> result = doMatch(leftRoot.eResource(), rightRoot.eResource(),
>>>>>>>> monitor);
>>>>>>>> in line 331 which is obviously null if rightRoot has a null
>>>>>>>> Resource.
>>>>>>>>
>>>>>>>>
>>>>>>>> Cédric brun wrote:
>>>>>>>>> Hi Lars,
>>>>>>>>>
>>>>>>>>> What EMF Compare build are you using ? The RC1 build should
>>>>>>>>> have fixed this
>>>>>>>>> NPE (bug 230347 - see the release
>>>>>>>>> notes
>>>>>>>>> :http://www.eclipse.org/modeling/emft/news/relnotes.php?proj ect=compare&version=0.8.0RC1
>>>>>>>>> )
>>>>>>>>>
>>>>>>>>> You should not have to provide your own match engine for such a
>>>>>>>>> thing :)
>>>>>>>>>
>>>>>>>>> Cédric
>>>>>>>>>
>>>>>>>>>
>>>>>>>>> Lars Schneider wrote:
>>>>>>>>>
>>>>>>>>>> I think this problem is better of in this newsgroup.
>>>>>>>>>>
>>>>>>>>>>> Hi,
>>>>>>>>>>> I have a little problem using EcoreUtil.copy(EObject) because
>>>>>>>>>>> the
>>>>>>>>>>> eResource() of that copy returns null.
>>>>>>>>>>>
>>>>>>>>>>> More precisely I want to copy the root of a model, change it
>>>>>>>>>>> and compare
>>>>>>>>>>> it to the original with EMF Compare. I think the following
>>>>>>>>>>> code snippet
>>>>>>>>>>> explains it best:
>>>>>>>>>>>
>>>>>>>>>>> //...
>>>>>>>>>>> EObject copy = EcoreUtil.copy(original);
>>>>>>>>>>> Transformation trans = new Transformation(copy);
>>>>>>>>>>> trans.transform(); // changes copy
>>>>>>>>>>> MatchModel match = null;
>>>>>>>>>>> try {
>>>>>>>>>>> match = MatchService.doMatch(original, copy
>>>>>>>>>>> Collections.<String, Object> emptyMap());
>>>>>>>>>>> } catch (InterruptedException e) {
>>>>>>>>>>> e.printStackTrace();
>>>>>>>>>>> }
>>>>>>>>>>> //...
>>>>>>>>>>>
>>>>>>>>>>> The problem is that doMatch(...) ends up in a
>>>>>>>>>>> NullPointerException
>>>>>>>>>>> because the resource of copy is null. Does anyone have an
>>>>>>>>>>> idea how to
>>>>>>>>>>> solve this problem? I think I can either set the resource
>>>>>>>>>>> manually or
>>>>>>>>>>> get another IMatchEngine implementation. But I don't know how
>>>>>>>>>>> to.
>>>>>>>>>>> Lars
>>>>>>>>>
>>>>>>
>>>>
>>>
>>


--------------020801030101010103000600
Content-Type: text/x-vcard; charset=utf-8;
name="laurent_goubet.vcf"
Content-Transfer-Encoding: base64
Content-Disposition: attachment;
filename="laurent_goubet.vcf"

YmVnaW46dmNhcmQNCmZuOkxhdXJlbnQgR291YmV0DQpuOkdvdWJldDtMYXVy ZW50DQpvcmc6
PGEgaHJlZj0iaHR0cDovL3d3dy5vYmVvLmZyLyI+T2JlbzwvYT4NCmVtYWls O2ludGVybmV0
OmxhdXJlbnQuZ291YmV0QG9iZW8uZnINCnVybDpodHRwOi8vd3d3Lm9iZW8u ZnINCnZlcnNp
b246Mi4xDQplbmQ6dmNhcmQNCg0K
--------------020801030101010103000600--
Re: How to create a copy of an EObject with non-null Resource [message #619050 is a reply to message #123402] Wed, 28 May 2008 14:31 Go to previous message
Ed Merks is currently offline Ed MerksFriend
Messages: 33113
Registered: July 2009
Senior Member
This is a multi-part message in MIME format.
--------------010002060507070000070800
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit

Laurent,

Try running Eclipse with -dir rtl. It's even more fun if you use a
Hebrew or Arabic locale and have actual right to left characters it's
even more fun. And if you mix them all up, the fun in simply endless:

https://bugs.eclipse.org/bugs/show_bug.cgi?id=131711


laurent Goubet wrote:
> Ed,
>
> BIDI?
>
> And no ... left appearing in the right also comes from a (discutable)
> choice from our side ... and will be reverted back to normal as soon
> as we come to https://bugs.eclipse.org/bugs/show_bug.cgi?id=232277 .
>
> Laurent Goubet
> Obeo
>
> Ed Merks a écrit :
>> Laurent,
>>
>> Comments below.
>>
>> laurent Goubet wrote:
>>> Lars,
>>>
>>> Okay, just tried this via the UI ... and it worked as expected. Yet
>>> I think your problem comes from the URI you use for your models. The
>>> snippet you provided will never produce differences since you load
>>> the same model twice without ever modifiying it, so I think you
>>> modified the snippet for visibility ;).
>>>
>>> The generic diff engine doesn't know which resource is the left
>>> model and which is the right when computing additions/deletions. All
>>> we have are the model URIs as can be retrieved via
>>> MatchModel#getLeftModel() and MatchModel#getRightModel() (these are
>>> Strings instead of resources ... AFAIK, this was because of legacy
>>> code). If you have the same URI for both ... the diff engine will
>>> only see *removed* elements.
>> I can see the BIDI defects now about the fact that the left model
>> appears on the right in the UI. :-P
>>>
>>> Something like this should work as you are expecting (I think you
>>> were copying your models so the following will make use of
>>> EcoreUtil.copy()) :
>>> try {
>>> lRoot = ModelUtils.load(modelURI, resourceSet);
>>> rRoot = EcoreUtil.copy(lRoot);
>>> // This URI should use the same extension, other than that, it
>>> can point to anything if this copy isn't meant to be saved
>>> ModelUtils.attachResource(copyModelURI, rRoot);
>>> } catch (IOException e) {
>>> e.printStackTrace();
>>> }
>>>
>>> And a little update : EMF Compare 0.8RC2 has been built and the
>>> changes to GenericMatchEngine should have made its way through this
>>> time. The build should be promoted today.
>>>
>>> Cheers,
>>>
>>> Laurent Goubet
>>> Obeo
>>>
>>> laurent Goubet a écrit :
>>>> This would seem like a problem in the DiffEngine, I'll test this
>>>> with your model ASAP. Though the fact your GenericMatchEngine is at
>>>> an older version puzzles me ... the build came 3 days after I
>>>> commited these changes ;(
>>>>
>>>> Lars Schneider a écrit :
>>>>> sorry, here comes the attachment
>>>>>
>>>>> Lars Schneider wrote:
>>>>>> It seems that I still have another version of GenericMatchEngine.
>>>>>> My Method hasSameURI looks like this:
>>>>>> private boolean hasSameUri(EObject obj1, EObject obj2) {
>>>>>> return
>>>>>> obj1.eResource().getURIFragment(obj1).equals(obj2.eResource( ).getURIFragment(obj2));
>>>>>>
>>>>>> }
>>>>>>
>>>>>> ModelUtils#attachResource() really solves the problem, so I can
>>>>>> use GenericMatchEngine#doMatch(). But there is another strange
>>>>>> behavior.
>>>>>> I am using this snippet and it does NOT work because "diff" is
>>>>>> partly wrong:
>>>>>>
>>>>>> -- snip
>>>>>>
>>>>>> EObject lRoot = null;
>>>>>> EObject rRoot = null;
>>>>>> try {
>>>>>> rRoot = ModelUtils.load(modelURI, resourceSet);
>>>>>> ModelUtils.attachResource(modelURI, rRoot);
>>>>>> lRoot = ModelUtils.load(modelURI, resourceSet);
>>>>>> ModelUtils.attachResource(modelURI, lRoot);
>>>>>> } catch (IOException e) {
>>>>>> e.printStackTrace();
>>>>>> }
>>>>>>
>>>>>> Resource lResource = lRoot.eResource();
>>>>>> Resource rResource = rRoot.eResource();
>>>>>>
>>>>>> Map<String, Object> options = Collections
>>>>>> .<String, Object> emptyMap();
>>>>>>
>>>>>> MatchModel match = null;
>>>>>>
>>>>>> try {
>>>>>> match = MatchService.doMatch(lRoot, rRoot, options);
>>>>>> //match = MatchService.doContentMatch(lRoot, rRoot, options);
>>>>>> //match = MatchService.doResourceMatch(lResource, rResource,
>>>>>> options);
>>>>>> } catch (InterruptedException e) {
>>>>>> e.printStackTrace();
>>>>>> }
>>>>>> DiffModel diff = DiffService.doDiff(match);
>>>>>> ModelInputSnapshot snapshot = DiffFactory.eINSTANCE
>>>>>> .createModelInputSnapshot();
>>>>>> snapshot.setMatch(match);
>>>>>> snapshot.setDiff(diff);
>>>>>>
>>>>>> CompareUI.openCompareDialog(
>>>>>> new ModelCompareEditorInput(modelInputSnapshot));
>>>>>>
>>>>>> -- snap
>>>>>>
>>>>>> But changing
>>>>>> match = MatchService.doMatch(lRoot, rRoot, options);
>>>>>> into
>>>>>> match = MatchService.doMatch(rRoot, lRoot, options);
>>>>>> WORKS!
>>>>>> Of course, the changings are the wrong way round. I am really
>>>>>> desperate because it depends on the right order.
>>>>>>
>>>>>> I attached the model I am working with. It is unfortunately in
>>>>>> german but that shouldn't matter.
>>>>>> By the way I am testing the Hide Property Refactoring with class
>>>>>> Konto (account) and property saldo (balance).
>>>>>>
>>>>>> match = MatchService.doMatch(lRoot, rRoot, options);
>>>>>> gets this diff:
>>>>>> Attribute visibility in saldo has changed from public to private
>>>>>>
>>>>>> org.eclipse.uml2.uml.internal.impl.OperationImpl@12c662b
>>>>>> (name: getSaldo, visibility: public) (isLeaf: false, isStatic:
>>>>>> false, isAbstract: false, concurrency: sequential) (isQuery:
>>>>>> false) has been *removed*
>>>>>>
>>>>>> org.eclipse.uml2.uml.internal.impl.OperationImpl@144f423
>>>>>> (name: setSaldo, visibility: public) (isLeaf: false, isStatic:
>>>>>> false, isAbstract: false, concurrency: sequential) (isQuery:
>>>>>> false) has been *removed*
>>>>>>
>>>>>> but they are *added*
>>>>>>
>>>>>> whereas
>>>>>> match = MatchService.doMatch(rRoot, lRoot, options);
>>>>>> provides a correct diff:
>>>>>> Attribute visibility in saldo has changed from private to public
>>>>>>
>>>>>> org.eclipse.uml2.uml.internal.impl.OperationImpl@847410
>>>>>> (name: getSaldo, visibility: public) (isLeaf: false, isStatic:
>>>>>> false, isAbstract: false, concurrency: sequential) (isQuery:
>>>>>> false) has been removed
>>>>>>
>>>>>> org.eclipse.uml2.uml.internal.impl.OperationImpl@12a6200
>>>>>> (name: setSaldo, visibility: public) (isLeaf: false, isStatic:
>>>>>> false, isAbstract: false, concurrency: sequential) (isQuery:
>>>>>> false) has been removed
>>>>>>
>>>>>> thanks for your patience,
>>>>>> lars
>>>>>>
>>>>>> laurent Goubet wrote:
>>>>>>> Lars,
>>>>>>>
>>>>>>> Yup, GenericMatchEngine#modelMatch() does his work on the
>>>>>>> resource and will fail if it is null, though contentMatch()
>>>>>>> shouldn't. What puzzles me though is that
>>>>>>> GenericMatchEngine#hasSameURI() at ligne 1174 is :
>>>>>>> if (obj1.eResource() != null && obj2.eResource() != null)
>>>>>>>
>>>>>>> which means you're getting an NPE since one of the two compared
>>>>>>> objects are null, not their resources... Could you provide us
>>>>>>> with the model you're using as input? As a side note, did you
>>>>>>> take a look at ModelUtils#attachResource() to see if it would
>>>>>>> solve the problem?
>>>>>>>
>>>>>>> Laurent Goubet
>>>>>>> Obeo
>>>>>>>
>>>>>>> Lars Schneider a écrit :
>>>>>>>> and also with a doContentMatch I get a NullPointerException
>>>>>>>>
>>>>>>>> java.lang.NullPointerException
>>>>>>>> at
>>>>>>>> org.eclipse.emf.compare.match.engine.GenericMatchEngine.hasS ameUri(GenericMatchEngine.java:1174)
>>>>>>>>
>>>>>>>> at
>>>>>>>> org.eclipse.emf.compare.match.engine.GenericMatchEngine.isSi milar(GenericMatchEngine.java:593)
>>>>>>>>
>>>>>>>> at
>>>>>>>> org.eclipse.emf.compare.match.engine.GenericMatchEngine.cont entMatch(GenericMatchEngine.java:252)
>>>>>>>>
>>>>>>>> at
>>>>>>>> org.eclipse.emf.compare.match.service.MatchService.doContent Match(MatchService.java:118)
>>>>>>>>
>>>>>>>>
>>>>>>>>
>>>>>>>> Lars Schneider wrote:
>>>>>>>>> Hi Cédric,
>>>>>>>>>
>>>>>>>>> I updated to 0.8.0RC1 and still get a NullPointerException.
>>>>>>>>>
>>>>>>>>> java.lang.NullPointerException
>>>>>>>>> at
>>>>>>>>> org.eclipse.emf.compare.match.engine.GenericMatchEngine.filt erUnused(GenericMatchEngine.java:1094)
>>>>>>>>>
>>>>>>>>> at
>>>>>>>>> org.eclipse.emf.compare.match.engine.GenericMatchEngine.doMa tch(GenericMatchEngine.java:907)
>>>>>>>>>
>>>>>>>>> at
>>>>>>>>> org.eclipse.emf.compare.match.engine.GenericMatchEngine.mode lMatch(GenericMatchEngine.java:331)
>>>>>>>>>
>>>>>>>>> at
>>>>>>>>> org.eclipse.emf.compare.match.service.MatchService.doMatch(M atchService.java:174)
>>>>>>>>>
>>>>>>>>>
>>>>>>>>> GenericMatchEngine.doMatch calls
>>>>>>>>> result = doMatch(leftRoot.eResource(), rightRoot.eResource(),
>>>>>>>>> monitor);
>>>>>>>>> in line 331 which is obviously null if rightRoot has a null
>>>>>>>>> Resource.
>>>>>>>>>
>>>>>>>>>
>>>>>>>>> Cédric brun wrote:
>>>>>>>>>> Hi Lars,
>>>>>>>>>>
>>>>>>>>>> What EMF Compare build are you using ? The RC1 build should
>>>>>>>>>> have fixed this
>>>>>>>>>> NPE (bug 230347 - see the release
>>>>>>>>>> notes
>>>>>>>>>> :http://www.eclipse.org/modeling/emft/news/relnotes.php?proj ect=compare&version=0.8.0RC1
>>>>>>>>>> )
>>>>>>>>>>
>>>>>>>>>> You should not have to provide your own match engine for such
>>>>>>>>>> a thing :)
>>>>>>>>>>
>>>>>>>>>> Cédric
>>>>>>>>>>
>>>>>>>>>>
>>>>>>>>>> Lars Schneider wrote:
>>>>>>>>>>
>>>>>>>>>>> I think this problem is better of in this newsgroup.
>>>>>>>>>>>
>>>>>>>>>>>> Hi,
>>>>>>>>>>>> I have a little problem using EcoreUtil.copy(EObject)
>>>>>>>>>>>> because the
>>>>>>>>>>>> eResource() of that copy returns null.
>>>>>>>>>>>>
>>>>>>>>>>>> More precisely I want to copy the root of a model, change
>>>>>>>>>>>> it and compare
>>>>>>>>>>>> it to the original with EMF Compare. I think the following
>>>>>>>>>>>> code snippet
>>>>>>>>>>>> explains it best:
>>>>>>>>>>>>
>>>>>>>>>>>> //...
>>>>>>>>>>>> EObject copy = EcoreUtil.copy(original);
>>>>>>>>>>>> Transformation trans = new Transformation(copy);
>>>>>>>>>>>> trans.transform(); // changes copy
>>>>>>>>>>>> MatchModel match = null;
>>>>>>>>>>>> try {
>>>>>>>>>>>> match = MatchService.doMatch(original, copy
>>>>>>>>>>>> Collections.<String, Object> emptyMap());
>>>>>>>>>>>> } catch (InterruptedException e) {
>>>>>>>>>>>> e.printStackTrace();
>>>>>>>>>>>> }
>>>>>>>>>>>> //...
>>>>>>>>>>>>
>>>>>>>>>>>> The problem is that doMatch(...) ends up in a
>>>>>>>>>>>> NullPointerException
>>>>>>>>>>>> because the resource of copy is null. Does anyone have an
>>>>>>>>>>>> idea how to
>>>>>>>>>>>> solve this problem? I think I can either set the resource
>>>>>>>>>>>> manually or
>>>>>>>>>>>> get another IMatchEngine implementation. But I don't know
>>>>>>>>>>>> how to.
>>>>>>>>>>>> Lars
>>>>>>>>>>
>>>>>>>
>>>>>
>>>>
>>>
>


--------------010002060507070000070800
Content-Type: text/html; charset=UTF-8
Content-Transfer-Encoding: 8bit

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta content="text/html;charset=UTF-8" http-equiv="Content-Type">
</head>
<body bgcolor="#ffffff" text="#000000">
Laurent,<br>
<br>
Try running Eclipse with -dir rtl.   It's even more fun if you use a
Hebrew or Arabic locale and have actual right to left characters it's
even more fun.  And if you mix them all up, the fun in simply endless:<br>
<blockquote><a
href="https://bugs.eclipse.org/bugs/show_bug.cgi?id=131711">https://bugs.eclipse.org/bugs/show_bug.cgi?id=131711</a><br>
</blockquote>
<br>
laurent Goubet wrote:
<blockquote cite="mid:g1jm6t$1r2$1@build.eclipse.org" type="cite">Ed,
<br>
<br>
BIDI?
<br>
<br>
And no ... left appearing in the right also comes from a (discutable)
choice from our side ... and will be reverted back to normal as soon as
we come to <a class="moz-txt-link-freetext" href="https://bugs.eclipse.org/bugs/show_bug.cgi?id=232277">https://bugs.eclipse.org/bugs/show_bug.cgi?id=232277</a> .
<br>
<br>
Laurent Goubet
<br>
Obeo
<br>
<br>
Ed Merks a écrit :
<br>
<blockquote type="cite">Laurent,
<br>
<br>
Comments below.
<br>
<br>
laurent Goubet wrote:
<br>
<blockquote type="cite">Lars,
<br>
<br>
Okay, just tried this via the UI ... and it worked as expected. Yet I
think your problem comes from the URI you use for your models. The
snippet you provided will never produce differences since you load the
same model twice without ever modifiying it, so I think you modified
the snippet for visibility ;).
<br>
<br>
The generic diff engine doesn't know which resource is the left model
and which is the right when computing additions/deletions. All we have
are the model URIs as can be retrieved via MatchModel#getLeftModel()
and MatchModel#getRightModel() (these are Strings instead of resources
.... AFAIK, this was because of legacy code). If you have the same URI
for both ... the diff engine will only see *removed* elements.
<br>
</blockquote>
I can see the BIDI defects now about the fact that the left model
appears on the right in the UI. :-P
<br>
<blockquote type="cite"><br>
Something like this should work as you are expecting (I think you were
copying your models so the following will make use of EcoreUtil.copy())
:
<br>
try {
<br>
    lRoot = ModelUtils.load(modelURI, resourceSet);
<br>
    rRoot = EcoreUtil.copy(lRoot);
<br>
    // This URI should use the same extension, other than that, it can
point to anything if this copy isn't meant to be saved
<br>
    ModelUtils.attachResource(copyModelURI, rRoot);
<br>
} catch (IOException e) {
<br>
    e.printStackTrace();
<br>
}
<br>
<br>
And a little update : EMF Compare 0.8RC2 has been built and the changes
to GenericMatchEngine should have made its way through this time. The
build should be promoted today.
<br>
<br>
Cheers,
<br>
<br>
Laurent Goubet
<br>
Obeo
<br>
<br>
laurent Goubet a écrit :
<br>
<blockquote type="cite">This would seem like a problem in the
DiffEngine, I'll test this with your model ASAP. Though the fact your
GenericMatchEngine is at an older version puzzles me ... the build came
3 days after I commited these changes ;(
<br>
<br>
Lars Schneider a écrit :
<br>
<blockquote type="cite">sorry, here comes the attachment
<br>
<br>
Lars Schneider wrote:
<br>
<blockquote type="cite">It seems that I still have another
version of GenericMatchEngine. My Method hasSameURI looks like this:
<br>
private boolean hasSameUri(EObject obj1, EObject obj2) {
<br>
    return
obj1.eResource().getURIFragment(obj1).equals(obj2.eResource( ).getURIFragment(obj2));
<br>
}
<br>
<br>
ModelUtils#attachResource() really solves the problem, so I can use
GenericMatchEngine#doMatch(). But there is another strange behavior.
<br>
I am using this snippet and it does NOT work because "diff" is partly
wrong:
<br>
<br>
-- snip
<br>
<br>
EObject lRoot = null;
<br>
EObject rRoot = null;
<br>
try {
<br>
    rRoot = ModelUtils.load(modelURI, resourceSet);
<br>
    ModelUtils.attachResource(modelURI, rRoot);
<br>
    lRoot = ModelUtils.load(modelURI, resourceSet);
<br>
    ModelUtils.attachResource(modelURI, lRoot);
<br>
} catch (IOException e) {
<br>
    e.printStackTrace();
<br>
}
<br>
<br>
Resource lResource = lRoot.eResource();
<br>
Resource rResource = rRoot.eResource();
<br>
<br>
Map&lt;String, Object&gt; options = Collections
<br>
        .&lt;String, Object&gt; emptyMap();
<br>
<br>
MatchModel match = null;
<br>
<br>
try {
<br>
    match = MatchService.doMatch(lRoot, rRoot, options);
<br>
    //match = MatchService.doContentMatch(lRoot, rRoot, options);
<br>
    //match = MatchService.doResourceMatch(lResource, rResource,
options);
<br>
} catch (InterruptedException e) {
<br>
    e.printStackTrace();
<br>
}
<br>
DiffModel diff = DiffService.doDiff(match);
<br>
ModelInputSnapshot snapshot = DiffFactory.eINSTANCE
<br>
        .createModelInputSnapshot();
<br>
snapshot.setMatch(match);
<br>
snapshot.setDiff(diff);
<br>
<br>
CompareUI.openCompareDialog(
<br>
        new ModelCompareEditorInput(modelInputSnapshot));
<br>
<br>
-- snap
<br>
<br>
But changing
<br>
    match = MatchService.doMatch(lRoot, rRoot, options);
<br>
into
<br>
    match = MatchService.doMatch(rRoot, lRoot, options);
<br>
WORKS!
<br>
Of course, the changings are the wrong way round. I am really desperate
because it depends on the right order.
<br>
<br>
I attached the model I am working with. It is unfortunately in german
but that shouldn't matter.
<br>
By the way I am testing the Hide Property Refactoring with class Konto
(account) and property saldo (balance).
<br>
<br>
match = MatchService.doMatch(lRoot, rRoot, options);
<br>
gets this diff:
<br>
    Attribute visibility in saldo has changed from public to private
<br>
<br>
    org.eclipse.uml2.uml.internal.impl.OperationImpl@12c662b (name:
getSaldo, visibility: public) (isLeaf: false, isStatic: false,
isAbstract: false, concurrency: sequential) (isQuery: false) has been
*removed*
<br>
<br>
    org.eclipse.uml2.uml.internal.impl.OperationImpl@144f423 (name:
setSaldo, visibility: public) (isLeaf: false, isStatic: false,
isAbstract: false, concurrency: sequential) (isQuery: false) has been
*removed*
<br>
<br>
but they are *added*
<br>
<br>
whereas
<br>
match = MatchService.doMatch(rRoot, lRoot, options);
<br>
provides a correct diff:
<br>
    Attribute visibility in saldo has changed from private to public
<br>
<br>
    org.eclipse.uml2.uml.internal.impl.OperationImpl@847410 (name:
getSaldo, visibility: public) (isLeaf: false, isStatic: false,
isAbstract: false, concurrency: sequential) (isQuery: false) has been
removed
<br>
<br>
    org.eclipse.uml2.uml.internal.impl.OperationImpl@12a6200 (name:
setSaldo, visibility: public) (isLeaf: false, isStatic: false,
isAbstract: false, concurrency: sequential) (isQuery: false) has been
removed
<br>
<br>
thanks for your patience,
<br>
lars
<br>
<br>
laurent Goubet wrote:
<br>
<blockquote type="cite">Lars,
<br>
<br>
Yup, GenericMatchEngine#modelMatch() does his work on the resource and
will fail if it is null, though contentMatch() shouldn't. What puzzles
me though is that GenericMatchEngine#hasSameURI() at ligne 1174 is :
<br>
    if (obj1.eResource() != null &amp;&amp; obj2.eResource() != null)
<br>
<br>
which means you're getting an NPE since one of the two compared objects
are null, not their resources... Could you provide us with the model
you're using as input? As a side note, did you take a look at
ModelUtils#attachResource() to see if it would solve the problem?
<br>
<br>
Laurent Goubet
<br>
Obeo
<br>
<br>
Lars Schneider a écrit :
<br>
<blockquote type="cite">and also with a doContentMatch I
get a NullPointerException
<br>
<br>
java.lang.NullPointerException
<br>
        at
org.eclipse.emf.compare.match.engine.GenericMatchEngine.hasS ameUri(GenericMatchEngine.java:1174)
<br>
        at
org.eclipse.emf.compare.match.engine.GenericMatchEngine.isSi milar(GenericMatchEngine.java:593)
<br>
        at
org.eclipse.emf.compare.match.engine.GenericMatchEngine.cont entMatch(GenericMatchEngine.java:252)
<br>
        at
org.eclipse.emf.compare.match.service.MatchService.doContent Match(MatchService.java:118)
<br>
<br>
<br>
Lars Schneider wrote:
<br>
<blockquote type="cite">Hi Cédric,
<br>
<br>
I updated to 0.8.0RC1 and still get a NullPointerException.
<br>
<br>
java.lang.NullPointerException
<br>
        at
org.eclipse.emf.compare.match.engine.GenericMatchEngine.filt erUnused(GenericMatchEngine.java:1094)
<br>
        at
org.eclipse.emf.compare.match.engine.GenericMatchEngine.doMa tch(GenericMatchEngine.java:907)
<br>
        at
org.eclipse.emf.compare.match.engine.GenericMatchEngine.mode lMatch(GenericMatchEngine.java:331)
<br>
        at
org.eclipse.emf.compare.match.service.MatchService.doMatch(M atchService.java:174)
<br>
<br>
GenericMatchEngine.doMatch calls
<br>
result = doMatch(leftRoot.eResource(), rightRoot.eResource(), monitor);
<br>
in line 331 which is obviously null if rightRoot has a null Resource.
<br>
<br>
<br>
Cédric brun wrote:
<br>
<blockquote type="cite">Hi Lars,
<br>
<br>
What EMF Compare build are you using ? The RC1 build should have fixed
this
<br>
NPE (bug 230347 - see the release
<br>
notes
:<a class="moz-txt-link-freetext" href=" http://www.eclipse.org/modeling/emft/news/relnotes.php?proje ct=compare&version=0.8.0RC1"> http://www.eclipse.org/modeling/emft/news/relnotes.php?proje ct=compare&amp;version=0.8.0RC1</a> 
)
<br>
<br>
You should not have to provide your own match engine for such a thing
:)
<br>
<br>
Cédric
<br>
<br>
<br>
Lars Schneider wrote:
<br>
<br>
<blockquote type="cite">I think this problem is
better of in this newsgroup.
<br>
<br>
<blockquote type="cite">Hi,
<br>
I have a little problem using EcoreUtil.copy(EObject) because the
<br>
eResource() of that copy returns null.
<br>
<br>
More precisely I want to copy the root of a model, change it and
compare
<br>
it to the original with EMF Compare. I think the following code snippet
<br>
explains it best:
<br>
<br>
//...
<br>
  EObject copy = EcoreUtil.copy(original);
<br>
  Transformation trans = new Transformation(copy);
<br>
  trans.transform(); // changes copy
<br>
  MatchModel match = null;
<br>
  try {
<br>
    match = MatchService.doMatch(original, copy
<br>
                Collections.&lt;String, Object&gt; emptyMap());
<br>
  } catch (InterruptedException e) {
<br>
    e.printStackTrace();
<br>
  }
<br>
//...
<br>
<br>
The problem is that doMatch(...) ends up in a NullPointerException
<br>
because the resource of copy is null. Does anyone have an idea how to
<br>
solve this problem? I think I can either set the resource manually or
<br>
get another IMatchEngine implementation. But I don't know how to.
<br>
Lars
<br>
</blockquote>
</blockquote>
<br>
</blockquote>
</blockquote>
</blockquote>
<br>
</blockquote>
</blockquote>
<br>
</blockquote>
<br>
</blockquote>
<br>
</blockquote>
</blockquote>
<br>
</blockquote>
<br>
</body>
</html>

--------------010002060507070000070800--


Ed Merks
Professional Support: https://www.macromodeling.com/
Previous Topic:shorthand notation for EMF factory invocations, now the PDF
Next Topic:CDO/Net4j Build Announcements
Goto Forum:
  


Current Time: Fri Mar 29 14:56:55 GMT 2024

Powered by FUDForum. Page generated in 0.03570 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top