KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > lib > lexer > inc > TokenHierarchyEventInfo


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.lib.lexer.inc;
21
22 import org.netbeans.api.lexer.TokenChange;
23 import org.netbeans.api.lexer.TokenHierarchyEventType;
24 import org.netbeans.api.lexer.TokenId;
25 import org.netbeans.lib.lexer.LexerApiPackageAccessor;
26 import org.netbeans.lib.lexer.LexerSpiPackageAccessor;
27 import org.netbeans.lib.lexer.TokenHierarchyOperation;
28
29 /**
30  * Shared information for all the token list changes
31  * for a single token hierarchy event.
32  *
33  * @author Miloslav Metelka
34  * @version 1.00
35  */

36
37 public final class TokenHierarchyEventInfo {
38
39     private final TokenHierarchyOperation<?,?> tokenHierarchyOperation;
40
41     private final TokenHierarchyEventType type;
42     
43     private TokenChange<? extends TokenId> tokenChange;
44
45     private final int modificationOffset;
46
47     private final int removedLength;
48
49     private final CharSequence JavaDoc removedText;
50
51     private final int insertedLength;
52
53     private OriginalText originalText;
54     
55     private int affectedStartOffset;
56     
57     private int affectedEndOffset;
58
59     public TokenHierarchyEventInfo(TokenHierarchyOperation<?,? extends TokenId> tokenHierarchyOperation,
60     TokenHierarchyEventType type, int modificationOffset, int removedLength, CharSequence JavaDoc removedText, int insertedLength) {
61         // Initial checks
62
if (modificationOffset < 0) {
63             throw new IllegalArgumentException JavaDoc("modificationOffset=" + modificationOffset + " < 0"); // NOI18N
64
}
65         if (removedLength < 0) {
66             throw new IllegalArgumentException JavaDoc("removedLength=" + removedLength + " < 0"); // NOI18N
67
}
68         if (insertedLength < 0) {
69             throw new IllegalArgumentException JavaDoc("insertedLength=" + insertedLength + " < 0"); // NOI18N
70
}
71
72         this.tokenHierarchyOperation = tokenHierarchyOperation;
73         this.type = type;
74         this.modificationOffset = modificationOffset;
75         this.removedLength = removedLength;
76         this.removedText = removedText;
77         this.insertedLength = insertedLength;
78     }
79
80     public TokenHierarchyOperation<?,? extends TokenId> tokenHierarchyOperation() {
81         return tokenHierarchyOperation;
82     }
83
84     public TokenHierarchyEventType type() {
85         return type;
86     }
87     
88     public TokenChange<? extends TokenId> tokenChange() {
89         return tokenChange;
90     }
91     
92     public void setTokenChangeInfo(TokenChangeInfo<? extends TokenId> info) {
93         this.tokenChange = LexerApiPackageAccessor.get().createTokenChange(info);
94     }
95     
96     public int affectedStartOffset() {
97         return affectedStartOffset;
98     }
99     
100     public void setAffectedStartOffset(int affectedStartOffset) {
101         this.affectedStartOffset = affectedStartOffset;
102     }
103
104     public int affectedEndOffset() {
105         return affectedEndOffset;
106     }
107     
108     public void setAffectedEndOffset(int affectedEndOffset) {
109         this.affectedEndOffset = affectedEndOffset;
110     }
111
112     public int modificationOffset() {
113         return modificationOffset;
114     }
115
116     public int removedLength() {
117         return removedLength;
118     }
119
120     public CharSequence JavaDoc removedText() {
121         return removedText;
122     }
123
124     public int insertedLength() {
125         return insertedLength;
126     }
127
128     public OriginalText originalText() {
129         if (originalText == null) {
130             if (removedLength != 0 && removedText == null) {
131                 throw new IllegalStateException JavaDoc("Cannot obtain removed text for " // NOI18N
132
+ tokenHierarchyOperation.mutableInputSource()
133                         + " which breaks token snapshots operation and" // NOI18N
134
+ " token text retaining after token's removal." // NOI18N
135
+ " Valid removedText in TokenHierarchyControl.textModified()" // NOI18N
136
+ " should be provided." // NOI18N
137
);
138             }
139             originalText = new OriginalText(
140                     LexerSpiPackageAccessor.get().text(tokenHierarchyOperation.mutableTextInput()),
141                     modificationOffset, removedText, insertedLength
142                     );
143         }
144         return originalText;
145     }
146
147 }
148
Popular Tags