Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Provide AADL Search that includes Plugin Contributions #1028

Closed
philip-alldredge opened this issue Jan 29, 2018 · 36 comments
Closed

Provide AADL Search that includes Plugin Contributions #1028

philip-alldredge opened this issue Jan 29, 2018 · 36 comments

Comments

@philip-alldredge
Copy link
Collaborator

@philip-alldredge philip-alldredge commented Jan 29, 2018

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
Copy link
Contributor

@lwrage lwrage commented Jan 31, 2018

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

@lwrage lwrage changed the title File Search does not search Plugin Contributions Provide AADL Search that includes Plugin Contributions Feb 2, 2018
@lwrage lwrage added the backlog label Feb 2, 2018
@lwrage lwrage added the core label Feb 21, 2018
@lwrage lwrage added next and removed backlog labels Jul 2, 2018
@lwrage lwrage added next and removed backlog labels Aug 18, 2018
@lwrage lwrage added this to the 2.3.6 milestone Aug 29, 2018
@AaronGreenhouse
Copy link
Contributor

@AaronGreenhouse AaronGreenhouse commented Sep 7, 2018

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
Copy link
Contributor

@lwrage lwrage commented Sep 7, 2018

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
Copy link
Contributor

@AaronGreenhouse AaronGreenhouse commented Sep 12, 2018

start with find classifier and find property

@AaronGreenhouse
Copy link
Contributor

@AaronGreenhouse AaronGreenhouse commented Oct 12, 2018

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
Copy link
Contributor

@AaronGreenhouse AaronGreenhouse commented Oct 12, 2018

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
Copy link
Contributor

@AaronGreenhouse AaronGreenhouse commented Oct 12, 2018

Initial version of the "AADL Search" page.

aadlsearchpage

@AaronGreenhouse
Copy link
Contributor

@AaronGreenhouse AaronGreenhouse commented Oct 15, 2018

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
Copy link
Contributor

@AaronGreenhouse AaronGreenhouse commented Oct 15, 2018

Possibility to get declarations

  1. Use resource descriptions to get what is available
  2. Filter based on search scope
@AaronGreenhouse
Copy link
Contributor

@AaronGreenhouse AaronGreenhouse commented Oct 15, 2018

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

@AaronGreenhouse
Copy link
Contributor

@AaronGreenhouse AaronGreenhouse commented Oct 17, 2018

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
Copy link
Contributor

@AaronGreenhouse AaronGreenhouse commented Oct 18, 2018

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
Copy link
Contributor

@lwrage lwrage commented Oct 18, 2018

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
Copy link
Contributor

@AaronGreenhouse AaronGreenhouse commented Oct 19, 2018

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
Copy link
Contributor

@AaronGreenhouse AaronGreenhouse commented Oct 19, 2018

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
Copy link
Contributor

@AaronGreenhouse AaronGreenhouse commented Oct 19, 2018

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
Copy link
Contributor

@AaronGreenhouse AaronGreenhouse commented Oct 19, 2018

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
Copy link
Contributor

@AaronGreenhouse AaronGreenhouse commented Oct 19, 2018

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

@lwrage
Copy link
Contributor

@lwrage lwrage commented Oct 19, 2018

How about AadlSearch instead of AadlFinder?

@lwrage lwrage modified the milestones: 2.3.6, 2.4 Oct 22, 2018
@AaronGreenhouse
Copy link
Contributor

@AaronGreenhouse AaronGreenhouse commented Oct 22, 2018

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

1 similar comment
@AaronGreenhouse
Copy link
Contributor

@AaronGreenhouse AaronGreenhouse commented Oct 22, 2018

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
Copy link
Contributor

@AaronGreenhouse AaronGreenhouse commented Oct 22, 2018

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

@AaronGreenhouse
Copy link
Contributor

@AaronGreenhouse AaronGreenhouse commented Oct 23, 2018

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

To do:

  • Tasks/Jobs, progress bar
  • results view
@AaronGreenhouse
Copy link
Contributor

@AaronGreenhouse AaronGreenhouse commented Oct 23, 2018

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
Copy link
Contributor

@AaronGreenhouse AaronGreenhouse commented Oct 23, 2018

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
Copy link
Contributor

@AaronGreenhouse AaronGreenhouse commented Oct 24, 2018

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
Copy link
Contributor

@AaronGreenhouse AaronGreenhouse commented Oct 25, 2018

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
Copy link
Contributor

@AaronGreenhouse AaronGreenhouse commented Oct 26, 2018

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

@AaronGreenhouse
Copy link
Contributor

@AaronGreenhouse AaronGreenhouse commented Oct 26, 2018

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
Copy link
Contributor

@AaronGreenhouse AaronGreenhouse commented Oct 29, 2018

don't forget to document this.

@AaronGreenhouse
Copy link
Contributor

@AaronGreenhouse AaronGreenhouse commented Nov 1, 2018

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
Copy link
Contributor

@AaronGreenhouse AaronGreenhouse commented Nov 1, 2018

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
Copy link
Contributor

@AaronGreenhouse AaronGreenhouse commented Nov 1, 2018

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
Copy link
Contributor

@AaronGreenhouse AaronGreenhouse commented Nov 2, 2018

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

@AaronGreenhouse
Copy link
Contributor

@AaronGreenhouse AaronGreenhouse commented Nov 2, 2018

Need to add to help documents.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
3 participants