IDEA-134123 Reflection code completion generates Type....class instead of Type[].class for varargs

This commit is contained in:
peter
2015-01-02 17:16:54 +01:00
parent 0a175d30bc
commit faa69a6aa2
4 changed files with 63 additions and 3 deletions

View File

@@ -23,9 +23,11 @@ import com.intellij.codeInsight.lookup.LookupElementBuilder;
import com.intellij.openapi.project.Project;
import com.intellij.psi.*;
import com.intellij.psi.codeStyle.JavaCodeStyleManager;
import com.intellij.psi.impl.source.PsiClassReferenceType;
import com.intellij.psi.search.GlobalSearchScope;
import com.intellij.psi.util.*;
import com.intellij.psi.util.PsiTreeUtil;
import com.intellij.psi.util.PsiTypesUtil;
import com.intellij.psi.util.PsiUtilCore;
import com.intellij.psi.util.TypeConversionUtil;
import com.intellij.util.IncorrectOperationException;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
@@ -169,7 +171,11 @@ public class JavaLangClassMemberReference extends PsiReferenceBase<PsiLiteralExp
private static String getMethodTypes(PsiMethod method) {
final StringBuilder buf = new StringBuilder();
for (PsiParameter parameter : method.getParameterList().getParameters()) {
buf.append(", ").append(TypeConversionUtil.erasure(parameter.getType()).getPresentableText()).append(".class");
PsiType type = TypeConversionUtil.erasure(parameter.getType());
if (type instanceof PsiEllipsisType) {
type = new PsiArrayType(((PsiEllipsisType)type).getComponentType());
}
buf.append(", ").append(type.getPresentableText()).append(".class");
}
return buf.toString();
}

View File

@@ -0,0 +1,25 @@
/*
* Copyright 2000-2012 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.
*/
class ForNameMethod {
void foo() {
Class.forName("Test").getMethod("va<caret>");
}
}
class Test {
public void vararg(String... b){}
public void vararg2(String... b){}
}

View File

@@ -0,0 +1,25 @@
/*
* Copyright 2000-2012 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.
*/
class ForNameMethod {
void foo() {
Class.forName("Test").getMethod("vararg<caret>", String[].class);
}
}
class Test {
public void vararg(String... b){}
public void vararg2(String... b){}
}

View File

@@ -63,6 +63,10 @@ public class JavaReflectionCompletionTest extends LightFixtureCompletionTestCase
doTest(2, "num", "num2", "num3");
}
public void testVarargMethod() throws Exception {
doTest(0, "vararg", "vararg2");
}
public void testGenerics() throws Exception {
myFixture.addFileToProject("a.properties", "foo=bar"); // check that property variants don't override reflection ones
doTest(0, "foo");