From b96a47cd24e388e75cc4686a8f615172c81f9926 Mon Sep 17 00:00:00 2001 From: Alexey Kudravtsev Date: Thu, 27 Jun 2024 17:45:27 +0200 Subject: [PATCH] cleanup: simplify FileTypeWithDescriptor GitOrigin-RevId: 736c0497f7755f6e6256a2af3dd60b3bcbf22d7e --- .../fileTypes/impl/FileTypeConfigurable.java | 43 +++---- .../ConflictingFileTypeMappingTracker.java | 38 +++--- .../impl/FileTypeDetectionService.java | 2 +- .../fileTypes/impl/FileTypeManagerImpl.java | 108 +++++++++--------- .../ConflictFileTypeMappingTrackerTest.java | 2 +- .../openapi/fileTypes/impl/FileTypesTest.java | 10 +- 6 files changed, 101 insertions(+), 102 deletions(-) diff --git a/platform/lang-impl/src/com/intellij/openapi/fileTypes/impl/FileTypeConfigurable.java b/platform/lang-impl/src/com/intellij/openapi/fileTypes/impl/FileTypeConfigurable.java index 0e1d27a6f0b6..1be7ccfa0a4d 100644 --- a/platform/lang-impl/src/com/intellij/openapi/fileTypes/impl/FileTypeConfigurable.java +++ b/platform/lang-impl/src/com/intellij/openapi/fileTypes/impl/FileTypeConfigurable.java @@ -148,8 +148,9 @@ public final class FileTypeConfigurable implements SearchableConfigurable, Confi } private void updateFileTypeList() { - List types = ContainerUtil.sorted(ContainerUtil.filter(myTempFileTypes, ftd -> !ftd.fileType.isReadOnly()), - (o1, o2) -> o1.fileType.getDescription().compareToIgnoreCase(o2.fileType.getDescription())); + List types = ContainerUtil.sorted(ContainerUtil.filter(myTempFileTypes, ftd -> !ftd.fileType() + .isReadOnly()), + (o1, o2) -> o1.fileType().getDescription().compareToIgnoreCase(o2.fileType().getDescription())); myRecognizedFileType.setFileTypes(types); } @@ -197,7 +198,7 @@ public final class FileTypeConfigurable implements SearchableConfigurable, Confi myRecognizedFileType.selectFileType(myFileTypeToPreselect); } else if (lastSelectedFileType != null) { - myRecognizedFileType.selectFileType(lastSelectedFileType.fileType); + myRecognizedFileType.selectFileType(lastSelectedFileType.fileType()); } } @@ -262,9 +263,9 @@ public final class FileTypeConfigurable implements SearchableConfigurable, Confi private void editFileType() { FileTypeManagerImpl.FileTypeWithDescriptor ftd = myRecognizedFileType.getSelectedFileType(); - if (ftd==null||!canBeModified(ftd.fileType)) return; + if (ftd==null||!canBeModified(ftd.fileType())) return; - UserFileType userFileType = (UserFileType)ftd.fileType; + UserFileType userFileType = (UserFileType)ftd.fileType(); UserFileType ftToEdit = myOriginalToEditedMap.get(userFileType); if (ftToEdit == null) ftToEdit = userFileType.clone(); TypeEditor editor = new TypeEditor(myRecognizedFileType.myFileTypesList, ftToEdit, FileTypesBundle.message("filetype.edit.existing.title")); @@ -282,7 +283,7 @@ public final class FileTypeConfigurable implements SearchableConfigurable, Confi private void removeFileType() { FileTypeManagerImpl.FileTypeWithDescriptor ftd = myRecognizedFileType.getSelectedFileType(); if (ftd == null) return; - FileType fileType = ftd.fileType; + FileType fileType = ftd.fileType(); FileTypeConfigurableInteractions.fileTypeRemoved.log(); int index = myRecognizedFileType.myFileTypesList.getSelectedIndex(); @@ -329,7 +330,7 @@ public final class FileTypeConfigurable implements SearchableConfigurable, Confi private void editPattern(@Nullable("null means new") Pair item) { FileTypeManagerImpl.FileTypeWithDescriptor ftd = myRecognizedFileType.getSelectedFileType(); if (ftd == null) return; - FileType type = ftd.fileType; + FileType type = ftd.fileType(); if (item == null) { FileTypeConfigurableInteractions.patternAdded.log(type); @@ -354,8 +355,8 @@ public final class FileTypeConfigurable implements SearchableConfigurable, Confi FileNameMatcher matcher = FileTypeManager.parseFromString(pattern); FileTypeManagerImpl.FileTypeWithDescriptor registeredFtd = findExistingFileType(matcher); - if (registeredFtd != null && registeredFtd.fileType != type) { - FileType registeredFileType = registeredFtd.fileType; + if (registeredFtd != null && registeredFtd.fileType() != type) { + FileType registeredFileType = registeredFtd.fileType(); if (registeredFileType.isReadOnly()) { Messages.showMessageDialog(myPatterns.myList, FileTypesBundle.message("filetype.edit.add.pattern.exists.error", registeredFileType.getDescription()), @@ -398,11 +399,11 @@ public final class FileTypeConfigurable implements SearchableConfigurable, Confi private @Nullable FileTypeManagerImpl.FileTypeWithDescriptor findExistingFileType(@NotNull FileNameMatcher matcher) { FileTypeManagerImpl.@Nullable FileTypeWithDescriptor ftd = myTempPatternsTable.findAssociatedFileType(matcher); - if (ftd != null && ftd.fileType != FileTypes.UNKNOWN) { + if (ftd != null && ftd.fileType() != FileTypes.UNKNOWN) { return ftd; } FileTypeManagerImpl.@NotNull FileTypeWithDescriptor registeredFtd = myFileTypeManager.getFileTypeWithDescriptorByExtension(matcher.getPresentableString()); - if (registeredFtd.fileType != FileTypes.UNKNOWN && registeredFtd.fileType.isReadOnly()) { + if (registeredFtd.fileType() != FileTypes.UNKNOWN && registeredFtd.fileType().isReadOnly()) { return registeredFtd; } return null; @@ -411,7 +412,7 @@ public final class FileTypeConfigurable implements SearchableConfigurable, Confi private void removePattern() { FileTypeManagerImpl.FileTypeWithDescriptor ftd = myRecognizedFileType.getSelectedFileType(); if (ftd == null) return; - FileTypeConfigurableInteractions.patternRemoved.log(ftd.fileType); + FileTypeConfigurableInteractions.patternRemoved.log(ftd.fileType()); Pair removed = myPatterns.removeSelected(); if (removed == null) return; @@ -423,7 +424,7 @@ public final class FileTypeConfigurable implements SearchableConfigurable, Confi private void removeHashBang() { FileTypeManagerImpl.FileTypeWithDescriptor ftd = myRecognizedFileType.getSelectedFileType(); if (ftd == null) return; - FileTypeConfigurableInteractions.hashbangRemoved.log(ftd.fileType); + FileTypeConfigurableInteractions.hashbangRemoved.log(ftd.fileType()); String extension = myHashBangs.removeSelected(); if (extension == null) return; @@ -445,7 +446,7 @@ public final class FileTypeConfigurable implements SearchableConfigurable, Confi myFileTypesList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); myCellRenderer = new FileTypeWithDescriptorRenderer<>(myFileTypesList.getModel(), ftd -> { - FileType fileType = ftd.fileType; + FileType fileType = ftd.fileType(); UserFileType modified = myOriginalToEditedMap.get(fileType); return modified != null ? modified : fileType; }); @@ -481,7 +482,7 @@ public final class FileTypeConfigurable implements SearchableConfigurable, Confi private boolean selectedTypeCanBeModified() { FileTypeManagerImpl.FileTypeWithDescriptor ftd = getSelectedFileType(); if (ftd == null) return false; - return canBeModified(ftd.fileType); + return canBeModified(ftd.fileType()); } private final class MySpeedSearch extends SpeedSearchBase> { @@ -496,7 +497,7 @@ public final class FileTypeConfigurable implements SearchableConfigurable, Confi p -> { String value = p.first.toString(); if (p.first instanceof FileTypeManagerImpl.FileTypeWithDescriptor) { - value = ((FileTypeManagerImpl.FileTypeWithDescriptor)p.first).fileType.getDescription(); + value = ((FileTypeManagerImpl.FileTypeWithDescriptor)p.first).fileType().getDescription(); } return getComparator().matchingFragments(p.second, value) != null; }, @@ -571,7 +572,7 @@ public final class FileTypeConfigurable implements SearchableConfigurable, Confi DefaultListModel listModel = (DefaultListModel)myFileTypesList.getModel(); listModel.clear(); for (FileTypeManagerImpl.FileTypeWithDescriptor type : types) { - if (type.fileType != FileTypes.UNKNOWN) { + if (type.fileType() != FileTypes.UNKNOWN) { listModel.addElement(type); } } @@ -725,7 +726,7 @@ public final class FileTypeConfigurable implements SearchableConfigurable, Confi private void editHashBang(@Nullable("null means new") String oldHashBang) { FileTypeManagerImpl.FileTypeWithDescriptor ftd = myRecognizedFileType.getSelectedFileType(); if (ftd == null) return; - FileType type = ftd.fileType; + FileType type = ftd.fileType(); if (oldHashBang == null) { FileTypeConfigurableInteractions.hashbangAdded.log(type); @@ -741,9 +742,9 @@ public final class FileTypeConfigurable implements SearchableConfigurable, Confi return; //canceled or empty } HashBangConflict conflict = checkHashBangConflict(hashbang); - if (conflict != null && conflict.fileType.fileType != type) { + if (conflict != null && conflict.fileType.fileType() != type) { FileTypeManagerImpl.FileTypeWithDescriptor existingFtd = conflict.fileType; - FileType existingFileType = existingFtd.fileType; + FileType existingFileType = existingFtd.fileType(); if (!conflict.writeable) { String message = conflict.exact ? FileTypesBundle.message("filetype.edit.hashbang.exists.exact.error", existingFileType.getDescription()) @@ -797,7 +798,7 @@ public final class FileTypeConfigurable implements SearchableConfigurable, Confi if (hashbang.contains(existingHashBang) || existingHashBang.contains(hashbang)) { FileTypeManagerImpl.FileTypeWithDescriptor ftd = entry.getValue(); boolean exact = existingHashBang.equals(hashbang); - boolean writeable = !ftd.fileType.isReadOnly() && !isStandardFileType(ftd.fileType); + boolean writeable = !ftd.fileType().isReadOnly() && !isStandardFileType(ftd.fileType()); return new HashBangConflict(ftd, exact, writeable, existingHashBang); } } diff --git a/platform/platform-impl/src/com/intellij/openapi/fileTypes/impl/ConflictingFileTypeMappingTracker.java b/platform/platform-impl/src/com/intellij/openapi/fileTypes/impl/ConflictingFileTypeMappingTracker.java index 1cf07410cf7a..a97607ecc2f0 100644 --- a/platform/platform-impl/src/com/intellij/openapi/fileTypes/impl/ConflictingFileTypeMappingTracker.java +++ b/platform/platform-impl/src/com/intellij/openapi/fileTypes/impl/ConflictingFileTypeMappingTracker.java @@ -33,8 +33,8 @@ final class ConflictingFileTypeMappingTracker { ResolveConflictResult warnAndResolveConflict(@NotNull FileNameMatcher matcher, @Nullable FileTypeManagerImpl.FileTypeWithDescriptor oldFtd, @NotNull FileTypeManagerImpl.FileTypeWithDescriptor newFtd) { - FileType oldFileType = oldFtd == null ? null : oldFtd.fileType; - FileType newFileType = newFtd.fileType; + FileType oldFileType = oldFtd == null ? null : oldFtd.fileType(); + FileType newFileType = newFtd.fileType(); if (oldFileType == null || oldFileType.equals(newFileType) || oldFileType instanceof AbstractFileType) { // no conflict really return new ResolveConflictResult(ObjectUtils.notNull(oldFtd, newFtd), "", "", true); @@ -43,7 +43,7 @@ final class ConflictingFileTypeMappingTracker { ResolveConflictResult result = resolveConflict(matcher, oldFtd, newFtd); // notify about only real conflicts between two same-league plugins if (!result.approved) { - if (oldFtd.fileType.equals(newFileType)) { + if (oldFtd.fileType().equals(newFileType)) { throw new IllegalArgumentException("expected different file types but got "+result.resolved); } @@ -63,17 +63,17 @@ final class ConflictingFileTypeMappingTracker { @NotNull FileTypeManagerImpl.FileTypeWithDescriptor oldFtd, @NotNull FileTypeManagerImpl.FileTypeWithDescriptor newFtd) { assert !oldFtd.equals(newFtd) : oldFtd; - if (newFtd.pluginDescriptor.isBundled() && - (!oldFtd.pluginDescriptor.isBundled() || isCorePlugin(newFtd.pluginDescriptor) && !isCorePlugin(oldFtd.pluginDescriptor))) { + if (newFtd.pluginDescriptor().isBundled() && + (!oldFtd.pluginDescriptor().isBundled() || isCorePlugin(newFtd.pluginDescriptor()) && !isCorePlugin(oldFtd.pluginDescriptor()))) { FileTypeManagerImpl.FileTypeWithDescriptor ftd = newFtd; newFtd = oldFtd; oldFtd = ftd; } // now the bundled or core plugin, if any, is stored in oldFtd - PluginDescriptor oldPlugin = oldFtd.pluginDescriptor; - PluginDescriptor newPlugin = newFtd.pluginDescriptor; - FileType oldFileType = oldFtd.fileType; - FileType newFileType = newFtd.fileType; + PluginDescriptor oldPlugin = oldFtd.pluginDescriptor(); + PluginDescriptor newPlugin = newFtd.pluginDescriptor(); + FileType oldFileType = oldFtd.fileType(); + FileType newFileType = newFtd.fileType(); // do not show notification if the new plugin reassigned core or bundled plugin String oldPluginName = oldPlugin.isBundled() ? "bundled" : oldPlugin.getName(); String explanation = FileTypesBundle.message("notification.content.file.type.reassigned.explanation", matcher.getPresentableString()); @@ -96,7 +96,8 @@ final class ConflictingFileTypeMappingTracker { boolean isNewJetBrains = PluginManagerCore.isVendorJetBrains(StringUtil.notNullize(newPlugin.getVendor())); if (isOldJetBrains != isNewJetBrains) { FileTypeManagerImpl.FileTypeWithDescriptor result = isOldJetBrains ? newFtd : oldFtd; - String message = FileTypesBundle.message("notification.content.file.pattern.was.reassigned.to", matcher.getPresentableString(), result.fileType.getDisplayName()); + String message = FileTypesBundle.message("notification.content.file.pattern.was.reassigned.to", matcher.getPresentableString(), result.fileType() + .getDisplayName()); return new ResolveConflictResult(result, message, explanation, true); } @@ -124,9 +125,9 @@ final class ConflictingFileTypeMappingTracker { @NotNull FileNameMatcher matcher, @NotNull FileTypeManagerImpl.FileTypeWithDescriptor oldFtd, @NotNull ResolveConflictResult result) { - FileType resolvedFileType = result.resolved.fileType; + FileType resolvedFileType = result.resolved.fileType(); @Nls String notificationText = result.notification; - String oldDisplayName = oldFtd.fileType.getDisplayName(); + String oldDisplayName = oldFtd.fileType().getDisplayName(); String resolvedDisplayName = resolvedFileType.getDisplayName(); if (ApplicationManager.getApplication().isUnitTestMode()) { return; @@ -139,8 +140,9 @@ final class ConflictingFileTypeMappingTracker { result.explanation, NotificationType.INFORMATION); String message = - result.resolved.pluginDescriptor.isBundled() ? FileTypesBundle.message("notification.content.conflict.confirm.reassign", resolvedDisplayName) : - FileTypesBundle.message("notification.content.conflict.confirm.reassign.from.plugin", resolvedDisplayName, result.resolved.pluginDescriptor.getName()); + result.resolved.pluginDescriptor().isBundled() ? FileTypesBundle.message("notification.content.conflict.confirm.reassign", resolvedDisplayName) : + FileTypesBundle.message("notification.content.conflict.confirm.reassign.from.plugin", resolvedDisplayName, result.resolved.pluginDescriptor() + .getName()); notification.addAction(NotificationAction.createSimple(message, () -> { // mark as removed from fileTypeOld and associated with fileTypeNew ApplicationManager.getApplication().runWriteAction(() -> { @@ -152,8 +154,8 @@ final class ConflictingFileTypeMappingTracker { showReassignedInfoNotification(project, m); })); String revertMessage = - oldFtd.pluginDescriptor.isBundled() ? FileTypesBundle.message("notification.content.revert.reassign", oldDisplayName) : - FileTypesBundle.message("notification.content.revert.reassign.from.plugin", oldDisplayName, oldFtd.pluginDescriptor.getName()); + oldFtd.pluginDescriptor().isBundled() ? FileTypesBundle.message("notification.content.revert.reassign", oldDisplayName) : + FileTypesBundle.message("notification.content.revert.reassign.from.plugin", oldDisplayName, oldFtd.pluginDescriptor().getName()); notification.addAction(NotificationAction.createSimple(revertMessage, () -> { // mark as removed from fileTypeNew and associated with fileTypeOld ApplicationManager.getApplication().runWriteAction(() -> { @@ -164,9 +166,9 @@ final class ConflictingFileTypeMappingTracker { String m = FileTypesBundle.message("dialog.message.file.pattern.was.reassigned.back.to", matcher.getPresentableString(), oldDisplayName); showReassignedInfoNotification(project, m); })); - if (!oldFtd.fileType.isReadOnly()) { + if (!oldFtd.fileType().isReadOnly()) { notification.addAction(NotificationAction.createSimple(FileTypesBundle.message("notification.content.edit", oldDisplayName), - () -> editFileType(project, oldFtd.fileType))); + () -> editFileType(project, oldFtd.fileType()))); } if (!resolvedFileType.isReadOnly()) { notification.addAction(NotificationAction.createSimple(FileTypesBundle.message("notification.content.edit", resolvedDisplayName), diff --git a/platform/platform-impl/src/com/intellij/openapi/fileTypes/impl/FileTypeDetectionService.java b/platform/platform-impl/src/com/intellij/openapi/fileTypes/impl/FileTypeDetectionService.java index a617cbdedd42..7c3ce3814b56 100644 --- a/platform/platform-impl/src/com/intellij/openapi/fileTypes/impl/FileTypeDetectionService.java +++ b/platform/platform-impl/src/com/intellij/openapi/fileTypes/impl/FileTypeDetectionService.java @@ -572,7 +572,7 @@ final class FileTypeDetectionService implements Disposable { if (detected == null && !StringUtil.isEmpty(text)) { FileTypeManagerImpl.FileTypeWithDescriptor ftd = myFileTypeManager.patternsTable.findAssociatedFileTypeByHashBang(text); - detected = ftd == null ? null : ftd.fileType; + detected = ftd == null ? null : ftd.fileType(); } if (detected == null) { detected = StringUtil.isEmpty(text) ? (bytes.getLength() == 0 ? DetectedByContentFileType.INSTANCE : UnknownFileType.INSTANCE): PlainTextFileType.INSTANCE; diff --git a/platform/platform-impl/src/com/intellij/openapi/fileTypes/impl/FileTypeManagerImpl.java b/platform/platform-impl/src/com/intellij/openapi/fileTypes/impl/FileTypeManagerImpl.java index a91a0a6eb71e..108a40ba03da 100644 --- a/platform/platform-impl/src/com/intellij/openapi/fileTypes/impl/FileTypeManagerImpl.java +++ b/platform/platform-impl/src/com/intellij/openapi/fileTypes/impl/FileTypeManagerImpl.java @@ -156,20 +156,20 @@ public class FileTypeManagerImpl extends FileTypeManagerEx implements Persistent @Override public @NotNull SchemeState getState(@NotNull FileTypeWithDescriptor ftd) { - if (!(ftd.fileType instanceof AbstractFileType) || !shouldSave(ftd.fileType)) { + if (!(ftd.fileType() instanceof AbstractFileType) || !shouldSave(ftd.fileType())) { return SchemeState.NON_PERSISTENT; } if (!defaultTypes.contains(ftd)) { return SchemeState.POSSIBLY_CHANGED; } - return ((AbstractFileType)ftd.fileType).isModified() ? SchemeState.POSSIBLY_CHANGED : SchemeState.NON_PERSISTENT; + return ((AbstractFileType)ftd.fileType()).isModified() ? SchemeState.POSSIBLY_CHANGED : SchemeState.NON_PERSISTENT; } @Override public @NotNull Element writeScheme(@NotNull FileTypeWithDescriptor ftd) { Element root = new Element(ELEMENT_FILETYPE); - AbstractFileType fileType = (AbstractFileType)ftd.fileType; + AbstractFileType fileType = (AbstractFileType)ftd.fileType(); root.setAttribute("binary", String.valueOf(fileType.isBinary())); if (!Strings.isEmpty(fileType.getDefaultExtension())) { root.setAttribute("default_extension", fileType.getDefaultExtension()); @@ -193,7 +193,7 @@ public class FileTypeManagerImpl extends FileTypeManagerEx implements Persistent Application app = ApplicationManager.getApplication(); app.runWriteAction(() -> fireBeforeFileTypesChanged()); patternsTable.removeAllAssociations(scheme); - app.runWriteAction(() -> fireFileTypesChanged(null, scheme.fileType)); + app.runWriteAction(() -> fireFileTypesChanged(null, scheme.fileType())); }); } }; @@ -246,31 +246,26 @@ public class FileTypeManagerImpl extends FileTypeManagerEx implements Persistent } } - static final class FileTypeWithDescriptor implements Scheme { + record FileTypeWithDescriptor(@NotNull FileType fileType, @NotNull PluginDescriptor pluginDescriptor) implements Scheme { private static final PluginDescriptor WILD_CARD = new DefaultPluginDescriptor("WILD_CARD"); - final @NotNull FileType fileType; - final @NotNull PluginDescriptor pluginDescriptor; - - FileTypeWithDescriptor(@NotNull FileType fileType, @NotNull PluginDescriptor pluginDescriptor) { - this.fileType = fileType; - this.pluginDescriptor = pluginDescriptor; - } - @Override public boolean equals(Object o) { - return this == o || o != null && getClass() == o.getClass() && fileType.equals(((FileTypeWithDescriptor)o).fileType); + return this == o || o != null && getClass() == o.getClass() && fileType().equals(((FileTypeWithDescriptor)o).fileType()); } @Override public int hashCode() { - return fileType.hashCode(); + return fileType().hashCode(); } @Override public String toString() { - return fileType + " from '" + (pluginDescriptor==WILD_CARD ? "*" : PluginManagerCore.CORE_ID.equals(pluginDescriptor.getPluginId()) - ? "CORE" : pluginDescriptor) + "'"; + return fileType() + + " from '" + + (pluginDescriptor() == WILD_CARD ? "*" : PluginManagerCore.CORE_ID.equals(pluginDescriptor().getPluginId()) + ? "CORE" : pluginDescriptor()) + + "'"; } // equals to all FileTypeWithDescriptor with this fileType @@ -280,7 +275,7 @@ public class FileTypeManagerImpl extends FileTypeManagerEx implements Persistent @Override public @NotNull String getName() { - return fileType.getName(); + return fileType().getName(); } } @@ -381,18 +376,18 @@ public class FileTypeManagerImpl extends FileTypeManagerEx implements Persistent removeAssociation(ftd, matcher, false); } schemeManager.removeScheme(name); - removeFromDuplicates(type, ftd.pluginDescriptor); + removeFromDuplicates(type, ftd.pluginDescriptor()); } standardFileTypes.clear(); for (FileTypeWithDescriptor ftd : defaultTypes) { String name = ftd.getName(); - FileType defaultType = ftd.fileType; + FileType defaultType = ftd.fileType(); List matchers = getAssociations(defaultType); for (FileNameMatcher matcher : matchers) { removeAssociation(ftd, matcher, false); } schemeManager.removeScheme(name); - removeFromDuplicates(defaultType, ftd.pluginDescriptor); + removeFromDuplicates(defaultType, ftd.pluginDescriptor()); } defaultTypes.clear(); } @@ -404,7 +399,7 @@ public class FileTypeManagerImpl extends FileTypeManagerEx implements Persistent private void removeFromDuplicates(@NotNull FileType type, @NotNull PluginDescriptor pluginDescriptor) { fileTypesPerPlugin .computeIfAbsent(pluginDescriptor, __ -> ConcurrentCollectionFactory.createConcurrentSet()) - .removeIf(descriptor -> descriptor.fileType.equals(type)); + .removeIf(descriptor -> descriptor.fileType().equals(type)); } private void loadFileTypeBeans() { @@ -508,7 +503,7 @@ public class FileTypeManagerImpl extends FileTypeManagerEx implements Persistent if (!pendingFileTypes.containsKey(fileTypeName)) { FileTypeWithDescriptor ftd = schemeManager.findSchemeByName(fileTypeName); - if (ftd != null && !(ftd.fileType instanceof AbstractFileType)) { + if (ftd != null && !(ftd.fileType() instanceof AbstractFileType)) { return ftd; } } @@ -678,7 +673,7 @@ public class FileTypeManagerImpl extends FileTypeManagerEx implements Persistent boolean isAtLeastOneStandardFileTypeHasBeenRead = false; for (FileTypeWithDescriptor ftd : schemeManager.loadSchemes()) { - isAtLeastOneStandardFileTypeHasBeenRead |= initialAssociations.hasAssociationsFor(ftd.fileType); + isAtLeastOneStandardFileTypeHasBeenRead |= initialAssociations.hasAssociationsFor(ftd.fileType()); } if (isAtLeastOneStandardFileTypeHasBeenRead) { restoreStandardFileExtensions(); @@ -898,8 +893,8 @@ public class FileTypeManagerImpl extends FileTypeManagerEx implements Persistent return type; } for (FileTypeWithDescriptor ftd: getAllFileTypeWithDescriptors()) { - if (fileTypeName.equals(ftd.fileType.getName())) { - return ftd.fileType; + if (fileTypeName.equals(ftd.fileType().getName())) { + return ftd.fileType(); } } return null; @@ -921,16 +916,16 @@ public class FileTypeManagerImpl extends FileTypeManagerEx implements Persistent }); if (bean != null) { FileTypeWithDescriptor descriptor = instantiateFileTypeBean(bean); - return descriptor != null ? (LanguageFileType)descriptor.fileType : null; + return descriptor != null ? (LanguageFileType)descriptor.fileType() : null; } // Do not use getRegisteredFileTypes(), to avoid instantiating all pending file types - return withReadLock(() -> language.findMyFileType(ContainerUtil.map2Array(getAllFileTypeWithDescriptors(), FileType.EMPTY_ARRAY, ftd->ftd.fileType))); + return withReadLock(() -> language.findMyFileType(ContainerUtil.map2Array(getAllFileTypeWithDescriptors(), FileType.EMPTY_ARRAY, ftd-> ftd.fileType()))); } @Override public @NotNull FileType getFileTypeByExtension(@NotNull String extension) { - return getFileTypeWithDescriptorByExtension(extension).fileType; + return getFileTypeWithDescriptorByExtension(extension).fileType(); } @NotNull FileTypeWithDescriptor getFileTypeWithDescriptorByExtension(@NotNull String extension) { @@ -970,7 +965,7 @@ public class FileTypeManagerImpl extends FileTypeManagerEx implements Persistent ApplicationManager.getApplication().runWriteAction(() -> { fireBeforeFileTypesChanged(); registerFileTypeWithoutNotification(type, - detectPluginDescriptor(type).pluginDescriptor, + detectPluginDescriptor(type).pluginDescriptor(), defaultAssociations, pluginAdvertiserExtensionsStateService, true); @@ -1028,7 +1023,7 @@ public class FileTypeManagerImpl extends FileTypeManagerEx implements Persistent FileType[] result = new FileType[descriptors.size()]; int i = 0; for (FileTypeManagerImpl.FileTypeWithDescriptor descriptor : descriptors) { - result[i++] = descriptor.fileType; + result[i++] = descriptor.fileType(); } return result; } @@ -1095,7 +1090,7 @@ public class FileTypeManagerImpl extends FileTypeManagerEx implements Persistent } private static @NotNull FileType getFileTypeOrUnknown(@Nullable FileTypeWithDescriptor ftd) { - return ftd == null ? UnknownFileType.INSTANCE : ftd.fileType; + return ftd == null ? UnknownFileType.INSTANCE : ftd.fileType(); } @Override @@ -1240,7 +1235,7 @@ public class FileTypeManagerImpl extends FileTypeManagerEx implements Persistent String fileTypeName = association.getSecond(); FileNameMatcher matcher = association.getFirst(); FileTypeWithDescriptor ftd = getFileTypeWithDescriptorByName(fileTypeName); - FileType type = ftd == null ? null : ftd.fileType; + FileType type = ftd == null ? null : ftd.fileType(); FileTypeBean pendingFileTypeBean = pendingAssociations.findAssociatedFileType(matcher); if (pendingFileTypeBean != null) { instantiateFileTypeBean(pendingFileTypeBean); @@ -1252,7 +1247,7 @@ public class FileTypeManagerImpl extends FileTypeManagerEx implements Persistent else { if (PlainTextFileType.INSTANCE.equals(type)) { FileTypeWithDescriptor textFtd = patternsTable.findAssociatedFileType(matcher); - FileType newFileType = textFtd==null?null:textFtd.fileType; + FileType newFileType = textFtd==null? null: textFtd.fileType(); if (newFileType != null && newFileType != PlainTextFileType.INSTANCE && newFileType != UnknownFileType.INSTANCE) { removedMappingTracker.add(matcher, newFileType.getName(), false); } @@ -1286,7 +1281,7 @@ public class FileTypeManagerImpl extends FileTypeManagerEx implements Persistent else { patternsTable.addHashBangPattern(hashBang, ftd); if (isAddToInit) { - initialAssociations.addHashBangPattern(hashBang, ftd.fileType); + initialAssociations.addHashBangPattern(hashBang, ftd.fileType()); } } } @@ -1344,12 +1339,12 @@ public class FileTypeManagerImpl extends FileTypeManagerEx implements Persistent List notExternalizableFileTypes = new ArrayList<>(); for (FileTypeWithDescriptor fileTypeDescriptor: getAllFileTypeWithDescriptors()) { - if (!(fileTypeDescriptor.fileType instanceof AbstractFileType) || defaultTypes.contains(fileTypeDescriptor)) { + if (!(fileTypeDescriptor.fileType() instanceof AbstractFileType) || defaultTypes.contains(fileTypeDescriptor)) { notExternalizableFileTypes.add(fileTypeDescriptor); } } if (!notExternalizableFileTypes.isEmpty()) { - notExternalizableFileTypes.sort(Comparator.comparing(it -> it.fileType.getName())); + notExternalizableFileTypes.sort(Comparator.comparing(it -> it.fileType().getName())); for (FileTypeWithDescriptor ftd : notExternalizableFileTypes) { writeExtensionsMap(extensionMap, ftd, true); } @@ -1406,7 +1401,7 @@ public class FileTypeManagerImpl extends FileTypeManagerEx implements Persistent } private void writeExtensionsMap(@NotNull Element extensionMap, @NotNull FileTypeWithDescriptor ftd, boolean specifyTypeName) { - FileType type = ftd.fileType; + FileType type = ftd.fileType(); List associations = patternsTable.getAssociations(ftd); Set defaultAssociations = new HashSet<>(initialAssociations.getAssociations(type)); @@ -1480,10 +1475,10 @@ public class FileTypeManagerImpl extends FileTypeManagerEx implements Persistent if (addScheme) { FileTypeWithDescriptor oldFileType = schemeManager.findSchemeByName(newFileType.getName()); if (oldFileType != null) { - if (!(oldFileType.fileType instanceof AbstractFileType)) { + if (!(oldFileType.fileType() instanceof AbstractFileType)) { throw new IllegalArgumentException(newFileType + " already registered"); } - removeFromDuplicates(oldFileType.fileType, oldFileType.pluginDescriptor); + removeFromDuplicates(oldFileType.fileType(), oldFileType.pluginDescriptor()); } schemeManager.addScheme(newFtd); pendingFileTypes.remove(newFileType.getName()); @@ -1513,7 +1508,7 @@ public class FileTypeManagerImpl extends FileTypeManagerEx implements Persistent conflictResultConsumer.accept(result); } FileTypeWithDescriptor resolvedFtd = result.resolved(); - FileType oldFileType = oldFtd == null ? null : oldFtd.fileType; + FileType oldFileType = oldFtd == null ? null : oldFtd.fileType(); if (!resolvedFtd.equals(oldFtd)) { patternsTable.addAssociation(newMatcher, resolvedFtd); if (result.approved() && oldFileType != null) { @@ -1535,7 +1530,7 @@ public class FileTypeManagerImpl extends FileTypeManagerEx implements Persistent } private void checkFileTypeNamesUniqueness(@NotNull FileTypeWithDescriptor newDescriptor) { - fileTypesPerPlugin.computeIfAbsent(newDescriptor.pluginDescriptor, __ -> ConcurrentHashMap.newKeySet()).add(newDescriptor); + fileTypesPerPlugin.computeIfAbsent(newDescriptor.pluginDescriptor(), __ -> ConcurrentHashMap.newKeySet()).add(newDescriptor); if (ApplicationManager.getApplication().isUnitTestMode()) { checkUnique(); } @@ -1566,17 +1561,18 @@ public class FileTypeManagerImpl extends FileTypeManagerEx implements Persistent @NotNull Map names, @NotNull String getterName, @NotNull Function nameExtractor) { - FileType newFileType = newFileTypeWithDescriptor.fileType; + FileType newFileType = newFileTypeWithDescriptor.fileType(); String name = nameExtractor.apply(newFileType); FileTypeWithDescriptor prevFileTypeWithDescriptor = names.put(name, newFileTypeWithDescriptor); - if (prevFileTypeWithDescriptor != null && (prevFileTypeWithDescriptor.fileType instanceof AbstractFileType) == (newFileType instanceof AbstractFileType)) { + if (prevFileTypeWithDescriptor != null && (prevFileTypeWithDescriptor.fileType() instanceof AbstractFileType) == (newFileType instanceof AbstractFileType)) { // should be able to override AbstractFileType silently - String error = "\n" + prevFileTypeWithDescriptor + " (" + prevFileTypeWithDescriptor.fileType.getClass() + ") and" + + String error = "\n" + prevFileTypeWithDescriptor + " (" + prevFileTypeWithDescriptor.fileType().getClass() + ") and" + "\n" + newFileTypeWithDescriptor + " (" + newFileType.getClass() + ")\n" + " both have the same ." + getterName + "(): '" + name + "'. " + "Please override either one's " + getterName + "() to something unique."; - PluginDescriptor pluginToBlame = prevFileTypeWithDescriptor.pluginDescriptor.isBundled() ? newFileTypeWithDescriptor.pluginDescriptor : prevFileTypeWithDescriptor.pluginDescriptor; - if (prevFileTypeWithDescriptor.pluginDescriptor.isBundled() || newFileTypeWithDescriptor.pluginDescriptor.isBundled()) { + PluginDescriptor pluginToBlame = prevFileTypeWithDescriptor.pluginDescriptor().isBundled() ? newFileTypeWithDescriptor.pluginDescriptor() + : prevFileTypeWithDescriptor.pluginDescriptor(); + if (prevFileTypeWithDescriptor.pluginDescriptor().isBundled() || newFileTypeWithDescriptor.pluginDescriptor().isBundled()) { // file type from the plugin conflicts with a bundled file type LOG.error(new PluginException(error, pluginToBlame.getPluginId())); } @@ -1620,7 +1616,7 @@ public class FileTypeManagerImpl extends FileTypeManagerEx implements Persistent FileTypeWithDescriptor ftd = isDefault && fileTypeName != null ? getFileTypeWithDescriptorByName(fileTypeName) : null; if (ftd != null) { - return ftd.fileType; + return ftd.fileType(); } Element element = typeElement.getChild(AbstractFileType.ELEMENT_HIGHLIGHTING); @@ -1723,8 +1719,8 @@ public class FileTypeManagerImpl extends FileTypeManagerEx implements Persistent } for (FileTypeWithDescriptor ftd : fileTypes) { schemeManager.addScheme(ftd); - if (ftd.fileType instanceof AbstractFileType) { - ((AbstractFileType)ftd.fileType).initSupport(); + if (ftd.fileType() instanceof AbstractFileType) { + ((AbstractFileType)ftd.fileType()).initSupport(); } } patternsTable = assocTable.copy(); @@ -1737,18 +1733,18 @@ public class FileTypeManagerImpl extends FileTypeManagerEx implements Persistent return fileType != null && assocTable.isAssociatedWith(fileType, matcher); }); for (Map.Entry entry : removedMappings.entrySet()) { - removedMappingTracker.add(entry.getKey(), entry.getValue().fileType.getName(), true); + removedMappingTracker.add(entry.getKey(), entry.getValue().fileType().getName(), true); } } void associate(@NotNull FileTypeWithDescriptor ftd, @NotNull FileNameMatcher matcher, boolean fireChange) { - FileType fileType = ftd.fileType; + FileType fileType = ftd.fileType(); // delete "this matcher is removed from this file type" record removedMappingTracker.removeIf(mapping -> matcher.equals(mapping.getFileNameMatcher()) && fileType.getName().equals(mapping.getFileTypeName())); if (!patternsTable.isAssociatedWith(ftd, matcher)) { Runnable command = () -> patternsTable.addAssociation(matcher, ftd); if (fireChange) { - makeFileTypesChange("file type '" + ftd.fileType + "' associated with '" + matcher + "'", command); + makeFileTypesChange("file type '" + ftd.fileType() + "' associated with '" + matcher + "'", command); } else { command.run(); @@ -1760,7 +1756,7 @@ public class FileTypeManagerImpl extends FileTypeManagerEx implements Persistent if (patternsTable.isAssociatedWith(ftd, matcher)) { Runnable command = () -> patternsTable.removeAssociation(matcher, ftd); if (fireChange) { - makeFileTypesChange("file type '" + ftd.fileType + "' association with '" + matcher + "' has been removed", command); + makeFileTypesChange("file type '" + ftd.fileType() + "' association with '" + matcher + "' has been removed", command); } else { command.run(); @@ -1807,8 +1803,8 @@ public class FileTypeManagerImpl extends FileTypeManagerEx implements Persistent public PluginDescriptor findPluginDescriptor(@NotNull FileType fileType) { for (FileTypeWithDescriptor ftd : getAllFileTypeWithDescriptors()) { - if (ftd.fileType.equals(fileType)) { - return ftd.pluginDescriptor; + if (ftd.fileType().equals(fileType)) { + return ftd.pluginDescriptor(); } } return null; diff --git a/platform/platform-tests/testSrc/com/intellij/openapi/fileTypes/impl/ConflictFileTypeMappingTrackerTest.java b/platform/platform-tests/testSrc/com/intellij/openapi/fileTypes/impl/ConflictFileTypeMappingTrackerTest.java index 474570179068..40b1cc2a6316 100644 --- a/platform/platform-tests/testSrc/com/intellij/openapi/fileTypes/impl/ConflictFileTypeMappingTrackerTest.java +++ b/platform/platform-tests/testSrc/com/intellij/openapi/fileTypes/impl/ConflictFileTypeMappingTrackerTest.java @@ -52,7 +52,7 @@ public class ConflictFileTypeMappingTrackerTest extends TestCase { FileTypeManagerImpl.FileTypeWithDescriptor oldFtd = new FileTypeManagerImpl.FileTypeWithDescriptor(oldFileType, oldDescriptor); FileTypeManagerImpl.FileTypeWithDescriptor newFtd = new FileTypeManagerImpl.FileTypeWithDescriptor(newFileType, newDescriptor); result = ConflictingFileTypeMappingTracker.resolveConflict(matcher, oldFtd, newFtd); - assertSame(expectedResolveToNew ? newFileType : oldFileType, result.resolved().fileType); + assertSame(expectedResolveToNew ? newFileType : oldFileType, result.resolved().fileType()); assertEquals(expectedApprove, result.approved()); } diff --git a/platform/platform-tests/testSrc/com/intellij/openapi/fileTypes/impl/FileTypesTest.java b/platform/platform-tests/testSrc/com/intellij/openapi/fileTypes/impl/FileTypesTest.java index 1f43c6949ba6..7327f412c050 100644 --- a/platform/platform-tests/testSrc/com/intellij/openapi/fileTypes/impl/FileTypesTest.java +++ b/platform/platform-tests/testSrc/com/intellij/openapi/fileTypes/impl/FileTypesTest.java @@ -288,7 +288,7 @@ public class FileTypesTest extends HeavyPlatformTestCase { assertEmpty(psi.getText()); FileTypeWithDescriptor anySaneFtd = ContainerUtil.find(myFileTypeManager.getRegisteredFileTypeWithDescriptors(), - f -> !(f.fileType instanceof AbstractFileType) && !f.fileType.isBinary()); + f -> !(f.fileType() instanceof AbstractFileType) && !f.fileType().isBinary()); String hashBang = "xxxxx"; // make sure no other hashBang substrings here associateHashBang(anySaneFtd, hashBang); @@ -305,7 +305,7 @@ public class FileTypesTest extends HeavyPlatformTestCase { }); PsiDocumentManager.getInstance(getProject()).commitAllDocuments(); FileDocumentManager.getInstance().saveAllDocuments(); - assertEquals(anySaneFtd.fileType, getFileType(virtualFile)); + assertEquals(anySaneFtd.fileType(), getFileType(virtualFile)); assertEquals(hashBangedString, getPsiManager().findFile(virtualFile).getText()); } @@ -519,7 +519,7 @@ public class FileTypesTest extends HeavyPlatformTestCase { table.removeAssociation(matcher, fileType); WriteAction.run(() -> myFileTypeManager.setPatternsTable(fileTypes, table)); - myFileTypeManager.getRemovedMappingTracker().add(matcher, fileType.fileType.getName(), true); + myFileTypeManager.getRemovedMappingTracker().add(matcher, fileType.fileType().getName(), true); Element state = myFileTypeManager.getState(); LOG.debug(JDOMUtil.writeElement(state)); @@ -544,7 +544,7 @@ public class FileTypesTest extends HeavyPlatformTestCase { table.removeAssociation(matcher, fileType); WriteAction.run(() -> myFileTypeManager.setPatternsTable(fileTypes, table)); - myFileTypeManager.getRemovedMappingTracker().add(matcher, fileType.fileType.getName(), true); + myFileTypeManager.getRemovedMappingTracker().add(matcher, fileType.fileType().getName(), true); Element state = myFileTypeManager.getState(); LOG.debug(JDOMUtil.writeElement(state)); @@ -593,7 +593,7 @@ public class FileTypesTest extends HeavyPlatformTestCase { public void testAddHashBangToReassignedTypeMustSurviveRestart() throws IOException, JDOMException { FileTypeWithDescriptor ftd = ContainerUtil.find(myFileTypeManager.getRegisteredFileTypeWithDescriptors(), - f -> !(f.fileType instanceof AbstractFileType)); + f -> !(f.fileType() instanceof AbstractFileType)); String hashBang = "xxx"; associateHashBang(ftd, hashBang);