[ductilej] 3 new revisions pushed by samskivert on 2010-07-11 01:49 GMT

2 views
Skip to first unread message

duct...@googlecode.com

unread,
Jul 10, 2010, 9:49:50 PM7/10/10
to ductil...@googlegroups.com
3 new revisions:

Revision: e41581e7dd
Author: Michael Bayne <m...@samskivert.com>
Date: Sat Jul 10 18:02:42 2010
Log: This test now works.
http://code.google.com/p/ductilej/source/detail?r=e41581e7dd

Revision: 8d6fa7ad75
Author: Michael Bayne <m...@samskivert.com>
Date: Sat Jul 10 18:20:08 2010
Log: Completely avoid detyping constructors of classes that extend...
http://code.google.com/p/ductilej/source/detail?r=8d6fa7ad75

Revision: 963fdd2dfa
Author: Michael Bayne <m...@samskivert.com>
Date: Sat Jul 10 18:49:11 2010
Log: Turns out there are other forms that TestCase constructors can take
(t...
http://code.google.com/p/ductilej/source/detail?r=963fdd2dfa

==============================================================================
Revision: e41581e7dd
Author: Michael Bayne <m...@samskivert.com>
Date: Sat Jul 10 18:02:42 2010
Log: This test now works.
http://code.google.com/p/ductilej/source/detail?r=e41581e7dd

Modified:
/src/org/ductilej/tests/SuperCallTest.java

=======================================
--- /src/org/ductilej/tests/SuperCallTest.java Tue Mar 23 14:03:26 2010
+++ /src/org/ductilej/tests/SuperCallTest.java Sat Jul 10 18:02:42 2010
@@ -55,7 +55,7 @@
public static class StringList extends ArrayList<String>
{
public StringList (Collection<String> values) {
- super(values); // TODO: picks the wrong static overload
+ super(values);
}
}

@@ -81,8 +81,8 @@

assertEquals("Because me", b.why("me"));

-// StringList slist = new
StringList(Collections.singleton("Hello"));
-// assertEquals(slist.get(0), "Hello");
+ StringList slist = new StringList(Collections.singleton("Hello"));
+ assertEquals(slist.get(0), "Hello");

TestButton button = new TestButton("test");
assertEquals(button.getLabel(), "test");

==============================================================================
Revision: 8d6fa7ad75
Author: Michael Bayne <m...@samskivert.com>
Date: Sat Jul 10 18:20:08 2010
Log: Completely avoid detyping constructors of classes that extend
junit.framework.TestCase. This is a hack to work around the fact that JUnit
expects such classes to have either a zero-argument constructor or a
constructor that takes a single string argument (which becomes broken if
detyped).

I would treat such constructors as library methods and detype their bodies,
but
that introduces substantial complexity because we cannot insert detyped
shadow
arguments before the call to super() which means that we would need to go in
and rewrite all instances of constructor arguments in any expressions inside
super() to their $T versions, which seems like a lot more trouble than it's
worth for this simple hack. So instead we just avoid detyping the
constructors
entirely. Since the JUnit test case constructors that we're not detyping
almost
invariably consist only of a call to "super(name)", this is not much of a
problem.
http://code.google.com/p/ductilej/source/detail?r=8d6fa7ad75

Added:
/src/org/ductilej/tests/OldJUnitTest.java
Modified:
/src/org/ductilej/detyper/Detype.java

=======================================
--- /dev/null
+++ /src/org/ductilej/tests/OldJUnitTest.java Sat Jul 10 18:20:08 2010
@@ -0,0 +1,27 @@
+//
+// $Id$
+
+package org.ductilej.tests;
+
+import junit.framework.TestCase;
+import junit.framework.TestSuite;
+
+/**
+ * Tests special handling for JUnit 3 test cases.
+ */
+public class OldJUnitTest extends TestCase
+{
+ public static TestSuite suite () {
+ return new TestSuite(OldJUnitTest.class);
+ }
+
+ // we need to make sure that this ctor is not detyped
+ public OldJUnitTest (String name) {
+ super(name);
+ }
+
+ // if this method gets called at all, things are working
+ public void testTest () {
+ assertEquals(1+1, 2);
+ }
+}
=======================================
--- /src/org/ductilej/detyper/Detype.java Sat Jul 10 11:48:44 2010
+++ /src/org/ductilej/detyper/Detype.java Sat Jul 10 18:20:08 2010
@@ -226,6 +226,13 @@
tree.sym = new MethodSymbol(0, tree.name, msig,
enclScope.owner);
// tree.sym.flags_field = chk.checkFlags(tree.pos(),
tree.mods.flags, m, tree);
}
+
+ // in very limited circumstances (currently only for JUnit
TestCase constructors) we leave
+ // things completely intact (detyping neither the arguments nor
the method body)
+ if (isUndetypableMethod(tree)) {
+ result = tree;
+ return;
+ }

