1 /*******************************************************************************
2 * Copyright (c) 2000, 2003 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 net.sourceforge.phpeclipse.internal.compiler.ast;
13 import net.sourceforge.phpdt.internal.compiler.IAbstractSyntaxTreeVisitor;
14 import net.sourceforge.phpdt.internal.compiler.impl.Constant;
15 import net.sourceforge.phpdt.internal.compiler.lookup.BlockScope;
16 import net.sourceforge.phpdt.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 * Code generation for string literal
54 // public void generateCode(BlockScope currentScope, CodeStream codeStream, boolean valueRequired) {
56 // int pc = codeStream.position;
58 // codeStream.ldc(constant.stringValue());
59 // codeStream.recordPositionsFrom(pc, this.sourceStart);
62 public TypeBinding literalType(BlockScope scope) {
64 return scope.getJavaLangString();
67 public char[] source() {
72 public String toStringExpression() {
74 // handle some special char.....
75 StringBuffer result = new StringBuffer("\""); //$NON-NLS-1$
76 for (int i = 0; i < source.length; i++) {
79 result.append("\\b"); //$NON-NLS-1$
82 result.append("\\t"); //$NON-NLS-1$
85 result.append("\\n"); //$NON-NLS-1$
88 result.append("\\f"); //$NON-NLS-1$
91 result.append("\\r"); //$NON-NLS-1$
94 result.append("\\\""); //$NON-NLS-1$
97 result.append("\\'"); //$NON-NLS-1$
99 case '\\' : //take care not to display the escape as a potential real char
100 result.append("\\\\"); //$NON-NLS-1$
103 result.append(source[i]);
106 result.append("\""); //$NON-NLS-1$
107 return result.toString();
110 public void traverse(IAbstractSyntaxTreeVisitor visitor, BlockScope scope) {
111 visitor.visit(this, scope);
112 visitor.endVisit(this, scope);