From 3a3f0d4d61e83d8173b6b4a83fa21866fd3562fd Mon Sep 17 00:00:00 2001 From: Jonah Graham Date: Fri, 7 Apr 2023 16:56:11 -0400 Subject: [PATCH] Only consider depth of content types when they are related In the case that two content types match a given input, the depth was being used to select between them. This was done top make sure more specific types for related types were selected as appropriate. The way content types are selected is by first sorting all the candidate types, and then choosing the first one. This change makes the sort only consider the depth of the content type if the content types have a descendent-ancestor relationship. If they are not in the same lineage, the depth is not a criteria for sorting the content types. New content type tests have been added to cover the case from #351, specifically, conflict4 matches the conflict for *.hpp files between the tm4e and cdt plug-ins. The comment update on conflict2 test and the new conflict2a test should probably have been done when Bug 86915 was completed because in 9cbda7e4a42e2fd94e50d8fe700c0ad1574fb5a9 the order of content types was changed, but the comment was not changed, and it wasn't apparent to me if there was an explicit test that covered the conflict case of described content types. Fixes #151 --- .../plugin.xml | 59 ++++++++++++++++-- .../content/Conflict2aContentDescriber.java | 50 +++++++++++++++ .../content/IContentTypeManagerTest.java | 61 +++++++++++++++++-- .../internal/content/ContentTypeCatalog.java | 56 +++++++++++------ 4 files changed, 199 insertions(+), 27 deletions(-) create mode 100644 resources/tests/org.eclipse.core.tests.resources/src/org/eclipse/core/tests/resources/content/Conflict2aContentDescriber.java diff --git a/resources/tests/org.eclipse.core.tests.resources/plugin.xml b/resources/tests/org.eclipse.core.tests.resources/plugin.xml index a65cbff3827..6696f68f9a5 100644 --- a/resources/tests/org.eclipse.core.tests.resources/plugin.xml +++ b/resources/tests/org.eclipse.core.tests.resources/plugin.xml @@ -306,10 +306,25 @@ file-extensions="conflict2" name="Specialized Conflict 2" id="sub_conflict2"/> - + + + + + + + + + + + + policyConstantGeneralIsBetter = (IContentType o1, IContentType o2) -> { ContentType type1 = (ContentType) o1; ContentType type2 = (ContentType) o2; - // first criteria: depth - the lower, the better - int depthCriteria = type1.getDepth() - type2.getDepth(); - if (depthCriteria != 0) - return depthCriteria; + if (isAncestor(type1, type2)) { + // first criteria: depth - the lower, the better + int depthCriteria = type1.getDepth() - type2.getDepth(); + if (depthCriteria != 0) + return depthCriteria; + } // second criteria: priority - the higher, the better int priorityCriteria = type1.getPriority() - type2.getPriority(); if (priorityCriteria != 0) @@ -66,10 +80,12 @@ public final class ContentTypeCatalog { private Comparator policyConstantSpecificIsBetter = (IContentType o1, IContentType o2) -> { ContentType type1 = (ContentType) o1; ContentType type2 = (ContentType) o2; - // first criteria: depth - the higher, the better - int depthCriteria = type1.getDepth() - type2.getDepth(); - if (depthCriteria != 0) - return -depthCriteria; + if (isAncestor(type1, type2)) { + // first criteria: depth - the higher, the better + int depthCriteria = type1.getDepth() - type2.getDepth(); + if (depthCriteria != 0) + return -depthCriteria; + } // second criteria: priority - the higher, the better int priorityCriteria = type1.getPriority() - type2.getPriority(); if (priorityCriteria != 0) @@ -84,10 +100,12 @@ public final class ContentTypeCatalog { private Comparator policyGeneralIsBetter = (IContentType o1, IContentType o2) -> { ContentType type1 = (ContentType) o1; ContentType type2 = (ContentType) o2; - // first criteria: depth - the lower, the better - int depthCriteria = type1.getDepth() - type2.getDepth(); - if (depthCriteria != 0) - return depthCriteria; + if (isAncestor(type1, type2)) { + // first criteria: depth - the lower, the better + int depthCriteria = type1.getDepth() - type2.getDepth(); + if (depthCriteria != 0) + return depthCriteria; + } // second criteria: priority - the higher, the better int priorityCriteria = type1.getPriority() - type2.getPriority(); if (priorityCriteria != 0) @@ -109,10 +127,12 @@ public final class ContentTypeCatalog { private Comparator policySpecificIsBetter = (IContentType o1, IContentType o2) -> { ContentType type1 = (ContentType) o1; ContentType type2 = (ContentType) o2; - // first criteria: depth - the higher, the better - int depthCriteria = type1.getDepth() - type2.getDepth(); - if (depthCriteria != 0) - return -depthCriteria; + if (isAncestor(type1, type2)) { + // first criteria: depth - the higher, the better + int depthCriteria = type1.getDepth() - type2.getDepth(); + if (depthCriteria != 0) + return -depthCriteria; + } // second criteria: priority - the higher, the better int priorityCriteria = type1.getPriority() - type2.getPriority(); if (priorityCriteria != 0)