Skip to content

Commit

Permalink
Merge pull request #239 from parsingdata/error-prone
Browse files Browse the repository at this point in the history
Added Google error-prone to the build and resolved all warnings. Resolves #237.
  • Loading branch information
jvdb committed May 23, 2018
2 parents 54f1fc4 + 7880b56 commit f432c33
Show file tree
Hide file tree
Showing 11 changed files with 73 additions and 38 deletions.
4 changes: 4 additions & 0 deletions core/src/main/java/io/parsingdata/metal/Trampoline.java
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,12 @@ static <T> Trampoline<T> complete(final CompletedTrampoline<T> completedTrampoli
@FunctionalInterface
interface CompletedTrampoline<T> extends Trampoline<T> {

@Override
default boolean hasNext() {
return false;
}

@Override
default Trampoline<T> next() {
throw new UnsupportedOperationException("A CompletedTrampoline does not have a next computation.");
}
Expand All @@ -61,10 +63,12 @@ static <T> Trampoline<T> intermediate(final IntermediateTrampoline<T> intermedia
@FunctionalInterface
interface IntermediateTrampoline<T> extends Trampoline<T> {

@Override
default T result() {
throw new UnsupportedOperationException("An IntermediateTrampoline does not have a result.");
}

@Override
default boolean hasNext() {
return true;
}
Expand Down
8 changes: 4 additions & 4 deletions core/src/main/java/io/parsingdata/metal/data/ParseGraph.java
Original file line number Diff line number Diff line change
Expand Up @@ -117,13 +117,13 @@ private Trampoline<Optional<ParseValue>> current(final ImmutableList<ParseItem>
return intermediate(() -> current(items.tail));
}

public boolean isGraph() { return true; }
public ParseGraph asGraph() { return this; }
public Token getDefinition() { return definition; }
@Override public boolean isGraph() { return true; }
@Override public ParseGraph asGraph() { return this; }
@Override public Token getDefinition() { return definition; }

@Override
public String toString() {
if (this == EMPTY) {
if (this.equals(EMPTY)) {
return "pg(EMPTY)";
}
if (head == null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,9 @@ public Optional<ParseItem> resolve(final ParseGraph root) {
return findItemAtOffset(getAllRoots(root, definition), location, source).computeResult();
}

public boolean isReference() { return true; }
public ParseReference asReference() { return this; }
public Token getDefinition() { return definition; }
@Override public boolean isReference() { return true; }
@Override public ParseReference asReference() { return this; }
@Override public Token getDefinition() { return definition; }

@Override
public String toString() {
Expand Down
6 changes: 3 additions & 3 deletions core/src/main/java/io/parsingdata/metal/data/ParseValue.java
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,9 @@ public boolean matches(final String name) {
return this.name.equals(name) || this.name.endsWith(Token.SEPARATOR + name);
}

public boolean isValue() { return true; }
public ParseValue asValue() { return this; }
public Token getDefinition() { return definition; }
@Override public boolean isValue() { return true; }
@Override public ParseValue asValue() { return this; }
@Override public Token getDefinition() { return definition; }

@Override
public String toString() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,10 @@

public enum ByteOrder {

BIG_ENDIAN { public byte[] apply(final byte[] bytes) {
BIG_ENDIAN { @Override public byte[] apply(final byte[] bytes) {
return bytes.clone();
} },
LITTLE_ENDIAN { public byte[] apply(final byte[] bytes) {
LITTLE_ENDIAN { @Override public byte[] apply(final byte[] bytes) {
final byte[] output = bytes.clone();
for (int i = 0; i < bytes.length; i++) {
output[i] = bytes[(bytes.length-1)-i];
Expand Down
4 changes: 2 additions & 2 deletions core/src/main/java/io/parsingdata/metal/token/Until.java
Original file line number Diff line number Diff line change
Expand Up @@ -101,8 +101,8 @@ private Trampoline<Optional<ParseState>> handleInterval(final Environment enviro

private Trampoline<Optional<ParseState>> iterate(final Environment environment, final BigInteger currentSize, final BigInteger stepSize, final BigInteger maxSize) {
if (stepSize.compareTo(ZERO) == 0 ||
stepSize.compareTo(ZERO) > 0 && currentSize.compareTo(maxSize) > 0 ||
stepSize.compareTo(ZERO) < 0 && currentSize.compareTo(maxSize) < 0) {
(stepSize.compareTo(ZERO) > 0 && currentSize.compareTo(maxSize) > 0) ||
(stepSize.compareTo(ZERO) < 0 && currentSize.compareTo(maxSize) < 0)) {
return complete(Util::failure);
}
return environment.parseState
Expand Down
46 changes: 25 additions & 21 deletions core/src/test/java/io/parsingdata/metal/AutoEqualityTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -154,27 +154,31 @@ public class AutoEqualityTest {
private static final List<Supplier<Object>> BIG_INTEGERS = Arrays.asList(() -> ONE, () -> BigInteger.valueOf(3));
private static final List<Supplier<Object>> PARSE_STATES = Arrays.asList(() -> createFromByteStream(DUMMY_STREAM), () -> createFromByteStream(DUMMY_STREAM, ONE), () -> new ParseState(GRAPH_WITH_REFERENCE, DUMMY_BYTE_STREAM_SOURCE, TEN));
private static final List<Supplier<Object>> IMMUTABLE_LISTS = Arrays.asList(ImmutableList::new, () -> ImmutableList.create("TEST"), () -> ImmutableList.create(1), () -> ImmutableList.create(1).add(2));
private static final Map<Class, List<Supplier<Object>>> mapping = new HashMap<Class, List<Supplier<Object>>>() {{
put(String.class, STRINGS);
put(Encoding.class, ENCODINGS);
put(Token.class, TOKENS);
put(Token[].class, TOKEN_ARRAYS);
put(ValueExpression.class, VALUE_EXPRESSIONS);
put(Expression.class, EXPRESSIONS);
put(Value.class, VALUES);
put(BinaryOperator.class, REDUCERS);
put(Slice.class, SLICES);
put(byte[].class, BYTE_ARRAYS);
put(Source.class, SOURCES);
put(long.class, LONGS);
put(int.class, INTEGERS);
put(ParseGraph.class, PARSE_GRAPHS);
put(ParseItem.class, PARSE_ITEMS);
put(ByteStream.class, BYTE_STREAMS);
put(BigInteger.class, BIG_INTEGERS);
put(ParseState.class, PARSE_STATES);
put(ImmutableList.class, IMMUTABLE_LISTS);
}};
private static final Map<Class, List<Supplier<Object>>> mapping = buildMap();

private static Map<Class, List<Supplier<Object>>> buildMap() {
final Map<Class, List<Supplier<Object>>> result = new HashMap<>();
result.put(String.class, STRINGS);
result.put(Encoding.class, ENCODINGS);
result.put(Token.class, TOKENS);
result.put(Token[].class, TOKEN_ARRAYS);
result.put(ValueExpression.class, VALUE_EXPRESSIONS);
result.put(Expression.class, EXPRESSIONS);
result.put(Value.class, VALUES);
result.put(BinaryOperator.class, REDUCERS);
result.put(Slice.class, SLICES);
result.put(byte[].class, BYTE_ARRAYS);
result.put(Source.class, SOURCES);
result.put(long.class, LONGS);
result.put(int.class, INTEGERS);
result.put(ParseGraph.class, PARSE_GRAPHS);
result.put(ParseItem.class, PARSE_ITEMS);
result.put(ByteStream.class, BYTE_STREAMS);
result.put(BigInteger.class, BIG_INTEGERS);
result.put(ParseState.class, PARSE_STATES);
result.put(ImmutableList.class, IMMUTABLE_LISTS);
return result;
}

@Parameterized.Parameters(name="{0}")
public static Collection<Object[]> data() throws IllegalAccessException, InvocationTargetException, InstantiationException {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,7 @@ void assertAllHandled() {
}
}

private class CountingCallback implements Callback {
private static class CountingCallback implements Callback {
private int successCount = 0;
private int failureCount = 0;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -301,7 +301,7 @@ public void getAllRootsMultiSub() throws IOException {
}
}

private class CustomToken extends Token {
private static class CustomToken extends Token {

public final Token token;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ private GUID() {}
* @return expression to use as predicate
*/
public static ValueExpression guid(final String guid) {
final String[] parts = checkNotNull(guid, "guid").split("-");
final String[] parts = checkNotNull(guid, "guid").split("-", -1);
if (parts.length != 5) {
throw new IllegalArgumentException("Invalid GUID string: " + guid);
}
Expand Down
27 changes: 27 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,9 @@
<source-plugin.version>3.0.1</source-plugin.version>
<pitest-maven.version>1.2.4</pitest-maven.version>
<maven-jar-plugin.version>3.0.2</maven-jar-plugin.version>
<errorprone.maven.compiler.version>3.3</errorprone.maven.compiler.version>
<errorprone.plexus.javac.version>2.8.3</errorprone.plexus.javac.version>
<errorprone.core.version>2.3.1</errorprone.core.version>
</properties>

<profiles>
Expand Down Expand Up @@ -98,6 +101,30 @@

<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>${errorprone.maven.compiler.version}</version>
<configuration>
<compilerId>javac-with-errorprone</compilerId>
<forceJavacCompilerUse>true</forceJavacCompilerUse>
<showWarnings>true</showWarnings>
</configuration>
<dependencies>
<dependency>
<groupId>org.codehaus.plexus</groupId>
<artifactId>plexus-compiler-javac-errorprone</artifactId>
<version>${errorprone.plexus.javac.version}</version>
</dependency>
<!-- override plexus-compiler-javac-errorprone's dependency on
Error Prone with the latest version -->
<dependency>
<groupId>com.google.errorprone</groupId>
<artifactId>error_prone_core</artifactId>
<version>${errorprone.core.version}</version>
</dependency>
</dependencies>
</plugin>
<plugin>
<groupId>org.sonatype.plugins</groupId>
<artifactId>nexus-staging-maven-plugin</artifactId>
Expand Down

0 comments on commit f432c33

Please sign in to comment.