throw new RuntimeException(
"illegal pattern in -k option ("
+ pattern
+ "). The -kD option only allows @p in D but not @f and @e because the filename will be generated to be __REP... and the extension is .java.");
}
TypeMetaclass t = (TypeMetaclass) annotations.firstElement();
String p = t.getPackageName();
repOutputDirectory = repOutputOption.getOutputFileName(targetFileName, p).trim();
if (!repOutputDirectory.endsWith("/") && !repOutputDirectory.endsWith("\\")
&& repOutputDirectory.length() > 0)
{
repOutputDirectory = repOutputDirectory + File.separator;
}
}
Vector args = o.getArguments();
boolean generate_pre_default = false;
boolean generate_post_default = false;
boolean generate_invariant_default = false;
if (args.isEmpty())
{
generate_pre_default = false;
generate_post_default = false;
generate_invariant_default = false;
}
else
{
if (args.contains("pre"))
{
generate_pre_default = true;
}
if (args.contains("post"))
{
generate_post_default = true;
}
if (args.contains("inv"))
{
generate_invariant_default = true;
}
}
Vector mControlTable = new Vector();
for (Enumeration e = args.elements(); e.hasMoreElements();)
{
String entry = (String) e.nextElement();
if (entry.startsWith("@"))
{
String fn = entry.substring(1, entry.length());
File file = new File(fn);
if (!file.exists())
{
throw new RuntimeException("Java Contract Suite: error file " + fn + " not found !");
}
try
{
FileReader file_input = new FileReader(fn);
try
{
BufferedReader f = new BufferedReader(file_input);
try
{
for (String line = null; (line = f.readLine()) != null;)
{
mControlTable.addElement(line);
}
}
finally
{
f.close();
}
}
finally
{
file_input.close();
}
}
catch (IOException _ex)
{
throw new RuntimeException("file " + fn + " disapeared after check!", _ex);
}
}
}
if (annotations.size() > 0)
{
CodeMetaclass cmc = (CodeMetaclass) annotations.elementAt(0);
PrintWriter output_file = null;
try
{
FileReader input_file = new FileReader(cmc.getFilename());
try
{
BufferedReader bufferedIs = new BufferedReader(input_file);
try
{
if (outputOption == null)
{
// TODO: close writers properly
output_file = new PrintWriter(System.out);
}
else
{
if (!outputOption.hasParameter())
{
throw new RuntimeException(
"Java Contract Suite: ERROR: output option (-o) requires filename (e.g. -oFile.java).");
}
String fon = "";
if (cmc instanceof TypeMetaclass)
{
String p = ((TypeMetaclass) cmc).getPackageName();
fon = outputOption.getOutputFileName(cmc.getFilename(), p);
}
if (!fileList.contains(fon))
{
fileList.addElement(fon);
}
// TODO: use a buffered writer
// TODO: close writers properly
output_file = new PrintWriter(new FileOutputStream(fon));
}
output_file.print("");
int last_pos = 0;
int next_pos = 0;
int plain_copy_amount = 0;
Hashtable repositories = new Hashtable();
Repository previousRepository = null;
for (int i = 0; i < annotations.size(); i++)
{
boolean shallInv = false;
InvCheck inv_element = (InvCheck) annotations.elementAt(i);
if (inv_element.mayHaveInvariant())
{
TypeMetaclass type = (TypeMetaclass) annotations.elementAt(i);
if (!type.isLocal())
{
String packag = type.getPackageName();
Repository rep = new Repository(packag, type.getUnqualifiedName(), "__REP_"
+ type.getUnqualifiedNameIncludingInner(), repOutputDirectory, type
.getFilename());
repositories.put("__REP_" + type.getSignature(), rep);
if (previousRepository != null)
{
previousRepository.dump();
if (!fileList.contains(previousRepository.getFilename()))
{
fileList.addElement(previousRepository.getFilename());
}
}
previousRepository = rep;
shallInv = shall("inv", type.getName(), mControlTable);
LOG.info("** type (t) " + type.getName() + " inv="
+ (shallInv || generate_invariant_default));
if (shallInv || generate_invariant_default)
{
String inv_code = ((InvCheck) type).getInvariantCode();
next_pos = type.getStartOfBody();
plain_copy_amount = next_pos - last_pos;
copy(bufferedIs, output_file, plain_copy_amount);
output_file.write(inv_code);
last_pos = next_pos;
}
rep = (Repository) repositories.get("__REP_" + type.getSignature());
rep.add(((InvCheck) type).getExportInvariantCode());
Vector nonimpl = ((InvCheck) type).getAllNonImplementedMethods();
net.sf.jcontracts.icontract.Method m;
for (Enumeration e = nonimpl.elements(); e.hasMoreElements(); rep.add(m
.getExportPostconditionCode()))
{
m = (net.sf.jcontracts.icontract.Method) e.nextElement();
rep.add(m.getExportPreconditionCode());
}
}
else
{
System.err
.println(type.getLocationDescription()
+ "Java Contract Suite: WARNING: contract-checks (invariant) will NOT be instrumented for (local/anonymous class) "
+ type.getSignature()
+ " [this version of the tool does not support the instrumentation of methods in local and anonymous classes]");
}
}
PrePostCheck prepost_element = (PrePostCheck) annotations.elementAt(i);
net.sf.jcontracts.icontract.Method method = null;