forked from Incendo/cloud
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Support suspending parsers. (Incendo#715)
* Support suspending parsers. * Update KotlinAnnotatedMethods.kt * Update KotlinAnnotatedMethods.kt * Fix Incendo#713 * remove Nonnul to make the kotlin happy. * Revert "Fix Incendo#713" This reverts commit 1260d94.
- Loading branch information
Showing
6 changed files
with
401 additions
and
76 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
62 changes: 62 additions & 0 deletions
62
...tions/src/main/java/org/incendo/cloud/annotations/parser/MethodArgumentParserFactory.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
// | ||
// MIT License | ||
// | ||
// Copyright (c) 2024 Incendo | ||
// | ||
// 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. | ||
// | ||
package org.incendo.cloud.annotations.parser; | ||
|
||
import java.lang.reflect.Method; | ||
import org.apiguardian.api.API; | ||
import org.checkerframework.checker.nullness.qual.NonNull; | ||
import org.incendo.cloud.injection.ParameterInjectorRegistry; | ||
import org.incendo.cloud.parser.ParserDescriptor; | ||
import org.incendo.cloud.suggestion.SuggestionProvider; | ||
|
||
@FunctionalInterface | ||
@API(status = API.Status.EXPERIMENTAL) | ||
public interface MethodArgumentParserFactory<C> { | ||
|
||
/** | ||
* Returns a factory that produces {@link MethodArgumentParserFactoryImpl} instances. | ||
* | ||
* @param <C> the command sender type | ||
* @return the created factory | ||
*/ | ||
static <C> @NonNull MethodArgumentParserFactory<C> defaultFactory() { | ||
return new MethodArgumentParserFactoryImpl<>(); | ||
} | ||
|
||
/** | ||
* Creates a suggestion provider using the given {@code method}. | ||
* | ||
* @param suggestionProvider suggestion provider | ||
* @param instance parsed instance | ||
* @param method suggestion method | ||
* @param injectorRegistry injector registry | ||
* @return the suggestion provider | ||
*/ | ||
@NonNull ParserDescriptor<C, ?> createArgumentParser( | ||
@NonNull SuggestionProvider<C> suggestionProvider, | ||
@NonNull Object instance, | ||
@NonNull Method method, | ||
@NonNull ParameterInjectorRegistry<C> injectorRegistry | ||
); | ||
} |
52 changes: 52 additions & 0 deletions
52
...s/src/main/java/org/incendo/cloud/annotations/parser/MethodArgumentParserFactoryImpl.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
// | ||
// MIT License | ||
// | ||
// Copyright (c) 2024 Incendo | ||
// | ||
// 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. | ||
// | ||
package org.incendo.cloud.annotations.parser; | ||
|
||
import io.leangen.geantyref.TypeToken; | ||
import java.lang.reflect.Method; | ||
import org.checkerframework.checker.nullness.qual.NonNull; | ||
import org.incendo.cloud.injection.ParameterInjectorRegistry; | ||
import org.incendo.cloud.parser.ParserDescriptor; | ||
import org.incendo.cloud.suggestion.SuggestionProvider; | ||
|
||
/** | ||
* Represents a method argument parser annotated with {@link Parser} | ||
* | ||
* @param <C> command sender type | ||
*/ | ||
public final class MethodArgumentParserFactoryImpl<C> implements MethodArgumentParserFactory<C> { | ||
|
||
@Override | ||
public @NonNull ParserDescriptor<C, ?> createArgumentParser( | ||
final @NonNull SuggestionProvider<C> suggestionProvider, | ||
final @NonNull Object instance, | ||
final @NonNull Method method, | ||
final @NonNull ParameterInjectorRegistry<C> injectorRegistry | ||
) { | ||
return ParserDescriptor.of( | ||
new MethodArgumentParser<>(suggestionProvider, instance, method, injectorRegistry), | ||
TypeToken.get(method.getGenericReturnType()) | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.