-
Notifications
You must be signed in to change notification settings - Fork 1
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
Add Index Checker annotations #2
base: master
Are you sure you want to change the base?
Conversation
…ing remaining errors
…except those caused by missing annotations in javax.swing classes
… and need to be investigated further; everything else has either been removed or suppressed
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I just quickly looked through the diff, looks good to me, just nitpicks: found some annotations still in comments (see review comments), sometimes inconsistent whitespace (I didn't mark that).
@@ -423,8 +433,10 @@ public static int stringToMonthCode(String s) { | |||
} | |||
} | |||
} | |||
@SuppressWarnings({"index", "value"}) // the loop above only ensures that 1 <= result <= 12 if s is an actual month name | |||
@IntRange(from = 1, to =12) int toReturn = result; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should be @IntRange(from = -1, to = 12)
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No. The if loop above ensures that the value is 1 to 12 if the variable s is a valid month name, which is a precondition of the function.
@@ -76,7 +82,7 @@ | |||
* @param month the month (in the range 1 to 12). | |||
* @param year the year (in the range 1900 to 9999). | |||
*/ | |||
public SpreadsheetDate(int day, int month, int year) { | |||
public SpreadsheetDate(@IntRange(from = 1, to = 31) int day, /*@IntRange(from = 1, to = 12)*/ int month, @IntRange(from = 1, to = 9999) int year) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Annotation in comment.
@@ -425,16 +445,22 @@ else if (include == SerialDate.INCLUDE_SECOND) { | |||
* | |||
* @return the serial number from the day, month and year. | |||
*/ | |||
private int calcSerial(int d, int m, int y) { | |||
private @IntRange(from = 2, to = 2958465) int calcSerial(/*@IntRange(from = 1, to = 31)*/ int d, /*@IntRange(from=1,to=12)*/ int m, @IntRange(from = 1900, to = 9999) int y) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Annotations in comments.
@@ -238,10 +241,11 @@ public static double calculateRowTotal(Values2D data, int row, | |||
* | |||
* @return An array of {@code double}. | |||
*/ | |||
public static Number[][] createNumberArray2D(double[][] data) { | |||
@SuppressWarnings("value") // the result array is manifestly the same size as the parameter | |||
public static Number @SameLen("#1") /*@PolyValue*/ [][] createNumberArray2D(double @PolyValue [][] data) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Annotation in comments.
@@ -63,7 +70,7 @@ | |||
* | |||
* @return The parameters. | |||
*/ | |||
public static double[] getOLSRegression(double[][] data) { | |||
public static double @ArrayLen(2) [] getOLSRegression(double /*@MinLen(2)*/ [] @MinLen(2) [] data) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Annotation in comment.
@@ -150,7 +157,7 @@ | |||
* | |||
* @return The parameters. | |||
*/ | |||
public static double[] getPowerRegression(double[][] data) { | |||
public static double @ArrayLen(2) [] getPowerRegression(double /*@MinLen(2)*/ [] @MinLen(2) [] data) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Annotation in comments.
@@ -327,7 +332,7 @@ public static double getStdDev(Number[] data) { | |||
* | |||
* @return A double array with the intercept in [0] and the slope in [1]. | |||
*/ | |||
public static double[] getLinearFit(Number[] xData, Number[] yData) { | |||
public static double @ArrayLen(2) [] getLinearFit(Number /*@SameLen("#2")*/ [] xData, Number @SameLen("#1") [] yData) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Annotation in comment.
@@ -439,8 +444,8 @@ public static double getCorrelation(Number[] data1, Number[] data2) { | |||
* @return A double[][] the length of the data set in the first dimension, | |||
* with two doubles for x and y in the second dimension | |||
*/ | |||
public static double[][] getMovingAverage(Number[] xData, Number[] yData, | |||
int period) { | |||
public static double[] @ArrayLen(2) [] getMovingAverage(Number /*@SameLen("#2")*/ [] xData, Number @SameLen("#1") [] yData, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Annotation in comment.
double[] high, double[] low, double[] open, double[] close, | ||
double[] volume) { | ||
@SuppressWarnings("samelen") // While initializing object, SameLen invariants between the fields will be broken (because one field must be initialized before the others). The annotations on the parameters guarantee the invariant holds after the constructor finishes executing. | ||
public DefaultHighLowDataset(Comparable seriesKey, Date @SameLen({"#2", "#3", "#4", "#4", "#5", "#6", "#7"}) [] date, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Duplicate "#4"
@@ -271,7 +271,7 @@ public static IntervalCategoryDataset createDataset() { | |||
* | |||
* @return a date. | |||
*/ | |||
private static Date date(int day, int month, int year) { | |||
private static Date date(@IntRange(from = 1, to = 31) int day, /*@IntRange(from = 1, to = 12)*/ int month, @IntRange(from = 1900, to = 9999) int year) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Annotation in comment.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The standard Maven target is mvn package
.
That works for upstream JFreeChart, but it fails for this pull request.
Please make mvn package
work, or document some other command that builds all the artifacts.
I have reviewed about 20% of the changes, but many of my comments apply throughout the codebase. Please make those changes and I will re-review.
.gitignore
Outdated
@@ -2,10 +2,12 @@ | |||
/target/ | |||
/javadoc/ | |||
|
|||
build/ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why is this change needed?
.gitignore
Outdated
.idea |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please don't make unnecessary whitespace changes. It pollutes the diffs.
.travis.yml
Outdated
sudo: false | ||
script: | ||
- mvn clean | ||
- travis_wait mvn compile |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add newline at end of files, when creating a new file.
.travis.yml
Outdated
language: java | ||
sudo: false | ||
script: | ||
- mvn clean |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why is this needed? A Travis job always starts out from a clean clone.
pom.xml
Outdated
<dependency> | ||
<groupId>org.checkerframework</groupId> | ||
<artifactId>checker-qual</artifactId> | ||
<version>2.5.0</version> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Update to latest version.
@@ -479,9 +490,10 @@ else if ((yyyy % 100) == 0) { | |||
* | |||
* @param yyyy the year (in the range 1900 to 9999). | |||
* | |||
* @return the number of leap years from 1900 to the specified year. | |||
* @return the number of leap years from 1900 to the specified year (if year is 9999, 1964 leap years). |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Comment is too telegraphic. Add a few words to clarify.
*/ | ||
public static int leapYearCount(int yyyy) { | ||
@SuppressWarnings({"index", "value"}) // imprecision wrt ranges | ||
public static @IntRange(from = 0, to = 1964) int leapYearCount(@IntRange(from = 1900, to = 9999)int yyyy) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Needs whitespace between ")" and "int".
@@ -538,14 +552,17 @@ public static SerialDate addDays(int days, SerialDate base) { | |||
* | |||
* @return a new date. | |||
*/ | |||
@SuppressWarnings({"index", "value"}) // True positive, fixed upstream bug |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Reference an issue tracker bug in upstream JFreeChart repository.
The same comment applies to other comments of this form.
public static SerialDate addMonths(int months, SerialDate base) { | ||
int yy = (12 * base.getYYYY() + base.getMonth() + months - 1) / 12; | ||
if (yy < MINIMUM_YEAR_SUPPORTED || yy > MAXIMUM_YEAR_SUPPORTED) { | ||
throw new IllegalArgumentException("Call to addMonths resulted in unsupported year"); | ||
} | ||
int mm = (12 * base.getYYYY() + base.getMonth() + months - 1) % 12 + 1; | ||
int dd = Math.min(base.getDayOfMonth(), | ||
SerialDate.lastDayOfMonth(mm, yy)); | ||
int lastDayOfMonth = SerialDate.lastDayOfMonth(mm, yy); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What is the point of abstracting out this variable?
(Maybe there used to be a @SuppressWarnings
on it?)
Please review the diffs and undo any unnecessary changes like this, to minimize the diffs.
@@ -581,7 +599,7 @@ public static SerialDate addYears(int years, SerialDate base) { | |||
* @return the latest date that falls on the specified day-of-the-week and | |||
* is BEFORE the base date. | |||
*/ | |||
public static SerialDate getPreviousDayOfWeek(int targetWeekday, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Don't change whitespace (there was a gratuitous trailing space here).
@@ -2,7 +2,7 @@ | |||
* JFreeChart : a free chart library for the Java(tm) platform | |||
* =========================================================== | |||
* | |||
* (C) Copyright 2000-2016, by Object Refinery Limited and Contributors. | |||
* (C) Copyright 2000-2018, by Object Refinery Limited and Contributors. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think the copyright dates should be changed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If this is because you want to revert the JFreeChart source code to an earlier version, that should be done in a separate pull request, to make this one easier to review.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is different because typetools hasn't merged from upstream, but this branch has (as of about 30 minutes ago when I realized I needed to because the tests were failing!). I certainly didn't change the copyright date. I'll merge upstream into typetools/master to fix the diff.
1. Remove two warning suppressions that aren't required. (One required more annotations.) 2. Added "rewrite" to 14 of the false positives that could be fixed by using Map.Entry.
Plus remove one more.
Work on Guaranteed index false positives.
This pull request includes all of the Index Checker annotations for the JFreeChart case study. When compiling (i.e. running
mvn compile
), the Index Checker is run automatically (using the version of the checker from Maven Central).I had to revert the old commit that added annotations in so that this can be merged cleanly. I've also removed all traces of the old
ant
build files.The annotated version of JFreeChart is version 1.5.0.