luehe 2004/05/11 17:26:53 Modified: jasper2/src/share/org/apache/jasper/compiler Mark.java Log: Code cleanup/reformatting prior to making any changes Revision Changes Path 1.6 +155 -122 jakarta-tomcat-jasper/jasper2/src/share/org/apache/jasper/compiler/Mark.java Index: Mark.java =================================================================== RCS file: /home/cvs/jakarta-tomcat-jasper/jasper2/src/share/org/apache/jasper/compiler/Mark.java,v retrieving revision 1.5 retrieving revision 1.6 diff -u -r1.5 -r1.6 --- Mark.java 17 Mar 2004 19:23:03 -0000 1.5 +++ Mark.java 12 May 2004 00:26:53 -0000 1.6 @@ -23,154 +23,157 @@ * @author Anil K. Vijendran */ final class Mark { - int cursor, line, col; // position within current stream - int fileid; // fileid of current stream - String fileName; // name of the current file - String baseDir; // directory of file for current stream - char[] stream = null; // current stream - Stack includeStack = null; // stack of stream and stream state of streams - // that have included current stream - String encoding = null; // encoding of current file - private JspReader reader; // reader that owns this mark - // (so we can look up fileid's) + + // position within current stream + int cursor, line, col; + + // directory of file for current stream + String baseDir; + + // current stream + char[] stream = null; + + // fileid of current stream + private int fileId; + + // name of the current file + private String fileName; + + /* + * stack of stream and stream state of streams that have included + * current stream + */ + private Stack includeStack = null; + + // encoding of current file + private String encoding = null; + + // reader that owns this mark (so we can look up fileid's) + private JspReader reader; /** - * Keep track of parser before parsing an included file. - * This class keeps track of the parser before we switch to parsing an - * included file. In other words, it's the parser's continuation to be - * reinstalled after the included file parsing is done. + * Constructor + * + * @param reader JspReader this mark belongs to + * @param inStream current stream for this mark + * @param fileId id of requested jsp file + * @param name JSP file name + * @param inBaseDir base directory of requested jsp file + * @param inEncoding encoding of current file */ - class IncludeState { - int cursor, line, col; - int fileid; - String fileName; - String baseDir; - String encoding; - char[] stream = null; - - IncludeState(int inCursor, int inLine, int inCol, int inFileid, - String name, String inBaseDir, String inEncoding, - char[] inStream) - { - cursor = inCursor; - line = inLine; - col = inCol; - fileid = inFileid; - fileName = name; - baseDir = inBaseDir; - encoding = inEncoding; - stream = inStream; - } + Mark(JspReader reader, char[] inStream, int fileId, String name, + String inBaseDir, String inEncoding) { + + this.reader = reader; + this.stream = inStream; + this.cursor = 0; + this.line = 1; + this.col = 1; + this.fileId = fileId; + this.fileName = name; + this.baseDir = inBaseDir; + this.encoding = inEncoding; + this.includeStack = new Stack(); } /** - * Creates a new mark - * @param inReader JspReader this mark belongs to - * @param inStream current stream for this mark - * @param inFileid id of requested jsp file - * @param inEncoding encoding of current file - * @param inBaseDir base directory of requested jsp file - */ - Mark(JspReader reader, char[] inStream, int fileid, String name, - String inBaseDir, String inEncoding) - { - this.reader = reader; - this.stream = inStream; - this.cursor = 0; - this.line = 1; - this.col = 1; - this.fileid = fileid; - this.fileName = name; - this.baseDir = inBaseDir; - this.encoding = inEncoding; - this.includeStack = new Stack(); - } - + * Constructor + */ Mark(Mark other) { - this.reader = other.reader; - this.stream = other.stream; - this.fileid = other.fileid; - this.fileName = other.fileName; - this.cursor = other.cursor; - this.line = other.line; - this.col = other.col; - this.baseDir = other.baseDir; - this.encoding = other.encoding; - - // clone includeStack without cloning contents - includeStack = new Stack(); - for ( int i=0; i < other.includeStack.size(); i++ ) { - includeStack.addElement( other.includeStack.elementAt(i) ); - } + + this.reader = other.reader; + this.stream = other.stream; + this.fileId = other.fileId; + this.fileName = other.fileName; + this.cursor = other.cursor; + this.line = other.line; + this.col = other.col; + this.baseDir = other.baseDir; + this.encoding = other.encoding; + + // clone includeStack without cloning contents + includeStack = new Stack(); + for ( int i=0; i < other.includeStack.size(); i++ ) { + includeStack.addElement( other.includeStack.elementAt(i) ); + } } - + + + /** + * Constructor + */ Mark(String filename, int line, int col) { - //System.out.println("MARK: filename is: " + filename); - this.reader = null; - this.stream = null; - this.cursor = 0; - this.line = line; - this.col = col; - this.fileid = -1; - this.fileName = filename; - this.baseDir = "le-basedir"; - this.encoding = "le-endocing"; - this.includeStack = null; + + this.reader = null; + this.stream = null; + this.cursor = 0; + this.line = line; + this.col = col; + this.fileId = -1; + this.fileName = filename; + this.baseDir = "le-basedir"; + this.encoding = "le-endocing"; + this.includeStack = null; } - /** Sets this mark's state to a new stream. + + /** + * Sets this mark's state to a new stream. * It will store the current stream in it's includeStack. + * * @param inStream new stream for mark - * @param inFileid id of new file from which stream comes from + * @param inFileId id of new file from which stream comes from * @param inBaseDir directory of file - * @param inEncoding encoding of new file + * @param inEncoding encoding of new file */ - public void pushStream(char[] inStream, int inFileid, String name, - String inBaseDir, String inEncoding) + public void pushStream(char[] inStream, int inFileId, String name, + String inBaseDir, String inEncoding) { - - // store current state in stack - includeStack.push(new IncludeState(cursor, line, col, fileid, fileName, baseDir, + // store current state in stack + includeStack.push(new IncludeState(cursor, line, col, fileId, + fileName, baseDir, encoding, stream) ); - // set new variables - cursor = 0; - line = 1; - col = 1; - fileid = inFileid; - fileName = name; - baseDir = inBaseDir; - encoding = inEncoding; - stream = inStream; + // set new variables + cursor = 0; + line = 1; + col = 1; + fileId = inFileId; + fileName = name; + baseDir = inBaseDir; + encoding = inEncoding; + stream = inStream; } + /** - /* Restores this mark's state to a previously stored stream. - * @return null if there is no previous stream - * The previous Makr instance when the stream is pushed. + * Restores this mark's state to a previously stored stream. + * @return The previous Mark instance when the stream was pushed, or null + * if there is no previous stream */ public Mark popStream() { - // make sure we have something to pop - if ( includeStack.size() <= 0 ) { - return null; - } - - // get previous state in stack - IncludeState state = (IncludeState) includeStack.pop( ); - - // set new variables - cursor = state.cursor; - line = state.line; - col = state.col; - fileid = state.fileid; - fileName = state.fileName; - baseDir = state.baseDir; - stream = state.stream; - return this; + // make sure we have something to pop + if ( includeStack.size() <= 0 ) { + return null; + } + + // get previous state in stack + IncludeState state = (IncludeState) includeStack.pop( ); + + // set new variables + cursor = state.cursor; + line = state.line; + col = state.col; + fileId = state.fileId; + fileName = state.fileName; + baseDir = state.baseDir; + stream = state.stream; + return this; } + // -------------------- Locator interface -------------------- public int getLineNumber() { @@ -204,11 +207,41 @@ public boolean equals(Object other) { if (other instanceof Mark) { Mark m = (Mark) other; - return this.reader == m.reader && this.fileid == m.fileid + return this.reader == m.reader && this.fileId == m.fileId && this.cursor == m.cursor && this.line == m.line && this.col == m.col; } return false; } + + + /** + * Keep track of parser before parsing an included file. + * This class keeps track of the parser before we switch to parsing an + * included file. In other words, it's the parser's continuation to be + * reinstalled after the included file parsing is done. + */ + class IncludeState { + int cursor, line, col; + int fileId; + String fileName; + String baseDir; + String encoding; + char[] stream = null; + + IncludeState(int inCursor, int inLine, int inCol, int inFileId, + String name, String inBaseDir, String inEncoding, + char[] inStream) { + cursor = inCursor; + line = inLine; + col = inCol; + fileId = inFileId; + fileName = name; + baseDir = inBaseDir; + encoding = inEncoding; + stream = inStream; + } + } + }
--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]