1 package gnu.text; 2 3 public interface SourceLocator 4 /* #ifdef SAX2 */ 5 extends 6 /* #ifdef use:javax.xml.transform */ 7 javax.xml.transform.SourceLocator, 8 /* #endif */ 9 org.xml.sax.Locator 10 /* #endif */ 11 { 12 /** Return current line number. 13 * Normally the same as {@code getStartLine()}. 14 * The "first" line is line 1; unknown is -1. */ getLineNumber()15 public int getLineNumber(); 16 17 /** Return current column number. 18 * Normally the same as {@code getStartColumn()}. 19 * The "first" column is column 1; unknown is -1. */ getColumnNumber()20 public int getColumnNumber(); 21 22 /** Line number (one-origin) of start of range; unknown/unspecified is -1. */ getStartLine()23 public int getStartLine(); 24 /** Column (one-origin) of start of range; unknown/unspecified is -1. */ getStartColumn()25 public int getStartColumn(); 26 /** Line number (one-origin) of end of range; unknown/unspecified is -1. */ getEndLine()27 public int getEndLine(); 28 /** Column (one-origin) of end of range; unknown/unspecified is -1. */ getEndColumn()29 public int getEndColumn(); 30 getPublicId()31 public String getPublicId(); 32 getSystemId()33 public String getSystemId(); 34 /** Normally same as getSystemId. */ getFileName()35 public String getFileName(); 36 37 /** True if position is unlikely to change. 38 * True for an expression but not an input file. */ isStableSourceLocation()39 public boolean isStableSourceLocation(); 40 41 public static class Simple implements SourceLocator { 42 protected String filename; 43 protected long position; 44 getFileName()45 public String getFileName() { 46 return filename; 47 } 48 isRepl()49 public boolean isRepl() { return "/dev/tty".equals(getFileName()); } 50 getPublicId()51 public String getPublicId() { 52 return null; 53 } 54 getSystemId()55 public String getSystemId() { 56 return filename; 57 } 58 getLineNumber()59 public int getLineNumber() { 60 return SourceMapper.simpleStartLine(position); 61 } 62 getColumnNumber()63 public int getColumnNumber() { 64 return SourceMapper.simpleStartColumn(position); 65 } 66 getStartLine()67 public int getStartLine() { 68 return SourceMapper.simpleStartLine(position); 69 } 70 getStartColumn()71 public int getStartColumn() { 72 return SourceMapper.simpleStartColumn(position); 73 } 74 getEndLine()75 public int getEndLine() { 76 return SourceMapper.simpleEndLine(position); 77 } 78 getEndColumn()79 public int getEndColumn() { 80 return SourceMapper.simpleEndColumn(position); 81 } 82 isStableSourceLocation()83 public boolean isStableSourceLocation() { return true; } 84 setFile(String filename)85 public void setFile(String filename) { 86 this.filename = filename; 87 } setLine(String filename, int line, int column)88 public void setLine(String filename, int line, int column) { 89 setFile(filename); 90 setLine(line, column); 91 } 92 setLine(int lineno, int colno)93 public void setLine(int lineno, int colno) { 94 position = SourceMapper.simpleEncode(lineno, colno); 95 } 96 setLine(int lineno)97 public void setLine(int lineno) { 98 setLine (lineno, 0); 99 } 100 setLocation(SourceLocator location)101 public void setLocation(SourceLocator location) { 102 this.filename = location.getFileName(); 103 this.position = SourceMapper.simpleEncode(location); 104 } 105 } 106 } 107