mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
no classes in reference code fragment
This commit is contained in:
+9
-8
@@ -256,8 +256,7 @@ public class JavaCompletionContributor extends CompletionContributor {
|
||||
public static void addAllClasses(CompletionParameters parameters,
|
||||
final CompletionResultSet result,
|
||||
final InheritorsHolder inheritors) {
|
||||
if (!isClassNamePossible(parameters.getPosition()) && parameters.getInvocationCount() <= 1 ||
|
||||
!mayStartClassName(result)) {
|
||||
if (!isClassNamePossible(parameters) || !mayStartClassName(result)) {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -380,10 +379,12 @@ public class JavaCompletionContributor extends CompletionContributor {
|
||||
}
|
||||
}
|
||||
|
||||
public static boolean isClassNamePossible(final PsiElement position) {
|
||||
final PsiElement parent = position.getParent();
|
||||
if (!(parent instanceof PsiJavaCodeReferenceElement)) return false;
|
||||
if (((PsiJavaCodeReferenceElement)parent).getQualifier() != null) return false;
|
||||
static boolean isClassNamePossible(CompletionParameters parameters) {
|
||||
boolean isSecondCompletion = parameters.getInvocationCount() >= 2;
|
||||
|
||||
final PsiElement parent = parameters.getPosition().getParent();
|
||||
if (!(parent instanceof PsiJavaCodeReferenceElement)) return isSecondCompletion;
|
||||
if (((PsiJavaCodeReferenceElement)parent).getQualifier() != null) return isSecondCompletion;
|
||||
|
||||
if (parent instanceof PsiJavaCodeReferenceElementImpl &&
|
||||
((PsiJavaCodeReferenceElementImpl)parent).getKind() == PsiJavaCodeReferenceElementImpl.PACKAGE_NAME_KIND) {
|
||||
@@ -396,7 +397,7 @@ public class JavaCompletionContributor extends CompletionContributor {
|
||||
}
|
||||
|
||||
if (psiElement().inside(PsiImportStatement.class).accepts(parent)) {
|
||||
return false;
|
||||
return isSecondCompletion;
|
||||
}
|
||||
|
||||
if (grand instanceof PsiAnonymousClass) {
|
||||
@@ -406,7 +407,7 @@ public class JavaCompletionContributor extends CompletionContributor {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (JavaCompletionData.isAfterPrimitiveOrArrayType(position)) {
|
||||
if (JavaCompletionData.isAfterPrimitiveOrArrayType(parameters.getPosition())) {
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
@@ -74,7 +74,7 @@ public class JavaNoVariantsDelegator extends CompletionContributor {
|
||||
|
||||
if (parameters.getInvocationCount() <= 1 &&
|
||||
JavaCompletionContributor.mayStartClassName(result) &&
|
||||
JavaCompletionContributor.isClassNamePossible(position)) {
|
||||
JavaCompletionContributor.isClassNamePossible(parameters)) {
|
||||
suggestNonImportedClasses(parameters, result);
|
||||
return;
|
||||
}
|
||||
|
||||
+10
@@ -41,6 +41,16 @@ public class FragmentCompletionTest extends LightCodeInsightFixtureTestCase {
|
||||
assert !('import' in myFixture.lookupElementStrings)
|
||||
}
|
||||
|
||||
public void "test no classes in reference code fragment"() throws Throwable {
|
||||
myFixture.addClass("package foo; public interface FooIntf { }")
|
||||
|
||||
def text = "FooInt<caret>"
|
||||
PsiFile file = JavaCodeFragmentFactory.getInstance(project).createReferenceCodeFragment(text, null, true, false);
|
||||
myFixture.configureFromExistingVirtualFile(file.getVirtualFile());
|
||||
assert !myFixture.complete(CompletionType.BASIC, 2)
|
||||
myFixture.checkResult(text)
|
||||
}
|
||||
|
||||
public void testNoPackagesInExpressionCodeFragment() throws Throwable {
|
||||
final String text = "jav<caret>";
|
||||
PsiFile file = JavaCodeFragmentFactory.getInstance(project).createExpressionCodeFragment(text, null, null, true);
|
||||
|
||||
Reference in New Issue
Block a user