This is an automated email from the ASF dual-hosted git repository. rec pushed a commit to branch refactoring/228-Move-the-UimaDecompiler-class in repository https://gitbox.apache.org/repos/asf/uima-uimaj.git
commit 09e7d9e4e2d4bf6cf3fdc15b55fa7f8d3b83939c Author: Richard Eckart de Castilho <[email protected]> AuthorDate: Thu Jul 28 12:15:55 2022 +0200 #228 - Move the UimaDecompiler class - Move the decompiler class - Remove dependencies of uimaj-core that were only required by the decompiler - Add these dependencies to uimaj-v3migration-jcas --- uimaj-core/pom.xml | 14 --- uimaj-v3migration-jcas/pom.xml | 21 ++-- .../apache/uima/migratev3/jcas/MigrateJCas.java | 110 ++++++++++++--------- .../uima/migratev3/jcas}/UimaDecompiler.java | 2 +- 4 files changed, 74 insertions(+), 73 deletions(-) diff --git a/uimaj-core/pom.xml b/uimaj-core/pom.xml index 6d2652205..8bac476c4 100644 --- a/uimaj-core/pom.xml +++ b/uimaj-core/pom.xml @@ -184,20 +184,6 @@ </dependency> --> - <!-- needed for UimaDecompiler class--> - <dependency> <!-- Apache v2 license 2016 checked --> - <groupId>org.bitbucket.mstrobel</groupId> - <artifactId>procyon-compilertools</artifactId> - <version>0.5.32</version> - </dependency> - - <!-- Apache v2 license 2016 checked. Also transitive include from above, - listed here so that binary assembly for distribution includes the jar --> - <dependency> - <groupId>org.bitbucket.mstrobel</groupId> - <artifactId>procyon-core</artifactId> - <version>0.5.32</version> - </dependency> <!-- for reading / transforming / generating JCas cover classes --> <!-- <dependency> diff --git a/uimaj-v3migration-jcas/pom.xml b/uimaj-v3migration-jcas/pom.xml index 3e81c1c3f..4ccdd4cad 100644 --- a/uimaj-v3migration-jcas/pom.xml +++ b/uimaj-v3migration-jcas/pom.xml @@ -53,25 +53,20 @@ <version>3.2.2</version> <!-- latest as of May 2017 --> </dependency> -<!-- <dependency> is included from uimaj-core, not needed for this project + <!-- needed for UimaDecompiler class--> + <dependency> <!-- Apache v2 license 2016 checked --> <groupId>org.bitbucket.mstrobel</groupId> <artifactId>procyon-compilertools</artifactId> <version>0.5.32</version> </dependency> - --> - <!-- for reading / transforming / generating JCas cover classes --> -<!-- <dependency> - <groupId>org.ow2.asm</groupId> - <artifactId>asm</artifactId> - <version>5.0.4</version> - </dependency> - + + <!-- Apache v2 license 2016 checked. Also transitive include from above, + listed here so that binary assembly for distribution includes the jar --> <dependency> - <groupId>org.ow2.asm</groupId> - <artifactId>asm-tree</artifactId> - <version>5.0.4</version> + <groupId>org.bitbucket.mstrobel</groupId> + <artifactId>procyon-core</artifactId> + <version>0.5.32</version> </dependency> - --> </dependencies> <build> diff --git a/uimaj-v3migration-jcas/src/main/java/org/apache/uima/migratev3/jcas/MigrateJCas.java b/uimaj-v3migration-jcas/src/main/java/org/apache/uima/migratev3/jcas/MigrateJCas.java index 99d5ae45a..c460b3f51 100644 --- a/uimaj-v3migration-jcas/src/main/java/org/apache/uima/migratev3/jcas/MigrateJCas.java +++ b/uimaj-v3migration-jcas/src/main/java/org/apache/uima/migratev3/jcas/MigrateJCas.java @@ -65,7 +65,6 @@ import javax.tools.ToolProvider; import org.apache.uima.UIMARuntimeException; import org.apache.uima.cas.impl.TypeImpl; import org.apache.uima.cas.impl.TypeSystemImpl; -import org.apache.uima.cas.impl.UimaDecompiler; import org.apache.uima.internal.util.CommandLineParser; import org.apache.uima.internal.util.Misc; import org.apache.uima.internal.util.UIMAClassLoader; @@ -354,9 +353,9 @@ public class MigrateJCas extends VoidVisitorAdapter<Object> { this.parent = parent; if (parent != null) { parent.subContainers.add(this); - this.pearClasspath = parent.pearClasspath; // default, when expanding Jars. + pearClasspath = parent.pearClasspath; // default, when expanding Jars. } - this.rootOrig = root; + rootOrig = root; String s = root.toString().toLowerCase(); isJar = s.endsWith(".jar"); isPear = s.endsWith(".pear"); @@ -392,7 +391,7 @@ public class MigrateJCas extends VoidVisitorAdapter<Object> { false); String newClasspath = ip.buildComponentClassPath(); String parentClasspath = parent.pearClasspath; - this.pearClasspath = (null == parentClasspath || 0 == parentClasspath.length()) + pearClasspath = (null == parentClasspath || 0 == parentClasspath.length()) ? newClasspath : newClasspath + File.pathSeparator + parentClasspath; } @@ -458,15 +457,19 @@ public class MigrateJCas extends VoidVisitorAdapter<Object> { */ @Override public boolean equals(Object obj) { - if (this == obj) - return true; - if (obj == null) - return false; - if (getClass() != obj.getClass()) - return false; + if (this == obj) { + return true; + } + if (obj == null) { + return false; + } + if (getClass() != obj.getClass()) { + return false; + } Container other = (Container) obj; - if (id != other.id) - return false; + if (id != other.id) { + return false; + } return true; } @@ -681,7 +684,7 @@ public class MigrateJCas extends VoidVisitorAdapter<Object> { CommonConverted(String origSource, byte[] v2ByteCode, Path path, Container container, String fqcn_slash) { - this.v2Source = origSource; + v2Source = origSource; this.v2ByteCode = v2ByteCode; containersAndV2Paths.add(new ContainerAndPath(path, container)); this.fqcn_slash = fqcn_slash; @@ -707,7 +710,7 @@ public class MigrateJCas extends VoidVisitorAdapter<Object> { if (id < 0) { Integer nextId = nextCcId.computeIfAbsent(fqcn_slash, s -> INTEGER0); nextCcId.put(fqcn_slash, nextId + 1); - this.id = nextId; + id = nextId; } return id; } @@ -914,8 +917,9 @@ public class MigrateJCas extends VoidVisitorAdapter<Object> { try { // copy the pear or jar so we don't change the original Path lastPartOfPath = container.rootOrig.getFileName(); - if (null == lastPartOfPath) - throw new RuntimeException("Internal Error"); + if (null == lastPartOfPath) { + throw new RuntimeException("Internal Error"); + } Path pearOrJarCopy = Paths.get(outputDirectory, container.isJar ? "jars" : "pears", Integer.toString(container.id), lastPartOfPath.toString()); @@ -1028,7 +1032,9 @@ public class MigrateJCas extends VoidVisitorAdapter<Object> { boolean isEmpty = true; for (CommonConverted cc : container.convertedItems) { if (cc.v3SourcePath == null) - continue; // skip items that failed migration + { + continue; // skip items that failed migration + } isEmpty = false; // relativePathInContainer = the whole path with the first part (up to the end of the // container root) stripped off @@ -1723,14 +1729,17 @@ public class MigrateJCas extends VoidVisitorAdapter<Object> { && Character.isUpperCase(name.charAt(3)) && !name.equals("getTypeIndexID")) { List<Parameter> ps = n.getParameters(); if (isGetter) { - if (ps.size() > 1) - break; + if (ps.size() > 1) { + break; + } } else { // is setter - if (ps.size() > 2 || ps.size() == 0) - break; + if (ps.size() > 2 || ps.size() == 0) { + break; + } if (ps.size() == 2) { - if (!getParmTypeName(ps, 0).equals("int")) - break; + if (!getParmTypeName(ps, 0).equals("int")) { + break; + } isArraySetter = true; } } @@ -1738,8 +1747,9 @@ public class MigrateJCas extends VoidVisitorAdapter<Object> { // get the range-part-name and convert to v3 range ("Ref" changes to "Feature") String bodyString = n.getBody().get().toString(printWithoutComments); int i = bodyString.indexOf("jcasType.ll_cas.ll_"); - if (i < 0) - break; + if (i < 0) { + break; + } String s = bodyString.substring(i + "jcasType.ll_cas.ll_get".length()); // also for // ...ll_set - same // length! @@ -1907,8 +1917,9 @@ public class MigrateJCas extends VoidVisitorAdapter<Object> { NodeList<Expression> args; do { - if (get_set_method == null) - break; + if (get_set_method == null) { + break; + } /** remove checkArraybounds statement **/ if (n.getNameAsString().equals("checkArrayBounds") @@ -1925,8 +1936,9 @@ public class MigrateJCas extends VoidVisitorAdapter<Object> { if (n.getNameAsString() .startsWith("ll_" + (useGetter ? "get" : "set") + rangeNameV2Part + "Value")) { args = n.getArguments(); - if (args.size() != (useGetter ? 2 : 3)) - break; + if (args.size() != (useGetter ? 2 : 3)) { + break; + } String suffix = useGetter ? "Nc" : rangeNamePart.equals("Feature") ? "NcWj" : "Nfc"; String methodName = "_" + (useGetter ? "get" : "set") + rangeNamePart + "Value" + suffix; args.remove(0); // remove the old addr arg @@ -1942,10 +1954,12 @@ public class MigrateJCas extends VoidVisitorAdapter<Object> { String s = nname.substring(z.length()); s = s.substring(0, s.length() - "Value".length()); // s = "ShortArray", etc. - if (s.equals("RefArray")) - s = "FSArray"; - if (s.equals("IntArray")) - s = "IntegerArray"; + if (s.equals("RefArray")) { + s = "FSArray"; + } + if (s.equals("IntArray")) { + s = "IntegerArray"; + } EnclosedExpr ee = new EnclosedExpr( new CastExpr(new ClassOrInterfaceType(s), n.getArguments().get(0))); @@ -2200,8 +2214,9 @@ public class MigrateJCas extends VoidVisitorAdapter<Object> { reportPathWorkaround(parent.toString(), p2.toString()); Path lastPartOfPath = p.getFileName(); - if (null == lastPartOfPath) - throw new RuntimeException(); + if (null == lastPartOfPath) { + throw new RuntimeException(); + } return Paths.get(p2.toString(), lastPartOfPath.toString()); } return p; @@ -2240,8 +2255,9 @@ public class MigrateJCas extends VoidVisitorAdapter<Object> { return true; } System.out.println("\n" + title); - for (int i = 0; i < title.length(); i++) - System.out.print('='); + for (int i = 0; i < title.length(); i++) { + System.out.print('='); + } System.out.println(""); try (BufferedWriter bw = Files.newBufferedWriter(makePath(outDirLog + fileName), @@ -2758,8 +2774,9 @@ public class MigrateJCas extends VoidVisitorAdapter<Object> { } else if (parent instanceof ObjectCreationExpr) { List<Expression> args = ((ObjectCreationExpr) parent).getArguments(); int i = args.indexOf(n); - if (i < 0) - throw new RuntimeException(); + if (i < 0) { + throw new RuntimeException(); + } args.set(i, v); } else { System.out.println(parent.getClass().getName()); @@ -2815,10 +2832,12 @@ public class MigrateJCas extends VoidVisitorAdapter<Object> { for (VariableDeclarator vd : vds) { if (vd.getType().equals(intType)) { String n = vd.getNameAsString(); - if (n.equals("type")) - hasType = true; - if (n.equals("typeIndexID")) - hasTypeId = true; + if (n.equals("type")) { + hasType = true; + } + if (n.equals("typeIndexID")) { + hasTypeId = true; + } if (hasTypeId && hasType) { return true; } @@ -2854,8 +2873,9 @@ public class MigrateJCas extends VoidVisitorAdapter<Object> { for (BodyDeclaration<?> bd : members) { if (bd instanceof ConstructorDeclaration) { List<Parameter> ps = ((ConstructorDeclaration) bd).getParameters(); - if (ps.size() == 0) - has0ArgConstructor = true; + if (ps.size() == 0) { + has0ArgConstructor = true; + } if (ps.size() == 1 && getParmTypeName(ps, 0).equals("JCas")) { has1ArgJCasConstructor = true; } diff --git a/uimaj-core/src/main/java/org/apache/uima/cas/impl/UimaDecompiler.java b/uimaj-v3migration-jcas/src/main/java/org/apache/uima/migratev3/jcas/UimaDecompiler.java similarity index 99% rename from uimaj-core/src/main/java/org/apache/uima/cas/impl/UimaDecompiler.java rename to uimaj-v3migration-jcas/src/main/java/org/apache/uima/migratev3/jcas/UimaDecompiler.java index e422616cf..2ea2aeb75 100644 --- a/uimaj-core/src/main/java/org/apache/uima/cas/impl/UimaDecompiler.java +++ b/uimaj-v3migration-jcas/src/main/java/org/apache/uima/migratev3/jcas/UimaDecompiler.java @@ -16,7 +16,7 @@ * specific language governing permissions and limitations * under the License. */ -package org.apache.uima.cas.impl; +package org.apache.uima.migratev3.jcas; import java.io.BufferedWriter; import java.io.ByteArrayOutputStream;
