Example #1
0
  private Collection<Selector> replaceFirstAppender(
      Selector selector, List<Selector> previousSelectors) {
    if (selector.getHead().isAppender()) {
      NestedSelectorAppender appender = (NestedSelectorAppender) selector.getHead();
      Selector reminder = chopOffHead(selector);
      return joinAll(
          previousSelectors,
          reminder,
          appender.getLeadingCombinator(),
          isDirectlyAfterPreviousPart(reminder));
    }

    // appender somewhere in the middle
    NestedSelectorAppender appender = selector.findFirstAppender();
    if (appender == null)
      throw new BugHappened("This is very weird error and should not happen.", selector);

    Selector afterAppender = splitOn(selector, appender);
    List<Selector> partialResults =
        joinAll(
            selector,
            previousSelectors,
            appender.getLeadingCombinator(),
            appender.isDirectlyAfter());
    // FIXME (now) last parameter should be nide and repats cold in 146
    return joinAll(partialResults, afterAppender, null, isDirectlyAfterPreviousPart(afterAppender));
  }
Example #2
0
  private Selector splitOn(Selector selector, NestedSelectorAppender appender) {
    List<SelectorPart> parts = selector.getParts();
    int indexOfAppender = parts.indexOf(appender);
    List<SelectorPart> appenderAndAfter = parts.subList(indexOfAppender, parts.size());

    // remove appender
    appenderAndAfter.remove(0);
    appender.setParent(null);

    // create selector with after appender parts
    Selector result = null;
    if (!appenderAndAfter.isEmpty()) {
      result =
          new Selector(
              selector.getUnderlyingStructure(), new ArrayList<SelectorPart>(appenderAndAfter));
      result.configureParentToAllChilds();
    }

    // leave only before appender parts in original selector
    appenderAndAfter.clear();
    return result;
  }