Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorrchaves2004-06-09 03:25:16 +0000
committerrchaves2004-06-09 03:25:16 +0000
commita9908d0d91dab4f8242bc7f6b306ea2d00942b0a (patch)
tree4c142cdcc716d31aec8c0483af884182cbba2db7
parentf9c4419d70edd0d67ac13093ef70847dfdd27767 (diff)
downloadeclipse.platform.runtime-a9908d0d91dab4f8242bc7f6b306ea2d00942b0a.tar.gz
eclipse.platform.runtime-a9908d0d91dab4f8242bc7f6b306ea2d00942b0a.tar.xz
eclipse.platform.runtime-a9908d0d91dab4f8242bc7f6b306ea2d00942b0a.zip
Fixed bug 66135 - IContentType#getBaseType does not honor aliasing
-rw-r--r--bundles/org.eclipse.core.runtime/src/org/eclipse/core/internal/content/ContentType.java19
-rw-r--r--bundles/org.eclipse.core.runtime/src/org/eclipse/core/internal/content/ContentTypeManager.java17
-rw-r--r--tests/org.eclipse.core.tests.runtime/plugin.xml34
-rw-r--r--tests/org.eclipse.core.tests.runtime/src/org/eclipse/core/tests/runtime/content/IContentTypeManagerTest.java22
4 files changed, 69 insertions, 23 deletions
diff --git a/bundles/org.eclipse.core.runtime/src/org/eclipse/core/internal/content/ContentType.java b/bundles/org.eclipse.core.runtime/src/org/eclipse/core/internal/content/ContentType.java
index fd992050c..d03cbf223 100644
--- a/bundles/org.eclipse.core.runtime/src/org/eclipse/core/internal/content/ContentType.java
+++ b/bundles/org.eclipse.core.runtime/src/org/eclipse/core/internal/content/ContentType.java
@@ -26,9 +26,11 @@ public final class ContentType implements IContentType {
public int describe(InputStream contents, IContentDescription description) throws IOException {
return INVALID;
}
+
public int describe(Reader contents, IContentDescription description) throws IOException {
return INVALID;
}
+
public QualifiedName[] getSupportedOptions() {
return new QualifiedName[0];
}
@@ -220,7 +222,8 @@ public final class ContentType implements IContentType {
return getTarget().getBaseType();
if (baseTypeId == null)
return null;
- return manager.getContentType(baseTypeId);
+ ContentType originalBaseType = manager.internalGetContentType(baseTypeId);
+ return originalBaseType != null ? originalBaseType.getTarget() : null;
}
String getBaseTypeId() {
@@ -474,7 +477,7 @@ public final class ContentType implements IContentType {
if (another == null)
return false;
if (aliasTarget != null)
- return getTarget().isKindOf(another);
+ return getTarget().isKindOf(another);
if (this == another)
return true;
if (getDepth() <= ((ContentType) another).getDepth())
@@ -525,6 +528,8 @@ public final class ContentType implements IContentType {
// don't allow a sub-type to be made into an alias to the base type
if (aliasTarget == null && isKindOf(newTarget))
return;
+ if (ContentTypeManager.DEBUGGING)
+ Policy.debug("Setting alias target for " + this + " -> " + newTarget); //$NON-NLS-1$ //$NON-NLS-2$
aliasTarget = newTarget;
}
@@ -549,9 +554,19 @@ public final class ContentType implements IContentType {
void setValidation(byte validation) {
this.validation = validation;
+ if (ContentTypeManager.DEBUGGING)
+ Policy.debug("Validating " + this + ": " + getValidationString(validation)); //$NON-NLS-1$ //$NON-NLS-2$
+ }
+
+ private static String getValidationString(byte validation) {
+ return validation == STATUS_VALID ? "VALID" : (validation == STATUS_INVALID ? "INVALID" : "UNKNOWN"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
}
public String toString() {
return getId();
}
+
+ public boolean isAlias() {
+ return aliasTarget != null;
+ }
} \ No newline at end of file
diff --git a/bundles/org.eclipse.core.runtime/src/org/eclipse/core/internal/content/ContentTypeManager.java b/bundles/org.eclipse.core.runtime/src/org/eclipse/core/internal/content/ContentTypeManager.java
index e790a6646..c08734f15 100644
--- a/bundles/org.eclipse.core.runtime/src/org/eclipse/core/internal/content/ContentTypeManager.java
+++ b/bundles/org.eclipse.core.runtime/src/org/eclipse/core/internal/content/ContentTypeManager.java
@@ -28,14 +28,21 @@ public class ContentTypeManager implements IContentTypeManager {
// don't do anything on close
}
}
+
final static String CONTENT_TYPE_PREF_NODE = Platform.PI_RUNTIME + IPath.SEPARATOR + "content-types"; //$NON-NLS-1$
+
private static final String OPTION_DEBUG_CONTENT_TYPES = Platform.PI_RUNTIME + "/contenttypes/debug"; //$NON-NLS-1$;
+
static final boolean DEBUGGING = Boolean.TRUE.toString().equalsIgnoreCase(InternalPlatform.getDefault().getOption(OPTION_DEBUG_CONTENT_TYPES));
+
private static ContentTypeManager instance;
+
private static final int MARK_LIMIT = 0x400;
private ContentTypeBuilder builder;
+
private Map catalog = new HashMap();
+
// a comparator used when resolving conflicts (two types associated to the same spec)
private Comparator conflictComparator = new Comparator() {
public int compare(Object o1, Object o2) {
@@ -48,7 +55,7 @@ public class ContentTypeManager implements IContentTypeManager {
// second criteria: priority - the higher, the better
int priorityCriteria = type1.getPriority() - type2.getPriority();
if (priorityCriteria != 0)
- return -priorityCriteria;
+ return -priorityCriteria;
// to ensure stability
return type1.getId().compareTo(type2.getId());
}
@@ -59,7 +66,9 @@ public class ContentTypeManager implements IContentTypeManager {
return ((ContentType) o2).getDepth() - ((ContentType) o1).getDepth();
}
};
+
private Map fileExtensions = new HashMap();
+
private Map fileNames = new HashMap();
/*
@@ -241,7 +250,7 @@ public class ContentTypeManager implements IContentTypeManager {
List result = new ArrayList(catalog.size());
for (Iterator i = catalog.values().iterator(); i.hasNext();) {
ContentType type = (ContentType) i.next();
- if (type.isValid())
+ if (type.isValid() && !type.isAlias())
result.add(type);
}
return (IContentType[]) result.toArray(new IContentType[result.size()]);
@@ -263,7 +272,7 @@ public class ContentTypeManager implements IContentTypeManager {
*/
public IContentType getContentType(String contentTypeIdentifier) {
ContentType type = internalGetContentType(contentTypeIdentifier);
- return (type != null && type.isValid()) ? type : null;
+ return (type != null && type.isValid() && !type.isAlias()) ? type : null;
}
/**
@@ -395,7 +404,7 @@ public class ContentTypeManager implements IContentTypeManager {
}
protected void startup() {
- builder = createBuilder();
+ builder = createBuilder();
catalog = new HashMap();
builder.startup();
builder.buildContentTypes();
diff --git a/tests/org.eclipse.core.tests.runtime/plugin.xml b/tests/org.eclipse.core.tests.runtime/plugin.xml
index d31b283dc..89b0fe5e6 100644
--- a/tests/org.eclipse.core.tests.runtime/plugin.xml
+++ b/tests/org.eclipse.core.tests.runtime/plugin.xml
@@ -51,7 +51,10 @@
priority="high"
name="Specialized Conflict 1"
id="aaa_conflict1"/>
- <!-- A base type and a sub-type (that restates file-spec) are in conflict. Base type should be picked. -->
+ <!--
+ A base type and a sub-type (that restates file-spec) are in conflict.
+ Base type should be picked (no aliasing will be done since they are related).
+ -->
<content-type
file-extensions="conflict2"
name="Conflict 2"
@@ -62,20 +65,29 @@
file-extensions="conflict2"
name="Specialized Conflict 2"
id="aaa_conflict2"/>
- <!-- Two unrelated types are in conflict. The "heaviest" one should be picked -->
+ <!--
+ Two unrelated types are in conflict. The one with lowest depth should be picked,
+ an the other marked as an alias.
+ -->
<content-type
- file-extensions="conflict3"
- name="Unrelated Conflict 3"
- id="xxx_conflict3"/>
- <content-type
- file-extensions="conflict3"
+ file-extensions="base_conflict3"
name="Conflict 3"
- id="conflict3"/>
- <content-type
- base-type="conflict3"
+ id="base_conflict3"/>
+ <content-type
+ base-type="base_conflict3"
file-extensions="conflict3"
- name="Specialized Conflict 3"
+ name="Deeper Conflict 3"
id="aaa_conflict3"/>
+ <content-type
+ base-type="aaa_conflict3"
+ file-extensions="specialized.conflict3"
+ name="Specialized Conflict 3"
+ id="bbb_conflict3"/>
+ <content-type
+ file-extensions="conflict3"
+ name="Unrelated Conflict 3"
+ id="conflict3"/>
+ <!-- end of conflict-related content types -->
<content-type
file-extensions="tzt"
default-charset="BAR"
diff --git a/tests/org.eclipse.core.tests.runtime/src/org/eclipse/core/tests/runtime/content/IContentTypeManagerTest.java b/tests/org.eclipse.core.tests.runtime/src/org/eclipse/core/tests/runtime/content/IContentTypeManagerTest.java
index 34ea5677a..8bb37d23a 100644
--- a/tests/org.eclipse.core.tests.runtime/src/org/eclipse/core/tests/runtime/content/IContentTypeManagerTest.java
+++ b/tests/org.eclipse.core.tests.runtime/src/org/eclipse/core/tests/runtime/content/IContentTypeManagerTest.java
@@ -465,20 +465,29 @@ public class IContentTypeManagerTest extends DynamicPluginTest {
IContentType conflict2a = manager.getContentType(PI_RUNTIME_TESTS + ".conflict2");
IContentType conflict2b = manager.getContentType(PI_RUNTIME_TESTS + ".aaa_conflict2");
assertNotNull("2.0", conflict2a);
+ // although there is conflict, aliasing is not done for related content types
assertNotNull("2.1", conflict2b);
IContentType preferredConflict2 = manager.findContentTypeFor("test.conflict2");
assertNotNull("2.2", preferredConflict2);
assertEquals("2.3", conflict2a, preferredConflict2);
IContentType conflict3a = manager.getContentType(PI_RUNTIME_TESTS + ".conflict3");
- IContentType conflict3b = manager.getContentType(PI_RUNTIME_TESTS + ".aaa_conflict3");
- IContentType conflict3c = manager.getContentType(PI_RUNTIME_TESTS + ".xxx_conflict3");
+ IContentType conflict3b = manager.getContentType(PI_RUNTIME_TESTS + ".base_conflict3");
+ IContentType conflict3c = manager.getContentType(PI_RUNTIME_TESTS + ".aaa_conflict3");
+ IContentType conflict3d = manager.getContentType(PI_RUNTIME_TESTS + ".bbb_conflict3");
assertNotNull("3.0", conflict3a);
- assertNotNull("3.1", conflict3b);
- assertNotNull("3.2", conflict3c);
+ assertNotNull("3.1", conflict3b);
+ // this content type is an alias for conflict3a, should not be visible
+ assertNull("3.2", conflict3c);
+ assertFalse(contains(manager.getAllContentTypes(), conflict3c));
+ // this descends from conflict3c. Its base type should be conflict3a instead (due to aliasing)
+ assertNotNull("3.3", conflict3d);
+ assertEquals("3.4", conflict3a, conflict3d.getBaseType());
+
+ // the chosen one should be conflict3a
IContentType preferredConflict3 = manager.findContentTypeFor("test.conflict3");
- assertNotNull("3.3", preferredConflict3);
- assertEquals("3.3", conflict3a, preferredConflict3);
+ assertNotNull("4.0", preferredConflict3);
+ assertEquals("4.1", conflict3a, preferredConflict3);
}
public void testMyContentDescriber() throws UnsupportedEncodingException, IOException {
@@ -512,6 +521,7 @@ public class IContentTypeManagerTest extends DynamicPluginTest {
}
public static Test suite() {
+// return new IContentTypeManagerTest("testFileSpecConflicts");
return new TestSuite(IContentTypeManagerTest.class);
}

Back to the top