Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » EMF » Problem when use generator in java code(when use generator function in java code the code generated is not correctly)
Problem when use generator in java code [message #1800801] Tue, 08 January 2019 13:58 Go to next message
Le Yang is currently offline Le YangFriend
Messages: 2
Registered: January 2019
Junior Member
the code that generated is not inherit the relation that defined by the emf model. And there is an Exception in SetInportmanager in the run time


the code that use generator is followed :
public boolean generator(GenModel genModel) {
// Generate Code
genModel.setCanGenerate(true);
if (genModel.getComplianceLevel().compareTo(GenJDKLevel.JDK50_LITERAL) < 0) {
genModel.setComplianceLevel(GenJDKLevel.JDK50_LITERAL);
}
GeneratorAdapterFactory.Descriptor.Registry.INSTANCE.addDescriptor(GenModelPackage.eNS_URI, GenModelGeneratorAdapterFactory.DESCRIPTOR);
// Create the generator and set the model-level input object.
Generator generator = new Generator();
generator.setInput(genModel);
// Generator model code.
Diagnostic d = generator.generate(genModel, GenBaseGeneratorAdapter.MODEL_PROJECT_TYPE, new BasicMonitor.Printing(System.out));
System.out.println(d.getMessage());



return false;
}


and the exception is followed:
java.lang.NullPointerException
at org.eclipse.emf.codegen.ecore.genmodel.impl.GenModelImpl.setImportManager(GenModelImpl.java:2536)
at org.eclipse.emf.codegen.ecore.genmodel.generator.GenBaseGeneratorAdapter.updateImportManager(GenBaseGeneratorAdapter.java:321)
at org.eclipse.emf.codegen.ecore.genmodel.generator.GenBaseGeneratorAdapter.clearImportManager(GenBaseGeneratorAdapter.java:314)
at org.eclipse.emf.codegen.ecore.generator.AbstractGeneratorAdapter.generateJava(AbstractGeneratorAdapter.java:2112)
at org.eclipse.emf.codegen.ecore.genmodel.generator.GenClassGeneratorAdapter.generateInterface(GenClassGeneratorAdapter.java:117)
at org.eclipse.emf.codegen.ecore.genmodel.generator.GenClassGeneratorAdapter.generateModel(GenClassGeneratorAdapter.java:100)
at org.eclipse.emf.codegen.ecore.genmodel.generator.GenBaseGeneratorAdapter.doGenerate(GenBaseGeneratorAdapter.java:215)
at org.eclipse.emf.codegen.ecore.generator.AbstractGeneratorAdapter.generate(AbstractGeneratorAdapter.java:319)
at org.eclipse.emf.codegen.ecore.generator.Generator.generate(Generator.java:718)
at org.eclipse.emf.codegen.ecore.generator.Generator.generate(Generator.java:629)
at fzi.emf.plugin.generator.cusGenerator.generator(cusGenerator.java:95)
at fzi.emf.plugin.generator.Generator.execute(Generator.java:66)
at org.eclipse.ui.internal.handlers.HandlerProxy.execute(HandlerProxy.java:294)
at org.eclipse.ui.internal.handlers.E4HandlerProxy.execute(E4HandlerProxy.java:96)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:483)
at org.eclipse.e4.core.internal.di.MethodRequestor.execute(MethodRequestor.java:58)
at org.eclipse.e4.core.internal.di.InjectorImpl.invokeUsingClass(InjectorImpl.java:320)
at org.eclipse.e4.core.internal.di.InjectorImpl.invoke(InjectorImpl.java:254)
at org.eclipse.e4.core.contexts.ContextInjectionFactory.invoke(ContextInjectionFactory.java:164)
at org.eclipse.e4.core.commands.internal.HandlerServiceHandler.execute(HandlerServiceHandler.java:156)
at org.eclipse.core.commands.Command.executeWithChecks(Command.java:497)
at org.eclipse.core.commands.ParameterizedCommand.executeWithChecks(ParameterizedCommand.java:490)
at org.eclipse.e4.core.commands.internal.HandlerServiceImpl.executeHandler(HandlerServiceImpl.java:207)
at org.eclipse.e4.ui.workbench.renderers.swt.HandledContributionItem.executeItem(HandledContributionItem.java:436)
at org.eclipse.e4.ui.workbench.renderers.swt.AbstractContributionItem.handleWidgetSelection(AbstractContributionItem.java:449)
at org.eclipse.e4.ui.workbench.renderers.swt.AbstractContributionItem.lambda$2(AbstractContributionItem.java:475)
at org.eclipse.e4.ui.workbench.renderers.swt.AbstractContributionItem$$Lambda$221/676538195.handleEvent(Unknown Source)
at org.eclipse.swt.widgets.EventTable.sendEvent(EventTable.java:89)
at org.eclipse.swt.widgets.Display.sendEvent(Display.java:4292)
at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1512)
at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1535)
at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1520)
at org.eclipse.swt.widgets.Widget.notifyListeners(Widget.java:1324)
at org.eclipse.swt.widgets.Display.runDeferredEvents(Display.java:4116)
at org.eclipse.swt.widgets.Display.readAndDispatch(Display.java:3733)
at org.eclipse.e4.ui.internal.workbench.swt.PartRenderingEngine$5.run(PartRenderingEngine.java:1173)
at org.eclipse.core.databinding.observable.Realm.runWithDefault(Realm.java:339)
at org.eclipse.e4.ui.internal.workbench.swt.PartRenderingEngine.run(PartRenderingEngine.java:1062)
at org.eclipse.e4.ui.internal.workbench.E4Workbench.createAndRunUI(E4Workbench.java:156)
at org.eclipse.ui.internal.Workbench.lambda$3(Workbench.java:628)
at org.eclipse.ui.internal.Workbench$$Lambda$23/1615669446.run(Unknown Source)
at org.eclipse.core.databinding.observable.Realm.runWithDefault(Realm.java:339)
at org.eclipse.ui.internal.Workbench.createAndRunWorkbench(Workbench.java:563)
at org.eclipse.ui.PlatformUI.createAndRunWorkbench(PlatformUI.java:151)
at org.eclipse.ui.internal.ide.application.IDEApplication.start(IDEApplication.java:155)
at org.eclipse.equinox.internal.app.EclipseAppHandle.run(EclipseAppHandle.java:199)
at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.runApplication(EclipseAppLauncher.java:137)
at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.start(EclipseAppLauncher.java:107)
at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:391)
at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:246)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:483)
at org.eclipse.equinox.launcher.Main.invokeFramework(Main.java:659)
at org.eclipse.equinox.launcher.Main.basicRun(Main.java:595)
at org.eclipse.equinox.launcher.Main.run(Main.java:1501)
at org.eclipse.equinox.launcher.Main.main(Main.java:1474)
Re: Problem when use generator in java code [message #1800918 is a reply to message #1800801] Wed, 09 January 2019 17:47 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 30693
Registered: July 2009
Senior Member
It sounds like you have unresolved proxies in your model.
Re: Problem when use generator in java code [message #1800956 is a reply to message #1800918] Thu, 10 January 2019 10:58 Go to previous messageGo to next message
Le Yang is currently offline Le YangFriend
Messages: 2
Registered: January 2019
Junior Member
thanks for the replying when i use emf directly it works alright but with the code i write i came to this problem, so should i chang something in my code?
Re: Problem when use generator in java code [message #1800968 is a reply to message #1800956] Thu, 10 January 2019 12:48 Go to previous message
Ed Merks is currently offline Ed MerksFriend
Messages: 30693
Registered: July 2009
Senior Member
I don't know anything about your code, so I can at best guess. One guess would be that you aren't doing this bit of magic:
resourceSet.getURIConverter().getURIMap().putAll(EcorePlugin.computePlatformURIMap(true));
on the resource set into which you've loaded your GenModel. The GenModelEditor does this when the editor loads the resource.

To debug this further, set an exception breakpoint (the little J! icon in the Breaks view) for NullPointerException. Then use the debugger's variables view to figure out the proxy URI of the genPackage whose getGenModel() is returning null. You'll need to figure out why that proxy doesn't resolve.
Previous Topic:copy an element
Next Topic:Copy Paste issue
Goto Forum:
  


Current Time: Sun Dec 15 17:43:35 GMT 2019

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

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

Back to the top