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