KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > spi > lexer > MutableTextInput


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-2007 Sun
17  * Microsystems, Inc. All Rights Reserved.
18  */

19
20 package org.netbeans.spi.lexer;
21
22 import org.netbeans.api.lexer.InputAttributes;
23 import org.netbeans.api.lexer.Language;
24 import org.netbeans.api.lexer.TokenId;
25
26 /**
27  * Mutable attributed character sequence allowing to listen for changes in its text.
28  *
29  * <p>
30  * The input can temporarily be made inactive which leads to dropping
31  * of all the present tokens for the input until the input becomes
32  * active again.
33  * </p>
34  *
35  * @author Miloslav Metelka
36  * @version 1.00
37  */

38
39 public abstract class MutableTextInput<I> {
40
41     private TokenHierarchyControl<I> thc;
42
43     /**
44      * Get the language suitable for lexing of this input.
45      *
46      * @return language language by which the text of this input should be lexed.
47      * <br/>
48      * This method is only checked upon creation of token hierarchy.
49      * <br/>
50      * If this method returns null the token hierarchy cannot be created
51      * and will be returned as null upon asking until this method will return
52      * non-null value.
53      */

54     protected abstract Language<? extends TokenId> language();
55
56     /**
57      * Get the character sequence provided and maintained by this input.
58      */

59     protected abstract CharSequence JavaDoc text();
60     
61     /**
62      * Get lexer-specific information about this input
63      * or null if there is no specific information.
64      * <br>
65      * The attributes are typically retrieved by the lexer.
66      */

67     protected abstract InputAttributes inputAttributes();
68     
69     /**
70      * Get object that logically provides the text
71      * for this mutable text input.
72      * <br/>
73      * For example it may be a swing text document instance
74      * {@link javax.swing.text.Document} in case the result of {@link #text()}
75      * is the content of the document.
76      *
77      * @return non-null mutable input source.
78      */

79     protected abstract I inputSource();
80     
81     /**
82      * Get token hierarchy control for this mutable text input.
83      * <br>
84      * Each mutable text input can hold it in a specific way
85      * e.g. swing document can use
86      * <code>getProperty(TokenHierarchyControl.class)</code>.
87      */

88     public final TokenHierarchyControl<I> tokenHierarchyControl() {
89         synchronized (this) {
90             if (thc == null) {
91                 thc = new TokenHierarchyControl<I>(this);
92             }
93             return thc;
94         }
95     }
96
97 }
98
Popular Tags