Methods Summary |
---|
private static void | addConstructorConditions(java.lang.reflect.Constructor realConstructor, java.lang.reflect.Constructor currentConstructor, java.util.ArrayList preConds, java.util.ArrayList postConds)
PreCond pre = (PreCond)AnnotationElement.getAnyAnnotation(currentConstructor, PreCond.class);
if (pre != null)
{
if (DesignByContractAspect.verbose) System.out.println("[dbc] Found preconditions in method: " + currentConstructor);
addConstructorConditions(realConstructor, preConds, pre.value());
}
PostCond post = (PostCond)AnnotationElement.getAnyAnnotation(currentConstructor, PostCond.class);
if (post != null)
{
if (DesignByContractAspect.verbose) System.out.println("[dbc] Found postconditions in method: " + currentConstructor);
addConstructorConditions(realConstructor, postConds, post.value());
}
|
private static java.util.ArrayList | addConstructorConditions(java.lang.reflect.Constructor realConstructor, java.util.ArrayList conditions, java.lang.String[] exprs)
if (exprs == null)
{
return conditions;
}
for (int i = 0 ; i < exprs.length ; i++)
{
conditions.add(new ConstructorCondition(realConstructor, exprs[i]));
}
return conditions;
|
private static java.lang.reflect.Constructor | findConstructorInClass(java.lang.Class clazz, java.lang.reflect.Constructor constructor)
String name = constructor.getName();
Constructor[] constructors = clazz.getDeclaredConstructors();
for (int i = 0 ; i < constructors.length ; i++)
{
if (constructors[i].getName().equals(name))
{
Class[] soughtParams = constructor.getParameterTypes();
Class[] foundParams = constructors[i].getParameterTypes();
if (soughtParams.length == foundParams.length)
{
for (int j = 0 ; j < soughtParams.length ; j++)
{
if (soughtParams[j] != foundParams[j])
{
break;
}
}
return constructors[i];
}
}
}
return null;
|
public static synchronized InvariantCondition[] | getInvariants(java.lang.reflect.Constructor constructor)
return getInvariants(constructor.getDeclaringClass());
|
public static synchronized ExecutableCondition[] | getPostConditions(java.lang.reflect.Constructor constructor)
ExecutableCondition[] post = (ExecutableCondition[])postConditions.get(constructor);
if (post != null)
{
return post;
}
initialise(constructor);
return (ExecutableCondition[])postConditions.get(constructor);
|
public static synchronized ExecutableCondition[] | getPreConditions(java.lang.reflect.Constructor constructor)
ExecutableCondition[] pre = (ExecutableCondition[])preConditions.get(constructor);
if (pre != null)
{
return pre;
}
initialise(constructor);
return (ExecutableCondition[])preConditions.get(constructor);
|
private static void | initialise(java.lang.reflect.Constructor constructor)
if (DesignByContractAspect.verbose) System.out.println("[dbc] ===== Intitalising constructor: " + constructor);
ArrayList preConds = new ArrayList();
ArrayList postConds = new ArrayList();
//Need @PreCond and @PostCond for this constructor, and all the super
//declarations of the constructor.
boolean first = true;
Class clazz = constructor.getDeclaringClass();
Class curClazz = clazz;
Constructor superConstructor = constructor;
while (curClazz != null)
{
if (first)
{
first = false;
}
else
{
superConstructor = findConstructorInClass(curClazz, constructor);
}
if (superConstructor != null)
{
addConstructorConditions(constructor, superConstructor, preConds, postConds);
}
curClazz = curClazz.getSuperclass();
}
ExecutableCondition[] pre = (ExecutableCondition[])preConds.toArray(new ExecutableCondition[preConds.size()]);
preConditions.put(constructor, pre);
ExecutableCondition[] post = (ExecutableCondition[])postConds.toArray(new ExecutableCondition[postConds.size()]);
postConditions.put(constructor, post);
|