Search in sources :

Example 1 with TemplateExpression

use of com.axellience.vuegwt.processors.component.template.parser.result.TemplateExpression in project vue-gwt by Axellience.

the class TemplateParser method processJavaExpression.

/**
 * Process the given string as a Java expression.
 * @param expressionString A valid Java expression
 * @return A processed expression, should be placed in the HTML in place of the original
 * expression
 */
private TemplateExpression processJavaExpression(String expressionString) {
    Expression expression;
    try {
        expression = JavaParser.parseExpression(expressionString);
    } catch (ParseProblemException parseException) {
        logger.error("Couldn't parse Expression, make sure it is valid Java.", expressionString);
        throw parseException;
    }
    resolveTypesUsingImports(expression);
    resolveStaticMethodsUsingImports(expression);
    checkMethodNames(expression);
    // Find the parameters used by the expression
    List<VariableInfo> expressionParameters = new LinkedList<>();
    findExpressionParameters(expression, expressionParameters);
    // If there is a cast first, we use this as the type of our expression
    if (currentProp == null)
        expression = getTypeFromCast(expression);
    // Update the expression as it might have been changed
    expressionString = expression.toString();
    // Add the resulting expression to our result
    return result.addExpression(expressionString, currentExpressionReturnType, currentProp == null, expressionParameters);
}
Also used : TemplateExpression(com.axellience.vuegwt.processors.component.template.parser.result.TemplateExpression) Expression(com.github.javaparser.ast.expr.Expression) VariableInfo(com.axellience.vuegwt.processors.component.template.parser.variable.VariableInfo) LocalVariableInfo(com.axellience.vuegwt.processors.component.template.parser.variable.LocalVariableInfo) LinkedList(java.util.LinkedList) ParseProblemException(com.github.javaparser.ParseProblemException)

Aggregations

TemplateExpression (com.axellience.vuegwt.processors.component.template.parser.result.TemplateExpression)1 LocalVariableInfo (com.axellience.vuegwt.processors.component.template.parser.variable.LocalVariableInfo)1 VariableInfo (com.axellience.vuegwt.processors.component.template.parser.variable.VariableInfo)1 ParseProblemException (com.github.javaparser.ParseProblemException)1 Expression (com.github.javaparser.ast.expr.Expression)1 LinkedList (java.util.LinkedList)1