1 19 package org.netbeans.modules.ruby.rubyproject.execution; 20 21 import java.util.regex.Matcher ; 22 import java.util.regex.Pattern ; 23 24 import org.netbeans.modules.ruby.rubyproject.execution.OutputRecognizer.FileLocation; 25 import org.openide.ErrorManager; 26 27 28 35 public class RegexpOutputRecognizer extends OutputRecognizer { 36 private final Pattern pattern; 37 private final int fileGroup; 38 private final int lineGroup; 39 private final int columnGroup; 40 41 42 public RegexpOutputRecognizer(String regexp, int fileGroup, int lineGroup, int columnGroup) { 43 pattern = Pattern.compile(regexp); 44 this.fileGroup = fileGroup; 45 this.lineGroup = lineGroup; 46 this.columnGroup = columnGroup; 47 } 48 49 @Override 50 public FileLocation processLine(String line) { 51 Matcher match = pattern.matcher(line); 52 53 if (match.matches()) { 54 String file = null; 55 int lineno = -1; 56 int column = -1; 57 58 if (fileGroup != -1) { 59 file = match.group(fileGroup); 60 } 61 62 if (lineGroup != -1) { 63 String linenoStr = match.group(lineGroup); 64 65 try { 66 lineno = Integer.parseInt(linenoStr); 67 } catch (NumberFormatException nfe) { 68 ErrorManager.getDefault().notify(nfe); 69 lineno = 0; 70 } 71 } 72 73 if (columnGroup != -1) { 74 String columnStr = match.group(columnGroup); 75 76 try { 77 column = Integer.parseInt(columnStr); 78 } catch (NumberFormatException nfe) { 79 ErrorManager.getDefault().notify(nfe); 80 column = 0; 81 } 82 } 83 84 return new FileLocation(file, lineno, column); 85 } 86 87 return null; 88 } 89 } 90 | Popular Tags |