char sep = File.separatorChar;
String filename = directory + sep
+ classname.replace('.', sep) + ".class";
- return new FileInputStream(filename.toString());
+ return new FileInputStream(filename);
}
catch (FileNotFoundException e) {}
catch (SecurityException e) {}
@Override
public String toString() {
- return jarfileURL == null ? "<null>" : jarfileURL.toString();
+ return jarfileURL == null ? "<null>" : jarfileURL;
}
}
@Override
public String toString() {
- StringBuffer buf = new StringBuffer();
+ StringBuilder buf = new StringBuilder();
buf.append("[class path: ");
ClassPathList list = pathList;
while (list != null) {
}
@Override
- protected void extendToString(StringBuffer buffer) {
+ protected void extendToString(StringBuilder buffer) {
buffer.append(' ');
buffer.append(getName());
buffer.append(' ');
*/
@Override
public String toString() {
- StringBuffer buf = new StringBuffer(getClass().getName());
- buf.append("@");
+ StringBuilder buf = new StringBuilder(getClass().getName());
+ buf.append('@');
buf.append(Integer.toHexString(hashCode()));
- buf.append("[");
+ buf.append('[');
extendToString(buf);
- buf.append("]");
+ buf.append(']');
return buf.toString();
}
* Implemented in subclasses to add to the {@link #toString()} result.
* Subclasses should put a space before each token added to the buffer.
*/
- protected void extendToString(StringBuffer buffer) {
+ protected void extendToString(StringBuilder buffer) {
buffer.append(getName());
}
}
@Override
- protected void extendToString(StringBuffer buffer) {
+ protected void extendToString(StringBuilder buffer) {
if (wasChanged)
buffer.append("changed ");
if (ext != null) {
String name = ext.getName();
if (!name.equals("java.lang.Object"))
- buffer.append(" extends " + ext.getName());
+ buffer.append(" extends ").append(ext.getName());
}
}
catch (NotFoundException e) {
memCache.methodHead(), memCache.lastMethod());
}
- private void exToString(StringBuffer buffer, String msg,
+ private void exToString(StringBuilder buffer, String msg,
CtMember head, CtMember tail) {
buffer.append(msg);
while (head != tail) {
}
@Override
- protected void extendToString(StringBuffer buffer) {
+ protected void extendToString(StringBuilder buffer) {
buffer.append(' ');
buffer.append(getName());
buffer.append(' ');
*/
static class Cache extends CtMember {
@Override
- protected void extendToString(StringBuffer buffer) {}
+ protected void extendToString(StringBuilder buffer) {}
@Override
public boolean hasAnnotation(String clz) { return false; }
@Override
@Override
public String toString() {
- StringBuffer buffer = new StringBuffer(getClass().getName());
- buffer.append("@");
+ StringBuilder buffer = new StringBuilder(getClass().getName());
+ buffer.append('@');
buffer.append(Integer.toHexString(hashCode()));
- buffer.append("[");
+ buffer.append('[');
buffer.append(Modifier.toString(getModifiers()));
extendToString(buffer);
- buffer.append("]");
+ buffer.append(']');
return buffer.toString();
}
* provided first; subclasses should provide additional data such
* as return type, field or method name, etc.
*/
- protected abstract void extendToString(StringBuffer buffer);
+ protected abstract void extendToString(StringBuilder buffer);
/**
* Returns the class that declares this member.
}
@Override
- protected void extendToString(StringBuffer buffer) {
+ protected void extendToString(StringBuilder buffer) {
if (hasConstructor)
buffer.append("hasConstructor ");
if (arrayDim == 0)
return name;
- StringBuffer sbuf = new StringBuffer(name);
+ StringBuilder sbuf = new StringBuilder(name);
do {
sbuf.append("[]");
} while (--arrayDim > 0);
if (desc.indexOf(oldname) < 0)
return desc;
- StringBuffer newdesc = new StringBuffer();
+ StringBuilder newdesc = new StringBuilder();
int head = 0;
int i = 0;
for (;;) {
if (map == null)
return desc;
- StringBuffer newdesc = new StringBuffer();
+ StringBuilder newdesc = new StringBuilder();
int head = 0;
int i = 0;
for (;;) {
* Returns the descriptor representing the given type.
*/
public static String of(CtClass type) {
- StringBuffer sbuf = new StringBuffer();
+ StringBuilder sbuf = new StringBuilder();
toDescriptor(sbuf, type);
return sbuf.toString();
}
- private static void toDescriptor(StringBuffer desc, CtClass type) {
+ private static void toDescriptor(StringBuilder desc, CtClass type) {
if (type.isArray()) {
desc.append('[');
try {
* @param paramTypes parameter types
*/
public static String ofMethod(CtClass returnType, CtClass[] paramTypes) {
- StringBuffer desc = new StringBuffer();
+ StringBuilder desc = new StringBuilder();
desc.append('(');
if (paramTypes != null) {
int n = paramTypes.length;
int i = desc.indexOf(')');
if (i < 0)
return desc;
- StringBuffer newdesc = new StringBuffer();
+ StringBuilder newdesc = new StringBuilder();
newdesc.append(desc.substring(0, i));
newdesc.append('L');
newdesc.append(classname.replace('.', '/'));
int i = descriptor.indexOf(')');
if (i < 0)
return descriptor;
- StringBuffer newdesc = new StringBuffer();
+ StringBuilder newdesc = new StringBuilder();
newdesc.append(descriptor.substring(0, i));
toDescriptor(newdesc, type);
newdesc.append(descriptor.substring(i));
int i = desc.indexOf(')');
if (i < 0)
return desc;
- StringBuffer newdesc = new StringBuffer();
+ StringBuilder newdesc = new StringBuilder();
newdesc.append(desc.substring(0, i + 1));
newdesc.append('L');
newdesc.append(classname.replace('.', '/'));
}
if (arrayDim > 0) {
- StringBuffer sbuf = new StringBuffer(name);
+ StringBuilder sbuf = new StringBuilder(name);
while (arrayDim-- > 0)
sbuf.append("[]");
static class PrettyPrinter {
static String toString(String desc) {
- StringBuffer sbuf = new StringBuffer();
+ StringBuilder sbuf = new StringBuilder();
if (desc.charAt(0) == '(') {
int pos = 1;
sbuf.append('(');
return sbuf.toString();
}
- static int readType(StringBuffer sbuf, int pos, String desc) {
+ static int readType(StringBuilder sbuf, int pos, String desc) {
char c = desc.charAt(pos);
int arrayDim = 0;
while (c == '[') {
private static String lookupSwitch(CodeIterator iter, int pos) {
- StringBuffer buffer = new StringBuffer("lookupswitch {\n");
+ StringBuilder buffer = new StringBuilder("lookupswitch {\n");
int index = (pos & ~3) + 4;
// default
- buffer.append("\t\tdefault: ").append(pos + iter.s32bitAt(index)).append("\n");
+ buffer.append("\t\tdefault: ").append(pos + iter.s32bitAt(index)).append('\n');
int npairs = iter.s32bitAt(index += 4);
int end = npairs * 8 + (index += 4);
for (; index < end; index += 8) {
int match = iter.s32bitAt(index);
int target = iter.s32bitAt(index + 4) + pos;
- buffer.append("\t\t").append(match).append(": ").append(target).append("\n");
+ buffer.append("\t\t").append(match).append(": ").append(target).append('\n');
}
buffer.setCharAt(buffer.length() - 1, '}');
private static String tableSwitch(CodeIterator iter, int pos) {
- StringBuffer buffer = new StringBuffer("tableswitch {\n");
+ StringBuilder buffer = new StringBuilder("tableswitch {\n");
int index = (pos & ~3) + 4;
// default
- buffer.append("\t\tdefault: ").append(pos + iter.s32bitAt(index)).append("\n");
+ buffer.append("\t\tdefault: ").append(pos + iter.s32bitAt(index)).append('\n');
int low = iter.s32bitAt(index += 4);
int high = iter.s32bitAt(index += 4);
int end = (high - low + 1) * 4 + (index += 4);
// Offset table
for (int key = low; index < end; index += 4, key++) {
int target = iter.s32bitAt(index) + pos;
- buffer.append("\t\t").append(key).append(": ").append(target).append("\n");
+ buffer.append("\t\t").append(key).append(": ").append(target).append('\n');
}
buffer.setCharAt(buffer.length() - 1, '}');
StringBuilder sbuf = new StringBuilder();
for (Annotation[] a : aa) {
for (Annotation i : a)
- sbuf.append(i.toString()).append(" ");
+ sbuf.append(i.toString()).append(' ');
sbuf.append(", ");
}
*/
@Override
public String toString() {
- StringBuffer sbuf = new StringBuffer(getName());
+ StringBuilder sbuf = new StringBuilder(getName());
if (superClass != null)
sbuf.append(" extends ").append(superClass.toString());
*/
@Override
public String toString() {
- StringBuffer sbuf = new StringBuffer();
+ StringBuilder sbuf = new StringBuilder();
ClassType parent = getDeclaringClass();
if (parent != null)
sbuf.append(parent.toString()).append('.');
return toString2(sbuf);
}
- private String toString2(StringBuffer sbuf) {
+ private String toString2(StringBuilder sbuf) {
sbuf.append(name);
if (arguments != null) {
sbuf.append('<');
*/
@Override
public String jvmTypeName() {
- StringBuffer sbuf = new StringBuffer();
+ StringBuilder sbuf = new StringBuilder();
ClassType parent = getDeclaringClass();
if (parent != null)
sbuf.append(parent.jvmTypeName()).append('$');
*/
@Override
public String toString() {
- StringBuffer sbuf = new StringBuffer(componentType.toString());
+ StringBuilder sbuf = new StringBuilder(componentType.toString());
for (int i = 0; i < dim; i++)
sbuf.append("[]");
}
@Override
- protected void toString2(StringBuffer sbuf) {
+ protected void toString2(StringBuilder sbuf) {
super.toString2(sbuf);
sbuf.append(", incoming{");
for (int i = 0; i < entrances.length; i++)
sbuf.append(entrances[i].position).append(", ");
- sbuf.append("}");
+ sbuf.append('}');
}
BasicBlock[] getExit() { return exit; }
*/
@Override
public String toString() {
- StringBuffer sbuf = new StringBuffer();
+ StringBuilder sbuf = new StringBuilder();
sbuf.append("Node[pos=").append(block().position());
sbuf.append(", parent=");
sbuf.append(parent == null ? "*" : Integer.toString(parent.block().position()));
@Override
public String toString() {
- StringBuffer buffer = new StringBuffer();
+ StringBuilder buffer = new StringBuilder();
buffer.append("locals = [");
for (int i = 0; i < locals.length; i++) {
if (i < top - 1)
buffer.append(", ");
}
- buffer.append("]");
+ buffer.append(']');
return buffer.toString();
}
if (resolved != null)
return resolved.toString();
- StringBuffer buffer = new StringBuffer("{");
+ StringBuilder buffer = new StringBuilder();
+ buffer.append('{');
for (String key:interfaces.keySet())
buffer.append(key).append(", ");
if (potentialClass != null)
- buffer.append("*").append(potentialClass.toString());
+ buffer.append('*').append(potentialClass.toString());
else
buffer.setLength(buffer.length() - 2);
- buffer.append("}");
+ buffer.append('}');
return buffer.toString();
}
}
*/
@Override
public String toString() {
- StringBuffer buf = new StringBuffer("@");
+ StringBuilder buf = new StringBuilder();
+ buf.append('@');
buf.append(getTypeName());
if (members != null) {
- buf.append("(");
+ buf.append('(');
for (String name:members.keySet()) {
- buf.append(name).append("=")
+ buf.append(name).append('=')
.append(getMemberValue(name))
.append(", ");
}
buf.setLength(buf.length()-2);
- buf.append(")");
+ buf.append(')');
}
return buf.toString();
*/
@Override
public String toString() {
- StringBuffer buf = new StringBuffer("{");
+ StringBuilder buf = new StringBuilder();
+ buf.append('{');
if (values != null) {
for (int i = 0; i < values.length; i++) {
buf.append(values[i].toString());
}
}
- buf.append("}");
+ buf.append('}');
return buf.toString();
}
int index = classname.indexOf("[]");
if (index != -1) {
String rawType = classname.substring(0, index);
- StringBuffer sb = new StringBuffer(Descriptor.of(rawType));
+ StringBuilder sb = new StringBuilder(Descriptor.of(rawType));
while (index != -1) {
- sb.insert(0, "[");
+ sb.insert(0, '[');
index = classname.indexOf("[]", index + 1);
}
return sb.toString().replace('/', '.');
@Override
public String toString() {
- StringBuffer sbuf = new StringBuffer();
+ StringBuilder sbuf = new StringBuilder();
String cname = this.getClass().getName();
int i = cname.lastIndexOf('.');
sbuf.append(i < 0 ? cname : cname.substring(i + 1));
- sbuf.append("[");
+ sbuf.append('[');
toString2(sbuf);
- sbuf.append("]");
+ sbuf.append(']');
return sbuf.toString();
}
- protected void toString2(StringBuffer sbuf) {
+ protected void toString2(StringBuilder sbuf) {
sbuf.append("pos=").append(position).append(", len=")
.append(length).append(", in=").append(incoming)
.append(", exit{");
if (exit != null)
for (BasicBlock b:exit)
- sbuf.append(b.position).append(",");
+ sbuf.append(b.position).append(',');
sbuf.append("}, {");
Catch th = toCatch;
while (th != null) {
- sbuf.append("(").append(th.body.position).append(", ")
+ sbuf.append('(').append(th.body.position).append(", ")
.append(th.typeIndex).append("), ");
th = th.next;
}
- sbuf.append("}");
+ sbuf.append('}');
}
/**
private String fixTypes2(List<TypeData> scc, Set<String> lowersSet, ClassPool cp) throws NotFoundException {
Iterator<String> it = lowersSet.iterator();
- if (lowersSet.size() == 0)
+ if (lowersSet.isEmpty())
return null; // only NullType
else if (lowersSet.size() == 1)
return it.next();
}
@Override
- protected void toString2(StringBuffer sbuf) {
+ protected void toString2(StringBuilder sbuf) {
super.toString2(sbuf);
sbuf.append(",\n stack={");
printTypes(sbuf, stackTop, stackTypes);
sbuf.append('}');
}
- private void printTypes(StringBuffer sbuf, int size,
+ private void printTypes(StringBuilder sbuf, int size,
TypeData[] types) {
if (types == null)
return;
if (dim == 0)
return name;
- StringBuffer sbuf = new StringBuffer();
+ StringBuilder sbuf = new StringBuilder();
int d = dim;
while (d-- > 0)
sbuf.append('[');
break;
}
- StringBuffer sbuf = new StringBuffer();
+ StringBuilder sbuf = new StringBuilder();
while (dim-- > 0)
sbuf.append('[');
boolean alwaysBranch = compileBooleanExpr(true, expr);
if (alwaysBranch) {
bytecode.addOpcode(Opcode.GOTO);
- alwaysBranch = breakList.size() == 0;
+ alwaysBranch = breakList.isEmpty();
}
bytecode.addIndex(pc2 - bytecode.currentPc() + 1);
* must be passed to Class.forName().
*/
name2 = MemberResolver.jvmToJavaName(name2);
- StringBuffer sbuf = new StringBuffer();
+ StringBuilder sbuf = new StringBuilder();
while (i-- >= 0)
sbuf.append('[');
/* To support $cflow().
*/
protected void atCflow(ASTList cname) throws CompileError {
- StringBuffer sbuf = new StringBuffer();
+ StringBuilder sbuf = new StringBuilder();
if (cname == null || cname.tail() != null)
throw new CompileError("bad " + cflowName);
* <cflow> : $cflow '(' <cflow name> ')'
* <cflow name> : <identifier> ('.' <identifier>)*
*/
- private static void makeCflowName(StringBuffer sbuf, ASTree name)
+ private static void makeCflowName(StringBuilder sbuf, ASTree name)
throws CompileError
{
if (name instanceof Symbol) {
public class Lex implements TokenId {
private int lastChar;
- private StringBuffer textBuffer;
+ private StringBuilder textBuffer;
private Token currentToken;
private Token lookAheadTokens;
*/
public Lex(String s) {
lastChar = -1;
- textBuffer = new StringBuffer();
+ textBuffer = new StringBuilder();
currentToken = new Token();
lookAheadTokens = null;
else if(c == '.'){
c = getc();
if ('0' <= c && c <= '9') {
- StringBuffer tbuf = textBuffer;
+ StringBuilder tbuf = textBuffer;
tbuf.setLength(0);
tbuf.append('.');
return readDouble(tbuf, c, token);
private int readStringL(Token token) {
int c;
- StringBuffer tbuf = textBuffer;
+ StringBuilder tbuf = textBuffer;
tbuf.setLength(0);
for (;;) {
while ((c = getc()) != '"') {
}
else if (c2 == 'E' || c2 == 'e'
|| c2 == 'D' || c2 == 'd' || c2 == '.') {
- StringBuffer tbuf = textBuffer;
+ StringBuilder tbuf = textBuffer;
tbuf.setLength(0);
tbuf.append(value);
return readDouble(tbuf, c2, token);
}
}
- private int readDouble(StringBuffer sbuf, int c, Token token) {
+ private int readDouble(StringBuilder sbuf, int c, Token token) {
if (c != 'E' && c != 'e' && c != 'D' && c != 'd') {
sbuf.append((char)c);
for (;;) {
}
private int readIdentifier(int c, Token token) {
- StringBuffer tbuf = textBuffer;
+ StringBuilder tbuf = textBuffer;
tbuf.setLength(0);
do {
int i = classname.lastIndexOf('.');
if (notCheckInner || i < 0)
throw e;
- StringBuffer sbuf = new StringBuffer(classname);
+ StringBuilder sbuf = new StringBuilder(classname);
sbuf.setCharAt(i, '$');
classname = sbuf.toString();
}
{
String cname = toClassName(className);
if (dim > 0) {
- StringBuffer sbuf = new StringBuffer();
+ StringBuilder sbuf = new StringBuilder();
while (dim-- > 0)
sbuf.append('[');
private String toClassName(ASTree name)
throws CompileError
{
- StringBuffer sbuf = new StringBuffer();
+ StringBuilder sbuf = new StringBuilder();
toClassName(name, sbuf);
return sbuf.toString();
}
- private void toClassName(ASTree name, StringBuffer sbuf)
+ private void toClassName(ASTree name, StringBuilder sbuf)
throws CompileError
{
if (name instanceof Symbol) {
*/
protected static String argTypesToString(int[] types, int[] dims,
String[] cnames) {
- StringBuffer sbuf = new StringBuffer();
+ StringBuilder sbuf = new StringBuilder();
sbuf.append('(');
int n = types.length;
if (n > 0) {
* Converts a tuple of exprType, arrayDim, and className
* into a String object.
*/
- protected static StringBuffer typeToString(StringBuffer sbuf,
+ protected static StringBuilder typeToString(StringBuilder sbuf,
int type, int dim, String cname) {
String s;
if (type == CLASS)
@Override
public String toString() {
- StringBuffer sbuf = new StringBuffer();
+ StringBuilder sbuf = new StringBuilder();
sbuf.append("(<");
sbuf.append(getTag());
sbuf.append('>');
@Override
public String toString() {
- StringBuffer sbuf = new StringBuffer();
+ StringBuilder sbuf = new StringBuilder();
sbuf.append('<');
sbuf.append(getTag());
sbuf.append('>');
if (name == null)
return null;
- StringBuffer sbuf = new StringBuffer();
+ StringBuilder sbuf = new StringBuilder();
astToClassName(sbuf, name, sep);
return sbuf.toString();
}
- private static void astToClassName(StringBuffer sbuf, ASTList name,
+ private static void astToClassName(StringBuilder sbuf, ASTList name,
char sep) {
for (;;) {
ASTree h = name.head();
@Override
public String toString() {
- StringBuffer sbuf = new StringBuffer();
+ StringBuilder sbuf = new StringBuilder();
sbuf.append("(<Pair> ");
sbuf.append(left == null ? "<null>" : left.toString());
sbuf.append(" . ");
break;
}
- if (methodName.equals(""))
+ if ("".equals(methodName))
methodName = null;
return methodName;
if (!rtclass.isArray())
name = rtclass.getName();
else {
- StringBuffer sbuf = new StringBuffer();
+ StringBuilder sbuf = new StringBuilder();
do {
sbuf.append("[]");
rtclass = rtclass.getComponentType();
}
private String readLine(InputStream in) throws IOException {
- StringBuffer buf = new StringBuffer();
+ StringBuilder buf = new StringBuilder();
int c;
while ((c = in.read()) >= 0 && c != 0x0d)
buf.append((char)c);
public String getKey(Class<?> superClass, Class<?>[] interfaces, byte[] signature, boolean useWriteReplace)
{
- StringBuffer sbuf = new StringBuffer();
+ StringBuilder sbuf = new StringBuilder();
if (superClass != null){
sbuf.append(superClass.getName());
}
- sbuf.append(":");
+ sbuf.append(':');
for (int i = 0; i < interfaces.length; i++) {
sbuf.append(interfaces[i].getName());
- sbuf.append(":");
+ sbuf.append(':');
}
for (int i = 0; i < signature.length; i++) {
byte b = signature[i];
* @param retType return type.
*/
public static String makeDescriptor(Class<?>[] params, Class<?> retType) {
- StringBuffer sbuf = new StringBuffer();
+ StringBuilder sbuf = new StringBuilder();
sbuf.append('(');
for (int i = 0; i < params.length; i++)
makeDesc(sbuf, params[i]);
* @param retType return type.
*/
public static String makeDescriptor(String params, Class<?> retType) {
- StringBuffer sbuf = new StringBuffer(params);
+ StringBuilder sbuf = new StringBuilder(params);
makeDesc(sbuf, retType);
return sbuf.toString();
}
- private static void makeDesc(StringBuffer sbuf, Class<?> type) {
+ private static void makeDesc(StringBuilder sbuf, Class<?> type) {
if (type.isArray()) {
sbuf.append('[');
makeDesc(sbuf, type.getComponentType());