code: @Nullable
    public ExpressionTreeElement addTreeElement(@Nonnull final ExpressionTreeElement element) {
      assertNotEmptySlot();
      assertNotNull("The element is null", element);
  
      final int newElementPriority = element.getPriority();
  
      ExpressionTreeElement result = this;
  
      final ExpressionTreeElement parentTreeElement = this.parentTreeElement;
  
      final int currentPriority = getPriority();
  
      if (newElementPriority < currentPriority) {
        if (parentTreeElement == null) {
          element.addTreeElement(this);
          result = element;
        } else {
          result = parentTreeElement.addTreeElement(element);
        }
      } else if (newElementPriority == currentPriority) {
        if (parentTreeElement != null) {
          parentTreeElement.replaceElement(this, element);
        }
        if (element.nextChildSlot >= element.childElements.length) {
          throw new PreprocessorException("[Expression]Can't process expression item, may be wrong number of arguments", this.sourceString, this.includeStack, null);
        }
        element.childElements[element.nextChildSlot] = this;
        element.nextChildSlot++;
        this.parentTreeElement = element;
        result = element;
      } else if (isFull()) {
        final int lastElementIndex = getArity() - 1;
  
        final ExpressionTreeElement lastElement = childElements[lastElementIndex];
        if (lastElement.getPriority() > newElementPriority) {
          element.addElementToNextFreeSlot(lastElement);
          childElements[lastElementIndex] = element;
          element.parentTreeElement = this;
          result = element;
        }
  
      } else {
        addElementToNextFreeSlot(element);
        result = element;
      }
      return result;
    }
docs: Add tree element with sorting operation depends on priority of the elements
  
  @param element the element to be added, must not be null
  @return the element which should be used as the last for the current tree