From ccc33ef1f031a334f707fc8bf754bfdf695cb52c Mon Sep 17 00:00:00 2001 From: Alexey Kudravtsev Date: Thu, 28 Jan 2010 14:23:01 +0300 Subject: [PATCH] lossy encoding inspection false positive for transparently converted properties files --- .../intellij/codeInspection/LossyEncodingInspection.java | 15 ++++++--------- .../src/com/intellij/openapi/vfs/VfsUtil.java | 3 ++- .../lang/properties/PropertiesReferenceManager.java | 6 ++---- 3 files changed, 10 insertions(+), 14 deletions(-) diff --git a/java/java-impl/src/com/intellij/codeInspection/LossyEncodingInspection.java b/java/java-impl/src/com/intellij/codeInspection/LossyEncodingInspection.java index 9e8514d95b..aa76760e29 100644 --- a/java/java-impl/src/com/intellij/codeInspection/LossyEncodingInspection.java +++ b/java/java-impl/src/com/intellij/codeInspection/LossyEncodingInspection.java @@ -66,14 +66,16 @@ public class LossyEncodingInspection extends BaseJavaLocalInspectionTool { if (virtualFile == null) return null; String text = file.getText(); Charset charset = LoadTextUtil.extractCharsetFromFileContent(file.getProject(), virtualFile, text); - charset = Native2AsciiCharset.nativeToBaseCharset(charset); + + // no sense in checking transparently decoded file: all characters there are already safely encoded + if (charset instanceof Native2AsciiCharset) return null; int errorCount = 0; int start = -1; List descriptors = new SmartList(); - for (int i = 0; i < text.length(); i++) { - char c = text.charAt(i); - if (isRepresentable(c, charset)) { + for (int i = 0; i <= text.length(); i++) { + char c = i == text.length() ? 0 : text.charAt(i); + if (i == text.length() || isRepresentable(c, charset)) { if (start != -1) { ProblemDescriptor descriptor = manager.createProblemDescriptor(file, new TextRange(start, i), InspectionsBundle.message( "unsupported.character.for.the.charset", charset), ProblemHighlightType.GENERIC_ERROR_OR_WARNING, isOnTheFly); @@ -90,11 +92,6 @@ public class LossyEncodingInspection extends BaseJavaLocalInspectionTool { } } } - if (start != -1) { - ProblemDescriptor descriptor = manager.createProblemDescriptor(file, new TextRange(start, text.length()), InspectionsBundle.message( - "unsupported.character.for.the.charset", charset), ProblemHighlightType.GENERIC_ERROR_OR_WARNING, isOnTheFly); - descriptors.add(descriptor); - } return descriptors.toArray(new ProblemDescriptor[descriptors.size()]); } diff --git a/platform/platform-api/src/com/intellij/openapi/vfs/VfsUtil.java b/platform/platform-api/src/com/intellij/openapi/vfs/VfsUtil.java index b37ddc8f06..ada5ce6b29 100644 --- a/platform/platform-api/src/com/intellij/openapi/vfs/VfsUtil.java +++ b/platform/platform-api/src/com/intellij/openapi/vfs/VfsUtil.java @@ -56,7 +56,8 @@ public class VfsUtil { } public static void saveText(@NotNull VirtualFile file, @NotNull String text) throws IOException { - file.setBinaryContent(text.getBytes(file.getCharset().name())); + Charset charset = file.getCharset(); + file.setBinaryContent(text.getBytes(charset.name())); } /** diff --git a/plugins/properties/src/com/intellij/lang/properties/PropertiesReferenceManager.java b/plugins/properties/src/com/intellij/lang/properties/PropertiesReferenceManager.java index c869d2705b..0f567e7404 100644 --- a/plugins/properties/src/com/intellij/lang/properties/PropertiesReferenceManager.java +++ b/plugins/properties/src/com/intellij/lang/properties/PropertiesReferenceManager.java @@ -38,15 +38,13 @@ import java.util.Locale; * @author max */ public class PropertiesReferenceManager { - private final Project myProject; private final PsiManager myPsiManager; public static PropertiesReferenceManager getInstance(Project project) { return ServiceManager.getService(project, PropertiesReferenceManager.class); } - public PropertiesReferenceManager(Project project, PsiManager psiManager) { - myProject = project; + public PropertiesReferenceManager(PsiManager psiManager) { myPsiManager = psiManager; } @@ -98,7 +96,7 @@ public class PropertiesReferenceManager { return null; } - public String[] getPropertyFileBaseNames(final @NotNull GlobalSearchScope searchScope, final BundleNameEvaluator bundleNameEvaluator) { + public String[] getPropertyFileBaseNames(@NotNull final GlobalSearchScope searchScope, final BundleNameEvaluator bundleNameEvaluator) { final ArrayList result = new ArrayList(); processPropertiesFiles(searchScope, new PropertiesFileProcessor() { public void process(String baseName, PropertiesFile propertiesFile) { -- 2.11.4.GIT