Lines 251-257
Link Here
|
251 |
|
251 |
|
252 |
IContentType[] findContentTypesFor(ContentTypeMatcher matcher, InputStream contents, String fileName) throws IOException { |
252 |
IContentType[] findContentTypesFor(ContentTypeMatcher matcher, InputStream contents, String fileName) throws IOException { |
253 |
final ILazySource buffer = ContentTypeManager.readBuffer(contents); |
253 |
final ILazySource buffer = ContentTypeManager.readBuffer(contents); |
254 |
IContentType[] selected = internalFindContentTypesFor(matcher, buffer, fileName); |
254 |
IContentType[] selected = internalFindContentTypesFor(matcher, buffer, fileName, true); |
255 |
// give the policy a chance to change the results |
255 |
// give the policy a chance to change the results |
256 |
ISelectionPolicy policy = matcher.getPolicy(); |
256 |
ISelectionPolicy policy = matcher.getPolicy(); |
257 |
if (policy != null) |
257 |
if (policy != null) |
Lines 299-305
Link Here
|
299 |
} |
299 |
} |
300 |
|
300 |
|
301 |
private IContentDescription getDescriptionFor(ContentTypeMatcher matcher, ILazySource contents, String fileName, QualifiedName[] options) throws IOException { |
301 |
private IContentDescription getDescriptionFor(ContentTypeMatcher matcher, ILazySource contents, String fileName, QualifiedName[] options) throws IOException { |
302 |
IContentType[] selected = internalFindContentTypesFor(matcher, contents, fileName); |
302 |
IContentType[] selected = internalFindContentTypesFor(matcher, contents, fileName, false); |
303 |
if (selected.length == 0) |
303 |
if (selected.length == 0) |
304 |
return null; |
304 |
return null; |
305 |
// give the policy a chance to change the results |
305 |
// give the policy a chance to change the results |
Lines 352-357
Link Here
|
352 |
} |
352 |
} |
353 |
|
353 |
|
354 |
public IContentType[] internalFindContentTypesFor(ILazySource buffer, IContentType[][] subset, Comparator validPolicy, Comparator indeterminatePolicy) throws IOException { |
354 |
public IContentType[] internalFindContentTypesFor(ILazySource buffer, IContentType[][] subset, Comparator validPolicy, Comparator indeterminatePolicy) throws IOException { |
|
|
355 |
if (subset[0].length + subset[1].length == 0) |
356 |
// don't do further work if subset is empty |
357 |
return subset[0]; |
355 |
final List appropriate = new ArrayList(5); |
358 |
final List appropriate = new ArrayList(5); |
356 |
final int validFullName = collectMatchingByContents(0, subset[0], appropriate, buffer); |
359 |
final int validFullName = collectMatchingByContents(0, subset[0], appropriate, buffer); |
357 |
final int appropriateFullName = appropriate.size(); |
360 |
final int appropriateFullName = appropriate.size(); |
Lines 369-375
Link Here
|
369 |
return result; |
372 |
return result; |
370 |
} |
373 |
} |
371 |
|
374 |
|
372 |
private IContentType[] internalFindContentTypesFor(ContentTypeMatcher matcher, ILazySource buffer, String fileName) throws IOException { |
375 |
private IContentType[] internalFindContentTypesFor(ContentTypeMatcher matcher, ILazySource buffer, String fileName, boolean forceValidation) throws IOException { |
373 |
final IContentType[][] subset; |
376 |
final IContentType[][] subset; |
374 |
final Comparator validPolicy; |
377 |
final Comparator validPolicy; |
375 |
Comparator indeterminatePolicy; |
378 |
Comparator indeterminatePolicy; |
Lines 383-388
Link Here
|
383 |
indeterminatePolicy = policyGeneralIsBetter; |
386 |
indeterminatePolicy = policyGeneralIsBetter; |
384 |
validPolicy = policySpecificIsBetter; |
387 |
validPolicy = policySpecificIsBetter; |
385 |
} |
388 |
} |
|
|
389 |
int total = subset[0].length + subset[1].length; |
390 |
if (total == 0) |
391 |
return subset[0]; |
392 |
if (!forceValidation && total == 1) |
393 |
// do not do validation if only one was found (caller will validate when describing) |
394 |
return subset[0].length == 1 ? subset[0] : subset[1]; |
386 |
return internalFindContentTypesFor(buffer, subset, validPolicy, indeterminatePolicy); |
395 |
return internalFindContentTypesFor(buffer, subset, validPolicy, indeterminatePolicy); |
387 |
} |
396 |
} |
388 |
|
397 |
|
Lines 450-458
Link Here
|
450 |
Set initialSet = (Set) associations.get(FileSpec.getMappingKeyFor(text)); |
459 |
Set initialSet = (Set) associations.get(FileSpec.getMappingKeyFor(text)); |
451 |
if (initialSet != null && !initialSet.isEmpty()) { |
460 |
if (initialSet != null && !initialSet.isEmpty()) { |
452 |
// copy so we can modify |
461 |
// copy so we can modify |
453 |
result = new HashSet(initialSet); |
462 |
result = new HashSet(initialSet); |
454 |
// invert the last two bits so it is easier to compare |
463 |
// invert the last two bits so it is easier to compare |
455 |
typeMask ^= (IContentType.IGNORE_PRE_DEFINED | IContentType.IGNORE_USER_DEFINED); |
464 |
typeMask ^= (IContentType.IGNORE_PRE_DEFINED | IContentType.IGNORE_USER_DEFINED); |
456 |
for (Iterator i = result.iterator(); i.hasNext();) { |
465 |
for (Iterator i = result.iterator(); i.hasNext();) { |
457 |
ContentType contentType = (ContentType) i.next(); |
466 |
ContentType contentType = (ContentType) i.next(); |
458 |
if (!contentType.hasFileSpec(text, typeMask, true)) |
467 |
if (!contentType.hasFileSpec(text, typeMask, true)) |