Skip to content
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

Introduce Error Prone #712

Merged
merged 56 commits into from
May 31, 2018
Merged
Show file tree
Hide file tree
Changes from 54 commits
Commits
Show all changes
56 commits
Select commit Hold shift + click to select a range
ca3791b
Add Error Prone compiler
alexander-yevsyukov May 22, 2018
a31f735
Change `Nullable`, address some ret. vals
alexander-yevsyukov May 22, 2018
cdd6f28
Handle ignored return values
alexander-yevsyukov May 22, 2018
6a287f4
Handle checking return values
alexander-yevsyukov May 23, 2018
3c8ba11
Handle checking return values
alexander-yevsyukov May 23, 2018
9243298
Extract variable
alexander-yevsyukov May 23, 2018
a963623
Use `Nullable` from the Checker framework
alexander-yevsyukov May 24, 2018
d519c98
Fix using generic param as qualifier
alexander-yevsyukov May 24, 2018
a3c5013
Handle return values
alexander-yevsyukov May 24, 2018
9b3849c
Handle ignored return values
alexander-yevsyukov May 26, 2018
1692180
Handle ignored return values
alexander-yevsyukov May 26, 2018
0980153
Handle ignored return values
alexander-yevsyukov May 27, 2018
86c9ae0
Handle ignored return values
alexander-yevsyukov May 27, 2018
95e2f77
Handle ignored return values
alexander-yevsyukov May 27, 2018
4721160
Fix tests
alexander-yevsyukov May 27, 2018
6b27e92
Fix test
alexander-yevsyukov May 27, 2018
9eb65ce
Fix test
alexander-yevsyukov May 28, 2018
735dd14
Fix tests
alexander-yevsyukov May 28, 2018
e50ddd3
Fix tests
alexander-yevsyukov May 28, 2018
1805508
Merge remote-tracking branch 'remotes/origin/master' into error-prone
alexander-yevsyukov May 28, 2018
f50ab3f
Merge remote-tracking branch 'remotes/origin/master' into error-prone
alexander-yevsyukov May 28, 2018
474130f
Improve code layout
alexander-yevsyukov May 28, 2018
8fdda34
Optimize imports
alexander-yevsyukov May 28, 2018
116d7df
Optimize imports
alexander-yevsyukov May 28, 2018
ea04d7a
Improve code layout
alexander-yevsyukov May 30, 2018
dc646e0
Fix EOF
alexander-yevsyukov May 30, 2018
8a9ec74
Extract aggregate reading operation as a method object
alexander-yevsyukov May 30, 2018
2d153ea
Improve code layout
alexander-yevsyukov May 30, 2018
352edf0
Remove redundant `inheritDoc`
alexander-yevsyukov May 30, 2018
203a3ad
Remove unused methods
alexander-yevsyukov May 30, 2018
505821b
Fix Javadoc layout
alexander-yevsyukov May 30, 2018
ec2cab9
Improve code layout
alexander-yevsyukov May 30, 2018
425fae2
Fix code layout
alexander-yevsyukov May 30, 2018
8917a70
Allow several types of nullable annotations
alexander-yevsyukov May 30, 2018
dc9e982
Simplify work with streams
alexander-yevsyukov May 30, 2018
a243fa3
Simplify var type
alexander-yevsyukov May 30, 2018
860c0c2
Fix code layout
alexander-yevsyukov May 30, 2018
08d16b4
Improve code layout
alexander-yevsyukov May 30, 2018
621c4eb
Improve code layout
alexander-yevsyukov May 30, 2018
8b881d8
Improve code layout
alexander-yevsyukov May 30, 2018
dbb62a9
Align generic params
alexander-yevsyukov May 30, 2018
d4039d8
Improve code layout
alexander-yevsyukov May 30, 2018
5ba1a15
Add static import
alexander-yevsyukov May 30, 2018
b9f1c0f
Use streams
alexander-yevsyukov May 30, 2018
febd39e
Fix code layout
alexander-yevsyukov May 30, 2018
1bd2d02
Merge remote-tracking branch 'remotes/origin/master' into error-prone
alexander-yevsyukov May 31, 2018
1c4823d
Resolve Error Prone errors
alexander-yevsyukov May 31, 2018
6b59984
Remove some `final`s for local vars
alexander-yevsyukov May 31, 2018
6064a57
Simplify a stream op.
alexander-yevsyukov May 31, 2018
1dbaead
Extract method
alexander-yevsyukov May 31, 2018
70072bf
Remove redundant formatting calls
alexander-yevsyukov May 31, 2018
ed402e3
Use statically imported methods for streams
alexander-yevsyukov May 31, 2018
2bf51b3
Extract variables
alexander-yevsyukov May 31, 2018
c260016
Merge remote-tracking branch 'remotes/origin/master' into error-prone
alexander-yevsyukov May 31, 2018
ae3b3bf
Remove `final` var qualifier
alexander-yevsyukov May 31, 2018
e812167
Improve code layout
alexander-yevsyukov May 31, 2018
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion .idea/codeStyles/Project.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

