mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
IDEA-87779 My code is deleted on the fly if 'Add unambiguous imports on the fly' option is enabled
This commit is contained in:
@@ -429,4 +429,24 @@ public class ImportHelperTest extends DaemonAnalyzerTestCase {
|
||||
}
|
||||
}
|
||||
|
||||
public void testAutoImportDoNotBreakCode() throws Throwable {
|
||||
@NonNls String text = "package x; class S {{ S.<caret>\n Runnable r; }}";
|
||||
configureByText(StdFileTypes.JAVA, text);
|
||||
|
||||
boolean old = CodeInsightSettings.getInstance().ADD_UNAMBIGIOUS_IMPORTS_ON_THE_FLY;
|
||||
boolean opt = CodeInsightSettings.getInstance().OPTIMIZE_IMPORTS_ON_THE_FLY;
|
||||
CodeInsightSettings.getInstance().ADD_UNAMBIGIOUS_IMPORTS_ON_THE_FLY = true;
|
||||
CodeInsightSettings.getInstance().OPTIMIZE_IMPORTS_ON_THE_FLY = true;
|
||||
DaemonCodeAnalyzerSettings.getInstance().setImportHintEnabled(true);
|
||||
|
||||
try {
|
||||
List<HighlightInfo> errs = highlightErrors();
|
||||
assertEquals(1, errs.size());
|
||||
}
|
||||
finally {
|
||||
CodeInsightSettings.getInstance().ADD_UNAMBIGIOUS_IMPORTS_ON_THE_FLY = old;
|
||||
CodeInsightSettings.getInstance().OPTIMIZE_IMPORTS_ON_THE_FLY = opt;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -39,6 +39,7 @@ import com.intellij.openapi.util.Pair;
|
||||
import com.intellij.openapi.util.TextRange;
|
||||
import com.intellij.psi.PsiElement;
|
||||
import com.intellij.psi.PsiFile;
|
||||
import com.intellij.psi.PsiReference;
|
||||
import com.intellij.util.Processor;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
@@ -102,7 +103,8 @@ public class ShowAutoImportPass extends TextEditorHighlightingPass {
|
||||
if (!info.hasHint() || info.getSeverity() != HighlightSeverity.ERROR) {
|
||||
return true;
|
||||
}
|
||||
if (TextRange.create(info.getActualStartOffset(), info.getActualEndOffset()).containsOffset(caretOffset)) return true;
|
||||
PsiReference reference = myFile.findReferenceAt(info.getActualStartOffset());
|
||||
if (reference != null && reference.getElement().getTextRange().containsOffset(caretOffset)) return true;
|
||||
infos.add(info);
|
||||
return true;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user