Code with Finding: |
class Utility {
/**
* A returntype signature represents the return value from a method.
* It is a series of bytes in the following grammar:
*
* <pre>
* <return_signature> ::= <field_type> | V
* </pre>
*
* The character V indicates that the method returns no value. Otherwise, the
* signature indicates the type of the return value.
* An argument signature represents an argument passed to a method:
*
* <pre>
* <argument_signature> ::= <field_type>
* </pre>
*
* A method signature represents the arguments that the method expects, and
* the value that it returns.
* <pre>
* <method_signature> ::= (<arguments_signature>) <return_signature>
* <arguments_signature>::= <argument_signature>*
* </pre>
*
* This method converts such a string into a Java type declaration like
* `void main(String[])' and throws a `ClassFormatException' when the parsed
* type is invalid.
*
* @param signature Method signature
* @param name Method name
* @param access Method access rights
* @param chopit
* @param vars
* @return Java type declaration
* @throws ClassFormatException
*/
public static String methodSignatureToString( String signature, String name,
String access, boolean chopit, LocalVariableTable vars ) throws ClassFormatException {
StringBuilder buf = new StringBuilder("(");
String type;
int index;
int var_index = access.contains("static") ? 0 : 1;
try { // Read all declarations between for `(' and `)'
if (signature.charAt(0) != '(') {
throw new ClassFormatException("Invalid method signature: " + signature);
}
index = 1; // current string position
while (signature.charAt(index) != ')') {
String param_type = signatureToString(signature.substring(index), chopit);
buf.append(param_type);
if (vars != null) {
LocalVariable l = vars.getLocalVariable(var_index, 0);
if (l != null) {
buf.append(" ").append(l.getName());
}
} else {
buf.append(" arg").append(var_index);
}
if ("double".equals(param_type) || "long".equals(param_type)) {
var_index += 2;
} else {
var_index++;
}
buf.append(", ");
//corrected concurrent private static field acess
index += unwrap(consumed_chars); // update position
}
index++; // update position
// Read return type after `)'
type = signatureToString(signature.substring(index), chopit);
} catch (StringIndexOutOfBoundsException e) { // Should never occur
throw new ClassFormatException("Invalid method signature: " + signature, e);
}
if (buf.length() > 1) {
buf.setLength(buf.length() - 2);
}
buf.append(")");
return access + ((access.length() > 0) ? " " : "") + // May be an empty string
type + " " + name + buf.toString();
}
}
class Utility {
/**
* Escape all occurences of newline chars '\n', quotes \", etc.
*/
public static String convertString( String label ) {
char[] ch = label.toCharArray();
StringBuilder buf = new StringBuilder();
for (char element : ch) {
switch (element) {
case '\n':
buf.append("\\n");
break;
case '\r':
buf.append("\\r");
break;
case '\"':
buf.append("\\\"");
break;
case '\'':
buf.append("\\'");
break;
case '\\':
buf.append("\\\\");
break;
default:
buf.append(element);
break;
}
}
return buf.toString();
}
}
|