|
|
Re: How to access index from wizard (without eObject) [message #1800822 is a reply to message #1800820] |
Tue, 08 January 2019 18:25 |
Konrad Jünemann Messages: 93 Registered: December 2018 |
Member |
|
|
Hi,
I usually access the index like this:
@Inject
var ResourceDescriptionsProvider rdp
@Inject
IContainer.Manager cm
private def getVisibleEObjectDescriptions(EObject o, EClass type) {
val tmp = o.getVisibleContainers.map [ c |
c.getExportedObjectsByType(type)
]
return tmp.flatten
}
private def getVisibleContainers(EObject o) {
if (o?.eResource === null)
return emptyList
val index = rdp.getResourceDescriptions(o.eResource)
val rd = index.getResourceDescription(o.eResource.URI)
if (rd === null)
return Collections.emptyList
cm.getVisibleContainers(rd, index)
}
So later I access getVisibleEObjectDescriptions when I an searching whether or not an Entity with a known name exists.
How is the IBuilderState different from a ResourceDescriptions?
Edit: Of course the problem here is that in order to use getVisibleEObjectDescriptions() I need an eObject first.
[Updated on: Tue, 08 January 2019 18:26] Report message to a moderator
|
|
|
|
|
|
|
|
Re: How to access index from wizard (without eObject) [message #1800841 is a reply to message #1800840] |
Tue, 08 January 2019 21:37 |
|
well. the main problem is: there is no proper api for your usecase.
what happens if you call it with a fake uri / resource desciption in the project?
IProject p = file.getProject();
//TODO make this be in a source folder if you have a java projct
URI fakeUri = URI.createURI("platform:/resource/"+p.getName()+"/dummy.mydsl");
ResourceSet resourceSet = rsp.get(p);
Resource fakeResource = resourceSet.createResource(fakeUri);
IContainer container = cmgr.getContainer(rdmgr.getResourceDescription(fakeResource), index);
System.err.println(container);
for (IContainer vc : cmgr.getVisibleContainers(rdmgr.getResourceDescription(fakeResource), index)) {
System.err.println(vc);
}
return null;
}
@Inject
IBuilderState index;
@Inject
IContainer.Manager cmgr;
@Inject
IResourceDescription.Manager rdmgr;
@Inject
IResourceSetProvider rsp;
Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
[Updated on: Tue, 08 January 2019 21:57] Report message to a moderator
|
|
|
Re: How to access index from wizard (without eObject) [message #1800844 is a reply to message #1800841] |
Tue, 08 January 2019 22:17 |
Konrad Jünemann Messages: 93 Registered: December 2018 |
Member |
|
|
This code works if I use an entity-File, but throws an java.lang.reflect.InvocationTargetException if I use an IProject. Any other ideas?
@Inject
var Provider<XtextResourceSet> rsp
def toResource(IResource proj) {
val rset = rsp.get
val uri = URI.createPlatformResourceURI(proj.getFullPath().toString(), true)
val res = rset.getResource(uri, true)
return res
}
Edit: Did not see your Update in time. Will try your code tomorrow. :)
[Updated on: Tue, 08 January 2019 22:24] Report message to a moderator
|
|
|
Re: How to access index from wizard (without eObject) [message #1800877 is a reply to message #1800844] |
Wed, 09 January 2019 11:04 |
Konrad Jünemann Messages: 93 Registered: December 2018 |
Member |
|
|
Hi Christian,
thanks a lot, the code below no (kinda) works. There remain two issues though:
1. When trying to access the dummy file, an exception is thrown which will be logged by class DefaultResourceDescription. I would at least like to prevent the error from being logged, as it is expected.
Caused by: org.eclipse.core.internal.resources.ResourceException: Resource '/Demo/dummy.dsl' does not exist.
at org.eclipse.core.internal.resources.Resource.checkExists(Resource.java:335)
at org.eclipse.core.internal.resources.Resource.checkAccessible(Resource.java:209)
at org.eclipse.core.internal.resources.File.getContents(File.java:275)
at org.eclipse.core.internal.resources.File.getContents(File.java:268)
at org.eclipse.emf.ecore.resource.impl.PlatformResourceURIHandlerImpl$WorkbenchHelper.createPlatformResourceInputStream(PlatformResourceURIHandlerImpl.java:207)
... 65 more
2. The exception is thrown, because the Container created is a DescriptionAddingContainer, which delegates to a StateBasedContainer. I think the whole error could be prevented, if I could create a StateBasedContainer directly, i.e., without nesting it in a DescriptionAddingContainer, as the "added" description is a dummy anyway. Any ideas how to achieve this? This would also fix problem 1.
3. Not a problem but a question: You proposed to use a IBuilderState instead of an IResourceDescriptions (I know that IBuilderState *is* an IResourceDescriptions). In your book it is proposed to use IResourceDescriptions - what is the difference? Which one should be used? To retrieve an IResourceDescriptions from a ResourceDescriptionsProvider you need a Resource - why, if an IBuilderState does not require a resource? I am a bit at a loss here.
Thanks for your great support!
Code:
@Inject
var Provider<XtextResourceSet> rsp
@Inject
IBuilderState index;
@Inject
IContainer.Manager cmgr;
@Inject
IResourceDescription.Manager rdmgr;
def searchIndexByType(IResource ires, EClass type) {
val rset = rsp.get
val uri = URI.createURI("platform:/resource/"+ires.project.getName()+"/dummy.dsl");
val res = rset.createResource(uri)
val IContainer projCont = cmgr.getContainer(rdmgr.getResourceDescription(res), index);
System.err.println("projCont: " + projCont);
val vcs = cmgr.getVisibleContainers(rdmgr.getResourceDescription(res), index)
for (IContainer vc : vcs) {
System.err.println("visible: " + vc);
}
val List<IEObjectDescription> result = newArrayList
for (vc : vcs) {
try {
val descrs = vc.getExportedObjectsByType(type).toList
result.addAll(descrs)
} catch (Exception e) {
// do nothing
println("ERROR")
}
}
return result
}
|
|
|
|
|
|
|
|
|
Powered by
FUDForum. Page generated in 0.07440 seconds