Skip to content

Commit 0b7f984

Browse files
author
pakruse
committed
Added support for JSR14 versions 2.4 or later in the interactions pane and added support for assert statements. Fixed the fixparser script as well.
git-svn-id: file:///tmp/test-svn/trunk@2738 fe72c1cf-3628-48e9-8b72-1c46755d3cff
1 parent b5c763b commit 0b7f984

11 files changed

Lines changed: 1705 additions & 1437 deletions

File tree

dynamicjava/src/koala/Version.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@
5353
* This file is copied to Version.java by the build process, which also
5454
* fills in the right values of the date and time.
5555
*
56-
* This javadoc corresponds to build drjava-20040908-2043;
56+
* This javadoc corresponds to build drjava-20041025-2018;
5757
*
5858
* @version $Id$
5959
*/
@@ -62,7 +62,7 @@ public abstract class Version {
6262
* This string will be automatically expanded upon "ant commit".
6363
* Do not edit it by hand!
6464
*/
65-
private static final String BUILD_TIME_STRING = "20040908-2043";
65+
private static final String BUILD_TIME_STRING = "20041025-2018";
6666

6767
/** A {@link Date} version of the build time. */
6868
private static final Date BUILD_TIME = _getBuildDate();

dynamicjava/src/koala/dynamicjava/interpreter/AbstractTypeChecker.java

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -476,6 +476,34 @@ public Class<?> visit(IfThenElseStatement node) {
476476
return null;
477477
}
478478

479+
/**
480+
* Visits an AssertStatement
481+
* @param node the node to visit
482+
*/
483+
public Class<?> visit(AssertStatement node) {
484+
Expression cond = node.getCondition();
485+
486+
//Check the condition
487+
Class<?> type = cond.acceptVisitor(this);
488+
if(type != boolean.class && type != Boolean.class) {
489+
throw new ExecutionError("condition.type", node);
490+
}
491+
492+
// Auto unbox; Boolean->boolean
493+
if(type == Boolean.class) {
494+
//add method call on expression;
495+
// "cond.booleanValue();"
496+
node.setCondition(_unbox(cond, type));
497+
}
498+
499+
//Check the failure string
500+
Expression failString = node.getFailString();
501+
if(failString != null) {
502+
Class<?> type2 = failString.acceptVisitor(this);
503+
}
504+
return null;
505+
}
506+
479507
/**
480508
* Visits a SynchronizedStatement
481509
* @param node the node to visit

dynamicjava/src/koala/dynamicjava/interpreter/EvaluationVisitor.java

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -706,6 +706,22 @@ public Object visit(IfThenElseStatement node) {
706706
return null;
707707
}
708708

709+
/**
710+
* Visits an AssertStatement
711+
* @param node the node to visit
712+
*/
713+
public Object visit(AssertStatement node) {
714+
if (! (((Boolean)node.getCondition().acceptVisitor(this)).booleanValue())) {
715+
String toThrow = "";
716+
Expression n = node.getFailString();
717+
if(n != null) {
718+
toThrow = n.acceptVisitor(this).toString();
719+
}
720+
throw new AssertionError(toThrow);
721+
}
722+
return null;
723+
}
724+
709725
/**
710726
* Visits a BlockStatement
711727
* @param node the node to visit

dynamicjava/src/koala/dynamicjava/interpreter/EvaluationVisitorTest.java

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -462,4 +462,69 @@ public void testInnerClassScoping() {
462462

463463
}
464464

465+
//Assert tests
466+
public void testSimpleTopLevelAssert() {
467+
testString = "assert(true);";
468+
469+
interpret(testString);
470+
471+
testString = "assert(false);";
472+
try {
473+
interpret(testString);
474+
fail("Assertion should have failed");
475+
}
476+
catch(AssertionError e) {
477+
//Expected
478+
}
479+
480+
testString = "boolean bool = true;\n"+
481+
"boolean c = false;\n"+
482+
"assert(bool);";
483+
interpret(testString);
484+
485+
testString = "assert(c);";
486+
try {
487+
interpret(testString);
488+
fail("Assertion should have failed");
489+
}
490+
catch(AssertionError e) {
491+
//Expected
492+
}
493+
}
494+
495+
public void testAutoBoxAssert() {
496+
testString = "Boolean bool = true;\n"+
497+
"Boolean c = false;\n"+
498+
"assert(bool);";
499+
interpret(testString);
500+
501+
testString = "assert(c);";
502+
try{
503+
interpret(testString);
504+
fail("Assertion should have failed");
505+
}
506+
catch(AssertionError e) {
507+
//Expected
508+
}
509+
}
510+
511+
public void testExpressionAssert() {
512+
testString = "assert( true || false );";
513+
interpret(testString);
514+
515+
516+
testString = "assert true || false \n";
517+
interpret(testString);
518+
}
519+
520+
public void testMessagePassedWithAssert() {
521+
testString = "assert(false) : \"this message was passed\";";
522+
try{
523+
interpret(testString);
524+
fail("Assertion should have failed");
525+
}
526+
catch(AssertionError e) {
527+
assertEquals(e.getMessage(),"this message was passed");
528+
}
529+
}
465530
}

dynamicjava/src/koala/dynamicjava/interpreter/NameVisitor.java

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -433,6 +433,29 @@ public Node visit(IfThenElseStatement node) {
433433
}
434434
return null;
435435
}
436+
437+
/**
438+
* Visits an AssertStatement
439+
* @param node the node to visit
440+
*/
441+
public Node visit(AssertStatement node) {
442+
//Visits the components of this node
443+
Node n = node.getCondition();
444+
Node o = n.acceptVisitor(this);
445+
if(o != null) {
446+
rejectReferenceType(o,n);
447+
node.setCondition((Expression)o);
448+
}
449+
450+
n = node.getFailString();
451+
if(n != null) {
452+
o = n.acceptVisitor(this);
453+
if(o != null) {
454+
node.setFailString((Expression)o);
455+
}
456+
}
457+
return null;
458+
}
436459

437460
/**
438461
* Visits a VariableDeclaration

0 commit comments

Comments
 (0)