5112a4f9045734a1b94488953c3bebd16cf300c0
[phpeclipse.git] / net.sourceforge.phpeclipse / src / net / sourceforge / phpdt / internal / compiler / ast / OperatorExpression.java
1 package net.sourceforge.phpdt.internal.compiler.ast;
2
3 /**
4  * Any expression that have an operator.
5  * @author Matthieu Casanova
6  */
7 public abstract class OperatorExpression
8     extends Expression
9     implements OperatorIds {
10
11   public int operator;
12
13   public OperatorExpression(int operator, int sourceStart, int sourceEnd) {
14     super(sourceStart, sourceEnd);
15     this.operator = operator;
16   }
17
18         public String operatorToString() {
19                 switch (operator) {
20                         case EQUAL_EQUAL :
21                                 return "=="; //$NON-NLS-1$
22                         case LESS_EQUAL :
23                                 return "<="; //$NON-NLS-1$
24                         case GREATER_EQUAL :
25                                 return ">="; //$NON-NLS-1$
26                         case NOT_EQUAL :
27                                 return "!="; //$NON-NLS-1$
28                         case LEFT_SHIFT :
29                                 return "<<"; //$NON-NLS-1$
30                         case RIGHT_SHIFT :
31                                 return ">>"; //$NON-NLS-1$
32                         case UNSIGNED_RIGHT_SHIFT :
33                                 return ">>>"; //$NON-NLS-1$
34                         case OR_OR :
35                                 return "||"; //$NON-NLS-1$
36                         case AND_AND :
37                                 return "&&"; //$NON-NLS-1$
38                         case PLUS :
39                                 return "+"; //$NON-NLS-1$
40                         case MINUS :
41                                 return "-"; //$NON-NLS-1$
42                         case NOT :
43                                 return "!"; //$NON-NLS-1$
44                         case REMAINDER :
45                                 return "%"; //$NON-NLS-1$
46                         case XOR :
47                                 return "^"; //$NON-NLS-1$
48                         case AND :
49                                 return "&"; //$NON-NLS-1$
50                         case MULTIPLY :
51                                 return "*"; //$NON-NLS-1$
52                         case OR :
53                                 return "|"; //$NON-NLS-1$
54                         case TWIDDLE :
55                                 return "~"; //$NON-NLS-1$
56                         case DIVIDE :
57                                 return "/"; //$NON-NLS-1$
58                         case GREATER :
59                                 return ">"; //$NON-NLS-1$
60                         case LESS :
61                                 return "<"; //$NON-NLS-1$
62                         case ORL :
63                                 return "OR"; //$NON-NLS-1$
64       case ANDL :
65         return "AND"; //$NON-NLS-1$
66       case DOT :
67         return "."; //$NON-NLS-1$
68       case DIF :
69         return "<>"; //$NON-NLS-1$
70       case BANG_EQUAL_EQUAL :
71         return "!=="; //$NON-NLS-1$
72       case EQUAL_EQUAL_EQUAL :
73         return "==="; //$NON-NLS-1$
74       case AT :
75         return "@"; //$NON-NLS-1$
76                 };
77                 return "unknown operator"; //$NON-NLS-1$
78         }
79
80   public String toStringExpression(){
81                 //subclass redefine toStringExpressionNoParenthesis()
82                 return  "(" + toStringExpressionNoParenthesis() + ")";  //$NON-NLS-2$ //$NON-NLS-1$
83         }
84
85         public abstract String toStringExpressionNoParenthesis();
86 }