Commit 6342d27e authored by Andras Janko's avatar Andras Janko
Browse files

Case insensitive model file extensions



I modified the file extension handling in the
AbstractResourceScopeProvider#hasApplicableFileExtension(IFile), to
ignore the case of the file extensions of IFiles, and also ignore the
case of the file extensions of the registered Content Types (e.g. .txt,
.TXT, .TxT are both accepted now as a .txt Content Type). Its usage
should be through the
ResourceScopeProviderRegistry#hasApplicableFileExtension(IFile)

Change-Id: Ieb6a664e94f6cf90f0f82300a361bdec2433b23f
Signed-off-by: default avatarAndras Janko <andras.janko@incquerylabs.com>
Signed-off-by: default avatarBalazs Varnai <balazs_varnai@mentor.com>
parent 021a6321
Loading
Loading
Loading
Loading
+18 −7
Original line number Diff line number Diff line
@@ -57,16 +57,18 @@ public abstract class AbstractResourceScopeProvider implements IResourceScopePro
			return false;
		}

		extension = extension.toLowerCase();

		// Check if the given file's extension matches one of the extensions associated with one of the content types
		// that are supported by one of the metamodel descriptors which this resource scope provider is used for
		for (IMetaModelDescriptor mmDescriptor : ResourceScopeProviderRegistry.INSTANCE.getMetaModelDescriptorsFor(this)) {
			for (String contentTypeId : mmDescriptor.getContentTypeIds()) {
				if (ExtendedPlatform.getContentTypeFileExtensions(contentTypeId).contains(extension)) {
				if (isContentTypeContainsFileExtension(contentTypeId, extension)) {
					return true;
				}
			}
			for (String compatibleContentTypeId : mmDescriptor.getCompatibleContentTypeIds()) {
				if (ExtendedPlatform.getContentTypeFileExtensions(compatibleContentTypeId).contains(extension)) {
				if (isContentTypeContainsFileExtension(compatibleContentTypeId, extension)) {
					return true;
				}
			}
@@ -130,4 +132,13 @@ public abstract class AbstractResourceScopeProvider implements IResourceScopePro
	public Diagnostic validate(IFile file) {
		return Diagnostic.OK_INSTANCE;
	}

	private boolean isContentTypeContainsFileExtension(String contentTypeID, String fileExtension) {
		for (String contentTypeFileExtension : ExtendedPlatform.getContentTypeFileExtensions(contentTypeID)) {
			if (contentTypeFileExtension != null && fileExtension.equals(contentTypeFileExtension.toLowerCase())) {
				return true;
			}
		}
		return false;
	}
}
+50 −0
Original line number Diff line number Diff line
package org.eclipse.sphinx.tests.emf.integration.scoping;

import java.util.Set;

import org.eclipse.core.resources.IFile;
import org.eclipse.sphinx.emf.scoping.ResourceScopeProviderRegistry;
import org.eclipse.sphinx.testutils.integration.referenceworkspace.DefaultIntegrationTestCase;
import org.eclipse.sphinx.testutils.integration.referenceworkspace.DefaultTestReferenceWorkspace;

public class ResourceScopeProviderRegistryTest extends DefaultIntegrationTestCase {

	public ResourceScopeProviderRegistryTest() {
		setRecycleReferenceWorkspaceOfPreviousTestRun(false);

		// Set subset of projects to load
		Set<String> projectsToLoad = getProjectSubsetToLoad();
		projectsToLoad.add(DefaultTestReferenceWorkspace.HB_PROJECT_NAME_20_F);
	}

	public void testResourceScopeProviderRegistry_UpperCaseFileExtension() {
		IFile file20F_1 = refWks.hbProject20_F.getFile(DefaultTestReferenceWorkspace.HB_FILE_NAME_20_20F_1);
		assertNotNull(file20F_1);
		assertEquals("INSTANCEMODEL", file20F_1.getFileExtension()); //$NON-NLS-1$
		assertTrue(ResourceScopeProviderRegistry.INSTANCE.hasApplicableFileExtension(file20F_1));

		IFile file20F_2 = refWks.hbProject20_F.getFile(DefaultTestReferenceWorkspace.HB_FILE_NAME_20_20F_2);
		assertNotNull(file20F_2);
		assertEquals("TYPEMODEL", file20F_2.getFileExtension()); //$NON-NLS-1$
		assertTrue(ResourceScopeProviderRegistry.INSTANCE.hasApplicableFileExtension(file20F_2));
	}

	public void testResourceScopeProviderRegistry_MixedCaseFileExtension() {
		IFile file20F_3 = refWks.hbProject20_F.getFile(DefaultTestReferenceWorkspace.HB_FILE_NAME_20_20F_3);
		assertNotNull(file20F_3);
		assertEquals("InStAnCeMoDeL", file20F_3.getFileExtension()); //$NON-NLS-1$
		assertTrue(ResourceScopeProviderRegistry.INSTANCE.hasApplicableFileExtension(file20F_3));

		IFile file20F_4 = refWks.hbProject20_F.getFile(DefaultTestReferenceWorkspace.HB_FILE_NAME_20_20F_4);
		assertNotNull(file20F_4);
		assertEquals("Typemodel", file20F_4.getFileExtension()); //$NON-NLS-1$
		assertTrue(ResourceScopeProviderRegistry.INSTANCE.hasApplicableFileExtension(file20F_4));
	}

	public void testResourceScopeProviderRegistry_LowerCaseFileExtension() {
		IFile file21F_4 = refWks.hbProject20_F.getFile(DefaultTestReferenceWorkspace.HB_FILE_NAME_21_20F_4);
		assertNotNull(file21F_4);
		assertEquals("instancemodel", file21F_4.getFileExtension()); //$NON-NLS-1$
		assertTrue(ResourceScopeProviderRegistry.INSTANCE.hasApplicableFileExtension(file21F_4));
	}
}
+3.43 KiB (72.4 KiB)

File changed.

No diff preview for this file type.

+23 −7
Original line number Diff line number Diff line
@@ -139,6 +139,15 @@ public class DefaultTestReferenceWorkspace extends AbstractReferenceWorkspace {
	public static final String UML2_FILE_NAME_20E_2 = "uml2File_20E_2.uml";
	public static final String UML2_FILE_NAME_20E_3 = "uml2File_20E_3.uml";

	/* ----- HUMMINGBIRD 20 Project A ----- */
	public static final String HB_PROJECT_NAME_20_F = "hbProject20_F";

	public static final String HB_FILE_NAME_20_20F_1 = "hbFile20_20F_1.INSTANCEMODEL";
	public static final String HB_FILE_NAME_20_20F_2 = "hbFile20_20F_2.TYPEMODEL";
	public static final String HB_FILE_NAME_20_20F_3 = "hbFile20_20F_3.InStAnCeMoDeL";
	public static final String HB_FILE_NAME_20_20F_4 = "hbFile20_20F_4.Typemodel";
	public static final String HB_FILE_NAME_21_20F_4 = "hbFile21_20F_4.instancemodel";

	/* ----- HUMMINGBIRD 20 Workflows ----- */
	public static final String HB_PROJECT_NAME_20_WORKFLOWS = "hbProject20.workflows";

@@ -154,6 +163,7 @@ public class DefaultTestReferenceWorkspace extends AbstractReferenceWorkspace {
	public IProject hbProject20_C;
	public IProject hbProject20_D;
	public IProject hbProject20_E;
	public IProject hbProject20_F;
	public IProject hbProject20_Workflows;

	/* ----- EditingDomains ----- */
@@ -193,6 +203,7 @@ public class DefaultTestReferenceWorkspace extends AbstractReferenceWorkspace {
		hbProject20_C = getReferenceProject(HB_PROJECT_NAME_20_C);
		hbProject20_D = getReferenceProject(HB_PROJECT_NAME_20_D);
		hbProject20_E = getReferenceProject(HB_PROJECT_NAME_20_E);
		hbProject20_F = getReferenceProject(HB_PROJECT_NAME_20_F);
		hbProject20_Workflows = getReferenceProject(HB_PROJECT_NAME_20_WORKFLOWS);
	}

@@ -205,8 +216,8 @@ public class DefaultTestReferenceWorkspace extends AbstractReferenceWorkspace {
	@Override
	protected void initReferenceFileDescriptors() {

		addFileDescriptors(HB_PROJECT_NAME_10_A, new String[] { HB_FILE_NAME_10_10A_1, HB_FILE_NAME_10_10A_2, HB_FILE_NAME_10_10A_3,
				HB_FILE_NAME_10_10A_4, HB_FILE_NAME_10_10A_5 }, Hummingbird10MMDescriptor.INSTANCE);
		addFileDescriptors(HB_PROJECT_NAME_10_A, new String[] { HB_FILE_NAME_10_10A_1, HB_FILE_NAME_10_10A_2, HB_FILE_NAME_10_10A_3, HB_FILE_NAME_10_10A_4, HB_FILE_NAME_10_10A_5 },
				Hummingbird10MMDescriptor.INSTANCE);
		addFileDescriptors(HB_PROJECT_NAME_10_B, new String[] { HB_FILE_NAME_10_10B_1, HB_FILE_NAME_10_10B_2, HB_FILE_NAME_10_10B_3 },
				Hummingbird10MMDescriptor.INSTANCE);
		addFileDescriptors(HB_PROJECT_NAME_10_C, new String[] { HB_FILE_NAME_10_10C_1, HB_FILE_NAME_10_10C_2, HB_FILE_NAME_10_10C_3 },
@@ -217,11 +228,13 @@ public class DefaultTestReferenceWorkspace extends AbstractReferenceWorkspace {
				Hummingbird10MMDescriptor.INSTANCE);
		addFileDescriptors(HB_PROJECT_NAME_10_E, new String[] { HB_FILE_NAME_10_10E_1, HB_FILE_NAME_10_10E_2, HB_FILE_NAME_10_10E_3 },
				Hummingbird10MMDescriptor.INSTANCE);
		addFileDescriptors(HB_PROJECT_NAME_10_F, new String[] { HB_FOLDER_NAME_10_10F_1 + "/" + HB_FILE_NAME_10_10F_1,
		addFileDescriptors(
				HB_PROJECT_NAME_10_F, new String[] { HB_FOLDER_NAME_10_10F_1 + "/" + HB_FILE_NAME_10_10F_1,
						HB_FOLDER_NAME_10_10F_1 + "/" + HB_FILE_NAME_10_10F_2, HB_FOLDER_NAME_10_10F_1 + "/" + HB_FILE_NAME_10_10F_3 },
				Hummingbird10MMDescriptor.INSTANCE);
		addFileDescriptors(HB_PROJECT_NAME_20_A, new String[] { HB_FILE_NAME_20_20A_1, HB_FILE_NAME_20_20A_2, HB_FILE_NAME_20_20A_3,
				HB_FILE_NAME_20_20A_4, HB_FILE_NAME_21_20A_4 }, Hummingbird20MMDescriptor.INSTANCE);
		addFileDescriptors(HB_PROJECT_NAME_20_A,
				new String[] { HB_FILE_NAME_20_20A_1, HB_FILE_NAME_20_20A_2, HB_FILE_NAME_20_20A_3, HB_FILE_NAME_20_20A_4, HB_FILE_NAME_21_20A_4 },
				Hummingbird20MMDescriptor.INSTANCE);
		addFileDescriptors(HB_PROJECT_NAME_20_B, new String[] { HB_FILE_NAME_20_20B_1, HB_FILE_NAME_20_20B_2, HB_FILE_NAME_20_20B_3 },
				Hummingbird20MMDescriptor.INSTANCE);
		addFileDescriptors(HB_PROJECT_NAME_20_B, new String[] { UML2_FILE_NAME_20B_1, UML2_FILE_NAME_20B_2, UML2_FILE_NAME_20B_3 },
@@ -238,12 +251,15 @@ public class DefaultTestReferenceWorkspace extends AbstractReferenceWorkspace {
				Hummingbird20MMDescriptor.INSTANCE);
		addFileDescriptors(HB_PROJECT_NAME_20_E, new String[] { UML2_FILE_NAME_20E_1, UML2_FILE_NAME_20E_2, UML2_FILE_NAME_20E_3 },
				UML2MMDescriptor.INSTANCE);
		addFileDescriptors(HB_PROJECT_NAME_20_F,
				new String[] { HB_FILE_NAME_20_20F_1, HB_FILE_NAME_20_20F_2, HB_FILE_NAME_20_20F_3, HB_FILE_NAME_20_20F_4, HB_FILE_NAME_21_20F_4 },
				Hummingbird20MMDescriptor.INSTANCE);
	}

	@Override
	protected String[] getReferenceProjectsNames() {
		return new String[] { HB_PROJECT_NAME_10_A, HB_PROJECT_NAME_10_B, HB_PROJECT_NAME_10_C, HB_PROJECT_NAME_10_D, HB_PROJECT_NAME_10_E,
				HB_PROJECT_NAME_10_F, HB_PROJECT_NAME_20_A, HB_PROJECT_NAME_20_B, HB_PROJECT_NAME_20_C, HB_PROJECT_NAME_20_D, HB_PROJECT_NAME_20_E,
				HB_PROJECT_NAME_20_WORKFLOWS };
				HB_PROJECT_NAME_20_F, HB_PROJECT_NAME_20_WORKFLOWS };
	}
}
 No newline at end of file