Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » EMF » Re: JMerge customization
Re: JMerge customization [message #423083] Mon, 22 September 2008 17:34 Go to next message
Paul Elder is currently offline Paul ElderFriend
Messages: 849
Registered: July 2009
Senior Member
Timothy:

I'm cross posting this to the eclipse.tools.emf newsgroup, as the JMerge
code is part of EMF.

Paul

"Timothy Marc" <timothymarc@freenet.de> wrote in message
news:gb2qrq$s80$1@build.eclipse.org...
> Hi all,
>
> i want to modify the JMerge AST of the existing code programmatically in
> an JET library, i want to implement. This JMerge process should do some
> addttional things like analyzing and reporting the existing AST before
> merging. Does anyone has some experiences how to extend the basic JMerge
> functionality?
>
> Any help is appreciated. Thanks in advance.
> Timothy
>
Re: JMerge customization [message #423085 is a reply to message #423083] Mon, 22 September 2008 19:36 Go to previous messageGo to next message
Marcelo Paternostro is currently offline Marcelo PaternostroFriend
Messages: 602
Registered: July 2009
Senior Member
This is a multi-part message in MIME format.
--------------080107040806080404000202
Content-Type: text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding: 7bit

Hi Timothy,

When we implemented the AST layer to support Java 5, we had to tackle
the conversion from Java 1.4 enumeration to proper enums. This work is
done by org.eclipse.emf.codegen.merge.java.facade.ast.ASTNodeConvert er,
which may be a good starting point for you since it manipulates the
existing code before doing the merge.

I am trying to remember the gotchas (I know there were some) but my
memory is failing on me. I am quite sure that one of the problems we
had was related either to reuse the modified AST during the merge or to
apply the changes before the merge itself. I am sorry this is too vague
but unfortunately I can't dig into the code right now.

Feel free to post questions or your finding as you go ;-)

Cheers,
Marcelo

Paul Elder wrote:
> Timothy:
>
> I'm cross posting this to the eclipse.tools.emf newsgroup, as the JMerge
> code is part of EMF.
>
> Paul
>
> "Timothy Marc" <timothymarc@freenet.de> wrote in message
> news:gb2qrq$s80$1@build.eclipse.org...
>
>> Hi all,
>>
>> i want to modify the JMerge AST of the existing code programmatically in
>> an JET library, i want to implement. This JMerge process should do some
>> addttional things like analyzing and reporting the existing AST before
>> merging. Does anyone has some experiences how to extend the basic JMerge
>> functionality?
>>
>> Any help is appreciated. Thanks in advance.
>> Timothy
>>
>>
>
>
>

--------------080107040806080404000202
Content-Type: text/html; charset=ISO-8859-1
Content-Transfer-Encoding: 7bit

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta content="text/html;charset=ISO-8859-1" http-equiv="Content-Type">
</head>
<body bgcolor="#ffffff" text="#000000">
Hi Timothy,<br>
<br>
When we implemented the AST layer to support Java 5, we had to tackle
the conversion from Java 1.4 enumeration to proper enums.&nbsp; This work is
done by org.eclipse.emf.codegen.merge.java.facade.ast.ASTNodeConvert er,
which may be a good starting point for you since it manipulates the
existing code before doing the merge.<br>
<br>
I am trying to remember the gotchas (I know there were some) but my
memory is failing on me.&nbsp; I am quite sure that one of the problems we
had was related either to reuse the modified AST during the merge or to
apply the changes before the merge itself.&nbsp; I am sorry this is too
vague but unfortunately I can't dig into the code right now.<br>
<br>
Feel free to post questions or your finding as you go ;-)<br>
<br>
Cheers,<br>
Marcelo<br>
<br>
Paul Elder wrote:
<blockquote cite="mid:gb8kun$acg$1@build.eclipse.org" type="cite">
<pre wrap="">Timothy:

I'm cross posting this to the eclipse.tools.emf newsgroup, as the JMerge
code is part of EMF.

Paul

