19
19
import static org .junit .Assert .assertTrue ;
20
20
import static org .junit .Assert .fail ;
21
21
22
+ import java .util .List ;
23
+
22
24
import org .eclipse .core .runtime .FileLocator ;
23
25
import org .eclipse .core .runtime .Path ;
24
26
import org .eclipse .core .runtime .Platform ;
28
30
import org .eclipse .jdt .core .IMethod ;
29
31
import org .eclipse .jdt .core .IType ;
30
32
import org .eclipse .jdt .core .JavaCore ;
31
- import org .eclipse .jdt .core .groovy .tests .MockSearchRequestor ;
32
- import org .eclipse .jdt .core .groovy .tests .SimpleProgressMonitor ;
33
33
import org .eclipse .jdt .core .search .IJavaSearchConstants ;
34
34
import org .eclipse .jdt .core .search .IJavaSearchScope ;
35
35
import org .eclipse .jdt .core .search .SearchEngine ;
36
36
import org .eclipse .jdt .core .search .SearchMatch ;
37
- import org .eclipse .jdt .core .search .SearchParticipant ;
38
37
import org .eclipse .jdt .core .search .SearchPattern ;
39
38
import org .eclipse .jdt .internal .core .BinaryMember ;
40
39
import org .junit .After ;
@@ -100,8 +99,6 @@ public void setUp() throws Exception {
100
99
env .addEntry (project .getFullPath (), JavaCore .newLibraryEntry (libDir .append ("binGroovySearch.jar" ), libDir .append ("binGroovySearchSrc.zip" ), null ));
101
100
102
101
javaProject = env .getJavaProject (project .getName ());
103
- waitForIndexer (javaProject );
104
-
105
102
// overwrite the contents vars with the actual contents
106
103
groovyClassContents = javaProject .findType ("pack.AGroovyClass" ).getTypeRoot ().getBuffer ().getContents ();
107
104
groovyClassContents2 = javaProject .findType ("pack.AnotherGroovyClass" ).getTypeRoot ().getBuffer ().getContents ();
@@ -112,38 +109,32 @@ public void tearDown() throws Exception {
112
109
javaProject = null ;
113
110
}
114
111
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 );
120
115
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 );
127
117
}
128
118
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 );
132
123
}
133
124
int currIndex = groovyClassContents .indexOf ("def doit" ) + "def doit" .length ();
134
125
for (int i = 0 ; i < firstMatches ; i += 1 ) {
135
- SearchMatch match = requestor . getMatches () .get (i );
126
+ SearchMatch match = matches .get (i );
136
127
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 ());
139
130
currIndex += toFind .length ();
140
131
}
141
132
currIndex = groovyClassContents2 .indexOf ("def doit" ) + "def doit" .length ();
142
133
for (int i = firstMatches ; i < allMatches ; i += 1 ) {
143
- SearchMatch match = requestor . getMatches () .get (i );
134
+ SearchMatch match = matches .get (i );
144
135
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 ());
147
138
currIndex += toFind .length ();
148
139
}
149
140
}
@@ -153,59 +144,52 @@ private void assertMatches(String toFind, MockSearchRequestor requestor, int all
153
144
@ Test
154
145
public void testClassDecl1 () throws Exception {
155
146
IType type = javaProject .findType ("pack.AGroovyClass" );
156
- MockSearchRequestor requestor = performSearch (type );
157
- assertMatches ("AGroovyClass" , requestor , 12 , 2 );
147
+ assertMatches ("AGroovyClass" , performSearch (type ), 12 , 2 );
158
148
}
159
149
160
150
@ Test
161
151
public void testClassDecl2 () throws Exception {
162
152
IType type = javaProject .findType ("pack.OtherClass" );
163
- MockSearchRequestor requestor = performSearch (type );
164
- assertMatches ("OtherClass" , requestor , 4 , 2 );
153
+ assertMatches ("OtherClass" , performSearch (type ), 4 , 2 );
165
154
}
166
155
167
156
@ Test
168
157
public void testFieldDecl1 () throws Exception {
169
158
IType type = javaProject .findType ("pack.AGroovyClass" );
170
159
String toFind = "age_1" ;
171
160
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
174
162
}
175
163
176
164
@ Test
177
165
public void testFieldDecl2 () throws Exception {
178
166
IType type = javaProject .findType ("pack.AGroovyClass" );
179
167
String toFind = "name_1" ;
180
168
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
183
170
}
184
171
185
172
@ Test
186
173
public void testMethodDecl () throws Exception {
187
174
IType type = javaProject .findType ("pack.AGroovyClass" );
188
175
String toFind = "doit" ;
189
176
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 );
192
178
}
193
179
194
180
@ Test
195
181
public void testFieldRefInInitializer () throws Exception {
196
182
IType type = javaProject .findType ("pack.AGroovyClass" );
197
183
String toFind = "fieldInInitializer" ;
198
184
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
201
186
}
202
187
203
188
@ Test
204
189
public void testMethodRefInInitializer () throws Exception {
205
190
IType type = javaProject .findType ("pack.AGroovyClass" );
206
191
String toFind = "referencedInInitializer" ;
207
192
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 );
210
194
}
211
195
}
0 commit comments