049c220bbcbb31c0229fbdf0508340d9a0ea3ed3
[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 =
48         currentOperator != TokenNameCOMMA
49           && currentOperator != TokenNameSEMICOLON;
50       boolean placeOperatorBehind =
51         currentOperator == TokenNameCOMMA
52           || currentOperator == TokenNameSEMICOLON;
53
54       switch (currentOperator) {
55         case TokenNameextends :
56           operatorString = "extends"; //$NON-NLS-1$
57           break;
58           //            case TokenNameimplements:
59           //                    operatorString="implements"; //$NON-NLS-1$
60           //                    break;
61           //            case TokenNamethrows:
62           //                    operatorString="throws"; //$NON-NLS-1$
63           //                    break;
64         case TokenNameSEMICOLON : // ;
65           operatorString = ";"; //$NON-NLS-1$
66           break;
67         case TokenNameCOMMA : // ,
68           operatorString = ","; //$NON-NLS-1$
69           break;
70         case TokenNameEQUAL : // =
71           operatorString = "="; //$NON-NLS-1$
72           break;
73         case TokenNameAND_AND : // && (15.22)
74           operatorString = "&&"; //$NON-NLS-1$
75           break;
76         case TokenNameOR_OR : // || (15.23)
77           operatorString = "||"; //$NON-NLS-1$
78           break;
79         case TokenNameQUESTION : // ? (15.24)
80           operatorString = "?"; //$NON-NLS-1$
81           break;
82
83         case TokenNameCOLON : // : (15.24)
84           operatorString = ":"; //$NON-NLS-1$
85           break;
86         case TokenNameEQUAL_EQUAL : // == (15.20, 15.20.1, 15.20.2, 15.20.3)
87           operatorString = "=="; //$NON-NLS-1$
88           break;
89
90         case TokenNameNOT_EQUAL : // != (15.20, 15.20.1, 15.20.2, 15.20.3)
91           operatorString = "!="; //$NON-NLS-1$
92           break;
93
94         case TokenNameLESS : // < (15.19.1)
95           operatorString = "<"; //$NON-NLS-1$
96           break;
97
98         case TokenNameLESS_EQUAL : // <= (15.19.1)
99           operatorString = "<="; //$NON-NLS-1$
100           break;
101
102         case TokenNameGREATER : // > (15.19.1)
103           operatorString = ">"; //$NON-NLS-1$
104           break;
105
106         case TokenNameGREATER_EQUAL : // >= (15.19.1)
107           operatorString = ">="; //$NON-NLS-1$
108           break;
109
110           //            case TokenNameinstanceof : // instanceof
111           //                    operatorString="instanceof"; //$NON-NLS-1$
112           //                    break;
113         case TokenNamePLUS : // + (15.17, 15.17.2)
114           operatorString = "+"; //$NON-NLS-1$
115           break;
116
117         case TokenNameMINUS : // - (15.17.2)
118           operatorString = "-"; //$NON-NLS-1$
119           break;
120         case TokenNameMULTIPLY : // * (15.16.1)
121           operatorString = "*"; //$NON-NLS-1$
122           break;
123
124         case TokenNameDIVIDE : // / (15.16.2)
125           operatorString = "/"; //$NON-NLS-1$
126           break;
127
128         case TokenNameREMAINDER : // % (15.16.3)
129           operatorString = "%"; //$NON-NLS-1$
130           break;
131         case TokenNameLEFT_SHIFT : // << (15.18)
132           operatorString = "<<"; //$NON-NLS-1$
133           break;
134
135         case TokenNameRIGHT_SHIFT : // >> (15.18)
136           operatorString = ">>"; //$NON-NLS-1$
137           break;
138
139           //            case TokenNameUNSIGNED_RIGHT_SHIFT : // >>> (15.18)
140           //                    operatorString=">>>"; //$NON-NLS-1$
141           //                    break;
142         case TokenNameAND : // & (15.21, 15.21.1, 15.21.2)
143           operatorString = "&"; //$NON-NLS-1$
144           break;
145
146         case TokenNameOR : // | (15.21, 15.21.1, 15.21.2)
147           operatorString = "|"; //$NON-NLS-1$
148           break;
149
150         case TokenNameXOR : // ^ (15.21, 15.21.1, 15.21.2)
151           operatorString = "^"; //$NON-NLS-1$
152           break;
153         case TokenNameMULTIPLY_EQUAL : // *= (15.25.2)
154           operatorString = "*="; //$NON-NLS-1$
155           break;
156
157         case TokenNameDIVIDE_EQUAL : // /= (15.25.2)
158           operatorString = "/="; //$NON-NLS-1$
159           break;
160         case TokenNameREMAINDER_EQUAL : // %= (15.25.2)
161           operatorString = "%="; //$NON-NLS-1$
162           break;
163
164         case TokenNamePLUS_EQUAL : // += (15.25.2)
165           operatorString = "+="; //$NON-NLS-1$
166           break;
167
168         case TokenNameMINUS_EQUAL : // -= (15.25.2)
169           operatorString = "-="; //$NON-NLS-1$
170           break;
171
172         case TokenNameLEFT_SHIFT_EQUAL : // <<= (15.25.2)
173           operatorString = "<<="; //$NON-NLS-1$
174           break;
175
176         case TokenNameRIGHT_SHIFT_EQUAL : // >>= (15.25.2)
177           operatorString = ">>="; //$NON-NLS-1$
178           break;
179
180           //            case TokenNameUNSIGNED_RIGHT_SHIFT_EQUAL : // >>>= (15.25.2)
181           //                    operatorString=">>>="; //$NON-NLS-1$
182           //                    break;
183
184         case TokenNameAND_EQUAL : // &= (15.25.2)
185           operatorString = "&="; //$NON-NLS-1$
186           break;
187
188         case TokenNameXOR_EQUAL : // ^= (15.25.2)
189           operatorString = "^="; //$NON-NLS-1$
190           break;
191
192         case TokenNameOR_EQUAL : // |= (15.25.2)
193           operatorString = "|="; //$NON-NLS-1$
194           break;
195         case TokenNameDOT : // .
196           operatorString = "."; //$NON-NLS-1$
197           break;
198
199         default :
200           operatorString = ""; //$NON-NLS-1$
201       }
202       if (placeOperatorAhead) {
203         result.append(operatorString);
204       }
205       result.append(currentString);
206       if (placeOperatorBehind) {
207         result.append(operatorString);
208       }
209       result.append('\n');
210     }
211     return ""; //$NON-NLS-1$
212   }
213 }