Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
 /*
  * 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.pig.impl.plan;
A visitor mechanism for navigating and operating on a plan of Operators. This class contains the logic to traverse the plan. It does not visit individual nodes. That is left to implementing classes (such as LOVisitor).
abstract public class PlanVisitor <O extends Operator, P extends OperatorPlan<O>> {
    protected P mPlan;

    
Guaranteed to always point to the walker currently being used.
    protected PlanWalker<O, P> mCurrentWalker;
    private Deque<PlanWalker<O, P>> mWalkers;

    
Entry point for visiting the plan.

Throws:
VisitorException if an error is encountered while visiting.
    public void visit() throws VisitorException {
        .walk(this);
    }
    public P getPlan() {
        return ;
    }

    

Parameters:
plan OperatorPlan this visitor will visit.
walker PlanWalker this visitor will use to traverse the plan.
    protected PlanVisitor(P planPlanWalker<O, P> walker) {
         = plan;
         = walker;
         = new LinkedList<PlanWalker<O, P>>();
    }

    
Push the current walker onto the stack of saved walkers and begin using the newly passed walker as the current walker.

Parameters:
walker new walker to set as the current walker.
    protected void pushWalker(PlanWalker<O, P> walker) {
        .push();
         = walker;
    }

    
Pop the next to previous walker off of the stack and set it as the current walker. This will drop the reference to the current walker.

Throws:
VisitorException if there are no more walkers on the stack. In this case the current walker is not reset.
    protected void popWalker() throws VisitorException {
        if (.isEmpty()) {
            throw new VisitorException("No more walkers to pop.");
        }
         = .pop();
    }
New to GrepCode? Check out our FAQ X