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
7  *
8  * Contributors:
9  *     IBM Corporation - initial API and implementation
10  *******************************************************************************/
11 package org.eclipse.jdt.internal.compiler.ast;
12 
13 import org.eclipse.jdt.internal.compiler.ASTVisitor;
14 import org.eclipse.jdt.internal.compiler.lookup.BlockScope;
15 
16 public class ExtendedStringLiteral extends StringLiteral {
17 
18 	/**
19 	 *  Build a string+char literal
20 	 */
ExtendedStringLiteral(StringLiteral str, CharLiteral character)21 	public ExtendedStringLiteral(StringLiteral str, CharLiteral character) {
22 
23 		super(str.source, str.sourceStart, str.sourceEnd);
24 		extendWith(character);
25 	}
26 
27 	/**
28 	 * Build a two-strings literal
29 	 * */
ExtendedStringLiteral(StringLiteral str1, StringLiteral str2)30 	public ExtendedStringLiteral(StringLiteral str1, StringLiteral str2) {
31 
32 		super(str1.source, str1.sourceStart, str1.sourceEnd);
33 		extendWith(str2);
34 	}
35 
36 	/**
37 	 * Add the lit source to mine, just as if it was mine
38 	 */
extendWith(CharLiteral lit)39 	public ExtendedStringLiteral extendWith(CharLiteral lit) {
40 
41 		//update the source
42 		int length = source.length;
43 		System.arraycopy(source, 0, (source = new char[length + 1]), 0, length);
44 		source[length] = lit.value;
45 		//position at the end of all literals
46 		sourceEnd = lit.sourceEnd;
47 		return this;
48 	}
49 
50 	/**
51 	 *  Add the lit source to mine, just as if it was mine
52 	 */
extendWith(StringLiteral lit)53 	public ExtendedStringLiteral extendWith(StringLiteral lit) {
54 
55 		//uddate the source
56 		int length = source.length;
57 		System.arraycopy(
58 			source,
59 			0,
60 			source = new char[length + lit.source.length],
61 			0,
62 			length);
63 		System.arraycopy(lit.source, 0, source, length, lit.source.length);
64 		//position at the end of all literals
65 		sourceEnd = lit.sourceEnd;
66 		return this;
67 	}
68 
printExpression(int indent, StringBuffer output)69 	public StringBuffer printExpression(int indent, StringBuffer output) {
70 
71 		return output.append("ExtendedStringLiteral{").append(source).append('}'); //$NON-NLS-1$
72 	}
73 
traverse(ASTVisitor visitor, BlockScope scope)74 	public void traverse(ASTVisitor visitor, BlockScope scope) {
75 
76 		visitor.visit(this, scope);
77 		visitor.endVisit(this, scope);
78 	}
79 }
80