Search in sources :

Example 1 with ClassInstanceCreation

use of org.jboss.forge.roaster._shade.org.eclipse.jdt.core.dom.ClassInstanceCreation 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;
}
Also used : ClassInstanceCreation(org.jboss.forge.roaster._shade.org.eclipse.jdt.core.dom.ClassInstanceCreation) MethodDeclaration(org.jboss.forge.roaster._shade.org.eclipse.jdt.core.dom.MethodDeclaration) VariableDeclarationStatement(org.jboss.forge.roaster._shade.org.eclipse.jdt.core.dom.VariableDeclarationStatement) ReturnStatement(org.jboss.forge.roaster._shade.org.eclipse.jdt.core.dom.ReturnStatement) Statement(org.jboss.forge.roaster._shade.org.eclipse.jdt.core.dom.Statement) ExpressionStatement(org.jboss.forge.roaster._shade.org.eclipse.jdt.core.dom.ExpressionStatement) MethodInvocation(org.jboss.forge.roaster._shade.org.eclipse.jdt.core.dom.MethodInvocation) SimpleType(org.jboss.forge.roaster._shade.org.eclipse.jdt.core.dom.SimpleType) Expression(org.jboss.forge.roaster._shade.org.eclipse.jdt.core.dom.Expression) InfixExpression(org.jboss.forge.roaster._shade.org.eclipse.jdt.core.dom.InfixExpression) ParenthesizedExpression(org.jboss.forge.roaster._shade.org.eclipse.jdt.core.dom.ParenthesizedExpression) ExpressionStatement(org.jboss.forge.roaster._shade.org.eclipse.jdt.core.dom.ExpressionStatement) ReturnStatement(org.jboss.forge.roaster._shade.org.eclipse.jdt.core.dom.ReturnStatement) Block(org.jboss.forge.roaster._shade.org.eclipse.jdt.core.dom.Block) ArrayList(java.util.ArrayList) List(java.util.List) AnonymousMethodSource(org.apache.camel.parser.roaster.AnonymousMethodSource)

Aggregations

ArrayList (java.util.ArrayList)1 List (java.util.List)1 AnonymousMethodSource (org.apache.camel.parser.roaster.AnonymousMethodSource)1 Block (org.jboss.forge.roaster._shade.org.eclipse.jdt.core.dom.Block)1 ClassInstanceCreation (org.jboss.forge.roaster._shade.org.eclipse.jdt.core.dom.ClassInstanceCreation)1 Expression (org.jboss.forge.roaster._shade.org.eclipse.jdt.core.dom.Expression)1 ExpressionStatement (org.jboss.forge.roaster._shade.org.eclipse.jdt.core.dom.ExpressionStatement)1 InfixExpression (org.jboss.forge.roaster._shade.org.eclipse.jdt.core.dom.InfixExpression)1 MethodDeclaration (org.jboss.forge.roaster._shade.org.eclipse.jdt.core.dom.MethodDeclaration)1 MethodInvocation (org.jboss.forge.roaster._shade.org.eclipse.jdt.core.dom.MethodInvocation)1 ParenthesizedExpression (org.jboss.forge.roaster._shade.org.eclipse.jdt.core.dom.ParenthesizedExpression)1 ReturnStatement (org.jboss.forge.roaster._shade.org.eclipse.jdt.core.dom.ReturnStatement)1 SimpleType (org.jboss.forge.roaster._shade.org.eclipse.jdt.core.dom.SimpleType)1 Statement (org.jboss.forge.roaster._shade.org.eclipse.jdt.core.dom.Statement)1 VariableDeclarationStatement (org.jboss.forge.roaster._shade.org.eclipse.jdt.core.dom.VariableDeclarationStatement)1