Skip to content

Commit

Permalink
Get rid of lombok to make source match bytecode
Browse files Browse the repository at this point in the history
  • Loading branch information
iiAhmedYT committed Sep 29, 2024
1 parent 52a0468 commit 96b93fa
Show file tree
Hide file tree
Showing 19 changed files with 210 additions and 64 deletions.
3 changes: 0 additions & 3 deletions core/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,6 @@ repositories {
}

dependencies {
compileOnly "${lombok()}"
annotationProcessor "${lombok()}"

compileOnly "org.jetbrains:annotations:24.1.0"
annotationProcessor "org.jetbrains:annotations:24.1.0"

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
import dev.velix.imperat.command.Command;
import dev.velix.imperat.command.parameters.CommandParameter;
import dev.velix.imperat.context.Source;
import lombok.Getter;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

Expand All @@ -19,7 +18,6 @@
*
* @param <S> the command-sender type
*/
@Getter
public abstract class AnnotationParser<S extends Source> {

protected final Imperat<S> imperat;
Expand Down Expand Up @@ -91,4 +89,8 @@ public final boolean isEntryPointAnnotation(Class<? extends Annotation> annotati
return annotation == dev.velix.imperat.annotations.Command.class || annotation == Usage.class || annotation == SubCommand.class;
}

public Imperat<S> getImperat() {
return imperat;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
import dev.velix.imperat.command.Command;
import dev.velix.imperat.context.Source;
import dev.velix.imperat.util.reflection.Reflections;
import lombok.Getter;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

Expand All @@ -15,7 +14,6 @@
import java.util.Set;
import java.util.function.Predicate;

@Getter
public final class ClassElement extends ParseElement<Class<?>> {

private final Set<ParseElement<?>> children = new LinkedHashSet<>();
Expand Down Expand Up @@ -55,10 +53,8 @@ public <S extends Source> Set<Command<S>> accept(CommandClassVisitor<S> visitor)
}
}


public @Nullable ParseElement<?> getChildElement(Predicate<ParseElement<?>> predicate) {
for (var element : getChildren())
if (predicate.test(element)) return element;
for (var element : getChildren()) if (predicate.test(element)) return element;
return null;
}

Expand All @@ -70,7 +66,6 @@ public boolean isRootClass() {
return getParent() == null;
}


@Override
public String getName() {
return getElement().getName();
Expand All @@ -79,4 +74,9 @@ public String getName() {
public String getSimpleName() {
return getElement().getSimpleName();
}

public Set<ParseElement<?>> getChildren() {
return children;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
import dev.velix.imperat.annotations.base.AnnotationHelper;
import dev.velix.imperat.annotations.base.AnnotationParser;
import dev.velix.imperat.context.Source;
import lombok.Getter;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

Expand All @@ -14,7 +13,6 @@
import java.util.ArrayList;
import java.util.List;

@Getter
public final class MethodElement extends ParseElement<Method> {

private final List<ParameterElement> parameters = new ArrayList<>();
Expand Down Expand Up @@ -63,4 +61,17 @@ public int getModifiers() {
public String getName() {
return getElement().getName();
}

public List<ParameterElement> getParameters() {
return parameters;
}

public int getInputCount() {
return inputCount;
}

public boolean isHelp() {
return help;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,12 @@
import dev.velix.imperat.annotations.base.AnnotationHelper;
import dev.velix.imperat.annotations.base.AnnotationParser;
import dev.velix.imperat.context.Source;
import lombok.Getter;
import org.jetbrains.annotations.ApiStatus;

import java.lang.reflect.Parameter;
import java.lang.reflect.Type;

@ApiStatus.Internal
@Getter
public final class ParameterElement extends ParseElement<Parameter> {

private final String name;
Expand All @@ -34,4 +32,16 @@ public String toString() {
return getElement().getType().getSimpleName() + " " + name;
}

public String getName() {
return name;
}

public Type getType() {
return type;
}

public ClassElement getOwningClass() {
return owningClass;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
import dev.velix.imperat.annotations.base.AnnotationReplacer;
import dev.velix.imperat.context.Source;
import dev.velix.imperat.util.AnnotationMap;
import lombok.Getter;
import org.jetbrains.annotations.ApiStatus;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
Expand All @@ -20,11 +19,7 @@ public sealed abstract class ParseElement<E extends AnnotatedElement> implements

//use more memory but better performance, since it's going to be GCed anyway
private final @NotNull AnnotationMap total = new AnnotationMap();

@Getter
private final @Nullable ParseElement<?> parent;

@Getter
private final @NotNull E element;

public <S extends Source> ParseElement(
Expand Down Expand Up @@ -145,4 +140,14 @@ public int hashCode() {
}

public abstract String getName();

public @Nullable ParseElement<?> getParent() {
return parent;
}

@NotNull
public E getElement() {
return element;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -7,21 +7,17 @@
import dev.velix.imperat.util.Registry;
import dev.velix.imperat.util.TypeUtility;
import dev.velix.imperat.util.TypeWrap;
import lombok.Getter;
import lombok.Setter;
import org.jetbrains.annotations.ApiStatus;
import org.jetbrains.annotations.Nullable;

import java.lang.reflect.Type;

@Getter
@Setter
@ApiStatus.AvailableSince("1.0.0")
final class ContextResolverRegistry<S extends Source> extends Registry<Type, ContextResolver<S, ?>> {

private ContextResolverFactory<S> factory;

private ContextResolverRegistry(Imperat<S> imperat) {
private ContextResolverRegistry(final Imperat<S> imperat) {
super();
factory = (parameter -> {
assert parameter != null;
Expand All @@ -30,7 +26,7 @@ private ContextResolverRegistry(Imperat<S> imperat) {
this.registerResolver(TypeWrap.of(CommandHelp.class).getType(), (ctx, param) -> new CommandHelp(imperat, ctx));
}

public static <S extends Source> ContextResolverRegistry<S> createDefault(Imperat<S> imperat) {
public static <S extends Source> ContextResolverRegistry<S> createDefault(final Imperat<S> imperat) {
return new ContextResolverRegistry<>(imperat);
}

Expand All @@ -51,5 +47,12 @@ public <T> void registerResolver(Type type, ContextResolver<S, T> resolver) {
});
}

public ContextResolverFactory<S> getFactory() {
return factory;
}

public void setFactory(ContextResolverFactory<S> factory) {
this.factory = factory;
}

}
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
package dev.velix.imperat.command.parameters;

import lombok.Getter;

@Getter
public final class NumericRange {

private final double min, max;
Expand All @@ -27,4 +24,13 @@ public static NumericRange max(double max) {
public boolean matches(double value) {
return value >= min && value <= max;
}

public double getMin() {
return min;
}

public double getMax() {
return max;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
import dev.velix.imperat.command.parameters.CommandParameter;
import dev.velix.imperat.context.Source;
import dev.velix.imperat.util.ImperatDebugger;
import lombok.Setter;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

Expand All @@ -17,14 +16,13 @@ public final class CommandDispatch<S extends Source> implements Iterable<Command

private final List<CommandParameter<S>> parameters = new ArrayList<>();

@Setter
private Result result;

private CommandDispatch(Result result) {
this.result = result;
}

static <S extends Source> CommandDispatch<S> of(Result result) {
static <S extends Source> CommandDispatch<S> of(final Result result) {
return new CommandDispatch<>(result);
}

Expand All @@ -51,6 +49,10 @@ public Result result() {
return result;
}

public void result(Result result) {
this.result = result;
}

public @Nullable CommandUsage<S> toUsage(Command<S> command) {
return command.getUsage(parameters);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
import dev.velix.imperat.context.SuggestionContext;
import dev.velix.imperat.resolvers.SuggestionResolver;
import dev.velix.imperat.util.TypeUtility;
import lombok.Getter;
import org.jetbrains.annotations.NotNull;

import java.util.ArrayList;
Expand All @@ -18,7 +17,6 @@
/**
* @author Mqzen
*/
@Getter
public final class CommandTree<S extends Source> {

final CommandNode<S> root;
Expand Down Expand Up @@ -197,7 +195,7 @@ private void addChildResults(
if (currentNode.isLeaf()) {

//not the deepest search depth (still more raw args than number of nodes)
commandDispatch.setResult((depth != input.size() - 1 && !currentNode.isGreedyParam())
commandDispatch.result((depth != input.size() - 1 && !currentNode.isGreedyParam())
? CommandDispatch.Result.INCOMPLETE : CommandDispatch.Result.COMPLETE);
return commandDispatch;
} else {
Expand Down Expand Up @@ -239,7 +237,7 @@ private void addChildResults(

//ImperatDebugger.debug("All optional after last depth ? = %s", (allOptional) );
var usage = commandDispatch.toUsage(root.data);
commandDispatch.setResult(
commandDispatch.result(
allOptional || usage != null
? CommandDispatch.Result.COMPLETE
: CommandDispatch.Result.INCOMPLETE
Expand Down Expand Up @@ -269,4 +267,7 @@ private CommandDispatch<S> searchForMatch(
return commandDispatch;
}

public CommandNode<S> getRoot() {
return root;
}
}
Loading

0 comments on commit 96b93fa

Please sign in to comment.