Skip to content

Commit

Permalink
Support optional booleans in annotation processor
Browse files Browse the repository at this point in the history
  • Loading branch information
nineinchnick authored and remkop committed Jun 23, 2022
1 parent 8041ddf commit b0a23ce
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 1 deletion.
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

0 comments on commit b0a23ce

Please sign in to comment.