use of org.jboss.forge.roaster._shade.org.eclipse.jdt.core.dom.ExpressionStatement in project camel by apache.
the class CamelJavaParserHelper method parseCamelSimpleExpressions.
public static List<ParserResult> parseCamelSimpleExpressions(MethodSource<JavaClassSource> method) {
List<ParserResult> answer = new ArrayList<ParserResult>();
MethodDeclaration md = (MethodDeclaration) method.getInternal();
Block block = md.getBody();
if (block != null) {
for (Object statement : block.statements()) {
// must be a method call expression
if (statement instanceof ExpressionStatement) {
ExpressionStatement es = (ExpressionStatement) statement;
Expression exp = es.getExpression();
List<ParserResult> expressions = new ArrayList<ParserResult>();
parseExpression(null, method.getOrigin(), block, exp, expressions);
if (!expressions.isEmpty()) {
// reverse the order as we will grab them from last->first
Collections.reverse(expressions);
answer.addAll(expressions);
}
}
}
}
return answer;
}
use of org.jboss.forge.roaster._shade.org.eclipse.jdt.core.dom.ExpressionStatement in project camel by apache.
the class CamelJavaParserHelper method doParseCamelUris.
private static List<ParserResult> doParseCamelUris(MethodSource<JavaClassSource> method, boolean consumers, boolean producers, boolean strings, boolean fields) {
List<ParserResult> answer = new ArrayList<ParserResult>();
if (method != null) {
MethodDeclaration md = (MethodDeclaration) method.getInternal();
Block block = md.getBody();
if (block != null) {
for (Object statement : md.getBody().statements()) {
// must be a method call expression
if (statement instanceof ExpressionStatement) {
ExpressionStatement es = (ExpressionStatement) statement;
Expression exp = es.getExpression();
List<ParserResult> uris = new ArrayList<ParserResult>();
parseExpression(method.getOrigin(), block, exp, uris, consumers, producers, strings, fields);
if (!uris.isEmpty()) {
// reverse the order as we will grab them from last->first
Collections.reverse(uris);
answer.addAll(uris);
}
}
}
}
}
return answer;
}
use of org.jboss.forge.roaster._shade.org.eclipse.jdt.core.dom.ExpressionStatement in project camel by apache.
the class CamelJavaParserHelper method findConfigureMethodInCreateRouteBuilder.
private static MethodSource<JavaClassSource> findConfigureMethodInCreateRouteBuilder(JavaClassSource clazz, MethodSource<JavaClassSource> method) {
// find configure inside the code
MethodDeclaration md = (MethodDeclaration) method.getInternal();
Block block = md.getBody();
if (block != null) {
List statements = block.statements();
for (int i = 0; i < statements.size(); i++) {
Statement stmt = (Statement) statements.get(i);
Expression exp = null;
if (stmt instanceof ReturnStatement) {
ReturnStatement rs = (ReturnStatement) stmt;
exp = rs.getExpression();
} else if (stmt instanceof ExpressionStatement) {
ExpressionStatement es = (ExpressionStatement) stmt;
exp = es.getExpression();
if (exp instanceof MethodInvocation) {
MethodInvocation mi = (MethodInvocation) exp;
for (Object arg : mi.arguments()) {
if (arg instanceof ClassInstanceCreation) {
exp = (Expression) arg;
break;
}
}
}
}
if (exp != null && exp instanceof ClassInstanceCreation) {
ClassInstanceCreation cic = (ClassInstanceCreation) exp;
boolean isRouteBuilder = false;
if (cic.getType() instanceof SimpleType) {
SimpleType st = (SimpleType) cic.getType();
isRouteBuilder = "RouteBuilder".equals(st.getName().toString());
}
if (isRouteBuilder && cic.getAnonymousClassDeclaration() != null) {
List body = cic.getAnonymousClassDeclaration().bodyDeclarations();
for (int j = 0; j < body.size(); j++) {
Object line = body.get(j);
if (line instanceof MethodDeclaration) {
MethodDeclaration amd = (MethodDeclaration) line;
if ("configure".equals(amd.getName().toString())) {
return new AnonymousMethodSource(clazz, amd);
}
}
}
}
}
}
}
return null;
}
Aggregations