Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Language IDEs » Java Development Tools (JDT) » Caching or improving search
Caching or improving search [message #867501] Tue, 01 May 2012 10:25 Go to next message
Roberto Lo Giacco is currently offline Roberto Lo GiaccoFriend
Messages: 17
Registered: April 2012
Junior Member
Hi all,
I'm quite new to Eclipse development so please forgive me for any big mistake and please be detailed in your answers Embarrassed .
I've started an open source project to provide some editors for BDD tools (Cucumber and JBehave) and I'm successfully using Xtext to create the editors.

I wanted to add the capability to link a step definition (a grammar element in both editors) to Java methods: let me explain what I mean.

If I encounter (in my bdd editor) something like Given the user does something I want to hyperlink it to any Java method annotated with Given, When, Then, And or But and an annotation value that represents a regular expression matching with the string "the user does something" so those are all valid matches:


  • @Given("the user does .*")
  • @But("user do.*")
  • @Then("^the user .*$")


The following is the code I'm using:
for (final String annotationName : annotationNames) {
			SearchPattern pattern = SearchPattern.createPattern(annotationName, IJavaSearchConstants.ANNOTATION_TYPE,
					IJavaSearchConstants.ANNOTATION_TYPE_REFERENCE, SearchPattern.R_EXACT_MATCH | SearchPattern.R_CASE_SENSITIVE);
			SearchRequestor requestor = new SearchRequestor() {
				public void acceptSearchMatch(SearchMatch match) throws CoreException {
					if (match.getElement() instanceof IMethod) {
						IMethod method = (IMethod) match.getElement();
						// verify pattern
						IAnnotation type = method.getAnnotation(annotationName);
						String annotationValue = (String) type.getMemberValuePairs()[0].getValue();
						if (step.matches(annotationValue)) {
							results.add(new JavaHyperlink("Open mapping " + annotationValue, method, region));
						}						
					}
				}
			};
			try {
				new SearchEngine().search(pattern, new SearchParticipant[] { SearchEngine.getDefaultSearchParticipant() }, SearchEngine.createWorkspaceScope(),
						requestor, null);
			} catch (CoreException e) {
				e.printStackTrace();
			}
		}


As you can imagine performing 5 searches on a large code basis and executing all those regular expression matches is time consuming and I wish to improve the plugin performances by pre-calculating the results in the background and caching them. I need to update the cache whenever a Java build (partial or full) is issued tho and here come my questions:

  • How can I do it (updating the cache) considering I'm into a non Java file editor and possibly not even in a Java project (the project is in the workspace or a project dependency tho)?
  • Can I get notified of which classes have been recompiled so that I can issue partial updates of the cache?
  • Is there any Eclipse specific data structure I can use or should I build my own data structure to hold those values?
  • Am I completely misusing the Eclipse JDT API and may be there's a better solution to my problem I haven't considered?


Thank you very much.
Re: Caching or improving search [message #868588 is a reply to message #867501] Wed, 02 May 2012 09:06 Go to previous messageGo to next message
Satyam Kandula is currently offline Satyam KandulaFriend
Messages: 444
Registered: July 2009
Senior Member
- You can listen to resource change events or build events. Look at JavaCore#addElementChangedListener() (http://help.eclipse.org/helios/topic/org.eclipse.jdt.doc.isv/guide/jdt_api_manip.htm - Responding to changes in Java elements).

BTW, do you really want the annotations of all the files in the workspace? Isn't just getting the annotation for the open file not enough?
Re: Caching or improving search [message #868710 is a reply to message #868588] Wed, 02 May 2012 12:37 Go to previous message
Roberto Lo Giacco is currently offline Roberto Lo GiaccoFriend
Messages: 17
Registered: April 2012
Junior Member
Thanks Satyam, this is good news.

The currently open file is not a Java file but a Cucumber file and the annotation can be in any Java class in the project classpath... Those classes do not have to inherit or use any annotation so, yes, I think I've to scan all the available classes.

Anyone aware of a cache structure I might use?
I was thinking I can use two hash maps: one to index the results by java class (so that when a Java class get compiled I can update only the results associated with that class) and the other to index the results by feature file (so that I can update only the results affected by the change in that file).

If the hash maps are a good choice where do you suggest to store them? In the plugin activator class? Should I persist those caches or it's more Eclipse style to rebuild them on plugin startup?
Previous Topic:Reading classpath entry
Next Topic:cannot paste the clipboard contents into the selected elements
Goto Forum:
  


Current Time: Thu Apr 25 21:09:58 GMT 2024

Powered by FUDForum. Page generated in 0.46676 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top