--- /dev/null
+/*\r
+\r
+ Derby - Class org.apache.derby.impl.sql.compile.SubstituteExpressionVisitor\r
+\r
+ Licensed to the Apache Software Foundation (ASF) under one or more\r
+ contributor license agreements. See the NOTICE file distributed with\r
+ this work for additional information regarding copyright ownership.\r
+ The ASF licenses this file to you under the Apache License, Version 2.0\r
+ (the "License"); you may not use this file except in compliance with\r
+ the License. You may obtain a copy of the License at\r
+\r
+ http://www.apache.org/licenses/LICENSE-2.0\r
+\r
+ Unless required by applicable law or agreed to in writing, software\r
+ distributed under the License is distributed on an "AS IS" BASIS,\r
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+ See the License for the specific language governing permissions and\r
+ limitations under the License.\r
+\r
+ */\r
+package org.apache.derby.impl.sql.compile;\r
+\r
+import org.apache.derby.iapi.error.StandardException;\r
+import org.apache.derby.iapi.sql.compile.Visitable;\r
+import org.apache.derby.iapi.sql.compile.Visitor;\r
+\r
+/**\r
+ * Replaces a <em>source</em> expression with a <em>target</em>\r
+ * expression. \r
+ * \r
+ */\r
+class SubstituteExpressionVisitor implements Visitor \r
+{\r
+ private ValueNode source;\r
+ private ValueNode target;\r
+ private Class skipOverClass;\r
+ \r
+ SubstituteExpressionVisitor(\r
+ ValueNode s, ValueNode t, Class skipThisClass) \r
+ {\r
+ source = s;\r
+ target = t;\r
+ skipOverClass = skipThisClass;\r
+ }\r
+\r
+ /**\r
+ * used by GroupByNode to process expressions by complexity level.\r
+ */\r
+ public ValueNode getSource()\r
+ {\r
+ return source;\r
+ }\r
+\r
+ public Visitable visit(Visitable node) throws StandardException \r
+ {\r
+ if (!(node instanceof ValueNode))\r
+ {\r
+ return node;\r
+ }\r
+ \r
+ ValueNode nd = (ValueNode)node;\r
+ if (nd.isEquivalent(source)) \r
+ {\r
+ return target;\r
+ } \r
+ else \r
+ {\r
+ return node;\r
+ }\r
+ }\r
+\r
+ public boolean stopTraversal() \r
+ {\r
+ return false;\r
+ }\r
+\r
+ public boolean skipChildren(Visitable node) \r
+ {\r
+ return (skipOverClass == null) ?\r
+ false:\r
+ skipOverClass.isInstance(node);\r
+ }\r
+}\r