1 17 package org.eclipse.emf.codegen.jet; 18 19 20 import java.util.Stack ; 21 22 import org.eclipse.core.resources.IFile; 23 import org.eclipse.core.resources.IWorkspaceRoot; 24 import org.eclipse.core.resources.ResourcesPlugin; 25 import org.eclipse.core.runtime.Path; 26 27 import org.eclipse.emf.codegen.CodeGenPlugin; 28 29 30 33 public final class JETMark 34 { 35 38 protected int cursor; 39 40 43 protected int line; 44 45 48 protected int col; 49 50 53 protected int fileid; 54 55 58 protected String baseDir; 59 60 63 protected char[] stream = null; 64 65 68 protected Stack includeStack = null; 69 70 73 protected String encoding = null; 74 75 78 protected JETReader reader; 79 80 86 class IncludeState 87 { 88 int cursor; 89 int line; 90 int col; 91 int fileid; 92 String baseDir; 93 String encoding; 94 char[] stream = null; 95 96 IncludeState(int inCursor, int inLine, int inCol, int inFileid, String inBaseDir, String inEncoding, char[] inStream) 97 { 98 cursor = inCursor; 99 line = inLine; 100 col = inCol; 101 fileid = inFileid; 102 baseDir = inBaseDir; 103 encoding = inEncoding; 104 stream = inStream; 105 } 106 } 107 108 116 JETMark(JETReader reader, char[] inStream, int fileid, String inBaseDir, String inEncoding) 117 { 118 this.reader = reader; 119 this.stream = inStream; 120 this.cursor = this.line = this.col = 0; 121 this.fileid = fileid; 122 this.baseDir = inBaseDir; 123 this.encoding = inEncoding; 124 this.includeStack = new Stack (); 125 } 126 127 JETMark(JETMark other) 128 { 129 this.reader = other.reader; 130 this.stream = other.stream; 131 this.fileid = other.fileid; 132 this.cursor = other.cursor; 133 this.line = other.line; 134 this.col = other.col; 135 this.baseDir = other.baseDir; 136 this.encoding = other.encoding; 137 138 includeStack = new Stack (); 141 for (int i = 0; i < other.includeStack.size(); ++i) 142 { 143 includeStack.addElement(other.includeStack.elementAt(i)); 144 } 145 } 146 147 155 public void pushStream(char[] inStream, int inFileid, String inBaseDir, String inEncoding) 156 { 157 includeStack.push(new IncludeState(cursor, line, col, fileid, baseDir, encoding, stream) ); 160 161 cursor = 0; 164 line = 0; 165 col = 0; 166 fileid = inFileid; 167 baseDir = inBaseDir; 168 encoding = inEncoding; 169 stream = inStream; 170 } 171 172 175 public boolean popStream() 176 { 177 if (includeStack.size() <= 0) 180 { 181 return false; 182 } 183 184 IncludeState state = (IncludeState) includeStack.pop( ); 187 188 cursor = state.cursor; 191 line = state.line; 192 col = state.col; 193 fileid = state.fileid; 194 baseDir = state.baseDir; 195 stream = state.stream; 196 return true; 197 } 198 199 public String getFile() 200 { 201 return reader.getFile(fileid); 202 } 203 204 public String getBaseURI() 205 { 206 return reader.getBaseURI(fileid); 207 } 208 209 public String getLocalFile() 210 { 211 String file = reader.getFile(fileid); 212 if (file.startsWith("file:/")) 213 { 214 IWorkspaceRoot workspaceRoot = ResourcesPlugin.getWorkspace().getRoot(); 215 IFile iFile = workspaceRoot.getFileForLocation(new Path(file.substring(6))); 216 file = iFile.getFullPath().toString(); 217 } 218 219 return file; 220 } 221 222 public int getFileId() 223 { 224 return fileid; 225 } 226 227 public int getCursor() 228 { 229 return cursor; 230 } 231 232 public String toShortString() 233 { 234 return "(" + line + "," + col + ")"; 235 } 236 237 public String toString() 238 { 239 return getLocalFile() + "(" + line + "," + col + ")"; 240 } 241 242 public String format(String key) 243 { 244 return 245 CodeGenPlugin.getPlugin().getString 246 (key, 247 new Object [] 248 { 249 getLocalFile(), 250 new Integer (line + 1), 251 new Integer (col + 1), 252 new Integer (cursor) 253 }); 254 } 255 256 public boolean equals(Object other) 257 { 258 if (other instanceof JETMark) 259 { 260 JETMark m = (JETMark) other; 261 return 262 this.reader == m.reader && 263 this.fileid == m.fileid && 264 this.cursor == m.cursor && 265 this.line == m.line && 266 this.col == m.col; 267 } 268 return false; 269 } 270 } 271 | Popular Tags |