How to access index from wizard (without eObject) [message #1800819] |
Tue, 08 January 2019 12:59  |
Eclipse User |
|
|
|
Hi,
I would like to implement a new entity wizard that provides semantic help to the user (autocompletion, etc...). In order to access the index I need an EObject, which I don't have at this point - while I have the user's current selection (a file or directory), I just use the selection to compute the Eclipse Project, the user is currently working in.
What is the correct way to access the index in this case? Should I search the file strucuture in order to find a file in the current project that stores an Entity and then load this Entity from the file? What if there is not such file (the project could, e.g., be brand new and empty)?
Is there anything I might be missing?
Thanks in advance!
|
|
|
|
|
|
|
|
|
|
|
|
Re: How to access index from wizard (without eObject) [message #1800877 is a reply to message #1800844] |
Wed, 09 January 2019 06:04   |
Eclipse User |
|
|
|
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
}
|
|
|
|
|
|
|
|
Re: How to access index from wizard (without eObject) [message #1800899 is a reply to message #1800891] |
Wed, 09 January 2019 09:08  |
Eclipse User |
|
|
|
OK, thank you. I will keep the IResourceDescriptions version then, and maybe try out IBuilderState later.
I also tried Mocking the ResourceDescription and now it works better (no more ErrorLogs). See below for the code, but its trivial.
Thanks again, you've been tremendously helpful!
val dDesc = rdmgr.getResourceDescription(res)
val dummyDesc = new IResourceDescription() {
override getExportedObjects() { dDesc.getExportedObjects }
override getImportedNames() {
dDesc.getImportedNames
}
override getReferenceDescriptions() {
emptyList
}
override getURI() {
dDesc.getURI
}
override getExportedObjects(EClass type, QualifiedName name, boolean ignoreCase) {
emptyList
}
override getExportedObjectsByObject(EObject object) {
emptyList
}
override getExportedObjectsByType(EClass type) {
emptyList
}
override isEmpty() {
dDesc.isEmpty
}
}
|
|
|
Powered by
FUDForum. Page generated in 0.09414 seconds