/******************************************************************************* * Copyright (c) 2000, 2001, 2002 International Business Machines Corp. and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Common Public License v0.5 * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/cpl-v05.html * * Contributors: * IBM Corporation - initial API and implementation ******************************************************************************/ package net.sourceforge.phpdt.internal.formatter.impl; import net.sourceforge.phpdt.core.compiler.ITerminalSymbols; /** * Represents a split line: contains an operator and all substrings */ public class SplitLine implements ITerminalSymbols { public TokenName[] operators; // the operator on which the string was split. public String[] substrings; public int[] startSubstringsIndexes; /** * SplitLine constructor comment. */ // public SplitLine(int[] operators, String[] substrings) { // this(operators, substrings, null); // } /** * SplitLine constructor comment. */ // public SplitLine(int[] operators, String[] substrings, int[] startIndexes) { // super(); // this.operators = operators; // this.substrings = substrings; // this.startSubstringsIndexes = startIndexes; // } /** * Prints a nice representation of the receiver * * @return java.lang.String */ public String toString() { StringBuffer result = new StringBuffer(); String operatorString = new String(); for (int i = 0, max = substrings.length; i < max; i++) { TokenName currentOperator = operators[i]; String currentString = substrings[i]; boolean placeOperatorAhead = currentOperator != TokenName.COMMA && currentOperator != TokenName.SEMICOLON; boolean placeOperatorBehind = currentOperator == TokenName.COMMA || currentOperator == TokenName.SEMICOLON; switch (currentOperator) { case EXTENDS: operatorString = "extends"; //$NON-NLS-1$ break; // case implements: // operatorString="implements"; //$NON-NLS-1$ // break; // case throws: // operatorString="throws"; //$NON-NLS-1$ // break; case SEMICOLON: // ; operatorString = ";"; //$NON-NLS-1$ break; case COMMA: // , operatorString = ","; //$NON-NLS-1$ break; case EQUAL: // = operatorString = "="; //$NON-NLS-1$ break; case AND_AND: // && (15.22) operatorString = "&&"; //$NON-NLS-1$ break; case OR_OR: // || (15.23) operatorString = "||"; //$NON-NLS-1$ break; case QUESTION: // ? (15.24) operatorString = "?"; //$NON-NLS-1$ break; case COLON: // : (15.24) operatorString = ":"; //$NON-NLS-1$ break; case EQUAL_EQUAL: // == (15.20, 15.20.1, 15.20.2, 15.20.3) operatorString = "=="; //$NON-NLS-1$ break; case NOT_EQUAL: // != (15.20, 15.20.1, 15.20.2, 15.20.3) operatorString = "!="; //$NON-NLS-1$ break; case LESS: // < (15.19.1) operatorString = "<"; //$NON-NLS-1$ break; case LESS_EQUAL: // <= (15.19.1) operatorString = "<="; //$NON-NLS-1$ break; case GREATER: // > (15.19.1) operatorString = ">"; //$NON-NLS-1$ break; case GREATER_EQUAL: // >= (15.19.1) operatorString = ">="; //$NON-NLS-1$ break; // case instanceof : // instanceof // operatorString="instanceof"; //$NON-NLS-1$ // break; case PLUS: // + (15.17, 15.17.2) operatorString = "+"; //$NON-NLS-1$ break; case MINUS: // - (15.17.2) operatorString = "-"; //$NON-NLS-1$ break; case MULTIPLY: // * (15.16.1) operatorString = "*"; //$NON-NLS-1$ break; case DIVIDE: // / (15.16.2) operatorString = "/"; //$NON-NLS-1$ break; case REMAINDER: // % (15.16.3) operatorString = "%"; //$NON-NLS-1$ break; case LEFT_SHIFT: // << (15.18) operatorString = "<<"; //$NON-NLS-1$ break; case RIGHT_SHIFT: // >> (15.18) operatorString = ">>"; //$NON-NLS-1$ break; // case UNSIGNED_RIGHT_SHIFT : // >>> (15.18) // operatorString=">>>"; //$NON-NLS-1$ // break; case OP_AND: // & (15.21, 15.21.1, 15.21.2) operatorString = "&"; //$NON-NLS-1$ break; case OP_OR: // | (15.21, 15.21.1, 15.21.2) operatorString = "|"; //$NON-NLS-1$ break; case OP_XOR: // ^ (15.21, 15.21.1, 15.21.2) operatorString = "^"; //$NON-NLS-1$ break; case MULTIPLY_EQUAL: // *= (15.25.2) operatorString = "*="; //$NON-NLS-1$ break; case DIVIDE_EQUAL: // /= (15.25.2) operatorString = "/="; //$NON-NLS-1$ break; case REMAINDER_EQUAL: // %= (15.25.2) operatorString = "%="; //$NON-NLS-1$ break; case PLUS_EQUAL: // += (15.25.2) operatorString = "+="; //$NON-NLS-1$ break; case MINUS_EQUAL: // -= (15.25.2) operatorString = "-="; //$NON-NLS-1$ break; case LEFT_SHIFT_EQUAL: // <<= (15.25.2) operatorString = "<<="; //$NON-NLS-1$ break; case RIGHT_SHIFT_EQUAL: // >>= (15.25.2) operatorString = ">>="; //$NON-NLS-1$ break; // case UNSIGNED_RIGHT_SHIFT_EQUAL : // >>>= (15.25.2) // operatorString=">>>="; //$NON-NLS-1$ // break; case AND_EQUAL: // &= (15.25.2) operatorString = "&="; //$NON-NLS-1$ break; case XOR_EQUAL: // ^= (15.25.2) operatorString = "^="; //$NON-NLS-1$ break; case OR_EQUAL: // |= (15.25.2) operatorString = "|="; //$NON-NLS-1$ break; case DOT_EQUAL: // .= operatorString = ".="; //$NON-NLS-1$ break; case DOT: // . operatorString = "."; //$NON-NLS-1$ break; default: operatorString = ""; //$NON-NLS-1$ } if (placeOperatorAhead) { result.append(operatorString); } result.append(currentString); if (placeOperatorBehind) { result.append(operatorString); } result.append('\n'); } return ""; //$NON-NLS-1$ } }