Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » EMF » JMERGE without Eclipse
JMERGE without Eclipse [message #428366] Wed, 18 March 2009 12:49 Go to next message
Stefan Ocke is currently offline Stefan OckeFriend
Messages: 3
Registered: July 2009
Junior Member
Hello Ed,

are there any news on this topic:
http://dev.eclipse.org/newslists/news.eclipse.tools.emf/msg1 8478.html ?

I mean: Is it possible to run JMerge completely standalone (that is: even
without some eclipse workbench location)?
I had a quick look at the code and saw, that AstHelperFacade uses JavaCore
to get default options. Maybe this is the only place that causes traouble
in standalone. But I am not to deep in that...

Best Regards,
Stefan.
Re: JMERGE without Eclipse [message #428369 is a reply to message #428366] Wed, 18 March 2009 14:20 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 33136
Registered: July 2009
Senior Member
Stefan,

I think JDT core's AST works stand alone but I've really not looked
into it nor had the time. It's worth exploring and it might be possible
to make simple changes that avoid any class loading problems.


Stefan Ocke wrote:
> Hello Ed,
> are there any news on this topic:
> http://dev.eclipse.org/newslists/news.eclipse.tools.emf/msg1 8478.html ?
>
> I mean: Is it possible to run JMerge completely standalone (that is:
> even without some eclipse workbench location)?
> I had a quick look at the code and saw, that AstHelperFacade uses
> JavaCore to get default options. Maybe this is the only place that
> causes traouble in standalone. But I am not to deep in that...
>
> Best Regards,
> Stefan.
>


Ed Merks
Professional Support: https://www.macromodeling.com/
Re: JMERGE without Eclipse [message #428375 is a reply to message #428369] Wed, 18 March 2009 16:19 Go to previous messageGo to next message
Stefan Ocke is currently offline Stefan OckeFriend
Messages: 3
Registered: July 2009
Junior Member
Okay, thank you. I will give it a try in the next days...

Regards,
Stefan.
Re: JMERGE without Eclipse [message #428590 is a reply to message #428375] Tue, 24 March 2009 20:58 Go to previous messageGo to next message
Stefan Ocke is currently offline Stefan OckeFriend
Messages: 3
Registered: July 2009
Junior Member
I had some success with code like this. Perhaps its useful for others.
Please note especially setting of JavaCore options:

public void merge(File src, File target) {
JControlModel model = new JControlModel();
ASTFacadeHelper astFacadeHelper = new ASTFacadeHelper() {
Map options;

@SuppressWarnings("unchecked")
@Override
public Map getJavaCoreOptions() {
if (options == null) {
options = new HashMap();

options.put(JavaCore.COMPILER_COMPLIANCE,
JavaCore.VERSION_1_6);
options.put(JavaCore.COMPILER_SOURCE, JavaCore.VERSION_1_6);
options.put(JavaCore.COMPILER_CODEGEN_TARGET_PLATFORM,
JavaCore.VERSION_1_6);
options.put(JavaCore.COMPILER_PB_ASSERT_IDENTIFIER,
JavaCore.ERROR);
options.put(JavaCore.COMPILER_PB_ENUM_IDENTIFIER,
JavaCore.ERROR);
options.put(JavaCore.COMPILER_CODEGEN_INLINE_JSR_BYTECODE,
JavaCore.ENABLED);

//!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
options.put(JavaCore.COMPILER_DOC_COMMENT_SUPPORT, JavaCore.ENABLED);


Map cfo = DefaultCodeFormatterConstants
.getEclipseDefaultSettings();

options.putAll(cfo);

options
.put(
DefaultCodeFormatterConstants.FORMATTER_BLANK_LINES_AFTER_PA CKAGE,
"1");

}
return options;
}

};

String mergexml = this.getClass().getClassLoader().getResource(
"merge.xml").getFile();

model.initialize(astFacadeHelper, mergexml);

JMerger jMerger = new JMerger(model);

String sourceCnt = "package jmerge; \npublic class Foobar{
java.lang.String s; int x; \n\n/**\n * @generated\n */\npublic void
doIt(){System.out.println(\"Hello\");}}";

jMerger.setSourceCompilationUnit(jMerger
.createCompilationUnitForContents(sourceCnt));

String targetCnt = "package jmerge; \npublic class Foobar{ public double
y; private int x;public void doIt(){} }";

jMerger.setTargetCompilationUnit(jMerger
.createCompilationUnitForContents(targetCnt));


jMerger.merge();


String result = jMerger.getTargetCompilationUnit().getContents();

System.out.println(result);

}
Re: JMERGE without Eclipse [message #428592 is a reply to message #428590] Tue, 24 March 2009 21:40 Go to previous message
Ed Merks is currently offline Ed MerksFriend
Messages: 33136
Registered: July 2009
Senior Member
Stefan,

Thanks for sharing! :-)


Stefan Ocke wrote:
> I had some success with code like this. Perhaps its useful for
> others. Please note especially setting of JavaCore options:
>
> public void merge(File src, File target) {
> JControlModel model = new JControlModel();
> ASTFacadeHelper astFacadeHelper = new ASTFacadeHelper() {
> Map options;
>
> @SuppressWarnings("unchecked")
> @Override
> public Map getJavaCoreOptions() {
> if (options == null) {
> options = new HashMap();
>
> options.put(JavaCore.COMPILER_COMPLIANCE,
> JavaCore.VERSION_1_6);
> options.put(JavaCore.COMPILER_SOURCE,
> JavaCore.VERSION_1_6);
>
> options.put(JavaCore.COMPILER_CODEGEN_TARGET_PLATFORM,
> JavaCore.VERSION_1_6);
> options.put(JavaCore.COMPILER_PB_ASSERT_IDENTIFIER,
> JavaCore.ERROR);
> options.put(JavaCore.COMPILER_PB_ENUM_IDENTIFIER,
> JavaCore.ERROR);
>
> options.put(JavaCore.COMPILER_CODEGEN_INLINE_JSR_BYTECODE,
> JavaCore.ENABLED);
>
> //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
> options.put(JavaCore.COMPILER_DOC_COMMENT_SUPPORT,
> JavaCore.ENABLED);
>
>
> Map cfo = DefaultCodeFormatterConstants
> .getEclipseDefaultSettings();
>
> options.putAll(cfo);
>
> options
> .put(
>
> DefaultCodeFormatterConstants.FORMATTER_BLANK_LINES_AFTER_PA CKAGE,
> "1");
>
> }
> return options;
> }
>
> };
>
> String mergexml = this.getClass().getClassLoader().getResource(
> "merge.xml").getFile();
>
> model.initialize(astFacadeHelper, mergexml);
>
> JMerger jMerger = new JMerger(model);
>
> String sourceCnt = "package jmerge; \npublic class Foobar{
> java.lang.String s; int x; \n\n/**\n * @generated\n */\npublic void
> doIt(){System.out.println(\"Hello\");}}";
>
> jMerger.setSourceCompilationUnit(jMerger
> .createCompilationUnitForContents(sourceCnt));
>
> String targetCnt = "package jmerge; \npublic class Foobar{
> public double y; private int x;public void doIt(){} }";
>
> jMerger.setTargetCompilationUnit(jMerger
> .createCompilationUnitForContents(targetCnt));
>
>
> jMerger.merge();
>
>
> String result = jMerger.getTargetCompilationUnit().getContents();
>
> System.out.println(result);
>
> }
>


Ed Merks
Professional Support: https://www.macromodeling.com/
Previous Topic:Meta modeling question
Next Topic:One CompoundCommand covering modifications across multible ResourceSets?
Goto Forum:
  


Current Time: Fri Apr 19 02:29:11 GMT 2024

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

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

Back to the top