Index: lexer/libsrc/org/netbeans/api/lexer/Token.java =================================================================== RCS file: /cvs/lexer/libsrc/org/netbeans/api/lexer/Token.java,v retrieving revision 1.2 diff -c -r1.2 Token.java *** lexer/libsrc/org/netbeans/api/lexer/Token.java 3 Apr 2002 11:40:35 -0000 1.2 --- lexer/libsrc/org/netbeans/api/lexer/Token.java 7 Apr 2002 19:21:12 -0000 *************** *** 21,36 **** * @version 1.00 */ ! public interface Token { /** @return non-null identification of this token. */ ! public TokenId getId(); /** Get the text of the token (also called image) * as sequence of characters. */ ! public CharSequence getText(); ! } --- 21,53 ---- * @version 1.00 */ ! public abstract class Token { ! /** data associated to this token by incermental algorithm implementation ! */ ! private Object data; ! ! /** Allows the incremental algorithm access the data field. ! */ ! static { ! class A implements org.netbeans.modules.lexer.inc.Algorithm.TokenAccess { ! public Object getData(Token t) { ! return t.data; ! } ! public void setData(Token t, Object data) { ! t.data = data; ! } ! } ! ! org.netbeans.modules.lexer.inc.Algorithm.registerTokenAccess (new A ()); ! } /** @return non-null identification of this token. */ ! public abstract TokenId getId(); /** Get the text of the token (also called image) * as sequence of characters. */ ! public abstract CharSequence getText(); } Index: lexer/libsrc/org/netbeans/api/lexer/TokenIterator.java =================================================================== RCS file: /cvs/lexer/libsrc/org/netbeans/api/lexer/TokenIterator.java,v retrieving revision 1.4 diff -c -r1.4 TokenIterator.java *** lexer/libsrc/org/netbeans/api/lexer/TokenIterator.java 3 Apr 2002 16:57:11 -0000 1.4 --- lexer/libsrc/org/netbeans/api/lexer/TokenIterator.java 7 Apr 2002 19:21:13 -0000 *************** *** 37,71 **** * of the token to which the iterator is relocated. */ public int relocate(int offset); - - /** Get the value of the attribute attached to the token - * that would be returned by a subsequent call to previous(). - * (Gets the attribute of the last token - * if the iterator is at the end of the list.) - *
Among other attributes the attribute keys - * defined in {@link TokenConstants} can be used. - * @param name non-null name of the attribute - * @return value of the attribute or null if the attribute - * was not found for this attribute. - * @throws IllegalStateException if the iterator is positioned - * before the first token in the list. - */ - public Object getAttribute(Object name); - - /** Set the value of the attribute attached to the token - * that would be returned by a subsequent call to previous(). - * (Sets the attribute of the last token - * if the iterator is at the end of the list.) - *
Among other attributes the attribute keys - * defined in {@link TokenConstants} can be used. - * @param name non-null name of the attribute. The names defined - * in the {@link TokenConstants} can be used here. - * @param value value of the attribute. Passing null - * means removing of the attribute from the token. - * @throws IllegalStateException if the iterator is positioned - * before the first token in the list. - */ - public void setAttribute(Object name, Object value); /** Create the lexer input positioned to the location * of the begining of the token that would be returned --- 37,42 ---- Index: lexer/libsrc/org/netbeans/modules/lexer/inc/Algorithm.java =================================================================== RCS file: /cvs/lexer/libsrc/org/netbeans/modules/lexer/inc/Algorithm.java,v retrieving revision 1.1 diff -c -r1.1 Algorithm.java *** lexer/libsrc/org/netbeans/modules/lexer/inc/Algorithm.java 3 Apr 2002 15:42:11 -0000 1.1 --- lexer/libsrc/org/netbeans/modules/lexer/inc/Algorithm.java 7 Apr 2002 19:21:14 -0000 *************** *** 47,74 **** } protected int getLookahead(TokenIterator it) { ! return ((Integer)it.getAttribute(TokenConstants.LOOKAHEAD)).intValue(); } protected int getLookback(TokenIterator it) { ! Integer lb = (Integer)it.getAttribute(TokenConstants.LOOKBACK); ! return (lb == null) ? -1 : lb.intValue(); } protected Object getState(TokenIterator it) { ! return it.getAttribute(TokenConstants.STATE); } protected void setLookahead(TokenIterator it, int lookahead) { ! it.setAttribute(TokenConstants.LOOKAHEAD, getInteger(lookahead)); } protected void setLookback(TokenIterator it, int lookback) { ! it.setAttribute(TokenConstants.LOOKBACK, getInteger(lookback)); } protected void setState(TokenIterator it, Object state) { ! it.setAttribute(TokenConstants.STATE, state); } public void update(TokenIterator it, Lexer lexer, int offset, int length) { --- 47,83 ---- } protected int getLookahead(TokenIterator it) { ! //access.getData (token); ! //return ((Integer)it.getAttribute(TokenConstants.LOOKAHEAD)).intValue(); ! return -1; } protected int getLookback(TokenIterator it) { ! // access.getData (token); ! //Integer lb = (Integer)it.getAttribute(TokenConstants.LOOKBACK); ! //return (lb == null) ? -1 : lb.intValue(); ! return -1; } protected Object getState(TokenIterator it) { ! // access.getData (token); ! //return it.getAttribute(TokenConstants.STATE); ! return null; } protected void setLookahead(TokenIterator it, int lookahead) { ! // access.setData (token, something); ! //it.setAttribute(TokenConstants.LOOKAHEAD, getInteger(lookahead)); } protected void setLookback(TokenIterator it, int lookback) { ! // access.setData (token, something); ! //it.setAttribute(TokenConstants.LOOKBACK, getInteger(lookback)); } protected void setState(TokenIterator it, Object state) { ! // access.setData (token, something); ! //it.setAttribute(TokenConstants.STATE, state); } public void update(TokenIterator it, Lexer lexer, int offset, int length) { *************** *** 518,521 **** --- 527,549 ---- } + /** The accessor for token data. + */ + private static TokenAccess access; + + /** Method to register a TokenAccess implementation. + */ + public static synchronized void registerTokenAccess (TokenAccess a) { + if (access != null) { + throw new IllegalStateException (); + } + access = a; + } + + /** Interface that allows access to Token associated data. + */ + public static interface TokenAccess { + public void setData (Token t, Object data); + public Object getData (Token t); + } } Index: lexer/libsrc/org/netbeans/modules/lexer/inc/OffsetToken.java =================================================================== RCS file: /cvs/lexer/libsrc/org/netbeans/modules/lexer/inc/OffsetToken.java,v retrieving revision 1.1 diff -c -r1.1 OffsetToken.java *** lexer/libsrc/org/netbeans/modules/lexer/inc/OffsetToken.java 3 Apr 2002 15:42:14 -0000 1.1 --- lexer/libsrc/org/netbeans/modules/lexer/inc/OffsetToken.java 7 Apr 2002 19:21:14 -0000 *************** *** 24,30 **** * @version 1.00 */ ! public interface OffsetToken extends Token { /** @return the start offset of this token. */ --- 24,30 ---- * @version 1.00 */ ! public interface OffsetToken { /** @return the start offset of this token. */ Index: lexer/libsrc/org/netbeans/modules/lexer/swing/TokenElement.java =================================================================== RCS file: /cvs/lexer/libsrc/org/netbeans/modules/lexer/swing/TokenElement.java,v retrieving revision 1.1 diff -c -r1.1 TokenElement.java *** lexer/libsrc/org/netbeans/modules/lexer/swing/TokenElement.java 3 Apr 2002 15:44:25 -0000 1.1 --- lexer/libsrc/org/netbeans/modules/lexer/swing/TokenElement.java 7 Apr 2002 19:21:14 -0000 *************** *** 24,30 **** * @version 1.00 */ ! public interface TokenElement extends Token, Element { } --- 24,30 ---- * @version 1.00 */ ! public interface TokenElement extends Element { }