Skip to content

Commit

Permalink
have fuzzy not include trivials
Browse files Browse the repository at this point in the history
  • Loading branch information
timo-a committed Mar 22, 2021
1 parent 45f4d8d commit 292a5fb
Show file tree
Hide file tree
Showing 8 changed files with 35 additions and 27 deletions.
6 changes: 4 additions & 2 deletions app/src/main/java/de/lomboker/app/CounterApp.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
*/
package de.lomboker.app;

import de.lomboker.lib.FuzzyGetters;
import de.lomboker.lib.FuzzySetters;
import de.lomboker.lib.TrivialGetters;
import de.lomboker.lib.TrivialSetters;
import picocli.CommandLine;
Expand Down Expand Up @@ -52,10 +54,10 @@ private static String evaluateFile(String fname) {
return fname + " ioexception reading file";
}
int trivialGetters = TrivialGetters.countTrivialGetters(code);
int fuzzyGetters = TrivialGetters.countFuzzyGetters(code);
int fuzzyGetters = FuzzyGetters.countFuzzyGetters(code);

int trivialSetters = TrivialSetters.countTrivialSetters(code);
int fuzzySetters = TrivialSetters.countFuzzySetters(code);
int fuzzySetters = FuzzySetters.countFuzzySetters(code);

return String.format("%d %d %d %d",
trivialGetters,
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/java/de/lomboker/app/getter/MarkGetter.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
import java.io.IOException;
import java.nio.file.Files;

import static de.lomboker.lib.FuzzyGetterMarker.markFuzzyGetters;
import static de.lomboker.lib.FuzzyGetters.markFuzzyGetters;

@Command(name = "getter", description = "mark non-trivial getters")
public class MarkGetter implements Runnable {
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/java/de/lomboker/app/setter/MarkSetter.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
import java.io.IOException;
import java.nio.file.Files;

import static de.lomboker.lib.FuzzySetterMarker.markFuzzySetters;
import static de.lomboker.lib.FuzzySetters.markFuzzySetters;

@Command(name = "setter", description = "mark non-trivial setters")
public class MarkSetter implements Runnable {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
import static de.lomboker.lib.TrivialGetters.isGetter;
import static de.lomboker.lib.TrivialGetters.isTrivialGetter;

public class FuzzyGetterMarker {
public class FuzzyGetters {

private static final String CHECK_COMMENT = "TODO Lomboker says check this potential getter";

Expand All @@ -29,7 +29,6 @@ public static String markFuzzyGetters(String code){

cu.findAll(MethodDeclaration.class).stream()
.filter(md -> isNonTrivialGetter(md, fieldNames))
.filter(md -> !isTrivialGetter(md, fieldNames))
.forEach(md -> {md.setLineComment(CHECK_COMMENT);});

return LexicalPreservingPrinter.print(cu);
Expand All @@ -40,7 +39,19 @@ private static boolean isNonTrivialGetter(MethodDeclaration md, Set<String> fiel
return false;
}

if (isTrivialGetter(md, fields)) {
return false;
}

return true;
}

public static int countFuzzyGetters(String code) {
ClassWrapper wrapper = new ClassWrapper(code);
long count = wrapper.methods.stream()
.filter(md -> isNonTrivialGetter(md, wrapper.fieldNames))
.count();

return (int) count;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,11 @@
import java.util.Set;
import java.util.stream.Collectors;

import static de.lomboker.lib.TrivialGetters.isTrivialGetter;
import static de.lomboker.lib.TrivialSetters.isSetter;
import static de.lomboker.lib.TrivialSetters.isTrivialSetter;

public class FuzzySetterMarker {
public class FuzzySetters {

private static final String CHECK_COMMENT = "TODO Lomboker says check this potential setter";
/**
Expand All @@ -39,7 +40,19 @@ private static boolean isNonTrivialSetter(MethodDeclaration md, Set<String> fiel
return false;
}

if (isTrivialSetter(md, fields)) {
return false;
}

return true;
}

public static int countFuzzySetters(String code) {
ClassWrapper wrapper = new ClassWrapper(code);
long count = wrapper.methods.stream()
.filter(md -> isNonTrivialSetter(md, wrapper.fieldNames))
.count();

return (int) count;
}
}
9 changes: 0 additions & 9 deletions lib/src/main/java/de/lomboker/lib/TrivialGetters.java
Original file line number Diff line number Diff line change
Expand Up @@ -173,13 +173,4 @@ public static int countTrivialGetters(String code) {
return (int) count;
}

public static int countFuzzyGetters(String code) {
ClassWrapper wrapper = new ClassWrapper(code);
long count = wrapper.methods.stream()
.filter(TrivialGetters::isGetter)
.count();

return (int) count;
}

}
9 changes: 0 additions & 9 deletions lib/src/main/java/de/lomboker/lib/TrivialSetters.java
Original file line number Diff line number Diff line change
Expand Up @@ -199,13 +199,4 @@ public static int countTrivialSetters(String code) {
return (int) count;
}

public static int countFuzzySetters(String code) {
ClassWrapper wrapper = new ClassWrapper(code);
long count = wrapper.methods.stream()
.filter(TrivialSetters::isSetter)
.count();

return (int) count;
}

}
4 changes: 2 additions & 2 deletions lib/src/test/java/de/lomboker/lib/Tests.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public void testGetterMarker() throws IOException {
String input = readFile(fileName);
String expected = readFile(fileNameRef);

assertEquals(expected, FuzzyGetterMarker.markFuzzyGetters(input));
assertEquals(expected, FuzzyGetters.markFuzzyGetters(input));

}

Expand All @@ -30,7 +30,7 @@ public void testSetterMarker() throws IOException {
String input = readFile(fileName);
String expected = readFile(fileNameRef);

assertEquals(expected, FuzzySetterMarker.markFuzzySetters(input));
assertEquals(expected, FuzzySetters.markFuzzySetters(input));

}

Expand Down

0 comments on commit 292a5fb

Please sign in to comment.