Home » Modeling » M2T (model-to-text transformation) » JMerge customization
| |
Re: JMerge customization [message #50301 is a reply to message #50271] |
Mon, 22 September 2008 19:36 |
Marcelo Paternostro 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. 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. 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.<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"><timothymarc@freenet.de></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 #50330 is a reply to message #50301] |
Tue, 23 September 2008 11:30 |
Timothy Marc 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 #50358 is a reply to message #50330] |
Tue, 23 September 2008 13:46 |
Ed Merks Messages: 33264 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 #50386 is a reply to message #50358] |
Tue, 23 September 2008 16:51 |
Timothy Marc 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 #50413 is a reply to message #50386] |
Tue, 23 September 2008 17:15 |
Ed Merks Messages: 33264 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. 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"><Ed.Merks@gmail.com></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 #50469 is a reply to message #50441] |
Tue, 23 September 2008 19:29 |
Ed Merks Messages: 33264 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/
|
|
|
Goto Forum:
Current Time: Fri Dec 27 00:37:07 GMT 2024
Powered by FUDForum. Page generated in 0.04710 seconds
|