001: /*
002: * Sun Public License Notice
003: *
004: * The contents of this file are subject to the Sun Public License
005: * Version 1.0 (the "License"). You may not use this file except in
006: * compliance with the License. A copy of the License is available at
007: * http://www.sun.com/
008: *
009: * The Original Code is NetBeans. The Initial Developer of the Original
010: * Code is Sun Microsystems, Inc. Portions Copyright 1997-2000 Sun
011: * Microsystems, Inc. All Rights Reserved.
012: */
013:
014: package org.netbeans.editor;
015:
016: /**
017: * Token-item presents a token as a piece information without dependence on a
018: * character buffer and it enables to chain the token-items in both directions.
019: *
020: * @author Miloslav Metelka
021: * @version 1.00
022: */
023:
024: public interface TokenItem {
025:
026: /** Get the token-id of this token-item */
027: public TokenID getTokenID();
028:
029: /** Get the token-id of this token-item */
030: public TokenContextPath getTokenContextPath();
031:
032: /** Get the position of the token in the document */
033: public int getOffset();
034:
035: /** Get the image of this token. */
036: public String getImage();
037:
038: /**
039: * Get next token-item in the text. It returns null if there's no more next
040: * tokens in the text. It can throw <tt>IllegalStateException</tt> in case
041: * the document was changed so the token-item chain becomes invalid.
042: */
043: public TokenItem getNext();
044:
045: /**
046: * Get previous token-item in the text. It returns null if there's no more
047: * previous tokens in the text. It can throw <tt>IllegalStateException</tt>
048: * in case the document was changed so the token-item chain becomes invalid.
049: */
050: public TokenItem getPrevious();
051:
052: /** Abstract implementation that doesn't contain chaining methods. */
053: public static abstract class AbstractItem implements TokenItem {
054:
055: private TokenID tokenID;
056:
057: private TokenContextPath tokenContextPath;
058:
059: private String image;
060:
061: private int offset;
062:
063: public AbstractItem(TokenID tokenID,
064: TokenContextPath tokenContextPath, int offset,
065: String image) {
066: this .tokenID = tokenID;
067: this .tokenContextPath = tokenContextPath;
068: this .offset = offset;
069: this .image = image;
070: }
071:
072: public TokenID getTokenID() {
073: return tokenID;
074: }
075:
076: public TokenContextPath getTokenContextPath() {
077: return tokenContextPath;
078: }
079:
080: public int getOffset() {
081: return offset;
082: }
083:
084: public String getImage() {
085: return image;
086: }
087:
088: public String toString() {
089: return "'"
090: + org.netbeans.editor.EditorDebug
091: .debugString(getImage()) + "', tokenID="
092: + getTokenID() + ", tcp=" + getTokenContextPath()
093: + ", offset=" + getOffset();
094: }
095:
096: }
097:
098: /** Implementation useful for delegation. */
099: public static class FilterItem implements TokenItem {
100:
101: protected TokenItem delegate;
102:
103: public FilterItem(TokenItem delegate) {
104: this .delegate = delegate;
105: }
106:
107: public TokenID getTokenID() {
108: return delegate.getTokenID();
109: }
110:
111: public TokenContextPath getTokenContextPath() {
112: return delegate.getTokenContextPath();
113: }
114:
115: public int getOffset() {
116: return delegate.getOffset();
117: }
118:
119: public String getImage() {
120: return delegate.getImage();
121: }
122:
123: public TokenItem getNext() {
124: return delegate.getNext();
125: }
126:
127: public TokenItem getPrevious() {
128: return delegate.getPrevious();
129: }
130:
131: public String toString() {
132: return delegate.toString();
133: }
134:
135: }
136:
137: }
|