Feuermagier / autograder

Automatic grading of student's Java code
MIT License
13 stars 7 forks source link

Detect classes that do not use inheritance or inner classes that should be `static` #560

Open Luro02 opened 4 days ago

Luro02 commented 4 days ago

What it does

One can nest a class in another class like this:

class A {
    class B {
    }
}

If the class is not static, it will extend the outer class, making the non-static fields and methods accessible.

In most submissions this behaviour is not intentional and therefore it makes sense to detect these cases.

Problems with this check:

After implementing this, it should be easy to find classes that inherit from another class, but do not need to inherit from it. Note: I do not think that this happens very often, that is why this issue is marked as low-priority

Things to be careful about with the inheritance thing:

Lint Name

INNER_CLASS_SHOULD_BE_STATIC,CLASS_SHOULD_NOT_INHERIT

Category

oop

Example

<code>

Could be written as:

<code>