Second GeneratorFragment [message #756072] |
Thu, 10 November 2011 14:11  |
Eclipse User |
|
|
|
hi,
I have a problem with the second generator and I am getting a strange error message.
In the following I have posted some code to illustrate it (the error message is at the end of the posting).
package org.xtext.gui;
import org.xtext.gui.generator.GuiDslGeneratorAnother;
import com.google.inject.Guice;
import com.google.inject.Injector;
public class AnotherInjector extends GuiDslStandaloneSetup {
public Injector createInjector() {
return Guice.createInjector(new AnotherRuntimeModule());
}
public class AnotherRuntimeModule extends GuiDslRuntimeModule {
@Override
public Class<? extends org.eclipse.xtext.generator.IGenerator> bindIGenerator() {
return GuiDslGeneratorAnother.class;
}
}
}
My GuiDslGeneratorMWE.mwe2 in the generator package looks like this:
module org.xtext.gui.generator.GuiDslGeneratorMWE
import org.eclipse.emf.mwe.utils.*
var targetDir = "src-gen"
var modelPath = "dmodel"
Workflow {
component = org.eclipse.xtext.mwe.Reader {
// lookup all resources on the classpath
// useJavaClassPath = true
// or define search scope explicitly
path = modelPath
// this class will be generated by the xtext generator
register = org.xtext.gui.GuiDslStandaloneSetup {}
loadResource = {
slot = "model"
}
}
component = org.eclipse.xtext.generator.GeneratorComponent {
register = org.xtext.gui.GuiDslStandaloneSetup {}
slot = 'model'
outlet = {
path = targetDir
}
}
}
In the generator package I have also created two xtend files:
GuiDslGenerator.xtend
GuiDslGeneratorAnother.xtend
But I am getting a strang error message now.
0 [main] ERROR mf.mwe2.launch.runtime.Mwe2Launcher - Problems instantiating module org.xtext.gui.generator.GuiDslGeneratorMWE: java.lang.reflect.InvocationTargetException
java.lang.RuntimeException: Problems instantiating module org.xtext.gui.generator.GuiDslGeneratorMWE: java.lang.reflect.InvocationTargetException
at org.eclipse.emf.mwe2.launch.runtime.Mwe2Runner.run(Mwe2Runner.java:90)
at org.eclipse.emf.mwe2.launch.runtime.Mwe2Runner.run(Mwe2Runner.java:73)
at org.eclipse.emf.mwe2.launch.runtime.Mwe2Runner.run(Mwe2Runner.java:64)
at org.eclipse.emf.mwe2.launch.runtime.Mwe2Runner.run(Mwe2Runner.java:55)
at org.eclipse.emf.mwe2.launch.runtime.Mwe2Launcher.run(Mwe2Launcher.java:74)
at org.eclipse.emf.mwe2.launch.runtime.Mwe2Launcher.main(Mwe2Launcher.java:35)
I hope you can help me out.
regards,
jens.
[Updated on: Thu, 10 November 2011 14:12] by Moderator
|
|
|
|
Re: Second GeneratorFragment [message #756245 is a reply to message #756088] |
Fri, 11 November 2011 11:27   |
Eclipse User |
|
|
|
hi,
sorry I don't know how to debug. I tried to keep it more simple.
So now I have only a console output in my generator file.
"run as" of the GuiDslGeneratorMWE.mwe2 file gives me the following response:
0 [main] INFO .emf.mwe2.runtime.workflow.Workflow - Done.
But there is no console output?
- System::out.println("Hello i'm the normal generator!");
package org.xtext.gui.generator
import org.eclipse.emf.ecore.resource.Resource
import org.eclipse.xtext.generator.IGenerator
import org.eclipse.xtext.generator.IFileSystemAccess
import org.eclipse.emf.ecore.resource.Resource
import org.eclipse.xtext.xbase.compiler.*
import org.eclipse.xtext.xbase.*
import org.eclipse.xtext.common.types.*
import com.google.inject.*
import org.xtext.gui.guiDsl.*
import java.util.*
import static extension org.eclipse.xtext.xtend2.lib.ResourceExtensions.*
import org.eclipse.xtext.naming.*
class GuiDslGenerator implements IGenerator {
@Inject extension IQualifiedNameProvider nameProvider
override void doGenerate(Resource resource, IFileSystemAccess fsa) {
System::out.println("Hello i'm the normal generator!");
}
}
package org.xtext.gui.generator.another
import org.eclipse.emf.ecore.resource.Resource
import org.eclipse.xtext.generator.IGenerator
import org.eclipse.xtext.generator.IFileSystemAccess
import org.eclipse.emf.ecore.resource.Resource
import org.eclipse.xtext.xbase.compiler.*
import org.eclipse.xtext.xbase.*
import org.eclipse.xtext.common.types.*
import com.google.inject.*
import org.xtext.gui.guiDsl.*
import java.util.*
import static extension org.eclipse.xtext.xtend2.lib.ResourceExtensions.*
import org.eclipse.xtext.naming.*
class AnotherGenerator implements IGenerator {
@Inject extension IQualifiedNameProvider nameProvider
override void doGenerate(Resource resource, IFileSystemAccess fsa) {
System::out.println("Hello I'm another Generator!");
}
}
module org.xtext.gui.generator.GuiDslGeneratorMWE
import org.eclipse.emf.mwe.utils.*
var targetDir = "src-gen"
var modelPath = "model"
Workflow {
component = org.eclipse.xtext.mwe.Reader {
// lookup all resources on the classpath
// useJavaClassPath = true
// or define search scope explicitly
path = modelPath
// this class will be generated by the xtext generator
register = org.xtext.gui.GuiDslStandaloneSetup {}
loadResource = {
slot = "model"
}
}
component = org.eclipse.xtext.generator.GeneratorComponent {
register = org.xtext.gui.GuiDslStandaloneSetup {}
slot = 'model'
outlet = {
path = targetDir
}
}
}
I have created a folder "model" in my workspace.
With the file "gui.mydsl"
package com.gui {
window win {
}
}
and so on..
regards,
jens
Even when I start a complete new project. I don't get the console output.
override void doGenerate(Resource resource, IFileSystemAccess fsa) {
System::out.println("Hello i'm the normal generator!");
for(e: resource.allContentsIterable.filter(typeof(PackageDeclaration))) {
fsa.generateFile(
e.fullyQualifiedName.toString.replace(".", "/") + ".java",
e.compile)
}
}
How can I make sure, that the doGenerate-method is called?
[Updated on: Fri, 11 November 2011 14:21] by Moderator
|
|
|
|
|
Re: Second GeneratorFragment [message #756353 is a reply to message #756303] |
Sat, 12 November 2011 05:44   |
Eclipse User |
|
|
|
update of my post:
It works now, but only when the beautifier is not activated.
in the .xtend file:
override void doGenerate(Resource resource, IFileSystemAccess fsa) {
System::out.println("Hey here is the Generator!!!!!!!!!!!")
for(e: resource.allContentsIterable.filter(typeof(PackageDeclaration))) {
fsa.generateFile(
e.fullyQualifiedName.toString.replace(".", "/") + "/Win" + ".java",
b.format(e.fullyQualifiedName.toString.replace(".", "/") + "/Win" + ".java",
e.compile))
}
package org.xtext.gui.dm.generator;
import java.io.File;
import org.eclipse.xpand2.output.FileHandle;
import org.eclipse.xpand2.output.FileHandleImpl;
import org.eclipse.xpand2.output.JavaBeautifier;
import org.eclipse.xpand2.output.Outlet;
import com.google.inject.Inject;
import com.google.inject.Singleton;
@Singleton
public class Beautifier {
@Inject
JavaBeautifier javaBeautifier;
/**
* Format code with PostProcessor (XPand style).
*/
public CharSequence format(String fileName, CharSequence code) {
// create fileHandle with dummy outlet.
File file = new File(fileName);
FileHandle fileHandle = new FileHandleImpl(new Outlet(), file);
fileHandle.setBuffer(code);
// call postProcessor for formatting the code.
javaBeautifier.beforeWriteAndClose(fileHandle);
// return formatted results.
return fileHandle.getBuffer();
}
}
With the activated beautifier I still get the error message:
1 [main] ERROR mf.mwe2.launch.runtime.Mwe2Launcher - Problems instantiating module org.xtext.gui.dm.generator.GuiDslGeneratorMWE: java.lang.reflect.InvocationTargetException
java.lang.RuntimeException: Problems instantiating module org.xtext.gui.dm.generator.GuiDslGeneratorMWE: java.lang.reflect.InvocationTargetException
at org.eclipse.emf.mwe2.launch.runtime.Mwe2Runner.run(Mwe2Runner.java:90)
at org.eclipse.emf.mwe2.launch.runtime.Mwe2Runner.run(Mwe2Runner.java:73)
at org.eclipse.emf.mwe2.launch.runtime.Mwe2Runner.run(Mwe2Runner.java:64)
at org.eclipse.emf.mwe2.launch.runtime.Mwe2Runner.run(Mwe2Runner.java:55)
at org.eclipse.emf.mwe2.launch.runtime.Mwe2Launcher.run(Mwe2Launcher.java:74)
regards,
Jens
|
|
|
|
|
|
|
Powered by
FUDForum. Page generated in 0.16263 seconds