InvariantConditionpublic class InvariantCondition extends Condition
Constructors Summary |
---|
public InvariantCondition(Class clazz, String condExpr, boolean isStatic)
super(condExpr, clazz, isStatic);
|
Methods Summary |
---|
public boolean | equals(java.lang.Object o)
if (o instanceof InvariantCondition)
{
return super.equals(o);
}
return false;
| public void | evaluateCondition(org.jboss.aop.joinpoint.Invocation inv, boolean staticCall, boolean constructor, java.lang.Object ret)
try
{
if (DesignByContractAspect.verbose) System.out.println("[dbc] Evaluate condition : '" + originalExpr + "' for class: " + clazz);
if (!isStatic && staticCall)
{
System.out.println("[dbc] Ignoring non-static invariant for static call");
return;
}
Interpreter interpreter = new Interpreter();
Object target = (constructor) ? ret : getTarget(inv, staticCall);
for (Iterator it = parameterLookup.keySet().iterator() ; it.hasNext() ; )
{
String bsname = (String)it.next();
String originalname = (String)parameterLookup.get(bsname);
if (originalname.equals(Condition.TARGET))
{
interpreter.set(bsname, target);
if (DesignByContractAspect.verbose) System.out.println("[dbc] Setting $" + originalname + " to " + target +" (type: " + target.getClass().getName() + ")");
}
else
{
System.out.println("INVARIANT CONDITION BROKEN: "+ originalExpr + " - " + clazz);
throw new RuntimeException("Invalid marker '" + originalname + "' in expression: " + originalExpr);
}
}
Boolean eval = (Boolean)interpreter.eval(condExpr);
if (!eval.booleanValue())
{
throw new RuntimeException("Invariant condition " + originalExpr + " was broken " + "for class: " + clazz);
}
}
catch (EvalError e)
{
throw new RuntimeException("There was an error in the expression: " + originalExpr, e);
}
|
|