mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
cleanup
GitOrigin-RevId: 732c080193b61324232cb1ac1d39a7e382cf8f2c
This commit is contained in:
committed by
intellij-monorepo-bot
parent
a58e3e7447
commit
1004800b4a
@@ -45,22 +45,23 @@ public class ExtensionFileNameMatcher implements FileNameMatcher {
|
||||
return "*." + myExtension;
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public String getExtension() {
|
||||
return myExtension;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public boolean equals(final Object o) {
|
||||
if (this == o) return true;
|
||||
if (o == null || getClass() != o.getClass()) return false;
|
||||
|
||||
final ExtensionFileNameMatcher that = (ExtensionFileNameMatcher)o;
|
||||
|
||||
if (!myExtension.equals(that.myExtension)) return false;
|
||||
|
||||
return true;
|
||||
return myExtension.equals(that.myExtension);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return myExtension.hashCode();
|
||||
}
|
||||
|
||||
@@ -19,14 +19,14 @@ import java.util.*;
|
||||
* @author max
|
||||
*/
|
||||
public class FileTypeAssocTable<T> {
|
||||
private final THashMap<CharSequence, T> myExtensionMappings;
|
||||
private final THashMap<CharSequence, T> myExactFileNameMappings;
|
||||
private final THashMap<CharSequence, T> myExactFileNameAnyCaseMappings;
|
||||
private final Map<CharSequence, T> myExtensionMappings;
|
||||
private final Map<CharSequence, T> myExactFileNameMappings;
|
||||
private final Map<CharSequence, T> myExactFileNameAnyCaseMappings;
|
||||
private final List<Pair<FileNameMatcher, T>> myMatchingMappings;
|
||||
|
||||
private FileTypeAssocTable(@NotNull Map<CharSequence, T> extensionMappings,
|
||||
@NotNull Map<CharSequence, T> exactFileNameMappings,
|
||||
@NotNull Map<CharSequence, T> exactFileNameAnyCaseMappings,
|
||||
private FileTypeAssocTable(@NotNull Map<? extends CharSequence, ? extends T> extensionMappings,
|
||||
@NotNull Map<? extends CharSequence, ? extends T> exactFileNameMappings,
|
||||
@NotNull Map<? extends CharSequence, T> exactFileNameAnyCaseMappings,
|
||||
@NotNull List<? extends Pair<FileNameMatcher, T>> matchingMappings) {
|
||||
myExtensionMappings = new THashMap<>(Math.max(10, extensionMappings.size()), 0.5f, CharSequenceHashingStrategy.CASE_INSENSITIVE);
|
||||
myExtensionMappings.putAll(extensionMappings);
|
||||
@@ -90,15 +90,7 @@ public class FileTypeAssocTable<T> {
|
||||
return false;
|
||||
}
|
||||
|
||||
List<Pair<FileNameMatcher, T>> copy = new ArrayList<>(myMatchingMappings);
|
||||
for (Pair<FileNameMatcher, T> assoc : copy) {
|
||||
if (matcher.equals(assoc.getFirst())) {
|
||||
myMatchingMappings.remove(assoc);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
return myMatchingMappings.removeIf(assoc -> matcher.equals(assoc.getFirst()));
|
||||
}
|
||||
|
||||
boolean removeAllAssociations(@NotNull T type) {
|
||||
@@ -107,27 +99,11 @@ public class FileTypeAssocTable<T> {
|
||||
changed = removeAssociationsFromMap(myExactFileNameAnyCaseMappings, type, changed);
|
||||
changed = removeAssociationsFromMap(myExactFileNameMappings, type, changed);
|
||||
|
||||
List<Pair<FileNameMatcher, T>> copy = new ArrayList<>(myMatchingMappings);
|
||||
for (Pair<FileNameMatcher, T> assoc : copy) {
|
||||
if (assoc.getSecond() == type) {
|
||||
myMatchingMappings.remove(assoc);
|
||||
changed = true;
|
||||
}
|
||||
}
|
||||
|
||||
return changed;
|
||||
return myMatchingMappings.removeIf(assoc -> assoc.getSecond() == type);
|
||||
}
|
||||
|
||||
private boolean removeAssociationsFromMap(@NotNull Map<CharSequence, T> extensionMappings, @NotNull T type, boolean changed) {
|
||||
Set<CharSequence> exts = extensionMappings.keySet();
|
||||
CharSequence[] extsStrings = exts.toArray(new CharSequence[0]);
|
||||
for (CharSequence s : extsStrings) {
|
||||
if (extensionMappings.get(s) == type) {
|
||||
extensionMappings.remove(s);
|
||||
changed = true;
|
||||
}
|
||||
}
|
||||
return changed;
|
||||
return extensionMappings.entrySet().removeIf(entry -> entry.getValue() == type) || changed;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@@ -201,26 +177,21 @@ public class FileTypeAssocTable<T> {
|
||||
}
|
||||
}
|
||||
|
||||
myExactFileNameMappings.forEachEntry((key, value) -> {
|
||||
if (value == type) {
|
||||
result.add(new ExactFileNameMatcher(key.toString()));
|
||||
for (Map.Entry<CharSequence, T> entry : myExactFileNameMappings.entrySet()) {
|
||||
if (entry.getValue() == type) {
|
||||
result.add(new ExactFileNameMatcher(entry.getKey().toString(), false));
|
||||
}
|
||||
return true;
|
||||
});
|
||||
|
||||
myExactFileNameAnyCaseMappings.forEachEntry((key, value) -> {
|
||||
if (value == type) {
|
||||
result.add(new ExactFileNameMatcher(key.toString(), true));
|
||||
}
|
||||
for (Map.Entry<CharSequence, T> entry : myExactFileNameAnyCaseMappings.entrySet()) {
|
||||
if (entry.getValue() == type) {
|
||||
result.add(new ExactFileNameMatcher(entry.getKey().toString(), true));
|
||||
}
|
||||
return true;
|
||||
});
|
||||
|
||||
myExtensionMappings.forEachEntry((key, value) -> {
|
||||
if (value == type) {
|
||||
result.add(new ExtensionFileNameMatcher(key.toString()));
|
||||
}
|
||||
for (Map.Entry<CharSequence, T> entry : myExtensionMappings.entrySet()) {
|
||||
if (entry.getValue() == type) {
|
||||
result.add(new ExtensionFileNameMatcher(entry.getKey().toString()));
|
||||
}
|
||||
return true;
|
||||
});
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
@@ -239,7 +210,8 @@ public class FileTypeAssocTable<T> {
|
||||
return false;
|
||||
}
|
||||
|
||||
Map<FileNameMatcher, T> getRemovedMappings(FileTypeAssocTable<T> newTable, Collection<? extends T> keys) {
|
||||
@NotNull
|
||||
Map<FileNameMatcher, T> getRemovedMappings(@NotNull FileTypeAssocTable<T> newTable, @NotNull Collection<? extends T> keys) {
|
||||
Map<FileNameMatcher, T> map = new HashMap<>();
|
||||
for (T key : keys) {
|
||||
List<FileNameMatcher> associations = getAssociations(key);
|
||||
@@ -251,6 +223,7 @@ public class FileTypeAssocTable<T> {
|
||||
return map;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o) {
|
||||
if (this == o) {
|
||||
return true;
|
||||
@@ -266,6 +239,7 @@ public class FileTypeAssocTable<T> {
|
||||
myExactFileNameAnyCaseMappings.equals(that.myExactFileNameAnyCaseMappings);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
int result = myExtensionMappings.hashCode();
|
||||
result = 31 * result + myMatchingMappings.hashCode();
|
||||
|
||||
@@ -25,7 +25,7 @@ public abstract class SimpleListCellRenderer<T> extends JBLabel implements ListC
|
||||
public static <T> SimpleListCellRenderer<T> create(@NotNull String nullValue, @NotNull Function<? super T, String> getText) {
|
||||
return new SimpleListCellRenderer<T>() {
|
||||
@Override
|
||||
public void customize(JList<? extends T> list, T value, int index, boolean selected, boolean hasFocus) {
|
||||
public void customize(@NotNull JList<? extends T> list, T value, int index, boolean selected, boolean hasFocus) {
|
||||
setText(value == null ? nullValue : getText.fun(value));
|
||||
}
|
||||
};
|
||||
@@ -35,7 +35,7 @@ public abstract class SimpleListCellRenderer<T> extends JBLabel implements ListC
|
||||
public static <T> SimpleListCellRenderer<T> create(@NotNull Customizer<? super T> customizer) {
|
||||
return new SimpleListCellRenderer<T>() {
|
||||
@Override
|
||||
public void customize(JList<? extends T> list, T value, int index, boolean selected, boolean hasFocus) {
|
||||
public void customize(@NotNull JList<? extends T> list, T value, int index, boolean selected, boolean hasFocus) {
|
||||
customizer.customize(this, value, index);
|
||||
}
|
||||
};
|
||||
@@ -66,7 +66,7 @@ public abstract class SimpleListCellRenderer<T> extends JBLabel implements ListC
|
||||
return this;
|
||||
}
|
||||
|
||||
public abstract void customize(JList<? extends T> list, T value, int index, boolean selected, boolean hasFocus);
|
||||
public abstract void customize(@NotNull JList<? extends T> list, T value, int index, boolean selected, boolean hasFocus);
|
||||
|
||||
@Override
|
||||
public Dimension getPreferredSize() {
|
||||
|
||||
+7
-7
@@ -34,7 +34,7 @@ public class AbstractFileType extends UserFileType<AbstractFileType> implements
|
||||
private static final String SEMICOLON = ";";
|
||||
protected SyntaxTable mySyntaxTable;
|
||||
private SyntaxTable myDefaultSyntaxTable;
|
||||
protected Commenter myCommenter = null;
|
||||
protected Commenter myCommenter;
|
||||
@NonNls public static final String ELEMENT_HIGHLIGHTING = "highlighting";
|
||||
@NonNls private static final String ELEMENT_OPTIONS = "options";
|
||||
@NonNls private static final String ELEMENT_OPTION = "option";
|
||||
@@ -62,7 +62,7 @@ public class AbstractFileType extends UserFileType<AbstractFileType> implements
|
||||
mySyntaxTable = syntaxTable;
|
||||
}
|
||||
|
||||
public void initSupport() {
|
||||
void initSupport() {
|
||||
for (FileTypeRegistrator registrator : Extensions.getRootArea().getExtensionPoint(FileTypeRegistrator.EP_NAME).getExtensions()) {
|
||||
registrator.initFileType(this);
|
||||
}
|
||||
@@ -109,7 +109,7 @@ public class AbstractFileType extends UserFileType<AbstractFileType> implements
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public static SyntaxTable readSyntaxTable(@NotNull Element root) {
|
||||
static SyntaxTable readSyntaxTable(@NotNull Element root) {
|
||||
SyntaxTable table = new SyntaxTable();
|
||||
|
||||
for (Element element : root.getChildren()) {
|
||||
@@ -186,7 +186,7 @@ public class AbstractFileType extends UserFileType<AbstractFileType> implements
|
||||
StringTokenizer tokenizer = new StringTokenizer(value, SEMICOLON);
|
||||
while(tokenizer.hasMoreElements()) {
|
||||
String keyword = tokenizer.nextToken().trim();
|
||||
if (keyword.length() != 0) keywords.add(keyword);
|
||||
if (!keyword.isEmpty()) keywords.add(keyword);
|
||||
}
|
||||
}
|
||||
for (final Object o1 : element.getChildren(ELEMENT_KEYWORD)) {
|
||||
@@ -272,7 +272,7 @@ public class AbstractFileType extends UserFileType<AbstractFileType> implements
|
||||
}
|
||||
|
||||
private static Element writeKeywords(Set<String> keywords, String tagName, Element highlightingElement) {
|
||||
if (keywords.size() == 0 && !ELEMENT_KEYWORDS.equals(tagName)) return null;
|
||||
if (keywords.isEmpty() && !ELEMENT_KEYWORDS.equals(tagName)) return null;
|
||||
Element keywordsElement = new Element(tagName);
|
||||
String[] strings = ArrayUtilRt.toStringArray(keywords);
|
||||
Arrays.sort(strings);
|
||||
@@ -311,7 +311,7 @@ public class AbstractFileType extends UserFileType<AbstractFileType> implements
|
||||
@NonNls static final String ATTRIBUTE_TYPE = "type";
|
||||
|
||||
@NotNull
|
||||
public static List<Pair<FileNameMatcher, String>> readAssociations(@NotNull Element element) {
|
||||
static List<Pair<FileNameMatcher, String>> readAssociations(@NotNull Element element) {
|
||||
List<Element> children = element.getChildren(ELEMENT_MAPPING);
|
||||
if (children.isEmpty()) {
|
||||
return Collections.emptyList();
|
||||
@@ -329,7 +329,7 @@ public class AbstractFileType extends UserFileType<AbstractFileType> implements
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public static Element writeMapping(String typeName, @NotNull FileNameMatcher matcher, boolean specifyTypeName) {
|
||||
static Element writeMapping(String typeName, @NotNull FileNameMatcher matcher, boolean specifyTypeName) {
|
||||
Element mapping = new Element(ELEMENT_MAPPING);
|
||||
if (matcher instanceof ExtensionFileNameMatcher) {
|
||||
mapping.setAttribute(ATTRIBUTE_EXT, ((ExtensionFileNameMatcher)matcher).getExtension());
|
||||
|
||||
@@ -70,7 +70,7 @@ public class FileTypeBean extends AbstractExtensionPointBean {
|
||||
public String language;
|
||||
|
||||
@ApiStatus.Internal
|
||||
public void addMatchers(List<FileNameMatcher> matchers) {
|
||||
public void addMatchers(List<? extends FileNameMatcher> matchers) {
|
||||
myMatchers.addAll(matchers);
|
||||
}
|
||||
|
||||
|
||||
+13
-13
@@ -157,8 +157,8 @@ public class FileTypeManagerImpl extends FileTypeManagerEx implements Persistent
|
||||
|
||||
private final Object PENDING_INIT_LOCK = new Object();
|
||||
|
||||
private MultiValuesMap<FileType, FileTypeDetector> myFileTypeDetectorMap = null;
|
||||
private List<FileTypeDetector> myUntypedFileTypeDetectors = new ArrayList<>();
|
||||
private MultiValuesMap<FileType, FileTypeDetector> myFileTypeDetectorMap;
|
||||
private final List<FileTypeDetector> myUntypedFileTypeDetectors = new ArrayList<>();
|
||||
private final Object FILE_TYPE_DETECTOR_MAP_LOCK = new Object();
|
||||
|
||||
public FileTypeManagerImpl() {
|
||||
@@ -377,9 +377,9 @@ public class FileTypeManagerImpl extends FileTypeManagerEx implements Persistent
|
||||
for (FileTypeBean bean : fileTypeBeans) {
|
||||
bean.addMatchers(ContainerUtil.concat(
|
||||
parse(bean.extensions),
|
||||
parse(bean.fileNames, (token) -> new ExactFileNameMatcher(token)),
|
||||
parse(bean.fileNamesCaseInsensitive, (token) -> new ExactFileNameMatcher(token, true)),
|
||||
parse(bean.patterns, (token) -> FileNameMatcherFactory.getInstance().createMatcher(token))));
|
||||
parse(bean.fileNames, token -> new ExactFileNameMatcher(token)),
|
||||
parse(bean.fileNamesCaseInsensitive, token -> new ExactFileNameMatcher(token, true)),
|
||||
parse(bean.patterns, token -> FileNameMatcherFactory.getInstance().createMatcher(token))));
|
||||
}
|
||||
|
||||
for (FileTypeBean bean : fileTypeBeans) {
|
||||
@@ -920,7 +920,7 @@ public class FileTypeManagerImpl extends FileTypeManagerEx implements Persistent
|
||||
}
|
||||
|
||||
@NotNull
|
||||
private FileType detectFromContent(@NotNull VirtualFile file, @NotNull Iterable<FileTypeDetector> detectors) throws IOException {
|
||||
private FileType detectFromContent(@NotNull VirtualFile file, @NotNull Iterable<? extends FileTypeDetector> detectors) throws IOException {
|
||||
FileType fileType;
|
||||
try (InputStream inputStream = ((FileSystemInterface)file.getFileSystem()).getInputStream(file)) {
|
||||
if (toLog()) {
|
||||
@@ -956,7 +956,7 @@ public class FileTypeManagerImpl extends FileTypeManagerEx implements Persistent
|
||||
}
|
||||
|
||||
@NotNull
|
||||
private FileType detect(@NotNull VirtualFile file, @NotNull byte[] bytes, int length, @NotNull Iterable<FileTypeDetector> detectors) {
|
||||
private FileType detect(@NotNull VirtualFile file, @NotNull byte[] bytes, int length, @NotNull Iterable<? extends FileTypeDetector> detectors) {
|
||||
if (length <= 0) return UnknownFileType.INSTANCE;
|
||||
|
||||
// use PlainTextFileType because it doesn't supply its own charset detector
|
||||
@@ -1095,7 +1095,7 @@ public class FileTypeManagerImpl extends FileTypeManagerEx implements Persistent
|
||||
return true;
|
||||
}
|
||||
}
|
||||
catch (IOException ignored) { ;
|
||||
catch (IOException ignored) {
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1526,7 +1526,7 @@ public class FileTypeManagerImpl extends FileTypeManagerEx implements Persistent
|
||||
}
|
||||
|
||||
@NotNull
|
||||
private static List<FileNameMatcher> parse(@Nullable String semicolonDelimited, Function<String, FileNameMatcher> matcherFactory) {
|
||||
private static List<FileNameMatcher> parse(@Nullable String semicolonDelimited, Function<? super String, ? extends FileNameMatcher> matcherFactory) {
|
||||
if (semicolonDelimited == null) {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
@@ -1669,7 +1669,7 @@ public class FileTypeManagerImpl extends FileTypeManagerEx implements Persistent
|
||||
return myPatternsTable;
|
||||
}
|
||||
|
||||
void setPatternsTable(@NotNull Set<FileType> fileTypes, @NotNull FileTypeAssocTable<FileType> assocTable) {
|
||||
void setPatternsTable(@NotNull Set<? extends FileType> fileTypes, @NotNull FileTypeAssocTable<FileType> assocTable) {
|
||||
Map<FileNameMatcher, FileType> removedMappings = getExtensionMap().getRemovedMappings(assocTable, fileTypes);
|
||||
fireBeforeFileTypesChanged();
|
||||
for (FileType existing : getRegisteredFileTypes()) {
|
||||
@@ -1690,8 +1690,8 @@ public class FileTypeManagerImpl extends FileTypeManagerEx implements Persistent
|
||||
FileType fileType = getFileTypeByName(fileTypeName);
|
||||
return fileType != null && assocTable.isAssociatedWith(fileType, matcher);
|
||||
});
|
||||
for (FileNameMatcher matcher : removedMappings.keySet()) {
|
||||
myRemovedMappingTracker.add(matcher, removedMappings.get(matcher).getName(), true);
|
||||
for (Map.Entry<FileNameMatcher, FileType> entry : removedMappings.entrySet()) {
|
||||
myRemovedMappingTracker.add(entry.getKey(), entry.getValue().getName(), true);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1748,7 +1748,7 @@ public class FileTypeManagerImpl extends FileTypeManagerEx implements Persistent
|
||||
}
|
||||
}
|
||||
|
||||
private void registerReDetectedMapping(String fileTypeName, @NotNull FileNameMatcher matcher) {
|
||||
private void registerReDetectedMapping(@NotNull String fileTypeName, @NotNull FileNameMatcher matcher) {
|
||||
String typeName = myUnresolvedMappings.get(matcher);
|
||||
if (typeName != null && !typeName.equals(fileTypeName)) {
|
||||
if (!myRemovedMappingTracker.hasRemovedMapping(matcher)) {
|
||||
|
||||
+5
-8
@@ -19,6 +19,7 @@ public class FileTypeRenderer extends SimpleListCellRenderer<FileType> {
|
||||
private static final Pattern CLEANUP = Pattern.compile("(?i)\\s+file(?:s)?$");
|
||||
|
||||
public interface FileTypeListProvider {
|
||||
@NotNull
|
||||
Iterable<FileType> getCurrentFileTypeList();
|
||||
}
|
||||
|
||||
@@ -29,12 +30,11 @@ public class FileTypeRenderer extends SimpleListCellRenderer<FileType> {
|
||||
}
|
||||
|
||||
public FileTypeRenderer(@NotNull FileTypeListProvider fileTypeListProvider) {
|
||||
super();
|
||||
myFileTypeListProvider = fileTypeListProvider;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void customize(JList<? extends FileType> list, FileType value, int index, boolean selected, boolean hasFocus) {
|
||||
public void customize(@NotNull JList<? extends FileType> list, FileType value, int index, boolean selected, boolean hasFocus) {
|
||||
LayeredIcon layeredIcon = new LayeredIcon(2);
|
||||
layeredIcon.setIcon(EMPTY_ICON, 0);
|
||||
Icon icon = value.getIcon();
|
||||
@@ -54,7 +54,7 @@ public class FileTypeRenderer extends SimpleListCellRenderer<FileType> {
|
||||
}
|
||||
}
|
||||
|
||||
private boolean isDuplicated(final String description) {
|
||||
private boolean isDuplicated(@NotNull String description) {
|
||||
boolean found = false;
|
||||
|
||||
for (FileType type : myFileTypeListProvider.getCurrentFileTypeList()) {
|
||||
@@ -71,12 +71,9 @@ public class FileTypeRenderer extends SimpleListCellRenderer<FileType> {
|
||||
}
|
||||
|
||||
private static class DefaultFileTypeListProvider implements FileTypeListProvider {
|
||||
private final List<FileType> myFileTypes;
|
||||
|
||||
DefaultFileTypeListProvider() {
|
||||
myFileTypes = Arrays.asList(FileTypeManager.getInstance().getRegisteredFileTypes());
|
||||
}
|
||||
private final List<FileType> myFileTypes = Arrays.asList(FileTypeManager.getInstance().getRegisteredFileTypes());
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public Iterable<FileType> getCurrentFileTypeList() {
|
||||
return myFileTypes;
|
||||
|
||||
+1
-1
@@ -59,7 +59,7 @@ final class IgnoredFileCache {
|
||||
myNonIgnoredIds.clear();
|
||||
}
|
||||
|
||||
boolean isFileIgnored(VirtualFile file) {
|
||||
boolean isFileIgnored(@NotNull VirtualFile file) {
|
||||
int id = myVfsEventNesting == 0 && file instanceof NewVirtualFile ? ((NewVirtualFile)file).getId() : -1;
|
||||
if (id > 0 && myNonIgnoredIds.get(id)) {
|
||||
return false;
|
||||
|
||||
+20
-21
@@ -17,7 +17,7 @@ class RemovedMappingTracker {
|
||||
private final String myFileTypeName;
|
||||
private boolean myApproved;
|
||||
|
||||
private RemovedMapping(FileNameMatcher matcher, String name, boolean approved) {
|
||||
private RemovedMapping(@NotNull FileNameMatcher matcher, @NotNull String name, boolean approved) {
|
||||
myFileNameMatcher = matcher;
|
||||
myFileTypeName = name;
|
||||
myApproved = approved;
|
||||
@@ -45,13 +45,13 @@ class RemovedMappingTracker {
|
||||
@NonNls private static final String ELEMENT_REMOVED_MAPPING = "removed_mapping";
|
||||
/** Applied for removed mappings approved by user */
|
||||
@NonNls private static final String ATTRIBUTE_APPROVED = "approved";
|
||||
@NonNls static final String ATTRIBUTE_TYPE = "type";
|
||||
@NonNls private static final String ATTRIBUTE_TYPE = "type";
|
||||
|
||||
void clear() {
|
||||
myRemovedMappings.clear();
|
||||
}
|
||||
|
||||
public void add(FileNameMatcher matcher, String fileTypeName, boolean approved) {
|
||||
public void add(@NotNull FileNameMatcher matcher, @NotNull String fileTypeName, boolean approved) {
|
||||
myRemovedMappings.put(matcher, new RemovedMapping(matcher, fileTypeName, approved));
|
||||
}
|
||||
|
||||
@@ -71,7 +71,9 @@ class RemovedMappingTracker {
|
||||
List<RemovedMapping> result = new ArrayList<>();
|
||||
for (Element mapping : children) {
|
||||
String ext = mapping.getAttributeValue(AbstractFileType.ATTRIBUTE_EXT);
|
||||
FileNameMatcher matcher = ext == null ? FileTypeManager.parseFromString(mapping.getAttributeValue(AbstractFileType.ATTRIBUTE_PATTERN)) : new ExtensionFileNameMatcher(ext);
|
||||
FileNameMatcher matcher = ext == null
|
||||
? FileTypeManager.parseFromString(mapping.getAttributeValue(AbstractFileType.ATTRIBUTE_PATTERN))
|
||||
: new ExtensionFileNameMatcher(ext);
|
||||
boolean approved = Boolean.parseBoolean(mapping.getAttributeValue(ATTRIBUTE_APPROVED));
|
||||
String fileTypeName = mapping.getAttributeValue(ATTRIBUTE_TYPE);
|
||||
if (fileTypeName == null) continue;
|
||||
@@ -82,7 +84,7 @@ class RemovedMappingTracker {
|
||||
return result;
|
||||
}
|
||||
|
||||
public void save(Element element) {
|
||||
public void save(@NotNull Element element) {
|
||||
for (RemovedMapping mapping : myRemovedMappings.values()) {
|
||||
Element content = writeRemovedMapping(mapping.myFileTypeName, mapping.myFileNameMatcher, true, mapping.myApproved);
|
||||
if (content != null) {
|
||||
@@ -91,7 +93,7 @@ class RemovedMappingTracker {
|
||||
}
|
||||
}
|
||||
|
||||
public void saveRemovedMappingsForFileType(Element map, String fileTypeName, Set<FileNameMatcher> associations, boolean specifyTypeName) {
|
||||
void saveRemovedMappingsForFileType(@NotNull Element map, @NotNull String fileTypeName, @NotNull Set<? extends FileNameMatcher> associations, boolean specifyTypeName) {
|
||||
for (FileNameMatcher matcher : associations) {
|
||||
Element content = writeRemovedMapping(fileTypeName, matcher, specifyTypeName, isApproved(matcher));
|
||||
if (content != null) {
|
||||
@@ -100,24 +102,25 @@ class RemovedMappingTracker {
|
||||
}
|
||||
}
|
||||
|
||||
boolean hasRemovedMapping(FileNameMatcher matcher) {
|
||||
boolean hasRemovedMapping(@NotNull FileNameMatcher matcher) {
|
||||
return myRemovedMappings.containsKey(matcher);
|
||||
}
|
||||
|
||||
boolean isApproved(FileNameMatcher matcher) {
|
||||
private boolean isApproved(@NotNull FileNameMatcher matcher) {
|
||||
RemovedMapping mapping = myRemovedMappings.get(matcher);
|
||||
return mapping != null && mapping.isApproved();
|
||||
}
|
||||
|
||||
public void approveRemoval(String fileTypeName, FileNameMatcher matcher) {
|
||||
void approveRemoval(@NotNull String fileTypeName, @NotNull FileNameMatcher matcher) {
|
||||
myRemovedMappings.put(matcher, new RemovedMapping(matcher, fileTypeName, true));
|
||||
}
|
||||
|
||||
@NotNull
|
||||
public List<RemovedMapping> getRemovedMappings() {
|
||||
return new ArrayList<>(myRemovedMappings.values());
|
||||
}
|
||||
|
||||
public List<FileNameMatcher> getMappingsForFileType(String name) {
|
||||
List<FileNameMatcher> getMappingsForFileType(@NotNull String name) {
|
||||
List<FileNameMatcher> result = new ArrayList<>();
|
||||
for (RemovedMapping mapping : myRemovedMappings.values()) {
|
||||
if (mapping.myFileTypeName.equals(name)) {
|
||||
@@ -127,15 +130,11 @@ class RemovedMappingTracker {
|
||||
return result;
|
||||
}
|
||||
|
||||
void removeMatching(BiPredicate<FileNameMatcher, String> predicate) {
|
||||
for (Iterator<Map.Entry<FileNameMatcher, RemovedMapping>> it = myRemovedMappings.entrySet().iterator(); it.hasNext(); ) {
|
||||
Map.Entry<FileNameMatcher, RemovedMapping> next = it.next();
|
||||
if (predicate.test(next.getValue().myFileNameMatcher, next.getValue().myFileTypeName)) {
|
||||
it.remove();
|
||||
}
|
||||
}
|
||||
void removeMatching(@NotNull BiPredicate<? super FileNameMatcher, ? super String> predicate) {
|
||||
myRemovedMappings.entrySet().removeIf(next -> predicate.test(next.getValue().myFileNameMatcher, next.getValue().myFileTypeName));
|
||||
}
|
||||
|
||||
@NotNull
|
||||
List<RemovedMapping> retrieveUnapprovedMappings() {
|
||||
List<RemovedMapping> result = new ArrayList<>();
|
||||
for (Iterator<Map.Entry<FileNameMatcher, RemovedMapping>> it = myRemovedMappings.entrySet().iterator(); it.hasNext(); ) {
|
||||
@@ -148,10 +147,10 @@ class RemovedMappingTracker {
|
||||
return result;
|
||||
}
|
||||
|
||||
static Element writeRemovedMapping(@NotNull String fileTypeName,
|
||||
@NotNull FileNameMatcher matcher,
|
||||
boolean specifyTypeName,
|
||||
boolean approved) {
|
||||
private static Element writeRemovedMapping(@NotNull String fileTypeName,
|
||||
@NotNull FileNameMatcher matcher,
|
||||
boolean specifyTypeName,
|
||||
boolean approved) {
|
||||
Element mapping = new Element(ELEMENT_REMOVED_MAPPING);
|
||||
if (matcher instanceof ExtensionFileNameMatcher) {
|
||||
mapping.setAttribute(AbstractFileType.ATTRIBUTE_EXT, ((ExtensionFileNameMatcher)matcher).getExtension());
|
||||
|
||||
+4
-4
@@ -111,8 +111,8 @@ public class AppScheduledExecutorServiceTest extends TestCase {
|
||||
|
||||
assertEquals(4, log.size());
|
||||
assertEquals(4, log.get(0).runnable);
|
||||
List<Thread> threads = Arrays.asList(log.get(1).currentThread, log.get(2).currentThread, log.get(3).currentThread);
|
||||
assertEquals(log.toString(), 3, new HashSet<>(threads).size()); // must be executed in parallel
|
||||
Set<Thread> threads = ContainerUtil.map2Set(log, l->l.currentThread);
|
||||
assertEquals(log.toString(), 3, threads.size()); // must be executed in parallel
|
||||
}
|
||||
|
||||
public void testMustNotBeAbleToShutdown() {
|
||||
@@ -211,7 +211,7 @@ public class AppScheduledExecutorServiceTest extends TestCase {
|
||||
assertEquals(1, service.getBackendPoolExecutorSize());
|
||||
|
||||
assertEquals(3, log.size());
|
||||
Set<Thread> usedThreads = new HashSet<>(Arrays.asList(log.get(0).currentThread, log.get(1).currentThread, log.get(2).currentThread));
|
||||
Set<Thread> usedThreads = ContainerUtil.map2Set(log, l->l.currentThread);
|
||||
assertEquals(usedThreads.toString(), 1, usedThreads.size()); // must be executed in same thread
|
||||
}
|
||||
catch (AssertionError e) {
|
||||
@@ -239,7 +239,7 @@ public class AppScheduledExecutorServiceTest extends TestCase {
|
||||
}
|
||||
|
||||
assertEquals(N, log.size());
|
||||
Set<Thread> usedThreads = ContainerUtil.map2Set(log, logInfo -> logInfo.currentThread);
|
||||
Set<Thread> usedThreads = ContainerUtil.map2Set(log, l -> l.currentThread);
|
||||
|
||||
assertEquals(N, usedThreads.size());
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user