Note that there are some explanatory texts on larger screens.

plurals
  1. POJDT SearchEngine throws a NullPointerException
    primarykey
    data
    text
    <p>I'm trying to use JDT SearchEngine to find references to a given object. But I'm getting a "NullPointerException" while invoking the "search" method of org.eclipse.jdt.core.search.SearchEngine.</p> <p>Following is the error trace:</p> <blockquote> <p>java.lang.NullPointerException at org.eclipse.jdt.internal.core.search.BasicSearchEngine.findMatches(BasicSearchEngine.java:214) at org.eclipse.jdt.internal.core.search.BasicSearchEngine.search(BasicSearchEngine.java:515) at org.eclipse.jdt.core.search.SearchEngine.search(SearchEngine.java:582)</p> </blockquote> <p>And following is the method I'm using to perform search:</p> <pre class="lang-java prettyprint-override"><code>private static void search(String elementName) { //elementName -&gt; a method Name try { SearchPattern pattern = SearchPattern.createPattern(elementName, IJavaSearchConstants.METHOD, IJavaSearchConstants.REFERENCES, SearchPattern.R_PATTERN_MATCH); IJavaSearchScope scope = SearchEngine.createWorkspaceScope(); SearchRequestor requestor = new SearchRequestor() { @Override public void acceptSearchMatch(SearchMatch match) { System.out.println("Element - " + match.getElement()); } }; SearchEngine searchEngine = new SearchEngine(); SearchParticipant[] searchParticipants = new SearchParticipant[] { SearchEngine .getDefaultSearchParticipant() }; searchEngine.search(pattern, searchParticipants, scope, requestor, null); } catch (Exception e) { e.printStackTrace(); } } </code></pre> <p>Refer the "Variables" window of the following snapshot to check the values of the arguments passing to the "searchEngine.search()":</p> <p><img src="https://i.stack.imgur.com/1wCo8.png" alt="enter image description here"></p> <p>I think the the issue is because of the value of "scope" [Highlighted in 'BLACK' above]. Which means "SearchEngine.createWorkspaceScope()" doesn't return expected values in this case. </p> <p><strong>NOTE:</strong> Please note that this is a part of my program which runs as a stand-alone java program (not an eclipse plugin) using JDT APIs to parse a given source code (using JDT-AST). </p> <p>Isn't it possible to use JDT SearchEngine in such case (non eclipse plugin program), or is this issue due to some other reason? Really appreciate your answer on this.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload