if (oldConditionSelector == null
|| !toString(oldConditionSelector).contains(
toBeReplacedSelectorName)) {
return oldConditionSelector;
}
SelectorFactory selectorFactory = new SelectorFactoryImpl();
if (candidateSelector instanceof ElementSelector) {
return selectorFactory.createConditionalSelector(candidateSelector,
oldConditionSelector.getCondition());
}
if (candidateSelector instanceof ConditionalSelector) {
// TODO some cases not covered.
ConditionalSelector candidateConditionSelector = (ConditionalSelector) candidateSelector;
Condition newCondition = createConditionWithSomePartReplaced(
oldConditionSelector.getCondition(),
toBeReplacedSelectorName,
candidateConditionSelector.getCondition());
return selectorFactory.createConditionalSelector(
oldConditionSelector.getSimpleSelector(), newCondition);
}
return oldConditionSelector;
}