parameter popup: escape for annotation methods (IDEA-113971)

This commit is contained in:
anna
2013-09-25 11:08:46 +02:00
parent f6537137a0
commit 8913712ee6
3 changed files with 42 additions and 5 deletions
@@ -21,6 +21,7 @@ import com.intellij.openapi.project.DumbAware;
import com.intellij.psi.*;
import com.intellij.psi.util.PsiUtil;
import com.intellij.util.text.CharArrayUtil;
import com.intellij.xml.util.XmlStringUtil;
import org.jetbrains.annotations.NonNls;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
@@ -110,14 +111,18 @@ public class AnnotationParameterInfoHandler implements ParameterInfoHandler<PsiA
@Override
public void updateUI(final PsiAnnotationMethod p, final ParameterInfoUIContext context) {
@NonNls StringBuffer buffer = new StringBuffer();
updateUIText(p, context);
}
public static String updateUIText(PsiAnnotationMethod p, ParameterInfoUIContext context) {
@NonNls StringBuilder buffer = new StringBuilder();
int highlightStartOffset;
int highlightEndOffset;
buffer.append(p.getReturnType().getPresentableText());
buffer.append(" ");
highlightStartOffset = buffer.length();
highlightStartOffset = XmlStringUtil.escapeString(buffer.toString()).length();
buffer.append(p.getName());
highlightEndOffset = buffer.length();
highlightEndOffset = XmlStringUtil.escapeString(buffer.toString()).length();
buffer.append("()");
if (p.getDefaultValue() != null) {
@@ -125,8 +130,8 @@ public class AnnotationParameterInfoHandler implements ParameterInfoHandler<PsiA
buffer.append(p.getDefaultValue().getText());
}
context.setupUIComponentPresentation(buffer.toString(), highlightStartOffset, highlightEndOffset, false, p.isDeprecated(),
false, context.getDefaultParameterColor());
return context.setupUIComponentPresentation(buffer.toString(), highlightStartOffset, highlightEndOffset, false, p.isDeprecated(),
false, context.getDefaultParameterColor());
}
private static PsiAnnotationMethod findAnnotationMethod(PsiFile file, int offset) {
@@ -0,0 +1,10 @@
import java.util.List;
@interface PrepareForTest {
Class<List<String[]>> value();
}
abstract class A implements List<String>{}
@PrepareForTest({A<caret>.class})
class Main {}
@@ -1,6 +1,7 @@
package com.intellij.codeInsight;
import com.intellij.codeInsight.hint.ParameterInfoComponent;
import com.intellij.codeInsight.hint.api.impls.AnnotationParameterInfoHandler;
import com.intellij.codeInsight.hint.api.impls.MethodParameterInfoHandler;
import com.intellij.lang.parameterInfo.CreateParameterInfoContext;
import com.intellij.lang.parameterInfo.ParameterInfoUIContextEx;
@@ -74,4 +75,25 @@ public class ParameterInfoTest extends LightCodeInsightTestCase {
MethodParameterInfoHandler
.updateMethodPresentation(method, ((MethodCandidateInfo)itemsToShow[0]).getSubstitutor(), parameterContext));
}
public void testAnnotationWithGenerics() throws Exception {
doTestAnnotationPresentation("<html>Class&lt;List&lt;String[]&gt;&gt; <b>value</b>()</html>");
}
private void doTestAnnotationPresentation(String expectedString) {
configureByFile(BASE_PATH + getTestName(false) + ".java");
final AnnotationParameterInfoHandler handler = new AnnotationParameterInfoHandler();
final CreateParameterInfoContext context = new MockCreateParameterInfoContext(myEditor, myFile);
final PsiAnnotationParameterList list = handler.findElementForParameterInfo(context);
assertNotNull(list);
final Object[] itemsToShow = context.getItemsToShow();
assertNotNull(itemsToShow);
assertTrue(itemsToShow.length == 1);
assertTrue(itemsToShow[0] instanceof PsiAnnotationMethod);
final PsiAnnotationMethod method = (PsiAnnotationMethod)itemsToShow[0];
final ParameterInfoUIContextEx parameterContext = ParameterInfoComponent.createContext(itemsToShow, myEditor, handler);
Assert.assertEquals(expectedString,
AnnotationParameterInfoHandler.updateUIText(method, parameterContext));
}
}