Skip to content

Commit 9b1f3c0

Browse files
janjukzi
authored andcommitted
Add methods with case sensitivity flag and deprecate current methods
1 parent 31e1ef4 commit 9b1f3c0

File tree

6 files changed

+145
-54
lines changed

6 files changed

+145
-54
lines changed

runtime/bundles/org.eclipse.core.contenttype/META-INF/MANIFEST.MF

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ Manifest-Version: 1.0
22
Bundle-ManifestVersion: 2
33
Bundle-Name: %pluginName
44
Bundle-SymbolicName: org.eclipse.core.contenttype; singleton:=true
5-
Bundle-Version: 3.9.300.qualifier
5+
Bundle-Version: 3.10.0.qualifier
66
Bundle-Vendor: %providerName
77
Bundle-Localization: plugin
88
Require-Bundle: org.eclipse.equinox.preferences;bundle-version="[3.2.0,4.0.0)",

runtime/bundles/org.eclipse.core.contenttype/src/org/eclipse/core/internal/content/ContentType.java

Lines changed: 41 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,26 @@
1313
*******************************************************************************/
1414
package org.eclipse.core.internal.content;
1515

16-
import java.io.*;
17-
import java.util.*;
16+
import java.io.IOException;
17+
import java.io.InputStream;
18+
import java.io.Reader;
19+
import java.util.ArrayList;
20+
import java.util.Iterator;
21+
import java.util.List;
22+
import java.util.Map;
1823
import org.eclipse.core.internal.runtime.RuntimeLog;
19-
import org.eclipse.core.runtime.*;
20-
import org.eclipse.core.runtime.content.*;
24+
import org.eclipse.core.runtime.Assert;
25+
import org.eclipse.core.runtime.CoreException;
26+
import org.eclipse.core.runtime.IConfigurationElement;
27+
import org.eclipse.core.runtime.IStatus;
28+
import org.eclipse.core.runtime.InvalidRegistryObjectException;
29+
import org.eclipse.core.runtime.QualifiedName;
30+
import org.eclipse.core.runtime.Status;
31+
import org.eclipse.core.runtime.content.IContentDescriber;
32+
import org.eclipse.core.runtime.content.IContentDescription;
33+
import org.eclipse.core.runtime.content.IContentType;
34+
import org.eclipse.core.runtime.content.IContentTypeSettings;
35+
import org.eclipse.core.runtime.content.ITextContentDescriber;
2136
import org.eclipse.core.runtime.preferences.IScopeContext;
2237
import org.eclipse.osgi.util.NLS;
2338
import org.osgi.service.prefs.BackingStoreException;
@@ -377,15 +392,15 @@ boolean hasBuiltInAssociations() {
377392
return builtInAssociations;
378393
}
379394

