Skip to content

Commit

Permalink
remove STATIC_METHOD_IN_INTERFACE and CONSTANT_IN_INTERFACE Feuer…
Browse files Browse the repository at this point in the history
  • Loading branch information
Luro02 committed May 16, 2024
1 parent ccba5db commit a998d2b
Show file tree
Hide file tree
Showing 7 changed files with 3 additions and 54 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -64,9 +64,7 @@ public enum ProblemType {
RUNTIME_EXCEPTION_CAUGHT,
OBJECTS_COMPARED_VIA_TO_STRING,
FIELD_SHOULD_BE_CONSTANT,
CONSTANT_IN_INTERFACE,
DO_NOT_HAVE_CONSTANTS_CLASS,
STATIC_METHOD_IN_INTERFACE,
DO_NOT_USE_RAW_TYPES,
DUPLICATE_CODE,
TOO_FEW_PACKAGES,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@
import java.util.List;
import java.util.Set;

@ExecutableCheck(reportedProblems = { ProblemType.CONSTANT_IN_INTERFACE, ProblemType.DO_NOT_HAVE_CONSTANTS_CLASS,
ProblemType.STATIC_METHOD_IN_INTERFACE, ProblemType.EMPTY_INTERFACE })
@ExecutableCheck(reportedProblems = { ProblemType.DO_NOT_HAVE_CONSTANTS_CLASS,
ProblemType.EMPTY_INTERFACE })
public class InterfaceBadPractices extends IntegratedCheck {
@Override
protected void check(StaticAnalysis staticAnalysis) {
Expand Down Expand Up @@ -43,26 +43,6 @@ public void process(CtInterface<?> ctInterface) {
new LocalizedMessage("constants-class-exp"),
ProblemType.DO_NOT_HAVE_CONSTANTS_CLASS
);
} else if (!fields.isEmpty()) {
// interfaces should not have fields:
for (CtField<?> field : fields) {
addLocalProblem(
field,
new LocalizedMessage("constants-interfaces-exp"),
ProblemType.CONSTANT_IN_INTERFACE
);
}
}

for (CtMethod<?> method : methods) {
// static methods in interfaces should be avoided
if (method.isStatic()) {
addLocalProblem(
method,
new LocalizedMessage("interface-static-method-exp"),
ProblemType.STATIC_METHOD_IN_INTERFACE
);
}
}
}
});
Expand Down
4 changes: 0 additions & 4 deletions autograder-core/src/main/resources/strings.de.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -148,8 +148,6 @@ compare-objects-exp = Implementiere eine equals-Methode für den Typ {$type} und
variable-should-be = Die Variable '{$variable}' sollte '{$suggestion}' sein.
constants-interfaces-exp = Interfaces sollten keine Attribute haben
reassigned-parameter = Dem Parameter '{$name}' sollte kein neuer Wert zugewiesen werden.
double-brace-init = Die obskure 'Double Brace'-Syntax sollte vermieden werden
Expand Down Expand Up @@ -240,8 +238,6 @@ static-field-should-be-instance = Das statische Attribut '{$name}' sollte ein In
constants-class-exp = Konstanten sollten in der Klasse gespeichert werden in der sie auch verwendet werden und nicht in einer separaten Klasse. Siehe https://stackoverflow.com/a/15056462/7766117
interface-static-method-exp = Interfaces sollte keine statischen Methoden haben, da sie nicht überschrieben werden können.
empty-interface-exp = Interfaces sollten nicht leer sein.
ui-input-separation = Eingaben sollten nicht im Programm verteilt sein. Wurde auch verwendet in {$first}.
Expand Down
4 changes: 0 additions & 4 deletions autograder-core/src/main/resources/strings.en.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -150,8 +150,6 @@ compare-objects-exp = Implement an equals method for type {$type} and use it for
variable-should-be = The variable '{$variable}' should be '{$suggestion}'.
constants-interfaces-exp = Interfaces must not have fields
reassigned-parameter = The parameter '{$name}' should not be assigned a new value.
double-brace-init = Don't use the obscure 'double brace initialization' syntax
Expand Down Expand Up @@ -239,8 +237,6 @@ static-field-should-be-instance = The static field '{$name}' must not be static.
constants-class-exp = Constants should be saved in the class they are used in and not in a separate class. See https://stackoverflow.com/a/15056462/7766117
interface-static-method-exp = Interfaces should not have static methods, because they can not be overwritten.
empty-interface-exp = Interfaces should not be empty.
ui-input-separation = Input should not be spread over the program. Other use in {$first}.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,7 @@ public static void main(String[] args) {}
private static interface MyInterface {} /*# not ok #*/
}

interface MyConstantsInterface { /*# not ok #*/
int MY_CONSTANT = 42;
String ANOTHER_CONSTANT = "Hello World";
}

interface MyConstantsInterfaceWithMethods {
int MY_CONSTANT = 42; /*# not ok #*/
String ANOTHER_CONSTANT = "Hello World"; /*# not ok #*/

void doSomething();

default void doSomethingElse() {}
Expand All @@ -24,17 +16,11 @@ interface MyInterfaceWithStaticMethod {
void doSomething();

default void doSomethingElse() {}

static void doesSomething2() {} /*# not ok #*/
}

interface Bar { /*# not ok #*/
}

interface Foo { /*# not ok #*/
public static final int FOO = 1;
}

class OuterClass {
interface InnerInterface { /*# ok #*/
void doSomething();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,4 @@
oop.InterfaceBadPractices
Bad practices for interfaces
Test.java:6
Test.java:9
Test.java:15
Test.java:16
Test.java:28
Test.java:31
Test.java:34
Test.java:21
2 changes: 0 additions & 2 deletions sample_config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ problemsToReport:
- RUNTIME_EXCEPTION_CAUGHT
- OBJECTS_COMPARED_VIA_TO_STRING
- FIELD_SHOULD_BE_CONSTANT
- CONSTANT_IN_INTERFACE
- DUPLICATE_CODE
- REASSIGNED_PARAMETER
- DOUBLE_BRACE_INITIALIZATION
Expand Down Expand Up @@ -63,7 +62,6 @@ problemsToReport:
- EXCEPTION_WITHOUT_MESSAGE
- DO_NOT_USE_RAW_TYPES
- DO_NOT_HAVE_CONSTANTS_CLASS
- STATIC_METHOD_IN_INTERFACE
- EMPTY_INTERFACE
- UI_INPUT_SEPARATION
- UI_OUTPUT_SEPARATION
Expand Down

0 comments on commit a998d2b

Please sign in to comment.