mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-18 09:34:34 +07:00
do not autoimport inner classes
This commit is contained in:
+9
-1
@@ -145,7 +145,9 @@ public abstract class ImportClassFixBase<T extends PsiElement & PsiReference> im
|
||||
&& (JspPsiUtil.isInJspFile(psiFile) ?
|
||||
CodeInsightSettings.getInstance().JSP_ADD_UNAMBIGIOUS_IMPORTS_ON_THE_FLY :
|
||||
CodeInsightSettings.getInstance().ADD_UNAMBIGIOUS_IMPORTS_ON_THE_FLY)
|
||||
&& codeAnalyzer.canChangeFileSilently(psiFile)) {
|
||||
&& codeAnalyzer.canChangeFileSilently(psiFile)
|
||||
&& !autoImportWillInsertUnexpectedCharacters(classes[0])
|
||||
) {
|
||||
CommandProcessor.getInstance().runUndoTransparentAction(new Runnable() {
|
||||
public void run() {
|
||||
action.execute();
|
||||
@@ -165,6 +167,12 @@ public abstract class ImportClassFixBase<T extends PsiElement & PsiReference> im
|
||||
return Result.POPUP_NOT_SHOWN;
|
||||
}
|
||||
|
||||
private static boolean autoImportWillInsertUnexpectedCharacters(PsiClass aClass) {
|
||||
PsiClass containingClass = aClass.getContainingClass();
|
||||
// when importing inner class, the reference might be qualified with outer class name and it can be confusing
|
||||
return containingClass != null;
|
||||
}
|
||||
|
||||
private boolean canImportHere(boolean allowCaretNearRef, Editor editor, PsiFile psiFile, String exampleClassName) {
|
||||
return (allowCaretNearRef || !isCaretNearRef(editor, myRef)) &&
|
||||
!hasUnresolvedImportWhichCanImport(psiFile, exampleClassName);
|
||||
|
||||
@@ -368,4 +368,27 @@ public class ImportHelperTest extends DaemonAnalyzerTestCase {
|
||||
}
|
||||
}
|
||||
|
||||
public void testAutoInsertImportForInnerClass() throws Throwable {
|
||||
@NonNls String text = "package x; class S { void f(ReadLock r){} } <caret> ";
|
||||
configureByText(StdFileTypes.JAVA, text);
|
||||
|
||||
boolean old = CodeInsightSettings.getInstance().ADD_UNAMBIGIOUS_IMPORTS_ON_THE_FLY;
|
||||
CodeInsightSettings.getInstance().ADD_UNAMBIGIOUS_IMPORTS_ON_THE_FLY = true;
|
||||
DaemonCodeAnalyzerSettings.getInstance().setImportHintEnabled(true);
|
||||
|
||||
try {
|
||||
List<HighlightInfo> errs = filter(doHighlighting(), HighlightSeverity.ERROR);
|
||||
assertEquals(1, errs.size());
|
||||
|
||||
assertEmpty(((PsiJavaFile)getFile()).getImportList().getAllImportStatements());
|
||||
type("/* */");
|
||||
doHighlighting();
|
||||
UIUtil.dispatchAllInvocationEvents();
|
||||
assertEmpty(((PsiJavaFile)getFile()).getImportList().getAllImportStatements());
|
||||
}
|
||||
finally {
|
||||
CodeInsightSettings.getInstance().ADD_UNAMBIGIOUS_IMPORTS_ON_THE_FLY = old;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user