NPE when creating DRepresentation [message #1741479] |
Thu, 25 August 2016 09:36  |
Eclipse User |
|
|
|
Hello,
I am currently developing an eclipse plugin whose purpose is to open a Sirius representation of a DSL file. If there is no aird file, or no existing representation of if, then it does what is needed to generate the diagram (creating the session, aird, representation, select viewpoint,...).
I have no problem with loading an existing representation, but I am struggling with creating a new one. Here is my code:
Collection<RepresentationDescription> descs = DialectManager.INSTANCE.getAvailableRepresentationDescriptions(session.getSelectedViewpoints(false), model);
for (RepresentationDescription desc : descs) {
if (DialectManager.INSTANCE.canCreate(model, desc)) {
rep = DialectManager.INSTANCE.createRepresentation(ifile.getParent().getFullPath().toString(), model, desc, session, new NullProgressMonitor());
DialectUIManager.INSTANCE.openEditor(session, rep, new NullProgressMonitor());
session.save(new NullProgressMonitor());
}
}
The NPE is at the line
rep = DialectManager.INSTANCE.createRepresentation(ifile.getParent().getFullPath().toString(), model, desc, session, new NullProgressMonitor());
And the stack trace is:
java.lang.NullPointerException
at org.eclipse.sirius.diagram.business.internal.experimental.sync.DDiagramSynchronizer.getAllInitialyActiveLayers(DDiagramSynchronizer.java:301)
at org.eclipse.sirius.diagram.business.internal.experimental.sync.DDiagramSynchronizer.activateInitialLayers(DDiagramSynchronizer.java:283)
at org.eclipse.sirius.diagram.business.internal.experimental.sync.DDiagramSynchronizer.initDiagram(DDiagramSynchronizer.java:237)
at org.eclipse.sirius.diagram.business.internal.sync.DDiagramSynchronizer.initDiagram(DDiagramSynchronizer.java:57)
at org.eclipse.sirius.diagram.business.internal.dialect.DiagramDialectServices.createRepresentation(DiagramDialectServices.java:166)
at org.eclipse.sirius.diagram.business.internal.dialect.DiagramDialectServices.createRepresentation(DiagramDialectServices.java:179)
at org.eclipse.sirius.business.internal.dialect.DialectManagerImpl.createRepresentation(DialectManagerImpl.java:173)
at org.eclipse.sirius.business.api.dialect.command.CreateRepresentationCommand.doExecute(CreateRepresentationCommand.java:117)
at org.eclipse.emf.transaction.RecordingCommand.execute(RecordingCommand.java:135)
at org.eclipse.emf.workspace.EMFCommandOperation.doExecute(EMFCommandOperation.java:119)
at org.eclipse.emf.workspace.AbstractEMFOperation.execute(AbstractEMFOperation.java:150)
at org.eclipse.core.commands.operations.DefaultOperationHistory.execute(DefaultOperationHistory.java:516)
at org.eclipse.emf.workspace.impl.WorkspaceCommandStackImpl.doExecute(WorkspaceCommandStackImpl.java:208)
at org.eclipse.emf.transaction.impl.AbstractTransactionalCommandStack.execute(AbstractTransactionalCommandStack.java:165)
at org.eclipse.emf.transaction.impl.AbstractTransactionalCommandStack.execute(AbstractTransactionalCommandStack.java:219)
I cannot debug directly the program since I an using Sirius as a plugin, so I took a look at the sources, but I found no reason to get this error. I think it might come from desc, but the only null parameter that does not seem normal is the "init" one: do someone know what it correspond to?
And if anyone have an idea concerning this error, I would appreciate some help
Thank you,
Vincent
[Updated on: Fri, 26 August 2016 04:36] by Moderator
|
|
|
|
Re: NPE when creating DRepresentation [message #1741599 is a reply to message #1741501] |
Fri, 26 August 2016 04:45  |
Eclipse User |
|
|
|
Hi Maxime,
Thank you for taking the time to answer.
What I did is importing org.eclipse.sirius.diagram from Repository, but I have a problem with one of the import of DiagramDialectSelect:
import org.eclipse.sirius.viewpoint.DRepresentationDescriptor;
It makes it impossible to debug... I looked for this class, but I havent found it: is there anything I can do to get it? Or am I missing something?
EDIT: I finally got it to work! I looked at the sources again and realized that the session could be null too. So I tried to do SessionManager.INSTANCE.getSession(resource) with the resource I was using: the value was null. Then I tried with Resource res = session.getSemanticResources().iterator().next(); as the parameter, and it now works perfectly.
Thank you for your help,
Keep up the good work on Sirius,
Vincent
[Updated on: Fri, 26 August 2016 05:10] by Moderator
|
|
|
Powered by
FUDForum. Page generated in 0.02595 seconds