public Selector directJoin(Selector firstI, Selector secondI) {
    // if both of them are null, something is very wrong
    if (secondI == null) return firstI.clone();

    if (firstI == null) return secondI.clone();

    Selector first = firstI.clone();
    List<SelectorPart> secondParts = ArraysUtils.deeplyClonedList(secondI.getParts());
    List<Extend> secondExtends = ArraysUtils.deeplyClonedList(secondI.getExtend());
    SelectorPart secondHead = secondParts.get(0);

    if (secondHead.isAppender())
      return indirectJoinNoClone(
          first, secondHead.getLeadingCombinator(), secondParts, secondExtends);

    /*
     * FIXME: test on old whether survives if first is not simple selector. (say, if:
     * (~"escaped") {
     *   &:pseudo() {
     *   }
     * }
     *
     */
    SelectorPart attachToHead = first.getLastPart();
    directlyJoinParts(attachToHead, secondHead);

    secondParts.remove(0);
    SelectorCombinator leadingCombinator =
        secondParts.isEmpty() ? null : secondParts.get(0).getLeadingCombinator();
    return indirectJoinNoClone(first, leadingCombinator, secondParts, secondExtends);
  }
  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;
  }
 public Selector indirectJoinNoClone(
     Selector first, SelectorCombinator combinator, Selector second) {
   return indirectJoinNoClone(first, combinator, second.getParts(), second.getExtend());
 }
Beispiel #4
0
 public boolean appendSelector(Selector selector) {
   for (SelectorPart part : selector.getParts()) {
     append(part);
   }
   return true;
 }