Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Move a method that was only used once

  • Loading branch information...
commit a81afbd4ea07f7164b2b67af3c4fc791d1cb8fbf 1 parent 29f5d28
@jdf authored
View
32 src/jycessing/build/PolymorphicMethod.java
@@ -104,8 +104,7 @@ private void append(final Signature signature, final StringBuilder sb) {
if (i > 0) {
sb.append(", ");
}
- sb.append(TypeUtil.asJavaExpression("args[" + i + "]", signature.getArgTypes().get(
- i)));
+ sb.append(asJavaExpression(signature, i));
}
sb.append(')');
if (signature.isVoid()) {
@@ -117,4 +116,33 @@ private void append(final Signature signature, final StringBuilder sb) {
sb.append('\n');
}
+ public static String asJavaExpression(final Signature signature, final int i) {
+ final String name = "args[" + i + "]";
+ final Class<?> javaType = signature.getArgTypes().get(i);
+ final StringBuilder sb = new StringBuilder();
+ if (javaType == float.class) {
+ sb.append("(float)").append(name).append(".asDouble()");
+ } else if (javaType == int.class) {
+ sb.append(name).append(".asInt()");
+ } else if (javaType == String.class) {
+ sb.append(name).append(".asString()");
+ } else if (javaType == char.class) {
+ sb.append(name).append(".asString().charAt(0)");
+ } else if (javaType == long.class) {
+ sb.append(name).append(".asLong()");
+ } else if (javaType == byte.class) {
+ sb.append("(byte)").append(name).append(".asInt()");
+ } else if (javaType == boolean.class) {
+ sb.append(name).append(".__nonzero__()");
+ } else if (javaType.isPrimitive()) {
+ throw new RuntimeException("You need a converter for " + javaType);
+ } else {
+ final String simpleName = javaType.isArray() ? javaType.getSimpleName() : javaType
+ .getName();
+ sb.append('(').append(simpleName).append(')').append(name).append(".__tojava__(")
+ .append(simpleName).append(".class)");
+ }
+ return sb.toString();
+ }
+
}
View
27 src/jycessing/build/TypeUtil.java
@@ -16,33 +16,6 @@
package jycessing.build;
public class TypeUtil {
- public static String asJavaExpression(final String name, final Class<?> javaType) {
- final StringBuilder sb = new StringBuilder();
- if (javaType == float.class) {
- sb.append("(float)").append(name).append(".asDouble()");
- } else if (javaType == int.class) {
- sb.append(name).append(".asInt()");
- } else if (javaType == String.class) {
- sb.append(name).append(".asString()");
- } else if (javaType == char.class) {
- sb.append(name).append(".asString().charAt(0)");
- } else if (javaType == long.class) {
- sb.append(name).append(".asLong()");
- } else if (javaType == byte.class) {
- sb.append("(byte)").append(name).append(".asInt()");
- } else if (javaType == boolean.class) {
- sb.append(name).append(".__nonzero__()");
- } else if (javaType.isPrimitive()) {
- throw new RuntimeException("You need a converter for " + javaType);
- } else {
- final String simpleName = javaType.isArray() ? javaType.getSimpleName() : javaType
- .getName();
- sb.append('(').append(simpleName).append(')').append(name).append(".__tojava__(")
- .append(simpleName).append(".class)");
- }
- return sb.toString();
- }
-
public static String pyConversionPrefix(final Class<?> k) {
if (k == float.class) {
return "new PyFloat(";
Please sign in to comment.
Something went wrong with that request. Please try again.