-
-
Notifications
You must be signed in to change notification settings - Fork 26
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactor argument api and create flow.
- Loading branch information
Showing
142 changed files
with
1,138 additions
and
1,674 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
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
2 changes: 1 addition & 1 deletion
2
examples/bukkit/src/main/java/dev/rollczi/example/bukkit/command/ConvertCommand.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
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
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
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
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
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
File renamed without changes.
File renamed without changes.
4 changes: 2 additions & 2 deletions
4
...itecommands/argument/ArgumentFactory.java → ...ecommands/annotation/ArgumentFactory.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
20 changes: 20 additions & 0 deletions
20
...-core-annotations/src/dev/rollczi/litecommands/annotation/ArgumentRequirementFactory.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,20 @@ | ||
package dev.rollczi.litecommands.annotation; | ||
|
||
import dev.rollczi.litecommands.requirement.Requirement; | ||
|
||
import java.lang.annotation.Annotation; | ||
|
||
class ArgumentRequirementFactory<SENDER, A extends Annotation> implements RequirementFactory<A> { | ||
|
||
private final ArgumentFactory<A> argumentFactory; | ||
|
||
public ArgumentRequirementFactory(ArgumentFactory<A> argumentFactory) { | ||
this.argumentFactory = argumentFactory; | ||
} | ||
|
||
@Override | ||
public <PARSED> Requirement<PARSED> create(AnnotationHolder<A, PARSED, ?> holder) { | ||
return argumentFactory.create(holder); | ||
} | ||
|
||
} |
14 changes: 14 additions & 0 deletions
14
...s-core-annotations/src/dev/rollczi/litecommands/annotation/ContextRequirementFactory.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,14 @@ | ||
package dev.rollczi.litecommands.annotation; | ||
|
||
import dev.rollczi.litecommands.requirement.Requirement; | ||
|
||
import java.lang.annotation.Annotation; | ||
|
||
class ContextRequirementFactory<A extends Annotation> implements RequirementFactory<A> { | ||
|
||
@Override | ||
public <PARSED> Requirement<PARSED> create(AnnotationHolder<A, PARSED, ?> holder) { | ||
return new ContextRequirementImpl<>(holder); | ||
} | ||
|
||
} |
42 changes: 42 additions & 0 deletions
42
...ands-core-annotations/src/dev/rollczi/litecommands/annotation/ContextRequirementImpl.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,42 @@ | ||
package dev.rollczi.litecommands.annotation; | ||
|
||
import dev.rollczi.litecommands.meta.Meta; | ||
import dev.rollczi.litecommands.meta.MetaHolder; | ||
import dev.rollczi.litecommands.annotation.AnnotationHolder; | ||
import dev.rollczi.litecommands.requirement.ContextRequirement; | ||
import dev.rollczi.litecommands.wrapper.WrapFormat; | ||
import org.jetbrains.annotations.Nullable; | ||
|
||
import java.lang.annotation.Annotation; | ||
|
||
class ContextRequirementImpl<PARSED, A extends Annotation> implements ContextRequirement<PARSED> { | ||
|
||
private final AnnotationHolder<A, PARSED, ?> holder; | ||
private final Meta meta = Meta.create(); | ||
|
||
ContextRequirementImpl(AnnotationHolder<A, PARSED, ?> holder) { | ||
this.holder = holder; | ||
} | ||
|
||
@Override | ||
public String getName() { | ||
return this.holder.getName(); | ||
} | ||
|
||
@Override | ||
public WrapFormat<PARSED, ?> getWrapperFormat() { | ||
return holder.getFormat(); | ||
} | ||
|
||
|
||
@Override | ||
public Meta meta() { | ||
return meta; | ||
} | ||
|
||
@Override | ||
public @Nullable MetaHolder parentMeta() { | ||
return null; | ||
} | ||
|
||
} |
11 changes: 11 additions & 0 deletions
11
...commands-core-annotations/src/dev/rollczi/litecommands/annotation/RequirementFactory.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,11 @@ | ||
package dev.rollczi.litecommands.annotation; | ||
|
||
import dev.rollczi.litecommands.requirement.Requirement; | ||
|
||
import java.lang.annotation.Annotation; | ||
|
||
interface RequirementFactory<A extends Annotation> { | ||
|
||
<PARSED> Requirement<PARSED> create(AnnotationHolder<A, PARSED, ?> holder); | ||
|
||
} |
29 changes: 29 additions & 0 deletions
29
...mmands-core-annotations/src/dev/rollczi/litecommands/annotation/RequirementProcessor.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,29 @@ | ||
package dev.rollczi.litecommands.annotation; | ||
|
||
import dev.rollczi.litecommands.annotation.processor.AnnotationInvoker; | ||
import dev.rollczi.litecommands.annotation.processor.AnnotationProcessor; | ||
|
||
import java.lang.annotation.Annotation; | ||
import java.util.Optional; | ||
|
||
public class RequirementProcessor<SENDER, A extends Annotation> implements AnnotationProcessor<SENDER> { | ||
|
||
private final RequirementFactory<A> requirementFactory; | ||
private final Class<A> annotationClass; | ||
|
||
public RequirementProcessor(Class<A> annotationClass, ArgumentFactory<A> argumentFactory) { | ||
this.requirementFactory = new ArgumentRequirementFactory<>(argumentFactory); | ||
this.annotationClass = annotationClass; | ||
} | ||
|
||
public RequirementProcessor(Class<A> annotationClass) { | ||
this.requirementFactory = new ContextRequirementFactory<>(); | ||
this.annotationClass = annotationClass; | ||
} | ||
|
||
@Override | ||
public AnnotationInvoker<SENDER> process(AnnotationInvoker<SENDER> invoker) { | ||
return invoker.onRequirement(annotationClass, (holder, builder) -> Optional.of(requirementFactory.create(holder))); | ||
} | ||
|
||
} |
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
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
59 changes: 59 additions & 0 deletions
59
...tations/src/dev/rollczi/litecommands/annotation/processor/AnnotationProcessorService.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,59 @@ | ||
package dev.rollczi.litecommands.annotation.processor; | ||
|
||
import dev.rollczi.litecommands.annotation.RequirementProcessor; | ||
import dev.rollczi.litecommands.argument.Arg; | ||
import dev.rollczi.litecommands.argument.ArgArgumentFactory; | ||
import dev.rollczi.litecommands.async.AsyncAnnotationResolver; | ||
import dev.rollczi.litecommands.command.CommandAnnotationProcessor; | ||
import dev.rollczi.litecommands.command.RootCommandAnnotationProcessor; | ||
import dev.rollczi.litecommands.command.builder.CommandBuilder; | ||
import dev.rollczi.litecommands.execute.ExecuteAnnotationResolver; | ||
import dev.rollczi.litecommands.context.Context; | ||
import dev.rollczi.litecommands.description.DescriptionAnnotationResolver; | ||
import dev.rollczi.litecommands.flag.Flag; | ||
import dev.rollczi.litecommands.flag.FlagArgumentFactory; | ||
import dev.rollczi.litecommands.join.Join; | ||
import dev.rollczi.litecommands.join.JoinArgumentFactory; | ||
import dev.rollczi.litecommands.meta.MarkMetaAnnotationResolver; | ||
import dev.rollczi.litecommands.permission.PermissionAnnotationResolver; | ||
import dev.rollczi.litecommands.permission.PermissionsAnnotationResolver; | ||
import dev.rollczi.litecommands.validator.ValidateAnnotationResolver; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
public class AnnotationProcessorService<SENDER> { | ||
|
||
private final List<AnnotationProcessor<SENDER>> annotationProcessors = new ArrayList<>(); | ||
|
||
public <A extends AnnotationProcessor<SENDER>> AnnotationProcessorService<SENDER> register(A processor) { | ||
annotationProcessors.add(processor); | ||
return this; | ||
} | ||
|
||
public CommandBuilder<SENDER> process(AnnotationInvoker<SENDER> invoker) { | ||
for (AnnotationProcessor<SENDER> processor : annotationProcessors) { | ||
invoker = processor.process(invoker); | ||
} | ||
|
||
return invoker.getResult(); | ||
} | ||
|
||
public static <SENDER> AnnotationProcessorService<SENDER> defaultService() { | ||
return new AnnotationProcessorService<SENDER>() | ||
.register(new CommandAnnotationProcessor<>()) | ||
.register(new RootCommandAnnotationProcessor<>()) | ||
.register(new MarkMetaAnnotationResolver<>()) | ||
.register(new DescriptionAnnotationResolver<>()) | ||
.register(new AsyncAnnotationResolver<>()) | ||
.register(new PermissionAnnotationResolver<>()) | ||
.register(new PermissionsAnnotationResolver<>()) | ||
.register(new ValidateAnnotationResolver<>()) | ||
.register(new ExecuteAnnotationResolver<>()) | ||
.register(new RequirementProcessor<>(Flag.class, new FlagArgumentFactory())) | ||
.register(new RequirementProcessor<>(Arg.class, new ArgArgumentFactory())) | ||
.register(new RequirementProcessor<>(Join.class, new JoinArgumentFactory())) | ||
.register(new RequirementProcessor<>(Context.class)); | ||
} | ||
|
||
} |
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.