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
9 * IBM Corporation - initial API and implementation
10 ******************************************************************************/
11 package net.sourceforge.phpdt.internal.formatter.impl;
13 import net.sourceforge.phpdt.core.compiler.ITerminalSymbols;
16 * Represents a split line: contains an operator and all substrings
18 public class SplitLine implements ITerminalSymbols {
19 public int[] operators; // the operator on which the string was split.
21 public String[] substrings;
23 public int[] startSubstringsIndexes;
26 * SplitLine constructor comment.
28 // public SplitLine(int[] operators, String[] substrings) {
29 // this(operators, substrings, null);
33 * SplitLine constructor comment.
35 // public SplitLine(int[] operators, String[] substrings, int[] startIndexes) {
37 // this.operators = operators;
38 // this.substrings = substrings;
39 // this.startSubstringsIndexes = startIndexes;
43 * Prints a nice representation of the receiver
45 * @return java.lang.String
47 public String toString() {
48 StringBuffer result = new StringBuffer();
49 String operatorString = new String();
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;
59 switch (currentOperator) {
60 case TokenNameextends:
61 operatorString = "extends"; //$NON-NLS-1$
63 // case TokenNameimplements:
64 // operatorString="implements"; //$NON-NLS-1$
66 // case TokenNamethrows:
67 // operatorString="throws"; //$NON-NLS-1$
69 case TokenNameSEMICOLON: // ;
70 operatorString = ";"; //$NON-NLS-1$
72 case TokenNameCOMMA: // ,
73 operatorString = ","; //$NON-NLS-1$
75 case TokenNameEQUAL: // =
76 operatorString = "="; //$NON-NLS-1$
78 case TokenNameAND_AND: // && (15.22)
79 operatorString = "&&"; //$NON-NLS-1$
81 case TokenNameOR_OR: // || (15.23)
82 operatorString = "||"; //$NON-NLS-1$
84 case TokenNameQUESTION: // ? (15.24)
85 operatorString = "?"; //$NON-NLS-1$
88 case TokenNameCOLON: // : (15.24)
89 operatorString = ":"; //$NON-NLS-1$
91 case TokenNameEQUAL_EQUAL: // == (15.20, 15.20.1, 15.20.2, 15.20.3)
92 operatorString = "=="; //$NON-NLS-1$
95 case TokenNameNOT_EQUAL: // != (15.20, 15.20.1, 15.20.2, 15.20.3)
96 operatorString = "!="; //$NON-NLS-1$
99 case TokenNameLESS: // < (15.19.1)
100 operatorString = "<"; //$NON-NLS-1$
103 case TokenNameLESS_EQUAL: // <= (15.19.1)
104 operatorString = "<="; //$NON-NLS-1$
107 case TokenNameGREATER: // > (15.19.1)
108 operatorString = ">"; //$NON-NLS-1$
111 case TokenNameGREATER_EQUAL: // >= (15.19.1)
112 operatorString = ">="; //$NON-NLS-1$
115 // case TokenNameinstanceof : // instanceof
116 // operatorString="instanceof"; //$NON-NLS-1$
118 case TokenNamePLUS: // + (15.17, 15.17.2)
119 operatorString = "+"; //$NON-NLS-1$
122 case TokenNameMINUS: // - (15.17.2)
123 operatorString = "-"; //$NON-NLS-1$
125 case TokenNameMULTIPLY: // * (15.16.1)
126 operatorString = "*"; //$NON-NLS-1$
129 case TokenNameDIVIDE: // / (15.16.2)
130 operatorString = "/"; //$NON-NLS-1$
133 case TokenNameREMAINDER: // % (15.16.3)
134 operatorString = "%"; //$NON-NLS-1$
136 case TokenNameLEFT_SHIFT: // << (15.18)
137 operatorString = "<<"; //$NON-NLS-1$
140 case TokenNameRIGHT_SHIFT: // >> (15.18)
141 operatorString = ">>"; //$NON-NLS-1$
144 // case TokenNameUNSIGNED_RIGHT_SHIFT : // >>> (15.18)
145 // operatorString=">>>"; //$NON-NLS-1$
147 case TokenNameAND: // & (15.21, 15.21.1, 15.21.2)
148 operatorString = "&"; //$NON-NLS-1$
151 case TokenNameOR: // | (15.21, 15.21.1, 15.21.2)
152 operatorString = "|"; //$NON-NLS-1$
155 case TokenNameXOR: // ^ (15.21, 15.21.1, 15.21.2)
156 operatorString = "^"; //$NON-NLS-1$
158 case TokenNameMULTIPLY_EQUAL: // *= (15.25.2)
159 operatorString = "*="; //$NON-NLS-1$
162 case TokenNameDIVIDE_EQUAL: // /= (15.25.2)
163 operatorString = "/="; //$NON-NLS-1$
165 case TokenNameREMAINDER_EQUAL: // %= (15.25.2)
166 operatorString = "%="; //$NON-NLS-1$
169 case TokenNamePLUS_EQUAL: // += (15.25.2)
170 operatorString = "+="; //$NON-NLS-1$
173 case TokenNameMINUS_EQUAL: // -= (15.25.2)
174 operatorString = "-="; //$NON-NLS-1$
177 case TokenNameLEFT_SHIFT_EQUAL: // <<= (15.25.2)
178 operatorString = "<<="; //$NON-NLS-1$
181 case TokenNameRIGHT_SHIFT_EQUAL: // >>= (15.25.2)
182 operatorString = ">>="; //$NON-NLS-1$
185 // case TokenNameUNSIGNED_RIGHT_SHIFT_EQUAL : // >>>= (15.25.2)
186 // operatorString=">>>="; //$NON-NLS-1$
189 case TokenNameAND_EQUAL: // &= (15.25.2)
190 operatorString = "&="; //$NON-NLS-1$
193 case TokenNameXOR_EQUAL: // ^= (15.25.2)
194 operatorString = "^="; //$NON-NLS-1$
197 case TokenNameOR_EQUAL: // |= (15.25.2)
198 operatorString = "|="; //$NON-NLS-1$
200 case TokenNameDOT_EQUAL: // .=
201 operatorString = ".="; //$NON-NLS-1$
203 case TokenNameDOT: // .
204 operatorString = "."; //$NON-NLS-1$
208 operatorString = ""; //$NON-NLS-1$
210 if (placeOperatorAhead) {
211 result.append(operatorString);
213 result.append(currentString);
214 if (placeOperatorBehind) {
215 result.append(operatorString);
219 return ""; //$NON-NLS-1$