Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAxel Richard2014-01-23 14:01:58 +0000
committerAxel Richard2014-01-28 08:39:57 +0000
commite980a55327fd951e8f534b4bd468c511292b4354 (patch)
tree1abcad33f3c1c91a06186e83ddabe9ec165c0c38 /plugins
parentc837889966369140ccc8c28a427833659a21f8bc (diff)
downloadorg.eclipse.emf.compare-e980a55327fd951e8f534b4bd468c511292b4354.tar.gz
org.eclipse.emf.compare-e980a55327fd951e8f534b4bd468c511292b4354.tar.xz
org.eclipse.emf.compare-e980a55327fd951e8f534b4bd468c511292b4354.zip
Improve performance of ProjectModelResolver
The method ResourceUtil.getContentTypes(IFile) was called several times for the same IFile. Reduces calls to 1 per IFile. Change-Id: I44f5fb54301016af2fa08d69bd7260941ea16502
Diffstat (limited to 'plugins')
-rw-r--r--plugins/org.eclipse.emf.compare.ide.ui/src/org/eclipse/emf/compare/ide/ui/internal/logical/ProjectModelResolver.java5
-rw-r--r--plugins/org.eclipse.emf.compare.ide/src/org/eclipse/emf/compare/ide/utils/ResourceUtil.java10
2 files changed, 8 insertions, 7 deletions
diff --git a/plugins/org.eclipse.emf.compare.ide.ui/src/org/eclipse/emf/compare/ide/ui/internal/logical/ProjectModelResolver.java b/plugins/org.eclipse.emf.compare.ide.ui/src/org/eclipse/emf/compare/ide/ui/internal/logical/ProjectModelResolver.java
index f66d4f1ed..9cd45fa25 100644
--- a/plugins/org.eclipse.emf.compare.ide.ui/src/org/eclipse/emf/compare/ide/ui/internal/logical/ProjectModelResolver.java
+++ b/plugins/org.eclipse.emf.compare.ide.ui/src/org/eclipse/emf/compare/ide/ui/internal/logical/ProjectModelResolver.java
@@ -42,6 +42,7 @@ import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Path;
import org.eclipse.core.runtime.Status;
+import org.eclipse.core.runtime.content.IContentType;
import org.eclipse.emf.common.util.URI;
import org.eclipse.emf.compare.ide.ui.internal.EMFCompareIDEUIMessages;
import org.eclipse.emf.compare.ide.ui.internal.EMFCompareIDEUIPlugin;
@@ -50,6 +51,7 @@ import org.eclipse.emf.compare.ide.ui.logical.IStorageProvider;
import org.eclipse.emf.compare.ide.ui.logical.IStorageProviderAccessor;
import org.eclipse.emf.compare.ide.ui.logical.IStorageProviderAccessor.DiffSide;
import org.eclipse.emf.compare.ide.ui.logical.SynchronizationModel;
+import org.eclipse.emf.compare.ide.utils.ResourceUtil;
import org.eclipse.emf.compare.ide.utils.StorageTraversal;
import org.eclipse.emf.compare.ide.utils.StorageURIConverter;
@@ -349,8 +351,9 @@ public class ProjectModelResolver extends LogicalModelResolver {
*/
protected static final boolean hasModelType(IFile file) {
boolean isModel = false;
+ final IContentType[] contentTypes = ResourceUtil.getContentTypes(file);
for (int i = 0; i < MODEL_CONTENT_TYPES.length && !isModel; i++) {
- isModel = hasContentType(file, MODEL_CONTENT_TYPES[i]);
+ isModel = hasContentType(MODEL_CONTENT_TYPES[i], contentTypes);
}
return isModel;
}
diff --git a/plugins/org.eclipse.emf.compare.ide/src/org/eclipse/emf/compare/ide/utils/ResourceUtil.java b/plugins/org.eclipse.emf.compare.ide/src/org/eclipse/emf/compare/ide/utils/ResourceUtil.java
index 61080c770..87d304cab 100644
--- a/plugins/org.eclipse.emf.compare.ide/src/org/eclipse/emf/compare/ide/utils/ResourceUtil.java
+++ b/plugins/org.eclipse.emf.compare.ide/src/org/eclipse/emf/compare/ide/utils/ResourceUtil.java
@@ -283,21 +283,19 @@ public final class ResourceUtil {
* configured (as returned by {@link IContentTypeManager#findContentTypesFor(InputStream, String)
* Platform.getContentTypeManager().findContentTypesFor(InputStream, String)}.
*
- * @param resource
- * The resource from which to test the content types.
* @param contentTypeId
* Fully qualified identifier of the content type this <em>resource</em> has to feature.
+ * @param contentTypes
+ * The whole list of content types of the given resource.
* @return <code>true</code> if the given {@link IFile} has the given content type.
*/
- public static boolean hasContentType(IFile resource, String contentTypeId) {
+ public static boolean hasContentType(String contentTypeId, IContentType[] contentTypes) {
IContentTypeManager ctManager = Platform.getContentTypeManager();
IContentType expected = ctManager.getContentType(contentTypeId);
if (expected == null) {
return false;
}
- final IContentType[] contentTypes = getContentTypes(resource);
-
boolean hasContentType = false;
for (int i = 0; i < contentTypes.length && !hasContentType; i++) {
if (contentTypes[i].isKindOf(expected)) {
@@ -315,7 +313,7 @@ public final class ResourceUtil {
* @return All content types associated with the given file, an empty array if none.
*/
@SuppressWarnings("resource")
- private static IContentType[] getContentTypes(IFile file) {
+ public static IContentType[] getContentTypes(IFile file) {
IContentTypeManager ctManager = Platform.getContentTypeManager();
InputStream resourceContent = null;

Back to the top