mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
CR-IC-765 - IDEA-105751 Convert line separators: Provide an inspection which reports files with line separator different from project's default
1. Caching ignored files set; 2. Corrected inspection description text;
This commit is contained in:
+19
-4
@@ -32,10 +32,12 @@ import com.intellij.util.LineSeparator;
|
||||
import com.intellij.util.Processor;
|
||||
import com.intellij.util.containers.ContainerUtilRt;
|
||||
import com.intellij.util.containers.Convertor;
|
||||
import com.intellij.util.containers.WeakKeyWeakValueHashMap;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
@@ -43,7 +45,9 @@ import java.util.Set;
|
||||
*/
|
||||
public abstract class AbstractConvertLineSeparatorsAction extends AnAction {
|
||||
|
||||
private static Logger LOG = Logger.getInstance("#com.strintec.intellij.webmaster.lineSeparator.ConvertLineSeparatorsAction");
|
||||
private static Logger LOG = Logger.getInstance("#com.intellij.codeStyle.AbstractConvertLineSeparatorsAction");
|
||||
|
||||
private static final Map<String, Set<VirtualFile>> CACHED_IGNORED_FILES = new WeakKeyWeakValueHashMap<String, Set<VirtualFile>>();
|
||||
|
||||
@NotNull
|
||||
private final String mySeparator;
|
||||
@@ -51,7 +55,7 @@ public abstract class AbstractConvertLineSeparatorsAction extends AnAction {
|
||||
protected AbstractConvertLineSeparatorsAction(@Nullable String text, @NotNull LineSeparator separator) {
|
||||
this(separator.toString() + " - " + text, separator.getSeparatorString());
|
||||
}
|
||||
|
||||
|
||||
protected AbstractConvertLineSeparatorsAction(@Nullable String text, @NotNull String separator) {
|
||||
super(text);
|
||||
mySeparator = separator;
|
||||
@@ -127,7 +131,13 @@ public abstract class AbstractConvertLineSeparatorsAction extends AnAction {
|
||||
|
||||
@NotNull
|
||||
private static Set<VirtualFile> getIgnoredFiles(@NotNull Project project) {
|
||||
final Set<VirtualFile> result = ContainerUtilRt.newHashSet();
|
||||
String key = project.getName() + project.getLocationHash();
|
||||
Set<VirtualFile> result = CACHED_IGNORED_FILES.get(key);
|
||||
if (result != null) {
|
||||
return result;
|
||||
}
|
||||
|
||||
result = ContainerUtilRt.newHashSet();
|
||||
|
||||
VirtualFile projectFile = project.getProjectFile();
|
||||
if (projectFile != null) {
|
||||
@@ -145,9 +155,14 @@ public abstract class AbstractConvertLineSeparatorsAction extends AnAction {
|
||||
result.add(moduleFile);
|
||||
}
|
||||
}
|
||||
synchronized (CACHED_IGNORED_FILES) {
|
||||
// We're brave enough to not be scared by double-cached value recalculation. Critical section is introduced only for the
|
||||
// data consistency.
|
||||
CACHED_IGNORED_FILES.put(key, result);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
public static boolean shouldProcess(@NotNull VirtualFile file, @NotNull Project project) {
|
||||
return shouldProcess(file, getIgnoredFiles(project));
|
||||
}
|
||||
|
||||
+1
-1
@@ -55,7 +55,7 @@ public class InconsistentLineSeparatorsInspection extends LocalInspectionTool {
|
||||
holder.registerProblem(
|
||||
file,
|
||||
"Line separators in the current file (" + StringUtil.escapeStringCharacters(curLineSeparator) + ") " +
|
||||
"differs from the project defaults (" + StringUtil.escapeStringCharacters(projectLineSeparator) + ")",
|
||||
"differ from the project defaults (" + StringUtil.escapeStringCharacters(projectLineSeparator) + ")",
|
||||
SET_PROJECT_LINE_SEPARATORS);
|
||||
}
|
||||
}
|
||||
|
||||
+3
-1
@@ -1,7 +1,9 @@
|
||||
<html>
|
||||
<body>
|
||||
<font face="verdana" size="-1">
|
||||
This inspection warns you of files which line separators differ from project defaults.
|
||||
This inspection detects files with line separators different from the project default.
|
||||
E.g. you set the line separator to "\n" in the Settings|Code Style|Line separator,
|
||||
and the file you are editing uses '\r\n' as a line separator.
|
||||
</font>
|
||||
|
||||
</body>
|
||||
|
||||
Reference in New Issue
Block a user