Skip to content

Commit

Permalink
Enable more errorprone rules for criteria module (and clean lots of c…
Browse files Browse the repository at this point in the history
…ode as consequence)

Helped cleanup quite a bit (both generated and library)

List of rules:
-Xep:BadImport:ERROR
-Xep:MissingOverride:ERROR
-Xep:OrphanedFormatString:ERROR
-Xep:RedundantOverride:ERROR
-Xep:RedundantThrows:ERROR
-Xep:RemoveUnusedImports:ERROR
  • Loading branch information
asereda-gs committed Oct 20, 2019
1 parent f97e223 commit 7e736f0
Show file tree
Hide file tree
Showing 26 changed files with 33 additions and 114 deletions.
35 changes: 9 additions & 26 deletions criteria/common/src/org/immutables/criteria/expression/Query.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,13 @@
/**
* Query which is composed of predicates, projections, limit, offset, group by and order by expressions.
*/
@Value.Style(visibility = Value.Style.ImplementationVisibility.PACKAGE)
@Value.Immutable
public abstract class Query {

public static ImmutableQuery of(Class<?> entityClass) {
return ImmutableQuery.of(entityClass);
}

@Value.Parameter
public abstract Class<?> entityClass();

Expand Down Expand Up @@ -68,46 +71,26 @@ public boolean hasAggregations() {
return !groupBy().isEmpty() || projections().stream().anyMatch(p -> p instanceof AggregationCall);
}

public static Query of(Class<?> entityClass) {
return ImmutableQuery.of(entityClass);
}

public Query withFilter(Expression filter) {
return ImmutableQuery.copyOf(this).withFilter(filter);
}

public Query addCollations(Iterable<Collation> collations) {
public ImmutableQuery addCollations(Iterable<Collation> collations) {
return ImmutableQuery.builder().from(this).addAllCollations(collations).build();
}

public Query addProjections(Expression ... projections) {
public ImmutableQuery addProjections(Expression ... projections) {
return ImmutableQuery.builder().from(this).addProjections(projections).build();
}

public Query addProjections(Iterable<Expression> projections) {
public ImmutableQuery addProjections(Iterable<Expression> projections) {
return ImmutableQuery.builder().from(this).addAllProjections(projections).build();
}

public Query addGroupBy(Iterable<Expression> groupBy) {
public ImmutableQuery addGroupBy(Iterable<Expression> groupBy) {
return ImmutableQuery.builder().from(this).addAllGroupBy(groupBy).build();
}

public Query addGroupBy(Expression ... groupBy) {
public ImmutableQuery addGroupBy(Expression ... groupBy) {
return ImmutableQuery.builder().from(this).addGroupBy(groupBy).build();
}

public Query withCount(boolean count) {
return ImmutableQuery.builder().from(this).count(count).build();
}

public Query withOffset(long offset) {
return ImmutableQuery.copyOf(this).withOffset(offset);
}

public Query withLimit(long limit) {
return ImmutableQuery.copyOf(this).withLimit(limit);
}

@Override
public String toString() {
final StringWriter string = new StringWriter();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

import org.immutables.criteria.expression.Expression;
import org.immutables.criteria.expression.Expressions;
import org.immutables.criteria.expression.ImmutableQuery;
import org.immutables.criteria.expression.Path;
import org.immutables.criteria.expression.Query;
import org.immutables.criteria.expression.Queryable;
Expand Down Expand Up @@ -123,7 +124,7 @@ private DnfExpression dnfExpression() {

@Override
public Query query() {
final Query query = Query.of(entityClass);
final ImmutableQuery query = Query.of(entityClass);
Expression expression = expression();
if (expression instanceof DnfExpression) {
DnfExpression dnfExpression = dnfExpression();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@
package org.immutables.criteria.matcher;

import org.immutables.criteria.Criterion;
import org.immutables.criteria.expression.Expression;
import org.immutables.criteria.expression.Expressions;
import org.immutables.criteria.expression.Operators;

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

import org.immutables.criteria.expression.Collation;
import org.immutables.criteria.expression.Expression;
import org.immutables.criteria.expression.ImmutableQuery;
import org.immutables.criteria.expression.Ordering;
import org.immutables.criteria.expression.Query;
import org.immutables.criteria.matcher.Matchers;
Expand All @@ -35,10 +36,11 @@
*/
public abstract class AbstractReader<R extends Reader<R>> implements Reader<R> {

private final Query query;
private final ImmutableQuery query;

protected AbstractReader(Query query) {
this.query = Objects.requireNonNull(query, "query");
Objects.requireNonNull(query, "query");
this.query = ImmutableQuery.copyOf(query);
}

protected abstract R newReader(Query query);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,6 @@
import com.google.common.collect.ImmutableList;
import org.immutables.criteria.Criterion;

import java.util.Arrays;

/**
* Declares repository as writable. Means documents can be inserted / updated / deleted.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import org.immutables.criteria.backend.NonUniqueResultException;
import org.immutables.criteria.backend.ProjectedTuple;
import org.immutables.criteria.backend.StandardOperations;
import org.immutables.criteria.expression.ImmutableQuery;
import org.immutables.criteria.expression.Query;
import org.immutables.criteria.matcher.Matchers;
import org.immutables.criteria.matcher.Projection;
Expand All @@ -34,11 +35,12 @@

class ReactiveFetcherDelegate<T> implements ReactiveFetcher<T> {

private final Query query;
private final ImmutableQuery query;
private final Backend.Session session;

private ReactiveFetcherDelegate(Query query, Backend.Session session) {
this.query = Objects.requireNonNull(query, "query");
Objects.requireNonNull(query, "query");
this.query = ImmutableQuery.copyOf(query);
this.session = Objects.requireNonNull(session, "session");
}

Expand Down Expand Up @@ -79,7 +81,7 @@ public Publisher<T> oneOrNone() {
}

private Publisher<T> validateAsList(Consumer<List<T>> validatorFn) {
Query query = this.query;
ImmutableQuery query = ImmutableQuery.copyOf(this.query);
if (!query.limit().isPresent()) {
// ensure at most one element
// fail if there are 2 or more
Expand All @@ -103,7 +105,7 @@ public Publisher<Boolean> exists() {

@Override
public Publisher<Long> count() {
Query newQuery = this.query.withCount(true);
Query newQuery = query.withCount(true);
return session.execute(StandardOperations.Select.of(newQuery)).publisher();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,6 @@
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;

import java.io.PrintWriter;
import java.io.StringWriter;
import java.util.Arrays;
import java.util.stream.Collectors;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,6 @@
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;

import java.io.PrintWriter;
import java.io.StringWriter;
import java.util.Arrays;
import java.util.stream.Collectors;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@

package org.immutables.criteria.backend;

import org.immutables.criteria.backend.IdResolver;
import org.immutables.criteria.javabean.JavaBean1;
import org.immutables.criteria.personmodel.Person;
import org.junit.jupiter.api.Test;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,6 @@
import org.immutables.criteria.expression.Path;
import org.junit.jupiter.api.Test;

import java.lang.reflect.Member;

import static org.immutables.check.Checkers.check;

class JavaBeanNamingTest {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@

package org.immutables.criteria.reflect;

import org.immutables.criteria.reflect.ClassScanner;
import org.junit.jupiter.api.Test;

import java.lang.reflect.Member;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
import org.junit.jupiter.api.Test;

import java.util.List;
import java.util.Objects;
import java.util.Optional;
import java.util.OptionalDouble;
import java.util.function.Supplier;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@

import java.util.List;
import java.util.Optional;
import java.util.OptionalDouble;
import java.util.OptionalInt;
import java.util.function.Supplier;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@

public interface IndexResolver extends ContainerResolver<String> {

@Override
String resolve(Class<?> entityType);

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
package org.immutables.criteria.elasticsearch;

import com.fasterxml.jackson.databind.ObjectMapper;
import com.google.common.base.Throwables;
import org.elasticsearch.client.RestClient;
import org.immutables.criteria.backend.Backend;
import org.immutables.criteria.personmodel.PersonAggregationTest;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@

package org.immutables.criteria.inmemory;

import org.immutables.criteria.personmodel.ImmutablePerson;
import org.immutables.criteria.personmodel.Person;
import org.immutables.criteria.personmodel.PersonCriteria;
import org.immutables.criteria.personmodel.PersonGenerator;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@
package org.immutables.criteria.mongo;

import org.immutables.criteria.backend.Backend;
import org.immutables.criteria.backend.PathNaming;
import org.immutables.criteria.backend.IdResolver;
import org.immutables.criteria.backend.PathNaming;

import java.util.Objects;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,13 @@
package org.immutables.criteria.mongo.bson4jackson;

import com.fasterxml.jackson.core.Base64Variant;
import com.fasterxml.jackson.core.ObjectCodec;
import com.fasterxml.jackson.core.base.GeneratorBase;
import org.bson.BsonBinary;
import org.bson.BsonWriter;
import org.bson.types.Decimal128;

import javax.annotation.concurrent.NotThreadSafe;
import java.io.IOException;
import java.io.InputStream;
import java.math.BigDecimal;
import java.math.BigInteger;
import java.util.Arrays;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@

import com.fasterxml.jackson.core.JsonGenerator;
import com.fasterxml.jackson.core.JsonParser;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.core.Version;
import com.fasterxml.jackson.databind.BeanDescription;
import com.fasterxml.jackson.databind.DeserializationConfig;
Expand Down Expand Up @@ -52,7 +51,6 @@
import org.bson.codecs.configuration.CodecRegistry;
import org.bson.conversions.Bson;

import java.io.IOException;
import java.util.Objects;
import java.util.function.Predicate;

Expand Down Expand Up @@ -98,7 +96,7 @@ private static <T> JsonDeserializer<T> deserializer(final Codec<T> codec) {
Objects.requireNonNull(codec, "codec");
return new JsonDeserializer<T>() {
@Override
public T deserialize(JsonParser parser, DeserializationContext ctxt) throws IOException, JsonProcessingException {
public T deserialize(JsonParser parser, DeserializationContext ctxt) {
@SuppressWarnings("unchecked")
final BsonReader reader = ((Wrapper<BsonReader>) parser).unwrap();
return codec.decode(reader, DecoderContext.builder().build());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ class AggregationQueryTest {

private final PersonCriteria person = PersonCriteria.person;


@Test
void basic() {
// select nickName, sum(age) from ... group by nickName
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,11 @@
import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule;
import com.google.common.collect.ImmutableList;
import org.immutables.criteria.Criteria;
import org.immutables.criteria.backend.IdResolver;
import org.immutables.criteria.javabean.JavaBean1;
import org.immutables.criteria.personmodel.ImmutablePerson;
import org.immutables.criteria.personmodel.Person;
import org.immutables.criteria.personmodel.PersonGenerator;
import org.immutables.criteria.backend.IdResolver;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.MethodSource;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
import org.bson.BsonBinaryWriter;
import org.bson.BsonDocument;
import org.bson.BsonValue;
import org.bson.BsonWriter;
import org.bson.codecs.EncoderContext;
import org.bson.codecs.configuration.CodecRegistry;
import org.bson.io.BasicOutputBuffer;
Expand Down
6 changes: 6 additions & 0 deletions criteria/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,12 @@
<compilerArgs>
<arg>-Xep:CheckReturnValue:ERROR</arg>
<arg>-Xep:MethodCanBeStatic:ERROR</arg>
<arg>-Xep:BadImport:ERROR</arg>
<arg>-Xep:MissingOverride:ERROR</arg>
<arg>-Xep:OrphanedFormatString:ERROR</arg>
<arg>-Xep:RedundantOverride:ERROR</arg>
<arg>-Xep:RedundantThrows:ERROR</arg>
<arg>-Xep:RemoveUnusedImports:ERROR</arg>
<arg>-Xlint:unchecked</arg>
</compilerArgs>
</configuration>
Expand Down
Loading

0 comments on commit 7e736f0

Please sign in to comment.