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


Java Expression.getNodeMetaData方法代码示例

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


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

示例1: resolveType

import org.codehaus.groovy.ast.expr.Expression; //导入方法依赖的package包/类
public ClassNode resolveType(final Expression exp, final ClassNode current) {
    if (exp instanceof ClassExpression) return ClassHelper.CLASS_Type;
    OptimizingStatementWriter.StatementMeta meta = exp.getNodeMetaData(OptimizingStatementWriter.StatementMeta.class);
    ClassNode type = null;
    if (meta != null) type = meta.type;
    if (type != null) return type;
    if (exp instanceof VariableExpression) {
        VariableExpression ve = (VariableExpression) exp;
        if (ve.isClosureSharedVariable()) return ve.getType();
        type = ve.getOriginType();
        if (ve.getAccessedVariable() instanceof FieldNode) {
            FieldNode fn = (FieldNode) ve.getAccessedVariable();
            if (!fn.getDeclaringClass().equals(current)) return fn.getOriginType();
        }
    } else if (exp instanceof Variable) {
        Variable v = (Variable) exp;
        type = v.getOriginType();
    } else {
        type = exp.getType();
    }
    return type.redirect();
}
 
开发者ID:apache,项目名称:groovy,代码行数:23,代码来源:StatementMetaTypeChooser.java

示例2: makeSingleArgumentCall

import org.codehaus.groovy.ast.expr.Expression; //导入方法依赖的package包/类
@Override
public void makeSingleArgumentCall(final Expression receiver, final String message, final Expression arguments, boolean safe) {
    TypeChooser typeChooser = controller.getTypeChooser();
    ClassNode classNode = controller.getClassNode();
    ClassNode rType = typeChooser.resolveType(receiver, classNode);
    ClassNode aType = typeChooser.resolveType(arguments, classNode);
    if (trySubscript(receiver, message, arguments, rType, aType, safe)) {
        return;
    }
    // now try with flow type instead of declaration type
    rType = receiver.getNodeMetaData(StaticTypesMarker.INFERRED_TYPE);
    if (receiver instanceof VariableExpression && rType == null) {
        // TODO: can STCV be made smarter to avoid this check?
        VariableExpression ve = (VariableExpression) ((VariableExpression)receiver).getAccessedVariable();
        rType = ve.getNodeMetaData(StaticTypesMarker.INFERRED_TYPE);
    }
    if (rType!=null && trySubscript(receiver, message, arguments, rType, aType, safe)) {
        return;
    }
    // todo: more cases
    throw new GroovyBugError(
            "At line " + receiver.getLineNumber() + " column " + receiver.getColumnNumber() + "\n" +
            "On receiver: " + receiver.getText() + " with message: " + message + " and arguments: " + arguments.getText() + "\n" +
            "This method should not have been called. Please try to create a simple example reproducing\n" +
            "this error and file a bug report at https://issues.apache.org/jira/browse/GROOVY");
}
 
开发者ID:apache,项目名称:groovy,代码行数:27,代码来源:StaticTypesCallSiteWriter.java

示例3: transform

import org.codehaus.groovy.ast.expr.Expression; //导入方法依赖的package包/类
@Override
public Expression transform(final Expression exp) {
    if (exp instanceof ConstructorCallExpression) {
        MethodCallExpression call = exp.getNodeMetaData(MacroTransformation.class);
        if (call != null) {
            return call;
        }
    }
    return super.transform(exp);
}
 
开发者ID:apache,项目名称:groovy,代码行数:11,代码来源:MacroClassTransformation.java

示例4: visitParExpression

import org.codehaus.groovy.ast.expr.Expression; //导入方法依赖的package包/类
@Override
public Expression visitParExpression(ParExpressionContext ctx) {
    Expression expression = this.visitExpressionInPar(ctx.expressionInPar());

    Integer insideParenLevel = expression.getNodeMetaData(INSIDE_PARENTHESES_LEVEL);
    if (null != insideParenLevel) {
        insideParenLevel++;
    } else {
        insideParenLevel = 1;
    }
    expression.putNodeMetaData(INSIDE_PARENTHESES_LEVEL, insideParenLevel);

    return configureAST(expression, ctx);
}
 
