public void startTemplateWithPrefix(
     final Editor editor,
     final TemplateImpl template,
     final int templateStart,
     @Nullable final PairProcessor<String, String> processor,
     @Nullable final String argument) {
   final int caretOffset = editor.getCaretModel().getOffset();
   final TemplateState templateState = initTemplateState(editor);
   CommandProcessor commandProcessor = CommandProcessor.getInstance();
   commandProcessor.executeCommand(
       myProject,
       () -> {
         editor.getDocument().deleteString(templateStart, caretOffset);
         editor.getCaretModel().moveToOffset(templateStart);
         editor.getScrollingModel().scrollToCaret(ScrollType.RELATIVE);
         editor.getSelectionModel().removeSelection();
         Map<String, String> predefinedVarValues = null;
         if (argument != null) {
           predefinedVarValues = new HashMap<String, String>();
           predefinedVarValues.put(TemplateImpl.ARG, argument);
         }
         templateState.start(template, processor, predefinedVarValues);
       },
       CodeInsightBundle.message("insert.code.template.command"),
       null);
 }
 public static String calcText(
     PsiModifierListOwner modifierListOwner, @NotNull String annotation) {
   final String shortName = annotation.substring(annotation.lastIndexOf('.') + 1);
   if (modifierListOwner instanceof PsiNamedElement) {
     final String name = ((PsiNamedElement) modifierListOwner).getName();
     if (name != null) {
       FindUsagesProvider provider =
           LanguageFindUsages.INSTANCE.forLanguage(modifierListOwner.getLanguage());
       return CodeInsightBundle.message(
           "inspection.i18n.quickfix.annotate.element.as",
           provider.getType(modifierListOwner),
           name,
           shortName);
     }
   }
   return CodeInsightBundle.message("inspection.i18n.quickfix.annotate.as", shortName);
 }
 protected void buildStatusText(@Nullable String elementName, int refCount) {
   if (refCount > 0) {
     myStatusText =
         CodeInsightBundle.message(
             elementName != null
                 ? "status.bar.highlighted.usages.message"
                 : "status.bar.highlighted.usages.no.target.message",
             refCount,
             elementName,
             HighlightUsagesHandler.getShortcutText());
   } else {
     myHintText =
         CodeInsightBundle.message(
             elementName != null
                 ? "status.bar.highlighted.usages.not.found.message"
                 : "status.bar.highlighted.usages.not.found.no.target.message",
             elementName);
   }
 }
 private boolean checkFileWritable(final PsiFile file) {
   if (!file.isWritable()) {
     MessagesEx.fileIsReadOnly(myProject, file.getVirtualFile())
         .setTitle(CodeInsightBundle.message("error.dialog.readonly.file.title"))
         .showLater();
     return false;
   } else {
     return true;
   }
 }
 public ExternalDocAction() {
   super(
       CodeInsightBundle.message("javadoc.action.view.external"),
       null,
       AllIcons.Actions.Browser_externalJavaDoc);
   registerCustomShortcutSet(
       ActionManager.getInstance()
           .getAction(IdeActions.ACTION_EXTERNAL_JAVADOC)
           .getShortcutSet(),
       null);
 }
  public static void doI18nSelectedString(
      final @NotNull Project project,
      final @NotNull Editor editor,
      final @NotNull PsiFile psiFile,
      final @NotNull I18nQuickFixHandler handler) {
    try {
      handler.checkApplicability(psiFile, editor);
    } catch (IncorrectOperationException ex) {
      CommonRefactoringUtil.showErrorHint(
          project, editor, ex.getMessage(), CodeInsightBundle.message("i18nize.error.title"), null);
      return;
    }

    final JavaI18nizeQuickFixDialog dialog = handler.createDialog(project, editor, psiFile);
    if (dialog == null) return;
    dialog.show();
    if (!dialog.isOK()) return;

    if (!CodeInsightUtilBase.prepareFileForWrite(psiFile)) return;
    final Collection<PropertiesFile> propertiesFiles = dialog.getAllPropertiesFiles();
    for (PropertiesFile file : propertiesFiles) {
      if (!CodeInsightUtilBase.prepareFileForWrite(file.getContainingFile())) return;
    }

    ApplicationManager.getApplication()
        .runWriteAction(
            new Runnable() {
              public void run() {
                CommandProcessor.getInstance()
                    .executeCommand(
                        project,
                        new Runnable() {
                          public void run() {
                            try {
                              handler.performI18nization(
                                  psiFile,
                                  editor,
                                  dialog.getLiteralExpression(),
                                  propertiesFiles,
                                  dialog.getKey(),
                                  dialog.getValue(),
                                  dialog.getI18nizedText(),
                                  dialog.getParameters(),
                                  dialog.getPropertyCreationHandler());
                            } catch (IncorrectOperationException e) {
                              LOG.error(e);
                            }
                          }
                        },
                        CodeInsightBundle.message("quickfix.i18n.command.name"),
                        project);
              }
            });
  }
 @Override
 public boolean isAvailable(@NotNull Project project, Editor editor, @NotNull PsiElement element) {
   PsiClass classToImport = getClassToPerformStaticImport(element);
   if (classToImport != null) {
     String text =
         CodeInsightBundle.message(
             "intention.add.on.demand.static.import.text", classToImport.getQualifiedName());
     setText(text);
   }
   return classToImport != null;
 }
  @Override
  protected JComponent createCenterPanel() {
    myTitle.setText(myText);
    myOptionsPanel.setBorder(
        IdeBorderFactory.createTitledBorder(
            CodeInsightBundle.message("reformat.directory.dialog.options")));
    myFiltersPanel.setBorder(
        IdeBorderFactory.createTitledBorder(
            CodeInsightBundle.message("reformat.directory.dialog.filters")));

    myMaskWarningLabel.setIcon(AllIcons.General.Warning);
    myMaskWarningLabel.setVisible(false);

    myIncludeSubdirsCb.setVisible(shouldShowIncludeSubdirsCb());

    initFileTypeFilter();
    initScopeFilter();

    restoreCbsStates();
    return myWholePanel;
  }
  protected void buildOptions(JPanel searchOptions) {
    super.buildOptions(searchOptions);
    searchOptions.add(
        UIUtil.createOptionLine(
            shortenFQN =
                new JCheckBox(SSRBundle.message("shorten.fully.qualified.names.checkbox"), true)));

    searchOptions.add(
        UIUtil.createOptionLine(
            formatAccordingToStyle =
                new JCheckBox(
                    CodeInsightBundle.message(
                        "dialog.edit.template.checkbox.reformat.according.to.style"),
                    true)));

    searchOptions.add(
        UIUtil.createOptionLine(
            useStaticImport =
                new JCheckBox(
                    CodeInsightBundle.message("dialog.edit.template.checkbox.use.static.import"),
                    true)));
  }
 private static String getMethodCandidateInfo(GrReferenceExpression expr) {
   final GroovyResolveResult[] candidates = expr.multiResolve(false);
   final String text = expr.getText();
   if (candidates.length > 0) {
     @NonNls final StringBuilder sb = new StringBuilder();
     for (final GroovyResolveResult candidate : candidates) {
       final PsiElement element = candidate.getElement();
       if (!(element instanceof PsiMethod)) {
         continue;
       }
       final String str =
           PsiFormatUtil.formatMethod(
               (PsiMethod) element,
               candidate.getSubstitutor(),
               PsiFormatUtilBase.SHOW_NAME
                   | PsiFormatUtilBase.SHOW_TYPE
                   | PsiFormatUtilBase.SHOW_PARAMETERS,
               PsiFormatUtilBase.SHOW_TYPE);
       createElementLink(sb, element, str);
     }
     return CodeInsightBundle.message("javadoc.candidates", text, sb);
   }
   return CodeInsightBundle.message("javadoc.candidates.not.found", text);
 }
