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.codegen.CodeStream;
15 import org.eclipse.jdt.internal.compiler.impl.Constant;
16 import org.eclipse.jdt.internal.compiler.lookup.BlockScope;
17 import org.eclipse.jdt.internal.compiler.lookup.TypeBinding;
19 public class StringLiteral extends Literal {
23 public StringLiteral(char[] token, int s, int e) {
29 public StringLiteral(int s, int e) {
34 public void computeConstant() {
36 constant = Constant.fromValue(String.valueOf(source));
39 public ExtendedStringLiteral extendWith(CharLiteral lit){
41 //add the lit source to mine, just as if it was mine
42 return new ExtendedStringLiteral(this,lit);
45 public ExtendedStringLiteral extendWith(StringLiteral lit){
47 //add the lit source to mine, just as if it was mine
48 return new ExtendedStringLiteral(this,lit);
52 * Add the lit source to mine, just as if it was mine
54 public StringLiteralConcatenation extendsWith(StringLiteral lit) {
55 return new StringLiteralConcatenation(this, lit);
58 * Code generation for string literal
60 public void generateCode(BlockScope currentScope, CodeStream codeStream, boolean valueRequired) {
62 int pc = codeStream.position;
64 codeStream.ldc(constant.stringValue());
65 codeStream.recordPositionsFrom(pc, this.sourceStart);
68 public TypeBinding literalType(BlockScope scope) {
70 return scope.getJavaLangString();
73 public StringBuffer printExpression(int indent, StringBuffer output) {
75 // handle some special char.....
77 for (int i = 0; i < source.length; i++) {
80 output.append("\\b"); //$NON-NLS-1$
83 output.append("\\t"); //$NON-NLS-1$
86 output.append("\\n"); //$NON-NLS-1$
89 output.append("\\f"); //$NON-NLS-1$
92 output.append("\\r"); //$NON-NLS-1$
95 output.append("\\\""); //$NON-NLS-1$
98 output.append("\\'"); //$NON-NLS-1$
100 case '\\' : //take care not to display the escape as a potential real char
101 output.append("\\\\"); //$NON-NLS-1$
104 output.append(source[i]);
111 public char[] source() {
116 public void traverse(ASTVisitor visitor, BlockScope scope) {
117 visitor.visit(this, scope);
118 visitor.endVisit(this, scope);