Closed philip-alldredge closed 5 years ago
It would be even better to have an AADL search dialog.
An example for a search contribution: https://github.com/Pontesegger/codeandme/tree/master/search_provider/com.codeandme.searchprovider
Okay, so I get that we want an AADL tab in the Eclipse search box. What I don't get is what special thing it is supposed to do.
It should do similar things as the Java search: Maybe find classifier declarations, find package declaration, find classifier references, find property declaration/usage, etc. We should start with something simple and then add more items as needed. It should support scope selection like the Java search (project, workspace, working set, AADL contributed by plugins, etc.)
start with find classifier and find property
Found TextSearchVisitor
and TextSearchVisitor.TextSearchJob
in package org.eclipse.search.internal.core.text
in plug-in org.eclipse.search
. Also org.eclipse.search.internal.ui.text.TextSearchPage
in the same plug-in. These are useful for seeing how to control the scoping of the search.
Interesting - I don't see any lock of the resource tree?
Plan now is
Initial version of the "AADL Search" page.
Look at EMFIndexRetrieval
for Xtext scoping business. Badly written class but searches for names in the scope the right way.
Get the injector in the same way as EMV2AnnexParser
:
public EMV2AnnexParser() {
Injector injector = IResourceServiceProvider.Registry.INSTANCE
.getResourceServiceProvider(URI.createFileURI("dummy.emv2")).get(Injector.class);
injector.injectMembers(this);
}
But use .aadl
as the file extension.
Possibility to get declarations
Look for AADL2 impl of IReferenceFinder
. Figure out how to use it
Added class AadlFinder
(better name please?):
public final class AadlFinder {
private static final AadlFinder instance = new AadlFinder();
@Inject
private ResourceDescriptionsProvider resourcesDescriptionProvider;
private AadlFinder() {
final Injector injector = IResourceServiceProvider.Registry.INSTANCE
.getResourceServiceProvider(URI.createFileURI("dummy.aadl")).get(Injector.class);
injector.injectMembers(this);
}
public static AadlFinder getInstance() {
return instance;
}
/**
* Get all the {@link Classifier}s in the workspace.
*/
public EList<IEObjectDescription> getAllClassifiersInWorkspace() {
final EList<IEObjectDescription> classifiers = new BasicEList<IEObjectDescription>();
final IResourceDescriptions resourceDescriptions = resourcesDescriptionProvider
.getResourceDescriptions(OsateResourceUtil.getResourceSet());
for (final IEObjectDescription eod : resourceDescriptions
.getExportedObjectsByType(Aadl2Package.eINSTANCE.getClassifier())) {
classifiers.add(eod);
}
return classifiers;
}
/**
* Get all the {@link Property} Declarations in the workspace.
*/
public EList<IEObjectDescription> getAllPropertyDeclarationsInWorkspace() {
final EList<IEObjectDescription> classifiers = new BasicEList<IEObjectDescription>();
final IResourceDescriptions resourceDescriptions = resourcesDescriptionProvider
.getResourceDescriptions(OsateResourceUtil.getResourceSet());
for (final IEObjectDescription eod : resourceDescriptions
.getExportedObjectsByType(Aadl2Package.eINSTANCE.getProperty())) {
classifiers.add(eod);
}
return classifiers;
}
}
Works great for getting the declarations.
Figured out how to get references:
final ResourceSet resourceSet = OsateResourceUtil.getResourceSet();
final IResourceDescriptions resourceDescriptions = resourcesDescriptionProvider
.getResourceDescriptions(resourceSet);
for (final IResourceDescription rsrcDesc : resourceDescriptions.getAllResourceDescriptions()) {
System.out.println(">>> " + rsrcDesc.getURI());
for (final IReferenceDescription refDesc : rsrcDesc.getReferenceDescriptions()) {
System.out.println(" Source: " + resourceSet.getEObject(refDesc.getSourceEObjectUri(), true));
System.out.println(" Target: " + resourceSet.getEObject(refDesc.getTargetEObjectUri(), true));
// System.out.println(refDesc.getSourceEObjectUri() + " -> " + refDesc.getTargetEObjectUri());
// System.out.println(" Container URI: " + refDesc.getContainerEObjectURI());
// System.out.println(" EReference: " + refDesc.getEReference());
}
}
Does this find references that are in the same resource as the referenced element? I thought resource descriptions only list references to elements in other resources.
Does this find references that are in the same resource as the referenced element? I thought resource descriptions only list references to elements in other resources.
Oh, right. Forgot about that. Was so excited that I got Xtext to do anything. I need to check on this. I did find the Aadl2ReferenceFinder
. I'll have to play with that if this doesn't work all the way.
Does this find references that are in the same resource as the referenced element? I thought resource descriptions only list references to elements in other resources.
Oh, right. Forgot about that. Was so excited that I got Xtext to do anything. I need to check on this. I did find the
Aadl2ReferenceFinder
. I'll have to play with that if this doesn't work all the way.
So Lutz is correct that doens't find references to stuff declared inside the given resource.
Had to switch to using the AadlReferenceFinder
to get the references. This is also pretty easy, but I need to force the resource set to load the resource (and not use the IResourceDescription directly) first:
public void getAllReferencesToTypeInWorkspace(final EClass eClass,
final FinderConsumer<IReferenceDescription> consumer) {
final ResourceSet resourceSet = OsateResourceUtil.getResourceSet();
final IResourceDescriptions resourceDescriptions = resourcesDescriptionProvider
.getResourceDescriptions(resourceSet);
for (final IResourceDescription rsrcDesc : resourceDescriptions.getAllResourceDescriptions()) {
final Resource rsrc = resourceSet.getResource(rsrcDesc.getURI(), true);
referenceFinder.findAllReferences(rsrc, new IReferenceFinder.Acceptor() {
@Override
public void accept(final EObject source, final URI sourceURI, final EReference eReference,
final int index, final EObject targetOrProxy, final URI targetURI) {
accept(new DefaultReferenceDescription(sourceURI, targetURI, eReference, index, null));
}
@Override
public void accept(final IReferenceDescription refDesc) {
consumer.found(refDesc);
}
}, null);
}
}
Side note: We need to filter by scope inside the AadlFinder
methods. In particular the get references operation is kinda expensive, so it makes sense to NOT search a resource for references if it is not in scope. This is not how I started to set things up, but better to find this out now than later on. So I need to add the filtering to be an integral part of the AadlFinder
.
Another Note: Not thrilled by the name AadlFinder
. Suggestions for a better name are welcome.
How about AadlSearch instead of AadlFinder?
Eclipse provides the "Scope" section of the search pane. It is controlled by an attribute in the plugin.xml
. But for some reason the buttons keep getting deactivated at times when you would expect them to be activated. So for now I'm just going to make my one workspace and selected buttons (and ignore the working set).
Eclipse provides the "Scope" section of the search pane. It is controlled by an attribute in the plugin.xml
. But for some reason the buttons keep getting deactivated at times when you would expect them to be activated. So for now I'm just going to make my one workspace and selected buttons (and ignore the working set).
Not going to worry about working sets in the scope for now because they do not currently show up in the AADL Navigator.
The basic search process is implemented and seems to work. Filtering by type/scope/name/declaratoin etc is there.
To do:
Was about to create a job and use the task manager, when I realized that my implementation of the search is dumb because it makes two passes through all the resources, 1 for declarations and 1 for references. I redid things so that there is only one. Made a lot of changes to the AadlFinder
to facilitate this.
Added use of the progress monitor. Verified the search query is executed in a job by the search framework, so I don't need to make my one job. Cancelling on the progress bar cancels the search.
Ready to start the results view.
COME BACK TO THIS: Not crazy about the callback
and resourceSet
parameters to the FinderConsumer.found()
method. Clutters up the name space in the client code when there are nested calls. Find a better way of dealing with this.
ALSO: make a way for the AadlFinder
to interact with a progress monitor so that the total work count can be set correctly.
Started to add a tree to the results view. It's very primitive right now and isn't at all what should be there in the final form, but I wanted to
Right now I just have the a tree of reference result URIs and declaration result URis
TO DO:
Other searches definitely run in the background. Need to see why AADL Search doesn't/cannot.
I have the results opening an editor for the URIs. Works just find for declarations. For references it works, but the URI is actually to the AObject that contains the reference, so I need to figure out how to highlight the reference itself.
Come back to this later. Fix the result tree first.
don't forget to document this.
I have the results opening an editor for the URIs. Works just find for declarations. For references it works, but the URI is actually to the AObject that contains the reference, so I need to figure out how to highlight the reference itself.
Fixed this. Just need to use the other open
method in the EditorOpener
object.
Fixed the result tree. Roots are an alphabetical list of the resources that contain found items. Children of resources are "Found declaration of ..." and "Reference to ..." nodes that are in syntactic order.
Other searches definitely run in the background. Need to see why AADL Search doesn't/cannot.
Fixed this. I thought I was using NewSearchUI.runQueryInBackground()
, but for some reason I was acutally using NewSearchUI.runQueryInForeground()
. So that was easy to fix.
Fixed the progress bar to know the total number of resources being searched.
Need to add to help documents.
It is often helpful to search the entire workspace for a text string using OSATE's/Eclipse's search feature. Search->File... In previous versions this would search the entire workspace. However, this capability no longer searches plugin contributions. child of #1371