andrewjc2000 commented on a change in pull request #394: URL: https://github.com/apache/incubator-daffodil/pull/394#discussion_r455879433
########## File path: daffodil-core/src/test/scala/org/apache/daffodil/dsom/walker/BasicWalker.scala ########## @@ -0,0 +1,50 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.apache.daffodil.dsom.walker + +import scala.collection.mutable.ArrayBuffer + +class BasicWalker(ignoreTypeWrappers: Boolean = false, onlyElements: Boolean = false) extends AbstractDSOMWalker { + + var nodeArr: ArrayBuffer[Either[TermView, TypeView]] = ArrayBuffer() + + override protected def onWalkBegin(root: RootView): Unit = {} + + override protected def onWalkEnd(root: RootView): Unit = {} + + override def onTermBegin(termElement: TermView): Unit = { + if (onlyElements) { + termElement match { + case _: ElementBaseView => nodeArr += Left(termElement) + case _ => + } + } else { + nodeArr += Left(termElement) + } + } + + override def onTermEnd(termElement: TermView): Unit = {} + + override def onTypeBegin(typeElement: TypeView): Unit = { + if (!ignoreTypeWrappers) { + nodeArr += Right(typeElement) + } + } + + override def onTypeEnd(typeElement: TypeView): Unit = {} +} Review comment: It ignores all end events because I wanted the end result to be a stack of every element encountered rather than a stack of Nodes with child elements. In all the implementations so far, End events were just used to remove the current element from the stack, which I don't want here. ---------------------------------------------------------------- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. For queries about this service, please contact Infrastructure at: [email protected]