// create a local environment for this method definition
Env<DetypeContext> oenv = _env;
@@ -269,7 +276,7 @@
// value carrying arguments for use in the method body:
// void someLibMethod (String arg1, int arg2) { ... } becomes
// void someLibMethod (String arg1$T, int arg2$T) {
- // Object arg1 = arg1$T, argg2 = arg2$T; ... }
+ // Object arg1 = arg1$T, arg2 = arg2$T; ... }
} else if (!tree.params.isEmpty() && tree.body != null) {
// we'll never have to insert shadow arguments into a
constructor because a constructor
// is never a library signature overrider; this it will always
be safe to jam
@@ -1133,17 +1140,15 @@
Name mname = _env.enclMethod.getName();
int pcount = _env.enclMethod.params.size();
if (mname == _readObjectName && pcount == 1) {
- return
String.valueOf(_env.enclMethod.params.head.sym.type).equals(
- "java.io.ObjectInputStream");
+ return
String.valueOf(_env.enclMethod.params.head.sym.type).equals(OIN_STREAM);

} else if (mname == _writeObjectName && pcount == 1) {
- return
String.valueOf(_env.enclMethod.params.head.sym.type).equals(
- "java.io.ObjectOutputStream");
+ return
String.valueOf(_env.enclMethod.params.head.sym.type).equals(OOUT_STREAM);

// "public static void main (String[] args)" must also remain
undetyped
} else if (mname == _mainName && pcount == 1) {
return (_env.enclMethod.sym.flags() & PUBSTATIC) == PUBSTATIC
&&
-
String.valueOf(_env.enclMethod.params.head.sym.type).equals("java.lang.String[]");
+
String.valueOf(_env.enclMethod.params.head.sym.type).equals(STRING_ARRAY);
}

// other serialization methods exist: readObjectNoData,
readReplace, writeReplace,
@@ -1202,6 +1207,19 @@
return false;
}
}
+
+ protected boolean isUndetypableMethod (JCMethodDecl meth)
+ {
+ Name mname = meth.getName();
+
+ // avoid detyping constructors of classes that extend
junit.framework.TestCase
+ if (mname == _names.init &&
+
String.valueOf(_env.enclClass.sym.getSuperclass()).equals(JUNIT_TESTCASE)) {
+ return true;
+ }
+
+ return false;
+ }

protected JCMethodInvocation unop (int pos, Tree.Kind op, JCExpression
arg)
{
@@ -1652,6 +1670,12 @@

protected static final int PUBSTATIC = Flags.PUBLIC | Flags.STATIC;

+ // some type names needed by inLibraryOverrider()
+ protected static final String OIN_STREAM = "java.io.ObjectInputStream";
+ protected static final String OOUT_STREAM
= "java.io.ObjectOutputStream";
+ protected static final String STRING_ARRAY = "java.lang.String[]";
+ protected static final String JUNIT_TESTCASE
= "junit.framework.TestCase";
+
// whether definite assignment relaxation is enabled
protected static final boolean RELAX_DEFASSIGN = true;
}

==============================================================================
Revision: 963fdd2dfa
Author: Michael Bayne <m...@samskivert.com>
Date: Sat Jul 10 18:49:11 2010
Log: Turns out there are other forms that TestCase constructors can take
(though in
such cases the test cases must be explicitly instantiated by other test
cases).
So we need to avoid our special casery for any TestCase constructor that
does
not take a single String argument.
http://code.google.com/p/ductilej/source/detail?r=963fdd2dfa

Modified:
/src/org/ductilej/detyper/Detype.java

=======================================
--- /src/org/ductilej/detyper/Detype.java Sat Jul 10 18:20:08 2010
+++ /src/org/ductilej/detyper/Detype.java Sat Jul 10 18:49:11 2010
@@ -1211,10 +1211,13 @@
protected boolean isUndetypableMethod (JCMethodDecl meth)
{
Name mname = meth.getName();
-
- // avoid detyping constructors of classes that extend
junit.framework.TestCase
- if (mname == _names.init &&
-
String.valueOf(_env.enclClass.sym.getSuperclass()).equals(JUNIT_TESTCASE)) {
+ int pcount = meth.params.size();
+
+ // avoid detyping constructors of classes that extend
junit.framework.TestCase that take a
+ // single String argument
+ if (mname == _names.init && pcount == 1 &&
+
String.valueOf(_env.enclClass.sym.getSuperclass()).equals(JUNIT_TESTCASE) &&
+ String.valueOf(meth.params.head.vartype).equals("String")) {
return true;
}

@@ -1670,10 +1673,12 @@

protected static final int PUBSTATIC = Flags.PUBLIC | Flags.STATIC;

- // some type names needed by inLibraryOverrider()
+ // type names needed by inLibraryOverrider()
protected static final String OIN_STREAM = "java.io.ObjectInputStream";
protected static final String OOUT_STREAM
= "java.io.ObjectOutputStream";
protected static final String STRING_ARRAY = "java.lang.String[]";
+
+ // type names needed by isUndetypableMethod()
protected static final String JUNIT_TESTCASE
= "junit.framework.TestCase";

// whether definite assignment relaxation is enabled

Reply all
Reply to author
Forward
0 new messages