*** empty log message ***
[phpeclipse.git] / net.sourceforge.phpeclipse / src / net / sourceforge / phpdt / internal / compiler / ast / StringLiteral.java
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
7  *
8  * Contributors:
9  *     IBM Corporation - initial API and implementation
10  ******************************************************************************/
11 package net.sourceforge.phpdt.internal.compiler.ast;
12
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;
18
19 public class StringLiteral extends Literal {
20   char[] source;
21
22   public StringLiteral(char[] token, int s) {
23     super(s, s + token.length);
24     source = token;
25   }
26
27   /**
28    * Create a new StringLiteral
29    * @param token the token
30    * @param s sourcestart
31    * @param e sourceend
32    * @deprecated
33    */
34   public StringLiteral(char[] token, int s, int e) {
35     super(s, e);
36     source = token;
37   }
38
39   public StringLiteral(int s, int e) {
40     super(s, e);
41   }
42
43   /**
44    * source method comment.
45    */
46   public char[] source() {
47     return source;
48   }
49
50   /**
51    * Return the expression as String.
52    * @return the expression
53    */
54   public String toStringExpression() {
55     // handle some special char.....
56     StringBuffer result = new StringBuffer("\""); //$NON-NLS-1$
57     for (int i = 0; i < source.length; i++) {
58       switch (source[i]) {
59         case '\b':
60           result.append("\\b"); //$NON-NLS-1$
61           break;
62         case '\t':
63           result.append("\\t"); //$NON-NLS-1$
64           break;
65         case '\n':
66           result.append("\\n"); //$NON-NLS-1$
67           break;
68         case '\f':
69           result.append("\\f"); //$NON-NLS-1$
70           break;
71         case '\r':
72           result.append("\\r"); //$NON-NLS-1$
73           break;
74         case '\"':
75           result.append("\\\""); //$NON-NLS-1$
76           break;
77         case '\'':
78           result.append("\\'"); //$NON-NLS-1$
79           break;
80         case '\\': //take care not to display the escape as a potential real char
81           result.append("\\\\"); //$NON-NLS-1$
82           break;
83         default :
84           result.append(source[i]);
85       }
86     }
87     result.append("\""); //$NON-NLS-1$
88     return result.toString();
89   }
90
91   /**
92    * @deprecated - use field instead
93    */
94   public int sourceEnd() {
95     return sourceEnd;
96   }
97
98   /**
99    * @deprecated - use field instead
100    */
101   public int sourceStart() {
102     return sourceStart;
103   }
104 }