KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > editor > TokenProcessor


1 /*
2  * The contents of this file are subject to the terms of the Common Development
3  * and Distribution License (the License). You may not use this file except in
4  * compliance with the License.
5  *
6  * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
7  * or http://www.netbeans.org/cddl.txt.
8  *
9  * When distributing Covered Code, include this CDDL Header Notice in each file
10  * and include the License file at http://www.netbeans.org/cddl.txt.
11  * If applicable, add the following below the CDDL Header, with the fields
12  * enclosed by brackets [] replaced by your own identifying information:
13  * "Portions Copyrighted [year] [name of copyright owner]"
14  *
15  * The Original Software is NetBeans. The Initial Developer of the Original
16  * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
17  * Microsystems, Inc. All Rights Reserved.
18  */

19
20 package org.netbeans.editor;
21
22 /** Process the tokens
23 *
24 * @author Miloslav Metelka
25 * @version 1.00
26 */

27
28
29 public interface TokenProcessor {
30
31     /** Notify that the token was found.
32     * @param tokenID ID of the token found
33     * @param tokenContextPath Context-path in which the token that was found.
34     * @param tokenBufferOffset Offset of the token in the buffer. The buffer
35     * is provided in the <tt>nextBuffer()</tt> method.
36     * @param tokenLength Length of the token found
37     * @return true if the next token should be searched or false if the scan should
38     * be stopped completely.
39     */

40     public boolean token(TokenID tokenID, TokenContextPath tokenContextPath,
41                          int tokenBufferOffset, int tokenLength);
42
43     /** Notify that end of scanned buffer was found.
44     * The method decides whether to continue the scan or stop. The rest
45     * of characters that were not scanned, because the is not completed
46     * is also provided.
47     * @param offset offset of the rest of the characters
48     * @return 0 to stop token processing,
49     * &gt 0 process additional characters in the document
50     */

51     public int eot(int offset);
52
53     /** Notify that the following buffer will be scanned. This method
54     * is called before the buffer is being scanned.
55     * @param buffer buffer that will be scanned. To get the text of the tokens
56     * the buffer should be stored in some instance variable.
57     * @param offset offset in the buffer with the first character to be scanned.
58     * If doesn't reflect the possible preScan. If the preScan would be non-zero
59     * then the first buffer offset that contains the valid data is
60     * <tt>offset - preScan</tt>.
61     * @param len count of the characters that will be scanned. It doesn't reflect
62     * the ppossible reScan.
63     * @param startPos starting position of the scanning in the document. It
64     * logically corresponds to the <tt>offset</tt> because of the same
65     * text data both in the buffer and in the document.
66     * It again doesn't reflect the possible preScan and the <tt>startPos - preScan</tt>
67     * gives the real start of the first token. If it's necessary to know
68     * the position of each token, it's a good idea to store the value
69     * <tt>startPos - offset</tt> in an instance variable that could be called
70     * <tt>bufferStartPos</tt>. The position of the token can be then computed
71     * as <tt>bufferStartPos + tokenBufferOffset</tt>.
72     * @param preScan preScan needed for the scanning.
73     * @param lastBuffer whether this is the last buffer to scan in the document
74     * so there are no more characters in the document after this buffer.
75     * @*/

76     public void nextBuffer(char[] buffer, int offset, int len,
77                            int startPos, int preScan, boolean lastBuffer);
78
79 }
80
Popular Tags