extract duplicate, cleanup

GitOrigin-RevId: 4e732dd8f2db9f6586f2a0b20fb377a597475888
This commit is contained in:
Alexey Kudravtsev
2020-03-19 19:23:01 +00:00
committed by intellij-monorepo-bot
parent f9f533440c
commit 8ee64025c2
2 changed files with 11 additions and 13 deletions
@@ -328,12 +328,9 @@ public class AbstractFileType extends UserFileType<AbstractFileType> implements
}
@Nullable
static Element writeMapping(String typeName, @NotNull FileNameMatcher matcher, boolean specifyTypeName) {
static Element writeMapping(@NotNull String typeName, @NotNull FileNameMatcher matcher, boolean specifyTypeName) {
Element mapping = new Element(ELEMENT_MAPPING);
if (matcher instanceof ExtensionFileNameMatcher) {
mapping.setAttribute(ATTRIBUTE_EXT, ((ExtensionFileNameMatcher)matcher).getExtension());
}
else if (writePattern(matcher, mapping)) {
if (!writePattern(matcher, mapping)) {
return null;
}
@@ -344,17 +341,21 @@ public class AbstractFileType extends UserFileType<AbstractFileType> implements
return mapping;
}
static boolean writePattern(FileNameMatcher matcher, Element mapping) {
if (matcher instanceof WildcardFileNameMatcher) {
// returns true if written
static boolean writePattern(@NotNull FileNameMatcher matcher, @NotNull Element mapping) {
if (matcher instanceof ExtensionFileNameMatcher) {
mapping.setAttribute(ATTRIBUTE_EXT, ((ExtensionFileNameMatcher)matcher).getExtension());
}
else if (matcher instanceof WildcardFileNameMatcher) {
mapping.setAttribute(ATTRIBUTE_PATTERN, ((WildcardFileNameMatcher)matcher).getPattern());
}
else if (matcher instanceof ExactFileNameMatcher) {
mapping.setAttribute(ATTRIBUTE_PATTERN, ((ExactFileNameMatcher)matcher).getFileName());
}
else {
return true;
return false;
}
return false;
return true;
}
@Override
@@ -152,10 +152,7 @@ class RemovedMappingTracker {
boolean specifyTypeName,
boolean approved) {
Element mapping = new Element(ELEMENT_REMOVED_MAPPING);
if (matcher instanceof ExtensionFileNameMatcher) {
mapping.setAttribute(AbstractFileType.ATTRIBUTE_EXT, ((ExtensionFileNameMatcher)matcher).getExtension());
}
else if (AbstractFileType.writePattern(matcher, mapping)) {
if (!AbstractFileType.writePattern(matcher, mapping)) {
return null;
}
if (approved) {