Search in sources :

Example 1 with VariableInfo

use of com.axellience.vuegwt.processors.component.template.parser.variable.VariableInfo 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)

Example 2 with VariableInfo

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

the class TemplateParser method processEventParameter.

/**
 * Process the $event variable passed on v-on. This variable must have a valid cast in front.
 * @param expression The currently processed expression
 * @param nameExpr The variable we are processing
 * @param parameters The parameters this expression depends on
 */
private void processEventParameter(Expression expression, NameExpr nameExpr, List<VariableInfo> parameters) {
    if (nameExpr.getParentNode().isPresent() && nameExpr.getParentNode().get() instanceof CastExpr) {
        CastExpr castExpr = (CastExpr) nameExpr.getParentNode().get();
        parameters.add(new VariableInfo(castExpr.getType().toString(), "$event"));
    } else {
        logger.error("\"$event\" should always be casted to it's intended type. Example: @click=\"doSomething((NativeEvent) $event)\".", expression.toString());
    }
}
Also used : VariableInfo(com.axellience.vuegwt.processors.component.template.parser.variable.VariableInfo) LocalVariableInfo(com.axellience.vuegwt.processors.component.template.parser.variable.LocalVariableInfo) CastExpr(com.github.javaparser.ast.expr.CastExpr)

Example 3 with VariableInfo

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

the class TemplateParser method processNameExpression.

/**
 * Process a name expression to determine if it exists in the context.
 * If it does, and it's a local variable (from a v-for) we add it to our parameters
 * @param expression The currently processed expression
 * @param nameExpr The variable we are processing
 * @param parameters The parameters this expression depends on
 */
private void processNameExpression(Expression expression, NameExpr nameExpr, List<VariableInfo> parameters) {
    String name = nameExpr.getNameAsString();
    if (context.hasImport(name)) {
        // This is a direct Class reference, we just replace with the fully qualified name
        nameExpr.setName(context.getFullyQualifiedNameForClassName(name));
        return;
    }
    VariableInfo variableInfo = context.findVariable(name);
    if (variableInfo == null) {
        logger.error("Couldn't find variable/method \"" + name + "\". Make sure you didn't forget the @JsProperty/@JsMethod annotation.");
    }
    if (variableInfo instanceof LocalVariableInfo) {
        parameters.add(variableInfo);
    }
}
Also used : LocalVariableInfo(com.axellience.vuegwt.processors.component.template.parser.variable.LocalVariableInfo) VariableInfo(com.axellience.vuegwt.processors.component.template.parser.variable.VariableInfo) LocalVariableInfo(com.axellience.vuegwt.processors.component.template.parser.variable.LocalVariableInfo)

Aggregations

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