Changeset 25


Ignore:
Timestamp:
08/24/10 18:11:38 (14 years ago)
Author:
phdmakk
Message:

+ improved exception and debugging handling (TODO: transfer to t3tools and t3d in t3e-tools; revert outputting formatted source to STDOUT)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/t3e-tools/t3q/src/org/etsi/t3q/T3Q.java

    r16 r25  
    77import java.util.HashMap; 
    88import java.util.List; 
     9 
     10import javax.sound.midi.SysexMessage; 
    911 
    1012import org.apache.commons.cli.CommandLine; 
     
    169171                                                + analyzer.getFilename();  
    170172                                        //TODO: adapt to T3D as well 
    171                                         String tree = ""; 
    172                                         tree = LocationAST.dumpTree((LocationAST)analyzer.getParser().getAST(),1,tree); 
    173173                                        if (getLogLevel().equals(LogLevel.DEBUG)) { 
     174                                                String tree = ""; 
     175                                                tree = LocationAST.dumpTree((LocationAST)analyzer.getParser().getAST(),1,tree); 
    174176                                                exceptionMessage+="\n" + 
    175177                                                                "Parse-tree trace:\n" + 
     
    183185                                                } catch (TTCN3ParserException e) { 
    184186                                                        System.err.println(e.getLocalizedMessage()); 
    185                                                         for (int i1 = 0; i1 < analyzer.getExceptions() 
    186                                                                         .size(); i1++) { 
    187                                                                 System.err.println("Line " 
    188                                                                                 + analyzer.getExceptions().get(i1) 
    189                                                                                                 .getLine() 
    190                                                                                 + ": " 
    191                                                                                 + analyzer.getExceptions().get(i1) 
    192                                                                                                 .getMessage()); 
    193                                                         } 
    194                                                         // e.printStackTrace(); 
     187                                                        dumpParserExceptions(analyzer); 
    195188                                                } 
    196189                                        } 
     
    260253                        // parsing error 
    261254                        System.err.println(e.getLocalizedMessage()); 
    262                         for (int i = 0; i < analyzer.getExceptions().size(); i++) { 
    263                                 System.err.println("Line " 
    264                                                 + analyzer.getExceptions().get(i).getLine() + ": " 
    265                                                 + analyzer.getExceptions().get(i).getMessage()); 
    266                         } 
     255                        dumpParserExceptions(analyzer); 
    267256                        // TODO: Isolate different steps and implement a recovery mechanism: 
    268257 
    269258                } 
    270259 
     260        } 
     261 
     262        private void dumpParserExceptions(TTCN3Analyzer analyzer) { 
     263                for (RecognitionException re : analyzer.getExceptions()) { 
     264                        System.err.println("  Cause:\tLine " 
     265                                        + re.getLine()  
     266                                        + ": " 
     267                                        + re.getMessage()); 
     268                         
     269                        String className = re.getStackTrace()[0].getClassName(); 
     270                        System.err.println("    Parser:\t" 
     271                                        + className.substring(className.lastIndexOf(".")+1)); 
     272                        System.err.println("    Rule: \t" 
     273                                        + re.getStackTrace()[0].getMethodName()); 
     274                } 
    271275        } 
    272276 
     
    342346//                                      System.out.println("OutputPath: \t\t"+outputPath); 
    343347//                                      System.out.println("****************************"); 
    344 //                                      System.out.println(formatted); 
     348                                        System.out.println(formatted); 
    345349//                                      System.out.println(outputPath); 
    346                                         MiscTools.writeFile(outputPath, formatted); 
     350//                                      MiscTools.writeFile(outputPath, formatted); 
    347351                                        System.out.println("File \""+outputPath+"\" written successfully!"); 
    348352 
    349353                                } catch (RecognitionException e1) { 
    350                                         System.err.println("Recognition exception:"); 
    351                                         System.err.println(e1.getLocalizedMessage()); 
     354                                        System.err.println("TTCN-3 Recognition exception: "+e1.getLocalizedMessage()); 
     355                                        System.err.println("  Cause:\tLine " 
     356                                                        + e1.getLine()  
     357                                                        + ": " 
     358                                                        + e1.getMessage()); 
     359                                         
     360                                        String className = e1.getStackTrace()[0].getClassName(); 
     361                                        System.err.println("    Parser:\t" 
     362                                                        + className.substring(className.lastIndexOf(".")+1)); 
     363                                        System.err.println("    Rule/Method: \t" 
     364                                                        + e1.getStackTrace()[0].getMethodName()); 
     365                                         
    352366                                } catch (TokenStreamException e) { 
    353367                                        System.err.println("Token stream exception:"); 
Note: See TracChangeset for help on using the changeset viewer.