380-
boolean hasFileSpec(IScopeContext context, String text, int typeMask) {
395+
boolean hasFileSpec(IScopeContext context, String text, int typeMask, boolean caseStrict) {
381396
if (context.equals(manager.getContext()) || (typeMask & IGNORE_USER_DEFINED) != 0)
382-
return hasFileSpec(text, typeMask, false);
397+
return hasFileSpec(text, typeMask, false, caseStrict);
383398
String[] fileSpecs = ContentTypeSettings.getFileSpecs(context, id, typeMask);
384399
for (String fileSpec : fileSpecs)
385400
if (text.equalsIgnoreCase(fileSpec))
386401
return true;
387402
// no user defined association... try built-in
388-
return hasFileSpec(text, typeMask | IGNORE_PRE_DEFINED, false);
403+
return hasFileSpec(text, typeMask | IGNORE_PRE_DEFINED, false, caseStrict);
389404
}
390405

391406
/**
@@ -397,11 +412,11 @@ boolean hasFileSpec(IScopeContext context, String text, int typeMask) {
397412
* FILE_NAME_SPEC or FILE_EXTENSION_SPEC or FILE_REGEXP_SPEC
398413
* @return true if this file spec has already been added, false otherwise
399414
*/
400-
boolean hasFileSpec(String text, int typeMask, boolean strict) {
415+
boolean hasFileSpec(String text, int typeMask, boolean typeStrict, boolean caseStrict) {
401416
if (fileSpecs.isEmpty())
402417
return false;
403418
for (FileSpec spec : fileSpecs) {
404-
if (spec.equals(text, typeMask, strict))
419+
if (spec.equals(text, typeMask, typeStrict, caseStrict))
405420
return true;
406421
}
407422
return false;
@@ -416,7 +431,7 @@ public int hashCode() {
416431
* Adds a user-defined or pre-defined file spec.
417432
*/
418433
boolean internalAddFileSpec(String fileSpec, int typeMask) {
419-
if (hasFileSpec(fileSpec, typeMask, false))
434+
if (hasFileSpec(fileSpec, typeMask, false, true))
420435
return false;
421436
FileSpec newFileSpec = createFileSpec(fileSpec, typeMask);
422437
if ((typeMask & ContentType.SPEC_USER_DEFINED) == 0) {
@@ -480,15 +495,15 @@ BasicDescription internalGetDescriptionFor(ILazySource buffer, QualifiedName[] o
480495
return description;
481496
}
482497

483-
byte internalIsAssociatedWith(String fileName, IScopeContext context) {
484-
if (hasFileSpec(context, fileName, FILE_NAME_SPEC))
498+
byte internalIsAssociatedWith(String fileName, boolean caseStrict, IScopeContext context) {
499+
if (hasFileSpec(context, fileName, FILE_NAME_SPEC, caseStrict))
485500
return ASSOCIATED_BY_NAME;
486501
String fileExtension = ContentTypeManager.getFileExtension(fileName);
487-
if (hasFileSpec(context, fileExtension, FILE_EXTENSION_SPEC))
502+
if (hasFileSpec(context, fileExtension, FILE_EXTENSION_SPEC, caseStrict))
488503
return ASSOCIATED_BY_EXTENSION;
489504
// if does not have built-in file specs, delegate to parent (if any)
490505
if (!hasBuiltInAssociations() && baseType != null)
491-
return baseType.internalIsAssociatedWith(fileName, context);
506+
return baseType.internalIsAssociatedWith(fileName, caseStrict, context);
492507
return NOT_ASSOCIATED;
493508
}
494509

@@ -523,12 +538,22 @@ boolean isAlias() {
523538

524539
@Override
525540
public boolean isAssociatedWith(String fileName) {
526-
return isAssociatedWith(fileName, manager.getContext());
541+
return isAssociatedWith(fileName, false, manager.getContext());
542+
}
543+
544+
@Override
545+
public boolean isAssociatedWith(String fileName, boolean caseStrict) {
546+
return isAssociatedWith(fileName, caseStrict, manager.getContext());
527547
}
528548

529549
@Override
530550
public boolean isAssociatedWith(String fileName, IScopeContext context) {
531-
return internalIsAssociatedWith(fileName, context) != NOT_ASSOCIATED;
551+
return internalIsAssociatedWith(fileName, false, context) != NOT_ASSOCIATED;
552+
}
553+
554+
@Override
555+
public boolean isAssociatedWith(String fileName, boolean caseStrict, IScopeContext context) {
556+
return internalIsAssociatedWith(fileName, caseStrict, context) != NOT_ASSOCIATED;
532557
}
533558

534559
@Override

runtime/bundles/org.eclipse.core.contenttype/src/org/eclipse/core/internal/content/ContentTypeCatalog.java

Lines changed: 37 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,35 @@
1414
*******************************************************************************/
1515
package org.eclipse.core.internal.content;
1616

17-
import java.io.*;
18-
import java.util.*;
17+
import java.io.IOException;
18+
import java.io.InputStream;
19+
import java.io.Reader;
20+
import java.util.ArrayList;
21+
import java.util.Arrays;
22+
import java.util.Collection;
23+
import java.util.Collections;
24+
import java.util.Comparator;
25+
import java.util.HashMap;
26+
import java.util.HashSet;
27+
import java.util.Iterator;
28+
import java.util.List;
29+
import java.util.Map;
1930
import java.util.Map.Entry;
31+
import java.util.Set;
2032
import java.util.regex.Pattern;
21-
import org.eclipse.core.runtime.*;
22-
import org.eclipse.core.runtime.content.*;
33+
import org.eclipse.core.runtime.CoreException;
34+
import org.eclipse.core.runtime.ISafeRunnable;
35+
import org.eclipse.core.runtime.QualifiedName;
36+
import org.eclipse.core.runtime.SafeRunner;
37+
import org.eclipse.core.runtime.content.IContentDescriber;
38+
import org.eclipse.core.runtime.content.IContentDescription;
39+
import org.eclipse.core.runtime.content.IContentType;
40+
import org.eclipse.core.runtime.content.IContentTypeManager;
2341
import org.eclipse.core.runtime.content.IContentTypeManager.ISelectionPolicy;
42+
import org.eclipse.core.runtime.content.IContentTypeSettings;
43+
import org.eclipse.core.runtime.content.ITextContentDescriber;
44+
import org.eclipse.core.runtime.content.XMLRootElementContentDescriber;
45+
import org.eclipse.core.runtime.content.XMLRootElementContentDescriber2;
2446
import org.eclipse.core.runtime.preferences.IScopeContext;
2547
import org.eclipse.osgi.util.NLS;
2648

@@ -652,7 +674,7 @@ private Set<ContentType> filterOnDefinitionSource(String text, int typeMask, Set
652674
typeMask ^= (IContentType.IGNORE_PRE_DEFINED | IContentType.IGNORE_USER_DEFINED);
653675
for (Iterator<ContentType> i = contentTypes.iterator(); i.hasNext();) {
654676
ContentType contentType = i.next();
655-
if (!contentType.hasFileSpec(text, typeMask, true))
677+
if (!contentType.hasFileSpec(text, typeMask, true, false))
656678
i.remove();
657679
}
658680
}
@@ -708,21 +730,16 @@ private Set<ContentType> selectMatchingByName(final IScopeContext context, Colle
708730
for (ContentType root : source) {
709731
// From a given content type, check if it matches, and
710732
// include any children that match as well.
711-
internalAccept(new ContentTypeVisitor() {
712-
@Override
713-
public int visit(ContentType type) {
714-
if (type != root && type.hasBuiltInAssociations())
715-
// this content type has built-in associations - visit it later as root
716-
return RETURN;
717-
if (type == root && !type.hasFileSpec(context, fileSpecText, fileSpecType))
718-
// it is the root and does not match the file name - do not add it nor look into its children
719-
return RETURN;
720-
// either the content type is the root and matches the file name or
721-
// is a sub content type and does not have built-in files specs
722-
if (!existing.contains(type))
723-
destination.add(type);
724-
return CONTINUE;
725-
}
733+
internalAccept(type -> {
734+
if ((type != root && type.hasBuiltInAssociations())
735+
|| (type == root && !type.hasFileSpec(context, fileSpecText, fileSpecType, false)))
736+
// it is the root and does not match the file name - do not add it nor look into its children
737+
return ContentTypeVisitor.RETURN;
738+
// either the content type is the root and matches the file name or
739+
// is a sub content type and does not have built-in files specs
740+
if (!existing.contains(type))
741+
destination.add(type);
742+
return ContentTypeVisitor.CONTINUE;
726743
}, root);
727744
}
728745
return destination;

runtime/bundles/org.eclipse.core.contenttype/src/org/eclipse/core/internal/content/ContentTypeHandler.java

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,15 @@
1313
*******************************************************************************/
1414
package org.eclipse.core.internal.content;
1515

16-
import java.io.*;
16+
import java.io.IOException;
17+
import java.io.InputStream;
18+
import java.io.Reader;
1719
import java.lang.ref.SoftReference;
1820
import org.eclipse.core.runtime.CoreException;
1921
import org.eclipse.core.runtime.QualifiedName;
20-
import org.eclipse.core.runtime.content.*;
22+
import org.eclipse.core.runtime.content.IContentDescription;
23+
import org.eclipse.core.runtime.content.IContentType;
24+
import org.eclipse.core.runtime.content.IContentTypeSettings;
2125
import org.eclipse.core.runtime.preferences.IScopeContext;
2226

2327
/**
@@ -169,13 +173,25 @@ public int hashCode() {
169173
@Override
170174
public boolean isAssociatedWith(String fileName) {
171175
final IContentType target = getTarget();
172-
return (target != null) ? target.isAssociatedWith(fileName) : false;
176+
return (target != null) ? target.isAssociatedWith(fileName, false) : false;
173177
}
174178

175179
@Override
176180
public boolean isAssociatedWith(String fileName, IScopeContext context) {
177181
final IContentType target = getTarget();
178-
return (target != null) ? target.isAssociatedWith(fileName, context) : false;
182+
return (target != null) ? target.isAssociatedWith(fileName, false, context) : false;
183+
}
184+
185+
@Override
186+
public boolean isAssociatedWith(String fileName, boolean caseStrict) {
187+
final IContentType target = getTarget();
188+
return (target != null) ? target.isAssociatedWith(fileName, caseStrict) : false;
189+
}
190+
191+
@Override
192+
public boolean isAssociatedWith(String fileName, boolean caseStrict, IScopeContext context) {
193+
final IContentType target = getTarget();
194+
return (target != null) ? target.isAssociatedWith(fileName, caseStrict, context) : false;
179195
}
180196

181197
@Override

runtime/bundles/org.eclipse.core.contenttype/src/org/eclipse/core/internal/content/FileSpec.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,11 +46,12 @@ public boolean equals(Object other) {
4646
if (!(other instanceof FileSpec))
4747
return false;
4848
FileSpec otherFileSpec = (FileSpec) other;
49-
return equals(text, otherFileSpec.getType(), false);
49+
return equals(text, otherFileSpec.getType(), false, false);
5050
}
5151

52-
public boolean equals(final String text, final int otherType, final boolean strict) {
53-
return ((!strict && getBasicType(type) == getBasicType(otherType)) || type == otherType) && this.text.equalsIgnoreCase(text);
52+
public boolean equals(final String text, final int otherType, final boolean typeStrict, final boolean caseStrict) {
53+
boolean textMatch = caseStrict ? this.text.equals(text) : this.text.equalsIgnoreCase(text);
54+
return ((!typeStrict && getBasicType(type) == getBasicType(otherType)) || type == otherType) && textMatch;
5455
}
5556

5657
@Override

runtime/bundles/org.eclipse.core.contenttype/src/org/eclipse/core/runtime/content/IContentType.java

Lines changed: 42 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,9 @@
1313
*******************************************************************************/
1414
package org.eclipse.core.runtime.content;
1515

16-
import java.io.*;
16+
import java.io.IOException;
17+
import java.io.InputStream;
18+
import java.io.Reader;
1719
import org.eclipse.core.runtime.CoreException;
1820
import org.eclipse.core.runtime.QualifiedName;
1921
import org.eclipse.core.runtime.preferences.IScopeContext;
@@ -167,26 +169,56 @@ public interface IContentType extends IContentTypeSettings {
167169
String getName();
168170

169171
/**
170-
* Returns whether this content type is associated with the
171-
* given file name.
172+
* Returns whether this content type is associated with the given file name. The
173+
* association is done ignoring case "c"=="C"
172174
*
173175
* @param fileName the file name
174-
* @return <code>true</code> if this content type is associated with
175-
* the given file name, <code>false</code> otherwise
176+
* @return <code>true</code> if this content type is associated with the given
177+
* file name, <code>false</code> otherwise
176178
* @see #isAssociatedWith(String, IScopeContext)
177179
*/
180+
@Deprecated
178181
boolean isAssociatedWith(String fileName);
179182

180183
/**
181-
* Returns whether this content type is associated with the
182-
* given file name in the given preference scope.
184+
* Returns whether this content type is associated with the given file name.
185+
*
186+
* @param fileName the file name
187+
* @param caseStrict if true the string comparison is case sensitive else the
188+
* comparison is ignoring case
189+
*
190+
* @return <code>true</code> if this content type is associated with the given
191+
* file name, <code>false</code> otherwise
192+
* @see #isAssociatedWith(String, IScopeContext)
193+
* @since 3.10
194+
*/
195+
boolean isAssociatedWith(String fileName, boolean caseStrict);
196+
197+
/**
198+
* Returns whether this content type is associated with the given file name in
199+
* the given preference scope.
200+
*
201+
* @param fileName the file name
202+
* @param caseStrict if true the string comparison is case sensitive else the
203+
* comparison is ignoring case
204+
* @param context a preference scope context
205+
* @return <code>true</code> if this content type is associated with the given
206+
* file name, <code>false</code> otherwise
207+
* @since 3.10
208+
*/
209+
boolean isAssociatedWith(String fileName, boolean caseStrict, IScopeContext context);
210+
211+
/**
212+
* Returns whether this content type is associated with the given file name in
213+
* the given preference scope. The association is done ignoring case "c"=="C"
183214
*
184215
* @param fileName the file name
185-
* @param context a preference scope context
186-
* @return <code>true</code> if this content type is associated with
187-
* the given file name, <code>false</code> otherwise
216+
* @param context a preference scope context
217+
* @return <code>true</code> if this content type is associated with the given
218+
* file name, <code>false</code> otherwise
188219
* @since 3.1
189220
*/
221+
@Deprecated
190222
boolean isAssociatedWith(String fileName, IScopeContext context);
191223

192224
/**

0 commit comments

Comments
 (0)