Skip to content

Commit

Permalink
#228 - Move the UimaDecompiler class
Browse files Browse the repository at this point in the history
- Move the decompiler class
- Remove dependencies of uimaj-core that were only required by the decompiler
- Add these dependencies to uimaj-v3migration-jcas
  • Loading branch information
reckart committed Jul 28, 2022
1 parent a79b9ab commit 09e7d9e
Show file tree
Hide file tree
Showing 4 changed files with 74 additions and 73 deletions.
14 changes: 0 additions & 14 deletions uimaj-core/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand Down
21 changes: 8 additions & 13 deletions uimaj-v3migration-jcas/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,6 @@
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;
Expand Down Expand Up @@ -354,9 +353,9 @@ private static class Container implements Comparable<Container> {
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");
Expand Down Expand Up @@ -392,7 +391,7 @@ private Path installJarOrPear() {
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;
}
Expand Down Expand Up @@ -458,15 +457,19 @@ public int hashCode() {
*/
@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;
}

Expand Down Expand Up @@ -681,7 +684,7 @@ private class CommonConverted {

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;
Expand All @@ -707,7 +710,7 @@ int getId() {
if (id < 0) {
Integer nextId = nextCcId.computeIfAbsent(fqcn_slash, s -> INTEGER0);
nextCcId.put(fqcn_slash, nextId + 1);
this.id = nextId;
id = nextId;
}
return id;
}
Expand Down Expand Up @@ -914,8 +917,9 @@ private void postProcessPearOrJar(Container container) {
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());

Expand Down Expand Up @@ -1028,7 +1032,9 @@ private boolean compileV3SourcesCommon2(Container container) {
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
Expand Down Expand Up @@ -1723,23 +1729,27 @@ public void visit(MethodDeclaration n, Object ignore) {
&& 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;
}
}

// 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!
Expand Down Expand Up @@ -1907,8 +1917,9 @@ public void visit(MethodCallExpr n, Object ignore) {
NodeList<Expression> args;

do {
if (get_set_method == null)
break;
if (get_set_method == null) {
break;
}

/** remove checkArraybounds statement **/
if (n.getNameAsString().equals("checkArrayBounds")
Expand All @@ -1925,8 +1936,9 @@ public void visit(MethodCallExpr n, Object ignore) {
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
Expand All @@ -1942,10 +1954,12 @@ public void visit(MethodCallExpr n, Object ignore) {

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)));

Expand Down Expand Up @@ -2200,8 +2214,9 @@ private Path makePath(String name) throws IOException {

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;
Expand Down Expand Up @@ -2240,8 +2255,9 @@ private <T, U> boolean reportPaths(String title, String fileName,
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),
Expand Down Expand Up @@ -2758,8 +2774,9 @@ private Node replaceInParent(Node n, Expression v) {
} 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());
Expand Down Expand Up @@ -2815,10 +2832,12 @@ private boolean hasTypeFields(NodeList<BodyDeclaration<?>> members) {
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;
}
Expand Down Expand Up @@ -2854,8 +2873,9 @@ private void setHasJCasConstructors(NodeList<BodyDeclaration<?>> members) {
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;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit 09e7d9e

Please sign in to comment.