From 1a51428899bd6e4d9c598a33092edfe0e7552f4a Mon Sep 17 00:00:00 2001 From: Anna Kozlova Date: Wed, 24 Aug 2016 20:04:25 +0300 Subject: [PATCH] find usages: explicit this/super means that super/this were not called implicitly --- .../search/ConstructorReferencesSearchHelper.java | 8 ++++++-- .../com/intellij/psi/search/FindFixtureBasedTest.kt | 13 +++++++++++++ 2 files changed, 19 insertions(+), 2 deletions(-) diff --git a/java/java-indexing-impl/src/com/intellij/psi/impl/search/ConstructorReferencesSearchHelper.java b/java/java-indexing-impl/src/com/intellij/psi/impl/search/ConstructorReferencesSearchHelper.java index f382ecf5ea98..c2a01117d72b 100644 --- a/java/java-indexing-impl/src/com/intellij/psi/impl/search/ConstructorReferencesSearchHelper.java +++ b/java/java-indexing-impl/src/com/intellij/psi/impl/search/ConstructorReferencesSearchHelper.java @@ -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 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; + } } } } diff --git a/java/java-tests/testSrc/com/intellij/psi/search/FindFixtureBasedTest.kt b/java/java-tests/testSrc/com/intellij/psi/search/FindFixtureBasedTest.kt index 0854777bfbf1..eb8fb56470a0 100644 --- a/java/java-tests/testSrc/com/intellij/psi/search/FindFixtureBasedTest.kt +++ b/java/java-tests/testSrc/com/intellij/psi/search/FindFixtureBasedTest.kt @@ -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()) + } }