mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
parameter popup: escape for annotation methods (IDEA-113971)
This commit is contained in:
+10
-5
@@ -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<List<String[]>> <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));
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user