fix parameter info after generics (IDEA-114245)

This commit is contained in:
anna
2013-10-02 17:13:30 +02:00
parent 99ab7e92a4
commit 58f4563df7
4 changed files with 37 additions and 5 deletions

View File

@@ -387,7 +387,7 @@ public class MethodParameterInfoHandler implements ParameterInfoHandlerWithTabAc
for (int j = 0; j < numParams; j++) {
PsiParameter param = parms[j];
int startOffset = buffer.length();
int startOffset = XmlStringUtil.escapeString(buffer.toString()).length();
if (param.isValid()) {
PsiType paramType = param.getType();

View File

@@ -0,0 +1,11 @@
import java.util.*;
class First {
public static <T> List<T> first(final Class<T> type, boolean tags) {
return null;
}
public static <T> List<T> first(final Class<T> type) {
return first(type, <caret>true);
}
}

View File

@@ -54,6 +54,25 @@ public class ParameterInfoTest extends LightCodeInsightTestCase {
doTestPresentation("<html>List&lt;String&gt; param</html>");
}
public void testAfterGenericsInsideCall() throws Exception {
configureByFile(BASE_PATH + getTestName(false) + ".java");
final MethodParameterInfoHandler handler = new MethodParameterInfoHandler();
final CreateParameterInfoContext context = new MockCreateParameterInfoContext(myEditor, myFile);
final PsiExpressionList list = handler.findElementForParameterInfo(context);
assertNotNull(list);
final Object[] itemsToShow = context.getItemsToShow();
assertNotNull(itemsToShow);
assertTrue(itemsToShow.length == 2);
assertTrue(itemsToShow[0] instanceof MethodCandidateInfo);
final PsiMethod method = ((MethodCandidateInfo)itemsToShow[0]).getElement();
final ParameterInfoUIContextEx parameterContext = ParameterInfoComponent.createContext(itemsToShow, myEditor, handler, 1);
parameterContext.setUIComponentEnabled(true);
Assert.assertEquals("<html>Class&lt;T&gt; type, <b>boolean tags</b></html>",
MethodParameterInfoHandler
.updateMethodPresentation(method, ((MethodCandidateInfo)itemsToShow[0]).getSubstitutor(), parameterContext));
}
public void testGenericsOutsideCall() throws Exception {
doTestPresentation("<html>List&lt;String&gt; param</html>");
}
@@ -70,7 +89,7 @@ public class ParameterInfoTest extends LightCodeInsightTestCase {
assertTrue(itemsToShow.length == 1);
assertTrue(itemsToShow[0] instanceof MethodCandidateInfo);
final PsiMethod method = ((MethodCandidateInfo)itemsToShow[0]).getElement();
final ParameterInfoUIContextEx parameterContext = ParameterInfoComponent.createContext(itemsToShow, myEditor, handler);
final ParameterInfoUIContextEx parameterContext = ParameterInfoComponent.createContext(itemsToShow, myEditor, handler, -1);
Assert.assertEquals(expectedString,
MethodParameterInfoHandler
.updateMethodPresentation(method, ((MethodCandidateInfo)itemsToShow[0]).getSubstitutor(), parameterContext));
@@ -92,7 +111,7 @@ public class ParameterInfoTest extends LightCodeInsightTestCase {
assertTrue(itemsToShow.length == 1);
assertTrue(itemsToShow[0] instanceof PsiAnnotationMethod);
final PsiAnnotationMethod method = (PsiAnnotationMethod)itemsToShow[0];
final ParameterInfoUIContextEx parameterContext = ParameterInfoComponent.createContext(itemsToShow, myEditor, handler);
final ParameterInfoUIContextEx parameterContext = ParameterInfoComponent.createContext(itemsToShow, myEditor, handler, -1);
Assert.assertEquals(expectedString,
AnnotationParameterInfoHandler.updateUIText(method, parameterContext));
}

View File

@@ -75,8 +75,10 @@ public class ParameterInfoComponent extends JPanel {
};
@TestOnly
public static ParameterInfoUIContextEx createContext(Object[] objects, Editor editor, @NotNull ParameterInfoHandler handler) {
return new ParameterInfoComponent(objects, editor, handler).new MyParameterContext();
public static ParameterInfoUIContextEx createContext(Object[] objects, Editor editor, @NotNull ParameterInfoHandler handler, int currentParameterIndex) {
final ParameterInfoComponent infoComponent = new ParameterInfoComponent(objects, editor, handler);
infoComponent.setCurrentParameterIndex(currentParameterIndex);
return infoComponent.new MyParameterContext();
}
ParameterInfoComponent(Object[] objects, Editor editor, @NotNull ParameterInfoHandler handler) {