find usages: explicit this/super means that super/this were not called implicitly

This commit is contained in:
Anna Kozlova
2016-08-24 21:16:13 +03:00
parent 6dcdf8b436
commit 1a51428899
2 changed files with 19 additions and 2 deletions
@@ -110,7 +110,7 @@ class ConstructorReferencesSearchHelper {
if (!DumbService.getInstance(project).runReadActionInSmartMode(
() -> processSuperOrThis(containingClass, constructor, constructorCanBeCalledImplicitly[0], searchScope, project,
isStrictSignatureSearch,
PsiKeyword.THIS, processor))) {
PsiKeyword.THIS, PsiKeyword.SUPER, processor))) {
return false;
}
@@ -119,7 +119,7 @@ class ConstructorReferencesSearchHelper {
final PsiElement navigationElement = inheritor.getNavigationElement();
if (navigationElement instanceof PsiClass) {
return processSuperOrThis((PsiClass)navigationElement, constructor, constructorCanBeCalledImplicitly[0], searchScope, project,
isStrictSignatureSearch, PsiKeyword.SUPER, processor);
isStrictSignatureSearch, PsiKeyword.SUPER, PsiKeyword.THIS, processor);
}
return true;
};
@@ -186,6 +186,7 @@ class ConstructorReferencesSearchHelper {
@NotNull Project project,
final boolean isStrictSignatureSearch,
@NotNull String superOrThisKeyword,
@NotNull String thisOrSuperKeyword,
@NotNull Processor<PsiReference> processor) {
PsiMethod[] constructors = inheritor.getConstructors();
if (constructors.length == 0 && constructorCanBeCalledImplicitly) {
@@ -216,6 +217,9 @@ class ConstructorReferencesSearchHelper {
//as long as we've encountered super/this keyword, no implicit ctr calls are possible here
continue;
}
else if (refExpr.textMatches(thisOrSuperKeyword)) {
continue;
}
}
}
}
@@ -28,4 +28,17 @@ class FindFixtureBasedTest : LightCodeInsightFixtureTestCase() {
val references = MethodReferencesSearch.search(constructors[0]).findAll()
assertSize(1, references)
}
fun testDefaultConstructorNotInvoked() {
val aClass = myFixture.addClass("public class A {\n" +
" public A() {}\n" +
" public A(String s){}\n" +
" public A(int i) {this(null);}\n" +
"}")
myFixture.addClass("class B extends A {public B(){this(\"\");} public B(String s) {super(s);} }")
val constructors = aClass.constructors
assertSize(3, constructors)
assertNull(MethodReferencesSearch.search(constructors[0]).findFirst())
}
}