in uimaj-v3migration-jcas/src/main/java/org/apache/uima/migratev3/jcas/MigrateJCas.java [1395:1535]
private void migrate(CommonConverted cc, Container container, Path path) {
if (null == cc) {
System.err.println("Skipping this component due to decompile failure: " + path.toString());
System.err.println(" in container: " + container);
isConvert2v3 = false;
error_decompiling = true;
return;
}
if (cc.v3Source != null) {
// next updates classname2multiSources for tracking non-identical defs
boolean identical = collectInfoForReports(cc);
assert identical;
psb.append("i");
flush(psb);
cc.containersAndV2Paths.add(new ContainerAndPath(path, container));
return;
}
assert cc.v2Source != null;
packageName = null;
className = null;
packageAndClassNameSlash = null;
cu = null;
String source = cc.v2Source;
isConvert2v3 = true; // preinit, set false if convert fails
isV2JCas = false; // preinit, set true by reportV2Class, called by visit to
// ClassOrInterfaceDeclaration,
// when it has v2 constructors, and the right type and type_index_id field
// declares
isBuiltinJCas = false;
featNames.clear();
fi_fields.clear();
try { // to reset the next 3 items
current_cc = cc;
current_container = container;
current_path = path;
// System.out.println("Migrating source before migration:\n");
// System.out.println(source);
// System.out.println("\n\n\n");
if (source.startsWith(ERROR_DECOMPILING)) {
System.err.println("Decompiling failed for class: " + cc.toString() + "\n got: "
+ Misc.elide(source, 300, false));
System.err.println("Please check the migrateClasspath");
if (null == migrateClasspath) {
System.err.println("classpath of this app is");
System.err.println(System.getProperty("java.class.path"));
} else {
System.err.println(" first part of migrateClasspath argument was: "
+ Misc.elide(migrateClasspath, 300, false));
System.err.println(" Value used was:");
URL[] urls = Misc.classpath2urls(migrateClasspath);
for (URL url : urls) {
System.err.println(" " + url.toString());
}
}
System.err.println("Skipping this component");
isConvert2v3 = false;
error_decompiling = true;
return;
}
StringReader sr = new StringReader(source);
try {
cu = JavaParser.parse(sr);
addImport("java.lang.invoke.CallSite");
addImport("java.lang.invoke.MethodHandle");
addImport("org.apache.uima.cas.impl.CASImpl");
addImport("org.apache.uima.cas.impl.TypeImpl");
addImport("org.apache.uima.cas.impl.TypeSystemImpl");
this.visit(cu, null); // side effect: sets the className, packageAndClassNameSlash,
// packageName
new removeEmptyStmts().visit(cu, null);
if (isConvert2v3) {
removeImport("org.apache.uima.jcas.cas.TOP_Type");
}
if (isConvert2v3 && fi_fields.size() > 0) {
NodeList<BodyDeclaration<?>> classMembers = cu.getTypes().get(0).getMembers();
int positionOfFirstConstructor = findConstructor(classMembers);
if (positionOfFirstConstructor < 0) {
throw new RuntimeException();
}
classMembers.addAll(positionOfFirstConstructor, fi_fields);
}
ImportDeclaration firstImport = cu.getImports().get(0);
String transformedMessage = String.format(
" Migrated by uimaj-v3-migration-jcas, %s%n" + " Container: %s%n"
+ " Path in container: %s%n",
new Date(), container.toString1(), path.toString()).replace('\\', '/');
Optional<Comment> existingComment = firstImport.getComment();
if (existingComment.isPresent()) {
Comment comment = existingComment.get();
comment.setContent(comment.getContent() + "\n" + transformedMessage);
} else {
firstImport.setBlockComment(transformedMessage);
}
if (isSource) {
sourceToCommonConverted.put(source, cc);
}
boolean identicalFound = collectInfoForReports(cc);
assert !identicalFound;
if (isV2JCas) {
writeV2Orig(cc, isConvert2v3);
}
if (isConvert2v3) {
cc.v3Source = new PrettyPrinter(printCu).print(cu);
writeV3(cc);
}
psb.append(isBuiltinJCas ? "b"
: (classname2multiSources.get(cc.fqcn_slash).size() == 1) ? "." : "d"); // means
// non-identical
// duplicate
flush(psb);
} catch (IOException e) {
e.printStackTrace();
throw new UIMARuntimeException(e);
} catch (Exception e) {
System.out.println("debug: exception caught, source was\n" + source);
throw new UIMARuntimeException(e);
}
} finally {
current_cc = null;
current_container = null;
current_path = null;
}
}