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


Java ListExpression.addExpression方法代码示例

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


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

示例1: transformInlineConstants

import org.codehaus.groovy.ast.expr.ListExpression; //导入方法依赖的package包/类
private Expression transformInlineConstants(Expression exp) {
    if (exp instanceof PropertyExpression) {
        PropertyExpression pe = (PropertyExpression) exp;
        if (pe.getObjectExpression() instanceof ClassExpression) {
            ClassExpression ce = (ClassExpression) pe.getObjectExpression();
            ClassNode type = ce.getType();
            if (type.isEnum()) return exp;
            Expression constant = findConstant(getField(type, pe.getPropertyAsString()));
            if (constant != null) return constant;
        }
    } else if (exp instanceof ListExpression) {
        ListExpression le = (ListExpression) exp;
        ListExpression result = new ListExpression();
        for (Expression e : le.getExpressions()) {
            result.addExpression(transformInlineConstants(e));
        }
        return result;
    }

    return exp;
}
 
开发者ID:apache,项目名称:groovy,代码行数:22,代码来源:StaticImportVisitor.java

示例2: indexExpression

import org.codehaus.groovy.ast.expr.ListExpression; //导入方法依赖的package包/类
protected Expression indexExpression(AST indexNode) {
    AST bracket = indexNode.getFirstChild();
    AST leftNode = bracket.getNextSibling();
    Expression leftExpression = expression(leftNode);

    AST rightNode = leftNode.getNextSibling();
    Expression rightExpression = expression(rightNode);
    // easier to massage here than in the grammar
    if (rightExpression instanceof SpreadExpression) {
        ListExpression wrapped = new ListExpression();
        wrapped.addExpression(rightExpression);
        rightExpression = wrapped;
    }

    BinaryExpression binaryExpression = new BinaryExpression(leftExpression, makeToken(Types.LEFT_SQUARE_BRACKET, bracket), rightExpression);
    configureAST(binaryExpression, indexNode);
    return binaryExpression;
}
 
开发者ID:apache,项目名称:groovy,代码行数:19,代码来源:AntlrParserPlugin.java

示例3: annotationValueToExpression

import org.codehaus.groovy.ast.expr.ListExpression; //导入方法依赖的package包/类
private Expression annotationValueToExpression (Object value) {
    if (value == null || value instanceof String || value instanceof Number || value instanceof Character || value instanceof Boolean)
        return new ConstantExpression(value);

    if (value instanceof Class)
        return new ClassExpression(ClassHelper.makeWithoutCaching((Class)value));

    if (value.getClass().isArray()) {
        ListExpression elementExprs = new ListExpression();
        int len = Array.getLength(value);
        for (int i = 0; i != len; ++i)
            elementExprs.addExpression(annotationValueToExpression(Array.get(value, i)));
        return elementExprs;
    }

    return null;
}
 
开发者ID:apache,项目名称:groovy,代码行数:18,代码来源:Java5.java

示例4: addEnumConstant

import org.codehaus.groovy.ast.expr.ListExpression; //导入方法依赖的package包/类
public static FieldNode addEnumConstant(ClassNode enumClass, String name, Expression init) {
    int modifiers = PUBLIC_FS | Opcodes.ACC_ENUM;
    if (init != null && !(init instanceof ListExpression)) {
        ListExpression list = new ListExpression();
        list.addExpression(init);
        init = list;
    }
    FieldNode fn = new FieldNode(name, modifiers, enumClass.getPlainNodeReference(), enumClass, init);
    enumClass.addField(fn);
    return fn;
}
 
开发者ID:apache,项目名称:groovy,代码行数:12,代码来源:EnumHelper.java

示例5: buildSubstitutions

import org.codehaus.groovy.ast.expr.ListExpression; //导入方法依赖的package包/类
public static ListExpression buildSubstitutions(final SourceUnit source, final ASTNode expr) {
    final ListExpression listExpression = new ListExpression();

    ClassCodeVisitorSupport visitor = new ClassCodeVisitorSupport() {
        @Override
        protected SourceUnit getSourceUnit() {
            return null;
        }

        @Override
        public void visitClass(final ClassNode node) {
            super.visitClass(node);
            Iterator<InnerClassNode> it = node.getInnerClasses();
            while (it.hasNext()) {
                InnerClassNode next = it.next();
                visitClass(next);
            }
        }

        @Override
        public void visitMethodCallExpression(MethodCallExpression call) {
            super.visitMethodCallExpression(call);

            if (DOLLAR_VALUE.equals(call.getMethodAsString())) {
                ClosureExpression substitutionClosureExpression = getClosureArgument(source, call);

                if (substitutionClosureExpression == null) {
                    return;
                }

                Statement code = substitutionClosureExpression.getCode();
                if (code instanceof BlockStatement) {
                    ((BlockStatement) code).setVariableScope(null);
                }

                listExpression.addExpression(substitutionClosureExpression);
            }
        }
    };
    if (expr instanceof ClassNode) {
        visitor.visitClass((ClassNode) expr);
    } else {
        expr.visit(visitor);
    }
    return listExpression;
}
 
开发者ID:apache,项目名称:groovy,代码行数:47,代码来源:MacroGroovyMethods.java

示例6: visitExpression

import org.codehaus.groovy.ast.expr.ListExpression; //导入方法依赖的package包/类
protected void visitExpression(String attrName, Expression attrExp, ClassNode attrType) {
    if (attrType.isArray()) {
        // check needed as @Test(attr = {"elem"}) passes through the parser
        if (attrExp instanceof ListExpression) {
            ListExpression le = (ListExpression) attrExp;
            visitListExpression(attrName, le, attrType.getComponentType());
        } else if (attrExp instanceof ClosureExpression) {
            addError("Annotation list attributes must use Groovy notation [el1, el2]", attrExp);
        } else {
            // treat like a singleton list as per Java
            ListExpression listExp = new ListExpression();
            listExp.addExpression(attrExp);
            if (annotation != null) {
                annotation.setMember(attrName, listExp);
            }
            visitExpression(attrName, listExp, attrType);
        }
    } else if (ClassHelper.isPrimitiveType(attrType)) {
        visitConstantExpression(attrName, getConstantExpression(attrExp, attrType), ClassHelper.getWrapper(attrType));
    } else if (ClassHelper.STRING_TYPE.equals(attrType)) {
        visitConstantExpression(attrName, getConstantExpression(attrExp, attrType), ClassHelper.STRING_TYPE);
    } else if (ClassHelper.CLASS_Type.equals(attrType)) {
        if (!(attrExp instanceof ClassExpression || attrExp instanceof ClosureExpression)) {
            addError("Only classes and closures can be used for attribute '" + attrName + "'", attrExp);
        }
    } else if (attrType.isDerivedFrom(ClassHelper.Enum_Type)) {
        if (attrExp instanceof PropertyExpression) {
            visitEnumExpression(attrName, (PropertyExpression) attrExp, attrType);
        } else {
            addError("Expected enum value for attribute " + attrName, attrExp);
        }
    } else if (isValidAnnotationClass(attrType)) {
        if (attrExp instanceof AnnotationConstantExpression) {
            visitAnnotationExpression(attrName, (AnnotationConstantExpression) attrExp, attrType);
        } else {
            addError("Expected annotation of type '" + attrType.getName() + "' for attribute " + attrName, attrExp);
        }
    } else {
        addError("Unexpected type " + attrType.getName(), attrExp);
    }
}
 
开发者ID:apache,项目名称:groovy,代码行数:42,代码来源:AnnotationVisitor.java


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