public void testSelectionWithGenerics() 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); assertEquals(2, itemsToShow.length); assertTrue(itemsToShow[0] instanceof MethodCandidateInfo); final ParameterInfoUIContextEx parameterContext = ParameterInfoComponent.createContext(itemsToShow, myEditor, handler, -1); final MockUpdateParameterInfoContext updateParameterInfoContext = new MockUpdateParameterInfoContext(myEditor, myFile, itemsToShow); updateParameterInfoContext.setParameterOwner(list); handler.updateParameterInfo(list, updateParameterInfoContext); assertTrue(updateParameterInfoContext.isUIComponentEnabled(0) || updateParameterInfoContext.isUIComponentEnabled(1)); }
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); assertEquals(2, itemsToShow.length); 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<T> type, <b>boolean tags</b></html>", MethodParameterInfoHandler .updateMethodPresentation(method, ((MethodCandidateInfo)itemsToShow[0]).getSubstitutor(), parameterContext)); }
private void doTestPresentation(String expectedString, int currentParameterIndex) { 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); assertEquals(1, itemsToShow.length); assertTrue(itemsToShow[0] instanceof MethodCandidateInfo); final PsiMethod method = ((MethodCandidateInfo)itemsToShow[0]).getElement(); final ParameterInfoUIContextEx parameterContext = ParameterInfoComponent.createContext(itemsToShow, myEditor, handler, currentParameterIndex); Assert.assertEquals(expectedString, MethodParameterInfoHandler .updateMethodPresentation(method, ((MethodCandidateInfo)itemsToShow[0]).getSubstitutor(), parameterContext)); }
private String setup(@NotNull String text, @NotNull Map<TextRange, ParameterInfoUIContextEx.Flag> flagsMap, @NotNull Color background) { myLabel.setBackground(background); setBackground(background); myLabel.setForeground(JBColor.foreground()); if (flagsMap.isEmpty()) { myLabel.setText(XmlStringUtil.wrapInHtml(text)); } else { String labelText = buildLabelText(text, flagsMap); myLabel.setText(labelText); } //IDEA-95904 Darcula parameter info pop-up colors hard to read if (UIUtil.isUnderDarcula()) { myLabel.setText(myLabel.getText().replace("<b>", "<b color=ffC800>")); } return myLabel.getText(); }
private String setup(@Nonnull String text, @Nonnull Map<TextRange, ParameterInfoUIContextEx.Flag> flagsMap, @Nonnull Color background) { myLabel.setBackground(background); setBackground(background); myLabel.setForeground(JBColor.foreground()); if (flagsMap.isEmpty()) { myLabel.setText(XmlStringUtil.wrapInHtml(text)); } else { String labelText = buildLabelText(text, flagsMap); myLabel.setText(labelText); } //IDEA-95904 Darcula parameter info pop-up colors hard to read if (UIUtil.isUnderDarcula()) { myLabel.setText(myLabel.getText().replace("<b>", "<b color=ffC800>")); } return myLabel.getText(); }
private static String invokeParameterInfoForAnnotations() { 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); assertEquals(1, itemsToShow.length); assertTrue(itemsToShow[0] instanceof PsiAnnotationMethod); final PsiAnnotationMethod method = (PsiAnnotationMethod)itemsToShow[0]; final ParameterInfoUIContextEx parameterContext = ParameterInfoComponent.createContext(itemsToShow, myEditor, handler, -1); return AnnotationParameterInfoHandler.updateUIText(method, parameterContext); }
@TestOnly public static ParameterInfoUIContextEx createContext(Object[] objects, Editor editor, @NotNull ParameterInfoHandler handler, int currentParameterIndex, @Nullable PsiElement parameterOwner) { final ParameterInfoComponent infoComponent = new ParameterInfoComponent(objects, editor, handler); infoComponent.setCurrentParameterIndex(currentParameterIndex); infoComponent.setParameterOwner(parameterOwner); return infoComponent.new MyParameterContext(); }
private String setup(String text, boolean isDisabled, boolean isStrikeout, Color background, @Nullable TextRange range) { Map<TextRange, ParameterInfoUIContextEx.Flag> flagsMap = new TreeMap<TextRange, ParameterInfoUIContextEx.Flag>(TEXT_RANGE_COMPARATOR); if (range != null) flagsMap.put(range, ParameterInfoUIContextEx.Flag.HIGHLIGHT); if (isDisabled) flagsMap.put(TextRange.create(0, text.length()), ParameterInfoUIContextEx.Flag.DISABLE); if (isStrikeout) flagsMap.put(TextRange.create(0, text.length()), ParameterInfoUIContextEx.Flag.STRIKEOUT); return setup(text, flagsMap, background); }
static void patchQuickInfo() throws Exception { final String accentColor = MTConfig.getInstance().getAccentColor(); final Field[] fields = ParameterInfoComponent.class.getDeclaredFields(); final Object[] objects = Arrays.stream(fields) .filter(f -> f.getType().equals(Map.class)) .toArray(); StaticPatcher.setFinalStatic((Field) objects[0], ImmutableMap.of( ParameterInfoUIContextEx.Flag.HIGHLIGHT, "b color=" + accentColor, ParameterInfoUIContextEx.Flag.DISABLE, "font color=gray", ParameterInfoUIContextEx.Flag.STRIKEOUT, "strike")); }
private void setup(String text, int startOffset, int endOffset, boolean isDisabled, boolean isStrikeout, Color background) { Map<TextRange, ParameterInfoUIContextEx.Flag> flagsMap = new TreeMap<TextRange, ParameterInfoUIContextEx.Flag>(TEXT_RANGE_COMPARATOR); final TextRange highlight = TextRange.create(startOffset, endOffset); if (!highlight.isEmpty()) flagsMap.put(highlight, ParameterInfoUIContextEx.Flag.HIGHLIGHT); if (isDisabled) flagsMap.put(TextRange.create(0, text.length()), ParameterInfoUIContextEx.Flag.DISABLE); if (isStrikeout) flagsMap.put(TextRange.create(0, text.length()), ParameterInfoUIContextEx.Flag.STRIKEOUT); setup(text, flagsMap, background); }
private void setup(@NotNull String text, @NotNull Map<TextRange, ParameterInfoUIContextEx.Flag> flagsMap, @NotNull Color background) { myLabel.setBackground(background); setBackground(background); myLabel.setForeground(FOREGROUND_COLOR); if (flagsMap.isEmpty()) { myLabel.setText(XmlStringUtil.wrapInHtml(XmlStringUtil.escapeString(text))); } else { String labelText = buildLabelText(text, flagsMap); myLabel.setText(labelText); } }
@TestOnly public static ParameterInfoUIContextEx createContext(Object[] objects, Editor editor, @Nonnull ParameterInfoHandler handler, int currentParameterIndex, @Nullable PsiElement parameterOwner) { final ParameterInfoComponent infoComponent = new ParameterInfoComponent(objects, editor, handler); infoComponent.setCurrentParameterIndex(currentParameterIndex); infoComponent.setParameterOwner(parameterOwner); return infoComponent.new MyParameterContext(); }
@TestOnly public static ParameterInfoUIContextEx createContext(Object[] objects, Editor editor, @NotNull ParameterInfoHandler handler, int currentParameterIndex) { return createContext(objects, editor, handler, currentParameterIndex, null); }
public void setup(final String[] texts, final EnumSet<ParameterInfoUIContextEx.Flag>[] flags, final Color background) { removeAll(); final String[] lines = UIUtil.splitText(StringUtil.join(texts), getFontMetrics(BOLD_FONT), myWidthLimit, ','); int index = 0; int curOffset = 0; myOneLineComponents = new OneLineComponent[lines.length]; Map<TextRange, ParameterInfoUIContextEx.Flag> flagsMap = new TreeMap<TextRange, ParameterInfoUIContextEx.Flag>(TEXT_RANGE_COMPARATOR); int added = 0; for (int i = 0; i < texts.length; i++) { String line = texts[i]; if (lines.length <= index) break; String text = lines[index]; final int paramCount = StringUtil.split(text, ", ").size(); final EnumSet<ParameterInfoUIContextEx.Flag> flag = flags[i]; if (flag.contains(ParameterInfoUIContextEx.Flag.HIGHLIGHT)) { flagsMap.put(TextRange.create(curOffset, curOffset + line.trim().length()), ParameterInfoUIContextEx.Flag.HIGHLIGHT); } if (flag.contains(ParameterInfoUIContextEx.Flag.DISABLE)) { flagsMap.put(TextRange.create(curOffset, curOffset + line.trim().length()), ParameterInfoUIContextEx.Flag.DISABLE); } if (flag.contains(ParameterInfoUIContextEx.Flag.STRIKEOUT)) { flagsMap.put(TextRange.create(curOffset, curOffset + line.trim().length()), ParameterInfoUIContextEx.Flag.STRIKEOUT); } curOffset += line.length(); if (i == paramCount + added - 1) { myOneLineComponents[index] = new OneLineComponent(); setBackground(background); myOneLineComponents[index].setup(text, flagsMap, background); add(myOneLineComponents[index], new GridBagConstraints(0, index, 1, 1, 1, 0, GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0)); index += 1; flagsMap.clear(); curOffset = 1; added += paramCount; } } }
@TestOnly public static ParameterInfoUIContextEx createContext(Object[] objects, Editor editor, @Nonnull ParameterInfoHandler handler, int currentParameterIndex) { return createContext(objects, editor, handler, currentParameterIndex, null); }