@@ -409,7 +409,7 @@ IContentType[] findContentTypesFor(ContentTypeMatcher matcher, InputStream conte
409409 }
410410
411411 IContentType [] findContentTypesFor (ContentTypeMatcher matcher , final String fileName ) {
412- IContentType [] selected = concat (internalFindContentTypesSorted (matcher , fileName , policyConstantGeneralIsBetter ));
412+ IContentType [] selected = concat (internalFindContentTypesSorted (matcher , fileName , policyConstantGeneralIsBetter , false ));
413413 // give the policy a chance to change the results
414414 ISelectionPolicy policy = matcher .getPolicy ();
415415 if (policy != null ) {
@@ -418,6 +418,15 @@ IContentType[] findContentTypesFor(ContentTypeMatcher matcher, final String file
418418 return selected ;
419419 }
420420
421+ IContentType findFirstContentTypeFor (ContentTypeMatcher matcher , final String fileName ) {
422+ ISelectionPolicy policy = matcher .getPolicy ();
423+ IContentType [] selected = concat (internalFindContentTypesSorted (matcher , fileName , policyConstantGeneralIsBetter , policy == null ));
424+ // give the policy a chance to change the results
425+ if (policy != null )
426+ selected = applyPolicy (policy , selected , true , false );
427+ return selected .length != 0 ? selected [0 ] : null ;
428+ }
429+
421430 synchronized public IContentType [] getAllContentTypes () {
422431 List <ContentType > result = new ArrayList <>(contentTypes .size ());
423432 for (IContentType iContentType : contentTypes .values ()) {
@@ -555,7 +564,7 @@ private IContentType[] internalFindContentTypesFor(ContentTypeMatcher matcher, I
555564 indeterminatePolicy = policyConstantGeneralIsBetter ;
556565 validPolicy = policyConstantSpecificIsBetter ;
557566 } else {
558- subset = internalFindContentTypesSorted (matcher , fileName , policyLexicographical );
567+ subset = internalFindContentTypesSorted (matcher , fileName , policyLexicographical , false );
559568 indeterminatePolicy = policyGeneralIsBetter ;
560569 validPolicy = policySpecificIsBetter ;
561570 }
@@ -590,7 +599,7 @@ private IContentType[] internalFindContentTypesFor(ContentTypeMatcher matcher, I
590599 * @return all matching content types in the preferred order
591600 * @see IContentTypeManager#findContentTypesFor(String)
592601 */
593- synchronized private IContentType [][] internalFindContentTypesSorted (ContentTypeMatcher matcher , final String fileName , Comparator <IContentType > sortingPolicy ) {
602+ synchronized private IContentType [][] internalFindContentTypesSorted (ContentTypeMatcher matcher , final String fileName , Comparator <IContentType > sortingPolicy , boolean quickFinish ) {
594603 IScopeContext context = matcher .getContext ();
595604 IContentType [][] result = { NO_CONTENT_TYPES , NO_CONTENT_TYPES , NO_CONTENT_TYPES };
596605
@@ -609,6 +618,9 @@ synchronized private IContentType[][] internalFindContentTypesSorted(ContentType
609618 result [0 ] = selectedByName .toArray (new IContentType [selectedByName .size ()]);
610619 if (result [0 ].length > 1 ) {
611620 Arrays .sort (result [0 ], sortingPolicy );
621+ if (quickFinish ) {
622+ return result ;
623+ }
612624 }
613625
614626 final String fileExtension = ContentTypeManager .getFileExtension (fileName );
@@ -628,6 +640,9 @@ synchronized private IContentType[][] internalFindContentTypesSorted(ContentType
628640 }
629641 if (result [1 ].length > 1 ) {
630642 Arrays .sort (result [1 ], sortingPolicy );
643+ if (quickFinish ) {
644+ return result ;
645+ }
631646 }
632647
633648 final Set <ContentType > allByFilePattern ;
0 commit comments