Class MigrateJCas
- All Implemented Interfaces:
com.github.javaparser.ast.visitor.VoidVisitor<Object>
A driver that scans given roots for source and/or class Java files that contain JCas classes
- identifies which ones appear to be JCas classes (heuristic)
- of these, identifies which ones appear to be v2
- converts these to v3
- of these, identifies which ones appear to be v2
- also can receive a list of individual class names
- also can do a single source file
Creates summary and detailed reports of its actions.
Files representing JCas classes to convert are discovered by walking file system directories from various roots, specified as input. The tool operates in 1 of two exclusive "modes": migrating from sources (e.g., .java files) and migrating using compiled classes.
Compiled classes are decompiled and then migrated. This decompilation step usually requires a java classpath, which is supplied using the -migrateClasspath parameter. Exception: migrating PEAR files, which contain their own specification for a classpath.
The same JCas class may be encountered multiple times while walking the directory tree from the roots, with the same or different definition. All of these definitions are migrated.
Copies of the original and the converted files are put into the output file tree.
Directory structure, starting at -outputDirectory (which if not specified, is a new temp directory). The "a0", "a1" represent non-identical alternative definitions for the same class.
converted/ v2/ these are the decompiled or "found" source files a0/x/y/z/javapath/.../Classname.java root-id + fully qualified java class + package as slashified name /Classname2.java etc. a1/x/y/z/javapath/.../Classname.java if there are different root-ids ... v3/ a0/x/y/z/javapath/.../Classname.java fully qualified java class + package as slashified name /Classname2.java etc. a1/x/y/z/javapath/.../Classname.java if there are different root-ids ... v3-classes - the compiled form if from classes and a java compiler was available The first directory is the id of the Jar or PEAR container. The second directory is the alternative. 23/a0/fully/slashified/package/class-name.class << parallel structure as v3/ jars/ - copies of the original JARs with the converted JCas classes The first directory is the id of the Jar or PEAR container 7/jar-file-name-last-part.jar 12/jar-file-name-last-part.jar 14/ etc. pears - copies of the original PEARs with the converted JCas classes, if there were no duplicates 8/pear-file-name-last-art.pear 9/ etc. not-converted/ (skipped) logs/ jar-map.txt list of index to paths pear-map.txt list of index to paths processed.txt duplicates.txt builtinsNotExtended.txt failed.txt skippedBuiltins.txt nonJCasFiles.txt woraroundDir.txt deletedCheckModified.txt manualInspection.txt pearFileUpdates.txt jarFileUpdates.txt ...
Operates in one of two modes:
Mode 1: Given classes-roots and/or individual class names, and a migrateClasspath, scans the classes-routes looking for classes candidates - determines the class name, - decompiles that - migrates that decompiled source. if a Java compiler (JDK) is available, - compiles the results - does reassembly for Jars and PEARs, replacing the JCas classes. Mode 2: Given sources-roots or a single source java file scans the sources-routes looking for candidates - migrates that decompiled source.
Note: Each run clears the output directory before starting the migration.
Note: classpath may be specified using -migrateClassPath or as the class path used to run this tool.
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionstatic void
void
Capture the type name from all top-level types AnnotationDeclaration, Empty, and Enumvoid
Check if the top level class looks like a JCas class, and report if not: has 0, 1, and 2 element constructors has static final field defs for type and typeIndexID Also check if V2 style: 2 arg constructor arg types Report if looks like V3 style due to args of 2 arg constructor if class doesn't extend anything, not a JCas class.void
Constructors - modify the 2 arg constructor - changing the args and the bodyvoid
void
Method Declaration Visitor Heuristic to determine if a feature getter or setter: - name: is 4 or more chars, starting with get or set, with 4th char uppercase is not "getTypeIndexID" - (optional - if comments are available:) getter for xxx, setter for xxx - for getter: has 0 or 1 arg (1 arg case for indexed getter, arg must be int type) - for setter: has 1 or 2 args Workaround for decompiler - getters which return FSs might be missing the cast to the return value typevoid
visitor for field access expressions - convert ((...type_Type)jcasType).casFeatCode_XXXX to _FI_xxxvoid
visitor for method callsvoid
void
Visitor for if stmts - removes feature missing testMethods inherited from class com.github.javaparser.ast.visitor.VoidVisitorAdapter
visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit, visit
-
Constructor Details
-
MigrateJCas
public MigrateJCas()
-
-
Method Details
-
main
-
visit
Capture the type name from all top-level types AnnotationDeclaration, Empty, and Enum -
visit
-
visit
Check if the top level class looks like a JCas class, and report if not: has 0, 1, and 2 element constructors has static final field defs for type and typeIndexID Also check if V2 style: 2 arg constructor arg types Report if looks like V3 style due to args of 2 arg constructor if class doesn't extend anything, not a JCas class. if class is enum, not a JCas class -
visit
-
visit
Constructors - modify the 2 arg constructor - changing the args and the body -
visit
Method Declaration Visitor Heuristic to determine if a feature getter or setter: - name: is 4 or more chars, starting with get or set, with 4th char uppercase is not "getTypeIndexID" - (optional - if comments are available:) getter for xxx, setter for xxx - for getter: has 0 or 1 arg (1 arg case for indexed getter, arg must be int type) - for setter: has 1 or 2 args Workaround for decompiler - getters which return FSs might be missing the cast to the return value type -
visit
Visitor for if stmts - removes feature missing test -
visit
visitor for method calls -
visit
visitor for field access expressions - convert ((...type_Type)jcasType).casFeatCode_XXXX to _FI_xxx
-