Class MigrateJCas

java.lang.Object
com.github.javaparser.ast.visitor.VoidVisitorAdapter<Object>
org.apache.uima.migratev3.jcas.MigrateJCas
All Implemented Interfaces:
com.github.javaparser.ast.visitor.VoidVisitor<Object>

public class MigrateJCas extends com.github.javaparser.ast.visitor.VoidVisitorAdapter<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
  • 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

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    static void
    main(String[] args)
     
    void
    visit(com.github.javaparser.ast.body.AnnotationDeclaration n, Object ignore)
    Capture the type name from all top-level types AnnotationDeclaration, Empty, and Enum
    void
    visit(com.github.javaparser.ast.body.ClassOrInterfaceDeclaration n, Object ignore)
    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
    visit(com.github.javaparser.ast.body.ConstructorDeclaration n, Object ignored)
    Constructors - modify the 2 arg constructor - changing the args and the body
    void
    visit(com.github.javaparser.ast.body.EnumDeclaration n, Object ignore)
     
    void
    visit(com.github.javaparser.ast.body.MethodDeclaration n, Object ignore)
    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
    void
    visit(com.github.javaparser.ast.expr.FieldAccessExpr n, Object ignore)
    visitor for field access expressions - convert ((...type_Type)jcasType).casFeatCode_XXXX to _FI_xxx
    void
    visit(com.github.javaparser.ast.expr.MethodCallExpr n, Object ignore)
    visitor for method calls
    void
    visit(com.github.javaparser.ast.PackageDeclaration n, Object ignored)
     
    void
    visit(com.github.javaparser.ast.stmt.IfStmt n, Object ignore)
    Visitor for if stmts - removes feature missing test

    Methods 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

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • MigrateJCas

      public MigrateJCas()
  • Method Details

    • main

      public static void main(String[] args)
    • visit

      public void visit(com.github.javaparser.ast.body.AnnotationDeclaration n, Object ignore)
      Capture the type name from all top-level types AnnotationDeclaration, Empty, and Enum
      Specified by:
      visit in interface com.github.javaparser.ast.visitor.VoidVisitor<Object>
      Overrides:
      visit in class com.github.javaparser.ast.visitor.VoidVisitorAdapter<Object>
    • visit

      public void visit(com.github.javaparser.ast.body.EnumDeclaration n, Object ignore)
      Specified by:
      visit in interface com.github.javaparser.ast.visitor.VoidVisitor<Object>
      Overrides:
      visit in class com.github.javaparser.ast.visitor.VoidVisitorAdapter<Object>
    • visit

      public void visit(com.github.javaparser.ast.body.ClassOrInterfaceDeclaration n, Object ignore)
      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
      Specified by:
      visit in interface com.github.javaparser.ast.visitor.VoidVisitor<Object>
      Overrides:
      visit in class com.github.javaparser.ast.visitor.VoidVisitorAdapter<Object>
      Parameters:
      n - -
      ignore - -
    • visit

      public void visit(com.github.javaparser.ast.PackageDeclaration n, Object ignored)
      Specified by:
      visit in interface com.github.javaparser.ast.visitor.VoidVisitor<Object>
      Overrides:
      visit in class com.github.javaparser.ast.visitor.VoidVisitorAdapter<Object>
    • visit

      public void visit(com.github.javaparser.ast.body.ConstructorDeclaration n, Object ignored)
      Constructors - modify the 2 arg constructor - changing the args and the body
      Specified by:
      visit in interface com.github.javaparser.ast.visitor.VoidVisitor<Object>
      Overrides:
      visit in class com.github.javaparser.ast.visitor.VoidVisitorAdapter<Object>
      Parameters:
      n - - the constructor node
      ignored - -
    • visit

      public void visit(com.github.javaparser.ast.body.MethodDeclaration n, Object ignore)
      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
      Specified by:
      visit in interface com.github.javaparser.ast.visitor.VoidVisitor<Object>
      Overrides:
      visit in class com.github.javaparser.ast.visitor.VoidVisitorAdapter<Object>
    • visit

      public void visit(com.github.javaparser.ast.stmt.IfStmt n, Object ignore)
      Visitor for if stmts - removes feature missing test
      Specified by:
      visit in interface com.github.javaparser.ast.visitor.VoidVisitor<Object>
      Overrides:
      visit in class com.github.javaparser.ast.visitor.VoidVisitorAdapter<Object>
    • visit

      public void visit(com.github.javaparser.ast.expr.MethodCallExpr n, Object ignore)
      visitor for method calls
      Specified by:
      visit in interface com.github.javaparser.ast.visitor.VoidVisitor<Object>
      Overrides:
      visit in class com.github.javaparser.ast.visitor.VoidVisitorAdapter<Object>
    • visit

      public void visit(com.github.javaparser.ast.expr.FieldAccessExpr n, Object ignore)
      visitor for field access expressions - convert ((...type_Type)jcasType).casFeatCode_XXXX to _FI_xxx
      Specified by:
      visit in interface com.github.javaparser.ast.visitor.VoidVisitor<Object>
      Overrides:
      visit in class com.github.javaparser.ast.visitor.VoidVisitorAdapter<Object>
      Parameters:
      n - -
      ignore - -