Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improved AbstractCommandSpecProcessor#isSubcommand(ExecutableElement, RoundEnvironment) #1483

Merged
merged 2 commits into from
Nov 30, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@
import java.util.logging.Logger;

import static java.lang.String.format;
import static java.util.Collections.disjoint;
import static javax.lang.model.element.ElementKind.ENUM;

/**
Expand Down Expand Up @@ -300,21 +301,21 @@ private void updateCommandFromMethodElement(ExecutableElement method, Context co

private boolean isSubcommand(ExecutableElement method, RoundEnvironment roundEnv) {
Element typeElement = method.getEnclosingElement();
if (typeElement.getAnnotation(Command.class) != null && typeElement.getAnnotation(Command.class).addMethodSubcommands()) {
return true;
}
if (typeElement.getAnnotation(Command.class) == null) {
Set<Element> elements = new HashSet<Element>(typeElement.getEnclosedElements());

// The class is a Command if it has any fields or methods annotated with the below:
return roundEnv.getElementsAnnotatedWith(Option.class).removeAll(elements)
|| roundEnv.getElementsAnnotatedWith(Parameters.class).removeAll(elements)
|| roundEnv.getElementsAnnotatedWith(Mixin.class).removeAll(elements)
|| roundEnv.getElementsAnnotatedWith(ArgGroup.class).removeAll(elements)
|| roundEnv.getElementsAnnotatedWith(Unmatched.class).removeAll(elements)
|| roundEnv.getElementsAnnotatedWith(Spec.class).removeAll(elements);
Command cmd = typeElement.getAnnotation(Command.class);

if (cmd != null) {
return cmd.addMethodSubcommands();
}
return false;

List<? extends Element> elements = typeElement.getEnclosedElements();

// The class is a Command if it has any fields or methods annotated with the below:
return !disjoint(roundEnv.getElementsAnnotatedWith(Option.class), elements)
|| !disjoint(roundEnv.getElementsAnnotatedWith(Parameters.class), elements)
|| !disjoint(roundEnv.getElementsAnnotatedWith(Mixin.class), elements)
|| !disjoint(roundEnv.getElementsAnnotatedWith(ArgGroup.class), elements)
|| !disjoint(roundEnv.getElementsAnnotatedWith(Unmatched.class), elements)
|| !disjoint(roundEnv.getElementsAnnotatedWith(Spec.class), elements);
}

private Stack<TypeElement> buildTypeHierarchy(TypeElement typeElement) {
Expand Down