1 24 25 package org.aspectj.compiler.base.ast; 26 27 import org.aspectj.compiler.base.*; 28 29 import java.util.*; 30 import java.io.File ; 31 32 public class TextSourceLocation extends SourceLocation { 33 protected int startPosition = -1; 34 protected int endPosition = -1; 35 protected CompilationUnit compilationUnit; 36 37 protected Comment comment; 39 40 public String toString() { 41 return "TextSourceLocation(" + getSourceFileName() + ":" + 42 getBeginLine() + ":" + getBeginColumn() + ")"; 43 } 44 45 46 public TextSourceLocation(CompilationUnit compilationUnit, int start, int end) { 47 this.compilationUnit = compilationUnit; 48 this.startPosition = start; 49 this.endPosition = end; 50 } 51 52 public JavaCompiler getCompiler() { return getCompilationUnit().getCompiler(); } 53 54 public int getStartPosition() { return startPosition; } 55 public int getEndPosition() { return endPosition; } 56 57 public int getBeginLine() { 58 if (startPosition == -1) return -1; 59 return getCompilationUnit().getLine(startPosition); 60 } 61 62 public int getEndLine() { 63 if (endPosition == -1) return -1; 64 return getCompilationUnit().getLine(endPosition); 65 } 66 67 public int getBeginColumn() { 68 if (startPosition == -1) return -1; 69 return getCompilationUnit().getColumn(startPosition); 70 } 71 72 public int getEndColumn() { 73 if (endPosition == -1) return -1; 74 return getCompilationUnit().getColumn(endPosition); 75 } 76 77 public Comment getComment() { 78 return comment; 79 } 80 81 public void addComment(Comment _comment) { 82 if (comment == null) { 83 comment = _comment; 84 } else { 85 comment.addComment(_comment); 86 } 87 } 88 89 public void clearComment() { 90 comment = null; 91 } 92 93 public void setFormalComment(String comment) { 94 addComment(new FormalComment(comment)); 96 } 97 98 public String getFormalComment() { 99 if (comment == null) return ""; 100 return comment.getFormalComment(); 101 } 102 103 public CompilationUnit getCompilationUnit() { 104 return compilationUnit; 105 } 106 107 public java.io.File getSourceFile() { 108 return getCompilationUnit().getSourceFile(); 109 } 110 111 public String getSourceFileName() { 112 return getCompilationUnit().getSourceCanonicalPath(); 113 } 114 115 public String getSourceDirectoryName() { 116 return getCompilationUnit().getSourceDirectory(); 117 } 118 119 public boolean isSynthetic() { 120 return false; 121 } 122 123 public boolean hasSource() { 124 return getCompilationUnit().getSourceFile() != null; 125 } 126 public boolean fromSource() { 127 return hasSource() && getCompilationUnit().getDecs() != null; 128 } 129 } 130 | Popular Tags |