51de1a41fa061903d93779be48c7847f414f5f02
[phpeclipse.git] / net.sourceforge.phpeclipse / src / net / sourceforge / phpdt / internal / formatter / impl / SplitLine.java
1 /*******************************************************************************
2  * Copyright (c) 2000, 2001, 2002 International Business Machines Corp. and others.
3  * All rights reserved. This program and the accompanying materials 
4  * are made available under the terms of the Common Public License v0.5 
5  * which accompanies this distribution, and is available at
6  * http://www.eclipse.org/legal/cpl-v05.html
7  * 
8  * Contributors:
9  *     IBM Corporation - initial API and implementation
10  ******************************************************************************/
11 package net.sourceforge.phpdt.internal.formatter.impl;
12
13 import net.sourceforge.phpdt.core.compiler.ITerminalSymbols;
14
15 /**
16  * Represents a split line: contains an operator and all substrings
17  */
18 public class SplitLine implements ITerminalSymbols {
19         public int[] operators; // the operator on which the string was split.
20
21         public String[] substrings;
22
23         public int[] startSubstringsIndexes;
24
25         /**
26          * SplitLine constructor comment.
27          */
28 //      public SplitLine(int[] operators, String[] substrings) {
29 //              this(operators, substrings, null);
30 //      }
31
32         /**
33          * SplitLine constructor comment.
34          */
35 //      public SplitLine(int[] operators, String[] substrings, int[] startIndexes) {
36 //              super();
37 //              this.operators = operators;
38 //              this.substrings = substrings;
39 //              this.startSubstringsIndexes = startIndexes;
40 //      }
41
42         /**
43          * Prints a nice representation of the receiver
44          * 
45          * @return java.lang.String
46          */
47         public String toString() {
48                 StringBuffer result = new StringBuffer();
49                 String operatorString = new String();
50
51                 for (int i = 0, max = substrings.length; i < max; i++) {
52                         int currentOperator = operators[i];
53                         String currentString = substrings[i];
54                         boolean placeOperatorAhead = currentOperator != TokenNameCOMMA
55                                         && currentOperator != TokenNameSEMICOLON;
56                         boolean placeOperatorBehind = currentOperator == TokenNameCOMMA
57                                         || currentOperator == TokenNameSEMICOLON;
58
59                         switch (currentOperator) {
60                         case TokenNameextends:
61                                 operatorString = "extends"; //$NON-NLS-1$
62                                 break;
63                         // case TokenNameimplements:
64                         // operatorString="implements"; //$NON-NLS-1$
65                         // break;
66                         // case TokenNamethrows:
67                         // operatorString="throws"; //$NON-NLS-1$
68                         // break;
69                         case TokenNameSEMICOLON: // ;
70                                 operatorString = ";"; //$NON-NLS-1$
71                                 break;
72                         case TokenNameCOMMA: // ,
73                                 operatorString = ","; //$NON-NLS-1$
74                                 break;
75                         case TokenNameEQUAL: // =
76                                 operatorString = "="; //$NON-NLS-1$
77                                 break;
78                         case TokenNameAND_AND: // && (15.22)
79                                 operatorString = "&&"; //$NON-NLS-1$
80                                 break;
81                         case TokenNameOR_OR: // || (15.23)
82                                 operatorString = "||"; //$NON-NLS-1$
83                                 break;
84                         case TokenNameQUESTION: // ? (15.24)
85                                 operatorString = "?"; //$NON-NLS-1$
86                                 break;
87
88                         case TokenNameCOLON: // : (15.24)
89                                 operatorString = ":"; //$NON-NLS-1$
90                                 break;
91                         case TokenNameEQUAL_EQUAL: // == (15.20, 15.20.1, 15.20.2, 15.20.3)
92                                 operatorString = "=="; //$NON-NLS-1$
93                                 break;
94
95                         case TokenNameNOT_EQUAL: // != (15.20, 15.20.1, 15.20.2, 15.20.3)
96                                 operatorString = "!="; //$NON-NLS-1$
97                                 break;
98
99                         case TokenNameLESS: // < (15.19.1)
100                                 operatorString = "<"; //$NON-NLS-1$
101                                 break;
102
103                         case TokenNameLESS_EQUAL: // <= (15.19.1)
104                                 operatorString = "<="; //$NON-NLS-1$
105                                 break;
106
107                         case TokenNameGREATER: // > (15.19.1)
108                                 operatorString = ">"; //$NON-NLS-1$
109                                 break;
110
111                         case TokenNameGREATER_EQUAL: // >= (15.19.1)
112                                 operatorString = ">="; //$NON-NLS-1$
113                                 break;
114
115                         // case TokenNameinstanceof : // instanceof
116                         // operatorString="instanceof"; //$NON-NLS-1$
117                         // break;
118                         case TokenNamePLUS: // + (15.17, 15.17.2)
119                                 operatorString = "+"; //$NON-NLS-1$
120                                 break;
121
122                         case TokenNameMINUS: // - (15.17.2)
123                                 operatorString = "-"; //$NON-NLS-1$
124                                 break;
125                         case TokenNameMULTIPLY: // * (15.16.1)
126                                 operatorString = "*"; //$NON-NLS-1$
127                                 break;
128
129                         case TokenNameDIVIDE: // / (15.16.2)
130                                 operatorString = "/"; //$NON-NLS-1$
131                                 break;
132
133                         case TokenNameREMAINDER: // % (15.16.3)
134                                 operatorString = "%"; //$NON-NLS-1$
135                                 break;
136                         case TokenNameLEFT_SHIFT: // << (15.18)
137                                 operatorString = "<<"; //$NON-NLS-1$
138                                 break;
139
140                         case TokenNameRIGHT_SHIFT: // >> (15.18)
141                                 operatorString = ">>"; //$NON-NLS-1$
142                                 break;
143
144                         // case TokenNameUNSIGNED_RIGHT_SHIFT : // >>> (15.18)
145                         // operatorString=">>>"; //$NON-NLS-1$
146                         // break;
147                         case TokenNameAND: // & (15.21, 15.21.1, 15.21.2)
148                                 operatorString = "&"; //$NON-NLS-1$
149                                 break;
150
151                         case TokenNameOR: // | (15.21, 15.21.1, 15.21.2)
152                                 operatorString = "|"; //$NON-NLS-1$
153                                 break;
154
155                         case TokenNameXOR: // ^ (15.21, 15.21.1, 15.21.2)
156                                 operatorString = "^"; //$NON-NLS-1$
157                                 break;
158                         case TokenNameMULTIPLY_EQUAL: // *= (15.25.2)
159                                 operatorString = "*="; //$NON-NLS-1$
160                                 break;
161
162                         case TokenNameDIVIDE_EQUAL: // /= (15.25.2)
163                                 operatorString = "/="; //$NON-NLS-1$
164                                 break;
165                         case TokenNameREMAINDER_EQUAL: // %= (15.25.2)
166                                 operatorString = "%="; //$NON-NLS-1$
167                                 break;
168
169                         case TokenNamePLUS_EQUAL: // += (15.25.2)
170                                 operatorString = "+="; //$NON-NLS-1$
171                                 break;
172
173                         case TokenNameMINUS_EQUAL: // -= (15.25.2)
174                                 operatorString = "-="; //$NON-NLS-1$
175                                 break;
176
177                         case TokenNameLEFT_SHIFT_EQUAL: // <<= (15.25.2)
178                                 operatorString = "<<="; //$NON-NLS-1$
179                                 break;
180
181                         case TokenNameRIGHT_SHIFT_EQUAL: // >>= (15.25.2)
182                                 operatorString = ">>="; //$NON-NLS-1$
183                                 break;
184
185                         // case TokenNameUNSIGNED_RIGHT_SHIFT_EQUAL : // >>>= (15.25.2)
186                         // operatorString=">>>="; //$NON-NLS-1$
187                         // break;
188
189                         case TokenNameAND_EQUAL: // &= (15.25.2)
190                                 operatorString = "&="; //$NON-NLS-1$
191                                 break;
192
193                         case TokenNameXOR_EQUAL: // ^= (15.25.2)
194                                 operatorString = "^="; //$NON-NLS-1$
195                                 break;
196
197                         case TokenNameOR_EQUAL: // |= (15.25.2)
198                                 operatorString = "|="; //$NON-NLS-1$
199                                 break;
200                         case TokenNameDOT_EQUAL: // .=
201                                 operatorString = ".="; //$NON-NLS-1$
202                                 break;
203                         case TokenNameDOT: // .
204                                 operatorString = "."; //$NON-NLS-1$
205                                 break;
206
207                         default:
208                                 operatorString = ""; //$NON-NLS-1$
209                         }
210                         if (placeOperatorAhead) {
211                                 result.append(operatorString);
212                         }
213                         result.append(currentString);
214                         if (placeOperatorBehind) {
215                                 result.append(operatorString);
216                         }
217                         result.append('\n');
218                 }
219                 return ""; //$NON-NLS-1$
220         }
221 }