开发者ID:apache,项目名称:groovy,代码行数:15,代码来源:AstBuilder.java

示例5: addedReadOnlyPropertyError

import org.codehaus.groovy.ast.expr.Expression; //导入方法依赖的package包/类
private boolean addedReadOnlyPropertyError(Expression expr) {
    // if expr is of READONLY_PROPERTY_RETURN type, then it means we are on a missing property
    if (expr.getNodeMetaData(StaticTypesMarker.READONLY_PROPERTY) == null) return false;
    String name;
    if (expr instanceof VariableExpression) {
        name = ((VariableExpression) expr).getName();
    } else {
        name = ((PropertyExpression) expr).getPropertyAsString();
    }
    addStaticTypeError("Cannot set read-only property: " + name, expr);
    return true;
}
 
开发者ID:apache,项目名称:groovy,代码行数:13,代码来源:StaticTypeCheckingVisitor.java

示例6: visitMethodCallArguments

import org.codehaus.groovy.ast.expr.Expression; //导入方法依赖的package包/类
protected void visitMethodCallArguments(final ClassNode receiver, ArgumentListExpression arguments, boolean visitClosures, final MethodNode selectedMethod) {
    Parameter[] params = selectedMethod!=null?selectedMethod.getParameters(): Parameter.EMPTY_ARRAY;
    List<Expression> expressions = new LinkedList<Expression>(arguments.getExpressions());
    if (selectedMethod instanceof ExtensionMethodNode) {
        params = ((ExtensionMethodNode) selectedMethod).getExtensionMethodNode().getParameters();
        expressions.add(0, varX("$self", receiver));
    }
    ArgumentListExpression newArgs = args(expressions);

    for (int i = 0, expressionsSize = expressions.size(); i < expressionsSize; i++) {
        final Expression expression = expressions.get(i);
        if (visitClosures && expression instanceof ClosureExpression
                || !visitClosures && !(expression instanceof ClosureExpression)) {
            if (i<params.length && visitClosures) {
                Parameter param = params[i];
                checkClosureWithDelegatesTo(receiver, selectedMethod, newArgs,params , expression, param);
                if (selectedMethod instanceof ExtensionMethodNode) {
                    if (i>0) {
                        inferClosureParameterTypes(receiver, arguments, (ClosureExpression)expression, param, selectedMethod);
                    }
                } else {
                    inferClosureParameterTypes(receiver, newArgs, (ClosureExpression) expression, param, selectedMethod);
                }
            }
            expression.visit(this);
            if (expression.getNodeMetaData(StaticTypesMarker.DELEGATION_METADATA)!=null) {
                expression.removeNodeMetaData(StaticTypesMarker.DELEGATION_METADATA);
            }
        }
    }
}
 
开发者ID:apache,项目名称:groovy,代码行数:32,代码来源:StaticTypeCheckingVisitor.java

示例7: getDeclaringClass

import org.codehaus.groovy.ast.expr.Expression; //导入方法依赖的package包/类
private static ClassNode getDeclaringClass(MethodNode method, Expression arguments) {
    ClassNode declaringClass = method.getDeclaringClass();

    // correcting declaring class for extension methods:
    if (arguments instanceof ArgumentListExpression) {
        ArgumentListExpression al = (ArgumentListExpression) arguments;
        List<Expression> list = al.getExpressions();
        if (list.isEmpty()) return declaringClass;
        Expression exp = list.get(0);
        ClassNode cn = exp.getNodeMetaData(ExtensionMethodDeclaringClass.class);
        if (cn!=null) return cn;
    }
    return declaringClass;
}
 
开发者ID:apache,项目名称:groovy,代码行数:15,代码来源:StaticTypeCheckingVisitor.java

示例8: removeSetterInfo

import org.codehaus.groovy.ast.expr.Expression; //导入方法依赖的package包/类
private static SetterInfo removeSetterInfo(Expression exp) {
    Object nodeMetaData = exp.getNodeMetaData(SetterInfo.class);
    if (nodeMetaData!=null) {
        exp.removeNodeMetaData(SetterInfo.class);
        return (SetterInfo) nodeMetaData;
    }
    return null;
}
 
