Skip to content

Commit 7fe089d

Browse files
committed
build: Add simple spotless checks for import order and annotations
1 parent 70db300 commit 7fe089d

File tree

65 files changed

+208
-181
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

65 files changed

+208
-181
lines changed

.checkstyle/checkstyle.xml

+2
Original file line numberDiff line numberDiff line change
@@ -271,6 +271,8 @@
271271
<module name="CustomImportOrder">
272272
<property name="sortImportsInGroupAlphabetically" value="true"/>
273273
<property name="separateLineBetweenGroups" value="true"/>
274+
<property name="standardPackageRegExp" value="^java\."/>
275+
<property name="specialImportsRegExp" value="^javax\."/>
274276
<!-- Sponge - Custom import order -->
275277
<property name="customImportOrderRules" value="STATIC###THIRD_PARTY_PACKAGE###STANDARD_JAVA_PACKAGE###SPECIAL_IMPORTS"/>
276278
<property name="tokens" value="IMPORT, STATIC_IMPORT, PACKAGE_DEF"/>

.editorconfig

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
root = true
2+
3+
[*]
4+
charset = utf-8
5+
end_of_line = lf
6+
indent_size = 4
7+
indent_style = space
8+
insert_final_newline = true
9+
max_line_length = 150
10+
tab_width = 4
11+
12+
[*.java]
13+
ij_java_imports_layout = $*,|,*,|,java.**,|,javax.**
14+
ij_java_insert_inner_class_imports = false
15+
ij_java_layout_static_imports_separately = true

build.gradle.kts