"Timothy Marc" <a class="moz-txt-link-rfc2396E" href="mailto:timothymarc@freenet.de">&lt;timothymarc@freenet.de&gt;</a> wrote in message
<a class="moz-txt-link-freetext" href="news:gb2qrq$s80$1@build.eclipse.org">news:gb2qrq$s80$1@build.eclipse.org</a>...
</pre>
<blockquote type="cite">
<pre wrap="">Hi all,

i want to modify the JMerge AST of the existing code programmatically in
an JET library, i want to implement. This JMerge process should do some
addttional things like analyzing and reporting the existing AST before
merging. Does anyone has some experiences how to extend the basic JMerge
functionality?

Any help is appreciated. Thanks in advance.
Timothy

</pre>
</blockquote>
<pre wrap=""><!---->

</pre>
</blockquote>
</body>
</html>

--------------080107040806080404000202--
Re: JMerge customization [message #423099 is a reply to message #423085] Tue, 23 September 2008 11:30 Go to previous messageGo to next message
Timothy Marc is currently offline Timothy MarcFriend
Messages: 547
Registered: July 2009
Senior Member
Dear Marcelo,

okay, so here is my first question. Before, i tell you, what i planned with
Jmerge to do:

I want to reuse the JAST from JMerge, for manual analyzation of a Java file.
I didn't want to create Target/SourceCompilationUnit, because i didn't want
to use the JMerge algorithm for merging. All i need is a JCompilationUnit,
which i can traverse like i've mentioned in the snippet below within the
for-loop. Therefore, i used the following code snippet:

final File f = new
File(" F:/TFH/SE/de.freundwendland.tfh.se.JMergeCodeGeneration/src/ jmerge/importWizards/ImportWizardPage.java ");
final File rules = new
File(" F:/TFH/SE/de.freundwendland.tfh.se.JMergeCodeGeneration/merg eRules.xml ");
JControlModel model = new JControlModel();
ASTFacadeHelper helper = new ASTFacadeHelper();
model.initialize(helper, rules.toURI().toString());
JMerger merger = new JMerger(model);
JCompilationUnit unit =
merger.createCompilationUnitForURI(f.toURI().toString()); //causes an
exception
ASTJCompilationUnit junit = helper.createCompilationUnit("Test",
unit.getContents());
for(final JNode o:junit.getChildren()){
if(o instanceof JMethod){
System.out.println(o.getQualifiedName());
}
}

Nothing unusual, as i think. But the process fails with the following, nut
interpretable error message for me:
org.eclipse.emf.common.util.WrappedException:
org.eclipse.emf.common.util.DiagnosticException: A problem was detected
while parsing a Java file

at
org.eclipse.emf.codegen.merge.java.facade.ast.ASTFacadeHelpe r.createCompilationUnit(ASTFacadeHelper.java:282)

at
org.eclipse.emf.codegen.merge.java.facade.ast.ASTFacadeHelpe r.createCompilationUnit(ASTFacadeHelper.java:1)

at
org.eclipse.emf.codegen.merge.java.JMerger.createCompilation UnitForURI(JMerger.java:368)

at
org.eclipse.emf.codegen.merge.java.JMerger.createCompilation UnitForURI(JMerger.java:343)


So, does anyone or you know, why that happens? I've introspect the related
codeline in the createCompilationUnit... method, but didn't get it.

Thx
Timothy
Re: JMerge customization [message #423110 is a reply to message #423099] Tue, 23 September 2008 13:46 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 33113
Registered: July 2009
Senior Member
Timothy,

Try setting a breakpoint in ASTFacadeHelper.analyzeCompilationUnit and
see what IProblems are reported. Perhaps you're generating code with
syntax errors?


Timothy Marc wrote:
> Dear Marcelo,
>
> okay, so here is my first question. Before, i tell you, what i planned with
> Jmerge to do:
>
> I want to reuse the JAST from JMerge, for manual analyzation of a Java file.
> I didn't want to create Target/SourceCompilationUnit, because i didn't want
> to use the JMerge algorithm for merging. All i need is a JCompilationUnit,
> which i can traverse like i've mentioned in the snippet below within the
> for-loop. Therefore, i used the following code snippet:
>
> final File f = new
> File(" F:/TFH/SE/de.freundwendland.tfh.se.JMergeCodeGeneration/src/ jmerge/importWizards/ImportWizardPage.java ");
> final File rules = new
> File(" F:/TFH/SE/de.freundwendland.tfh.se.JMergeCodeGeneration/merg eRules.xml ");
> JControlModel model = new JControlModel();
> ASTFacadeHelper helper = new ASTFacadeHelper();
> model.initialize(helper, rules.toURI().toString());
> JMerger merger = new JMerger(model);
> JCompilationUnit unit =
> merger.createCompilationUnitForURI(f.toURI().toString()); //causes an
> exception
> ASTJCompilationUnit junit = helper.createCompilationUnit("Test",
> unit.getContents());
> for(final JNode o:junit.getChildren()){
> if(o instanceof JMethod){
> System.out.println(o.getQualifiedName());
> }
> }
>
> Nothing unusual, as i think. But the process fails with the following, nut
> interpretable error message for me:
> org.eclipse.emf.common.util.WrappedException:
> org.eclipse.emf.common.util.DiagnosticException: A problem was detected
> while parsing a Java file
>
> at
> org.eclipse.emf.codegen.merge.java.facade.ast.ASTFacadeHelpe r.createCompilationUnit(ASTFacadeHelper.java:282)
>
> at
> org.eclipse.emf.codegen.merge.java.facade.ast.ASTFacadeHelpe r.createCompilationUnit(ASTFacadeHelper.java:1)
>
> at
> org.eclipse.emf.codegen.merge.java.JMerger.createCompilation UnitForURI(JMerger.java:368)
>
> at
> org.eclipse.emf.codegen.merge.java.JMerger.createCompilation UnitForURI(JMerger.java:343)
>
>
> So, does anyone or you know, why that happens? I've introspect the related
> codeline in the createCompilationUnit... method, but didn't get it.
>
> Thx
> Timothy
>
>
>


Ed Merks
Professional Support: https://www.macromodeling.com/
Re: JMerge customization [message #423134 is a reply to message #423110] Tue, 23 September 2008 16:51 Go to previous messageGo to next message
Timothy Marc is currently offline Timothy MarcFriend
Messages: 547
Registered: July 2009
Senior Member
Ed,
indeed, you're right. The IProblem says, that the ClassBody contains a
missing "}", but that isn't so in real, because the java file i want to
parse is a valid file in a working project without syntax errors.
Why does this error appears?
Thx
Timothy

"Ed Merks" <Ed.Merks@gmail.com> schrieb im Newsbeitrag
news:gbarvg$bkt$1@build.eclipse.org...
> Timothy,
>
> Try setting a breakpoint in ASTFacadeHelper.analyzeCompilationUnit and see
> what IProblems are reported. Perhaps you're generating code with syntax
> errors?
>
>
> Timothy Marc wrote:
>> Dear Marcelo,
>>
>> okay, so here is my first question. Before, i tell you, what i planned
>> with Jmerge to do:
>>
>> I want to reuse the JAST from JMerge, for manual analyzation of a Java
>> file. I didn't want to create Target/SourceCompilationUnit, because i
>> didn't want to use the JMerge algorithm for merging. All i need is a
>> JCompilationUnit, which i can traverse like i've mentioned in the snippet
>> below within the for-loop. Therefore, i used the following code snippet:
>>
>> final File f = new
>> File(" F:/TFH/SE/de.freundwendland.tfh.se.JMergeCodeGeneration/src/ jmerge/importWizards/ImportWizardPage.java ");
>> final File rules = new
>> File(" F:/TFH/SE/de.freundwendland.tfh.se.JMergeCodeGeneration/merg eRules.xml ");
>> JControlModel model = new JControlModel();
>> ASTFacadeHelper helper = new ASTFacadeHelper();
>> model.initialize(helper, rules.toURI().toString());
>> JMerger merger = new JMerger(model);
>> JCompilationUnit unit =
>> merger.createCompilationUnitForURI(f.toURI().toString()); //causes an
>> exception
>> ASTJCompilationUnit junit = helper.createCompilationUnit("Test",
>> unit.getContents());
>> for(final JNode o:junit.getChildren()){
>> if(o instanceof JMethod){
>> System.out.println(o.getQualifiedName());
>> }
>> }
>>
>> Nothing unusual, as i think. But the process fails with the following,
>> nut interpretable error message for me:
>> org.eclipse.emf.common.util.WrappedException:
>> org.eclipse.emf.common.util.DiagnosticException: A problem was detected
>> while parsing a Java file
>>
>> at
>> org.eclipse.emf.codegen.merge.java.facade.ast.ASTFacadeHelpe r.createCompilationUnit(ASTFacadeHelper.java:282)
>>
>> at
>> org.eclipse.emf.codegen.merge.java.facade.ast.ASTFacadeHelpe r.createCompilationUnit(ASTFacadeHelper.java:1)
>>
>> at
>> org.eclipse.emf.codegen.merge.java.JMerger.createCompilation UnitForURI(JMerger.java:368)
>>
>> at
>> org.eclipse.emf.codegen.merge.java.JMerger.createCompilation UnitForURI(JMerger.java:343)
>>
>>
>> So, does anyone or you know, why that happens? I've introspect the
>> related codeline in the createCompilationUnit... method, but didn't get
>> it.
>>
>> Thx
>> Timothy
>>
>>
Re: JMerge customization [message #423136 is a reply to message #423134] Tue, 23 September 2008 17:15 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 33113
Registered: July 2009
Senior Member
This is a multi-part message in MIME format.
--------------090607030306030002000005
Content-Type: text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding: 7bit

Timonthy,

I doubt the tools are making it up. The diagnostic that's created has
the string with the contents, so look closely at those...


Timothy Marc wrote:
> Ed,
> indeed, you're right. The IProblem says, that the ClassBody contains a
> missing "}", but that isn't so in real, because the java file i want to
> parse is a valid file in a working project without syntax errors.
> Why does this error appears?
> Thx
> Timothy
>
> "Ed Merks" <Ed.Merks@gmail.com> schrieb im Newsbeitrag
> news:gbarvg$bkt$1@build.eclipse.org...
>
>> Timothy,
>>
>> Try setting a breakpoint in ASTFacadeHelper.analyzeCompilationUnit and see
>> what IProblems are reported. Perhaps you're generating code with syntax
>> errors?
>>
>>
>> Timothy Marc wrote:
>>
>>> Dear Marcelo,
>>>
>>> okay, so here is my first question. Before, i tell you, what i planned
>>> with Jmerge to do:
>>>
>>> I want to reuse the JAST from JMerge, for manual analyzation of a Java
>>> file. I didn't want to create Target/SourceCompilationUnit, because i
>>> didn't want to use the JMerge algorithm for merging. All i need is a
>>> JCompilationUnit, which i can traverse like i've mentioned in the snippet
>>> below within the for-loop. Therefore, i used the following code snippet:
>>>
>>> final File f = new
>>> File(" F:/TFH/SE/de.freundwendland.tfh.se.JMergeCodeGeneration/src/ jmerge/importWizards/ImportWizardPage.java ");
>>> final File rules = new
>>> File(" F:/TFH/SE/de.freundwendland.tfh.se.JMergeCodeGeneration/merg eRules.xml ");
>>> JControlModel model = new JControlModel();
>>> ASTFacadeHelper helper = new ASTFacadeHelper();
>>> model.initialize(helper, rules.toURI().toString());
>>> JMerger merger = new JMerger(model);
>>> JCompilationUnit unit =
>>> merger.createCompilationUnitForURI(f.toURI().toString()); //causes an
>>> exception
>>> ASTJCompilationUnit junit = helper.createCompilationUnit("Test",
>>> unit.getContents());
>>> for(final JNode o:junit.getChildren()){
>>> if(o instanceof JMethod){
>>> System.out.println(o.getQualifiedName());
>>> }
>>> }
>>>
>>> Nothing unusual, as i think. But the process fails with the following,
>>> nut interpretable error message for me:
>>> org.eclipse.emf.common.util.WrappedException:
>>> org.eclipse.emf.common.util.DiagnosticException: A problem was detected
>>> while parsing a Java file
>>>
>>> at
>>> org.eclipse.emf.codegen.merge.java.facade.ast.ASTFacadeHelpe r.createCompilationUnit(ASTFacadeHelper.java:282)
>>>
>>> at
>>> org.eclipse.emf.codegen.merge.java.facade.ast.ASTFacadeHelpe r.createCompilationUnit(ASTFacadeHelper.java:1)
>>>
>>> at
>>> org.eclipse.emf.codegen.merge.java.JMerger.createCompilation UnitForURI(JMerger.java:368)
>>>
>>> at
>>> org.eclipse.emf.codegen.merge.java.JMerger.createCompilation UnitForURI(JMerger.java:343)
>>>
>>>
>>> So, does anyone or you know, why that happens? I've introspect the
>>> related codeline in the createCompilationUnit... method, but didn't get
>>> it.
>>>
>>> Thx
>>> Timothy
>>>
>>>
>>>
>
>
>

--------------090607030306030002000005
Content-Type: text/html; charset=ISO-8859-1
Content-Transfer-Encoding: 7bit

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta content="text/html;charset=ISO-8859-1" http-equiv="Content-Type">
</head>
<body bgcolor="#ffffff" text="#000000">
Timonthy,<br>
<br>
I doubt the tools are making it up.&nbsp; The diagnostic that's created has
the string with the contents, so look closely at those...<br>
<br>
<br>
Timothy Marc wrote:
<blockquote cite="mid:gbb6n3$s4m$1@build.eclipse.org" type="cite">
<pre wrap="">Ed,
indeed, you're right. The IProblem says, that the ClassBody contains a
missing "}", but that isn't so in real, because the java file i want to
parse is a valid file in a working project without syntax errors.
Why does this error appears?
Thx
Timothy

"Ed Merks" <a class="moz-txt-link-rfc2396E" href="mailto:Ed.Merks@gmail.com">&lt;Ed.Merks@gmail.com&gt;</a> schrieb im Newsbeitrag
<a class="moz-txt-link-freetext" href="news:gbarvg$bkt$1@build.eclipse.org">news:gbarvg$bkt$1@build.eclipse.org</a>...
</pre>
<blockquote type="cite">
<pre wrap="">Timothy,

Try setting a breakpoint in ASTFacadeHelper.analyzeCompilationUnit and see
what IProblems are reported. Perhaps you're generating code with syntax
errors?


Timothy Marc wrote:
</pre>
<blockquote type="cite">
<pre wrap="">Dear Marcelo,

okay, so here is my first question. Before, i tell you, what i planned
with Jmerge to do:

I want to reuse the JAST from JMerge, for manual analyzation of a Java
file. I didn't want to create Target/SourceCompilationUnit, because i
didn't want to use the JMerge algorithm for merging. All i need is a
JCompilationUnit, which i can traverse like i've mentioned in the snippet
below within the for-loop. Therefore, i used the following code snippet:

final File f = new
File(" F:/TFH/SE/de.freundwendland.tfh.se.JMergeCodeGeneration/src/ jmerge/importWizards/ImportWizardPage.java ");
final File rules = new
File(" F:/TFH/SE/de.freundwendland.tfh.se.JMergeCodeGeneration/merg eRules.xml ");
JControlModel model = new JControlModel();
ASTFacadeHelper helper = new ASTFacadeHelper();
model.initialize(helper, rules.toURI().toString());
JMerger merger = new JMerger(model);
JCompilationUnit unit =
merger.createCompilationUnitForURI(f.toURI().toString()); //causes an
exception
ASTJCompilationUnit junit = helper.createCompilationUnit("Test",
unit.getContents());
for(final JNode o:junit.getChildren()){
if(o instanceof JMethod){
System.out.println(o.getQualifiedName());
}
}

Nothing unusual, as i think. But the process fails with the following,
nut interpretable error message for me:
org.eclipse.emf.common.util.WrappedException:
org.eclipse.emf.common.util.DiagnosticException: A problem was detected
while parsing a Java file

at
org.eclipse.emf.codegen.merge.java.facade.ast.ASTFacadeHelpe r.createCompilationUnit(ASTFacadeHelper.java:282)

at
org.eclipse.emf.codegen.merge.java.facade.ast.ASTFacadeHelpe r.createCompilationUnit(ASTFacadeHelper.java:1)

at
org.eclipse.emf.codegen.merge.java.JMerger.createCompilation UnitForURI(JMerger.java:368)

at
org.eclipse.emf.codegen.merge.java.JMerger.createCompilation UnitForURI(JMerger.java:343)


So, does anyone or you know, why that happens? I've introspect the
related codeline in the createCompilationUnit... method, but didn't get
it.

Thx
Timothy


</pre>
</blockquote>
</blockquote>
<pre wrap=""><!---->

</pre>
</blockquote>
</body>
</html>

--------------090607030306030002000005--


Ed Merks
Professional Support: https://www.macromodeling.com/
Re: JMerge customization [message #423141 is a reply to message #423136] Tue, 23 September 2008 18:10 Go to previous messageGo to next message
Timothy Marc is currently offline Timothy MarcFriend
Messages: 547
Registered: July 2009
Senior Member
Okay,
for everyone, how is interested in this discussion, i've found the problem
with the ASTJCompilationUnit parser.

1. The parser didn't accept the single line comments in the
CompilationUnit's content. So, a snippet like this:

//a comment
System.out.println("What the hell?");

will cause an exception with the message ("Syntax error.insert } to complete
class body"). Both inside of a method body and in the class body. But you
can use the multiline comments.

/*a comment */
System.out.println("What the hell?");

produces the correct JAST. Currently, i'm working with EMF 2.3, may be this
is erased in a later version?
Or is there a flag, which has to be set for enabling // comments? IMHO, this
kind of parsing is not feasible
Re: JMerge customization [message #423147 is a reply to message #423141] Tue, 23 September 2008 19:29 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.
--------------050205040400060602050001
Content-Type: text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding: 8bit

Timothy,

We handle files with with // comments without this type of problem.
Perhaps you have some preference settings that enforce style issues (no
// comments) by marking them as errors? E.g.,

public static LibraryPackage init()
{
if (isInited) return
(LibraryPackage)EPackage.Registry.INSTANCE.getEPackage(Libra ryPackage.eNS_URI);

// Obtain or create and register package
LibraryPackageImpl theLibraryPackage =
(LibraryPackageImpl)(EPackage.Registry.INSTANCE.getEPackage( eNS_URI)
instanceof LibraryPackageImpl ?
EPackage.Registry.INSTANCE.getEPackage(eNS_URI) : new
LibraryPackageImpl());



Timothy Marc wrote:
> Okay,
> for everyone, how is interested in this discussion, i've found the problem
> with the ASTJCompilationUnit parser.
>
> 1. The parser didn't accept the single line comments in the
> CompilationUnit's content. So, a snippet like this:
>
> //a comment
> System.out.println("What the hell?");
>
> will cause an exception with the message ("Syntax error.insert } to complete
> class body"). Both inside of a method body and in the class body. But you
> can use the multiline comments.
>
> /*a comment */
> System.out.println("What the hell?");
>
> produces the correct JAST. Currently, i'm working with EMF 2.3, may be this
> is erased in a later version?
> Or is there a flag, which has to be set for enabling // comments? IMHO, this
> kind of parsing is not feasible


Ed Merks
Professional Support: https://www.macromodeling.com/
Previous Topic:ChangeDescription applyAndReverse performance issue
Next Topic:Problem loading XMI resource
Goto Forum:
  


Current Time: Thu Mar 28 19:26:46 GMT 2024

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

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

Back to the top