Problem with IJavaSearchScope [message #258523] |
Fri, 06 February 2009 06:54  |
Eclipse User |
|
|
|
hello,
i am building an application that finds pattern for Integer() wrapper
class, means occurance of Integer() in a java file. for that i find
eclipse.jdt.core.search and with that i build a program but it throws
ExceptionInInitializerError
I am not getting why this error has occured, please help me to solve my
problem.....
thnx in advance...
my source code is as follows:
import org.eclipse.jdt.core.IClassFile;
import org.eclipse.jdt.core.ICompilationUnit;
import org.eclipse.jdt.core.IJavaElement;
import org.eclipse.jdt.core.IJavaProject;
import org.eclipse.jdt.core.IPackageFragment;
import org.eclipse.jdt.core.IPackageFragmentRoot;
import org.eclipse.jdt.core.search.IJavaSearchConstants;
import org.eclipse.jdt.core.search.IJavaSearchScope;
import org.eclipse.jdt.core.search.SearchEngine;
import org.eclipse.jdt.core.search.SearchMatch;
import org.eclipse.jdt.core.search.SearchParticipant;
import org.eclipse.jdt.core.search.SearchPattern;
import org.eclipse.jdt.core.search.SearchRequestor;
import org.eclipse.core.*;
import org.eclipse.core.resources.*;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.jdt.core.util.*;
import java.io.IOException;
import java.io.InputStream;
import java.lang.*;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.StringTokenizer;
import org.osgi.*;
import org.eclipse.jface.viewers.ISelection;
import org.eclipse.jface.viewers.IStructuredSelection;
public class test {
IPackageFragment pkg ;
IJavaSearchScope scope;
public void parser() throws IOException {
// TODO Auto-generated method stub
try {
System.out.println("in method..");
SearchPattern pattern = SearchPattern.createPattern(
"Integer*",
IJavaSearchConstants.METHOD,
IJavaSearchConstants.DECLARATIONS,
SearchPattern.R_PATTERN_MATCH);
scope = SearchEngine.createJavaSearchScope(new IJavaElement[]{this.pkg});
SearchRequestor requestor = new SearchRequestor() {
public void acceptSearchMatch(SearchMatch match) {
System.out.println(match.getElement());
}
};
SearchEngine searchEngine= new SearchEngine();
searchEngine.search(pattern, new
SearchParticipant[]{SearchEngine.getDefaultSearchParticipant ()}, scope,
requestor, null);
} catch (CoreException e) {
// TODO Auto-generated catch block
System.out.println(e.getCause());
}
catch(NullPointerException ne){
System.out.println(ne.getCause());
}
catch (ExceptionInInitializerError ee) {
// TODO Auto-generated catch block
System.out.println(ee.getCause());
}
}
}
|
|
|
|
|
Re: Problem with IJavaSearchScope [message #258580 is a reply to message #258523] |
Tue, 10 February 2009 10:42  |
Eclipse User |
|
|
|
gunjju wrote:
> hello,
> i am building an application that finds pattern for Integer() wrapper
> class, means occurance of Integer() in a java file. for that i find
> eclipse.jdt.core.search and with that i build a program but it throws
> ExceptionInInitializerError
> I am not getting why this error has occured, please help me to solve my
> problem.....
> thnx in advance...
>
> my source code is as follows:
>
> import org.eclipse.jdt.core.IClassFile;
> import org.eclipse.jdt.core.ICompilationUnit;
> import org.eclipse.jdt.core.IJavaElement;
> import org.eclipse.jdt.core.IJavaProject;
> import org.eclipse.jdt.core.IPackageFragment;
> import org.eclipse.jdt.core.IPackageFragmentRoot;
> import org.eclipse.jdt.core.search.IJavaSearchConstants;
> import org.eclipse.jdt.core.search.IJavaSearchScope;
> import org.eclipse.jdt.core.search.SearchEngine;
> import org.eclipse.jdt.core.search.SearchMatch;
> import org.eclipse.jdt.core.search.SearchParticipant;
> import org.eclipse.jdt.core.search.SearchPattern;
> import org.eclipse.jdt.core.search.SearchRequestor;
> import org.eclipse.core.*;
> import org.eclipse.core.resources.*;
> import org.eclipse.core.runtime.CoreException;
> import org.eclipse.core.runtime.IProgressMonitor;
> import org.eclipse.jdt.core.util.*;
> import java.io.IOException;
> import java.io.InputStream;
> import java.lang.*;
> import java.util.ArrayList;
> import java.util.Iterator;
> import java.util.StringTokenizer;
> import org.osgi.*;
> import org.eclipse.jface.viewers.ISelection;
> import org.eclipse.jface.viewers.IStructuredSelection;
> public class test {
> IPackageFragment pkg ;
> IJavaSearchScope scope;
> public void parser() throws IOException {
> // TODO Auto-generated method stub
> try {
> System.out.println("in method..");
>
> SearchPattern pattern = SearchPattern.createPattern(
> "Integer*", IJavaSearchConstants.METHOD,
> IJavaSearchConstants.DECLARATIONS,
> SearchPattern.R_PATTERN_MATCH);
> scope = SearchEngine.createJavaSearchScope(new IJavaElement[]{this.pkg});
> SearchRequestor requestor = new SearchRequestor() {
> public void acceptSearchMatch(SearchMatch match) {
> System.out.println(match.getElement());
>
> }
> };
> SearchEngine searchEngine= new SearchEngine();
> searchEngine.search(pattern, new
> SearchParticipant[]{SearchEngine.getDefaultSearchParticipant ()}, scope,
> requestor, null);
> } catch (CoreException e) {
> // TODO Auto-generated catch block
> System.out.println(e.getCause());
> }
> catch(NullPointerException ne){
> System.out.println(ne.getCause());
> }
> catch (ExceptionInInitializerError ee) {
> // TODO Auto-generated catch block
> System.out.println(ee.getCause());
>
> }
> }
>
> }
>
>
>
It looks like you're running this snippet as a Java application...
If so, could you try to run it as an Eclipse application?
I also doubt that this snippet will address your search need.
The created pattern is about method declarations although that
reading your first paragraph it sounds to me that you wanted
to search either for Integer constructors or class references.
The former would expect the following pattern:
SearchPattern pattern = SearchPattern.createPattern(
"Integer",
IJavaSearchConstants.CONSTRUCTOR,
IJavaSearchConstants.REFERENCES,
SearchPattern.R_EXACT_MATCH);
The latter would expect the following pattern:
SearchPattern pattern = SearchPattern.createPattern(
"Integer",
IJavaSearchConstants.CLASS,
IJavaSearchConstants.REFERENCES,
SearchPattern.R_EXACT_MATCH);
|
|
|
Powered by
FUDForum. Page generated in 0.03470 seconds