1 /*******************************************************************************
2 * Copyright (c) 2000, 2004 IBM Corporation and others.
3 * All rights reserved. This program and the accompanying materials
4 * are made available under the terms of the Common Public License v1.0
5 * which accompanies this distribution, and is available at
6 * http://www.eclipse.org/legal/cpl-v10.html
9 * IBM Corporation - initial API and implementation
10 *******************************************************************************/
11 package org.eclipse.jdt.internal.compiler.ast;
13 import org.eclipse.jdt.internal.compiler.ASTVisitor;
14 import org.eclipse.jdt.internal.compiler.lookup.BlockScope;
17 * Flatten string literal
19 public class StringLiteralConcatenation extends StringLiteral {
20 private static final int INITIAL_SIZE = 5;
21 public StringLiteral[] literals;
24 * Build a two-strings literal
26 public StringLiteralConcatenation(StringLiteral str1, StringLiteral str2) {
27 super(str1.sourceStart, str1.sourceEnd);
28 this.source = str1.source;
29 this.literals = new StringLiteral[INITIAL_SIZE];
31 this.literals[this.counter++] = str1;
36 * Add the lit source to mine, just as if it was mine
38 public StringLiteralConcatenation extendsWith(StringLiteral lit) {
39 this.sourceEnd = lit.sourceEnd;
40 final int literalsLength = this.literals.length;
41 if (this.counter == literalsLength) {
43 System.arraycopy(this.literals, 0, this.literals = new StringLiteral[literalsLength + INITIAL_SIZE], 0, literalsLength);
46 int length = source.length;
50 source = new char[length + lit.source.length],
53 System.arraycopy(lit.source, 0, source, length, lit.source.length);
54 this.literals[this.counter++] = lit;
58 public StringBuffer printExpression(int indent, StringBuffer output) {
59 output.append("StringLiteralConcatenation{"); //$NON-NLS-1$
60 for (int i = 0, max = this.counter; i < max; i++) {
61 this.literals[i].printExpression(indent, output);
62 output.append("+\n");//$NON-NLS-1$
64 return output.append('}');
67 public char[] source() {
71 public void traverse(ASTVisitor visitor, BlockScope scope) {
72 if (visitor.visit(this, scope)) {
73 for (int i = 0, max = this.counter; i < max; i++) {
74 this.literals[i].traverse(visitor, scope);
77 visitor.endVisit(this, scope);