KickJava   Java API By Example, From Geeks To Geeks.

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


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.Token;
23 import org.netbeans.api.lexer.TokenId;
24
25 /**
26  * Provides extra properties of a token.
27  * <br/>
28  * Normally each token has an extra instance of the property provider:
29  * <pre>
30  * final class MyTokenPropertyProvider implements TokenPropertyProvider {
31  *
32  * private final Object value;
33  *
34  * TokenPropProvider(Object value) {
35  * this.value = value;
36  * }
37  *
38  * public Object getValue (Token token, Object key) {
39  * if ("type".equals(key))
40  * return value;
41  * return null;
42  * }
43  *
44  * }
45  * </pre>
46  * <br/>
47  * However multiple flyweight instances of the provider may be used to save memory
48  * if there are just several values for a property.
49  * <br/>
50  * Example of two instances of a provider for boolean property "key":
51  * <pre>
52  * final class MyTokenPropertyProvider implements TokenPropertyProvider {
53  *
54  * static final MyTokenPropertyProvider TRUE = new MyTokenPropertyProvider(Boolean.TRUE);
55  *
56  * static final MyTokenPropertyProvider FALSE = new MyTokenPropertyProvider(Boolean.FALSE);
57  *
58  * private final Boolean value;
59  *
60  * private MyTokenPropertyProvider(Boolean value) {
61  * this.value = value;
62  * }
63  *
64  * public Object getValue(Token token, Object key) {
65  * if ("key".equals(key)) {
66  * return value;
67  * }
68  * return null;
69  * }
70  *
71  * }
72  * </pre>
73  * <br/>
74  * A special kind of token <code>PropertyToken</code> allows to carry token properties.
75  *
76  * @author Miloslav Metelka
77  * @version 1.00
78  */

79
80 public interface TokenPropertyProvider<T extends TokenId> {
81     
82     /**
83      * Get value of a token property.
84      *
85      * @param token non-null token for which the property is being retrieved.
86      * It might be useful if the property would be computed dynamically.
87      * @param key non-null key for which the value should be retrieved.
88      * @return value of the property or null if there is no value for the given key.
89      */

90     Object JavaDoc getValue(Token token, Object JavaDoc key);
91
92 }
93
Popular Tags