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 =
48 currentOperator != TokenNameCOMMA
49 && currentOperator != TokenNameSEMICOLON;
50 boolean placeOperatorBehind =
51 currentOperator == TokenNameCOMMA
52 || currentOperator == TokenNameSEMICOLON;
54 switch (currentOperator) {
55 case TokenNameextends :
56 operatorString = "extends"; //$NON-NLS-1$
58 // case TokenNameimplements:
59 // operatorString="implements"; //$NON-NLS-1$
61 // case TokenNamethrows:
62 // operatorString="throws"; //$NON-NLS-1$
64 case TokenNameSEMICOLON : // ;
65 operatorString = ";"; //$NON-NLS-1$
67 case TokenNameCOMMA : // ,
68 operatorString = ","; //$NON-NLS-1$
70 case TokenNameEQUAL : // =
71 operatorString = "="; //$NON-NLS-1$
73 case TokenNameAND_AND : // && (15.22)
74 operatorString = "&&"; //$NON-NLS-1$
76 case TokenNameOR_OR : // || (15.23)
77 operatorString = "||"; //$NON-NLS-1$
79 case TokenNameQUESTION : // ? (15.24)
80 operatorString = "?"; //$NON-NLS-1$
83 case TokenNameCOLON : // : (15.24)
84 operatorString = ":"; //$NON-NLS-1$
86 case TokenNameEQUAL_EQUAL : // == (15.20, 15.20.1, 15.20.2, 15.20.3)
87 operatorString = "=="; //$NON-NLS-1$
90 case TokenNameNOT_EQUAL : // != (15.20, 15.20.1, 15.20.2, 15.20.3)
91 operatorString = "!="; //$NON-NLS-1$
94 case TokenNameLESS : // < (15.19.1)
95 operatorString = "<"; //$NON-NLS-1$
98 case TokenNameLESS_EQUAL : // <= (15.19.1)
99 operatorString = "<="; //$NON-NLS-1$
102 case TokenNameGREATER : // > (15.19.1)
103 operatorString = ">"; //$NON-NLS-1$
106 case TokenNameGREATER_EQUAL : // >= (15.19.1)
107 operatorString = ">="; //$NON-NLS-1$
110 // case TokenNameinstanceof : // instanceof
111 // operatorString="instanceof"; //$NON-NLS-1$
113 case TokenNamePLUS : // + (15.17, 15.17.2)
114 operatorString = "+"; //$NON-NLS-1$
117 case TokenNameMINUS : // - (15.17.2)
118 operatorString = "-"; //$NON-NLS-1$
120 case TokenNameMULTIPLY : // * (15.16.1)
121 operatorString = "*"; //$NON-NLS-1$
124 case TokenNameDIVIDE : // / (15.16.2)
125 operatorString = "/"; //$NON-NLS-1$
128 case TokenNameREMAINDER : // % (15.16.3)
129 operatorString = "%"; //$NON-NLS-1$
131 case TokenNameLEFT_SHIFT : // << (15.18)
132 operatorString = "<<"; //$NON-NLS-1$
135 case TokenNameRIGHT_SHIFT : // >> (15.18)
136 operatorString = ">>"; //$NON-NLS-1$
139 // case TokenNameUNSIGNED_RIGHT_SHIFT : // >>> (15.18)
140 // operatorString=">>>"; //$NON-NLS-1$
142 case TokenNameAND : // & (15.21, 15.21.1, 15.21.2)
143 operatorString = "&"; //$NON-NLS-1$
146 case TokenNameOR : // | (15.21, 15.21.1, 15.21.2)
147 operatorString = "|"; //$NON-NLS-1$
150 case TokenNameXOR : // ^ (15.21, 15.21.1, 15.21.2)
151 operatorString = "^"; //$NON-NLS-1$
153 case TokenNameMULTIPLY_EQUAL : // *= (15.25.2)
154 operatorString = "*="; //$NON-NLS-1$
157 case TokenNameDIVIDE_EQUAL : // /= (15.25.2)
158 operatorString = "/="; //$NON-NLS-1$
160 case TokenNameREMAINDER_EQUAL : // %= (15.25.2)
161 operatorString = "%="; //$NON-NLS-1$
164 case TokenNamePLUS_EQUAL : // += (15.25.2)
165 operatorString = "+="; //$NON-NLS-1$
168 case TokenNameMINUS_EQUAL : // -= (15.25.2)
169 operatorString = "-="; //$NON-NLS-1$
172 case TokenNameLEFT_SHIFT_EQUAL : // <<= (15.25.2)
173 operatorString = "<<="; //$NON-NLS-1$
176 case TokenNameRIGHT_SHIFT_EQUAL : // >>= (15.25.2)
177 operatorString = ">>="; //$NON-NLS-1$
180 // case TokenNameUNSIGNED_RIGHT_SHIFT_EQUAL : // >>>= (15.25.2)
181 // operatorString=">>>="; //$NON-NLS-1$
184 case TokenNameAND_EQUAL : // &= (15.25.2)
185 operatorString = "&="; //$NON-NLS-1$
188 case TokenNameXOR_EQUAL : // ^= (15.25.2)
189 operatorString = "^="; //$NON-NLS-1$
192 case TokenNameOR_EQUAL : // |= (15.25.2)
193 operatorString = "|="; //$NON-NLS-1$
195 case TokenNameDOT : // .
196 operatorString = "."; //$NON-NLS-1$
200 operatorString = ""; //$NON-NLS-1$
202 if (placeOperatorAhead) {
203 result.append(operatorString);
205 result.append(currentString);
206 if (placeOperatorBehind) {
207 result.append(operatorString);
211 return ""; //$NON-NLS-1$