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;
|
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)
|
@Retention(RetentionPolicy.RUNTIME)
|
||||||
@Target(ElementType.PARAMETER)
|
@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;
|
return false;
|
||||||
}
|
}
|
||||||
final ParserParameter<?> that = (ParserParameter<?>) o;
|
final ParserParameter<?> that = (ParserParameter<?>) o;
|
||||||
return Objects.equals(key, that.key) &&
|
return Objects.equals(key, that.key)
|
||||||
Objects.equals(expectedType, that.expectedType);
|
&& Objects.equals(expectedType, that.expectedType);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
||||||
|
|
@ -36,9 +36,6 @@ public final class ParserParameters {
|
||||||
|
|
||||||
private final Map<ParserParameter<?>, Object> internalMap = Maps.newHashMap();
|
private final Map<ParserParameter<?>, Object> internalMap = Maps.newHashMap();
|
||||||
|
|
||||||
public ParserParameters() {
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get an empty {@link ParserParameters} instance
|
* 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}
|
* to configure the parser, many of which are documented in {@link StandardParameters}
|
||||||
* @param <T> Generic type specifying what is produced by the parser
|
* @param <T> Generic type specifying what is produced by the parser
|
||||||
*/
|
*/
|
||||||
<T> void registerParserSupplier(@Nonnull final TypeToken<T> type,
|
<T> void registerParserSupplier(@Nonnull TypeToken<T> type,
|
||||||
@Nonnull final Function<ParserParameters, ComponentParser<C, ?>> supplier);
|
@Nonnull Function<ParserParameters, ComponentParser<C, ?>> supplier);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Register a mapper that maps annotation instances to a map of parameter-object pairs
|
* 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 <A> Annotation type
|
||||||
* @param <T> Type of the object that the parser is retrieved for
|
* @param <T> Type of the object that the parser is retrieved for
|
||||||
*/
|
*/
|
||||||
<A extends Annotation, T> void registerAnnotationMapper(@Nonnull final Class<A> annotation,
|
<A extends Annotation, T> void registerAnnotationMapper(@Nonnull Class<A> annotation,
|
||||||
@Nonnull final BiFunction<A, TypeToken<?>,
|
@Nonnull BiFunction<A, TypeToken<?>,
|
||||||
ParserParameters> mapper);
|
ParserParameters> mapper);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -74,7 +74,7 @@ public interface ParserRegistry<C extends CommandSender> {
|
||||||
* @return Parsed parameters
|
* @return Parsed parameters
|
||||||
*/
|
*/
|
||||||
@Nonnull
|
@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
|
* 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
|
* @return Parser, if one can be created
|
||||||
*/
|
*/
|
||||||
@Nonnull
|
@Nonnull
|
||||||
<T> Optional<ComponentParser<C, T>> createParser(@Nonnull final TypeToken<T> type,
|
<T> Optional<ComponentParser<C, T>> createParser(@Nonnull TypeToken<T> type,
|
||||||
@Nonnull final ParserParameters parserParameters);
|
@Nonnull ParserParameters parserParameters);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -43,9 +43,9 @@ import java.util.function.Function;
|
||||||
*
|
*
|
||||||
* @param <C> Command sender type
|
* @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(char.class, Character.class)
|
||||||
.put(int.class, Integer.class)
|
.put(int.class, Integer.class)
|
||||||
.put(short.class, Short.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>>
|
private final Map<Class<? extends Annotation>, BiFunction<? extends Annotation, TypeToken<?>, ParserParameters>>
|
||||||
annotationMappers = new HashMap<>();
|
annotationMappers = new HashMap<>();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Construct a new {@link StandardParserRegistry} instance. This will also
|
||||||
|
* register all standard annotation mappers and parser suppliers
|
||||||
|
*/
|
||||||
public StandardParserRegistry() {
|
public StandardParserRegistry() {
|
||||||
/* Register standard mappers */
|
/* Register standard mappers */
|
||||||
this.<Range, Number>registerAnnotationMapper(Range.class, new RangeMapper<>());
|
this.<Range, Number>registerAnnotationMapper(Range.class, new RangeMapper<>());
|
||||||
|
|
@ -107,7 +111,7 @@ public class StandardParserRegistry<C extends CommandSender> implements ParserRe
|
||||||
@Nonnull final ParserParameters parserParameters) {
|
@Nonnull final ParserParameters parserParameters) {
|
||||||
final TypeToken<?> actualType;
|
final TypeToken<?> actualType;
|
||||||
if (type.isPrimitive()) {
|
if (type.isPrimitive()) {
|
||||||
actualType = TypeToken.of(primitiveMappings.get(type.getRawType()));
|
actualType = TypeToken.of(PRIMITIVE_MAPPINGS.get(type.getRawType()));
|
||||||
} else {
|
} else {
|
||||||
actualType = type;
|
actualType = type;
|
||||||
}
|
}
|
||||||
|
|
@ -127,7 +131,7 @@ public class StandardParserRegistry<C extends CommandSender> implements ParserRe
|
||||||
public ParserParameters apply(final Range range, final TypeToken<?> type) {
|
public ParserParameters apply(final Range range, final TypeToken<?> type) {
|
||||||
final Class<?> clazz;
|
final Class<?> clazz;
|
||||||
if (type.isPrimitive()) {
|
if (type.isPrimitive()) {
|
||||||
clazz = primitiveMappings.get(type.getRawType());
|
clazz = PRIMITIVE_MAPPINGS.get(type.getRawType());
|
||||||
} else {
|
} else {
|
||||||
clazz = type.getRawType();
|
clazz = type.getRawType();
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -171,6 +171,12 @@ public final class IntegerComponent<C extends CommandSender> extends CommandComp
|
||||||
private final int min;
|
private final int min;
|
||||||
private final int max;
|
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) {
|
public IntegerParser(final int min, final int max) {
|
||||||
this.min = min;
|
this.min = min;
|
||||||
this.max = max;
|
this.max = max;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue