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
@Retention(RetentionPolicy.RUNTIME) | |
@Qualifier | |
@Target({ElementType.TYPE}) | |
public @interface InProfile { | |
DbProfile value(); | |
} |
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
public enum DbProfile { | |
IN_MEMORY_DB, JEE_DATASOURCE; | |
public AnnotationLiteral<InProfile> literal(){ | |
return new InProfileLiteral(); | |
} | |
class InProfileLiteral extends AnnotationLiteral<InProfile> implements InProfile { | |
@Override |
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
@Produces | |
public SampleSvc sampleSvc(@Any Instance<SampleSvc> candidates) { | |
return candidates.select( activeProfile.literal() ).get(); | |
} | |
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
class TestParser extends JavaTokenParsers with CompletingParser { | |
def propertyPath: Parser[Any] = "name" | ( "child"~opt("."~childProperties) ) | "chunk" | |
def childProperties: Parser[Any] = "name" | "toys" | "tolerance" | |
} |
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
object CompletingParserTestApp extends TestParser with App { | |
println( "Type something and hit enter" ); | |
var input = "" | |
do { | |
input = readLine(); | |
parseAll( propertyPath, input ) match { | |
case s : Success[Any] => println ( "valid, parsed as "+ s.get) | |
case MissingCompletionOrFailure( completions, msg, in) | |
=> if ( completions.isEmpty ) |
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
import util.parsing.combinator.RegexParsers | |
/** | |
* A trait to make parsers for string literals return a nice list of possible completions if | |
* we're at the end of the input. | |
* | |
* @author Marcus Schulte | |
*/ |