开发者ID:apache,项目名称:groovy,代码行数:9,代码来源:StaticTypeCheckingVisitor.java

示例9: transform

import org.codehaus.groovy.ast.expr.Expression; //导入方法依赖的package包/类
@Override
public Expression transform(final Expression exp) {
    if (exp != null) {
        Expression replacement = exp.getNodeMetaData(TraitASTTransformation.POST_TYPECHECKING_REPLACEMENT);
        if (replacement!=null) {
            return replacement;
        }
    }
    return super.transform(exp);
}
 
开发者ID:apache,项目名称:groovy,代码行数:11,代码来源:TraitASTTransformation.java

示例10: makeDirectCall

import org.codehaus.groovy.ast.expr.Expression; //导入方法依赖的package包/类
@Override
protected boolean makeDirectCall(final Expression origin, final Expression receiver, final Expression message, final Expression arguments, final MethodCallerMultiAdapter adapter, final boolean implicitThis, final boolean containsSpreadExpression) {
    if (origin instanceof MethodCallExpression &&
            receiver instanceof VariableExpression &&
            ((VariableExpression) receiver).isSuperExpression()) {
        ClassNode superClass = receiver.getNodeMetaData(StaticCompilationMetadataKeys.PROPERTY_OWNER);
        if (superClass!=null && !controller.getCompileStack().isLHS()) {
            // GROOVY-7300
            MethodCallExpression mce = (MethodCallExpression) origin;
            MethodNode node = superClass.getDeclaredMethod(mce.getMethodAsString(), Parameter.EMPTY_ARRAY);
            mce.setMethodTarget(node);
        }
    }
    return super.makeDirectCall(origin, receiver, message, arguments, adapter, implicitThis, containsSpreadExpression);
}
 
开发者ID:apache,项目名称:groovy,代码行数:16,代码来源:StaticInvocationWriter.java

示例11: visitAssignmentExprAlt

import org.codehaus.groovy.ast.expr.Expression; //导入方法依赖的package包/类
@Override
    public BinaryExpression visitAssignmentExprAlt(AssignmentExprAltContext ctx) {
        Expression leftExpr = (Expression) this.visit(ctx.left);

        if (leftExpr instanceof VariableExpression
                && isInsideParentheses(leftExpr)) { // it is a special multiple assignment whose variable count is only one, e.g. (a) = [1]

            if ((Integer) leftExpr.getNodeMetaData(INSIDE_PARENTHESES_LEVEL) > 1) {
                throw createParsingFailedException("Nested parenthesis is not allowed in multiple assignment, e.g. ((a)) = b", ctx);
            }

            return configureAST(
                    new BinaryExpression(
                            configureAST(new TupleExpression(leftExpr), ctx.left),
                            this.createGroovyToken(ctx.op),
                            this.visitEnhancedStatementExpression(ctx.enhancedStatementExpression())),
                    ctx);
        }

        // the LHS expression should be a variable which is not inside any parentheses
        if (
                !(
                        (leftExpr instanceof VariableExpression
//                                && !(THIS_STR.equals(leftExpr.getText()) || SUPER_STR.equals(leftExpr.getText()))     // commented, e.g. this = value // this will be transformed to $this
                                && !isInsideParentheses(leftExpr)) // e.g. p = 123

                                || leftExpr instanceof PropertyExpression // e.g. obj.p = 123

                                || (leftExpr instanceof BinaryExpression
//                                && !(((BinaryExpression) leftExpr).getRightExpression() instanceof ListExpression)    // commented, e.g. list[1, 2] = [11, 12]
                                && Types.LEFT_SQUARE_BRACKET == ((BinaryExpression) leftExpr).getOperation().getType()) // e.g. map[a] = 123 OR map['a'] = 123 OR map["$a"] = 123
                )

                ) {

            throw createParsingFailedException("The LHS of an assignment should be a variable or a field accessing expression", ctx);
        }

        return configureAST(
                new BinaryExpression(
                        leftExpr,
                        this.createGroovyToken(ctx.op),
                        this.visitEnhancedStatementExpression(ctx.enhancedStatementExpression())),
                ctx);
    }
 
