Search in sources :

Example 76 with MethodCallExpr

use of com.github.javaparser.ast.expr.MethodCallExpr in project vue-gwt by Axellience.

the class TemplateParser method checkMethodNames.

/**
 * Check the expression for component method calls.
 * This will check that the methods used in the template exist in the Component.
 * It throws an exception if we use a method that is not declared in our Component.
 * This will not check for the type or number of parameters, we leave that to the Java Compiler.
 * @param expression The expression to check
 */
private void checkMethodNames(Expression expression) {
    if (expression instanceof MethodCallExpr) {
        MethodCallExpr methodCall = ((MethodCallExpr) expression);
        if (!methodCall.getScope().isPresent()) {
            String methodName = methodCall.getName().getIdentifier();
            if (!context.hasMethod(methodName) && !context.hasStaticMethod(methodName)) {
                logger.error("Couldn't find the method \"" + methodName + "\". " + "Make sure it is not private.");
            }
        }
    }
    for (com.github.javaparser.ast.Node node : expression.getChildNodes()) {
        if (!(node instanceof Expression))
            continue;
        Expression childExpr = (Expression) node;
        checkMethodNames(childExpr);
    }
}
Also used : TemplateExpression(com.axellience.vuegwt.processors.component.template.parser.result.TemplateExpression) Expression(com.github.javaparser.ast.expr.Expression) MethodCallExpr(com.github.javaparser.ast.expr.MethodCallExpr)

Example 77 with MethodCallExpr

use of com.github.javaparser.ast.expr.MethodCallExpr in project vue-gwt by Axellience.

the class TemplateParser method resolveStaticMethodsUsingImports.

/**
 * Resolve static method calls using static imports
 * @param expression The expression to resolve
 */
private void resolveStaticMethodsUsingImports(Expression expression) {
    if (expression instanceof MethodCallExpr) {
        MethodCallExpr methodCall = ((MethodCallExpr) expression);
        String methodName = methodCall.getName().getIdentifier();
        if (!methodCall.getScope().isPresent() && context.hasStaticMethod(methodName)) {
            methodCall.setName(context.getFullyQualifiedNameForMethodName(methodName));
        }
    }
    // Recurse downward in the expression
    expression.getChildNodes().stream().filter(Expression.class::isInstance).map(Expression.class::cast).forEach(this::resolveStaticMethodsUsingImports);
}
Also used : TemplateExpression(com.axellience.vuegwt.processors.component.template.parser.result.TemplateExpression) Expression(com.github.javaparser.ast.expr.Expression) MethodCallExpr(com.github.javaparser.ast.expr.MethodCallExpr)

Aggregations

MethodCallExpr (com.github.javaparser.ast.expr.MethodCallExpr)77 Test (org.junit.Test)70 CompilationUnit (com.github.javaparser.ast.CompilationUnit)63 MethodDeclaration (com.github.javaparser.ast.body.MethodDeclaration)56 ReflectionTypeSolver (com.github.javaparser.symbolsolver.resolution.typesolvers.ReflectionTypeSolver)46 ClassOrInterfaceDeclaration (com.github.javaparser.ast.body.ClassOrInterfaceDeclaration)40 MethodUsage (com.github.javaparser.resolution.MethodUsage)33 TypeSolver (com.github.javaparser.symbolsolver.model.resolution.TypeSolver)30 AbstractResolutionTest (com.github.javaparser.symbolsolver.resolution.AbstractResolutionTest)25 JavaParserFacade (com.github.javaparser.symbolsolver.javaparsermodel.JavaParserFacade)21 ResolvedType (com.github.javaparser.resolution.types.ResolvedType)16 AbstractTest (com.github.javaparser.symbolsolver.AbstractTest)16 Expression (com.github.javaparser.ast.expr.Expression)14 ResolvedMethodDeclaration (com.github.javaparser.resolution.declarations.ResolvedMethodDeclaration)14 CombinedTypeSolver (com.github.javaparser.symbolsolver.resolution.typesolvers.CombinedTypeSolver)14 SymbolReference (com.github.javaparser.symbolsolver.model.resolution.SymbolReference)8 ExpressionStmt (com.github.javaparser.ast.stmt.ExpressionStmt)5 JavaParserTypeSolver (com.github.javaparser.symbolsolver.resolution.typesolvers.JavaParserTypeSolver)5 JavaParserClassDeclaration (com.github.javaparser.symbolsolver.javaparsermodel.declarations.JavaParserClassDeclaration)4 ReturnStmt (com.github.javaparser.ast.stmt.ReturnStmt)3