Commit 2755bdfb authored by Markus Klinik's avatar Markus Klinik
Browse files

make ioClasses utility function

parent 72aacd46
......@@ -26,20 +26,13 @@ set[Message] a02_all_io_in_view(M3 model)
loc gallows = findClass(model, "Gallows");
loc wordReader = findClass(model, "WordReader");
// find all methods that use System
set[loc] ioMethods =
{ m
| m <- invert(model.typeDependency)[|java+class:///java/io/PrintStream|]
, isMethod(m)
};
// find the classes to which these methods belong
set[loc] ioClasses = range(domainR(invert(model.containment), ioMethods));
dirtyClasses = ioClasses(model);
// Generate error messages if Main or Gallows performs I/O
result += { error("All I/O should happen in the view class", c) | c <- { mainClass, gallows }, c in ioClasses };
result += { error("All I/O should happen in the view class", c) | c <- { mainClass, gallows }, c in dirtyClasses };
// If there is more than one class that performs I/O, generate error messages
set[loc] ioClasses2 = ioClasses - { mainClass, gallows, wordReader };
set[loc] ioClasses2 = dirtyClasses - { mainClass, gallows, wordReader };
if( size(ioClasses2) > 1 )
{
result += { error("Only the view class should perform I/O", c) | c <- ioClasses2 };
......
......@@ -23,4 +23,18 @@ loc getMainClass(M3 model) =
getOneFrom(range(domainR(invert(model.containment), getMainMethods(model))));
// extract only the messages of a set of errors, discarding the locations
set[str] messages(set[Message] errors) = { message | error(message, _) <- errors };
\ No newline at end of file
set[str] messages(set[Message] errors) = { message | error(message, _) <- errors };
// All classes that perform I/O
// Performing I/O is defined as using PrintStream, which is System.out
set[loc] ioClasses(M3 model)
{
// find all methods that use System
set[loc] ioMethods =
{ m
| m <- invert(model.typeDependency)[|java+class:///java/io/PrintStream|]
, isMethod(m)
};
// find the classes to which these methods belong
return range(domainR(invert(model.containment), ioMethods));
}
\ No newline at end of file
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment