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

[Issue 1713] Support optional booleans in annotation processor #1714

Merged
merged 1 commit into from
Jun 23, 2022
Merged
Show file tree
Hide file tree
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
@@ -0,0 +1,26 @@
package picocli.annotation.processing.tests;

import com.google.testing.compile.Compilation;
import com.google.testing.compile.JavaFileObjects;
import org.junit.Test;

import javax.annotation.processing.Processor;

import static com.google.testing.compile.CompilationSubject.assertThat;
import static com.google.testing.compile.Compiler.javac;

public class Issue1713Test
{
//@Ignore("https://github.com/remkop/picocli/issues/1713")
@Test
public void testIssue1713() {
Processor processor = new AnnotatedCommandSourceGeneratorProcessor();
Compilation compilation =
javac()
.withProcessors(processor)
.compile(JavaFileObjects.forResource(
"picocli/issue1713/Command.java"));

assertThat(compilation).succeeded();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package picocli.issue1713;

import java.util.Optional;

import picocli.CommandLine;
import picocli.CommandLine.Command;
import picocli.CommandLine.Model.CommandSpec;
import picocli.CommandLine.Spec;

@Command(name = "Command",
description = "Command description")
class Command1 {

@Spec
CommandSpec spec;

@CommandLine.Option(names = "--progress",
description = "A negatable optional boolean should be allowed",
negatable = true)
Optional<Boolean> progress;
}
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ public boolean isBoolean() {
}

static boolean isBooleanType(TypeMirror type) {
return type.getKind() == TypeKind.BOOLEAN || "java.lang.Boolean".equals(type.toString());
return type.getKind() == TypeKind.BOOLEAN || "java.lang.Boolean".equals(type.toString()) || "java.util.Optional<java.lang.Boolean>".equals(type.toString());
}

@Override
Expand Down