Skip to content

Commit

Permalink
add another test, fix a bug I intro'd in #34 because there was no suc…
Browse files Browse the repository at this point in the history
…h test
  • Loading branch information
kelloggm committed Jan 9, 2023
1 parent e566a27 commit d17a838
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -66,10 +66,10 @@ private static boolean checkGoogleFormatOpenCase(String line) {
if (line.length() == 0) {
return false;
}
String elements[] = line.trim().split(" ");
String[] elements = line.trim().split(" ");
int n = elements.length;
if (n >= 1 && elements[n - 1].endsWith("@org")) {
String breaks[] = elements[n - 1].split("[.]");
if (n >= 1 && elements[n - 1].contains("@org")) {
String[] breaks = elements[n - 1].split("[.]");
int numberOfParts = breaks.length;
if (numberOfParts < 2) {
throw new RuntimeException("Invalid annotation form in line: " + line);
Expand All @@ -95,7 +95,7 @@ private static boolean checkGoogleFormatCloseCase(String line) {
}

/**
* This method checks the status of a line. If that line is the openning of a multi-line
* This method checks the status of a line. If that line is the opening of a multi-line
* annotation, we call it "Open". If the line is the closing of a multi-line annotation, we call
* it "Close". And if the line does not contain any multi-line annotation, we call it "Complete".
*
Expand Down Expand Up @@ -136,8 +136,8 @@ private static LineStatus checkLineStatus(String line) {
* @param fileName the name of the input file to be formatted
* @return inputFiles a list containing lines of the formatted file
*/
private static List annoMultiToSingle(String fileName) {
List<String> inputFiles = new ArrayList<String>();
private static List<String> annoMultiToSingle(String fileName) {
List<String> inputFiles = new ArrayList<>();
File file = new File(fileName);
try (BufferedReader br = new BufferedReader(new FileReader(file))) {
String originalFileLine;
Expand Down Expand Up @@ -196,7 +196,7 @@ private static List eachAnnotationInOneSingleLine(List<String> inputFiles) {
if (resultLine.length() > 0) {
// sometimes the annotation can be in the middle of a declaration
formatted.add(resultLine + element.substring(0, indexOfAnno));
element = element.substring(indexOfAnno, element.length());
element = element.substring(indexOfAnno);
}
resultLine = "";
if (checkLineStatus(element) == LineStatus.COMPLETE) {
Expand Down Expand Up @@ -600,6 +600,7 @@ public static void main(String[] args) {
for (AbstractDelta<String> delta : patch.getDeltas()) {
// get the delta in string format
String deltaInString = delta.toString();
System.out.println(deltaInString);
// just take the delta with annotations into consideration
// INSERT type indicates that the annotations only appear in the computer-generated files.
// So we don't take it into consideration.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -140,4 +140,20 @@ public void multiLineAnnotation() {
+ outputStreamCaptor,
outputStreamCaptor.toString().trim().contains(line1));
}

@Test
public void gJFMultiLine() {
InferredAnnosCounter.main(
new String[] {"testCases/GJFMultiLine.java", "testCases/GJFMultiLine.ajava"});
String line1 = "@CalledMethods got 1/1";
String line2 = "@NonNull got 1/1";
assertTrue(
"Didn't find the correct number of @CalledMethods annotations; expected 1/1, got: "
+ outputStreamCaptor,
outputStreamCaptor.toString().trim().contains(line1));
assertTrue(
"Didn't find the correct number of @NonNull annotations; expected 1/1, got: "
+ outputStreamCaptor,
outputStreamCaptor.toString().trim().contains(line2));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
public static @org.checkerframework.checker.calledmethods.qual
.CalledMethods({"someVeryLongMethodName"}) Object getFoo() {

}

public static @org.checkerframework.checker.initialization.qual.Initialized @org.checkerframework
.checker.nullness.qual.NonNull DateTime start_date = new DateTime();
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
public static @CalledMethods({"someVeryLongMethodName"}) Object getFoo() {

}

public static @NonNull DateTime start_date = new DateTime();

0 comments on commit d17a838

Please sign in to comment.