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

Implement error-prone for basic analysis #2344

Merged
merged 1 commit into from
May 8, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
18 changes: 18 additions & 0 deletions build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import net.ltgt.gradle.errorprone.errorprone

plugins {
`java-library`
`maven-publish`
Expand All @@ -6,6 +8,7 @@ plugins {
id("org.spongepowered.gradle.event-impl-gen")
id("org.cadixdev.licenser")
id("org.jetbrains.gradle.plugin.idea-ext")
id("net.ltgt.errorprone")
}

repositories {
Expand Down Expand Up @@ -38,6 +41,8 @@ val ap by sourceSets.registering {

// Project dependencies
dependencies {
val errorproneVersion: String by project

// Directly tied to what's available from Minecraft
api("org.apache.logging.log4j:log4j-api:2.8.1")
api("com.google.guava:guava:21.0") {
Expand Down Expand Up @@ -111,6 +116,13 @@ dependencies {
exclude(group = "com.google.inject", module = "guice")
}

// Compile-time static analysis
compileOnly("com.google.errorprone:error_prone_annotations:$errorproneVersion")
errorprone("com.google.errorprone:error_prone_core:$errorproneVersion")
if (!JavaVersion.current().isJava9Compatible) { // for building with JDK 8
errorproneJavac("com.google.errorprone:javac:9+181-r4173-1")
}

// Math library
api("org.spongepowered:math:2.0.0-SNAPSHOT")

Expand Down Expand Up @@ -192,6 +204,12 @@ tasks {
if (JavaVersion.current().isJava10Compatible) {
options.release.set(8)
}

options.errorprone {
disable("FutureReturnValueIgnored") // this check doesn't handle CompletableFuture properly
disable("EqualsGetClass") // conflicts with IntelliJ defaults
disable("MissingSummary") // TODO: Re-enable this check once Javadoc is in a better state
}
}

test {
Expand Down
2 changes: 2 additions & 0 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,5 @@ projectUrl=https://www.spongepowered.org
projectDescription=A plugin API for Minecraft: Java Edition

org.gradle.parallel=true

errorproneVersion=2.6.0
1 change: 1 addition & 0 deletions settings.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,6 @@ pluginManagement {
id("org.spongepowered.gradle.event-impl-gen") version "7.0.0"
id("org.cadixdev.licenser") version "0.6.0"
id("org.jetbrains.gradle.plugin.idea-ext") version "1.0"
id("net.ltgt.errorprone") version "2.0.1"
}
}
1 change: 1 addition & 0 deletions src/main/java/org/spongepowered/api/ResourceKey.java
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,7 @@ default Builder namespace(PluginContainer container) {
* @return The built resource key
* @throws IllegalStateException If {@link Builder#namespace(String)} or {@link Builder#value(String)} are not set.
*/
@Override
ResourceKey build() throws IllegalStateException;
}

Expand Down
1 change: 1 addition & 0 deletions src/main/java/org/spongepowered/api/ResourceKeyed.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@

public interface ResourceKeyed extends Keyed {

@Override
ResourceKey key();

}
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,7 @@ default Builder icon(ItemStack itemStack) {
*
* @return The display info
*/
@Override
DisplayInfo build();

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,7 @@ interface BaseBuilder<T extends AdvancementCriterion, B extends BaseBuilder<T, B
*
* @return The criterion
*/
@Override
T build();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ interface Builder<C extends FilteredTriggerConfiguration> extends org.spongepowe
*
* @return The trigger
*/
@Override
FilteredTrigger<C> build();
}

Expand Down
4 changes: 2 additions & 2 deletions src/main/java/org/spongepowered/api/adventure/Audiences.java
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ public static Audience server() {
* @return An audience
*/
public static Audience onlinePlayers() {
return Sponge.game().factoryProvider().provide(Factory.class).onlinePlayers();
return Audiences.factory().onlinePlayers();
}

/**
Expand All @@ -61,7 +61,7 @@ public static Audience onlinePlayers() {
*/
public static Audience withPermission(final String permission) {
Objects.requireNonNull(permission);
return Sponge.game().factoryProvider().provide(Factory.class).withPermission(permission);
return Audiences.factory().withPermission(permission);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,7 @@ default Builder blockEntity(Supplier<? extends BlockEntityType> type) {
*
* @return The new instance
*/
@Override
BlockEntityArchetype build();

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ public boolean equals(final Object obj) {
final BlockTransaction other = (BlockTransaction) obj;
return Objects.equals(this.original(), other.original())
&& Objects.equals(this.defaultReplacement(), other.defaultReplacement())
&& Objects.equals(this.isValid(), other.isValid())
&& this.isValid() == other.isValid()
&& Objects.equals(this.custom(), other.custom())
&& Objects.equals(this.operation, other.operation);
}
Expand Down
3 changes: 2 additions & 1 deletion src/main/java/org/spongepowered/api/command/Command.java
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ default Optional<Component> help(@NonNull final CommandCause cause) {
* Gets the usage string of this command.
*
* <p>A usage string may look like
* {@code [&lt;world&gt;] &lt;var1&gt; &lt;var2&gt;}.</p>
* {@code [<world>] <var1> <var2>}.</p>
*
* <p>The string must not contain the command alias.</p>
*
Expand Down Expand Up @@ -606,6 +606,7 @@ default Builder shortDescription(@Nullable final Component description) {
* @return The command, ready for registration
* @throws IllegalStateException if the builder is not complete
*/
@Override
Command.Parameterized build();

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -257,6 +257,7 @@ default List<Object> all() {
*
* @return The {@link Subject} responsible, if any.
*/
@Override
Subject subject();

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,7 @@ interface Builder extends org.spongepowered.api.util.Builder<CommandResult, Buil
*
* @return A CommandResult with the specified settings
*/
@Override
CommandResult build();

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
* </p>
*
* <pre> {@code
* final Parameter.Value&lt;ServerPlayer&gt; parameter = Parameter.player().setKey("player").build();
* final Parameter.Value<ServerPlayer> parameter = Parameter.player().setKey("player").build();
* final Command.Parameterized builder = Command.builder()
* .parameter(parameter)
* .executor(context -> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1255,6 +1255,7 @@ default <V extends ValueParser<? extends T>> Builder<T> addParser(@NonNull final
*
* @return The {@link Parameter}
*/
@Override
Parameter.Value<T> build();

}
Expand Down Expand Up @@ -1311,6 +1312,7 @@ interface Builder extends org.spongepowered.api.util.Builder<Subcommand, Builder
*
* @return The {@link Subcommand}
*/
@Override
Subcommand build();

}
Expand Down Expand Up @@ -1395,6 +1397,7 @@ default SequenceBuilder then(@NonNull final Iterable<Parameter> parameters) {
*
* @return The {@link Parameter}
*/
@Override
Multi build();

}
Expand Down Expand Up @@ -1467,6 +1470,7 @@ default FirstOfBuilder orFirstOf(@NonNull final Iterable<Parameter> parameters)
*
* @return The {@link Multi}
*/
@Override
Multi build();

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,7 @@ default Builder aliases(final String... aliases) {
* @return A {@link Flag}
* @throws IllegalStateException if no key or no alias is specified
*/
@Override
Flag build() throws IllegalStateException;

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -294,6 +294,7 @@ public interface RegistryEntryBuilder<T> extends Builder<ValueParameter<T>, Regi
*
* @return The {@link ValueParameter}
*/
@Override
ValueParameter<T> build();

}
Expand Down Expand Up @@ -367,6 +368,7 @@ default StaticChoicesBuilder<T> addChoices(final Map<String, ? extends T> choice
* @return The {@link ValueParameter}
* @throws IllegalStateException if no choices have been specified
*/
@Override
ValueParameter<T> build();

}
Expand Down Expand Up @@ -424,6 +426,7 @@ public interface DynamicChoicesBuilder<T> extends Builder<ValueParameter<T>, Dyn
* @return The {@link ValueParameter}
* @throws IllegalStateException if no choices have been specified
*/
@Override
ValueParameter<T> build();

}
Expand Down Expand Up @@ -483,6 +486,7 @@ default LiteralBuilder<T> returnValue(final T returnValue) {
* @throws IllegalStateException if the literal and the return object
* have not been specified
*/
@Override
ValueParameter<T> build();

}
Expand Down Expand Up @@ -533,6 +537,7 @@ public interface TextBuilder extends Builder<ValueParameter<Component>, TextBuil
* @throws IllegalStateException if the {@link ComponentSerializer} has not
* been specified
*/
@Override
ValueParameter<Component> build() throws IllegalStateException;

}
Expand Down Expand Up @@ -572,6 +577,7 @@ public interface NumberRangeBuilder<T extends Number> extends Builder<ValueParam
* @throws IllegalStateException if the minimum is greater than the
* maximum
*/
@Override
ValueParameter<T> build();

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -476,6 +476,7 @@ interface Builder extends org.spongepowered.api.util.Builder<Selector, Builder>
* @throws IllegalStateException if the builder could not create a
* selector
*/
@Override
Selector build() throws IllegalStateException;

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -699,6 +699,7 @@ public Builder absorbResult(final DataTransactionResult result) {
*
* @return The newly created transaction result
*/
@Override
public DataTransactionResult build() {
if (this.resultType == null) {
throw new IllegalStateException("ResultType must be set!");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,5 +46,6 @@ public interface ImmutableDataProviderBuilder<H extends DataHolder, V extends Va

ImmutableDataProviderBuilder<H, V, E> supports(final Function<H, Boolean> supports);

@Override
DataProvider<? extends Value<E>, E> build();
}
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,7 @@ interface Builder<V> extends org.spongepowered.api.util.Builder<KeyValueMatcher<
*
* @return The key value matcher
*/
@Override
KeyValueMatcher<V> build();
}
}
9 changes: 6 additions & 3 deletions src/main/java/org/spongepowered/api/data/Keys.java
Original file line number Diff line number Diff line change
Expand Up @@ -1007,11 +1007,14 @@ public final class Keys {
*
* <p>The format of the rotation is represented by:</p>
*
* <ul><li>{@code x -&gt; pitch</code></li><li> <code>y -&gt; yaw</code></li><li><code>z -&gt; roll
* }</li></ul>
* <ul>
* <li>{@code x -> pitch}</li>
* <li> {@code y -> yaw}</li>
* <li>{@code z -> roll}</li>
* </ul>
*
* <p>Note that the pitch will be the same x value returned by
* {@link Entity#rotation ()} and Minecraft does not currently support
* {@link Entity#rotation()} and Minecraft does not currently support
* head roll so the z value will always be zero.</p>
*/
public static final Key<Value<Vector3d>> HEAD_ROTATION = Keys.key(ResourceKey.sponge("head_rotation"), TypeTokens.VECTOR_3D_VALUE_TOKEN);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,5 +63,6 @@ public interface MutableDataProviderBuilder<H extends DataHolder.Mutable, V exte

MutableDataProviderBuilder<H, V, E> supports(final Function<H, Boolean> supports);

@Override
DataProvider<V, E> build();
}
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ public interface SerializableDataHolder extends DataSerializable, CopyableDataHo
@Override
SerializableDataHolder copy();

interface Mutable extends SerializableDataHolder, CopyableDataHolder.Mutable {
interface Mutable extends SerializableDataHolder, DataHolder.Mutable {

/**
* Attempts to set all data of this {@link DataHolder} according to the
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/org/spongepowered/api/data/Transaction.java
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ public int hashCode() {

@SuppressWarnings("rawtypes")
@Override
public boolean equals(Object obj) {
public boolean equals(final @Nullable Object obj) {
if (this == obj) {
return true;
}
Expand All @@ -185,7 +185,7 @@ public boolean equals(Object obj) {
final Transaction other = (Transaction) obj;
return Objects.equals(this.original, other.original)
&& Objects.equals(this.defaultReplacement, other.defaultReplacement)
&& Objects.equals(this.valid, other.valid)
&& this.valid == other.valid
&& Objects.equals(this.custom, other.custom);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,7 @@ default Builder color(Supplier<? extends DyeColor> color) {
*
* @return The new pattern layer
*/
@Override
BannerPatternLayer build();

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -350,6 +350,7 @@ default Optional<List<ResourceKey>> getResourceKeyList(final DataQuery path) {
try {
keys.add(ResourceKey.resolve(s));
} catch (final Exception ignored) {
// skip invalid keys
}
}

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

import static org.spongepowered.api.data.persistence.DataQuery.of;

@SuppressWarnings("BadImport")
public final class Queries {

// Content version
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,7 @@ default Builder quantity(int quantity) throws IllegalArgumentException {
*
* @return A new instance of a ParticleEffect
*/
@Override
ParticleEffect build();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,7 @@ default Builder potionType(Supplier<? extends PotionEffectType> potionEffectType
* @return A new instance of a PotionEffect
* @throws IllegalStateException If the potion effect is not completed
*/
@Override
PotionEffect build() throws IllegalStateException;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ public abstract class AbstractGoal<O extends Agent> implements Goal<O> {
*
* @param type The type
*/
public AbstractGoal(GoalType type) {
protected AbstractGoal(final GoalType type) {
Objects.requireNonNull(type);
this.type = type;
}
Expand Down
Loading