Allow for complicated result checks on primitive return types

Jonathan Bell [2012-04-11 16:43:37]
Allow for complicated result checks on primitive return types
Filename
Columbus2Tester/apt_generated/edu/columbia/cs/psl/metamorphic/example/ProcessorTester_tests.java
Columbus2Tester/lib/columbus2.jar
Columbus2Tester/src/edu/columbia/cs/psl/metamorphic/example/ProcessorTester.java
cloning/eclipse/BenchmarkCloner.launch
columbus2/jar-descriptor.jardesc
columbus2/src/edu/columbia/cs/psl/metamorphic/compiler/MetamorphicPropertyCompiler.java
diff --git a/Columbus2Tester/apt_generated/edu/columbia/cs/psl/metamorphic/example/ProcessorTester_tests.java b/Columbus2Tester/apt_generated/edu/columbia/cs/psl/metamorphic/example/ProcessorTester_tests.java
index ab6b99e..7dcd232 100644
--- a/Columbus2Tester/apt_generated/edu/columbia/cs/psl/metamorphic/example/ProcessorTester_tests.java
+++ b/Columbus2Tester/apt_generated/edu/columbia/cs/psl/metamorphic/example/ProcessorTester_tests.java
@@ -1,40 +1,40 @@
 package edu.columbia.cs.psl.metamorphic.example;
 public class ProcessorTester_tests {
 @SuppressWarnings("all")
-public static  int findClosestValue_0 ( int[] values,  Integer target, ProcessorTester ___object, java.lang.reflect.Method ___method) throws Exception {
-return (Integer) ___method.invoke(___object,new edu.columbia.cs.psl.metamorphic.inputProcessor.impl.MultiplyByNumericConstant().apply((Object) values, 10), target * 10);
+public static  java.lang.String pickFirstString_0 ( java.lang.String[] in, ProcessorTester ___object, java.lang.reflect.Method ___method) throws Exception {
+return (java.lang.String) ___method.invoke(___object,new edu.columbia.cs.psl.metamorphic.inputProcessor.impl.Shuffle().apply((Object) in));

 }
 @SuppressWarnings("all")
-public static  boolean findClosestValue_Check0 (int orig, int metamorphic, int[] values,  Integer target) {
-return metamorphic == orig * 10;
+public static  boolean pickFirstString_Check0 (java.lang.String orig, java.lang.String metamorphic, java.lang.String[] in) {
+if(orig == null && metamorphic != null) return false; if(orig == null && metamorphic == null) return true;return metamorphic.equals(orig);

 }@SuppressWarnings("all")
-public static  int findClosestValue_1 ( int[] values,  Integer target, ProcessorTester ___object, java.lang.reflect.Method ___method) throws Exception {
-return (Integer) ___method.invoke(___object,new edu.columbia.cs.psl.metamorphic.inputProcessor.impl.AddNumericConstant().apply((Object) values, 10), target + 10);
+public static  java.lang.String pickFirstString_1 ( java.lang.String[] in, ProcessorTester ___object, java.lang.reflect.Method ___method) throws Exception {
+return (java.lang.String) ___method.invoke(___object,new edu.columbia.cs.psl.metamorphic.inputProcessor.impl.Shuffle().apply((Object) in));

 }
 @SuppressWarnings("all")
-public static  boolean findClosestValue_Check1 (int orig, int metamorphic, int[] values,  Integer target) {
-return metamorphic == orig + 10;
+public static  boolean pickFirstString_Check1 (java.lang.String orig, java.lang.String metamorphic, java.lang.String[] in) {
+if(orig == null && metamorphic != null) return false; if(orig == null && metamorphic == null) return true;return metamorphic.equals(orig);

 }@SuppressWarnings("all")
-public static  java.lang.String pickFirstString_0 ( java.lang.String[] in, ProcessorTester ___object, java.lang.reflect.Method ___method) throws Exception {
-return (java.lang.String) ___method.invoke(___object,new edu.columbia.cs.psl.metamorphic.inputProcessor.impl.Shuffle().apply((Object) in));
+public static  int findClosestValue_0 ( int[] values,  Integer target, ProcessorTester ___object, java.lang.reflect.Method ___method) throws Exception {
+return (Integer) ___method.invoke(___object,new edu.columbia.cs.psl.metamorphic.inputProcessor.impl.MultiplyByNumericConstant().apply((Object) values, 10), target * 10);

 }
 @SuppressWarnings("all")
-public static  boolean pickFirstString_Check0 (java.lang.String orig, java.lang.String metamorphic, java.lang.String[] in) {
-if(orig == null && metamorphic != null) return false; if(orig == null && metamorphic == null) return true;return metamorphic.equals(orig);
+public static  boolean findClosestValue_Check0 (int orig, int metamorphic, int[] values,  Integer target) {
+return metamorphic == orig * 10;

 }@SuppressWarnings("all")
-public static  java.lang.String pickFirstString_1 ( java.lang.String[] in, ProcessorTester ___object, java.lang.reflect.Method ___method) throws Exception {
-return (java.lang.String) ___method.invoke(___object,new edu.columbia.cs.psl.metamorphic.inputProcessor.impl.Shuffle().apply((Object) in));
+public static  int findClosestValue_1 ( int[] values,  Integer target, ProcessorTester ___object, java.lang.reflect.Method ___method) throws Exception {
+return (Integer) ___method.invoke(___object,new edu.columbia.cs.psl.metamorphic.inputProcessor.impl.AddNumericConstant().apply((Object) values, 10), target + 10);

 }
 @SuppressWarnings("all")
-public static  boolean pickFirstString_Check1 (java.lang.String orig, java.lang.String metamorphic, java.lang.String[] in) {
-if(orig == null && metamorphic != null) return false; if(orig == null && metamorphic == null) return true;return metamorphic.equals(orig);
+public static  boolean findClosestValue_Check1 (int orig, int metamorphic, int[] values,  Integer target) {
+return metamorphic == orig + 10;

 }
 }
\ No newline at end of file
diff --git a/Columbus2Tester/lib/columbus2.jar b/Columbus2Tester/lib/columbus2.jar
index e7da3eb..83ff376 100644
Binary files a/Columbus2Tester/lib/columbus2.jar and b/Columbus2Tester/lib/columbus2.jar differ
diff --git a/Columbus2Tester/src/edu/columbia/cs/psl/metamorphic/example/ProcessorTester.java b/Columbus2Tester/src/edu/columbia/cs/psl/metamorphic/example/ProcessorTester.java
index 2ddd230..5f24d19 100644
--- a/Columbus2Tester/src/edu/columbia/cs/psl/metamorphic/example/ProcessorTester.java
+++ b/Columbus2Tester/src/edu/columbia/cs/psl/metamorphic/example/ProcessorTester.java
@@ -8,9 +8,9 @@ import edu.columbia.cs.psl.metamorphic.runtime.annotation.Rule;
 public class ProcessorTester {
     public static void main(String[] args) {
         ProcessorTester tester = new ProcessorTester();
-//        System.out.println(tester.findClosestValue(new int[] {1,2,3,1000, 10,1000,40000}, 3));
-        tester.cl.foo = "foobar";
-        System.out.println(tester.pickFirstString(new String[] {"a","b","c","b","c","b","c","b","c","b","c","b","c","b","c"}));
+        System.out.println(tester.findClosestValue(new int[] {1,2,3,1000, 10,1000,40000}, 3));
+//        tester.cl.foo = "foobar";
+//        System.out.println(tester.pickFirstString(new String[] {"a","b","c","b","c","b","c","b","c","b","c","b","c","b","c"}));
 //        SimpleExample ex2 = new SimpleExample();
 //        ex2.go(new String[] {"d"});
     }
@@ -39,8 +39,8 @@ public class ProcessorTester {
 	// this will give an error if the array is empty, but whatever... =)
 	return values[closestIndex];
   }
-    private String foo = "foo";
-    private AnotherClass cl = new AnotherClass();
+    private static String foo = "foo";
+    private static AnotherClass cl = new AnotherClass();
 //    private static String[] myStuff = new String[] {"d","e","f"};
 //    private static String[] myStuff_2 = new String[] {"d","e","f"};
     @Metamorphic(rules = {
@@ -50,11 +50,11 @@ public class ProcessorTester {
 	{
     	int childThread = AbstractInterceptor.getThreadChildId();
     	System.out.println("I'm in child " + childThread);
-    	System.out.println(childThread + " ()AnotherClass's foo:" + cl.foo);
-    	cl.foo = "asdf"+childThread;
-    	System.out.println(childThread + "AnotherClass's foo:" + cl.foo);
+    	System.out.println(childThread + " ()AnotherClass's foo:" + foo);
+    	foo = "asdf"+childThread;
+    	System.out.println(childThread + "AnotherClass's foo:" + foo);
     	for(int i = 0; i < 100;i++)
-    	System.out.println(childThread + "AnotherClass's foo:" + cl.foo);
+    	System.out.println(childThread + "AnotherClass's foo:" + foo);
     	return in[0];
 	}
 }
diff --git a/cloning/eclipse/BenchmarkCloner.launch b/cloning/eclipse/BenchmarkCloner.launch
index 9fe2664..4fa0028 100644
--- a/cloning/eclipse/BenchmarkCloner.launch
+++ b/cloning/eclipse/BenchmarkCloner.launch
@@ -1,10 +1,10 @@
 <?xml version="1.0" encoding="UTF-8" standalone="no"?>
 <launchConfiguration type="org.eclipse.jdt.launching.localJavaApplication">
 <listAttribute key="org.eclipse.debug.core.MAPPED_RESOURCE_PATHS">
-<listEntry value="/cloning/src/test/java/com/rits/tests/cloning/BenchmarkCloner.java"/>
+<listEntry value="/cloning"/>
 </listAttribute>
 <listAttribute key="org.eclipse.debug.core.MAPPED_RESOURCE_TYPES">
-<listEntry value="1"/>
+<listEntry value="4"/>
 </listAttribute>
 <stringAttribute key="org.eclipse.jdt.launching.CLASSPATH_PROVIDER" value="org.eclipse.m2e.launchconfig.classpathProvider"/>
 <stringAttribute key="org.eclipse.jdt.launching.MAIN_TYPE" value="com.rits.tests.cloning.BenchmarkCloner"/>
diff --git a/columbus2/jar-descriptor.jardesc b/columbus2/jar-descriptor.jardesc
index 9765a93..75e7e80 100644
--- a/columbus2/jar-descriptor.jardesc
+++ b/columbus2/jar-descriptor.jardesc
@@ -1,6 +1,6 @@
 <?xml version="1.0" encoding="MacRoman" standalone="no"?>
 <jardesc>
-    <jar path="Columbus2Tester/lib/columbus2.jar"/>
+    <jar path="columbus2-tester/lib/columbus2.jar"/>
     <options buildIfNeeded="true" compress="false" descriptionLocation="/columbus2-runtime/jar-descriptor.jardesc" exportErrors="true" exportWarnings="true" includeDirectoryEntries="true" overwrite="true" saveDescription="true" storeRefactorings="false" useSourceFolders="false"/>
     <storedRefactorings deprecationInfo="true" structuralOnly="false"/>
     <selectedProjects/>
diff --git a/columbus2/src/edu/columbia/cs/psl/metamorphic/compiler/MetamorphicPropertyCompiler.java b/columbus2/src/edu/columbia/cs/psl/metamorphic/compiler/MetamorphicPropertyCompiler.java
index 422f6be..d60f405 100644
--- a/columbus2/src/edu/columbia/cs/psl/metamorphic/compiler/MetamorphicPropertyCompiler.java
+++ b/columbus2/src/edu/columbia/cs/psl/metamorphic/compiler/MetamorphicPropertyCompiler.java
@@ -14,11 +14,14 @@ import javax.lang.model.element.ExecutableElement;
 import javax.lang.model.element.Modifier;
 import javax.lang.model.element.PackageElement;
 import javax.lang.model.element.VariableElement;
+import javax.lang.model.type.TypeKind;
 import javax.lang.model.type.TypeMirror;
 import javax.tools.Diagnostic;
 import javax.tools.DiagnosticCollector;
 import javax.tools.JavaFileObject;

+import org.objectweb.asm.Type;
+
 import edu.columbia.cs.psl.metamorphic.runtime.annotation.Metamorphic;
 import edu.columbia.cs.psl.metamorphic.runtime.annotation.Rule;

@@ -165,6 +168,17 @@ public class MetamorphicPropertyCompiler {
 	private String formatRuleCheck(ExecutableElement method, Rule rule, TypeMirror returnType, int ruleIndex) throws Exception {
 		String right = rule.check();

+		Pattern p = Pattern.compile("\\\\([^(]+)\\(");
+		Matcher m = p.matcher(right);
+		if(m.find())
+		{
+			right = (returnType.getKind().isPrimitive() ? getBoxedType(returnType.getKind()) + ".valueOf((" + getBoxedType(returnType.getKind()) + ")" : "" ) +
+					m.replaceAll("new edu.columbia.cs.psl.metamorphic.inputProcessor.impl.$1().apply((Object) " );
+			if(returnType.getKind().isPrimitive())
+				right =  right + ")";
+			m.reset(right);
+		}
+
 		right = right.replace("\\result", "orig");
 		if (rule.checkMethod().equals("==") || rule.checkMethod().equals(">=") || rule.checkMethod().equals("<=") || rule.checkMethod().equals("<")
 				|| rule.checkMethod().equals(">") || rule.checkMethod().equals("!=")) {
@@ -185,8 +199,26 @@ public class MetamorphicPropertyCompiler {
 				}
 			}
 		}
+
 		return right;
 	}
+	private String getBoxedType(TypeKind kind) {
+		if(kind == TypeKind.BOOLEAN)
+			return "Boolean";
+		else if(kind == TypeKind.BYTE)
+			return "Byte";
+		else if(kind == TypeKind.DOUBLE)
+			return "Double";
+		else if(kind == TypeKind.FLOAT)
+			return "Float";
+		else if(kind == TypeKind.INT)
+			return "Integer";
+		else if(kind == TypeKind.LONG)
+			return "Long";
+		else if(kind == TypeKind.SHORT)
+			return "Short";
+		return null;
+	}


 }