Beispiel #11
0
  @Override
  public void actionPerformed(final AnActionEvent e) {
    DataContext dataContext = e.getDataContext();

    final ListPopup popup =
        JBPopupFactory.getInstance()
            .createActionGroupPopup(
                CodeInsightBundle.message("generate.list.popup.title"),
                wrapGroup(getGroup(), dataContext),
                dataContext,
                JBPopupFactory.ActionSelectionAid.SPEEDSEARCH,
                false);

    popup.showInBestPositionFor(dataContext);
  }
  public LayoutProjectCodeDialog(
      @NotNull Project project,
      @NotNull String title,
      @NotNull String text,
      boolean enableOnlyVCSChangedTextCb) {
    super(project, false);
    myText = text;
    myProject = project;
    myEnableOnlyVCSChangedTextCb = enableOnlyVCSChangedTextCb;
    myLastRunOptions = new LastRunReformatCodeOptionsProvider(PropertiesComponent.getInstance());

    setOKButtonText(CodeInsightBundle.message("reformat.code.accept.button.text"));
    setTitle(title);
    init();
  }
  private void runProcessFile(@NotNull final PsiFile file) {
    Document document = PsiDocumentManager.getInstance(myProject).getDocument(file);

    if (document == null) {
      return;
    }

    if (!FileDocumentManager.getInstance().requestWriting(document, myProject)) {
      Messages.showMessageDialog(
          myProject,
          PsiBundle.message("cannot.modify.a.read.only.file", file.getName()),
          CodeInsightBundle.message("error.dialog.readonly.file.title"),
          Messages.getErrorIcon());
      return;
    }

    final Ref<FutureTask<Boolean>> writeActionRunnable = new Ref<FutureTask<Boolean>>();
    Runnable readAction =
        new Runnable() {
          @Override
          public void run() {
            if (!checkFileWritable(file)) return;
            try {
              FutureTask<Boolean> writeTask = preprocessFile(file, myProcessChangedTextOnly);
              writeActionRunnable.set(writeTask);
            } catch (IncorrectOperationException e) {
              LOG.error(e);
            }
          }
        };
    Runnable writeAction =
        new Runnable() {
          @Override
          public void run() {
            if (writeActionRunnable.isNull()) return;
            FutureTask<Boolean> task = writeActionRunnable.get();
            task.run();
            try {
              task.get();
            } catch (CancellationException ignored) {
            } catch (Exception e) {
              LOG.error(e);
            }
          }
        };
    runLayoutCodeProcess(readAction, writeAction, false);
  }
  public LayoutCodeDialog(
      @NotNull Project project,
      @NotNull String title,
      @Nullable PsiFile file,
      @Nullable PsiDirectory directory,
      Boolean isTextSelected,
      final String helpId) {
    super(project, true);
    myFile = file;
    myDirectory = directory;
    myTextSelected = isTextSelected;

    setOKButtonText(CodeInsightBundle.message("reformat.code.accept.button.text"));
    setTitle(title);
    init();
    myHelpId = helpId;
  }
 private static void chooseAmbiguousTarget(
     final Editor editor, int offset, PsiElement[] elements, PsiFile currentFile) {
   PsiElementProcessor<PsiElement> navigateProcessor =
       element -> {
         gotoTargetElement(element, editor, currentFile);
         return true;
       };
   boolean found =
       chooseAmbiguousTarget(
           editor,
           offset,
           navigateProcessor,
           CodeInsightBundle.message("declaration.navigation.title"),
           elements);
   if (!found) {
     HintManager.getInstance().showErrorHint(editor, "Cannot find declaration to go to");
   }
 }
  @Override
  public boolean isAvailable(@NotNull Project project, Editor editor, @NotNull PsiElement element) {
    if (!super.isAvailable(project, editor, element)) {
      return false;
    }

    final PsiNewExpression expression =
        PsiTreeUtil.getParentOfType(element, PsiNewExpression.class, false);
    if (expression == null) {
      return false;
    }

    final PsiExpressionList arguments = expression.getArgumentList();
    if (arguments == null) {
      return false;
    }

    final PsiMethod constructor = expression.resolveConstructor();
    if (constructor == null) {
      return false;
    }

    final PsiExpressionList newArguments =
        createNewArguments(
            JavaPsiFacade.getElementFactory(project),
            constructor.getParameterList().getParameters(),
            arguments.getExpressions());

    if (newArguments == null) {
      return false;
    }

    setText(
        CodeInsightBundle.message(
            "intention.convert.color.representation.text", newArguments.getText()));

    return true;
  }
  private void startTemplate(
      final Editor editor,
      final String selectionString,
      final Template template,
      boolean inSeparateCommand,
      TemplateEditingListener listener,
      final PairProcessor<String, String> processor,
      final Map<String, String> predefinedVarValues) {
    final TemplateState templateState = initTemplateState(editor);

    //noinspection unchecked
    templateState.getProperties().put(ExpressionContext.SELECTION, selectionString);

    if (listener != null) {
      templateState.addTemplateStateListener(listener);
    }
    Runnable r =
        () -> {
          if (selectionString != null) {
            ApplicationManager.getApplication()
                .runWriteAction(() -> EditorModificationUtil.deleteSelectedText(editor));
          } else {
            editor.getSelectionModel().removeSelection();
          }
          templateState.start((TemplateImpl) template, processor, predefinedVarValues);
        };
    if (inSeparateCommand) {
      CommandProcessor.getInstance()
          .executeCommand(
              myProject, r, CodeInsightBundle.message("insert.code.template.command"), null);
    } else {
      r.run();
    }

    if (shouldSkipInTests()) {
      if (!templateState.isFinished()) templateState.gotoEnd(false);
    }
  }
 public ForwardAction() {
   super(CodeInsightBundle.message("javadoc.action.forward"), null, AllIcons.Actions.Forward);
 }
 public BackAction() {
   super(CodeInsightBundle.message("javadoc.action.back"), null, AllIcons.Actions.Back);
 }
 public ShowSourceAction() {
   super(
       false,
       AllIcons.Actions.ShowSource,
       CodeInsightBundle.message("quick.definition.show.source"));
 }
 public EditSourceAction() {
   super(
       true,
       AllIcons.Actions.EditSource,
       CodeInsightBundle.message("quick.definition.edit.source"));
 }
 public ForwardAction() {
   super(CodeInsightBundle.message("quick.definition.forward"), null, AllIcons.Actions.Forward);
 }
 public BackAction() {
   super(CodeInsightBundle.message("quick.definition.back"), null, AllIcons.Actions.Back);
 }
 private void updateLabels() {
   // TODO: Move from JavaDoc to somewhere more appropriate place.
   ElementLocationUtil.customizeElementLabel(myElements[myIndex], myLocationLabel);
   //noinspection AutoBoxing
   myCountLabel.setText(CodeInsightBundle.message("n.of.m", myIndex + 1, myElements.length));
 }
 public String getDescription() {
   return CodeInsightBundle.message("macro.iterable.component.type");
 }
  @Override
  protected JComponent createCenterPanel() {
    JPanel panel = new JPanel(new GridBagLayout());
    panel.setBorder(BorderFactory.createEmptyBorder(4, 8, 8, 0));
    GridBagConstraints gbConstraints = new GridBagConstraints();
    gbConstraints.gridy = 0;
    gbConstraints.gridx = 0;
    gbConstraints.gridwidth = 3;
    gbConstraints.gridheight = 1;
    gbConstraints.weightx = 1;

    gbConstraints.fill = GridBagConstraints.BOTH;
    gbConstraints.insets = new Insets(0, 0, 0, 0);

    myRbFile =
        new JRadioButton(
            CodeInsightBundle.message(
                "process.scope.file",
                (myFile != null ? "'" + myFile.getVirtualFile().getPresentableUrl() + "'" : "")));
    panel.add(myRbFile, gbConstraints);

    myRbSelectedText = new JRadioButton(CodeInsightBundle.message("reformat.option.selected.text"));
    if (myTextSelected != null) {
      gbConstraints.gridy++;
      gbConstraints.insets = new Insets(0, 0, 0, 0);
      panel.add(myRbSelectedText, gbConstraints);
    }

    myRbDirectory = new JRadioButton();
    myCbIncludeSubdirs =
        new JCheckBox(CodeInsightBundle.message("reformat.option.include.subdirectories"));
    if (myDirectory != null) {
      myRbDirectory.setText(
          CodeInsightBundle.message(
              "reformat.option.all.files.in.directory",
              myDirectory.getVirtualFile().getPresentableUrl()));
      gbConstraints.gridy++;
      gbConstraints.insets = new Insets(0, 0, 0, 0);
      panel.add(myRbDirectory, gbConstraints);

      if (myDirectory.getSubdirectories().length > 0) {
        gbConstraints.gridy++;
        gbConstraints.insets = new Insets(0, 20, 0, 0);
        panel.add(myCbIncludeSubdirs, gbConstraints);
      }
    }

    myCbOptimizeImports =
        new JCheckBox(CodeInsightBundle.message("reformat.option.optimize.imports"));
    if (myTextSelected != null && LanguageImportStatements.INSTANCE.hasAnyExtensions()) {
      gbConstraints.gridy++;
      gbConstraints.insets = new Insets(0, 0, 0, 0);
      panel.add(myCbOptimizeImports, gbConstraints);
    }

    myCbArrangeEntries =
        new JCheckBox(CodeInsightBundle.message("reformat.option.rearrange.entries"));
    if (myFile != null && Rearranger.EXTENSION.forLanguage(myFile.getLanguage()) != null) {
      gbConstraints.gridy++;
      gbConstraints.insets = new Insets(0, 0, 0, 0);
      panel.add(myCbArrangeEntries, gbConstraints);
    }

    myCbOnlyVcsChangedRegions =
        new JCheckBox(CodeInsightBundle.message("reformat.option.vcs.changed.region"));
    gbConstraints.gridy++;
    panel.add(myCbOnlyVcsChangedRegions, gbConstraints);

    ButtonGroup buttonGroup = new ButtonGroup();
    buttonGroup.add(myRbFile);
    buttonGroup.add(myRbSelectedText);
    buttonGroup.add(myRbDirectory);

    myRbFile.setEnabled(myFile != null);
    myRbSelectedText.setEnabled(myTextSelected == Boolean.TRUE);

    return panel;
  }
 @NotNull
 @Override
 public String getText() {
   return CodeInsightBundle.message("intention.introduce.variable.text");
 }
  @Override
  public void updateUI(Object descriptor, ParameterInfoUIContext context) {
    // todo: when we will have ability to pass Array as vararg, implement such feature here too?
    if (context == null
        || context.getParameterOwner() == null
        || !context.getParameterOwner().isValid()) {
      return;
    }
    PsiElement parameterOwner = context.getParameterOwner();
    if (parameterOwner instanceof JetValueArgumentList) {
      JetValueArgumentList argumentList = (JetValueArgumentList) parameterOwner;
      if (descriptor instanceof FunctionDescriptor) {
        JetFile file = (JetFile) argumentList.getContainingFile();
        BindingContext bindingContext = AnalyzeSingleFileUtil.getContextForSingleFile(file);
        FunctionDescriptor functionDescriptor = (FunctionDescriptor) descriptor;
        StringBuilder builder = new StringBuilder();
        List<ValueParameterDescriptor> valueParameters = functionDescriptor.getValueParameters();
        List<JetValueArgument> valueArguments = argumentList.getArguments();
        int currentParameterIndex = context.getCurrentParameterIndex();
        int boldStartOffset = -1;
        int boldEndOffset = -1;
        boolean isGrey = false;
        boolean isDeprecated = false; // todo: add deprecation check
        Color color = context.getDefaultParameterColor();
        PsiElement parent = argumentList.getParent();
        if (parent instanceof JetCallElement) {
          JetCallElement callExpression = (JetCallElement) parent;
          JetExpression calleeExpression = callExpression.getCalleeExpression();
          JetSimpleNameExpression refExpression = null;
          if (calleeExpression instanceof JetSimpleNameExpression) {
            refExpression = (JetSimpleNameExpression) calleeExpression;
          } else if (calleeExpression instanceof JetConstructorCalleeExpression) {
            JetConstructorCalleeExpression constructorCalleeExpression =
                (JetConstructorCalleeExpression) calleeExpression;
            if (constructorCalleeExpression.getConstructorReferenceExpression()
                instanceof JetSimpleNameExpression) {
              refExpression =
                  (JetSimpleNameExpression)
                      constructorCalleeExpression.getConstructorReferenceExpression();
            }
          }
          if (refExpression != null) {
            DeclarationDescriptor declarationDescriptor =
                bindingContext.get(BindingContext.REFERENCE_TARGET, refExpression);
            if (declarationDescriptor != null) {
              if (declarationDescriptor == functionDescriptor) {
                color = GREEN_BACKGROUND;
              }
            }
          }
        }

        boolean[] usedIndexes = new boolean[valueParameters.size()];
        boolean namedMode = false;
        Arrays.fill(usedIndexes, false);
        if ((currentParameterIndex >= valueParameters.size()
                && (valueParameters.size() > 0 || currentParameterIndex > 0))
            && (valueParameters.size() == 0
                || valueParameters.get(valueParameters.size() - 1).getVarargElementType()
                    == null)) {
          isGrey = true;
        }
        if (valueParameters.size() == 0)
          builder.append(CodeInsightBundle.message("parameter.info.no.parameters"));
        for (int i = 0; i < valueParameters.size(); ++i) {
          if (i != 0) builder.append(", ");
          boolean highlightParameter =
              i == currentParameterIndex
                  || (!namedMode
                      && i < currentParameterIndex
                      && valueParameters.get(valueParameters.size() - 1).getVarargElementType()
                          != null);
          if (highlightParameter) boldStartOffset = builder.length();
          if (!namedMode) {
            if (valueArguments.size() > i) {
              JetValueArgument argument = valueArguments.get(i);
              if (argument.isNamed()) {
                namedMode = true;
              } else {
                ValueParameterDescriptor param = valueParameters.get(i);
                builder.append(renderParameter(param, false, bindingContext));
                if (i < currentParameterIndex) {
                  if (argument.getArgumentExpression() != null) {
                    // check type
                    JetType paramType = getActualParameterType(param);
                    JetType exprType =
                        bindingContext.get(
                            BindingContext.EXPRESSION_TYPE, argument.getArgumentExpression());
                    if (exprType != null
                        && !JetTypeChecker.INSTANCE.isSubtypeOf(exprType, paramType)) isGrey = true;
                  } else isGrey = true;
                }
                usedIndexes[i] = true;
              }
            } else {
              ValueParameterDescriptor param = valueParameters.get(i);
              builder.append(renderParameter(param, false, bindingContext));
            }
          }
          if (namedMode) {
            boolean takeAnyArgument = true;
            if (valueArguments.size() > i) {
              JetValueArgument argument = valueArguments.get(i);
              if (argument.isNamed()) {
                for (int j = 0; j < valueParameters.size(); ++j) {
                  JetSimpleNameExpression referenceExpression =
                      argument.getArgumentName().getReferenceExpression();
                  ValueParameterDescriptor param = valueParameters.get(j);
                  if (referenceExpression != null
                      && !usedIndexes[j]
                      && param.getName().equals(referenceExpression.getReferencedNameAsName())) {
                    takeAnyArgument = false;
                    usedIndexes[j] = true;
                    builder.append(renderParameter(param, true, bindingContext));
                    if (i < currentParameterIndex) {
                      if (argument.getArgumentExpression() != null) {
                        // check type
                        JetType paramType = getActualParameterType(param);
                        JetType exprType =
                            bindingContext.get(
                                BindingContext.EXPRESSION_TYPE, argument.getArgumentExpression());
                        if (exprType != null
                            && !JetTypeChecker.INSTANCE.isSubtypeOf(exprType, paramType))
                          isGrey = true;
                      } else isGrey = true;
                    }
                    break;
                  }
                }
              }
            }

            if (takeAnyArgument) {
              if (i < currentParameterIndex) isGrey = true;

              for (int j = 0; j < valueParameters.size(); ++j) {
                ValueParameterDescriptor param = valueParameters.get(j);
                if (!usedIndexes[j]) {
                  usedIndexes[j] = true;
                  builder.append(renderParameter(param, true, bindingContext));
                  break;
                }
              }
            }
          }
          if (highlightParameter) boldEndOffset = builder.length();
        }
        if (builder.toString().isEmpty()) context.setUIComponentEnabled(false);
        else
          context.setupUIComponentPresentation(
              builder.toString(),
              boldStartOffset,
              boldEndOffset,
              isGrey,
              isDeprecated,
              false,
              color);
      } else context.setUIComponentEnabled(false);
    }
  }
  @Override
  public void updateUI(
      Pair<? extends FunctionDescriptor, ResolutionFacade> itemToShow,
      @NotNull ParameterInfoUIContext context) {
    // todo: when we will have ability to pass Array as vararg, implement such feature here too?
    if (context == null
        || context.getParameterOwner() == null
        || !context.getParameterOwner().isValid()) {
      context.setUIComponentEnabled(false);
      return;
    }

    PsiElement parameterOwner = context.getParameterOwner();
    if (!(parameterOwner instanceof JetValueArgumentList)) {
      context.setUIComponentEnabled(false);
      return;
    }

    JetValueArgumentList argumentList = (JetValueArgumentList) parameterOwner;

    FunctionDescriptor functionDescriptor = itemToShow.first;
    ResolutionFacade resolutionFacade = itemToShow.second;

    List<ValueParameterDescriptor> valueParameters = functionDescriptor.getValueParameters();
    List<JetValueArgument> valueArguments = argumentList.getArguments();

    int currentParameterIndex = context.getCurrentParameterIndex();
    int boldStartOffset = -1;
    int boldEndOffset = -1;
    boolean isGrey = false;
    boolean isDeprecated = KotlinBuiltIns.isDeprecated(functionDescriptor);

    boolean[] usedIndexes = new boolean[valueParameters.size()];
    Arrays.fill(usedIndexes, false);

    boolean namedMode = false;

    if (!isIndexValid(valueParameters, currentParameterIndex)) {
      isGrey = true;
    }

    StringBuilder builder = new StringBuilder();

    PsiElement owner = context.getParameterOwner();
    BindingContext bindingContext =
        resolutionFacade.analyze((JetElement) owner, BodyResolveMode.FULL);

    for (int i = 0; i < valueParameters.size(); ++i) {
      if (i != 0) {
        builder.append(", ");
      }

      boolean highlightParameter =
          i == currentParameterIndex
              || (!namedMode
                  && i < currentParameterIndex
                  && Iterables.getLast(valueParameters).getVarargElementType() != null);

      if (highlightParameter) {
        boldStartOffset = builder.length();
      }

      if (!namedMode) {
        if (valueArguments.size() > i) {
          JetValueArgument argument = valueArguments.get(i);
          if (argument.isNamed()) {
            namedMode = true;
          } else {
            ValueParameterDescriptor param = valueParameters.get(i);
            builder.append(renderParameter(param, false));
            if (i <= currentParameterIndex
                && !isArgumentTypeValid(bindingContext, argument, param)) {
              isGrey = true;
            }
            usedIndexes[i] = true;
          }
        } else {
          ValueParameterDescriptor param = valueParameters.get(i);
          builder.append(renderParameter(param, false));
        }
      }

      if (namedMode) {
        boolean takeAnyArgument = true;
        if (valueArguments.size() > i) {
          JetValueArgument argument = valueArguments.get(i);
          if (argument.isNamed()) {
            for (int j = 0; j < valueParameters.size(); ++j) {
              JetSimpleNameExpression referenceExpression =
                  argument.getArgumentName().getReferenceExpression();
              ValueParameterDescriptor param = valueParameters.get(j);
              if (referenceExpression != null
                  && !usedIndexes[j]
                  && param.getName().equals(referenceExpression.getReferencedNameAsName())) {
                takeAnyArgument = false;
                usedIndexes[j] = true;
                builder.append(renderParameter(param, true));
                if (i < currentParameterIndex
                    && !isArgumentTypeValid(bindingContext, argument, param)) {
                  isGrey = true;
                }
                break;
              }
            }
          }
        }

        if (takeAnyArgument) {
          if (i < currentParameterIndex) {
            isGrey = true;
          }

          for (int j = 0; j < valueParameters.size(); ++j) {
            ValueParameterDescriptor param = valueParameters.get(j);
            if (!usedIndexes[j]) {
              usedIndexes[j] = true;
              builder.append(renderParameter(param, true));
              break;
            }
          }
        }
      }

      if (highlightParameter) {
        boldEndOffset = builder.length();
      }
    }

    if (valueParameters.size() == 0) {
      builder.append(CodeInsightBundle.message("parameter.info.no.parameters"));
    }

    assert !builder.toString().isEmpty()
        : "A message about 'no parameters' or some parameters should be present: "
            + functionDescriptor;

    Color color =
        isResolvedToDescriptor(argumentList, functionDescriptor, bindingContext)
            ? GREEN_BACKGROUND
            : context.getDefaultParameterColor();
    context.setupUIComponentPresentation(
        builder.toString(), boldStartOffset, boldEndOffset, isGrey, isDeprecated, false, color);
  }
  @Override
  @Nullable
  protected ClassMember[] chooseOriginalMembers(PsiClass aClass, Project project) {
    if (aClass instanceof PsiAnonymousClass) {
      Messages.showMessageDialog(
          project,
          CodeInsightBundle.message("error.attempt.to.generate.constructor.for.anonymous.class"),
          CommonBundle.getErrorTitle(),
          Messages.getErrorIcon());
      return null;
    }

    myCopyJavadoc = false;
    PsiMethod[] baseConstructors = null;
    PsiClass baseClass = aClass.getSuperClass();
    if (baseClass != null) {
      ArrayList<PsiMethod> array = new ArrayList<PsiMethod>();
      for (PsiMethod method : baseClass.getConstructors()) {
        if (JavaPsiFacade.getInstance(method.getProject())
            .getResolveHelper()
            .isAccessible(method, aClass, null)) {
          array.add(method);
        }
      }
      if (!array.isEmpty()) {
        if (array.size() == 1) {
          baseConstructors = new PsiMethod[] {array.get(0)};
        } else {
          final PsiSubstitutor substitutor =
              TypeConversionUtil.getSuperClassSubstitutor(baseClass, aClass, PsiSubstitutor.EMPTY);
          PsiMethodMember[] constructors =
              ContainerUtil.map2Array(
                  array,
                  PsiMethodMember.class,
                  new Function<PsiMethod, PsiMethodMember>() {
                    @Override
                    public PsiMethodMember fun(final PsiMethod s) {
                      return new PsiMethodMember(s, substitutor);
                    }
                  });
          MemberChooser<PsiMethodMember> chooser =
              new MemberChooser<PsiMethodMember>(constructors, false, true, project);
          chooser.setTitle(
              CodeInsightBundle.message("generate.constructor.super.constructor.chooser.title"));
          chooser.show();
          List<PsiMethodMember> elements = chooser.getSelectedElements();
          if (elements == null || elements.isEmpty()) return null;
          baseConstructors = new PsiMethod[elements.size()];
          for (int i = 0; i < elements.size(); i++) {
            final ClassMember member = elements.get(i);
            baseConstructors[i] = ((PsiMethodMember) member).getElement();
          }
          myCopyJavadoc = chooser.isCopyJavadoc();
        }
      }
    }

    ClassMember[] allMembers = getAllOriginalMembers(aClass);
    ClassMember[] members;
    if (allMembers.length == 0) {
      members = ClassMember.EMPTY_ARRAY;
    } else {
      members = chooseMembers(allMembers, true, false, project, null);
      if (members == null) return null;
    }
    if (baseConstructors != null) {
      ArrayList<ClassMember> array = new ArrayList<ClassMember>();
      for (PsiMethod baseConstructor : baseConstructors) {
        array.add(new PsiMethodMember(baseConstructor));
      }
      ContainerUtil.addAll(array, members);
      members = array.toArray(new ClassMember[array.size()]);
    }

    return members;
  }