Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » EMF "Technology" (Ecore Tools, EMFatic, etc)  » Using JET to create java Code
Using JET to create java Code [message #22190] Wed, 15 February 2006 00:26 Go to next message
Eclipse UserFriend
Originally posted by: ed.ed4becky.org

And I am trying to find if there is a Best Practice way to reformat the
output accordinging to the Java Editor format selected by the user.
Re: Using JET to create java Code [message #22241 is a reply to message #22190] Wed, 15 February 2006 02:22 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: stepper.sympedia.de

Ed,

If you want to use the Sympedia Generator Framework,
then you can simply configure a generator pipeline with a Java Formatter.
Please have a look at http://genfw.berlios.de

Cheers
/Eike


Ed Thompson schrieb:
> And I am trying to find if there is a Best Practice way to reformat the
> output accordinging to the Java Editor format selected by the user.
Re: Using JET to create java Code [message #22340 is a reply to message #22190] Wed, 15 February 2006 12:17 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: merks.ca.ibm.com

This is a multi-part message in MIME format.
--------------070809050302050806010101
Content-Type: text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding: 7bit

Ed,

It's quite easy to invoke the formatter programmatically.

You can create a formatter using
org.eclipse.jdt.coreToolFactory.createCodeFormatter(codeForm atterOptions)
and then apply it like this:

protected static String formatCode(String contents,
CodeFormatter codeFormatter)
{
IDocument doc = new Document(contents);
TextEdit edit =
codeFormatter.format(CodeFormatter.K_COMPILATION_UNIT, doc.get(), 0,
doc.get().length(), 0, null);

try
{
edit.apply(doc);
contents = doc.get();
}
catch (Exception exception)
{
CodeGenEcorePlugin.INSTANCE.log(exception);
}

return contents;
}


Ed Thompson wrote:
> And I am trying to find if there is a Best Practice way to reformat
> the output accordinging to the Java Editor format selected by the user.


--------------070809050302050806010101
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">
Ed,<br>
<br>
It's quite easy to invoke the formatter programmatically.<br>
<br>
You can create a formatter using
org.eclipse.jdt.coreToolFactory.createCodeFormatter(codeForm atterOptions)
and then apply it like this:<br>
<blockquote><small>&nbsp;&nbsp;&nbsp; protected static String formatCode(String
contents, CodeFormatter codeFormatter)</small><br>
<small>&nbsp;&nbsp;&nbsp; {</small><br>
<small>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; IDocument doc = new Document(contents);</small><br>
<small>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; TextEdit edit =
codeFormatter.format(CodeFormatter.K_COMPILATION_UNIT, doc.get(), 0,
doc.get().length(), 0, null);</small><br>
<small>&nbsp; </small><br>
<small>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; try</small><br>
<small>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {</small><br>
<small> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp; edit.apply(doc);</small><br>
<small> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp; contents = doc.get();</small><br>
<small>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }</small><br>
<small>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; catch (Exception exception)</small><br>
<small>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {</small><br>
<small> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp; CodeGenEcorePlugin.INSTANCE.log(exception);</small><br>
<small>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }</small><br>
<small>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </small><br>
<small>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; return contents;</small><br>
<small>&nbsp;&nbsp;&nbsp; }</small><br>
</blockquote>
<br>
Ed Thompson wrote:
<blockquote cite="middstsf1$e8g$1@utils.eclipse.org" type="cite">And I
am trying to find if there is a Best Practice way to reformat the
output accordinging to the Java Editor format selected by the user.
<br>
</blockquote>
<br>
</body>
</html>

--------------070809050302050806010101--
Re: Using JET to create java Code [message #22596 is a reply to message #22340] Wed, 15 February 2006 22:56 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: ed.ed4becky.org

Thanx Ed, this looks great!

I have just started in the world of code generation, and am having a lot
of fun with it. Appreciate the help!

Ed Merks wrote:
> Ed,
>
> It's quite easy to invoke the formatter programmatically.
>
> You can create a formatter using
> org.eclipse.jdt.coreToolFactory.createCodeFormatter(codeForm atterOptions)
> and then apply it like this:
>
> protected static String formatCode(String contents,
> CodeFormatter codeFormatter)
> {
> IDocument doc = new Document(contents);
> TextEdit edit =
> codeFormatter.format(CodeFormatter.K_COMPILATION_UNIT, doc.get(), 0,
> doc.get().length(), 0, null);
>
> try
> {
> edit.apply(doc);
> contents = doc.get();
> }
> catch (Exception exception)
> {
> CodeGenEcorePlugin.INSTANCE.log(exception);
> }
>
> return contents;
> }
>
>
> Ed Thompson wrote:
>
>> And I am trying to find if there is a Best Practice way to reformat
>> the output accordinging to the Java Editor format selected by the user.
>
>
Re: Using JET to create java Code [message #22682 is a reply to message #22340] Thu, 16 February 2006 00:54 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: ed.ed4becky.org

Ok, getting a wierd error when I try this:

String buffer = rmt.generate(bean);
CodeFormatter codeFormatter = ToolFactory.createCodeFormatter(null);

I am running it in a jUnir test just to test the concept. Googling
comes up with a ned to initialize something, but not sure what..


java.lang.ExceptionInInitializerError
at org.eclipse.jdt.core.JavaCore.getOptions(JavaCore.java:2401)
at
org.eclipse.jdt.core.ToolFactory.createCodeFormatter(ToolFac tory.java:96)
at
org.ed4becky.codegen.TestModelBeanTemplate.testGenerate(Test ModelBeanTemplate.java:39)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at junit.framework.TestCase.runTest(TestCase.java:154)
at junit.framework.TestCase.runBare(TestCase.java:127)
at junit.framework.TestResult$1.protect(TestResult.java:106)
at junit.framework.TestResult.runProtected(TestResult.java:124)
at junit.framework.TestResult.run(TestResult.java:109)
at junit.framework.TestCase.run(TestCase.java:118)
at junit.framework.TestSuite.runTest(TestSuite.java:208)
at junit.framework.TestSuite.run(TestSuite.java:203)
at
org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTe sts(RemoteTestRunner.java:478)
at
org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(R emoteTestRunner.java:344)
at
org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main( RemoteTestRunner.java:196)
Caused by: java.lang.NullPointerException
at
org.eclipse.jdt.internal.core.search.indexing.IndexManager.g etJavaPluginWorkingLocation(IndexManager.java:284)
at
org.eclipse.jdt.internal.core.search.indexing.IndexManager.<init >(IndexManager.java:50)
at
org.eclipse.jdt.internal.core.JavaModelManager.<init>(JavaModelManager.java:671)
at
org.eclipse.jdt.internal.core.JavaModelManager.<clinit>(JavaModelManager.java:649)
... 18 more




Ed Merks wrote:
> Ed,
>
> It's quite easy to invoke the formatter programmatically.
>
> You can create a formatter using
> org.eclipse.jdt.coreToolFactory.createCodeFormatter(codeForm atterOptions)
> and then apply it like this:
>
> protected static String formatCode(String contents,
> CodeFormatter codeFormatter)
> {
> IDocument doc = new Document(contents);
> TextEdit edit =
> codeFormatter.format(CodeFormatter.K_COMPILATION_UNIT, doc.get(), 0,
> doc.get().length(), 0, null);
>
> try
> {
> edit.apply(doc);
> contents = doc.get();
> }
> catch (Exception exception)
> {
> CodeGenEcorePlugin.INSTANCE.log(exception);
> }
>
> return contents;
> }
>
>
> Ed Thompson wrote:
>
>> And I am trying to find if there is a Best Practice way to reformat
>> the output accordinging to the Java Editor format selected by the user.
>
>
Re: Using JET to create java Code [message #22726 is a reply to message #22340] Thu, 16 February 2006 02:18 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: ed.ed4becky.org

I traced it and JavaModelManager.getJavaModelManager() seems to fail,
though I cannot find who is throwing the exception.
Re: Using JET to create java Code [message #22856 is a reply to message #22682] Thu, 16 February 2006 10:25 Go to previous message
Eclipse UserFriend
Originally posted by: merks.ca.ibm.com

Ed,

Are you running in a headless Eclipse rather than stand-alone? That's
required for JDT to function properly.


Ed Thompson wrote:
> Ok, getting a wierd error when I try this:
>
> String buffer = rmt.generate(bean);
> CodeFormatter codeFormatter = ToolFactory.createCodeFormatter(null);
>
> I am running it in a jUnir test just to test the concept. Googling
> comes up with a ned to initialize something, but not sure what..
>
>
> java.lang.ExceptionInInitializerError
> at org.eclipse.jdt.core.JavaCore.getOptions(JavaCore.java:2401)
> at
> org.eclipse.jdt.core.ToolFactory.createCodeFormatter(ToolFac tory.java:96)
> at
> org.ed4becky.codegen.TestModelBeanTemplate.testGenerate(Test ModelBeanTemplate.java:39)
>
> at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
> at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
> at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
> at java.lang.reflect.Method.invoke(Unknown Source)
> at junit.framework.TestCase.runTest(TestCase.java:154)
> at junit.framework.TestCase.runBare(TestCase.java:127)
> at junit.framework.TestResult$1.protect(TestResult.java:106)
> at junit.framework.TestResult.runProtected(TestResult.java:124)
> at junit.framework.TestResult.run(TestResult.java:109)
> at junit.framework.TestCase.run(TestCase.java:118)
> at junit.framework.TestSuite.runTest(TestSuite.java:208)
> at junit.framework.TestSuite.run(TestSuite.java:203)
> at
> org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTe sts(RemoteTestRunner.java:478)
>
> at
> org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(R emoteTestRunner.java:344)
>
> at
> org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main( RemoteTestRunner.java:196)
>
> Caused by: java.lang.NullPointerException
> at
> org.eclipse.jdt.internal.core.search.indexing.IndexManager.g etJavaPluginWorkingLocation(IndexManager.java:284)
>
> at
> org.eclipse.jdt.internal.core.search.indexing.IndexManager.<init >(IndexManager.java:50)
>
> at
> org.eclipse.jdt.internal.core.JavaModelManager.<init>(JavaModelManager.java:671)
>
> at
> org.eclipse.jdt.internal.core.JavaModelManager.<clinit>(JavaModelManager.java:649)
>
> ... 18 more
>
>
>
>
> Ed Merks wrote:
>> Ed,
>>
>> It's quite easy to invoke the formatter programmatically.
>>
>> You can create a formatter using
>> org.eclipse.jdt.coreToolFactory.createCodeFormatter(codeForm atterOptions)
>> and then apply it like this:
>>
>> protected static String formatCode(String contents,
>> CodeFormatter codeFormatter)
>> {
>> IDocument doc = new Document(contents);
>> TextEdit edit =
>> codeFormatter.format(CodeFormatter.K_COMPILATION_UNIT, doc.get(), 0,
>> doc.get().length(), 0, null);
>> try
>> {
>> edit.apply(doc);
>> contents = doc.get();
>> }
>> catch (Exception exception)
>> {
>> CodeGenEcorePlugin.INSTANCE.log(exception);
>> }
>> return contents;
>> }
>>
>>
>> Ed Thompson wrote:
>>
>>> And I am trying to find if there is a Best Practice way to reformat
>>> the output accordinging to the Java Editor format selected by the user.
>>
>>
Re: Using JET to create java Code [message #566785 is a reply to message #22190] Wed, 15 February 2006 02:22 Go to previous message
Eike Stepper is currently offline Eike StepperFriend
Messages: 6655
Registered: July 2009
Senior Member
Ed,

If you want to use the Sympedia Generator Framework,
then you can simply configure a generator pipeline with a Java Formatter.
Please have a look at http://genfw.berlios.de

Cheers
/Eike


Ed Thompson schrieb:
> And I am trying to find if there is a Best Practice way to reformat the
> output accordinging to the Java Editor format selected by the user.


Re: Using JET to create java Code [message #566896 is a reply to message #22190] Wed, 15 February 2006 12:17 Go to previous message
Ed Merks is currently offline Ed MerksFriend
Messages: 32561
Registered: July 2009
Senior Member
This is a multi-part message in MIME format.
--------------070809050302050806010101
Content-Type: text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding: 7bit

Ed,

It's quite easy to invoke the formatter programmatically.

You can create a formatter using
org.eclipse.jdt.coreToolFactory.createCodeFormatter(codeForm atterOptions)
and then apply it like this:

protected static String formatCode(String contents,
CodeFormatter codeFormatter)
{
IDocument doc = new Document(contents);
TextEdit edit =
codeFormatter.format(CodeFormatter.K_COMPILATION_UNIT, doc.get(), 0,
doc.get().length(), 0, null);

try
{
edit.apply(doc);
contents = doc.get();
}
catch (Exception exception)
{
CodeGenEcorePlugin.INSTANCE.log(exception);
}

return contents;
}


Ed Thompson wrote:
> And I am trying to find if there is a Best Practice way to reformat
> the output accordinging to the Java Editor format selected by the user.


--------------070809050302050806010101
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">
Ed,<br>
<br>
It's quite easy to invoke the formatter programmatically.<br>
<br>
You can create a formatter using
org.eclipse.jdt.coreToolFactory.createCodeFormatter(codeForm atterOptions)
and then apply it like this:<br>
<blockquote><small>&nbsp;&nbsp;&nbsp; protected static String formatCode(String
contents, CodeFormatter codeFormatter)</small><br>
<small>&nbsp;&nbsp;&nbsp; {</small><br>
<small>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; IDocument doc = new Document(contents);</small><br>
<small>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; TextEdit edit =
codeFormatter.format(CodeFormatter.K_COMPILATION_UNIT, doc.get(), 0,
doc.get().length(), 0, null);</small><br>
<small>&nbsp; </small><br>
<small>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; try</small><br>
<small>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {</small><br>
<small> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp; edit.apply(doc);</small><br>
<small> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp; contents = doc.get();</small><br>
<small>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }</small><br>
<small>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; catch (Exception exception)</small><br>
<small>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; {</small><br>
<small> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; &nbsp; CodeGenEcorePlugin.INSTANCE.log(exception);</small><br>
<small>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; }</small><br>
<small>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; </small><br>
<small>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; return contents;</small><br>
<small>&nbsp;&nbsp;&nbsp; }</small><br>
</blockquote>
<br>
Ed Thompson wrote:
<blockquote cite="middstsf1$e8g$1@utils.eclipse.org" type="cite">And I
am trying to find if there is a Best Practice way to reformat the
output accordinging to the Java Editor format selected by the user.
<br>
</blockquote>
<br>
</body>
</html>

--------------070809050302050806010101--


Ed Merks
Professional Support: https://www.macromodeling.com/
Re: Using JET to create java Code [message #567127 is a reply to message #22340] Wed, 15 February 2006 22:56 Go to previous message
Eclipse UserFriend
Originally posted by: ed.ed4becky.org

Thanx Ed, this looks great!

I have just started in the world of code generation, and am having a lot
of fun with it. Appreciate the help!

Ed Merks wrote:
> Ed,
>
> It's quite easy to invoke the formatter programmatically.
>
> You can create a formatter using
> org.eclipse.jdt.coreToolFactory.createCodeFormatter(codeForm atterOptions)
> and then apply it like this:
>
> protected static String formatCode(String contents,
> CodeFormatter codeFormatter)
> {
> IDocument doc = new Document(contents);
> TextEdit edit =
> codeFormatter.format(CodeFormatter.K_COMPILATION_UNIT, doc.get(), 0,
> doc.get().length(), 0, null);
>
> try
> {
> edit.apply(doc);
> contents = doc.get();
> }
> catch (Exception exception)
> {
> CodeGenEcorePlugin.INSTANCE.log(exception);
> }
>
> return contents;
> }
>
>
> Ed Thompson wrote:
>
>> And I am trying to find if there is a Best Practice way to reformat
>> the output accordinging to the Java Editor format selected by the user.
>
>
Re: Using JET to create java Code [message #567173 is a reply to message #22340] Thu, 16 February 2006 00:54 Go to previous message
Eclipse UserFriend
Originally posted by: ed.ed4becky.org

Ok, getting a wierd error when I try this:

String buffer = rmt.generate(bean);
CodeFormatter codeFormatter = ToolFactory.createCodeFormatter(null);

I am running it in a jUnir test just to test the concept. Googling
comes up with a ned to initialize something, but not sure what..


java.lang.ExceptionInInitializerError
at org.eclipse.jdt.core.JavaCore.getOptions(JavaCore.java:2401)
at
org.eclipse.jdt.core.ToolFactory.createCodeFormatter(ToolFac tory.java:96)
at
org.ed4becky.codegen.TestModelBeanTemplate.testGenerate(Test ModelBeanTemplate.java:39)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at junit.framework.TestCase.runTest(TestCase.java:154)
at junit.framework.TestCase.runBare(TestCase.java:127)
at junit.framework.TestResult$1.protect(TestResult.java:106)
at junit.framework.TestResult.runProtected(TestResult.java:124)
at junit.framework.TestResult.run(TestResult.java:109)
at junit.framework.TestCase.run(TestCase.java:118)
at junit.framework.TestSuite.runTest(TestSuite.java:208)
at junit.framework.TestSuite.run(TestSuite.java:203)
at
org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTe sts(RemoteTestRunner.java:478)
at
org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(R emoteTestRunner.java:344)
at
org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main( RemoteTestRunner.java:196)
Caused by: java.lang.NullPointerException
at
org.eclipse.jdt.internal.core.search.indexing.IndexManager.g etJavaPluginWorkingLocation(IndexManager.java:284)
at
org.eclipse.jdt.internal.core.search.indexing.IndexManager.<init >(IndexManager.java:50)
at
org.eclipse.jdt.internal.core.JavaModelManager.<init>(JavaModelManager.java:671)
at
org.eclipse.jdt.internal.core.JavaModelManager.<clinit>(JavaModelManager.java:649)
... 18 more




Ed Merks wrote:
> Ed,
>
> It's quite easy to invoke the formatter programmatically.
>
> You can create a formatter using
> org.eclipse.jdt.coreToolFactory.createCodeFormatter(codeForm atterOptions)
> and then apply it like this:
>
> protected static String formatCode(String contents,
> CodeFormatter codeFormatter)
> {
> IDocument doc = new Document(contents);
> TextEdit edit =
> codeFormatter.format(CodeFormatter.K_COMPILATION_UNIT, doc.get(), 0,
> doc.get().length(), 0, null);
>
> try
> {
> edit.apply(doc);
> contents = doc.get();
> }
> catch (Exception exception)
> {
> CodeGenEcorePlugin.INSTANCE.log(exception);
> }
>
> return contents;
> }
>
>
> Ed Thompson wrote:
>
>> And I am trying to find if there is a Best Practice way to reformat
>> the output accordinging to the Java Editor format selected by the user.
>
>
Re: Using JET to create java Code [message #567224 is a reply to message #22340] Thu, 16 February 2006 02:18 Go to previous message
Eclipse UserFriend
Originally posted by: ed.ed4becky.org

I traced it and JavaModelManager.getJavaModelManager() seems to fail,
though I cannot find who is throwing the exception.
Re: Using JET to create java Code [message #567318 is a reply to message #22682] Thu, 16 February 2006 10:25 Go to previous message
Ed Merks is currently offline Ed MerksFriend
Messages: 32561
Registered: July 2009
Senior Member
Ed,

Are you running in a headless Eclipse rather than stand-alone? That's
required for JDT to function properly.


Ed Thompson wrote:
> Ok, getting a wierd error when I try this:
>
> String buffer = rmt.generate(bean);
> CodeFormatter codeFormatter = ToolFactory.createCodeFormatter(null);
>
> I am running it in a jUnir test just to test the concept. Googling
> comes up with a ned to initialize something, but not sure what..
>
>
> java.lang.ExceptionInInitializerError
> at org.eclipse.jdt.core.JavaCore.getOptions(JavaCore.java:2401)
> at
> org.eclipse.jdt.core.ToolFactory.createCodeFormatter(ToolFac tory.java:96)
> at
> org.ed4becky.codegen.TestModelBeanTemplate.testGenerate(Test ModelBeanTemplate.java:39)
>
> at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
> at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
> at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
> at java.lang.reflect.Method.invoke(Unknown Source)
> at junit.framework.TestCase.runTest(TestCase.java:154)
> at junit.framework.TestCase.runBare(TestCase.java:127)
> at junit.framework.TestResult$1.protect(TestResult.java:106)
> at junit.framework.TestResult.runProtected(TestResult.java:124)
> at junit.framework.TestResult.run(TestResult.java:109)
> at junit.framework.TestCase.run(TestCase.java:118)
> at junit.framework.TestSuite.runTest(TestSuite.java:208)
> at junit.framework.TestSuite.run(TestSuite.java:203)
> at
> org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTe sts(RemoteTestRunner.java:478)
>
> at
> org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(R emoteTestRunner.java:344)
>
> at
> org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main( RemoteTestRunner.java:196)
>
> Caused by: java.lang.NullPointerException
> at
> org.eclipse.jdt.internal.core.search.indexing.IndexManager.g etJavaPluginWorkingLocation(IndexManager.java:284)
>
> at
> org.eclipse.jdt.internal.core.search.indexing.IndexManager.<init >(IndexManager.java:50)
>
> at
> org.eclipse.jdt.internal.core.JavaModelManager.<init>(JavaModelManager.java:671)
>
> at
> org.eclipse.jdt.internal.core.JavaModelManager.<clinit>(JavaModelManager.java:649)
>
> ... 18 more
>
>
>
>
> Ed Merks wrote:
>> Ed,
>>
>> It's quite easy to invoke the formatter programmatically.
>>
>> You can create a formatter using
>> org.eclipse.jdt.coreToolFactory.createCodeFormatter(codeForm atterOptions)
>> and then apply it like this:
>>
>> protected static String formatCode(String contents,
>> CodeFormatter codeFormatter)
>> {
>> IDocument doc = new Document(contents);
>> TextEdit edit =
>> codeFormatter.format(CodeFormatter.K_COMPILATION_UNIT, doc.get(), 0,
>> doc.get().length(), 0, null);
>> try
>> {
>> edit.apply(doc);
>> contents = doc.get();
>> }
>> catch (Exception exception)
>> {
>> CodeGenEcorePlugin.INSTANCE.log(exception);
>> }
>> return contents;
>> }
>>
>>
>> Ed Thompson wrote:
>>
>>> And I am trying to find if there is a Best Practice way to reformat
>>> the output accordinging to the Java Editor format selected by the user.
>>
>>


Ed Merks
Professional Support: https://www.macromodeling.com/
Previous Topic:Definition of OCL-Queries
Next Topic:Using the OCL parser
Goto Forum:
  


Current Time: Mon Nov 28 12:56:31 GMT 2022

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