public class LegacyBuiltInClassSanitizer
extends java.lang.Object
LegacySignature annotations for
hand-written legacy builtin classes, which exists in the com.goldencode.p2j.oo package.
To run this in test mode (which will just print the problems), use the (t)est mode.
The following LegacySignature attributes are verified and injected (if possible):
object methods or parameters
If the parameter count at LegacySignature doesn't match the paramter count at the Java method
definition, a message will be logged.
TODO: sanitize full Java method signature against the LegacySignature.
| Modifier and Type | Field and Description |
|---|---|
private static boolean |
testMode
Flag indicating if we are in test mode - no changes will be made to source code.
|
| Constructor and Description |
|---|
LegacyBuiltInClassSanitizer() |
| Modifier and Type | Method and Description |
|---|---|
private static int |
countParenthesis(java.lang.String line)
Count the number of opened parenthesis.
|
private static int |
findLegacySignatureLine(javassist.bytecode.CodeAttribute code,
java.util.List<java.lang.String> clsLines)
Find the line which holds the
LegacySignature annotation for the given method. |
private static int |
findLegacySignatureLine(javassist.CtClass cc,
javassist.CtMethod m,
java.util.List<java.lang.String> clsLines)
Find the line which holds the
LegacySignature annotation for the given method. |
private static int |
findLegacySignatureLine(int firstCodeLine,
java.util.List<java.lang.String> clsLines)
Find the line which holds the
LegacySignature annotation for the given method, by walking 'up'
until the LegacySignature is found. |
private static java.lang.String |
getLegacyType(javassist.bytecode.SignatureAttribute.MethodSignature sig,
javassist.bytecode.SignatureAttribute.ClassType tp)
Find the legacy OO type.
|
private static java.util.List<java.lang.String> |
injectMethodReturn(javassist.CtClass cc,
javassist.CtMethod m,
java.util.List<java.lang.String> clsLines)
Inject the
returns attribute (with the method's legacy return type) at the
LegacySignature annotation. |
private static java.util.List<java.lang.String> |
injectQualifiedParameter(javassist.CtClass cc,
javassist.CtMethod m,
int pidx,
java.util.List<java.lang.String> clsLines)
Inject the
qualified attribute (with the parameter's legacy qualified type) at the
LegacyParameter annotation. |
private static java.util.List<java.lang.String> |
injectQualifiedReturn(javassist.CtClass cc,
javassist.CtMethod m,
java.util.List<java.lang.String> clsLines)
Inject the
qualified attribute (with the method's legacy qualified type) at the
LegacySignature annotation. |
static void |
main(java.lang.String[] args)
Run the tool.
|
private static boolean |
parameterMatch(javassist.CtMethod m,
java.lang.String sig)
Check if the given Java-style signature matches the specified method.
|
private static java.util.List<java.lang.String> |
readSourceCode(javassist.CtClass cc)
Read the Java source code for the given class.
|
private static void |
writeSourceCode(javassist.CtClass cc,
java.util.List<java.lang.String> clsLines)
Write the santizied Java source code for the given class.
|
private static boolean testMode
private static java.util.List<java.lang.String> injectMethodReturn(javassist.CtClass cc,
javassist.CtMethod m,
java.util.List<java.lang.String> clsLines)
throws java.lang.Exception
returns attribute (with the method's legacy return type) at the
LegacySignature annotation.cc - The target class.m - The target method.clsLines - The source code.java.lang.Exceptionprivate static java.util.List<java.lang.String> injectQualifiedReturn(javassist.CtClass cc,
javassist.CtMethod m,
java.util.List<java.lang.String> clsLines)
throws java.lang.Exception
qualified attribute (with the method's legacy qualified type) at the
LegacySignature annotation. Only if the Java method returns object.cc - The target class.m - The target method.clsLines - The source code.java.lang.Exceptionprivate static java.util.List<java.lang.String> injectQualifiedParameter(javassist.CtClass cc,
javassist.CtMethod m,
int pidx,
java.util.List<java.lang.String> clsLines)
throws java.lang.Exception
qualified attribute (with the parameter's legacy qualified type) at the
LegacyParameter annotation. Only if the Java parameter's type is object.cc - The target class.m - The target method.pidx - The parameter index.clsLines - The source code.java.lang.Exceptionprivate static int findLegacySignatureLine(javassist.CtClass cc,
javassist.CtMethod m,
java.util.List<java.lang.String> clsLines)
throws java.lang.Exception
LegacySignature annotation for the given method.
This uses a heuristic to find the Java source code for the specified method.
cc - The target class.m - The target method.clsLines - The source code.-1 if can't be resolved.java.lang.Exceptionprivate static boolean parameterMatch(javassist.CtMethod m,
java.lang.String sig)
throws javassist.NotFoundException
m - The target method.sig - The candidate signature.true if the method has the same signature.javassist.NotFoundExceptionprivate static int countParenthesis(java.lang.String line)
line - The line of code.private static int findLegacySignatureLine(javassist.bytecode.CodeAttribute code,
java.util.List<java.lang.String> clsLines)
LegacySignature annotation for the given method.
This uses the disassembled bytecode to position on the method code, and walk 'up' until the
LegacySignature is found.
code - The method's code attribute.clsLines - The source code.-1 if can't be resolved.private static int findLegacySignatureLine(int firstCodeLine,
java.util.List<java.lang.String> clsLines)
LegacySignature annotation for the given method, by walking 'up'
until the LegacySignature is found.firstCodeLine - The method's first code line.clsLines - The source code.-1 if can't be resolved.private static java.lang.String getLegacyType(javassist.bytecode.SignatureAttribute.MethodSignature sig,
javassist.bytecode.SignatureAttribute.ClassType tp)
throws java.lang.ClassNotFoundException
sig - The method signature.tp - The type to resolve.java.lang.ClassNotFoundExceptionprivate static java.util.List<java.lang.String> readSourceCode(javassist.CtClass cc)
cc - The class to be read.private static void writeSourceCode(javassist.CtClass cc,
java.util.List<java.lang.String> clsLines)
cc - The class to be written.clsLines - The source code.public static void main(java.lang.String[] args)
throws java.lang.Exception
(t)est to run in 'test mode', with no side-effects for existing code -
this will only report any found problems in the com.goldencode.p2j.oo package.args - The arguments.java.lang.Exception