1 /*******************************************************************************
2 * Copyright (c) 2000, 2001, 2002 International Business Machines Corp. and others.
3 * All rights reserved. This program and the accompanying materials
4 * are made available under the terms of the Common Public License v0.5
5 * which accompanies this distribution, and is available at
6 * http://www.eclipse.org/legal/cpl-v05.html
9 * IBM Corporation - initial API and implementation
10 ******************************************************************************/
11 package net.sourceforge.phpdt.internal.compiler.ast;
13 import net.sourceforge.phpdt.internal.compiler.IAbstractSyntaxTreeVisitor;
14 import net.sourceforge.phpdt.internal.compiler.codegen.CodeStream;
15 import net.sourceforge.phpdt.internal.compiler.impl.Constant;
16 import net.sourceforge.phpdt.internal.compiler.lookup.BlockScope;
17 import net.sourceforge.phpdt.internal.compiler.lookup.TypeBinding;
19 public class StringLiteral extends Literal {
22 public StringLiteral(char[] token, int s, int e) {
26 public StringLiteral(int s, int e) {
29 public void computeConstant() {
31 constant = Constant.fromValue(String.valueOf(source));}
32 public ExtendedStringLiteral extendWith(CharLiteral lit){
33 //add the lit source to mine, just as if it was mine
35 return new ExtendedStringLiteral(this,lit);
37 public ExtendedStringLiteral extendWith(StringLiteral lit){
38 //add the lit source to mine, just as if it was mine
40 return new ExtendedStringLiteral(this,lit);
43 * Code generation for string literal
45 * @param currentScope org.eclipse.jdt.internal.compiler.lookup.BlockScope
46 * @param codeStream org.eclipse.jdt.internal.compiler.codegen.CodeStream
47 * @param valueRequired boolean
49 public void generateCode(BlockScope currentScope, CodeStream codeStream, boolean valueRequired) {
50 int pc = codeStream.position;
52 codeStream.ldc(constant.stringValue());
53 codeStream.recordPositionsFrom(pc, this.sourceStart);
55 public TypeBinding literalType(BlockScope scope) {
56 return scope.getJavaLangString();
59 * source method comment.
61 public char[] source() {
64 public String toStringExpression() {
66 // handle some special char.....
67 StringBuffer result = new StringBuffer("\""); //$NON-NLS-1$
68 for (int i = 0; i < source.length; i++) {
71 result.append("\\b"); //$NON-NLS-1$
74 result.append("\\t"); //$NON-NLS-1$
77 result.append("\\n"); //$NON-NLS-1$
80 result.append("\\f"); //$NON-NLS-1$
83 result.append("\\r"); //$NON-NLS-1$
86 result.append("\\\""); //$NON-NLS-1$
89 result.append("\\'"); //$NON-NLS-1$
91 case '\\' : //take care not to display the escape as a potential real char
92 result.append("\\\\"); //$NON-NLS-1$
95 result.append(source[i]);
98 result.append("\""); //$NON-NLS-1$
99 return result.toString();
101 public void traverse(IAbstractSyntaxTreeVisitor visitor, BlockScope scope) {
102 visitor.visit(this, scope);
103 visitor.endVisit(this, scope);