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;
15 /** Represents a split line: contains an operator and all substrings
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;
22 * SplitLine constructor comment.
24 public SplitLine(int[] operators, String[] substrings) {
25 this(operators, substrings, null);
28 * SplitLine constructor comment.
30 public SplitLine(int[] operators, String[] substrings, int[] startIndexes) {
32 this.operators=operators;
33 this.substrings=substrings;
34 this.startSubstringsIndexes = startIndexes;
37 * Prints a nice representation of the receiver
38 * @return java.lang.String
40 public String toString() {
41 StringBuffer result=new StringBuffer();
42 String operatorString = new String();
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;
52 switch (currentOperator){
53 case TokenNameextends:
54 operatorString="extends"; //$NON-NLS-1$
56 // case TokenNameimplements:
57 // operatorString="implements"; //$NON-NLS-1$
59 // case TokenNamethrows:
60 // operatorString="throws"; //$NON-NLS-1$
62 case TokenNameSEMICOLON : // ;
63 operatorString=";"; //$NON-NLS-1$
65 case TokenNameCOMMA : // ,
66 operatorString=","; //$NON-NLS-1$
68 case TokenNameEQUAL : // =
69 operatorString="="; //$NON-NLS-1$
71 case TokenNameAND_AND : // && (15.22)
72 operatorString="&&"; //$NON-NLS-1$
74 case TokenNameOR_OR : // || (15.23)
75 operatorString="||"; //$NON-NLS-1$
77 case TokenNameQUESTION : // ? (15.24)
78 operatorString="?"; //$NON-NLS-1$
81 case TokenNameCOLON : // : (15.24)
82 operatorString=":"; //$NON-NLS-1$
84 case TokenNameEQUAL_EQUAL : // == (15.20, 15.20.1, 15.20.2, 15.20.3)
85 operatorString="=="; //$NON-NLS-1$
88 case TokenNameNOT_EQUAL : // != (15.20, 15.20.1, 15.20.2, 15.20.3)
89 operatorString="!="; //$NON-NLS-1$
92 case TokenNameLESS : // < (15.19.1)
93 operatorString="<"; //$NON-NLS-1$
96 case TokenNameLESS_EQUAL : // <= (15.19.1)
97 operatorString="<="; //$NON-NLS-1$
100 case TokenNameGREATER : // > (15.19.1)
101 operatorString=">"; //$NON-NLS-1$
104 case TokenNameGREATER_EQUAL : // >= (15.19.1)
105 operatorString=">="; //$NON-NLS-1$
108 // case TokenNameinstanceof : // instanceof
109 // operatorString="instanceof"; //$NON-NLS-1$
111 case TokenNamePLUS : // + (15.17, 15.17.2)
112 operatorString="+"; //$NON-NLS-1$
115 case TokenNameMINUS : // - (15.17.2)
116 operatorString="-"; //$NON-NLS-1$
118 case TokenNameMULTIPLY : // * (15.16.1)
119 operatorString="*"; //$NON-NLS-1$
122 case TokenNameDIVIDE : // / (15.16.2)
123 operatorString="/"; //$NON-NLS-1$
126 case TokenNameREMAINDER : // % (15.16.3)
127 operatorString="%"; //$NON-NLS-1$
129 case TokenNameLEFT_SHIFT : // << (15.18)
130 operatorString="<<"; //$NON-NLS-1$
133 case TokenNameRIGHT_SHIFT : // >> (15.18)
134 operatorString=">>"; //$NON-NLS-1$
137 // case TokenNameUNSIGNED_RIGHT_SHIFT : // >>> (15.18)
138 // operatorString=">>>"; //$NON-NLS-1$
140 case TokenNameAND : // & (15.21, 15.21.1, 15.21.2)
141 operatorString="&"; //$NON-NLS-1$
144 case TokenNameOR : // | (15.21, 15.21.1, 15.21.2)
145 operatorString="|"; //$NON-NLS-1$
148 case TokenNameXOR : // ^ (15.21, 15.21.1, 15.21.2)
149 operatorString="^"; //$NON-NLS-1$
151 case TokenNameMULTIPLY_EQUAL : // *= (15.25.2)
152 operatorString="*="; //$NON-NLS-1$
155 case TokenNameDIVIDE_EQUAL : // /= (15.25.2)
156 operatorString="/="; //$NON-NLS-1$
158 case TokenNameREMAINDER_EQUAL : // %= (15.25.2)
159 operatorString="%="; //$NON-NLS-1$
162 case TokenNamePLUS_EQUAL : // += (15.25.2)
163 operatorString="+="; //$NON-NLS-1$
166 case TokenNameMINUS_EQUAL : // -= (15.25.2)
167 operatorString="-="; //$NON-NLS-1$
170 case TokenNameLEFT_SHIFT_EQUAL : // <<= (15.25.2)
171 operatorString="<<="; //$NON-NLS-1$
174 case TokenNameRIGHT_SHIFT_EQUAL : // >>= (15.25.2)
175 operatorString=">>="; //$NON-NLS-1$
178 // case TokenNameUNSIGNED_RIGHT_SHIFT_EQUAL : // >>>= (15.25.2)
179 // operatorString=">>>="; //$NON-NLS-1$
182 case TokenNameAND_EQUAL : // &= (15.25.2)
183 operatorString="&="; //$NON-NLS-1$
186 case TokenNameXOR_EQUAL : // ^= (15.25.2)
187 operatorString="^="; //$NON-NLS-1$
190 case TokenNameOR_EQUAL : // |= (15.25.2)
191 operatorString="|="; //$NON-NLS-1$
193 case TokenNameDOT : // .
194 operatorString="."; //$NON-NLS-1$
198 operatorString=""; //$NON-NLS-1$
200 if (placeOperatorAhead){
201 result.append(operatorString);
203 result.append(currentString);
204 if (placeOperatorBehind){
205 result.append(operatorString);
209 return ""; //$NON-NLS-1$