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.phpdt.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,
51 // boolean valueRequired) {
53 // int pc = codeStream.position;
55 // codeStream.ldc(constant.stringValue());
56 // codeStream.recordPositionsFrom(pc, this.sourceStart);
58 public TypeBinding literalType(BlockScope scope) {
60 return scope.getJavaLangString();
63 public StringBuffer printExpression(int indent, StringBuffer output) {
65 // handle some special char.....
67 for (int i = 0; i < source.length; i++) {
70 output.append("\\b"); //$NON-NLS-1$
73 output.append("\\t"); //$NON-NLS-1$
76 output.append("\\n"); //$NON-NLS-1$
79 output.append("\\f"); //$NON-NLS-1$
82 output.append("\\r"); //$NON-NLS-1$
85 output.append("\\\""); //$NON-NLS-1$
88 output.append("\\'"); //$NON-NLS-1$
90 case '\\': // take care not to display the escape as a potential
92 output.append("\\\\"); //$NON-NLS-1$
95 output.append(source[i]);
102 public char[] source() {
107 public String toStringExpression() {
109 // handle some special char.....
110 StringBuffer result = new StringBuffer("\""); //$NON-NLS-1$
111 for (int i = 0; i < source.length; i++) {
114 result.append("\\b"); //$NON-NLS-1$
117 result.append("\\t"); //$NON-NLS-1$
120 result.append("\\n"); //$NON-NLS-1$
123 result.append("\\f"); //$NON-NLS-1$
126 result.append("\\r"); //$NON-NLS-1$
129 result.append("\\\""); //$NON-NLS-1$
132 result.append("\\'"); //$NON-NLS-1$
134 case '\\': // take care not to display the escape as a potential
136 result.append("\\\\"); //$NON-NLS-1$
139 result.append(source[i]);
142 result.append("\""); //$NON-NLS-1$
143 return result.toString();
146 public void traverse(IAbstractSyntaxTreeVisitor visitor, BlockScope scope) {
147 visitor.visit(this, scope);
148 visitor.endVisit(this, scope);