KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > jdt > internal > ui > javaeditor > SemanticToken


1 /*******************************************************************************
2  * Copyright (c) 2000, 2005 IBM Corporation and others.
3  * All rights reserved. This program and the accompanying materials
4  * are made available under the terms of the Eclipse Public License v1.0
5  * which accompanies this distribution, and is available at
6  * http://www.eclipse.org/legal/epl-v10.html
7  *
8  * Contributors:
9  * IBM Corporation - initial API and implementation
10  *******************************************************************************/

11
12 package org.eclipse.jdt.internal.ui.javaeditor;
13
14 import org.eclipse.jdt.core.dom.CompilationUnit;
15 import org.eclipse.jdt.core.dom.Expression;
16 import org.eclipse.jdt.core.dom.IBinding;
17 import org.eclipse.jdt.core.dom.SimpleName;
18
19 /**
20  * Semantic token
21  */

22 public final class SemanticToken {
23
24     /** AST node */
25     private SimpleName fNode;
26     private Expression fLiteral;
27
28     /** Binding */
29     private IBinding fBinding;
30     /** Is the binding resolved? */
31     private boolean fIsBindingResolved= false;
32
33     /** AST root */
34     private CompilationUnit fRoot;
35     private boolean fIsRootResolved= false;
36
37     /**
38      * @return Returns the binding, can be <code>null</code>.
39      */

40     public IBinding getBinding() {
41         if (!fIsBindingResolved) {
42             fIsBindingResolved= true;
43             if (fNode != null)
44                 fBinding= fNode.resolveBinding();
45         }
46         
47         return fBinding;
48     }
49
50     /**
51      * @return the AST node (a {@link SimpleName})
52      */

53     public SimpleName getNode() {
54         return fNode;
55     }
56     
57     /**
58      * @return the AST node (a <code>Boolean-, Character- or NumberLiteral</code>)
59      */

60     public Expression getLiteral() {
61         return fLiteral;
62     }
63
64     /**
65      * @return the AST root
66      */

67     public CompilationUnit getRoot() {
68         if (!fIsRootResolved) {
69             fIsRootResolved= true;
70             fRoot= (CompilationUnit) (fNode != null ? fNode : fLiteral).getRoot();
71         }
72
73         return fRoot;
74     }
75
76     /**
77      * Update this token with the given AST node.
78      * <p>
79      * NOTE: Allowed to be used by {@link SemanticHighlightingReconciler} only.
80      * </p>
81      *
82      * @param node the AST simple name
83      */

84     void update(SimpleName node) {
85         clear();
86         fNode= node;
87     }
88
89     /**
90      * Update this token with the given AST node.
91      * <p>
92      * NOTE: Allowed to be used by {@link SemanticHighlightingReconciler} only.
93      * </p>
94      *
95      * @param literal the AST literal
96      */

97     void update(Expression literal) {
98         clear();
99         fLiteral= literal;
100     }
101
102     /**
103      * Clears this token.
104      * <p>
105      * NOTE: Allowed to be used by {@link SemanticHighlightingReconciler} only.
106      * </p>
107      */

108     void clear() {
109         fNode= null;
110         fLiteral= null;
111         fBinding= null;
112         fIsBindingResolved= false;
113         fRoot= null;
114         fIsRootResolved= false;
115     }
116 }
117
Popular Tags