public static String generateDoc(
     @Nullable final String signature,
     final boolean signatureIsHtml,
     @Nullable final String docText,
     @Nullable final String containingLibraryName,
     @Nullable final String containingClassDescription,
     @Nullable final String staticType,
     @Nullable final String propagatedType) {
   final boolean hasContainingLibraryName = !StringUtil.isEmpty(containingLibraryName);
   final boolean hasContainingClassDescription = !StringUtil.isEmpty(containingClassDescription);
   final boolean hasStaticType = !StringUtil.isEmpty(staticType);
   final boolean hasPropagatedType = !StringUtil.isEmpty(propagatedType);
   // generate
   final StringBuilder builder = new StringBuilder();
   builder.append("<code>");
   if (signature != null) {
     builder.append("<b>Signature:</b> ");
     if (signatureIsHtml) {
       builder.append(signature);
     } else {
       builder.append(StringUtil.escapeXml(signature));
     }
     builder.append("<br>");
   }
   if (hasContainingLibraryName || hasContainingClassDescription) {
     builder.append("<br>");
     if (hasContainingLibraryName) {
       builder.append("<b>Containing library:</b> ");
       builder.append(StringUtil.escapeXml(containingLibraryName));
       builder.append("<br>");
     }
     if (hasContainingClassDescription) {
       builder.append("<b>Containing class:</b> ");
       builder.append(StringUtil.escapeXml(containingClassDescription));
       builder.append("<br>");
     }
   }
   if (hasStaticType || hasPropagatedType) {
     builder.append("<br>");
     if (hasStaticType) {
       builder.append("<b>Static type:</b> ");
       builder.append(StringUtil.escapeXml(staticType));
       builder.append("<br>");
     }
     if (hasPropagatedType) {
       builder.append("<b>Propagated type:</b> ");
       builder.append(StringUtil.escapeXml(propagatedType));
       builder.append("<br>");
     }
   }
   builder.append("</code>");
   if (docText != null) {
     builder.append("<br>");
     final MarkdownProcessor processor = new MarkdownProcessor();
     builder.append(processor.markdown(docText));
   }
   // done
   return builder.toString();
 }
  private static void appendClassSignature(final StringBuilder builder, final DartClass dartClass) {
    if (dartClass.isEnum()) {
      builder.append("enum <b>").append(dartClass.getName()).append("</b>");
      return;
    }

    if (dartClass.isAbstract()) {
      builder.append("abstract ");
    }

    builder.append("class <b>").append(dartClass.getName()).append("</b>");
    appendTypeParams(builder, dartClass.getTypeParameters());

    final List<DartType> mixins = dartClass.getMixinsList();
    final DartType superClass = dartClass.getSuperClass();
    if (superClass != null) {
      builder.append(" extends ").append(StringUtil.escapeXml(superClass.getText()));
    }

    if (!mixins.isEmpty()) {
      builder.append(" with ");
      appendDartTypeList(builder, mixins);
    }

    final List<DartType> implementsList = dartClass.getImplementsList();
    if (!implementsList.isEmpty()) {
      builder.append(" implements ");
      appendDartTypeList(builder, implementsList);
    }
  }
 private static void appendFunctionSignature(
     final StringBuilder builder, final DartComponent function, final DartReturnType returnType) {
   final String returnString =
       returnType == null
           ? "dynamic"
           : StringUtil.escapeXml(DartPresentableUtil.buildTypeText(null, returnType, null));
   appendFunctionSignature(builder, function, returnString);
 }
 public void append(
     @NotNull final String fragment, @NotNull final SimpleTextAttributes attributes) {
   if (fragment.length() > 0) {
     myText.append("<span ");
     formatStyle(myText, attributes);
     myText.append('>').append(StringUtil.escapeXml(fragment)).append("</span>");
   }
 }
  @SuppressWarnings("StringConcatenationInsideStringBufferAppend")
  @NotNull
  private static String makeDescription(
      @NotNull Collection<VcsRootError> unregisteredRoots,
      @NotNull Collection<VcsRootError> invalidRoots) {
    Function<VcsRootError, String> rootToDisplayableString =
        rootError -> {
          if (rootError.getMapping().equals(VcsDirectoryMapping.PROJECT_CONSTANT)) {
            return StringUtil.escapeXml(rootError.getMapping());
          }
          return FileUtil.toSystemDependentName(rootError.getMapping());
        };

    StringBuilder description = new StringBuilder();
    if (!invalidRoots.isEmpty()) {
      if (invalidRoots.size() == 1) {
        VcsRootError rootError = invalidRoots.iterator().next();
        String vcsName = rootError.getVcsKey().getName();
        description.append(
            String.format(
                "The directory %s is registered as a %s root, but no %s repositories were found there.",
                rootToDisplayableString.fun(rootError), vcsName, vcsName));
      } else {
        description.append(
            "The following directories are registered as VCS roots, but they are not: <br/>"
                + StringUtil.join(invalidRoots, rootToDisplayableString, "<br/>"));
      }
      description.append("<br/>");
    }

    if (!unregisteredRoots.isEmpty()) {
      if (unregisteredRoots.size() == 1) {
        VcsRootError unregisteredRoot = unregisteredRoots.iterator().next();
        description.append(
            String.format(
                "The directory %s is under %s, but is not registered in the Settings.",
                rootToDisplayableString.fun(unregisteredRoot),
                unregisteredRoot.getVcsKey().getName()));
      } else {
        description.append(
            "The following directories are roots of VCS repositories, but they are not registered in the Settings: <br/>"
                + StringUtil.join(unregisteredRoots, rootToDisplayableString, "<br/>"));
      }
      description.append("<br/>");
    }

    String add =
        invalidRoots.isEmpty()
            ? "<a href='add'>Add "
                + pluralize("root", unregisteredRoots.size())
                + "</a>&nbsp;&nbsp;"
            : "";
    String configure = "<a href='configure'>Configure</a>";
    String ignore = invalidRoots.isEmpty() ? "&nbsp;&nbsp;<a href='ignore'>Ignore</a>" : "";
    description.append(add + configure + ignore);

    return description.toString();
  }
 private static void appendDartTypeList(
     final StringBuilder builder, final List<DartType> dartTypes) {
   for (Iterator<DartType> iter = dartTypes.iterator(); iter.hasNext(); ) {
     builder.append(StringUtil.escapeXml(iter.next().getText()));
     if (iter.hasNext()) {
       builder.append(", ");
     }
   }
 }
  public static void invokeImpl(
      Project project, Editor editor, final PsiFile file, Injectable injectable) {
    final PsiLanguageInjectionHost host = findInjectionHost(editor, file);
    if (host == null) return;
    if (defaultFunctionalityWorked(host, injectable.getId())) return;

    try {
      host.putUserData(FIX_KEY, null);
      Language language = injectable.toLanguage();
      for (LanguageInjectionSupport support : InjectorUtils.getActiveInjectionSupports()) {
        if (support.isApplicableTo(host) && support.addInjectionInPlace(language, host)) {
          return;
        }
      }
      if (TemporaryPlacesRegistry.getInstance(project)
          .getLanguageInjectionSupport()
          .addInjectionInPlace(language, host)) {
        final Processor<PsiLanguageInjectionHost> data = host.getUserData(FIX_KEY);
        String text =
            StringUtil.escapeXml(language.getDisplayName()) + " was temporarily injected.";
        if (data != null) {
          if (!ApplicationManager.getApplication().isUnitTestMode()) {
            final SmartPsiElementPointer<PsiLanguageInjectionHost> pointer =
                SmartPointerManager.getInstance(project).createSmartPsiElementPointer(host);
            final TextRange range = host.getTextRange();
            HintManager.getInstance()
                .showQuestionHint(
                    editor,
                    text
                        + "<br>Do you want to insert annotation? "
                        + KeymapUtil.getFirstKeyboardShortcutText(
                            ActionManager.getInstance()
                                .getAction(IdeActions.ACTION_SHOW_INTENTION_ACTIONS)),
                    range.getStartOffset(),
                    range.getEndOffset(),
                    new QuestionAction() {
                      @Override
                      public boolean execute() {
                        return data.process(pointer.getElement());
                      }
                    });
          }
        } else {
          HintManager.getInstance().showInformationHint(editor, text);
        }
      }
    } finally {
      if (injectable.getLanguage() != null) { // no need for reference injection
        FileContentUtil.reparseFiles(project, Collections.<VirtualFile>emptyList(), true);
      } else {
        ((PsiModificationTrackerImpl) PsiManager.getInstance(project).getModificationTracker())
            .incCounter();
        DaemonCodeAnalyzer.getInstance(project).restart();
      }
    }
  }
 public void appendLink(
     @NotNull final String fragment,
     @NotNull final SimpleTextAttributes attributes,
     @NotNull final String url) {
   if (fragment.length() > 0) {
     myText.append("<a href=\"").append(StringUtil.replace(url, "\"", "%22")).append("\" ");
     formatStyle(myText, attributes);
     myText.append('>').append(StringUtil.escapeXml(fragment)).append("</a>");
   }
 }
 private static void appendFunctionSignature(
     final StringBuilder builder, final DartComponent function, final String returnType) {
   builder.append("<b>").append(function.getName()).append("</b>");
   if (!function.isGetter()) {
     builder.append('(');
     builder.append(
         StringUtil.escapeXml(
             DartPresentableUtil.getPresentableParameterList(
                 function, new DartGenericSpecialization(), true, true)));
     builder.append(')');
   }
   builder.append(' ');
   builder.append(DartPresentableUtil.RIGHT_ARROW);
   builder.append(' ');
   builder.append(returnType);
 }
  private boolean checkRunConfiguration(
      Executor executor, Project project, RunnerAndConfigurationSettings configuration) {
    ExecutionTarget target = ExecutionTargetManager.getActiveTarget(project);

    if (!ExecutionTargetManager.canRun(configuration, target)) {
      ExecutionUtil.handleExecutionError(
          project,
          executor.getToolWindowId(),
          configuration.getConfiguration(),
          new ExecutionException(
              StringUtil.escapeXml(
                  "Cannot run '"
                      + configuration.getName()
                      + "' on '"
                      + target.getDisplayName()
                      + "'")));
      return false;
    }

    if (!RunManagerImpl.canRunConfiguration(configuration, executor)
        || configuration.isEditBeforeRun()) {
      if (!RunDialog.editConfiguration(project, configuration, "Edit configuration", executor)) {
        return false;
      }

      while (!RunManagerImpl.canRunConfiguration(configuration, executor)) {
        if (0
            == Messages.showYesNoDialog(
                project,
                "Configuration is still incorrect. Do you want to edit it again?",
                "Change Configuration Settings",
                "Edit",
                "Continue Anyway",
                Messages.getErrorIcon())) {
          if (!RunDialog.editConfiguration(
              project, configuration, "Edit configuration", executor)) {
            break;
          }
        } else {
          break;
        }
      }
    }
    return true;
  }
 private void annotateExternally(
     @NotNull PsiModifierListOwner listOwner,
     @NotNull String annotationFQName,
     @Nullable final XmlFile xmlFile,
     @NotNull PsiFile codeUsageFile,
     PsiNameValuePair[] values) {
   if (xmlFile == null) return;
   try {
     final XmlDocument document = xmlFile.getDocument();
     if (document != null) {
       final XmlTag rootTag = document.getRootTag();
       final String externalName = getExternalName(listOwner, false);
       if (rootTag != null) {
         for (XmlTag tag : rootTag.getSubTags()) {
           if (Comparing.strEqual(
               StringUtil.unescapeXml(tag.getAttributeValue("name")), externalName)) {
             for (XmlTag annTag : tag.getSubTags()) {
               if (Comparing.strEqual(annTag.getAttributeValue("name"), annotationFQName)) {
                 annTag.delete();
                 break;
               }
             }
             tag.add(
                 XmlElementFactory.getInstance(myPsiManager.getProject())
                     .createTagFromText(createAnnotationTag(annotationFQName, values)));
             return;
           }
         }
         @NonNls String text = "<item name=\'" + StringUtil.escapeXml(externalName) + "\'>\n";
         text += createAnnotationTag(annotationFQName, values);
         text += "</item>";
         rootTag.add(
             XmlElementFactory.getInstance(myPsiManager.getProject()).createTagFromText(text));
       }
     }
   } catch (IncorrectOperationException e) {
     LOG.error(e);
   } finally {
     dropCache();
     if (codeUsageFile.getVirtualFile().isInLocalFileSystem()) {
       UndoUtil.markPsiFileForUndo(codeUsageFile);
     }
   }
 }
 public static String escapeXmlIfNeeded(InsertionContext context, String generics) {
   if (context.getFile().getViewProvider().getBaseLanguage() == StdLanguages.JSPX) {
     return StringUtil.escapeXml(generics);
   }
   return generics;
 }
 private static String convertFragment(String fragment) {
   return StringUtil.escapeXml(fragment).replaceAll("\\\\n", "<br>");
 }
 protected static String escapePresentableType(PsiType exprType) {
   return StringUtil.escapeXml(exprType.getPresentableText());
 }
 public String escapeText(String originalText) {
   return StringUtil.escapeXml(originalText);
 }
  public static void executeConfiguration(
      @NotNull ExecutionEnvironment environment, boolean showSettings, boolean assignNewId) {
    if (ExecutorRegistry.getInstance().isStarting(environment)) {
      return;
    }

    RunnerAndConfigurationSettings runnerAndConfigurationSettings =
        environment.getRunnerAndConfigurationSettings();
    if (runnerAndConfigurationSettings != null) {
      if (!ExecutionTargetManager.canRun(environment)) {
        ExecutionUtil.handleExecutionError(
            environment,
            new ExecutionException(
                StringUtil.escapeXml(
                    "Cannot run '"
                        + environment.getRunProfile().getName()
                        + "' on '"
                        + environment.getExecutionTarget().getDisplayName()
                        + "'")));
        return;
      }

      if (!RunManagerImpl.canRunConfiguration(environment)
          || (showSettings && runnerAndConfigurationSettings.isEditBeforeRun())) {
        if (!RunDialog.editConfiguration(environment, "Edit configuration")) {
          return;
        }

        while (!RunManagerImpl.canRunConfiguration(environment)) {
          if (Messages.YES
              == Messages.showYesNoDialog(
                  environment.getProject(),
                  "Configuration is still incorrect. Do you want to edit it again?",
                  "Change Configuration Settings",
                  "Edit",
                  "Continue Anyway",
                  Messages.getErrorIcon())) {
            if (!RunDialog.editConfiguration(environment, "Edit configuration")) {
              return;
            }
          } else {
            break;
          }
        }
      }

      ConfigurationType configurationType = runnerAndConfigurationSettings.getType();
      if (configurationType != null) {
        UsageTrigger.trigger(
            "execute."
                + ConvertUsagesUtil.ensureProperKey(configurationType.getId())
                + "."
                + environment.getExecutor().getId());
      }
    }

    try {
      if (assignNewId) {
        environment.assignNewExecutionId();
      }
      environment.getRunner().execute(environment);
    } catch (ExecutionException e) {
      String name =
          runnerAndConfigurationSettings != null ? runnerAndConfigurationSettings.getName() : null;
      if (name == null) {
        name = environment.getRunProfile().getName();
      }
      if (name == null && environment.getContentToReuse() != null) {
        name = environment.getContentToReuse().getDisplayName();
      }
      if (name == null) {
        name = "<Unknown>";
      }
      ExecutionUtil.handleExecutionError(
          environment.getProject(), environment.getExecutor().getToolWindowId(), name, e);
    }
  }