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); }
public void directlyJoinParts(SelectorPart first, SelectorPart second) { if (second.hasElement()) { String secondName = second.hasElement() ? second.getElementName().getName() : ""; if (first.hasSubsequent()) { ElementSubsequent subsequent = first.getLastSubsequent(); subsequent.extendName(secondName); } else { first.extendName(secondName, second.getUnderlyingStructure()); } } first.addSubsequent(second.getSubsequent()); first.configureParentToAllChilds(); }
private boolean isEmptySelector(Selector selector) { if (selector.isCombined()) return false; SelectorPart head = selector.getHead(); if (head.getType() != ASTCssNodeType.SIMPLE_SELECTOR) return false; SimpleSelector simpleHead = (SimpleSelector) head; if (!simpleHead.isEmptyForm() || !simpleHead.isStar()) { return false; } if (simpleHead.hasSubsequent()) return false; return true; }