开发者ID:apache,项目名称:groovy,代码行数:46,代码来源:AstBuilder.java

示例12: getTargetMethod

import org.codehaus.groovy.ast.expr.Expression; //导入方法依赖的package包/类
public MethodNode getTargetMethod(final Expression expression) {
    return (MethodNode) expression.getNodeMetaData(StaticTypesMarker.DIRECT_METHOD_CALL_TARGET);
}
 
开发者ID:apache,项目名称:groovy,代码行数:4,代码来源:TypeCheckingExtension.java

示例13: typeCheckAssignment

import org.codehaus.groovy.ast.expr.Expression; //导入方法依赖的package包/类
protected void typeCheckAssignment(
        final BinaryExpression assignmentExpression,
        final Expression leftExpression,
        final ClassNode leftExpressionType,
        final Expression rightExpression,
        final ClassNode inferredRightExpressionTypeOrig)
{
    ClassNode inferredRightExpressionType = inferredRightExpressionTypeOrig;
    if (!typeCheckMultipleAssignmentAndContinue(leftExpression, rightExpression)) return;

    if (leftExpression instanceof VariableExpression
            && ((VariableExpression) leftExpression).getAccessedVariable() instanceof FieldNode) {
        checkOrMarkPrivateAccess(leftExpression, (FieldNode) ((VariableExpression) leftExpression).getAccessedVariable(), true);
    }

    //TODO: need errors for write-only too!
    if (addedReadOnlyPropertyError(leftExpression)) return;

    ClassNode leftRedirect = leftExpressionType.redirect();
    // see if instanceof applies
    if (rightExpression instanceof VariableExpression && hasInferredReturnType(rightExpression) && assignmentExpression.getOperation().getType() == EQUAL) {
        inferredRightExpressionType = rightExpression.getNodeMetaData(StaticTypesMarker.INFERRED_RETURN_TYPE);
    }
    ClassNode wrappedRHS = adjustTypeForSpreading(inferredRightExpressionType, leftExpression);

    // check types are compatible for assignment
    boolean compatible = checkCompatibleAssignmentTypes(leftRedirect, wrappedRHS, rightExpression);


    if (!compatible) {
        if (!extension.handleIncompatibleAssignment(leftExpressionType, inferredRightExpressionType, assignmentExpression)) {
            addAssignmentError(leftExpressionType, inferredRightExpressionType, assignmentExpression.getRightExpression());
        }
    } else {
        addPrecisionErrors(leftRedirect, leftExpressionType, inferredRightExpressionType, rightExpression);
        addListAssignmentConstructorErrors(leftRedirect, leftExpressionType, inferredRightExpressionType, rightExpression, assignmentExpression);
        addMapAssignmentConstructorErrors(leftRedirect, leftExpression, rightExpression);
        if (hasGStringStringError(leftExpressionType, wrappedRHS, rightExpression)) return;
        checkTypeGenerics(leftExpressionType, wrappedRHS, rightExpression);
    }
}
 
开发者ID:apache,项目名称:groovy,代码行数:42,代码来源:StaticTypeCheckingVisitor.java

示例14: checkReturnType

