osate / osate2

Open Source AADL2 Tool Environment
http://osate.org
Eclipse Public License 2.0
36 stars 8 forks source link

Provide AADL Search that includes Plugin Contributions #1028

Closed philip-alldredge closed 5 years ago

philip-alldredge commented 6 years ago

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

lwrage commented 6 years ago

It would be even better to have an AADL search dialog.

lwrage commented 6 years ago

An example for a search contribution: https://github.com/Pontesegger/codeandme/tree/master/search_provider/com.codeandme.searchprovider

AaronGreenhouse commented 6 years ago

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.

lwrage commented 6 years ago

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.)

AaronGreenhouse commented 6 years ago

start with find classifier and find property

AaronGreenhouse commented 5 years ago

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?

AaronGreenhouse commented 5 years ago

Plan now is

  1. Create a search page
  2. Create a visitor that to get the scoping right and filtering of AADL models right. (Don't worry about actually searching models yet)
  3. Search and dump results to the console
  4. Make the results view
AaronGreenhouse commented 5 years ago

Initial version of the "AADL Search" page.

aadlsearchpage

AaronGreenhouse commented 5 years ago

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.

AaronGreenhouse commented 5 years ago

Possibility to get declarations

  1. Use resource descriptions to get what is available
  2. Filter based on search scope
AaronGreenhouse commented 5 years ago

Look for AADL2 impl of IReferenceFinder. Figure out how to use it

AaronGreenhouse commented 5 years ago

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.

AaronGreenhouse commented 5 years ago

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());
            }
        }
lwrage commented 5 years ago

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.

AaronGreenhouse commented 5 years ago

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.

AaronGreenhouse commented 5 years ago

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.

AaronGreenhouse commented 5 years ago

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);
        }
    }
AaronGreenhouse commented 5 years ago

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.

AaronGreenhouse commented 5 years ago

Another Note: Not thrilled by the name AadlFinder. Suggestions for a better name are welcome.

lwrage commented 5 years ago

How about AadlSearch instead of AadlFinder?

AaronGreenhouse commented 5 years ago

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).

AaronGreenhouse commented 5 years ago

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).

AaronGreenhouse commented 5 years ago

Not going to worry about working sets in the scope for now because they do not currently show up in the AADL Navigator.

AaronGreenhouse commented 5 years ago

The basic search process is implemented and seems to work. Filtering by type/scope/name/declaratoin etc is there.

To do:

AaronGreenhouse commented 5 years ago

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.

AaronGreenhouse commented 5 years ago

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.

AaronGreenhouse commented 5 years ago

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.

AaronGreenhouse commented 5 years ago

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

  1. make sure I added the tree to the search results view correctly
  2. make sure I can handle the input to the view being changed
  3. make sure I can jump to the editor location correctly

Right now I just have the a tree of reference result URIs and declaration result URis

TO DO:

  1. Actually store the search results in the search result class (the simple example I was referring to doesn't do this)
  2. Make the results view able to build the view from an old result
  3. Add a double-click listener to the tree so and jump to the URI in an editor.
  4. Fix the tree to show a hierarchy based on AADL Project > package/property set > path through aadl file
  5. See about making the search run in background. Do/can other searches?
AaronGreenhouse commented 5 years ago

Other searches definitely run in the background. Need to see why AADL Search doesn't/cannot.

AaronGreenhouse commented 5 years ago

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.

AaronGreenhouse commented 5 years ago

don't forget to document this.

AaronGreenhouse commented 5 years ago

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.

AaronGreenhouse commented 5 years ago

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.

AaronGreenhouse commented 5 years ago

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.

AaronGreenhouse commented 5 years ago

Fixed the progress bar to know the total number of resources being searched.

AaronGreenhouse commented 5 years ago

Need to add to help documents.