Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » MoDisco » How can i generate a KDM code model programatically?
How can i generate a KDM code model programatically? [message #1221433] Tue, 17 December 2013 12:44 Go to next message
keynne Belle is currently offline keynne Belle
Messages: 21
Registered: January 2013
Junior Member
Hello.
I am trying to generate a KDM code model programmatically. For this purpose, i use the following instructions:
IProject project = ResourcesPlugin.getWorkspace().getRoot().getProject(projectName);
IJavaProject javaProject = JavaCore.create(project);
DiscoverKDMModelFromJavaProject kdmDiscoverer = new DiscoverKDMModelFromJavaProject();
kdmDiscoverer.discoverElement(javaProject, new NullProgressMonitor());
Resource kdmResource = kdmDiscoverer.getTargetModel();
//serialize


However, i get a NullPointerException with the method discoverElement() and i don't exactly know what is going wrong with this code. Could you help me figure it out? Is there a better way to to generate a KDM code model programmatically? Here are the details of the NullPointerException i get:

java.lang.NullPointerException
at org.eclipse.modisco.java.discoverer.internal.io.java.JDTVisitor.endVisit(JDTVisitor.java:1597)
at org.eclipse.jdt.core.dom.MethodDeclaration.accept0(MethodDeclaration.java:506)
at org.eclipse.jdt.core.dom.ASTNode.accept(ASTNode.java:2514)
at org.eclipse.jdt.core.dom.ASTNode.acceptChildren(ASTNode.java:2585)
at org.eclipse.jdt.core.dom.TypeDeclaration.accept0(TypeDeclaration.java:484)
at org.eclipse.jdt.core.dom.ASTNode.accept(ASTNode.java:2514)
at org.eclipse.jdt.core.dom.ASTNode.acceptChildren(ASTNode.java:2585)
at org.eclipse.jdt.core.dom.CompilationUnit.accept0(CompilationUnit.java:219)
at org.eclipse.jdt.core.dom.ASTNode.accept(ASTNode.java:2514)
at org.eclipse.modisco.java.discoverer.internal.io.java.JavaReader.visitCompilationUnit(JavaReader.java:322)
at org.eclipse.modisco.java.discoverer.internal.io.java.JavaReader.parseTypeRoot(JavaReader.java:279)
at org.eclipse.modisco.java.discoverer.internal.io.java.JavaReader.parsePackage(JavaReader.java:304)
at org.eclipse.modisco.java.discoverer.internal.io.java.JavaReader.readModel(JavaReader.java:182)
at org.eclipse.modisco.java.discoverer.AbstractDiscoverJavaModelFromProject.analyzeJavaProject(AbstractDiscoverJavaModelFromProject.java:162)
at org.eclipse.modisco.java.discoverer.DiscoverJavaModelFromJavaProject.basicDiscoverElement(DiscoverJavaModelFromJavaProject.java:38)
at org.eclipse.modisco.java.discoverer.DiscoverJavaModelFromJavaProject.basicDiscoverElement(DiscoverJavaModelFromJavaProject.java:1)
at org.eclipse.modisco.infra.discovery.core.AbstractDiscoverer.discoverElement(AbstractDiscoverer.java:93)
at org.eclipse.modisco.infra.discovery.core.AbstractModelDiscoverer.discoverElement(AbstractModelDiscoverer.java:183)
at org.eclipse.modisco.java.discoverer.DiscoverKDMModelFromJavaProject.discoverKDM(DiscoverKDMModelFromJavaProject.java:56)
at org.eclipse.modisco.java.discoverer.DiscoverKDMModelFromJavaProject.basicDiscoverElement(DiscoverKDMModelFromJavaProject.java:46)
at org.eclipse.modisco.java.discoverer.DiscoverKDMModelFromJavaProject.basicDiscoverElement(DiscoverKDMModelFromJavaProject.java:1)
at org.eclipse.modisco.infra.discovery.core.AbstractDiscoverer.discoverElement(AbstractDiscoverer.java:93)
at org.eclipse.modisco.infra.discovery.core.AbstractModelDiscoverer.discoverElement(AbstractModelDiscoverer.java:183)
at realeity.util.KDMDiscoverer.kdmModelDiscovery(KDMDiscoverer.java:95)
at view.actions.ExtractionAction.generateKDM(ExtractionAction.java:129)
at view.actions.ExtractionAction.run(ExtractionAction.java:48)
at org.eclipse.jface.action.Action.runWithEvent(Action.java:498)
at org.eclipse.jface.action.ActionContributionItem.handleWidgetSelection(ActionContributionItem.java:584)
at org.eclipse.jface.action.ActionContributionItem.access$2(ActionContributionItem.java:501)
at org.eclipse.jface.action.ActionContributionItem$6.handleEvent(ActionContributionItem.java:452)
at org.eclipse.swt.widgets.EventTable.sendEvent(EventTable.java:84)
at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1053)
at org.eclipse.swt.widgets.Display.runDeferredEvents(Display.java:4165)
at org.eclipse.swt.widgets.Display.readAndDispatch(Display.java:3754)
at org.eclipse.ui.internal.Workbench.runEventLoop(Workbench.java:2701)
at org.eclipse.ui.internal.Workbench.runUI(Workbench.java:2665)
at org.eclipse.ui.internal.Workbench.access$4(Workbench.java:2499)
at org.eclipse.ui.internal.Workbench$7.run(Workbench.java:679)
at org.eclipse.core.databinding.observable.Realm.runWithDefault(Realm.java:332)
at org.eclipse.ui.internal.Workbench.createAndRunWorkbench(Workbench.java:668)
at org.eclipse.ui.PlatformUI.createAndRunWorkbench(PlatformUI.java:149)
at org.eclipse.ui.internal.ide.application.IDEApplication.start(IDEApplication.java:123)
at org.eclipse.equinox.internal.app.EclipseAppHandle.run(EclipseAppHandle.java:196)
at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.runApplication(EclipseAppLauncher.java:110)
at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.start(EclipseAppLauncher.java:79)
at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:344)
at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:179)
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 org.eclipse.equinox.launcher.Main.invokeFramework(Main.java:622)
at org.eclipse.equinox.launcher.Main.basicRun(Main.java:577)
at org.eclipse.equinox.launcher.Main.run(Main.java:1410)
at org.eclipse.equinox.launcher.Main.main(Main.java:1386)
Re: How can i generate a KDM code model programatically? [message #1221696 is a reply to message #1221433] Wed, 18 December 2013 03:56 Go to previous messageGo to next message
Hugo Bruneliere is currently offline Hugo Bruneliere
Messages: 600
Registered: July 2009
Senior Member
Hello,

Have you checked too with the other KDM discoverer interfaces, for instance DiscoverKDMModelFromJavaModel from a previously discovered Java model?


------------------------------------------
Hugo Bruneliere - R&D Engineer
AtlanMod research team (Inria, EMN & LINA)
Ecole des Mines de Nantes
Nantes - France
------------------------------------------
Re: How can i generate a KDM code model programatically? [message #1221700 is a reply to message #1221433] Wed, 18 December 2013 04:06 Go to previous messageGo to next message
keynne Belle is currently offline keynne Belle
Messages: 21
Registered: January 2013
Junior Member
Hi.
I read the code of Thanasis Naskos (http://www.eclipse.org/forums/index.php/t/213661/) who succeeded at generating a java model from a java project. And it gave me the inspiration to modify my code in order to generate a KDM model from a project containing a java code. My new code seems to work. Here are its instructions:
IProject project = ResourcesPlugin.getWorkspace().getRoot().getProject(projectName);
DiscoverKDMModelFromProject kdmDiscoverer = new DiscoverKDMModelFromProject();
kdmDiscoverer.setSerializeTarget(true);
kdmDiscoverer.discoverElement(project, new NullProgressMonitor());
Resource kdmResource = kdmDiscoverer.getTargetModel();

I hope it will be helpful to other developers Smile
Thanks a lot for your help Hugo Bruneliere.

[Updated on: Wed, 18 December 2013 04:21]

Report message to a moderator

Re: How can i generate a KDM code model programatically? [message #1221701 is a reply to message #1221700] Wed, 18 December 2013 04:08 Go to previous messageGo to next message
Hugo Bruneliere is currently offline Hugo Bruneliere
Messages: 600
Registered: July 2009
Senior Member
Great, thanks Smile

------------------------------------------
Hugo Bruneliere - R&D Engineer
AtlanMod research team (Inria, EMN & LINA)
Ecole des Mines de Nantes
Nantes - France
------------------------------------------
Re: How can i generate a KDM code model programatically? [message #1221707 is a reply to message #1221433] Wed, 18 December 2013 04:14 Go to previous message
keynne Belle is currently offline keynne Belle
Messages: 21
Registered: January 2013
Junior Member
No Message Body

[Updated on: Wed, 18 December 2013 04:19]

Report message to a moderator

Previous Topic:created kdm.xmi - but can't do anything with it
Next Topic:How can i persist a new created KDM model?
Goto Forum:
  


Current Time: Tue Jul 22 23:46:45 EDT 2014

Powered by FUDForum. Page generated in 0.02059 seconds