Fix checkstyle violations
This commit is contained in:
parent
0fcf9822a9
commit
d60e201502
7 changed files with 54 additions and 17 deletions
|
|
@ -30,7 +30,8 @@ import java.lang.annotation.RetentionPolicy;
|
|||
import java.lang.annotation.Target;
|
||||
|
||||
/**
|
||||
* Used to specify min and max values of numerical {@link com.intellectualsites.commands.components.parser.ComponentParser parsers}
|
||||
* Used to specify min and max values of numerical
|
||||
* {@link com.intellectualsites.commands.components.parser.ComponentParser parsers}
|
||||
*/
|
||||
@Retention(RetentionPolicy.RUNTIME)
|
||||
@Target(ElementType.PARAMETER)
|
||||
|
|
|
|||
|
|
@ -0,0 +1,29 @@
|
|||
//
|
||||
// MIT License
|
||||
//
|
||||
// Copyright (c) 2020 Alexander Söderberg
|
||||
//
|
||||
// Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
// of this software and associated documentation files (the "Software"), to deal
|
||||
// in the Software without restriction, including without limitation the rights
|
||||
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
// copies of the Software, and to permit persons to whom the Software is
|
||||
// furnished to do so, subject to the following conditions:
|
||||
//
|
||||
// The above copyright notice and this permission notice shall be included in all
|
||||
// copies or substantial portions of the Software.
|
||||
//
|
||||
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
// SOFTWARE.
|
||||
//
|
||||
|
||||
/**
|
||||
* Standard annotations used to match {@link com.intellectualsites.commands.components.parser.ComponentParser}
|
||||
* in {@link com.intellectualsites.commands.components.parser.ParserRegistry}
|
||||
*/
|
||||
package com.intellectualsites.commands.annotations.specifier;
|
||||
|
|
@ -76,8 +76,8 @@ public class ParserParameter<T> {
|
|||
return false;
|
||||
}
|
||||
final ParserParameter<?> that = (ParserParameter<?>) o;
|
||||
return Objects.equals(key, that.key) &&
|
||||
Objects.equals(expectedType, that.expectedType);
|
||||
return Objects.equals(key, that.key)
|
||||
&& Objects.equals(expectedType, that.expectedType);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
|||
|
|
@ -36,9 +36,6 @@ public final class ParserParameters {
|
|||
|
||||
private final Map<ParserParameter<?>, Object> internalMap = Maps.newHashMap();
|
||||
|
||||
public ParserParameters() {
|
||||
}
|
||||
|
||||
/**
|
||||
* Get an empty {@link ParserParameters} instance
|
||||
*
|
||||
|
|
|
|||
|
|
@ -50,8 +50,8 @@ public interface ParserRegistry<C extends CommandSender> {
|
|||
* to configure the parser, many of which are documented in {@link StandardParameters}
|
||||
* @param <T> Generic type specifying what is produced by the parser
|
||||
*/
|
||||
<T> void registerParserSupplier(@Nonnull final TypeToken<T> type,
|
||||
@Nonnull final Function<ParserParameters, ComponentParser<C, ?>> supplier);
|
||||
<T> void registerParserSupplier(@Nonnull TypeToken<T> type,
|
||||
@Nonnull Function<ParserParameters, ComponentParser<C, ?>> supplier);
|
||||
|
||||
/**
|
||||
* Register a mapper that maps annotation instances to a map of parameter-object pairs
|
||||
|
|
@ -62,8 +62,8 @@ public interface ParserRegistry<C extends CommandSender> {
|
|||
* @param <A> Annotation type
|
||||
* @param <T> Type of the object that the parser is retrieved for
|
||||
*/
|
||||
<A extends Annotation, T> void registerAnnotationMapper(@Nonnull final Class<A> annotation,
|
||||
@Nonnull final BiFunction<A, TypeToken<?>,
|
||||
<A extends Annotation, T> void registerAnnotationMapper(@Nonnull Class<A> annotation,
|
||||
@Nonnull BiFunction<A, TypeToken<?>,
|
||||
ParserParameters> mapper);
|
||||
|
||||
/**
|
||||
|
|
@ -74,7 +74,7 @@ public interface ParserRegistry<C extends CommandSender> {
|
|||
* @return Parsed parameters
|
||||
*/
|
||||
@Nonnull
|
||||
ParserParameters parseAnnotations(@Nonnull final TypeToken<?> parsingType, @Nonnull final Collection<? extends Annotation> annotations);
|
||||
ParserParameters parseAnnotations(@Nonnull TypeToken<?> parsingType, @Nonnull Collection<? extends Annotation> annotations);
|
||||
|
||||
/**
|
||||
* Attempt to create a {@link ComponentParser} for a specified type, using
|
||||
|
|
@ -86,7 +86,7 @@ public interface ParserRegistry<C extends CommandSender> {
|
|||
* @return Parser, if one can be created
|
||||
*/
|
||||
@Nonnull
|
||||
<T> Optional<ComponentParser<C, T>> createParser(@Nonnull final TypeToken<T> type,
|
||||
@Nonnull final ParserParameters parserParameters);
|
||||
<T> Optional<ComponentParser<C, T>> createParser(@Nonnull TypeToken<T> type,
|
||||
@Nonnull ParserParameters parserParameters);
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -43,9 +43,9 @@ import java.util.function.Function;
|
|||
*
|
||||
* @param <C> Command sender type
|
||||
*/
|
||||
public class StandardParserRegistry<C extends CommandSender> implements ParserRegistry<C> {
|
||||
public final class StandardParserRegistry<C extends CommandSender> implements ParserRegistry<C> {
|
||||
|
||||
private static final Map<Class<?>, Class<?>> primitiveMappings = ImmutableMap.<Class<?>, Class<?>>builder()
|
||||
private static final Map<Class<?>, Class<?>> PRIMITIVE_MAPPINGS = ImmutableMap.<Class<?>, Class<?>>builder()
|
||||
.put(char.class, Character.class)
|
||||
.put(int.class, Integer.class)
|
||||
.put(short.class, Short.class)
|
||||
|
|
@ -60,6 +60,10 @@ public class StandardParserRegistry<C extends CommandSender> implements ParserRe
|
|||
private final Map<Class<? extends Annotation>, BiFunction<? extends Annotation, TypeToken<?>, ParserParameters>>
|
||||
annotationMappers = new HashMap<>();
|
||||
|
||||
/**
|
||||
* Construct a new {@link StandardParserRegistry} instance. This will also
|
||||
* register all standard annotation mappers and parser suppliers
|
||||
*/
|
||||
public StandardParserRegistry() {
|
||||
/* Register standard mappers */
|
||||
this.<Range, Number>registerAnnotationMapper(Range.class, new RangeMapper<>());
|
||||
|
|
@ -107,7 +111,7 @@ public class StandardParserRegistry<C extends CommandSender> implements ParserRe
|
|||
@Nonnull final ParserParameters parserParameters) {
|
||||
final TypeToken<?> actualType;
|
||||
if (type.isPrimitive()) {
|
||||
actualType = TypeToken.of(primitiveMappings.get(type.getRawType()));
|
||||
actualType = TypeToken.of(PRIMITIVE_MAPPINGS.get(type.getRawType()));
|
||||
} else {
|
||||
actualType = type;
|
||||
}
|
||||
|
|
@ -127,7 +131,7 @@ public class StandardParserRegistry<C extends CommandSender> implements ParserRe
|
|||
public ParserParameters apply(final Range range, final TypeToken<?> type) {
|
||||
final Class<?> clazz;
|
||||
if (type.isPrimitive()) {
|
||||
clazz = primitiveMappings.get(type.getRawType());
|
||||
clazz = PRIMITIVE_MAPPINGS.get(type.getRawType());
|
||||
} else {
|
||||
clazz = type.getRawType();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -171,6 +171,12 @@ public final class IntegerComponent<C extends CommandSender> extends CommandComp
|
|||
private final int min;
|
||||
private final int max;
|
||||
|
||||
/**
|
||||
* Construct a new integer parser
|
||||
*
|
||||
* @param min Minimum acceptable value
|
||||
* @param max Maximum acceptable value
|
||||
*/
|
||||
public IntegerParser(final int min, final int max) {
|
||||
this.min = min;
|
||||
this.max = max;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue