Commit ddd44f6f authored by Rick van der Wal's avatar Rick van der Wal
Browse files

Personal Prof no longer mentions missing access modifiers for enum...

Personal Prof no longer mentions missing access modifiers for enum constructors and interface methods
parent a433169a
module CodingRules
import Relation;
......@@ -15,6 +16,8 @@ set[Message] allCodingRules(M3 model)
+ ps_attribute_names_lowercase(model)
+ ps_all_caps_constant_names(model)
+ ps_explicit_access_modifiers(model)
//+ ps_no_enum_modifier(model)
//+ ps_no_interface_modifier(model)
+ ps_public_attributes(model)
// Redundant for Main, but useful for the tests
+ modelErrors(model)
......@@ -63,17 +66,40 @@ set[Message] ps_explicit_access_modifiers(M3 model)
{
set[loc] artifactsOfInterest = range(declaredMethods(model)) + range(declaredFields(model));
return
{ error("Always explicitly specify access modifiers: public, protected, or private", thing)
{ error("Explicitly specify access modifiers: public, protected, or private", thing)
| thing <- artifactsOfInterest
// & is set intersection
, isEmpty(model.modifiers[thing] & {\public(), \protected(), \private()})
&& {1 | interface <- interfaces(model), thing in methods(model, interface)} == {}
&& {1 | enum <- enums(model), thing in constructors(model, enum)} == {}
};
}
//set[Message] ps_no_enum_modifier(M3 model)
//{
// set[loc] artifactsOfInterest = range(declaredMethods(model));
// return
// { error("Private access modifiers for enum constructors are redundant", thing)
// | thing <- artifactsOfInterest
// // & is set intersection
// , !isEmpty(model.modifiers[thing] & {\private()}) &&
// };
//}
//
//set[Message] ps_no_interface_modifier(M3 model)
//{
// set[loc] artifactsOfInterest = range(declaredMethods(model));
// return
// { error("Public access modifiers for interface methods are redundant", thing)
// | thing <- artifactsOfInterest
// // & is set intersection
// , !isEmpty(model.modifiers[thing] & {\public()}) &&
// };
//}
// If an attribute is public, it must be final
set[Message] ps_public_attributes(M3 model) =
{ error("Only final attributes may be public", field)
| field <- range(declaredFields(model))
, \public() in model.modifiers[field] && !(\final() in model.modifiers[field])
};
\ No newline at end of file
};
public enum Level {
LOW,
MEDIUM,
HIGH;
private Level() {}
}
public class Main {
public static void main(String[] args) {}
}
public enum Level {
LOW,
MEDIUM,
HIGH;
Level() {}
}
public class Main {
public static void main(String[] args) {}
}
......@@ -57,7 +57,20 @@ test bool explicitAccessModifiersMissing()
errors = ps_explicit_access_modifiers(loadTestProject("assignment01-missing-access-modifier"));
return
size(errors) == 2 &&
{ "Always explicitly specify access modifiers: public, protected, or private" } <=
{ "Explicitly specify access modifiers: public, protected, or private" } <=
messages(errors);
}
test bool enumInterfaceAccessModifiersGood()
{
return isEmpty(ps_explicit_access_modifiers(loadTestProject("implicit-enum-interface-access-modifiers")));
}
test bool enumInterfaceAccessModifiersExplicit()
{
errors = ps_explicit_access_modifiers(loadTestProject("explicit-enum-interface-access-modifiers"));
return
{} <=
messages(errors);
}
......
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