mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
Possibility to mark a file type as secondary so it's not returned by Language.getAssociatedFileType()
GitOrigin-RevId: 94fa97faccc17f778db16dda380cf029b71a175f
This commit is contained in:
committed by
intellij-monorepo-bot
parent
25db57876a
commit
9ceb6a8a88
@@ -161,13 +161,19 @@ public abstract class Language extends UserDataHolderBase {
|
||||
@ApiStatus.Internal
|
||||
public LanguageFileType findMyFileType(FileType[] types) {
|
||||
for (final FileType fileType : types) {
|
||||
if (fileType instanceof LanguageFileType && ((LanguageFileType)fileType).getLanguage() == this) {
|
||||
return (LanguageFileType)fileType;
|
||||
if (fileType instanceof LanguageFileType) {
|
||||
final LanguageFileType languageFileType = (LanguageFileType)fileType;
|
||||
if (languageFileType.getLanguage() == this && !languageFileType.isSecondary()) {
|
||||
return languageFileType;
|
||||
}
|
||||
}
|
||||
}
|
||||
for (final FileType fileType : types) {
|
||||
if (fileType instanceof LanguageFileType && isKindOf(((LanguageFileType)fileType).getLanguage())) {
|
||||
return (LanguageFileType)fileType;
|
||||
if (fileType instanceof LanguageFileType) {
|
||||
final LanguageFileType languageFileType = (LanguageFileType)fileType;
|
||||
if (isKindOf(languageFileType.getLanguage()) && !languageFileType.isSecondary()) {
|
||||
return languageFileType;
|
||||
}
|
||||
}
|
||||
}
|
||||
return null;
|
||||
|
||||
@@ -29,13 +29,25 @@ import java.nio.charset.Charset;
|
||||
*/
|
||||
public abstract class LanguageFileType implements FileType{
|
||||
private final Language myLanguage;
|
||||
private final boolean mySecondary;
|
||||
|
||||
/**
|
||||
* Creates a language file type for the specified language.
|
||||
* @param language The language used in the files of the type.
|
||||
*/
|
||||
protected LanguageFileType(@NotNull final Language language) {
|
||||
this(language, false);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a language file type for the specified language.
|
||||
* @param language The language used in the files of the type.
|
||||
* @param secondary If true, this language file type will never be returned as the associated file type for the language.
|
||||
* (Used when a file type is reusing the language of another file type, e.g. XML).
|
||||
*/
|
||||
protected LanguageFileType(@NotNull final Language language, boolean secondary) {
|
||||
myLanguage = language;
|
||||
mySecondary = secondary;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -57,6 +69,10 @@ public abstract class LanguageFileType implements FileType{
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean isSecondary() {
|
||||
return mySecondary;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getCharset(@NotNull VirtualFile file, @NotNull final byte[] content) {
|
||||
return null;
|
||||
|
||||
@@ -63,8 +63,8 @@ public class FileTypeBean extends AbstractExtensionPointBean {
|
||||
public String fileNamesCaseInsensitive;
|
||||
|
||||
/**
|
||||
* For file types that extend {@link LanguageFileType}, this must be set to the ID of the language
|
||||
* returned by {@link LanguageFileType#getLanguage()}.
|
||||
* For file types that extend {@link LanguageFileType} and are the primary file type for the corresponding language, this must be set
|
||||
* to the ID of the language returned by {@link LanguageFileType#getLanguage()}
|
||||
*/
|
||||
@Attribute("language")
|
||||
public String language;
|
||||
|
||||
@@ -21,7 +21,7 @@
|
||||
extensions="py;pyw;"
|
||||
implementationClass="com.jetbrains.python.PythonFileType"
|
||||
fieldName="INSTANCE"/>
|
||||
<fileType name="Qt UI file" language="XML" extensions="ui" implementationClass="com.jetbrains.pyqt.QtUIFileType" fieldName="INSTANCE"/>
|
||||
<fileType name="Qt UI file" extensions="ui" implementationClass="com.jetbrains.pyqt.QtUIFileType" fieldName="INSTANCE"/>
|
||||
<fileType name="XML" language="XML" extensions="qrc"/>
|
||||
<fileTypeDetector implementation="com.jetbrains.python.PyFileTypeDetector"/>
|
||||
<editorHighlighterProvider filetype="Python" implementationClass="com.jetbrains.python.PyEditorHighlighterProvider"/>
|
||||
|
||||
@@ -32,7 +32,7 @@ public abstract class QtFileType extends LanguageFileType implements INativeFile
|
||||
private final String myDefaultExtension;
|
||||
|
||||
QtFileType(String name, String description, String defaultExtension) {
|
||||
super(XMLLanguage.INSTANCE);
|
||||
super(XMLLanguage.INSTANCE, true);
|
||||
myName = name;
|
||||
myDescription = description;
|
||||
myDefaultExtension = defaultExtension;
|
||||
|
||||
Reference in New Issue
Block a user