Methods Summary |
---|
private static void | addMethodConditions(java.lang.reflect.Method realMethod, java.lang.reflect.Method currentMethod, java.util.ArrayList preConds, java.util.ArrayList postConds)
PreCond pre = (PreCond)AnnotationElement.getAnyAnnotation(currentMethod, PreCond.class);
if (pre != null)
{
if (DesignByContractAspect.verbose) System.out.println("[dbc] Found preconditions in method: " + currentMethod);
addMethodConditions(realMethod, preConds, pre.value());
}
PostCond post = (PostCond)AnnotationElement.getAnyAnnotation(currentMethod, PostCond.class);
if (post != null)
{
if (DesignByContractAspect.verbose) System.out.println("[dbc] Found postconditions in method: " + currentMethod);
addMethodConditions(realMethod, postConds, post.value());
}
|
private static java.util.ArrayList | addMethodConditions(java.lang.reflect.Method realMethod, java.util.ArrayList conditions, java.lang.String[] exprs)
if (exprs == null)
{
return conditions;
}
boolean staticCall = Modifier.isStatic(realMethod.getModifiers());
for (int i = 0 ; i < exprs.length ; i++)
{
conditions.add(new MethodCondition(realMethod, exprs[i], staticCall));
}
return conditions;
|
private static void | addMethodConditionsForInterfaces(java.util.ArrayList preConds, java.util.ArrayList postConds, java.lang.Class clazz, java.lang.reflect.Method method)
Class[] interfaces = clazz.getInterfaces();
for (int i = 0 ; i < interfaces.length ; i++)
{
//System.out.println("Checking interface: " + interfaces[i]);
Method foundMethod = findMethodInClass(interfaces[i], method);
if (foundMethod != null)
{
//System.out.println("Found method: " + foundMethod);
addMethodConditions(method, foundMethod, preConds, postConds);
}
}
|
private static java.lang.reflect.Method | findMethodInClass(java.lang.Class clazz, java.lang.reflect.Method method)
String name = method.getName();
Method[] methods = clazz.getDeclaredMethods();
for (int i = 0 ; i < methods.length ; i++)
{
if (methods[i].getName().equals(name))
{
Class[] soughtParams = method.getParameterTypes();
Class[] foundParams = methods[i].getParameterTypes();
if (soughtParams.length == foundParams.length)
{
for (int j = 0 ; j < soughtParams.length ; j++)
{
if (soughtParams[j] != foundParams[j])
{
break;
}
}
return methods[i];
}
}
}
return null;
|
public static synchronized InvariantCondition[] | getInvariants(java.lang.reflect.Method method)
return getInvariants(method.getDeclaringClass());
|
public static synchronized ExecutableCondition[] | getPostConditions(java.lang.reflect.Method method)
ExecutableCondition[] post = (ExecutableCondition[])postConditions.get(method);
if (post != null)
{
return post;
}
initialise(method);
return (ExecutableCondition[])postConditions.get(method);
|
public static synchronized ExecutableCondition[] | getPreConditions(java.lang.reflect.Method method)
ExecutableCondition[] pre = (ExecutableCondition[])preConditions.get(method);
if (pre != null)
{
return pre;
}
initialise(method);
return (ExecutableCondition[])preConditions.get(method);
|
private static void | initialise(java.lang.reflect.Method method)
if (DesignByContractAspect.verbose) System.out.println("[dbc] ===== Intitalising method: " + method);
ArrayList preConds = new ArrayList();
ArrayList postConds = new ArrayList();
//Need @PreCond and @PostCond for this method, and all the super
//declarations of the method.
//Likewise we need the @Invariant for this class and the super classes
boolean first = true;
Class clazz = method.getDeclaringClass();
Class curClazz = clazz;
Method superMethod = method;
while (curClazz != null)
{
if (first)
{
first = false;
}
else
{
superMethod = findMethodInClass(curClazz, method);
}
if (superMethod != null)
{
addMethodConditions(method, superMethod, preConds, postConds);
}
addMethodConditionsForInterfaces(preConds, postConds, curClazz, method);
curClazz = curClazz.getSuperclass();
}
ExecutableCondition[] pre = (ExecutableCondition[])preConds.toArray(new ExecutableCondition[preConds.size()]);
preConditions.put(method, pre);
ExecutableCondition[] post = (ExecutableCondition[])postConds.toArray(new ExecutableCondition[postConds.size()]);
postConditions.put(method, post);
|