KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jacorb > notification > filter > etcl > PlusOperator


1 package org.jacorb.notification.filter.etcl;
2
3 /*
4  * JacORB - a free Java ORB
5  *
6  * Copyright (C) 1999-2004 Gerald Brose
7  *
8  * This library is free software; you can redistribute it and/or
9  * modify it under the terms of the GNU Library General Public
10  * License as published by the Free Software Foundation; either
11  * version 2 of the License, or (at your option) any later version.
12  *
13  * This library is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16  * Library General Public License for more details.
17  *
18  * You should have received a copy of the GNU Library General Public
19  * License along with this library; if not, write to the Free
20  * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
21  *
22  */

23
24 import org.jacorb.notification.filter.EvaluationContext;
25 import org.jacorb.notification.filter.EvaluationException;
26 import org.jacorb.notification.filter.EvaluationResult;
27
28 import antlr.Token;
29
30 /**
31  * A simple node to represent PLUS operation
32  */

33
34 public class PlusOperator extends UnaryOperator
35 {
36     private boolean isUnaryOperator_;
37
38     public PlusOperator(Token tok)
39     {
40         super(tok);
41         setName("PlusOperator");
42     }
43
44     public void setType(int type)
45     {
46         isUnaryOperator_ = (type == UNARY_PLUS);
47     }
48
49     public String JavaDoc toString()
50     {
51         return " +";
52     }
53
54     public EvaluationResult evaluate(EvaluationContext context, EvaluationResult left)
55             throws EvaluationException
56     {
57         if (isUnaryOperator_)
58         {
59             return left;
60         }
61
62         return EvaluationResult.plus(left, right().evaluate(context));
63     }
64
65     public boolean isStatic()
66     {
67         return (left().isStatic() && right().isStatic());
68     }
69
70     public void acceptInOrder(AbstractTCLVisitor visitor) throws VisitorException
71     {
72         left().acceptInOrder(visitor);
73         visitor.visitPlus(this);
74         if (!isUnaryOperator_)
75         {
76             right().acceptInOrder(visitor);
77         }
78     }
79
80     public void acceptPostOrder(AbstractTCLVisitor visitor) throws VisitorException
81     {
82         left().acceptPostOrder(visitor);
83         if (!isUnaryOperator_)
84         {
85             right().acceptPostOrder(visitor);
86         }
87         visitor.visitPlus(this);
88     }
89
90     public void acceptPreOrder(AbstractTCLVisitor visitor) throws VisitorException
91     {
92         visitor.visitPlus(this);
93         left().acceptPreOrder(visitor);
94         if (!isUnaryOperator_)
95         {
96             right().acceptPreOrder(visitor);
97         }
98     }
99 }
Popular Tags