ec39d6e94a483373af725549e2cbe003e95ab269
[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, int e) {
23     super(s,e);
24                 source = token;
25         }
26
27         public StringLiteral(int s, int e) {
28     super(s,e);
29         }
30
31         /**
32          * source method comment.
33          */
34         public char[] source() {
35                 return source;
36         }
37
38   /**
39    * Return the expression as String.
40    * @return the expression
41    */
42         public String toStringExpression() {
43                 // handle some special char.....
44                 StringBuffer result = new StringBuffer("\""); //$NON-NLS-1$
45                 for (int i = 0; i < source.length; i++) {
46                         switch (source[i]) {
47                                 case '\b' :
48                                         result.append("\\b"); //$NON-NLS-1$
49                                         break;
50                                 case '\t' :
51                                         result.append("\\t"); //$NON-NLS-1$
52                                         break;
53                                 case '\n' :
54                                         result.append("\\n"); //$NON-NLS-1$
55                                         break;
56                                 case '\f' :
57                                         result.append("\\f"); //$NON-NLS-1$
58                                         break;
59                                 case '\r' :
60                                         result.append("\\r"); //$NON-NLS-1$
61                                         break;
62                                 case '\"' :
63                                         result.append("\\\""); //$NON-NLS-1$
64                                         break;
65                                 case '\'' :
66                                         result.append("\\'"); //$NON-NLS-1$
67                                         break;
68                                 case '\\' : //take care not to display the escape as a potential real char
69                                         result.append("\\\\"); //$NON-NLS-1$
70                                         break;
71                                 default :
72                                         result.append(source[i]);
73                         }
74                 }
75                 result.append("\""); //$NON-NLS-1$
76                 return result.toString();
77         }
78         
79         /** 
80          * @deprecated - use field instead
81         */
82         public int sourceEnd() {
83                 return sourceEnd;
84         }
85         
86         /** 
87          * @deprecated - use field instead
88         */
89         public int sourceStart() {
90                 return sourceStart;
91         }
92 }