import org.codehaus.groovy.ast.expr.Expression; //导入方法依赖的package包/类
protected ClassNode checkReturnType(final ReturnStatement statement) {
    Expression expression = statement.getExpression();
    ClassNode type = getType(expression);
    if (typeCheckingContext.getEnclosingClosure()!=null) {
        return type;
    }
    // handle instanceof cases
    if ((expression instanceof VariableExpression) && hasInferredReturnType(expression)) {
        type = expression.getNodeMetaData(StaticTypesMarker.INFERRED_RETURN_TYPE);
    }
    MethodNode enclosingMethod = typeCheckingContext.getEnclosingMethod();
    if (enclosingMethod != null && typeCheckingContext.getEnclosingClosure()==null) {
        if (!enclosingMethod.isVoidMethod()
                && !type.equals(void_WRAPPER_TYPE)
                && !type.equals(VOID_TYPE)
                && !checkCompatibleAssignmentTypes(enclosingMethod.getReturnType(), type, null, false)
                && !(isNullConstant(expression))) {
            if (!extension.handleIncompatibleReturnType(statement, type)) {
                addStaticTypeError("Cannot return value of type " + type.toString(false) + " on method returning type " + enclosingMethod.getReturnType().toString(false), expression);
            }
        } else if (!enclosingMethod.isVoidMethod()) {
            ClassNode previousType = getInferredReturnType(enclosingMethod);
            ClassNode inferred = previousType == null ? type : lowestUpperBound(type, previousType);
            if (implementsInterfaceOrIsSubclassOf(inferred, enclosingMethod.getReturnType())) {
                if (missesGenericsTypes(inferred)) {
                    DeclarationExpression virtualDecl = new DeclarationExpression(
                            varX("{target}", enclosingMethod.getReturnType()),
                            Token.newSymbol(EQUAL, -1, -1),
                            varX("{source}", type)
                    );
                    virtualDecl.setSourcePosition(statement);
                    virtualDecl.visit(this);
                    ClassNode newlyInferred = (ClassNode) virtualDecl.getNodeMetaData(StaticTypesMarker.INFERRED_TYPE);
                    if (!missesGenericsTypes(newlyInferred)) type = newlyInferred;
                } else {
                    checkTypeGenerics(enclosingMethod.getReturnType(), inferred, expression);
                }
                return type;
            } else {
                return enclosingMethod.getReturnType();
            }
        }
    }
    return type;
}
 
开发者ID:apache,项目名称:groovy,代码行数:46,代码来源:StaticTypeCheckingVisitor.java

示例15: visitTernaryExpression

import org.codehaus.groovy.ast.expr.Expression; //导入方法依赖的package包/类
@Override
public void visitTernaryExpression(final TernaryExpression expression) {
    Map<VariableExpression, List<ClassNode>> oldTracker = pushAssignmentTracking();
    // create a new temporary element in the if-then-else type info
    typeCheckingContext.pushTemporaryTypeInfo();
    expression.getBooleanExpression().visit(this);
    Expression trueExpression = expression.getTrueExpression();
    Expression falseExpression = expression.getFalseExpression();
    trueExpression.visit(this);
    // pop if-then-else temporary type info
    typeCheckingContext.popTemporaryTypeInfo();
    falseExpression.visit(this);
    ClassNode resultType;
    ClassNode typeOfFalse = getType(falseExpression);
    ClassNode typeOfTrue = getType(trueExpression);
    // handle instanceof cases
    if (hasInferredReturnType(falseExpression)) {
        typeOfFalse = falseExpression.getNodeMetaData(StaticTypesMarker.INFERRED_RETURN_TYPE);
    }
    if (hasInferredReturnType(trueExpression)) {
        typeOfTrue = trueExpression.getNodeMetaData(StaticTypesMarker.INFERRED_RETURN_TYPE);
    }
    // TODO consider moving next two statements "up a level", i.e. have just one more widely invoked
    // check but determine no -ve consequences first
    typeOfFalse = checkForTargetType(falseExpression, typeOfFalse);
    typeOfTrue = checkForTargetType(trueExpression, typeOfTrue);
    if (isNullConstant(trueExpression) || isNullConstant(falseExpression)) {
        BinaryExpression enclosingBinaryExpression = typeCheckingContext.getEnclosingBinaryExpression();
        if (enclosingBinaryExpression != null && enclosingBinaryExpression.getRightExpression()==expression) {
            resultType = getType(enclosingBinaryExpression.getLeftExpression());
        } else if (isNullConstant(trueExpression) && isNullConstant(falseExpression)) {
            resultType = OBJECT_TYPE;
        } else if (isNullConstant(trueExpression)) {
            resultType = wrapTypeIfNecessary(typeOfFalse);
        } else {
            resultType = wrapTypeIfNecessary(typeOfTrue);
        }
    } else {
        // store type information
        resultType = lowestUpperBound(typeOfTrue, typeOfFalse);
    }
    storeType(expression, resultType);
    popAssignmentTracking(oldTracker);
}
 
开发者ID:apache,项目名称:groovy,代码行数:45,代码来源:StaticTypeCheckingVisitor.java


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