Commit fa229deb authored by Markus Klinik's avatar Markus Klinik
Browse files

heuristic to identify view classes

parent e95b3b37
......@@ -51,9 +51,38 @@ set[Message] a01_io(M3 model)
loc mainClass = getOneFrom(range(domainR(invert(model.containment), getMainMethods(model))));
// find all methods that use System
set[loc] ioMethods = invert(model.typeDependency)[|java+class:///java/lang/System|];
set[loc] ioMethods =
{ m
| m <- invert(model.typeDependency)[|java+class:///java/lang/System|]
, isMethod(m)
};
// find the classes to which these methods belong
set[loc] ioClasses = range(domainR(invert(model.containment), ioMethods));
return { error("Only the main class should contain I/O", c) | c <- ioClasses, c != mainClass };
set[str] ioClassNames = { getName(model, c) | c <- ioClasses };
// Some heuristics. Many students implemented a view class, which is not main.
// In this case we don't want to generate an error message.
// Therefore, the rules:
// - If more than one class has I/O: generate messages for both of them
// - If only one class has I/O: check that it is NOT Student or Group.
// More than one class has I/O
if( size(ioClasses) > 1 )
{
return
{ error("Only the main or view class should contain I/O", c)
| c <- ioClasses, c != mainClass
};
}
// Only one class has I/O
else if( "Student" in ioClassNames || "Group" in ioClassNames )
{
return
{ error("Only the main or view class should contain I/O", c)
| c <- ioClasses
};
}
return {};
}
\ No newline at end of file
......@@ -20,5 +20,5 @@ test bool twoMains()
test bool ioOnlyInMainClass()
{
errors = a01_io(loadTestProject("assignment01-io-in-group"));
return "Only the main class should contain I/O" in { message | error(message,_) <- errors };
return "Only the main or view class should contain I/O" in { message | error(message,_) <- errors };
}
\ 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