diff --git a/java/java-impl/src/com/intellij/codeInspection/LossyEncodingInspection.java b/java/java-impl/src/com/intellij/codeInspection/LossyEncodingInspection.java deleted file mode 100644 index 7cc5bb2673d6..000000000000 --- a/java/java-impl/src/com/intellij/codeInspection/LossyEncodingInspection.java +++ /dev/null @@ -1,142 +0,0 @@ -/* - * Copyright 2000-2009 JetBrains s.r.o. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -/* - * Created by IntelliJ IDEA. - * User: cdr - * Date: Aug 6, 2007 - * Time: 3:09:55 PM - */ -package com.intellij.codeInspection; - -import com.intellij.codeInsight.daemon.GroupNames; -import com.intellij.ide.DataManager; -import com.intellij.lang.properties.charset.Native2AsciiCharset; -import com.intellij.openapi.actionSystem.DataContext; -import com.intellij.openapi.actionSystem.DefaultActionGroup; -import com.intellij.openapi.fileEditor.impl.LoadTextUtil; -import com.intellij.openapi.project.Project; -import com.intellij.openapi.ui.popup.JBPopupFactory; -import com.intellij.openapi.util.TextRange; -import com.intellij.openapi.vfs.VirtualFile; -import com.intellij.openapi.vfs.encoding.ChooseFileEncodingAction; -import com.intellij.openapi.vfs.encoding.EncodingManager; -import com.intellij.psi.PsiFile; -import com.intellij.util.ArrayUtil; -import com.intellij.util.SmartList; -import org.jetbrains.annotations.Nls; -import org.jetbrains.annotations.NonNls; -import org.jetbrains.annotations.NotNull; -import org.jetbrains.annotations.Nullable; - -import java.nio.ByteBuffer; -import java.nio.CharBuffer; -import java.nio.charset.Charset; -import java.util.List; - -public class LossyEncodingInspection extends BaseJavaLocalInspectionTool { - private static final LocalQuickFix CHANGE_ENCODING_FIX = new LocalQuickFix() { - @NotNull - @Override - public String getName() { - return "Change file encoding"; - } - - @NotNull - @Override - public String getFamilyName() { - return getName(); - } - - @Override - public void applyFix(@NotNull Project project, @NotNull ProblemDescriptor descriptor) { - PsiFile psiFile = descriptor.getPsiElement().getContainingFile(); - VirtualFile virtualFile = psiFile.getVirtualFile(); - ChooseFileEncodingAction action = new ChooseFileEncodingAction(virtualFile) { - @Override - protected void chosen(VirtualFile virtualFile, Charset charset) { - if (virtualFile != null) { - EncodingManager.getInstance().setEncoding(virtualFile, charset); - } - } - }; - DefaultActionGroup group = action.createGroup(false); - DataContext dataContext = DataManager.getInstance().getDataContext(); - JBPopupFactory.getInstance().createActionGroupPopup(null, group, dataContext, false, false, false, null, 30, null).showInBestPositionFor(dataContext); - } - }; - - @Nls - @NotNull - public String getGroupDisplayName() { - return GroupNames.INTERNATIONALIZATION_GROUP_NAME; - } - - @Nls - @NotNull - public String getDisplayName() { - return InspectionsBundle.message("lossy.encoding"); - } - - @NonNls - @NotNull - public String getShortName() { - return "LossyEncoding"; - } - - @Nullable - public ProblemDescriptor[] checkFile(@NotNull PsiFile file, @NotNull InspectionManager manager, boolean isOnTheFly) { - if (ArrayUtil.find(file.getPsiRoots(), file) != 0) return null; - VirtualFile virtualFile = file.getVirtualFile(); - if (virtualFile == null) return null; - String text = file.getText(); - Charset charset = LoadTextUtil.extractCharsetFromFileContent(file.getProject(), virtualFile, text); - - // 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 = i == text.length() ? 0 : text.charAt(i); - if (i == text.length() || isRepresentable(c, charset)) { - if (start != -1) { - TextRange range = new TextRange(start, i); - String message = InspectionsBundle.message("unsupported.character.for.the.charset", charset); - ProblemDescriptor descriptor = manager.createProblemDescriptor(file, range, message, ProblemHighlightType.GENERIC_ERROR_OR_WARNING, isOnTheFly, - CHANGE_ENCODING_FIX); - descriptors.add(descriptor); - start = -1; - //do not report too many errors - if (errorCount++ > 200) break; - } - } - else if (start == -1) { - start = i; - } - } - - return descriptors.toArray(new ProblemDescriptor[descriptors.size()]); - } - - private static boolean isRepresentable(final char c, final Charset charset) { - String str = Character.toString(c); - ByteBuffer out = charset.encode(str); - CharBuffer buffer = charset.decode(out); - return str.equals(buffer.toString()); - } -} diff --git a/java/java-impl/src/com/intellij/codeInspection/ex/StandardInspectionToolsProvider.java b/java/java-impl/src/com/intellij/codeInspection/ex/StandardInspectionToolsProvider.java index 56fffdb96148..973c4463b4b2 100644 --- a/java/java-impl/src/com/intellij/codeInspection/ex/StandardInspectionToolsProvider.java +++ b/java/java-impl/src/com/intellij/codeInspection/ex/StandardInspectionToolsProvider.java @@ -108,7 +108,6 @@ public class StandardInspectionToolsProvider implements InspectionToolProvider { UncheckedWarningLocalInspection.class, SuspiciousNameCombinationInspection.class, DuplicateThrowsInspection.class, - LossyEncodingInspection.class, FieldAccessNotGuardedInspection.class, InstanceGuardedByStaticInspection.class, diff --git a/java/java-tests/testSrc/com/intellij/codeInsight/daemon/LossyEncodingTest.java b/java/java-tests/testSrc/com/intellij/codeInsight/daemon/LossyEncodingTest.java index 6f7f21d5cc36..02aa4d403f3d 100644 --- a/java/java-tests/testSrc/com/intellij/codeInsight/daemon/LossyEncodingTest.java +++ b/java/java-tests/testSrc/com/intellij/codeInsight/daemon/LossyEncodingTest.java @@ -1,3 +1,19 @@ +/* + * Copyright 2000-2011 JetBrains s.r.o. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + /* * Created by IntelliJ IDEA. * User: max diff --git a/platform/lang-impl/src/com/intellij/codeInspection/PlatformInspectionToolProvider.java b/platform/lang-impl/src/com/intellij/codeInspection/PlatformInspectionToolProvider.java index 562b266cc58f..fdd4fe52f61c 100644 --- a/platform/lang-impl/src/com/intellij/codeInspection/PlatformInspectionToolProvider.java +++ b/platform/lang-impl/src/com/intellij/codeInspection/PlatformInspectionToolProvider.java @@ -23,6 +23,8 @@ public class PlatformInspectionToolProvider implements InspectionToolProvider { public Class[] getInspectionClasses() { return new Class[] { DefaultHighlightVisitorBasedInspection.AnnotatorBasedInspection.class, - DefaultHighlightVisitorBasedInspection.SyntaxErrorInspection.class }; + DefaultHighlightVisitorBasedInspection.SyntaxErrorInspection.class, + LossyEncodingInspection.class, + }; } } diff --git a/resources-en/src/inspectionDescriptions/LossyEncoding.html b/resources-en/src/inspectionDescriptions/LossyEncoding.html deleted file mode 100644 index c305effb8b9b..000000000000 --- a/resources-en/src/inspectionDescriptions/LossyEncoding.html +++ /dev/null @@ -1,13 +0,0 @@ - - - - This inspection warns you of characters that current encoding is incapable to represent.
- E.g. when you are trying to type international characters in an US-ASCII-encoded file.
- Typically, you would fix this by changing the file encoding, - either by specifying the encoding directly in the file, e.g. by editing encoding= attribute in the XML prolog of XML file, - or configuring the Settings|General|File Encoding|Default encoding setting, - or by setting up the file/directory encoding in the Settings|File/Directory Options|File Encodings. -
- - - \ No newline at end of file