当前位置: 首页>>代码示例>>Java>>正文


Java Expression.toString方法代码示例

本文整理汇总了Java中com.github.javaparser.ast.expr.Expression.toString方法的典型用法代码示例。如果您正苦于以下问题:Java Expression.toString方法的具体用法?Java Expression.toString怎么用?Java Expression.toString使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在com.github.javaparser.ast.expr.Expression的用法示例。


在下文中一共展示了Expression.toString方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: processEventParameter

import com.github.javaparser.ast.expr.Expression; //导入方法依赖的package包/类
/**
 * 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
    {
        throw new TemplateExpressionException(
            "\"$event\" should always be casted to it's intended type. Example: @click=\"doSomething((NativeEvent) $event)\".",
            expression.toString(),
            context);
    }
}
 
开发者ID:Axellience,项目名称:vue-gwt,代码行数:25,代码来源:TemplateParser.java

示例2: processJavaExpression

import com.github.javaparser.ast.expr.Expression; //导入方法依赖的package包/类
/**
 * 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)
    {
        throw new TemplateExpressionException(
            "Couldn't parse Expression, make sure it is valid Java.",
            expressionString,
            context,
            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);
}
 
开发者ID:Axellience,项目名称:vue-gwt,代码行数:45,代码来源:TemplateParser.java

示例3: checkMethodNames

import com.github.javaparser.ast.expr.Expression; //导入方法依赖的package包/类
/**
 * 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))
            {
                throw new TemplateExpressionException("Couldn't find the method \""
                    + methodName
                    + "\" in the Component."
                    + "\nMake sure it is not private or try rerunning your Annotation processor.",
                    expression.toString(),
                    context);
            }
        }
    }

    for (com.github.javaparser.ast.Node node : expression.getChildNodes())
    {
        if (!(node instanceof Expression))
            continue;

        Expression childExpr = (Expression) node;
        checkMethodNames(childExpr);
    }
}
 
开发者ID:Axellience,项目名称:vue-gwt,代码行数:37,代码来源:TemplateParser.java

示例4: processNameExpression

import com.github.javaparser.ast.expr.Expression; //导入方法依赖的package包/类
/**
 * 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)
    {
        throw new TemplateExpressionException("Couldn't find variable/method \""
            + name
            + "\" in the Component.\nMake sure you didn't forget the @JsProperty/@JsMethod annotation or try rerunning your Annotation processor.",
            expression.toString(),
            context);
    }

    if (variableInfo instanceof LocalVariableInfo)
    {
        parameters.add(variableInfo);
    }
}
 
开发者ID:Axellience,项目名称:vue-gwt,代码行数:34,代码来源:TemplateParser.java

示例5: parseExpression

import com.github.javaparser.ast.expr.Expression; //导入方法依赖的package包/类
/**
 *
 * @param expression
 *  a github javaparser Expression
 * @param attributes
 *      the list of attributes of the class,
 *      to potentially get a type from the name
 * @param lineNumber
 *      the starting line number of the parse method or constructor
 * @return
 *      an Expression structure
 */
public Expr parseExpression(Expression expression, List<Attribute> attributes, int lineNumber) {
    if (expression instanceof AssignExpr) { // this.bar = "bar";
        AssignExpr assExpr = (AssignExpr) expression;
        return parseExpression(assExpr.getTarget(), attributes, lineNumber);
    } else if (expression instanceof MethodCallExpr) {
        MethodCallExpr mcEx = (MethodCallExpr) expression;
        return parseMethodCallExpression(mcEx, attributes, lineNumber);
    } else if (expression instanceof NameExpr) { // ident
        NameExpr nEx = (NameExpr) expression;
        Ident nameExpr = new Ident(nEx.getName());
        return nameExpr;
    } else if (expression instanceof LiteralExpr) { // basic lit
        return parseLiteralExpr((LiteralExpr) expression);
    } else if (expression instanceof FieldAccessExpr) {
        FieldAccessExpr fieldExpr = (FieldAccessExpr) expression;
        Ident ident = new Ident(ParserUtils.parseTarget(expression.toString()).get("name"));
        AttributeRef attrRef = new AttributeRef(ident);
        return attrRef;
    } else if (expression instanceof ObjectCreationExpr) {
        ObjectCreationExpr objConExpr = (ObjectCreationExpr) expression;
        return parseObjectCreationExpression(objConExpr, attributes, lineNumber);
    } else if (expression instanceof ArrayAccessExpr) {
        ArrayAccessExpr arryExpr = (ArrayAccessExpr) expression;
        return parseArrayAccessExpression(arryExpr);
    } else if (expression instanceof UnaryExpr) {
        UnaryExpr unExpr = (UnaryExpr) expression;
        return parseUnaryExpression(unExpr, attributes, lineNumber);
    } else if (expression instanceof ConditionalExpr) {
        ConditionalExpr condExpr = (ConditionalExpr) expression;
        return parseConditionalExpression(condExpr, attributes, lineNumber);
    } else if (expression instanceof CastExpr) {
        CastExpr castExpr = (CastExpr) expression;
        return parseExpression(castExpr.getExpr(), attributes, lineNumber);
    } else if (expression instanceof BinaryExpr) {
        BinaryExpr binEx = (BinaryExpr) expression;
        return parseBinaryExpression(binEx, attributes, lineNumber);
    } else if (expression instanceof EnclosedExpr) {
        EnclosedExpr enclosedExpr = (EnclosedExpr) expression;
        return parseExpression(enclosedExpr.getInner(), attributes, lineNumber);
    } else if (expression instanceof InstanceOfExpr) {
        InstanceOfExpr intExpr = (InstanceOfExpr) expression;
        return parseInstanceOfExpression(intExpr, attributes, lineNumber);
    } else if (expression instanceof ArrayCreationExpr) {
        ArrayCreationExpr arryCreaExpr = (ArrayCreationExpr) expression;
        return parseArrayCreationExpression(arryCreaExpr, attributes, lineNumber);
    } else if (expression instanceof ArrayInitializerExpr) {
        ArrayInitializerExpr arryInEx = (ArrayInitializerExpr) expression;
        return parseArrayInitializerExpression(arryInEx, attributes, lineNumber);
    } else if (expression instanceof ThisExpr) {
        return new Ident("this");
    } else if (expression instanceof SuperExpr) {
        return new Ident("super");
    } else if (expression instanceof ClassExpr) {
        return new Ident(expression.toString());
    } else if (expression instanceof VariableDeclarationExpr) { // int foo = 42;
        // should be parsed by parseVariableDeclarationExpression()
        Log.e(TAG, "Unreachable case :: expression : ".concat(expression.toString()));
        return null;
    } else {
        Log.e(TAG, "The type of expression '".concat(expression.getClass().toString()).concat("' is not managed by the parser"));
        return null;
    }
}
 
开发者ID:DevMine,项目名称:parsers,代码行数:76,代码来源:Parser.java


注:本文中的com.github.javaparser.ast.expr.Expression.toString方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。