mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
suggest import for non-accessible classes (IDEA-192084)
assuming that no accessible classes are available and non-accessible classes are located inside the project so the visibility could be changed
This commit is contained in:
@@ -107,6 +107,7 @@ public class ImportClassFix extends ImportClassFixBase<PsiJavaCodeReferenceEleme
|
||||
|
||||
@Override
|
||||
protected boolean canReferenceClass(PsiJavaCodeReferenceElement ref) {
|
||||
if (PsiTreeUtil.getParentOfType(ref, PsiImportStatementBase.class) != null) return false;
|
||||
if (ref instanceof PsiReferenceExpression) {
|
||||
PsiElement parent = ref.getParent();
|
||||
return parent instanceof PsiReferenceExpression || parent instanceof PsiExpressionStatement;
|
||||
|
||||
+5
-3
@@ -121,13 +121,15 @@ public abstract class ImportClassFixBase<T extends PsiElement, R extends PsiRefe
|
||||
if (qName != null) { //filter local classes
|
||||
if (qName.indexOf('.') == -1 || !PsiNameHelper.getInstance(project).isQualifiedName(qName)) continue; //do not show classes from default or invalid package
|
||||
if (qName.endsWith(name) && (file == null || ImportFilter.shouldImport(file, qName))) {
|
||||
if (isAccessible(aClass, myElement)) {
|
||||
classList.add(aClass);
|
||||
}
|
||||
classList.add(aClass);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
boolean anyAccessibleFound = classList.stream().anyMatch(aClass -> isAccessible(aClass, myElement));
|
||||
PsiManager manager = myElement.getManager();
|
||||
classList.removeIf(aClass -> (anyAccessibleFound || !manager.isInProject(aClass)) && !isAccessible(aClass, myElement));
|
||||
|
||||
if (acceptWrongNumberOfTypeParams && referenceHasTypeParameters) {
|
||||
final List<PsiClass> candidates = new ArrayList<>();
|
||||
for (Iterator<PsiClass> iterator = classList.iterator(); iterator.hasNext(); ) {
|
||||
|
||||
+10
@@ -670,4 +670,14 @@ class Foo {
|
||||
'''
|
||||
assert myFixture.filterAvailableIntentions("Import class").empty
|
||||
}
|
||||
|
||||
void "test inaccessible class from the project"() {
|
||||
myFixture.addClass('package foo; class Foo {}')
|
||||
myFixture.configureByText 'a.java', '''
|
||||
class Bar {
|
||||
F<caret>oo abc;
|
||||
}
|
||||
'''
|
||||
assert !myFixture.filterAvailableIntentions("Import class").empty
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user