+18-2
Original file line numberDiff line numberDiff line change
@@ -244,7 +244,7 @@ spongeConvention {
244244

245245
indra {
246246
val checkstyleVersion: String by project
247-
247+
248248
javaVersions {
249249
testWith(8, 11, 17)
250250
}
@@ -263,6 +263,22 @@ indraCrossdoc {
263263
baseUrl(providers.gradleProperty("javadocPublishRoot"))
264264
}
265265

266+
spotless {
267+
java {
268+
endWithNewline()
269+
indentWithSpaces(4)
270+
trimTrailingWhitespace()
271+
toggleOffOn("@formatter:off", "@formatter:on")
272+
formatAnnotations()
273+
importOrderFile(rootProject.file("extra/eclipse/sponge_eclipse.importorder"))
274+
}
275+
kotlinGradle {
276+
endWithNewline()
277+
indentWithSpaces(4)
278+
trimTrailingWhitespace()
279+
}
280+
}
281+
266282
val sortClasses = listOf(
267283
"org.spongepowered.api.advancement.AdvancementTypes",
268284
"org.spongepowered.api.advancement.criteria.trigger.Triggers",
@@ -389,4 +405,4 @@ val sortClasses = listOf(
389405
"org.spongepowered.api.world.schematic.PaletteTypes",
390406
"org.spongepowered.api.world.teleport.TeleportHelperFilters",
391407
"org.spongepowered.api.world.weather.WeatherTypes"
392-
)
408+
)

src/ap/java/org/spongepowered/plugin/processor/ListenerParameterAnnotation.java

+1
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
import java.util.HashMap;
3636
import java.util.Map;
3737
import java.util.Set;
38+
3839
import javax.lang.model.element.AnnotationValue;
3940
import javax.lang.model.element.Element;
4041
import javax.lang.model.element.ElementKind;

src/ap/java/org/spongepowered/plugin/processor/ListenerProcessor.java

+1
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@
3737
import java.util.List;
3838
import java.util.Map;
3939
import java.util.Set;
40+
4041
import javax.annotation.processing.AbstractProcessor;
4142
import javax.annotation.processing.RoundEnvironment;
4243
import javax.annotation.processing.SupportedAnnotationTypes;

src/ap/java/org/spongepowered/plugin/processor/ParameterContext.java

+1
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828

2929
import java.util.Objects;
3030
import java.util.Optional;
31+
3132
import javax.annotation.processing.ProcessingEnvironment;
3233
import javax.lang.model.element.AnnotationMirror;
3334
import javax.lang.model.element.AnnotationValue;

src/ap/java/org/spongepowered/plugin/processor/ProcessorUtils.java

+1
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828

2929
import java.util.Collection;
3030
import java.util.List;
31+
3132
import javax.lang.model.element.Element;
3233
import javax.lang.model.element.ElementKind;
3334
import javax.lang.model.element.TypeElement;

src/main/java/org/spongepowered/api/ResourceKey.java

+5-8
Original file line numberDiff line numberDiff line change
@@ -74,8 +74,7 @@ public interface ResourceKey extends Key {
7474
* @param value The value
7575
* @return A new resource key
7676
*/
77-
@NonNull
78-
static ResourceKey brigadier(final String value) {
77+
static @NonNull ResourceKey brigadier(final String value) {
7978
return ResourceKey.of(ResourceKey.BRIGADIER_NAMESPACE, value);
8079
}
8180

@@ -85,8 +84,7 @@ static ResourceKey brigadier(final String value) {
8584
* @param value The value
8685
* @return A new resource key
8786
*/
88-
@NonNull
89-
static ResourceKey minecraft(final String value) {
87+
static @NonNull ResourceKey minecraft(final String value) {
9088
return ResourceKey.of(ResourceKey.MINECRAFT_NAMESPACE, value);
9189
}
9290

@@ -96,8 +94,7 @@ static ResourceKey minecraft(final String value) {
9694
* @param value The value
9795
* @return A new resource key
9896
*/
99-
@NonNull
100-
static ResourceKey sponge(final String value) {
97+
static @NonNull ResourceKey sponge(final String value) {
10198
return ResourceKey.of(ResourceKey.SPONGE_NAMESPACE, value);
10299
}
103100

@@ -166,7 +163,7 @@ default String asString() {
166163
}
167164

168165
@Override
169-
default int compareTo(Key o) {
166+
default int compareTo(final Key o) {
170167
return Key.super.compareTo(o);
171168
}
172169

@@ -195,7 +192,7 @@ interface Builder extends org.spongepowered.api.util.Builder<ResourceKey, Builde
195192
* @param container The plugin container to fetch from
196193
* @return This builder, for chaining
197194
*/
198-
default Builder namespace(PluginContainer container) {
195+
default Builder namespace(final PluginContainer container) {
199196
return this.namespace(container.metadata().id());
200197
}
201198

src/main/java/org/spongepowered/api/block/entity/BlockEntityType.java

-1
Original file line numberDiff line numberDiff line change
@@ -47,4 +47,3 @@ public interface BlockEntityType extends DefaultedRegistryValue {
4747
*/
4848
boolean isValidBlock(BlockState block);
4949
}
50-

src/main/java/org/spongepowered/api/command/parameter/CommonParameters.java

+4-4
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@
3939
* used when creating commands and retrieving elements. A general workflow for
4040
* defining a command with a {@link ServerPlayer} parameter may look like this:
4141
* </p>
42-
*
42+
*
4343
* <pre> {@code
4444
* final Parameter.Value<ServerPlayer> parameter = Parameter.player().setKey("player").build();
4545
* final Command.Parameterized builder = Command.builder()
@@ -51,9 +51,9 @@
5151
* // registration happens here.
5252
* }</pre>
5353
*
54-
* <p>While this is a totally valid approach, there are two particular
54+
* <p>While this is a totally valid approach, there are two particular
5555
* considerations that can be made:</p>
56-
*
56+
*
5757
* <ul>
5858
* <li>Sponge provided {@link ValueParameter}s and, by extension,
5959
* {@link Parameter.Value}s are stateless and so can be reused by multiple
@@ -67,7 +67,7 @@
6767
* </ul>
6868
*
6969
* <p>Given these two considerations, it generally makes sense to store one
70-
* {@link Parameter.Value} for a given {@link ValueParameter} and
70+
* {@link Parameter.Value} for a given {@link ValueParameter} and
7171
* {@link Parameter.Key} combination. Further, it is clear that plugins will
7272
* tend to use similar, if not the same, parameter/key combinations.</p>
7373
*

src/main/java/org/spongepowered/api/data/persistence/DataFormat.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ public interface DataFormat extends DefaultedRegistryValue {
4141
/**
4242
* Creates a new {@link DataContainer} from the contents of the given
4343
* {@link InputStream}.
44-
*
44+
*
4545
* @param input The input stream
4646
* @return A data container representing the contents of the input stream
4747
* @throws InvalidDataFormatException If the data in the stream was not a
@@ -53,7 +53,7 @@ public interface DataFormat extends DefaultedRegistryValue {
5353
/**
5454
* Writes the given {@link DataView} to the given {@link OutputStream} using
5555
* the format specified by this {@link DataFormat}.
56-
*
56+
*
5757
* @param output The output stream to write the data to
5858
* @param data The DataView to write to the stream
5959
* @throws IOException If there was an error writing to the stream

src/main/java/org/spongepowered/api/datapack/DataPackType.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ public interface DataPackType<T> {
4444
* is no longer present (or no longer performs a registration in {@link RegisterDataPackValueEvent}
4545
*
4646
* <p>Consult your implementation vendor for more details on exactly what resources are kept.</p>
47-
*
47+
*
4848
* @return True if persistent, false if not
4949
*/
5050
boolean persistent();

src/main/java/org/spongepowered/api/event/Cause.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -249,7 +249,7 @@ public Optional<?> after(final Class<?> clazz) {
249249

250250
/**
251251
* Returns whether the target class matches any object of this {@link Cause}.
252-
*
252+
*
253253
* @param target The class of the target type
254254
* @return True if found, false otherwise
255255
*/

src/main/java/org/spongepowered/api/event/CauseStackManager.java

+16-16
Original file line numberDiff line numberDiff line change
@@ -33,11 +33,11 @@
3333
* information for events being thrown. This allows plugins to attach more
3434
* contextual information to events which may be triggered from their api
3535
* interactions.
36-
*
36+
*
3737
* <p>For example a plugin may wish to push a player into the cause stack before
3838
* spawning an entity to expose to any plugin listening for SpawnEntityEvents
3939
* that the player is the reason that the entity was spawned.</p>
40-
*
40+
*
4141
* <p>This system will automatically handle associating a plugin with actions
4242
* performed inside of event listeners, command executors, and scheduled
4343
* tasks.</p>
@@ -46,23 +46,23 @@ public interface CauseStackManager {
4646

4747
/**
4848
* Gets the current {@link Cause} object from the current cause stack.
49-
*
49+
*
5050
* @return A cause of the current stack.
5151
*/
5252
Cause currentCause();
5353

5454
/**
5555
* Gets an {@link EventContext} object on the current contextual
5656
* information.
57-
*
57+
*
5858
* @return The current event context
5959
*/
6060
EventContext currentContext();
6161

6262
/**
6363
* Pushes an object to the current cause stack which will associate it with
6464
* all events through from api actions until it is popped off again.
65-
*
65+
*
6666
* @param obj The object to push to the stack
6767
* @return The cause stack manager, for chaining
6868
*/
@@ -71,28 +71,28 @@ public interface CauseStackManager {
7171
/**
7272
* Pops the most recently pushed cause object off of the stack and returns
7373
* it.
74-
*
74+
*
7575
* @return The last pushed object
7676
*/
7777
Object popCause();
7878

7979
/**
8080
* Pops the most recently <b>n</b> pushed cause objects off of the stack.
81-
*
81+
*
8282
* @param n The number of causes to pop
8383
*/
8484
void popCauses(int n);
8585

8686
/**
8787
* Retrieves but does not remove the most recently pushed cause object.
88-
*
88+
*
8989
* @return The last pushed object
9090
*/
9191
Object peekCause();
9292

9393
/**
9494
* Pushes a frame of the current cause stack and context state.
95-
*
95+
*
9696
* @return A handle for the frame which must be passed back to pop the frame
9797
* from the stack
9898
*/
@@ -101,19 +101,19 @@ public interface CauseStackManager {
101101
/**
102102
* Replaces the current cause stack and context with the cause frame at the
103103
* top of the frame stack.
104-
*
104+
*
105105
* <p>The frame handle is required to ensure that frames are popped of in
106106
* order and are not left in the stack. If an attempt is made to pop a frame
107107
* which is not the head of the frame stack then an error will be thrown as
108108
* this indicates that a frame was not popped properly.</p>
109-
*
109+
*
110110
* @param handle The frame handle to pop
111111
*/
112112
void popCauseFrame(StackFrame handle);
113113

114114
/**
115115
* Adds the given object to the current context under the given key.
116-
*
116+
*
117117
* @param key The context key
118118
* @param value The object
119119
* @param <T> The type of the value stored with the event context key
@@ -163,7 +163,7 @@ default <T> CauseStackManager addContext(Supplier<EventContextKey<T>> key, Suppl
163163

164164
/**
165165
* Gets the context value with the given key.
166-
*
166+
*
167167
* @param key The context key
168168
* @param <T> The type of the value stored with the event context key
169169
* @return The context object, if present
@@ -183,10 +183,10 @@ default <T> Optional<T> context(Supplier<EventContextKey<T>> key) {
183183

184184
/**
185185
* Gets the context value with the given key.
186-
*
186+
*
187187
* <p>If the key is not available, {@link NoSuchElementException} will be
188188
* thrown.</p>
189-
*
189+
*
190190
* @param key The context key
191191
* @param <T> The type of the value stored with the event context key
192192
* @return The context object, if present
@@ -220,7 +220,7 @@ default <T> T requireContext(Supplier<EventContextKey<T>> key) {
220220

221221
/**
222222
* Removes the given context key from the current context.
223-
*
223+
*
224224
* @param key The key to clear
225225
* @param <T> The type of the value stored with the event context key
226226
* @return The existing context value, if it was present

src/main/java/org/spongepowered/api/event/Event.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ public interface Event {
5656

5757
/**
5858
* Gets the source of the event (the first object in the cause).
59-
*
59+
*
6060
* @return The event source
6161
*/
6262
default Object source() {
@@ -65,7 +65,7 @@ default Object source() {
6565

6666
/**
6767
* Gets the context of the event.
68-
*
68+
*
6969
* @return The event context
7070
*/
7171
default EventContext context() {

0 commit comments

Comments
 (0)