-
Notifications
You must be signed in to change notification settings - Fork 37
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
ElkhalifiZahia-GhammouriAsmae #27
base: develop
Are you sure you want to change the base?
Conversation
|
||
@Override | ||
public void apply(CompilationUnitWrapper compilationUnit) { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
no implementation found
public void apply(CompilationUnitWrapper compilationUnit) { | ||
List<FieldDeclaration> fields = compilationUnit.getCompilationUnit().findAll(FieldDeclaration.class); | ||
fields | ||
.forEach(fieldDeclaration -> { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use visitor pattern
.forEach(classOrInterface -> { | ||
String name = classOrInterface.getNameAsString(); | ||
int lineNumber = classOrInterface.getName().getBegin().get().line; | ||
if (!Character.isUpperCase(name.charAt(0))) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
!Character.isUpperCase ==> Character.isLowerCase
@Override | ||
public void apply(CompilationUnitWrapper compilationUnit) { | ||
compilationUnit.getCompilationUnit().findAll(FieldDeclaration.class).forEach(fieldDeclaration -> { | ||
String name = fieldDeclaration.getVariables().get(0).getNameAsString(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if a field declaration contains more than one variable, this will not work
example :
private String foo, bar, alice;
int lineNumber = fieldDeclaration.getVariables().get(0).getBegin().get().line; | ||
if (!Character.isLowerCase(name.charAt(0))) { | ||
final Violation violation = new Violation(); | ||
violation.setDescription("Les attributs d'une classe commencent par une minuscule: " + name); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
attributs d'instance et non pas de classe
for (IfStmt clause : compilationUnit.getCompilationUnit().findAll(IfStmt.class)) { | ||
Statement ifClause = clause.getThenStmt(); | ||
Optional<Statement> elseClause = clause.getElseStmt(); | ||
if (!(ifClause instanceof BlockStmt)) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
use visitor pattern to avoid type checks
violation.setFileName(compilationUnit.getFileName()); | ||
addViolation(violation); | ||
} | ||
if (elseClause.isPresent() && !(elseClause.get() instanceof BlockStmt)) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
use Optional chaining
// Check if the name contains underscores | ||
if (!name.contains("_")) { | ||
final Violation violation = new Violation(); | ||
violation.setDescription("Enum element name must contain underscores: " + name); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
not a must, if there is a need to separate things it will be by using an underscore
public void apply(CompilationUnitWrapper compilationUnit) { | ||
compilationUnit.getCompilationUnit().findAll(ClassOrInterfaceDeclaration.class) | ||
.forEach(classOrInterface -> { | ||
long methodCount = classOrInterface.getMethods().size(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why long ? int is largely enough
public void apply(CompilationUnitWrapper compilationUnit) { | ||
List<VariableDeclarator> unusedVariables = compilationUnit.getCompilationUnit().findAll(VariableDeclarator.class) | ||
.stream() | ||
.filter(variable -> variable.getInitializer().isPresent() && variable.getInitializer().get().findAll(NameExpr.class, nameExpr -> nameExpr.getNameAsString().equals(variable.getNameAsString())).isEmpty()) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the boolean condition is too long
implementing all the rules 1-18 .