Esempio n. 1
0
  private void renderParameters(
      Element parent, SignatureInfo signatureInfo, Optional<Integer> activeParameter) {
    int end = signatureInfo.getLabel().length();
    int idx;
    Element element;
    for (int i = signatureInfo.getParameters().get().size() - 1; i >= 0; i--) {
      ParameterInfo parameterInfo = signatureInfo.getParameters().get().get(i);
      idx = signatureInfo.getLabel().lastIndexOf(parameterInfo.getLabel(), end);
      int signatureLabelOffset = 0;
      int signatureLabelEnd = 0;
      if (idx >= 0) {
        signatureLabelOffset = idx;
        signatureLabelEnd = idx + parameterInfo.getLabel().length();
      }

      element = Elements.createSpanElement();
      element.setTextContent(signatureInfo.getLabel().substring(signatureLabelEnd, end));
      parent.insertBefore(element, parent.getFirstElementChild());

      element = Elements.createSpanElement(resources.css().parameter());
      if (activeParameter.isPresent() && i == activeParameter.get()) {
        Elements.addClassName(resources.css().active(), element);
      }
      element.setTextContent(
          signatureInfo.getLabel().substring(signatureLabelOffset, signatureLabelEnd));
      parent.insertBefore(element, parent.getFirstElementChild());
      end = signatureLabelOffset;
    }
    element = Elements.createSpanElement();
    element.setTextContent(signatureInfo.getLabel().substring(0, end));
    parent.insertBefore(element, parent.getFirstElementChild());
  }
Esempio n. 2
0
  private Element renderSignature(
      Element signatures, SignatureInfo signatureInfo, Optional<Integer> activeParameter) {
    Element signatureElement = Elements.createDivElement();
    signatures.appendChild(signatureElement);

    Element code = Elements.createDivElement();
    signatureElement.appendChild(code);
    boolean hasParameters =
        signatureInfo.getParameters().isPresent() && !signatureInfo.getParameters().get().isEmpty();

    if (hasParameters) {
      renderParameters(code, signatureInfo, activeParameter);
    } else {
      Node label = code.appendChild(Elements.createSpanElement());
      label.setTextContent(signatureInfo.getLabel());
    }

    return signatureElement;
  }