|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object com.ph.pr.apps.jaspcleaner.JaspCleaner
public class JaspCleaner
The main Victor class...
main(String[])
,
FogBugzIIINested Class Summary | |
---|---|
(package private) class |
JaspCleaner.CompositePattern
|
(package private) class |
JaspCleaner.SignatureComparator
|
Field Summary | |
---|---|
static boolean |
_DEBUG
|
private java.util.HashMap |
BOXED_PRIMITIVE_TYPES
|
private static java.lang.Class[] |
DUMMY_CLASS_ARRAY
For faster performance when we need to cast an array. |
private static boolean |
echoToStdout
|
private java.lang.String |
inMethod
|
private java.util.List |
javaLines
|
private java.util.Map |
javaToJspLine
|
private java.util.List |
jspLineOffset
|
private java.util.List |
jspLines
|
private JCClassLoader |
loader
Used for loading classes based on import statements. |
private java.util.Map |
localMethods
Map of method names to their return types. |
private static java.io.PrintStream |
logPrintStream
|
private static int |
MAX_PASSES
|
private java.util.Map |
newNodeType
Map of AST to return replacement type (as Class). |
private java.util.Map |
newVars
Map of variables (as Strings) to their new types (as Class) |
private java.util.Map |
nodeText
Map of AST to textual representation (as String) |
private java.util.Map |
nodeType
Map of AST to return type (as Class). |
private java.util.Map |
pmdReplacements
Map of regexp patterns to replace from PMD phase. |
private java.util.Set |
PRIMITIVE_TYPES
|
private java.util.HashMap |
PROGID_MAP
|
static char[] |
REGEX_RESERVED_CHAR
Reserved characters for regular expressions in java.util.regex package. |
private java.util.Map |
replacements
Map of regexp patterns to replace. |
(package private) static java.lang.Class |
UNKNOWN_CLASS
Unknown Class |
private java.util.Map |
used
|
private java.util.HashMap |
VARIANT_CONVERSIONS
|
private java.util.HashMap |
VARIANT_OPERATORS
|
private java.util.Map |
vars
Map of variables to their old types |
private java.util.Properties |
victorProperties
|
private java.util.Set |
visited
|
Constructor Summary | |
---|---|
JaspCleaner()
|
Method Summary | |
---|---|
private void |
cascadeReplacements()
|
private void |
checkForPMDReplacement(antlr.collections.AST ast)
Check an assignment to see if its LHS has been flagged by PMS as an unused variable. |
private java.util.Map |
checkForPVectorAddChain(antlr.collections.AST exprContents)
Check a METHOD_CALL to see if it is a pVector.Add() chain |
private void |
coerceAssignTypes(antlr.collections.AST ast)
Check an assignment to see if we can coerce lhs or rhs type |
private static void |
copy(java.io.File from,
java.io.File to)
Copies files. |
void |
do_ArrayList_getItem(java.util.Map callInfo)
A getItem() called on a vbarray object will be translated to a get() call on an ArrayList object, but since J-ASP seems to be using arrays with OPTION BASE1, this method will automatically subtract one from index. |
void |
do_operator_get(java.util.Map callInfo)
|
void |
do_operator_Greater(java.util.Map callInfo)
|
void |
do_operator_invoke(java.util.Map callInfo)
|
void |
do_operator_Is(java.util.Map callInfo)
|
void |
do_operator_set(java.util.Map callInfo)
|
void |
do_PHUtils_CreateObject(java.util.Map callInfo)
|
void |
do_primitive_operator(java.util.Map callInfo)
Replace primitive-operator equivalents (e.g. |
void |
do_Server_CreateObject(java.util.Map callInfo)
|
void |
do_String_unequals(java.util.Map callInfo)
|
void |
do_variant_conversion(java.util.Map callInfo)
|
void |
do_variant_set(java.util.Map callInfo)
For a set() invocation on a variant object, try to determine the type of the object, and replace the set() call with an assignment. |
void |
do_variant_setObject(java.util.Map callInfo)
|
void |
do_vb_Chr(java.util.Map callInfo)
|
void |
do_vb_Instr(java.util.Map callInfo)
|
void |
do_vb_IsArray(java.util.Map callInfo)
|
void |
do_vb_IsEmpty(java.util.Map callInfo)
|
void |
do_vb_IsEmptyIsNull(java.util.Map callInfo)
|
void |
do_vb_IsNull(java.util.Map callInfo)
|
void |
do_vb_LCase(java.util.Map callInfo)
|
void |
do_vb_Left(java.util.Map callInfo)
|
void |
do_vb_Len(java.util.Map callInfo)
|
void |
do_vb_Mid(java.util.Map callInfo)
|
void |
do_vb_Replace(java.util.Map callInfo)
|
void |
do_vb_Right(java.util.Map callInfo)
|
void |
do_vb_RightLeftMid(java.util.Map callInfo)
|
void |
do_vb_String(java.util.Map callInfo)
|
void |
do_vb_Trim(java.util.Map callInfo)
|
void |
do_vb_UBound(java.util.Map callInfo)
Replace UBound() with size(). |
void |
do_vb_UCase(java.util.Map callInfo)
|
void |
do_vb_UCaseLCase(java.util.Map callInfo)
|
private void |
doPMD(java.io.File f)
Perform PMD analysis, and get rid of unused vars. |
private java.lang.String |
doReplacements(java.lang.String jspPage)
|
private static java.lang.String |
escapeRegex(java.lang.String pattern)
Escape all the regexp reserved characters in a string |
private java.lang.String |
fileToString(java.io.File interJsp)
|
private java.util.ArrayList |
findMatchingMethods(java.util.Map callInfo,
JaspCleaner.SignatureComparator sc)
|
private java.lang.String |
getCanonicalText(antlr.collections.AST ast)
|
private java.lang.Class |
guessClassFromHungarianNotation(java.lang.String id)
|
private static java.lang.String[] |
inclusiveSplit(java.lang.String regex,
java.lang.String target)
Works like String.split(String regex), except that the delimiters that are detected appear as elements in the output array. |
private void |
insertLineNumbers(java.io.File interJsp,
java.io.File linedJsp)
|
private java.lang.String |
intString(java.lang.String doubleString)
Convert a vb string index/length expression from double to int |
private boolean |
isPrimitiveOperator(java.util.Map callInfo)
Check if method can be coerced to a primitive (or String) operator If it can be, then callInfo.get("COERCEDTYPE") is updated with the coerced type. |
private static void |
log(java.lang.String s)
Log the message (currently, to System.out). |
private static void |
logDebug(java.lang.String s)
|
static void |
main(java.lang.String[] args)
For each of the JSP files to be converted, the following algorithm is performed: Preprocess the page
Do static semantic analysis of the file (in visit(AST) ,
and processMethodCall(antlr.collections.AST) }, and identify with what types to replace
variant types to the best of our ability (see above two
methods for heuristics used). |
private static java.lang.String |
makeArgList(java.util.List list)
Make a comma-separated String out of the contents of the passed List. |
private JaspCleaner.CompositePattern |
makeMethodCallCP(java.lang.String arg0,
java.lang.String method,
java.lang.String args)
|
java.util.List |
matchArgBoxing(java.util.Map callInfo)
|
private static void |
postProcess(java.lang.String jspPage,
java.io.File to)
Postprocess, as follows: Replace invocation of default variant constructors with
nothing; i.e., new variant().foo() becomes foo()
Replace Netcoole's conversion methods -- static methods of the class
vb whose names start with C, e.g., (
vb.CInt(jasp.vbs.variant) -- with their arguments. |
private static void |
preProcess(java.io.File from,
java.io.File to)
Preprocesses the original Netcoole-converted JSP file. |
private java.util.Map |
processMethodCall(antlr.collections.AST inAst)
Processes an encountered method call. |
private void |
propagateNodeText(antlr.collections.AST ast)
Visit children, accumulating and storing nodeText for this node |
private java.lang.String |
replaceHTMLComments(java.lang.String jspFragment)
|
private void |
setNewVar(java.lang.String ident,
java.lang.Class type)
|
static java.lang.String |
stripEnclosingChar(java.lang.String arg1)
|
static java.lang.String |
toUpperCamelCase(java.lang.String arg1)
|
void |
visit(antlr.collections.AST ast)
Visitor pattern applied, based on AST.getType() and
switch statement, as follows (unless ast is
null):
Default: call this method on all children of the supplied
ast in turn. |
private static void |
write(java.io.File f,
java.lang.String s)
Writes the string into a file. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
static final java.lang.Class UNKNOWN_CLASS
private final java.util.Map localMethods
private static final java.lang.Class[] DUMMY_CLASS_ARRAY
List.toArray(java.lang.Object[])
public static final char[] REGEX_RESERVED_CHAR
private final java.util.HashMap VARIANT_OPERATORS
private final java.util.HashMap VARIANT_CONVERSIONS
private final java.util.Set PRIMITIVE_TYPES
private final java.util.HashMap BOXED_PRIMITIVE_TYPES
private final java.util.HashMap PROGID_MAP
private final java.util.Map vars
private final java.util.Map newVars
private final java.util.Map replacements
private final java.util.Map pmdReplacements
private final java.util.Map nodeText
private final java.util.Set visited
private final java.util.Map nodeType
private final java.util.Map newNodeType
private final JCClassLoader loader
private final java.util.Map used
private java.util.Properties victorProperties
private static boolean echoToStdout
private static java.io.PrintStream logPrintStream
public static boolean _DEBUG
private java.lang.String inMethod
private static final int MAX_PASSES
private final java.util.List javaLines
private final java.util.List jspLines
private final java.util.Map javaToJspLine
private final java.util.List jspLineOffset
Constructor Detail |
---|
JaspCleaner() throws java.lang.Exception
java.lang.Exception
Method Detail |
---|
private static final java.lang.String makeArgList(java.util.List list)
list
- list to convert.
private static final java.lang.String escapeRegex(java.lang.String pattern)
private java.util.Map processMethodCall(antlr.collections.AST inAst)
#doset(Map)
. This is done so processing of each particular
method call is in its own method instead of crowding this one. If nothing
is to be done, well, nothing is done.
ast
- AST representing a
JavaTokenTypes.METHOD_CALL
.
Key (always a String) | Value (if a Class, can be UNKNOWN_CLASS ) |
---|---|
"CALLAST" | The AST node for the method call itself |
"ARG0" | The object (String) on which this method is dispatched, |
"ARG0AST" | The AST node for the object on which this method is dispatched |
"CLASS" | Class of "ARG0" above |
"METHOD" | The method name, as String |
"ARGLIST" | List of arguments (as String s -- such that, for instance, "ARGLIST" for foo(x.bar().baz(),44) is a List of two Strings: "x.bar().baz()" and "44". |
"ARGASTLIST" | List of arguments (as AST s -- such that, for instance, "ARGLIST" for foo(x.bar().baz(),44) is a List of two ASTs: the DOT that is the root of the subtree for x.bar().baz() and the NUM_INT that represents 44. |
"ARGTYPES" | A List of types of arguments passed in this method call (corresponding to value of "ARGLIST" above) as Class objects. |
"RETURNS" | A type (as Class) that this method returns. |
private boolean isPrimitiveOperator(java.util.Map callInfo)
callInfo
-
private void setNewVar(java.lang.String ident, java.lang.Class type)
public void do_vb_Right(java.util.Map callInfo)
public void do_vb_Left(java.util.Map callInfo)
public void do_vb_Mid(java.util.Map callInfo)
public void do_vb_UCase(java.util.Map callInfo)
public void do_vb_LCase(java.util.Map callInfo)
public void do_vb_IsEmpty(java.util.Map callInfo)
public void do_vb_IsNull(java.util.Map callInfo)
public void do_vb_Chr(java.util.Map callInfo)
public void do_vb_IsEmptyIsNull(java.util.Map callInfo)
public void do_vb_UCaseLCase(java.util.Map callInfo)
public void do_vb_RightLeftMid(java.util.Map callInfo)
callInfo
- private java.lang.String intString(java.lang.String doubleString)
doubleString
-
public void do_variant_conversion(java.util.Map callInfo)
private JaspCleaner.CompositePattern makeMethodCallCP(java.lang.String arg0, java.lang.String method, java.lang.String args)
arg0
- method
- args
-
public void do_primitive_operator(java.util.Map callInfo)
public void do_vb_UBound(java.util.Map callInfo)
public void do_vb_Len(java.util.Map callInfo)
public void do_vb_Trim(java.util.Map callInfo)
private java.util.Map checkForPVectorAddChain(antlr.collections.AST exprContents)
exprContents
- public void do_vb_Instr(java.util.Map callInfo)
public void do_vb_Replace(java.util.Map callInfo)
public void do_vb_String(java.util.Map callInfo)
public void do_vb_IsArray(java.util.Map callInfo)
public void do_ArrayList_getItem(java.util.Map callInfo)
public void do_String_unequals(java.util.Map callInfo)
public void do_PHUtils_CreateObject(java.util.Map callInfo)
public void do_Server_CreateObject(java.util.Map callInfo)
public void do_variant_setObject(java.util.Map callInfo)
public void do_variant_set(java.util.Map callInfo)
callInfo
- public java.util.List matchArgBoxing(java.util.Map callInfo)
private java.util.ArrayList findMatchingMethods(java.util.Map callInfo, JaspCleaner.SignatureComparator sc)
callInfo
- sc
-
public void do_operator_Greater(java.util.Map callInfo)
public void do_operator_Is(java.util.Map callInfo)
public void do_operator_invoke(java.util.Map callInfo)
public void do_operator_get(java.util.Map callInfo)
public void do_operator_set(java.util.Map callInfo)
public static java.lang.String stripEnclosingChar(java.lang.String arg1)
public static java.lang.String toUpperCamelCase(java.lang.String arg1)
arg1
-
public void visit(antlr.collections.AST ast)
AST.getType()
and
switch statement, as follows (unless ast is
null):
next sibling
of this ast.
visit
in interface antlr.ASTVisitor
ast
- AST to visit.private void coerceAssignTypes(antlr.collections.AST ast)
ast
- private void checkForPMDReplacement(antlr.collections.AST ast)
ast
- private void propagateNodeText(antlr.collections.AST ast)
ast
- private java.lang.String getCanonicalText(antlr.collections.AST ast)
ast
- txt
-
private static final void log(java.lang.String s)
s
- message to log.private static final void logDebug(java.lang.String s)
private static void preProcess(java.io.File from, java.io.File to) throws java.io.FileNotFoundException, java.io.IOException
The preprocessing involves the following:
from
- .jsp file to preprocessto
- file to write the output of the preprocessing.
java.io.FileNotFoundException
- if an error occur accessing files.
java.io.IOException
- if an error occur accessing files.private static void write(java.io.File f, java.lang.String s) throws java.io.IOException
f
- file to write to.s
- string to write
java.io.IOException
- if an error occurs during writingprivate static void postProcess(java.lang.String jspPage, java.io.File to) throws java.io.FileNotFoundException, java.io.IOException
variant
constructors with
nothing; i.e., new variant().foo() becomes foo()
vb.CInt(jasp.vbs.variant)
-- with their arguments. E.g.,
vb.CInt(foo) will become foo.
jspPage
- JSP Page to preprocessto
- file to write the output of the preprocessing.
java.io.FileNotFoundException
- if an error occur accessing files.
java.io.IOException
- if an error occur accessing files.private static final void copy(java.io.File from, java.io.File to) throws java.io.IOException
from
- File to copyto
- File to copy to
java.io.IOException
- whenever an I/O error occurs.public static void main(java.lang.String[] args) throws java.lang.Exception
Preprocess
the page
visit(AST)
,
and processMethodCall(antlr.collections.AST)
}, and identify with what types to replace
variant types to the best of our ability (see above two
methods for heuristics used).
Postprocess
the page
args
- JSP files to be converted.
java.lang.Exception
private void insertLineNumbers(java.io.File interJsp, java.io.File linedJsp) throws java.io.IOException
interJsp
- -
input File - intermediate JSP file
java.io.IOException
private java.lang.String doReplacements(java.lang.String jspPage) throws java.io.FileNotFoundException, java.io.IOException
cleaner
- interJsp
-
java.io.FileNotFoundException
java.io.IOException
private java.lang.String replaceHTMLComments(java.lang.String jspFragment)
jspFragment
-
private java.lang.String fileToString(java.io.File interJsp) throws java.io.FileNotFoundException, java.io.IOException
interJsp
-
java.io.FileNotFoundException
java.io.IOException
private static java.lang.String[] inclusiveSplit(java.lang.String regex, java.lang.String target)
regex
- target
- private void doPMD(java.io.File f) throws net.sourceforge.pmd.PMDException, java.io.IOException
f
- .java file to analyzereplaceements
- Map of replacements
.
net.sourceforge.pmd.PMDException
java.io.IOException
private java.lang.Class guessClassFromHungarianNotation(java.lang.String id)
private void cascadeReplacements()
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |