// the processor is executed
final int nodeLocalVariablesHashBefore =
(node.nodeLocalVariables == null? -1 : node.nodeLocalVariables.contentsHash());
// Execute processor
final ProcessorResult processorResult =
processor.getProcessor().process(executionArguments, processor.getContext(), node);
// Obtain a "hash snapshot" of the node local variables map after
// the processor has been executed
final int nodeLocalVariablesHashAfter =
(node.nodeLocalVariables == null? -1 : node.nodeLocalVariables.contentsHash());
// Check whether the processor just modified the node variables map. This
// is done BEFORE processorResult.computeNewArguments(...) so that variables
// set from the ProcessorResult have higher priority (i.e. can override) variables
// set directly into the nodeLocalVariables map.
if (nodeLocalVariablesHashBefore != nodeLocalVariablesHashAfter) {
executionArguments = executionArguments.addLocalVariables(node.nodeLocalVariables);
}
// The execution arguments need to be updated as instructed by the processor
// (for example, for adding local variables)
executionArguments = processorResult.computeNewArguments(executionArguments);
// Using only the Arguments object for keeping track of whether the text/comment nodes had to be
// computed or not is not a good option because such information dissapears if the node
// setting these flags dissapears afterwards (because of a "remove", for instance).
if (processorResult.isProcessTextNodesSet()) {
node.setProcessTextNodes(processorResult.getProcessTextNodes());
}
if (processorResult.isProcessCommentNodesSet()) {
node.setProcessCommentNodes(processorResult.getProcessCommentNodes());
}
// If we have added local variables, we should update the node's map for these variables in
// order to keep them synchronized
if ((processorResult.hasLocalVariables() || processorResult.isSelectionTargetSet()) && executionArguments.hasLocalVariables()) {
node.unsafeSetNodeLocalVariables(executionArguments.getLocalVariables());
}
// Make sure this specific processor instance is not executed again
alreadyExecuted.count(processor);