Fix contentType for an empty YAML file, now it returns a more generic
YEdit editor.
Why this fix works
An empty file always returns INDETERMINATE as description. Note
that it's not the VALID which is returned when a content describer
actually accepts the input. See
com.reprezen.swagedit.core.editor.TextContentDescriber.describe(InputStream, IContentDescription):
All ContentDescriber for a given file extensions are equally
important.
Because all the ContentDescriber return INDETERMINATE, they are
treated equally important, see
org.eclipse.core.internal.content.ContentTypeCatalog.collectMatchingByContents(int, IContentType[], List<ContentType>, ILazySource, Map<String, Object>)
Then IContentType are sorted and the first one wins
org.eclipse.core.internal.content.ContentTypeCatalog.internalFindContentTypesFor(ILazySource, IContentType[][], Comparator<IContentType>, Comparator<IContentType>)
sorts the inputs. In case of INDETERMINATE,
ContentTypeCatalog.policyConstantGeneralIsBetter is used which is...
A sorting policy where the more generic content type wins.
Lexicographical comparison is done as a last resort when all other
criteria fail.
where more generic content type means, getDepth() is based on the
hierarchy defined by the base-type:
// first criteria: depth - the lower, the better
int depthCriteria = type1.getDepth() - type2.getDepth();
By using YEdit as the base-type, we make the YEdit the more generic
content type => it will be used in case of empty files.
Fix contentType for an empty YAML file, now it returns a more generic YEdit editor. Why this fix works
An empty file always returns
INDETERMINATE
as description. Note that it's not theVALID
which is returned when a content describer actually accepts the input. Seecom.reprezen.swagedit.core.editor.TextContentDescriber.describe(InputStream, IContentDescription)
:All ContentDescriber for a given file extensions are equally important. Because all the ContentDescriber return
INDETERMINATE
, they are treated equally important, seeorg.eclipse.core.internal.content.ContentTypeCatalog.collectMatchingByContents(int, IContentType[], List<ContentType>, ILazySource, Map<String, Object>)
Then
IContentType
are sorted and the first one winsorg.eclipse.core.internal.content.ContentTypeCatalog.internalFindContentTypesFor(ILazySource, IContentType[][], Comparator<IContentType>, Comparator<IContentType>)
sorts the inputs. In case ofINDETERMINATE
,ContentTypeCatalog.policyConstantGeneralIsBetter
is used which is...where more generic content type means,
getDepth()
is based on the hierarchy defined by thebase-type
:By using YEdit as the
base-type
, we make the YEdit the more generic content type => it will be used in case of empty files.