return createSimpleSelectorWithSomePartReplaced(
(SimpleSelector) selector, toBeReplacedSelectorName,
candidateSelector);
} else if (selector instanceof DescendantSelector) {
DescendantSelector descendantSelector = (DescendantSelector) selector;
Selector ancestor = descendantSelector.getAncestorSelector();
SimpleSelector simpleSelector = descendantSelector
.getSimpleSelector();
return factory.createDescendantSelector(
createSelectorWithSomePartReplaced(ancestor,
toBeReplacedSelectorName, candidateSelector),
createSimpleSelectorWithSomePartReplaced(simpleSelector,
toBeReplacedSelectorName, candidateSelector));
} else if (selector instanceof DirectAdjacentSelectorImpl) {
SiblingSelector siblingSelector = (SiblingSelector) selector;
Selector ancestor = siblingSelector.getSelector();
SimpleSelector simpleSelector = siblingSelector
.getSiblingSelector();
return factory.createDirectAdjacentSelector(
Selector.SAC_DIRECT_ADJACENT_SELECTOR, ancestor,
simpleSelector);
} else if (selector instanceof CompositeSelector) {
CompositeSelector compositeSelector = (CompositeSelector) selector;
Selector first = compositeSelector.getFirst();
Selector second = compositeSelector.getSecond();
return new CompositeSelector(createSelectorWithSomePartReplaced(
first, toBeReplacedSelectorName, candidateSelector),
createSelectorWithSomePartReplaced(second,
toBeReplacedSelectorName, candidateSelector));
}