mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
refactored Condition<String> to Condition<CharSequence> to use it with cheaper vfile.getNameSequence()
This commit is contained in:
@@ -895,7 +895,7 @@ public class FindManagerTest extends DaemonAnalyzerTestCase {
|
||||
}
|
||||
|
||||
public void testCreateFileMaskCondition() {
|
||||
Condition<String> condition = createFileMaskCondition("*.java, *.js, !Foo.java, !*.min.js");
|
||||
Condition<CharSequence> condition = createFileMaskCondition("*.java, *.js, !Foo.java, !*.min.js");
|
||||
assertTrue(condition.value("Bar.java"));
|
||||
assertTrue(!condition.value("Bar.javac"));
|
||||
assertTrue(!condition.value("Foo.java"));
|
||||
|
||||
@@ -243,16 +243,16 @@ public class ReformatCodeAction extends AnAction implements DumbAware {
|
||||
if (fileTypeMask == null)
|
||||
return;
|
||||
|
||||
final Condition<String> patternCondition = getFileTypeMaskPattern(fileTypeMask);
|
||||
final Condition<CharSequence> patternCondition = getFileTypeMaskPattern(fileTypeMask);
|
||||
processor.addFileFilter(new VirtualFileFilter() {
|
||||
@Override
|
||||
public boolean accept(@NotNull VirtualFile file) {
|
||||
return patternCondition.value(file.getName());
|
||||
return patternCondition.value(file.getNameSequence());
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private static Condition<String> getFileTypeMaskPattern(@Nullable String mask) {
|
||||
private static Condition<CharSequence> getFileTypeMaskPattern(@Nullable String mask) {
|
||||
try {
|
||||
return FindInProjectUtil.createFileMaskCondition(mask);
|
||||
} catch (PatternSyntaxException e) {
|
||||
|
||||
@@ -60,11 +60,11 @@ class FileFilterPanel {
|
||||
String text = (String)myFileMask.getSelectedItem();
|
||||
if (text == null) return null;
|
||||
|
||||
final Condition<String> patternCondition = FindInProjectUtil.createFileMaskCondition(text);
|
||||
final Condition<CharSequence> patternCondition = FindInProjectUtil.createFileMaskCondition(text);
|
||||
return new GlobalSearchScope() {
|
||||
@Override
|
||||
public boolean contains(@NotNull VirtualFile file) {
|
||||
return patternCondition.value(file.getName());
|
||||
return patternCondition.value(file.getNameSequence());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -109,9 +109,9 @@ class FindInProjectTask {
|
||||
myProjectFileIndex = ProjectRootManager.getInstance(project).getFileIndex();
|
||||
myFileIndex = myModule == null ? myProjectFileIndex : ModuleRootManager.getInstance(myModule).getFileIndex();
|
||||
|
||||
final Condition<String> patternCondition = FindInProjectUtil.createFileMaskCondition(findModel.getFileFilter());
|
||||
Condition<CharSequence> patternCondition = FindInProjectUtil.createFileMaskCondition(findModel.getFileFilter());
|
||||
|
||||
myFileMask = file -> file != null && patternCondition.value(file.getName());
|
||||
myFileMask = file -> file != null && patternCondition.value(file.getNameSequence());
|
||||
|
||||
final ProgressIndicator progress = ProgressManager.getInstance().getProgressIndicator();
|
||||
myProgress = progress != null ? progress : new EmptyProgressIndicator();
|
||||
|
||||
@@ -162,7 +162,7 @@ public class FindInProjectUtil {
|
||||
|
||||
/* filter can have form "*.js, !*_min.js", latter means except matched by *_min.js */
|
||||
@NotNull
|
||||
public static Condition<String> createFileMaskCondition(@Nullable String filter) throws PatternSyntaxException {
|
||||
public static Condition<CharSequence> createFileMaskCondition(@Nullable String filter) throws PatternSyntaxException {
|
||||
if (filter == null) {
|
||||
return Conditions.alwaysTrue();
|
||||
}
|
||||
@@ -175,7 +175,8 @@ public class FindInProjectUtil {
|
||||
mask = mask.trim();
|
||||
if (StringUtil.startsWith(mask, "!")) {
|
||||
negativePattern += (negativePattern.isEmpty() ? "" : "|") + "(" + PatternUtil.convertToRegex(mask.substring(1)) + ")";
|
||||
} else {
|
||||
}
|
||||
else {
|
||||
pattern += (pattern.isEmpty() ? "" : "|") + "(" + PatternUtil.convertToRegex(mask) + ")";
|
||||
}
|
||||
}
|
||||
@@ -184,11 +185,11 @@ public class FindInProjectUtil {
|
||||
final String finalPattern = pattern;
|
||||
final String finalNegativePattern = negativePattern;
|
||||
|
||||
return new Condition<String>() {
|
||||
return new Condition<CharSequence>() {
|
||||
final Pattern regExp = Pattern.compile(finalPattern, Pattern.CASE_INSENSITIVE);
|
||||
final Pattern negativeRegExp = StringUtil.isEmpty(finalNegativePattern) ? null : Pattern.compile(finalNegativePattern, Pattern.CASE_INSENSITIVE);
|
||||
@Override
|
||||
public boolean value(String input) {
|
||||
public boolean value(CharSequence input) {
|
||||
return regExp.matcher(input).matches() && (negativeRegExp == null || !negativeRegExp.matcher(input).matches());
|
||||
}
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user