Coverage Report - net.sf.jmatchparser.template.engine.operation.FormatOperation
 
Classes in this File Line Coverage Branch Coverage Complexity
FormatOperation
80%
8/10
N/A
2,5
 
 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.operation;
 19  
 
 20  
 import java.io.IOException;
 21  
 
 22  
 import net.sf.jmatchparser.template.Formatter;
 23  
 import net.sf.jmatchparser.template.engine.ParserState;
 24  
 
 25  
 public class FormatOperation extends SideEffectOperation {
 26  
 
 27  
         private Formatter formatter;
 28  
 
 29  
         public FormatOperation(String templatePosition, Formatter formatter) {
 30  9
                 super(templatePosition);
 31  9
                 this.formatter = formatter;
 32  9
         }
 33  
 
 34  
         @Override
 35  
         public OperationResult executeWithSideEffects(ParserState state) {
 36  
                 try {
 37  9
                         String rest = state.getRest().toString();
 38  9
                         state.discardCharacters(rest.length());
 39  9
                         state.write(formatter.format(rest, state.getParser().getDebugStream()));
 40  9
                         state.startNextPass();
 41  9
                         return OperationResult.NEXTPASS;
 42  0
                 } catch (IOException ex) {
 43  0
                         throw new RuntimeException("Formatter threw an exception", ex);
 44  
                 }
 45  
         }
 46  
 }