KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > api > lexer > TokenHierarchyEvent


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.api.lexer;
21
22 import org.netbeans.lib.lexer.inc.TokenHierarchyEventInfo;
23 import org.netbeans.lib.lexer.inc.TokenListChange;
24
25 /**
26  * Description of the changes made in a token hierarchy.
27  *
28  * @author Miloslav Metelka
29  * @version 1.00
30  */

31
32 public final class TokenHierarchyEvent extends java.util.EventObject JavaDoc {
33
34     private final TokenHierarchyEventInfo info;
35
36     TokenHierarchyEvent(TokenHierarchyEventInfo info) {
37         super(info.tokenHierarchyOperation().tokenHierarchy());
38         this.info = info;
39     }
40
41     /**
42      * Get source of this event as a token hierarchy instance.
43      */

44     public TokenHierarchy<?> tokenHierarchy() {
45         return (TokenHierarchy<?>)getSource();
46     }
47     
48     /**
49      * Get reason why a token hierarchy event was fired.
50      */

51     public TokenHierarchyEventType type() {
52         return info.type();
53     }
54
55     /**
56      * Get the token change that occurred in the tokens
57      * at the top-level of the token hierarchy.
58      */

59     public TokenChange<? extends TokenId> tokenChange() {
60         return info.tokenChange();
61     }
62
63     /**
64      * Get the token change if the top level of the token hierarchy
65      * contains tokens of the given language.
66      *
67      * @param language non-null language.
68      * @return non-null token change if the language at the top level
69      * of the token hierarchy equals to the given language.
70      * Returns null otherwise.
71      */

72     public <T extends TokenId> TokenChange<T> tokenChange(Language<T> language) {
73         TokenChange<? extends TokenId> tc = tokenChange();
74         @SuppressWarnings JavaDoc("unchecked")
75         TokenChange<T> tcl = (tc != null && tc.language() == language) ? (TokenChange<T>)tc : null;
76         return tcl;
77     }
78     
79     /**
80      * Get start offset of the area that was affected by the attached
81      * token change(s).
82      */

83     public int affectedStartOffset() {
84         return info.affectedStartOffset();
85     }
86     
87     /**
88      * Get end offset of the area that was affected by the attached
89      * token change(s).
90      * <br/>
91      * If there was a text modification the offsets are related
92      * to the state after the modification.
93      */

94     public int affectedEndOffset() {
95         return info.affectedEndOffset();
96     }
97
98     /**
99      * Get offset in the input source where the modification occurred.
100      *
101      * @return modification offset or -1
102      * if this event's type is not {@link TokenHierarchyEventType#MODIFICATION}.
103      */

104     public int modificationOffset() {
105         return info.modificationOffset();
106     }
107     
108     /**
109      * Get number of characters inserted by the text modification
110      * that caused this token change.
111      *
112      * @return number of inserted characters by the modification.
113      * <br/>
114      * Returns 0
115      * if this event's type is not {@link TokenHierarchyEventType#MODIFICATION}.
116      */

117     public int insertedLength() {
118         return info.insertedLength();
119     }
120     
121     /**
122      * Get number of characters removed by the text modification
123      * that caused this token change.
124      *
125      * @return number of inserted characters by the modification.
126      * <br/>
127      * Returns 0
128      * if this event's type is not {@link TokenHierarchyEventType#MODIFICATION}.
129      */

130     public int removedLength() {
131         return info.removedLength();
132     }
133     
134
135 }
Popular Tags