-
Notifications
You must be signed in to change notification settings - Fork 422
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[#1137] Fix ClassCastException in annotation processor when an option…
… has completionCandidates Closes #1137
- Loading branch information
Showing
6 changed files
with
155 additions
and
11 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
41 changes: 41 additions & 0 deletions
41
...ion-processing-tests/src/test/java/picocli/annotation/processing/tests/Issue1137Test.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,41 @@ | ||
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 javax.tools.StandardLocation; | ||
|
||
import static com.google.testing.compile.CompilationSubject.assertThat; | ||
import static com.google.testing.compile.Compiler.javac; | ||
import static picocli.annotation.processing.tests.Resources.slurp; | ||
import static picocli.annotation.processing.tests.YamlAssert.compareCommandYamlDump; | ||
|
||
public class Issue1137Test { | ||
@Test | ||
public void testIssue1137() { | ||
Processor processor = new AnnotatedCommandSourceGeneratorProcessor(); | ||
Compilation compilation = | ||
javac() | ||
.withProcessors(processor) | ||
.compile(JavaFileObjects.forResource( | ||
"picocli/issue1137/Issue1137.java")); | ||
|
||
assertThat(compilation).succeeded(); | ||
} | ||
|
||
@Test | ||
public void testIssue1137Details() { | ||
|
||
Compilation compilation = compareCommandYamlDump(slurp("/picocli/issue1137/Issue1137.yaml"), | ||
JavaFileObjects.forResource("picocli/issue1137/Issue1137.java")); | ||
|
||
assertOnlySourceVersionWarning(compilation); | ||
} | ||
|
||
private void assertOnlySourceVersionWarning(Compilation compilation) { | ||
assertThat(compilation).hadWarningCount(0); // #826 version warnings are now suppressed | ||
// assertThat(compilation).hadWarningContaining("Supported source version 'RELEASE_6' from annotation processor 'picocli.annotation.processing.tests"); | ||
} | ||
} |
39 changes: 39 additions & 0 deletions
39
picocli-annotation-processing-tests/src/test/resources/picocli/issue1137/Issue1137.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,39 @@ | ||
package picocli.issue1137; | ||
|
||
import picocli.CommandLine; | ||
import picocli.CommandLine.Command; | ||
import picocli.CommandLine.Model.CommandSpec; | ||
import picocli.CommandLine.Option; | ||
import picocli.CommandLine.Spec; | ||
|
||
import java.util.Arrays; | ||
import java.util.ArrayList; | ||
import java.util.UUID; | ||
import java.util.concurrent.Callable; | ||
|
||
@Command(name = "top", | ||
version = {"test 1.0"}, | ||
resourceBundle = "mybundle5") | ||
public class Issue1137 implements Callable<Integer> { | ||
|
||
@CommandLine.Option(names = "--level", | ||
description = "Level.", | ||
defaultValue = "OFF", | ||
showDefaultValue = CommandLine.Help.Visibility.ALWAYS, | ||
completionCandidates = LevelCompletion.class) | ||
private String level; | ||
|
||
@Spec | ||
CommandSpec spec; | ||
|
||
@Override | ||
public Integer call() throws Exception { | ||
return 0; | ||
} | ||
|
||
public static class LevelCompletion extends ArrayList<String> { | ||
public LevelCompletion() { | ||
super(Arrays.asList("OFF", "INFO", "WARN")); | ||
} | ||
} | ||
} |
70 changes: 70 additions & 0 deletions
70
picocli-annotation-processing-tests/src/test/resources/picocli/issue1137/Issue1137.yaml
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,70 @@ | ||
--- | ||
CommandSpec: | ||
name: 'top' | ||
aliases: [] | ||
userObject: picocli.issue1137.Issue1137 | ||
helpCommand: false | ||
defaultValueProvider: null | ||
versionProvider: null | ||
version: [test 1.0] | ||
ArgGroups: [] | ||
Options: | ||
- names: [--level] | ||
usageHelp: false | ||
versionHelp: false | ||
description: [Level.] | ||
descriptionKey: '' | ||
typeInfo: CompileTimeTypeInfo(java.lang.String, aux=[java.lang.String], collection=false, map=false) | ||
arity: 1 | ||
splitRegex: '' | ||
interactive: false | ||
required: false | ||
hidden: false | ||
hideParamSyntax: false | ||
defaultValue: 'OFF' | ||
showDefaultValue: ALWAYS | ||
hasInitialValue: false | ||
initialValue: 'null' | ||
paramLabel: '<level>' | ||
converters: [] | ||
completionCandidates: CompletionCandidatesMetaData(picocli.issue1137.Issue1137.LevelCompletion) | ||
getter: AnnotatedElementHolder(FIELD level in picocli.issue1137.Issue1137) | ||
setter: AnnotatedElementHolder(FIELD level in picocli.issue1137.Issue1137) | ||
PositionalParams: [] | ||
UnmatchedArgsBindings: [] | ||
Mixins: [] | ||
UsageMessageSpec: | ||
width: 80 | ||
abbreviateSynopsis: false | ||
hidden: false | ||
showDefaultValues: false | ||
sortOptions: true | ||
requiredOptionMarker: ' ' | ||
headerHeading: '' | ||
header: [] | ||
synopsisHeading: 'Usage: ' | ||
customSynopsis: [] | ||
descriptionHeading: '' | ||
description: [] | ||
parameterListHeading: '' | ||
optionListHeading: '' | ||
commandListHeading: 'Commands:%n' | ||
footerHeading: '' | ||
footer: [] | ||
ParserSpec: | ||
separator: '=' | ||
endOfOptionsDelimiter: '--' | ||
expandAtFiles: true | ||
atFileCommentChar: '#' | ||
overwrittenOptionsAllowed: false | ||
unmatchedArgumentsAllowed: false | ||
unmatchedOptionsArePositionalParams: false | ||
stopAtUnmatched: false | ||
stopAtPositional: false | ||
posixClusteredShortOptionsAllowed: true | ||
aritySatisfiedByAttachedOptionParam: false | ||
caseInsensitiveEnumValuesAllowed: false | ||
collectErrors: false | ||
limitSplit: false | ||
toggleBooleanFlags: false | ||
Subcommands: [] |
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