Move some helper methods of PatternExtraction in the extension methods of TreeNode.