1 /***********************************************************************************************************************************
2 * Copyright (c) 2000, 2003 IBM Corporation and others. All rights reserved. This program and the accompanying materials are made
3 * available under the terms of the Common Public License v1.0 which accompanies this distribution, and is available at
4 * http://www.eclipse.org/legal/cpl-v10.html
6 * Contributors: IBM Corporation - initial API and implementation
7 **********************************************************************************************************************************/
8 package net.sourceforge.phpeclipse.internal.compiler.ast;
10 import net.sourceforge.phpdt.internal.compiler.IAbstractSyntaxTreeVisitor;
11 import net.sourceforge.phpdt.internal.compiler.impl.Constant;
12 import net.sourceforge.phpdt.internal.compiler.lookup.BlockScope;
13 import net.sourceforge.phpdt.internal.compiler.lookup.TypeBinding;
15 public class StringLiteral extends Literal {
19 public StringLiteral(char[] token, int s, int e) {
25 public StringLiteral(int s, int e) {
30 public void computeConstant() {
32 constant = Constant.fromValue(String.valueOf(source));
35 // public ExtendedStringLiteral extendWith(CharLiteral lit) {
37 // //add the lit source to mine, just as if it was mine
38 // return new ExtendedStringLiteral(this, lit);
41 public ExtendedStringLiteral extendWith(StringLiteral lit) {
43 //add the lit source to mine, just as if it was mine
44 return new ExtendedStringLiteral(this, lit);
48 * Code generation for string literal
50 // public void generateCode(BlockScope currentScope, CodeStream codeStream, boolean valueRequired) {
52 // int pc = codeStream.position;
54 // codeStream.ldc(constant.stringValue());
55 // codeStream.recordPositionsFrom(pc, this.sourceStart);
57 public TypeBinding literalType(BlockScope scope) {
59 return scope.getJavaLangString();
62 public StringBuffer printExpression(int indent, StringBuffer output) {
64 // handle some special char.....
66 for (int i = 0; i < source.length; i++) {
69 output.append("\\b"); //$NON-NLS-1$
72 output.append("\\t"); //$NON-NLS-1$
75 output.append("\\n"); //$NON-NLS-1$
78 output.append("\\f"); //$NON-NLS-1$
81 output.append("\\r"); //$NON-NLS-1$
84 output.append("\\\""); //$NON-NLS-1$
87 output.append("\\'"); //$NON-NLS-1$
89 case '\\': //take care not to display the escape as a potential real char
90 output.append("\\\\"); //$NON-NLS-1$
93 output.append(source[i]);
100 public char[] source() {
105 public String toStringExpression() {
107 // handle some special char.....
108 StringBuffer result = new StringBuffer("\""); //$NON-NLS-1$
109 for (int i = 0; i < source.length; i++) {
112 result.append("\\b"); //$NON-NLS-1$
115 result.append("\\t"); //$NON-NLS-1$
118 result.append("\\n"); //$NON-NLS-1$
121 result.append("\\f"); //$NON-NLS-1$
124 result.append("\\r"); //$NON-NLS-1$
127 result.append("\\\""); //$NON-NLS-1$
130 result.append("\\'"); //$NON-NLS-1$
132 case '\\': //take care not to display the escape as a potential real char
133 result.append("\\\\"); //$NON-NLS-1$
136 result.append(source[i]);
139 result.append("\""); //$NON-NLS-1$
140 return result.toString();
143 public void traverse(IAbstractSyntaxTreeVisitor visitor, BlockScope scope) {
144 visitor.visit(this, scope);
145 visitor.endVisit(this, scope);