use of org.apache.camel.parser.ParserResult in project camel by apache.
the class RoasterFieldRouteBuilderConfigureTest method parse.
@Test
public void parse() throws Exception {
JavaClassSource clazz = (JavaClassSource) Roaster.parse(new File("src/test/java/org/apache/camel/parser/java/MyFieldRouteBuilder.java"));
MethodSource<JavaClassSource> method = clazz.getMethod("configure");
List<ParserResult> list = CamelJavaParserHelper.parseCamelConsumerUris(method, true, true);
for (ParserResult result : list) {
LOG.info("Consumer: " + result.getElement());
}
Assert.assertEquals("timer:foo", list.get(0).getElement());
list = CamelJavaParserHelper.parseCamelProducerUris(method, true, true);
for (ParserResult result : list) {
LOG.info("Producer: " + result.getElement());
}
Assert.assertEquals("file:output?fileExist=Override", list.get(0).getElement());
Assert.assertEquals("log:b", list.get(1).getElement());
}
use of org.apache.camel.parser.ParserResult in project camel by apache.
the class RoasterMyFieldMethodCallRouteBuilderConfigureTest method parse.
@Test
public void parse() throws Exception {
JavaClassSource clazz = (JavaClassSource) Roaster.parse(new File("src/test/java/org/apache/camel/parser/java/MyFieldMethodCallRouteBuilder.java"));
MethodSource<JavaClassSource> method = clazz.getMethod("configure");
List<ParserResult> list = CamelJavaParserHelper.parseCamelConsumerUris(method, true, true);
for (ParserResult result : list) {
LOG.info("Consumer: " + result.getElement());
}
Assert.assertEquals("netty-http:http://0.0.0.0:{{port}}/foo", list.get(0).getElement());
Assert.assertEquals("netty-http:http://0.0.0.0:{{getNextPort}}/bar", list.get(1).getElement());
list = CamelJavaParserHelper.parseCamelProducerUris(method, true, true);
for (ParserResult result : list) {
LOG.info("Producer: " + result.getElement());
}
Assert.assertEquals("mock:input1", list.get(0).getElement());
Assert.assertEquals("netty-http:http://0.0.0.0:{{getNextPort}}/bar", list.get(1).getElement());
Assert.assertEquals("mock:input2", list.get(2).getElement());
}
use of org.apache.camel.parser.ParserResult in project camel by apache.
the class CamelJavaParserHelper method doParseCamelSimple.
private static void doParseCamelSimple(String node, JavaClassSource clazz, Block block, MethodInvocation mi, List<ParserResult> expressions) {
String name = mi.getName().getIdentifier();
if ("simple".equals(name)) {
List args = mi.arguments();
// the first argument is a string parameter for the simple expression
if (args != null && args.size() >= 1) {
// it is a String type
Object arg = args.get(0);
String simple = getLiteralValue(clazz, block, (Expression) arg);
if (!Strings.isBlank(simple)) {
// is this a simple expression that is called as a predicate or expression
boolean predicate = false;
Expression parent = mi.getExpression();
if (parent == null) {
// maybe its an argument
// simple maybe be passed in as an argument
List list = mi.arguments();
// must be a single argument
if (list != null && list.size() == 1) {
ASTNode o = (ASTNode) list.get(0);
ASTNode p = o.getParent();
if (p instanceof MethodInvocation) {
// this is simple
String pName = ((MethodInvocation) p).getName().getIdentifier();
if ("simple".equals(pName)) {
// okay find the parent of simple which is the method that uses simple
parent = (Expression) p.getParent();
}
}
}
}
if (parent != null && parent instanceof MethodInvocation) {
MethodInvocation emi = (MethodInvocation) parent;
String parentName = emi.getName().getIdentifier();
predicate = isSimplePredicate(parentName);
}
int position = ((Expression) arg).getStartPosition();
ParserResult result = new ParserResult(node, position, simple);
result.setPredicate(predicate);
expressions.add(result);
}
}
}
// simple maybe be passed in as an argument
List args = mi.arguments();
if (args != null) {
for (Object arg : args) {
if (arg instanceof MethodInvocation) {
MethodInvocation ami = (MethodInvocation) arg;
doParseCamelSimple(node, clazz, block, ami, expressions);
}
}
}
}
Aggregations