Lines 21-26
Link Here
|
21 |
|
21 |
|
22 |
import java.io.File; |
22 |
import java.io.File; |
23 |
import java.io.IOException; |
23 |
import java.io.IOException; |
|
|
24 |
import java.io.InterruptedIOException; |
24 |
import java.text.ParseException; |
25 |
import java.text.ParseException; |
25 |
import java.util.Comparator; |
26 |
import java.util.Comparator; |
26 |
import java.util.EnumSet; |
27 |
import java.util.EnumSet; |
Lines 80-86
Link Here
|
80 |
private IndexReader reader; //Cache, do not use this dirrectly, use getReader |
81 |
private IndexReader reader; //Cache, do not use this dirrectly, use getReader |
81 |
private Set<String> rootPkgCache; //Cache, do not use this dirrectly |
82 |
private Set<String> rootPkgCache; //Cache, do not use this dirrectly |
82 |
|
83 |
|
83 |
public static Index create (final File cacheRoot) throws IOException { |
84 |
static Index create (final File cacheRoot) throws IOException { |
84 |
assert cacheRoot != null && cacheRoot.exists() && cacheRoot.canRead() && cacheRoot.canWrite(); |
85 |
assert cacheRoot != null && cacheRoot.exists() && cacheRoot.canRead() && cacheRoot.canWrite(); |
85 |
return new LuceneIndex (getReferencesCacheFolder(cacheRoot)); |
86 |
return new LuceneIndex (getReferencesCacheFolder(cacheRoot)); |
86 |
} |
87 |
} |
Lines 92-101
Link Here
|
92 |
} |
93 |
} |
93 |
|
94 |
|
94 |
@SuppressWarnings("unchecked") // NOI18N, unchecked - lucene has source 1.4 |
95 |
@SuppressWarnings("unchecked") // NOI18N, unchecked - lucene has source 1.4 |
95 |
public List<String> getUsagesData(final String resourceName, Set<ClassIndexImpl.UsageType> mask, BooleanOperator operator) throws IOException { |
96 |
private List<String> getUsagesData(final String resourceName, Set<ClassIndexImpl.UsageType> mask, BooleanOperator operator) throws IOException { |
96 |
if (!isValid(false)) { |
97 |
if (!isValid(false)) { |
97 |
return null; |
98 |
return null; |
98 |
} |
99 |
} |
99 |
final Searcher searcher = new IndexSearcher (this.getReader()); |
100 |
final Searcher searcher = new IndexSearcher (this.getReader()); |
100 |
try { |
101 |
try { |
101 |
final List<String> result = new LinkedList<String> (); |
102 |
final List<String> result = new LinkedList<String> (); |
Lines 139-148
Link Here
|
139 |
} |
140 |
} |
140 |
|
141 |
|
141 |
@SuppressWarnings ("unchecked") // NOI18N, unchecked - lucene has source 1.4 |
142 |
@SuppressWarnings ("unchecked") // NOI18N, unchecked - lucene has source 1.4 |
142 |
public List<String> getUsagesFQN(final String resourceName, final Set<ClassIndexImpl.UsageType>mask, final BooleanOperator operator) throws IOException { |
143 |
public List<String> getUsagesFQN(final String resourceName, final Set<ClassIndexImpl.UsageType>mask, final BooleanOperator operator) throws IOException, InterruptedException { |
143 |
if (!isValid(false)) { |
144 |
if (!isValid(false)) { |
144 |
return null; |
145 |
return null; |
145 |
} |
146 |
} |
|
|
147 |
final AtomicBoolean cancel = this.cancel.get(); |
148 |
assert cancel != null; |
146 |
assert resourceName != null; |
149 |
assert resourceName != null; |
147 |
assert mask != null; |
150 |
assert mask != null; |
148 |
assert operator != null; |
151 |
assert operator != null; |
Lines 164-172
Link Here
|
164 |
break; |
167 |
break; |
165 |
default: |
168 |
default: |
166 |
throw new IllegalArgumentException (operator.toString()); |
169 |
throw new IllegalArgumentException (operator.toString()); |
167 |
} |
170 |
} |
|
|
171 |
if (cancel.get()) { |
172 |
throw new InterruptedException (); |
173 |
} |
168 |
final Hits hits = searcher.search (query); |
174 |
final Hits hits = searcher.search (query); |
169 |
for (Iterator<Hit> it = (Iterator<Hit>) hits.iterator(); it.hasNext();) { |
175 |
for (Iterator<Hit> it = (Iterator<Hit>) hits.iterator(); it.hasNext();) { |
|
|
176 |
if (cancel.get()) { |
177 |
throw new InterruptedIOException (); |
178 |
} |
170 |
final Hit hit = it.next (); |
179 |
final Hit hit = it.next (); |
171 |
final Document doc = hit.getDocument(); |
180 |
final Document doc = hit.getDocument(); |
172 |
final String user = DocumentUtil.getBinaryName(doc); |
181 |
final String user = DocumentUtil.getBinaryName(doc); |
Lines 178-184
Link Here
|
178 |
} |
187 |
} |
179 |
} |
188 |
} |
180 |
|
189 |
|
181 |
public List<String> getReferencesData(final String resourceName) throws IOException { |
190 |
private List<String> getReferencesData(final String resourceName) throws IOException { |
182 |
if (!isValid(false)) { |
191 |
if (!isValid(false)) { |
183 |
return null; |
192 |
return null; |
184 |
} |
193 |
} |
Lines 200-210
Link Here
|
200 |
} |
209 |
} |
201 |
|
210 |
|
202 |
@SuppressWarnings ("unchecked") // NOI18N, unchecked - lucene has source 1.4 |
211 |
@SuppressWarnings ("unchecked") // NOI18N, unchecked - lucene has source 1.4 |
203 |
public <T> void getDeclaredTypes (final String name, final ClassIndex.NameKind kind, final ResultConvertor<T> convertor, final Set<? super T> result) throws IOException { |
212 |
public <T> void getDeclaredTypes (final String name, final ClassIndex.NameKind kind, final ResultConvertor<T> convertor, final Set<? super T> result) throws IOException, InterruptedException { |
204 |
if (!isValid(false)) { |
213 |
if (!isValid(false)) { |
205 |
LOGGER.fine(String.format("LuceneIndex[%s] is invalid!\n", this.toString())); |
214 |
LOGGER.fine(String.format("LuceneIndex[%s] is invalid!\n", this.toString())); |
206 |
return; |
215 |
return; |
207 |
} |
216 |
} |
|
|
217 |
final AtomicBoolean cancel = this.cancel.get(); |
218 |
assert cancel != null; |
208 |
assert name != null; |
219 |
assert name != null; |
209 |
final Set<Term> toSearch = new TreeSet<Term> (new Comparator<Term>(){ |
220 |
final Set<Term> toSearch = new TreeSet<Term> (new Comparator<Term>(){ |
210 |
public int compare (Term t1, Term t2) { |
221 |
public int compare (Term t1, Term t2) { |
Lines 225-247
Link Here
|
225 |
case PREFIX: |
236 |
case PREFIX: |
226 |
if (name.length() == 0) { |
237 |
if (name.length() == 0) { |
227 |
//Special case (all) handle in different way |
238 |
//Special case (all) handle in different way |
228 |
emptyPrefixSearch(in, convertor, result); |
239 |
emptyPrefixSearch(in, convertor, result, cancel); |
229 |
return; |
240 |
return; |
230 |
} |
241 |
} |
231 |
else { |
242 |
else { |
232 |
final Term nameTerm = DocumentUtil.simpleNameTerm(name); |
243 |
final Term nameTerm = DocumentUtil.simpleNameTerm(name); |
233 |
prefixSearh(nameTerm, in, toSearch); |
244 |
prefixSearh(nameTerm, in, toSearch, cancel); |
234 |
break; |
245 |
break; |
235 |
} |
246 |
} |
236 |
case CASE_INSENSITIVE_PREFIX: |
247 |
case CASE_INSENSITIVE_PREFIX: |
237 |
if (name.length() == 0) { |
248 |
if (name.length() == 0) { |
238 |
//Special case (all) handle in different way |
249 |
//Special case (all) handle in different way |
239 |
emptyPrefixSearch(in, convertor, result); |
250 |
emptyPrefixSearch(in, convertor, result, cancel); |
240 |
return; |
251 |
return; |
241 |
} |
252 |
} |
242 |
else { |
253 |
else { |
243 |
final Term nameTerm = DocumentUtil.caseInsensitiveNameTerm(name.toLowerCase()); //XXX: I18N, Locale |
254 |
final Term nameTerm = DocumentUtil.caseInsensitiveNameTerm(name.toLowerCase()); //XXX: I18N, Locale |
244 |
prefixSearh(nameTerm, in, toSearch); |
255 |
prefixSearh(nameTerm, in, toSearch, cancel); |
245 |
break; |
256 |
break; |
246 |
} |
257 |
} |
247 |
case CAMEL_CASE: |
258 |
case CAMEL_CASE: |
Lines 266-272
Link Here
|
266 |
} |
277 |
} |
267 |
} |
278 |
} |
268 |
final Pattern pattern = Pattern.compile(patternString.toString()); |
279 |
final Pattern pattern = Pattern.compile(patternString.toString()); |
269 |
regExpSearch(pattern,DocumentUtil.simpleNameTerm(Character.toString(startChar)),in,toSearch); |
280 |
regExpSearch(pattern,DocumentUtil.simpleNameTerm(Character.toString(startChar)),in,toSearch,cancel); |
270 |
break; |
281 |
break; |
271 |
} |
282 |
} |
272 |
case CASE_INSENSITIVE_REGEXP: |
283 |
case CASE_INSENSITIVE_REGEXP: |
Lines 275-281
Link Here
|
275 |
} |
286 |
} |
276 |
{ |
287 |
{ |
277 |
final Pattern pattern = Pattern.compile(name,Pattern.CASE_INSENSITIVE); |
288 |
final Pattern pattern = Pattern.compile(name,Pattern.CASE_INSENSITIVE); |
278 |
regExpSearch(pattern, DocumentUtil.caseInsensitiveNameTerm(name.toLowerCase()), in, toSearch); //XXX: Locale |
289 |
regExpSearch(pattern, DocumentUtil.caseInsensitiveNameTerm(name.toLowerCase()), in, toSearch,cancel); //XXX: Locale |
279 |
break; |
290 |
break; |
280 |
} |
291 |
} |
281 |
case REGEXP: |
292 |
case REGEXP: |
Lines 284-290
Link Here
|
284 |
} |
295 |
} |
285 |
{ |
296 |
{ |
286 |
final Pattern pattern = Pattern.compile(name); |
297 |
final Pattern pattern = Pattern.compile(name); |
287 |
regExpSearch(pattern, DocumentUtil.simpleNameTerm(name), in, toSearch); |
298 |
regExpSearch(pattern, DocumentUtil.simpleNameTerm(name), in, toSearch, cancel); |
288 |
break; |
299 |
break; |
289 |
} |
300 |
} |
290 |
default: |
301 |
default: |
Lines 296-314
Link Here
|
296 |
final ElementKind[] kindHolder = new ElementKind[1]; |
307 |
final ElementKind[] kindHolder = new ElementKind[1]; |
297 |
Set<Integer> docNums = new TreeSet<Integer>(); |
308 |
Set<Integer> docNums = new TreeSet<Integer>(); |
298 |
while (it.hasNext()) { |
309 |
while (it.hasNext()) { |
|
|
310 |
if (cancel.get()) { |
311 |
throw new InterruptedException (); |
312 |
} |
299 |
tds.seek(it.next()); |
313 |
tds.seek(it.next()); |
300 |
while (tds.next()) { |
314 |
while (tds.next()) { |
301 |
docNums.add (tds.doc()); |
315 |
docNums.add (tds.doc()); |
302 |
} |
316 |
} |
303 |
} |
317 |
} |
304 |
for (Integer docNum : docNums) { |
318 |
for (Integer docNum : docNums) { |
|
|
319 |
if (cancel.get()) { |
320 |
throw new InterruptedException (); |
321 |
} |
305 |
final Document doc = in.document(docNum); |
322 |
final Document doc = in.document(docNum); |
306 |
final String binaryName = DocumentUtil.getBinaryName(doc, kindHolder); |
323 |
final String binaryName = DocumentUtil.getBinaryName(doc, kindHolder); |
307 |
result.add (convertor.convert(kindHolder[0],binaryName)); |
324 |
result.add (convertor.convert(kindHolder[0],binaryName)); |
308 |
} |
325 |
} |
309 |
} |
326 |
} |
310 |
|
327 |
|
311 |
private void regExpSearch (final Pattern pattern, final Term startTerm, final IndexReader in, final Set<Term> toSearch) throws IOException { |
328 |
private void regExpSearch (final Pattern pattern, final Term startTerm, final IndexReader in, final Set<Term> toSearch, final AtomicBoolean cancel) throws IOException, InterruptedException { |
312 |
final String startText = startTerm.text(); |
329 |
final String startText = startTerm.text(); |
313 |
final StringBuilder startBuilder = new StringBuilder (); |
330 |
final StringBuilder startBuilder = new StringBuilder (); |
314 |
startBuilder.append(startText.charAt(0)); |
331 |
startBuilder.append(startText.charAt(0)); |
Lines 324-329
Link Here
|
324 |
final TermEnum en = in.terms(startTerm); |
341 |
final TermEnum en = in.terms(startTerm); |
325 |
try { |
342 |
try { |
326 |
do { |
343 |
do { |
|
|
344 |
if (cancel.get()) { |
345 |
throw new InterruptedException (); |
346 |
} |
327 |
Term term = en.term(); |
347 |
Term term = en.term(); |
328 |
if (term != null && camelField == term.field() && term.text().startsWith(startPrefix)) { |
348 |
if (term != null && camelField == term.field() && term.text().startsWith(startPrefix)) { |
329 |
final Matcher m = pattern.matcher(term.text()); |
349 |
final Matcher m = pattern.matcher(term.text()); |
Lines 340-349
Link Here
|
340 |
} |
360 |
} |
341 |
} |
361 |
} |
342 |
|
362 |
|
343 |
private <T> void emptyPrefixSearch (final IndexReader in, final ResultConvertor<T> convertor, final Set<? super T> result) throws IOException { |
363 |
private <T> void emptyPrefixSearch (final IndexReader in, final ResultConvertor<T> convertor, final Set<? super T> result, final AtomicBoolean cancel) throws IOException, InterruptedException { |
344 |
final int bound = in.maxDoc(); |
364 |
final int bound = in.maxDoc(); |
345 |
final ElementKind[] kindHolder = new ElementKind[1]; |
365 |
final ElementKind[] kindHolder = new ElementKind[1]; |
346 |
for (int i=0; i<bound; i++) { |
366 |
for (int i=0; i<bound; i++) { |
|
|
367 |
if (cancel.get()) { |
368 |
throw new InterruptedException (); |
369 |
} |
347 |
if (!in.isDeleted(i)) { |
370 |
if (!in.isDeleted(i)) { |
348 |
final Document doc = in.document(i); |
371 |
final Document doc = in.document(i); |
349 |
if (doc != null) { |
372 |
if (doc != null) { |
Lines 360-371
Link Here
|
360 |
} |
383 |
} |
361 |
} |
384 |
} |
362 |
|
385 |
|
363 |
private void prefixSearh (Term nameTerm, final IndexReader in, final Set<Term> toSearch) throws IOException { |
386 |
private void prefixSearh (Term nameTerm, final IndexReader in, final Set<Term> toSearch, final AtomicBoolean cancel) throws IOException, InterruptedException { |
364 |
final String prefixField = nameTerm.field(); |
387 |
final String prefixField = nameTerm.field(); |
365 |
final String name = nameTerm.text(); |
388 |
final String name = nameTerm.text(); |
366 |
final TermEnum en = in.terms(nameTerm); |
389 |
final TermEnum en = in.terms(nameTerm); |
367 |
try { |
390 |
try { |
368 |
do { |
391 |
do { |
|
|
392 |
if (cancel.get()) { |
393 |
throw new InterruptedException (); |
394 |
} |
369 |
Term term = en.term(); |
395 |
Term term = en.term(); |
370 |
if (term != null && prefixField == term.field() && term.text().startsWith(name)) { |
396 |
if (term != null && prefixField == term.field() && term.text().startsWith(name)) { |
371 |
toSearch.add (term); |
397 |
toSearch.add (term); |
Lines 380-389
Link Here
|
380 |
} |
406 |
} |
381 |
|
407 |
|
382 |
|
408 |
|
383 |
public void getPackageNames (final String prefix, final boolean directOnly, final Set<String> result) throws IOException { |
409 |
public void getPackageNames (final String prefix, final boolean directOnly, final Set<String> result) throws IOException, InterruptedException { |
384 |
if (!isValid(false)) { |
410 |
if (!isValid(false)) { |
385 |
return; |
411 |
return; |
386 |
} |
412 |
} |
|
|
413 |
final AtomicBoolean cancel = this.cancel.get(); |
414 |
assert cancel != null; |
387 |
final IndexReader in = getReader(); |
415 |
final IndexReader in = getReader(); |
388 |
final Term pkgTerm = DocumentUtil.packageNameTerm (prefix); |
416 |
final Term pkgTerm = DocumentUtil.packageNameTerm (prefix); |
389 |
final String prefixField = pkgTerm.field(); |
417 |
final String prefixField = pkgTerm.field(); |
Lines 398-403
Link Here
|
398 |
final TermEnum terms = in.terms (); |
426 |
final TermEnum terms = in.terms (); |
399 |
try { |
427 |
try { |
400 |
do { |
428 |
do { |
|
|
429 |
if (cancel.get()) { |
430 |
throw new InterruptedIOException (); |
431 |
} |
401 |
final Term currentTerm = terms.term(); |
432 |
final Term currentTerm = terms.term(); |
402 |
if (currentTerm != null && prefixField == currentTerm.field()) { |
433 |
if (currentTerm != null && prefixField == currentTerm.field()) { |
403 |
String pkgName = currentTerm.text(); |
434 |
String pkgName = currentTerm.text(); |
Lines 420-425
Link Here
|
420 |
final TermEnum terms = in.terms (pkgTerm); |
451 |
final TermEnum terms = in.terms (pkgTerm); |
421 |
try { |
452 |
try { |
422 |
do { |
453 |
do { |
|
|
454 |
if (cancel.get()) { |
455 |
throw new InterruptedException (); |
456 |
} |
423 |
final Term currentTerm = terms.term(); |
457 |
final Term currentTerm = terms.term(); |
424 |
if (currentTerm != null && prefixField == currentTerm.field() && currentTerm.text().startsWith(prefix)) { |
458 |
if (currentTerm != null && prefixField == currentTerm.field() && currentTerm.text().startsWith(prefix)) { |
425 |
String pkgName = currentTerm.text(); |
459 |
String pkgName = currentTerm.text(); |