1
2
3
4
5 package com.randomnoun.common.jexl.ast;
6
7 import java.util.*;
8
9
10
11
12 public class NodeToken implements Node {
13 public NodeToken(String s) {
14 this(s, -1, -1, -1, -1, -1); }
15
16 public NodeToken(String s, int kind, int beginLine, int beginColumn, int endLine, int endColumn) {
17 tokenImage = s;
18 specialTokens = null;
19 this.kind = kind;
20 this.beginLine = beginLine;
21 this.beginColumn = beginColumn;
22 this.endLine = endLine;
23 this.endColumn = endColumn;
24 }
25
26 public NodeToken getSpecialAt(int i) {
27 if ( specialTokens == null )
28 throw new java.util.NoSuchElementException("No specials in token");
29 return specialTokens.elementAt(i);
30 }
31
32 public int numSpecials() {
33 if ( specialTokens == null ) return 0;
34 return specialTokens.size();
35 }
36
37 public void addSpecial(NodeToken s) {
38 if ( specialTokens == null ) specialTokens = new Vector<NodeToken>();
39 specialTokens.addElement(s);
40 }
41
42 public void trimSpecials() {
43 if ( specialTokens == null ) return;
44 specialTokens.trimToSize();
45 }
46
47 public String toString() { return tokenImage; }
48
49 public String withSpecials() {
50 if ( specialTokens == null )
51 return tokenImage;
52
53 StringBuffer buf = new StringBuffer();
54
55 for ( Enumeration<NodeToken> e = specialTokens.elements(); e.hasMoreElements(); )
56 buf.append(e.nextElement().toString());
57
58 buf.append(tokenImage);
59 return buf.toString();
60 }
61
62 public void accept(com.randomnoun.common.jexl.visitor.Visitor v) {
63 v.visit(this);
64 }
65 public <R,A> R accept(com.randomnoun.common.jexl.visitor.GJVisitor<R,A> v, A argu) {
66 return v.visit(this,argu);
67 }
68 public <R> R accept(com.randomnoun.common.jexl.visitor.GJNoArguVisitor<R> v) {
69 return v.visit(this);
70 }
71 public <A> void accept(com.randomnoun.common.jexl.visitor.GJVoidVisitor<A> v, A argu) {
72 v.visit(this,argu);
73 }
74
75 public String tokenImage;
76
77
78 public Vector<NodeToken> specialTokens;
79
80
81 public int beginLine, beginColumn, endLine, endColumn;
82
83
84
85 public int kind;
86 }
87