mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
find of constructor with one vararg parameter should assume implicit usages (IDEA-158585)
This commit is contained in:
+14
@@ -64,6 +64,9 @@ class ConstructorReferencesSearchHelper {
|
||||
@Override
|
||||
public Void compute() {
|
||||
constructorCanBeCalledImplicitly[0] = constructor.getParameterList().getParametersCount() == 0;
|
||||
if (!constructorCanBeCalledImplicitly[0]) {
|
||||
constructorCanBeCalledImplicitly[0] = hasDefaultConstructorWithVarargParameter(containingClass);
|
||||
}
|
||||
isEnum[0] = containingClass.isEnum();
|
||||
isUnder18[0] = PsiUtil.getLanguageLevel(containingClass).isAtLeast(LanguageLevel.JDK_1_8);
|
||||
return null;
|
||||
@@ -124,6 +127,17 @@ class ConstructorReferencesSearchHelper {
|
||||
return ClassInheritorsSearch.search(containingClass, searchScope, false).forEach(processor2);
|
||||
}
|
||||
|
||||
private static boolean hasDefaultConstructorWithVarargParameter(@NotNull PsiClass containingClass) {
|
||||
final PsiMethod[] constructors = containingClass.getConstructors();
|
||||
for (PsiMethod ctr : constructors) {
|
||||
final PsiParameter[] parameters = ctr.getParameterList().getParameters();
|
||||
if (parameters.length == 1 && parameters[0].isVarArgs()) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private static boolean processEnumReferences(@NotNull final Processor<PsiReference> processor,
|
||||
@NotNull final PsiMethod constructor,
|
||||
@NotNull final Project project,
|
||||
|
||||
@@ -0,0 +1,31 @@
|
||||
/*
|
||||
* Copyright 2000-2016 JetBrains s.r.o.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package com.intellij.psi.search
|
||||
|
||||
import com.intellij.psi.search.searches.MethodReferencesSearch
|
||||
import com.intellij.testFramework.fixtures.LightCodeInsightFixtureTestCase
|
||||
|
||||
class FindFixtureBasedTest : LightCodeInsightFixtureTestCase() {
|
||||
fun testDefaultConstructorWithVarargsParameters() {
|
||||
val aClass = myFixture.addClass("public class Foo {public Foo(int... a) {}}")
|
||||
myFixture.addClass("public class Bar extends Foo {}")
|
||||
|
||||
val constructors = aClass.constructors
|
||||
assertSize(1, constructors)
|
||||
val references = MethodReferencesSearch.search(constructors[0]).findAll()
|
||||
assertSize(1, references)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user