22 changes: 12 additions & 10 deletions .idea/inspectionProfiles/Project_Default.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

37 changes: 35 additions & 2 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,12 @@ buildscript {
maven { url = sonatypeSnapshots }

jcenter()

maven { url = googleMavenCentralMirror }

// Repository for error-prone plugin.
maven { url = gradlePlugins }

mavenCentral()
mavenLocal()

Expand All @@ -50,6 +54,9 @@ buildscript {
name: 'guava',
version: guavaVersion,
changing: true
classpath ("net.ltgt.gradle:gradle-errorprone-plugin:$errorPronePluginVersion") {
exclude group: 'com.google.guava'
}
classpath("com.google.protobuf:protobuf-gradle-plugin:$protobufGradlePluginVersion") {
// exclude an old Guava version
exclude group: 'com.google.guava'
Expand All @@ -65,6 +72,14 @@ buildscript {
exclude group: 'com.google.guava'
}
}

configurations.all({
resolutionStrategy {
cacheChangingModulesFor(0, 'seconds')
force "com.google.guava:guava:$guavaVersion"
force "com.google.guava:guava-testlib:$guavaVersion"
}
})
}

apply from: 'ext.gradle'
Expand Down Expand Up @@ -143,6 +158,7 @@ subprojects {

apply plugin: 'com.google.protobuf'
apply plugin: 'java'
apply plugin: 'net.ltgt.errorprone'

// Specific setup for a Travis build,
// which prevents appearing of warning messages in build logs.
Expand Down Expand Up @@ -184,8 +200,14 @@ subprojects {
name: 'guava',
version: guavaVersion,
changing: true

//TODO:2018-05-11:alexander.yevsyukov: Replace the below with Checker Framework
// after Guava fully migrates from it too.
compile "com.google.code.findbugs:jsr305:3.0.0"

compile "org.checkerframework:checker-qual:$checkerFrameworkVersion"
compile "com.google.errorprone:error_prone_annotations:$errorProneVersion"

//As a Library, we provide logging facade API, not specific logger bindings.
//Target apps are free to use any binding they need.
compile "org.slf4j:slf4j-api:$slf4JVersion"
Expand Down Expand Up @@ -213,12 +235,16 @@ subprojects {
sourceSets {
main {
proto.srcDirs = ["$sourcesRootDir/main/proto"]
java.srcDirs = [generatedJavaDir, "$sourcesRootDir/main/java", generatedSpineDir]
java.srcDirs = [generatedJavaDir,
"$sourcesRootDir/main/java",
generatedSpineDir]
resources.srcDirs = ["$generatedRootDir/main/resources"]
}
test {
proto.srcDirs = ["$sourcesRootDir/test/proto"]
java.srcDirs = [generatedTestJavaDir, "$sourcesRootDir/test/java", generatedTestSpineDir]
java.srcDirs = [generatedTestJavaDir,
"$sourcesRootDir/test/java",
generatedTestSpineDir]
resources.srcDirs = ["$generatedRootDir/test/resources"]
}
}
Expand Down Expand Up @@ -290,6 +316,13 @@ subprojects {
source = sourceSets.main.allJava
}

tasks.withType(JavaCompile) {
// Exclude generated sources from being analyzed by Error Prone.
options.compilerArgs += [
'-XepExcludedPaths:.*/generated/.*'
]
}

task sourceJar(type: Jar) {
from sourceSets.main.allJava
classifier "sources"
Expand Down
41 changes: 20 additions & 21 deletions client/src/main/java/io/spine/client/ActorRequestFactory.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,7 @@
import io.spine.core.UserId;
import io.spine.time.ZoneOffset;
import io.spine.time.ZoneOffsets;

import javax.annotation.Nullable;
import org.checkerframework.checker.nullness.qual.Nullable;

import static com.google.common.base.Preconditions.checkNotNull;
import static io.spine.base.Time.getCurrentTime;
Expand All @@ -53,8 +52,7 @@ public class ActorRequestFactory {
*
* <p>This field is null in a single tenant application.
*/
@Nullable
private final TenantId tenantId;
private final @Nullable TenantId tenantId;

protected ActorRequestFactory(Builder builder) {
this.actor = builder.actor;
Expand All @@ -74,8 +72,7 @@ public ZoneOffset getZoneOffset() {
return zoneOffset;
}

@Nullable
public TenantId getTenantId() {
public @Nullable TenantId getTenantId() {
return tenantId;
}

Expand All @@ -86,10 +83,11 @@ public TenantId getTenantId() {
* @return new factory at new time zone
*/
public ActorRequestFactory switchTimezone(ZoneOffset zoneOffset) {
final ActorRequestFactory result = newBuilder().setActor(getActor())
.setZoneOffset(zoneOffset)
.setTenantId(getTenantId())
.build();
ActorRequestFactory result =
newBuilder().setActor(getActor())
.setZoneOffset(zoneOffset)
.setTenantId(getTenantId())
.build();
return result;
}

Expand Down Expand Up @@ -137,11 +135,13 @@ protected CommandContext createCommandContext() {
* <p>Sets the timestamp value to the
* {@linkplain io.spine.base.Time#getCurrentTime() current time}.
*/
@SuppressWarnings("CheckReturnValue") // calling builder
ActorContext actorContext() {
final ActorContext.Builder builder = ActorContext.newBuilder()
.setActor(actor)
.setTimestamp(getCurrentTime())
.setZoneOffset(zoneOffset);
ActorContext.Builder builder = ActorContext
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@dmdashenkov, it's the new layout for calling builders. In Java 11, we'd have var instead of type.

.newBuilder()
.setActor(actor)
.setTimestamp(getCurrentTime())
.setZoneOffset(zoneOffset);
if (tenantId != null) {
builder.setTenantId(tenantId);
}
Expand All @@ -157,8 +157,7 @@ public static class Builder {

private ZoneOffset zoneOffset;

@Nullable
private TenantId tenantId;
private @Nullable TenantId tenantId;

public UserId getActor() {
return actor;
Expand All @@ -169,13 +168,13 @@ public UserId getActor() {
*
* @param actor the ID of the user generating commands
*/
@CanIgnoreReturnValue
public Builder setActor(UserId actor) {
this.actor = checkNotNull(actor);
return this;
}

@Nullable
public ZoneOffset getZoneOffset() {
public @Nullable ZoneOffset getZoneOffset() {
return zoneOffset;
}

Expand All @@ -184,13 +183,13 @@ public ZoneOffset getZoneOffset() {
*
* @param zoneOffset the offset of the timezone the user works in
*/
@CanIgnoreReturnValue
public Builder setZoneOffset(ZoneOffset zoneOffset) {
this.zoneOffset = checkNotNull(zoneOffset);
return this;
}

@Nullable
public TenantId getTenantId() {
public @Nullable TenantId getTenantId() {
return tenantId;
}

Expand All @@ -199,6 +198,7 @@ public TenantId getTenantId() {
*
* @param tenantId the ID of the tenant or null for single-tenant applications
*/
@CanIgnoreReturnValue
public Builder setTenantId(@Nullable TenantId tenantId) {
this.tenantId = tenantId;
return this;
Expand All @@ -211,7 +211,6 @@ public Builder setTenantId(@Nullable TenantId tenantId) {
*
* @return {@code null}
*/
@SuppressWarnings("ReturnOfNull") // It's fine for an abstract Builder.
@CanIgnoreReturnValue
public ActorRequestFactory build() {
checkNotNull(actor, "`actor` must be defined");
Expand Down
Loading