01: /*******************************************************************************
02: * Copyright (c) 2000, 2006 IBM Corporation and others.
03: * All rights reserved. This program and the accompanying materials
04: * are made available under the terms of the Eclipse Public License v1.0
05: * which accompanies this distribution, and is available at
06: * http://www.eclipse.org/legal/epl-v10.html
07: *
08: * Contributors:
09: * IBM Corporation - initial API and implementation
10: *******************************************************************************/package org.eclipse.jdt.internal.compiler.ast;
11:
12: import org.eclipse.jdt.internal.compiler.ASTVisitor;
13: import org.eclipse.jdt.internal.compiler.lookup.BlockScope;
14:
15: public class ExtendedStringLiteral extends StringLiteral {
16:
17: /**
18: * Build a string+char literal
19: */
20: public ExtendedStringLiteral(StringLiteral str,
21: CharLiteral character) {
22:
23: super (str.source, str.sourceStart, str.sourceEnd,
24: str.lineNumber);
25: extendWith(character);
26: }
27:
28: /**
29: * Build a two-strings literal
30: * */
31: public ExtendedStringLiteral(StringLiteral str1, StringLiteral str2) {
32:
33: super (str1.source, str1.sourceStart, str1.sourceEnd,
34: str1.lineNumber);
35: extendWith(str2);
36: }
37:
38: /**
39: * Add the lit source to mine, just as if it was mine
40: */
41: public ExtendedStringLiteral extendWith(CharLiteral lit) {
42:
43: //update the source
44: int length = source.length;
45: System.arraycopy(source, 0, (source = new char[length + 1]), 0,
46: length);
47: source[length] = lit.value;
48: //position at the end of all literals
49: sourceEnd = lit.sourceEnd;
50: return this ;
51: }
52:
53: /**
54: * Add the lit source to mine, just as if it was mine
55: */
56: public ExtendedStringLiteral extendWith(StringLiteral lit) {
57:
58: //uddate the source
59: int length = source.length;
60: System.arraycopy(source, 0, source = new char[length
61: + lit.source.length], 0, length);
62: System.arraycopy(lit.source, 0, source, length,
63: lit.source.length);
64: //position at the end of all literals
65: sourceEnd = lit.sourceEnd;
66: return this ;
67: }
68:
69: public StringBuffer printExpression(int indent, StringBuffer output) {
70:
71: return output
72: .append("ExtendedStringLiteral{").append(source).append('}'); //$NON-NLS-1$
73: }
74:
75: public void traverse(ASTVisitor visitor, BlockScope scope) {
76:
77: visitor.visit(this, scope);
78: visitor.endVisit(this, scope);
79: }
80: }
|