1 24 25 package org.aspectj.compiler.base.ast; 26 27 import org.aspectj.compiler.base.JavaCompiler; 28 import org.aspectj.compiler.base.TypeManager; 29 30 import org.aspectj.compiler.base.bcg.FieldBuilder; 31 import org.aspectj.compiler.base.bcg.CodeBuilder; 32 import org.aspectj.compiler.base.bcg.Label; 33 34 35 39 public class StringLiteralExpr extends LiteralExpr { 40 41 44 private static void quoteCharacter(char ch, StringBuffer buf) { 45 49 switch (ch) { 50 case '\b': buf.append("\\b"); return; 51 case '\t': buf.append("\\t"); return; 52 case '\n': buf.append("\\n"); return; 53 case '\f': buf.append("\\f"); return; 54 case '\r': buf.append("\\r"); return; 55 case '\"': buf.append("\\\""); return; 56 case '\'': buf.append("\\\'"); return; 57 case '\\': buf.append("\\\\"); return; 58 } 59 60 buf.append(ch); 61 62 } 67 68 private static String quoteString(String value) { 69 StringBuffer buf = new StringBuffer ("\""); 70 for(int i=0; i<value.length(); i++) { 71 quoteCharacter(value.charAt(i), buf); 72 } 73 buf.append("\""); 74 return buf.toString(); 75 } 76 77 public StringLiteralExpr(SourceLocation source, String _stringValue) { 78 this(source, source.getCompiler().getTypeManager().getStringType(), 79 quoteString(_stringValue), 80 _stringValue); 81 } 82 83 86 protected void cgValue(CodeBuilder cb) { 87 cb.emitStringConstant(stringValue); 88 } 89 public void addConstant(FieldBuilder fb) { 90 fb.setConstantValue(stringValue); 91 } 92 93 protected String stringValue; 95 public String getStringValue() { return stringValue; } 96 public void setStringValue(String _stringValue) { stringValue = _stringValue; } 97 98 public StringLiteralExpr(SourceLocation location, Type _type, String _value, String _stringValue) { 99 super(location, _type, _value); 100 setStringValue(_stringValue); 101 } 102 protected StringLiteralExpr(SourceLocation source) { 103 super(source); 104 } 105 106 public ASTObject copyWalk(CopyWalker walker) { 107 StringLiteralExpr ret = new StringLiteralExpr(getSourceLocation()); 108 ret.preCopy(walker, this); 109 ret.type = type; 110 ret.value = value; 111 ret.stringValue = stringValue; 112 return ret; 113 } 114 115 116 public String getDefaultDisplayName() { 117 return "StringLiteralExpr(type: "+type+", "+"value: "+value+", "+"stringValue: "+stringValue+")"; 118 } 119 120 } 122 | Popular Tags |