Skip to content

Commit f1e4b91

Browse files
author
zhourenjian
committed
Generate constant string instead of qualified name if constant string is shorter than 20 characters.
1 parent 14a2d50 commit f1e4b91

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

src/net/sf/j2s/core/astvisitors/ASTVariableVisitor.java

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -204,6 +204,20 @@ protected String checkConstantValue(Expression node) {
204204
}
205205
return buffer.toString();
206206
}
207+
if (constValue != null && (constValue instanceof String)) {
208+
StringBuffer buffer = new StringBuffer();
209+
String str = (String) constValue;
210+
if (str.length() > 20) {
211+
return null;
212+
}
213+
buffer.append("\"");
214+
buffer.append(str.replaceAll("\\\\", "\\\\\\\\")
215+
.replaceAll("\r", "\\\\r")
216+
.replaceAll("\n", "\\\\n")
217+
.replaceAll("\"", "\\\\\""));
218+
buffer.append("\"");
219+
return buffer.toString();
220+
}
207221
return null;
208222
}
209223
}

0 commit comments

Comments
 (0)