1919import static org .junit .Assert .assertTrue ;
2020import static org .junit .Assert .fail ;
2121
22+ import java .util .List ;
23+
2224import org .eclipse .core .runtime .FileLocator ;
2325import org .eclipse .core .runtime .Path ;
2426import org .eclipse .core .runtime .Platform ;
2830import org .eclipse .jdt .core .IMethod ;
2931import org .eclipse .jdt .core .IType ;
3032import org .eclipse .jdt .core .JavaCore ;
31- import org .eclipse .jdt .core .groovy .tests .MockSearchRequestor ;
32- import org .eclipse .jdt .core .groovy .tests .SimpleProgressMonitor ;
3333import org .eclipse .jdt .core .search .IJavaSearchConstants ;
3434import org .eclipse .jdt .core .search .IJavaSearchScope ;
3535import org .eclipse .jdt .core .search .SearchEngine ;
3636import org .eclipse .jdt .core .search .SearchMatch ;
37- import org .eclipse .jdt .core .search .SearchParticipant ;
3837import org .eclipse .jdt .core .search .SearchPattern ;
3938import org .eclipse .jdt .internal .core .BinaryMember ;
4039import org .junit .After ;
@@ -100,8 +99,6 @@ public void setUp() throws Exception {
10099 env .addEntry (project .getFullPath (), JavaCore .newLibraryEntry (libDir .append ("binGroovySearch.jar" ), libDir .append ("binGroovySearchSrc.zip" ), null ));
101100
102101 javaProject = env .getJavaProject (project .getName ());
103- waitForIndexer (javaProject );
104-
105102 // overwrite the contents vars with the actual contents
106103 groovyClassContents = javaProject .findType ("pack.AGroovyClass" ).getTypeRoot ().getBuffer ().getContents ();
107104 groovyClassContents2 = javaProject .findType ("pack.AnotherGroovyClass" ).getTypeRoot ().getBuffer ().getContents ();
@@ -112,38 +109,32 @@ public void tearDown() throws Exception {
112109 javaProject = null ;
113110 }
114111
115- private MockSearchRequestor performSearch (IJavaElement toSearchFor ) throws Exception {
116- assertTrue ("Expected binary member, but got: " + toSearchFor == null ? null : toSearchFor .getClass ().getName (), toSearchFor instanceof BinaryMember );
117-
118- SearchPattern pattern = SearchPattern .createPattern (toSearchFor , IJavaSearchConstants .REFERENCES );
119- SearchParticipant participant = SearchEngine .getDefaultSearchParticipant ();
112+ private List <SearchMatch > performSearch (final IJavaElement javaElement ) throws Exception {
113+ assertTrue ("Expected binary member, but got: " + javaElement == null ? null : javaElement .getClass ().getName (), javaElement instanceof BinaryMember );
114+ SearchPattern pattern = SearchPattern .createPattern (javaElement , IJavaSearchConstants .REFERENCES );
120115 IJavaSearchScope scope = SearchEngine .createJavaSearchScope (new IJavaElement [] {javaProject });
121- MockSearchRequestor requestor = new MockSearchRequestor ();
122- SimpleProgressMonitor monitor = new SimpleProgressMonitor ("Search in project binaries" );
123-
124- new SearchEngine ().search (pattern , new SearchParticipant [] {participant }, scope , requestor , monitor );
125- monitor .waitForCompletion (10 );
126- return requestor ;
116+ return search (pattern , scope );
127117 }
128118
129- private void assertMatches (String toFind , MockSearchRequestor requestor , int allMatches , int firstMatches ) {
130- if (requestor .getMatches ().size () != allMatches ) {
131- fail ("Expecting " + allMatches + " matches, but found " + requestor .getMatches ().size () + "\n " + requestor .printMatches ());
119+ private void assertMatches (final String toFind , final List <SearchMatch > matches , final int allMatches , final int firstMatches ) {
120+ String matchesString = toString (matches );
121+ if (matches .size () != allMatches ) {
122+ fail ("Expecting " + allMatches + " matches, but found " + matches .size () + "\n " + matchesString );
132123 }
133124 int currIndex = groovyClassContents .indexOf ("def doit" ) + "def doit" .length ();
134125 for (int i = 0 ; i < firstMatches ; i += 1 ) {
135- SearchMatch match = requestor . getMatches () .get (i );
126+ SearchMatch match = matches .get (i );
136127 currIndex = groovyClassContents .indexOf (toFind , currIndex );
137- assertEquals ("Invalid start position in match " + i + "\n " + requestor . printMatches () , currIndex , match .getOffset ());
138- assertEquals ("Invalid length in match " + i + "\n " + requestor . printMatches () , toFind .length (), match .getLength ());
128+ assertEquals ("Invalid start position in match " + i + "\n " + matchesString , currIndex , match .getOffset ());
129+ assertEquals ("Invalid length in match " + i + "\n " + matchesString , toFind .length (), match .getLength ());
139130 currIndex += toFind .length ();
140131 }
141132 currIndex = groovyClassContents2 .indexOf ("def doit" ) + "def doit" .length ();
142133 for (int i = firstMatches ; i < allMatches ; i += 1 ) {
143- SearchMatch match = requestor . getMatches () .get (i );
134+ SearchMatch match = matches .get (i );
144135 currIndex = groovyClassContents2 .indexOf (toFind , currIndex );
145- assertEquals ("Invalid start position in match " + i + "\n " + requestor . printMatches () , currIndex , match .getOffset ());
146- assertEquals ("Invalid length in match " + i + "\n " + requestor . printMatches () , toFind .length (), match .getLength ());
136+ assertEquals ("Invalid start position in match " + i + "\n " + matchesString , currIndex , match .getOffset ());
137+ assertEquals ("Invalid length in match " + i + "\n " + matchesString , toFind .length (), match .getLength ());
147138 currIndex += toFind .length ();
148139 }
149140 }
@@ -153,59 +144,52 @@ private void assertMatches(String toFind, MockSearchRequestor requestor, int all
153144 @ Test
154145 public void testClassDecl1 () throws Exception {
155146 IType type = javaProject .findType ("pack.AGroovyClass" );
156- MockSearchRequestor requestor = performSearch (type );
157- assertMatches ("AGroovyClass" , requestor , 12 , 2 );
147+ assertMatches ("AGroovyClass" , performSearch (type ), 12 , 2 );
158148 }
159149
160150 @ Test
161151 public void testClassDecl2 () throws Exception {
162152 IType type = javaProject .findType ("pack.OtherClass" );
163- MockSearchRequestor requestor = performSearch (type );
164- assertMatches ("OtherClass" , requestor , 4 , 2 );
153+ assertMatches ("OtherClass" , performSearch (type ), 4 , 2 );
165154 }
166155
167156 @ Test
168157 public void testFieldDecl1 () throws Exception {
169158 IType type = javaProject .findType ("pack.AGroovyClass" );
170159 String toFind = "age_1" ;
171160 IField field = type .getField (toFind );
172- MockSearchRequestor requestor = performSearch (field );
173- assertMatches (toFind , requestor , 2 , 2 ); // all was 4, but in binary synthetic accessor is indistinguishable from source method
161+ assertMatches (toFind , performSearch (field ), 2 , 2 ); // all was 4, but in binary synthetic accessor is indistinguishable from source method
174162 }
175163
176164 @ Test
177165 public void testFieldDecl2 () throws Exception {
178166 IType type = javaProject .findType ("pack.AGroovyClass" );
179167 String toFind = "name_1" ;
180168 IField field = type .getField (toFind );
181- MockSearchRequestor requestor = performSearch (field );
182- assertMatches (toFind , requestor , 2 , 2 ); // all was 4, but in binary synthetic accessor is indistinguishable from source method
169+ assertMatches (toFind , performSearch (field ), 2 , 2 ); // all was 4, but in binary synthetic accessor is indistinguishable from source method
183170 }
184171
185172 @ Test
186173 public void testMethodDecl () throws Exception {
187174 IType type = javaProject .findType ("pack.AGroovyClass" );
188175 String toFind = "doit" ;
189176 IMethod method = type .getMethod (toFind , new String [0 ]);
190- MockSearchRequestor requestor = performSearch (method );
191- assertMatches (toFind , requestor , 4 , 2 );
177+ assertMatches (toFind , performSearch (method ), 4 , 2 );
192178 }
193179
194180 @ Test
195181 public void testFieldRefInInitializer () throws Exception {
196182 IType type = javaProject .findType ("pack.AGroovyClass" );
197183 String toFind = "fieldInInitializer" ;
198184 IField method = type .getField (toFind );
199- MockSearchRequestor requestor = performSearch (method );
200- assertMatches (toFind , requestor , 1 , 1 ); // all was 2, but in binary synthetic accessor is indistinguishable from source method
185+ assertMatches (toFind , performSearch (method ), 1 , 1 ); // all was 2, but in binary synthetic accessor is indistinguishable from source method
201186 }
202187
203188 @ Test
204189 public void testMethodRefInInitializer () throws Exception {
205190 IType type = javaProject .findType ("pack.AGroovyClass" );
206191 String toFind = "referencedInInitializer" ;
207192 IMethod method = type .getMethod (toFind , new String [0 ]);
208- MockSearchRequestor requestor = performSearch (method );
209- assertMatches (toFind , requestor , 2 , 1 );
193+ assertMatches (toFind , performSearch (method ), 2 , 1 );
210194 }
211195}
0 commit comments