Coverage Report - net.sf.jmatchparser.template.engine.CallStackFrame
 
Classes in this File Line Coverage Branch Coverage Complexity
CallStackFrame
92%
23/25
70%
7/10
2,333
 
 1  
 /*
 2  
  * Copyright (c) 2006 - 2011 Michael Schierl
 3  
  * All rights reserved.
 4  
  * 
 5  
  * This program is free software: you can redistribute it and/or modify
 6  
  * it under the terms of the GNU General Public License as published by
 7  
  * the Free Software Foundation, either version 2 of the License, or
 8  
  * (at your option) any later version.
 9  
  * 
 10  
  * This program is distributed in the hope that it will be useful,
 11  
  * but WITHOUT ANY WARRANTY; without even the implied warranty of
 12  
  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 13  
  * GNU General Public License for more details.
 14  
  * 
 15  
  * You should have received a copy of the GNU General Public License
 16  
  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 17  
  */
 18  
 package net.sf.jmatchparser.template.engine;
 19  
 
 20  
 public class CallStackFrame {
 21  
         private final int returnAddress;
 22  
         private final CallStackFrame nextFrame;
 23  
         private final String origName, origValue;
 24  
 
 25  125
         public CallStackFrame(CallStackFrame nextFrame, int returnAddress) {
 26  125
                 this.nextFrame = nextFrame;
 27  125
                 this.returnAddress = returnAddress;
 28  125
                 origName = origValue = null;
 29  125
         }
 30  
 
 31  246
         public CallStackFrame(CallStackFrame thisFrame, String name, String oldValue) {
 32  246
                 if (thisFrame == null || thisFrame.containsName(name))
 33  0
                         throw new IllegalArgumentException();
 34  246
                 this.nextFrame = thisFrame;
 35  246
                 returnAddress = -1;
 36  246
                 origName = name;
 37  246
                 origValue = oldValue;
 38  246
         }
 39  
 
 40  
         public boolean containsName(String name) {
 41  738
                 if (origName == null)
 42  492
                         return false;
 43  246
                 if (origName.equals(name))
 44  0
                         return true;
 45  
                 // nextFrame is non-null here!
 46  246
                 return nextFrame.containsName(name);
 47  
         }
 48  
 
 49  
         public CallStackFrame restoreVariables(ParserState state) {
 50  163
                 CallStackFrame f = this;
 51  485
                 while (f.origName != null) {
 52  322
                         state.setLocal(f.origName, f.origValue);
 53  322
                         f = f.nextFrame;
 54  
                 }
 55  163
                 return f;
 56  
         }
 57  
 
 58  
         public int getReturnAddress() {
 59  163
                 return returnAddress;
 60  
         }
 61  
 
 62  
         public CallStackFrame getNextFrame() {
 63  163
                 return nextFrame;
 64  
         }
 65  
 }