Skip to content
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

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from

Conversation

asmae-ghammouri
Copy link

@asmae-ghammouri asmae-ghammouri commented Jan 14, 2023

implementing all the rules 1-18 .


@Override
public void apply(CompilationUnitWrapper compilationUnit) {

Copy link
Owner

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 -> {
Copy link
Owner

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))) {
Copy link
Owner

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();
Copy link
Owner

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);
Copy link
Owner

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)) {
Copy link
Owner

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)) {
Copy link
Owner

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);
Copy link
Owner

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();
Copy link
Owner

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())
Copy link
Owner

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants