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


Java Expression类代码示例

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


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

示例1: changeBaseScriptTypeFromPackageOrImport

import org.codehaus.groovy.ast.expr.Expression; //导入依赖的package包/类
private void changeBaseScriptTypeFromPackageOrImport(final SourceUnit source, final AnnotatedNode parent, final AnnotationNode node) {
    Expression value = node.getMember("value");
    ClassNode scriptType;
    if (value == null) {
        scriptType = BASE_SCRIPT_TYPE;
    } else {
        if (!(value instanceof ClassExpression)) {
            addError("Annotation " + MY_TYPE_NAME + " member 'value' should be a class literal.", value);
            return;
        }
        scriptType = value.getType();
    }
    List<ClassNode> classes = source.getAST().getClasses();
    for (ClassNode classNode : classes) {
        if (classNode.isScriptBody()) {
            changeBaseScriptType(source, parent, classNode, scriptType, node);
        }
    }
}
 
开发者ID:remkop,项目名称:picocli,代码行数:20,代码来源:PicocliScriptASTTransformation.java

示例2: changeBaseScriptTypeFromDeclaration

import org.codehaus.groovy.ast.expr.Expression; //导入依赖的package包/类
private void changeBaseScriptTypeFromDeclaration(final SourceUnit source, final DeclarationExpression de, final AnnotationNode node) {
    if (de.isMultipleAssignmentDeclaration()) {
        addError("Annotation " + MY_TYPE_NAME + " not supported with multiple assignment notation.", de);
        return;
    }

    if (!(de.getRightExpression() instanceof EmptyExpression)) {
        addError("Annotation " + MY_TYPE_NAME + " not supported with variable assignment.", de);
        return;
    }
    Expression value = node.getMember("value");
    if (value != null) {
        addError("Annotation " + MY_TYPE_NAME + " cannot have member 'value' if used on a declaration.", value);
        return;
    }

    ClassNode cNode = de.getDeclaringClass();
    ClassNode baseScriptType = de.getVariableExpression().getType().getPlainNodeReference();
    de.setRightExpression(new VariableExpression("this"));

    changeBaseScriptType(source, de, cNode, baseScriptType, node);
}
 
开发者ID:remkop,项目名称:picocli,代码行数:23,代码来源:PicocliScriptASTTransformation.java

示例3: visit

import org.codehaus.groovy.ast.expr.Expression; //导入依赖的package包/类
@Override
public void visit(ASTNode[] nodes, SourceUnit source) {
    init(nodes, source);
    AnnotatedNode annotatedNode = (AnnotatedNode) nodes[1];
    AnnotationNode annotationNode = (AnnotationNode) nodes[0];

    if (MY_TYPE.equals(annotationNode.getClassNode()) && annotatedNode instanceof ClassNode) {
        final Expression theAggregate = annotationNode.getMember("value");
        final ClassNode theClassNode = (ClassNode) annotatedNode;
        final String aggregateClassName = theAggregate.getType().getName();
        log.fine(() -> MessageFormat.format("Adding event {0} to aggregate {1}",
                theClassNode.getNameWithoutPackage(), aggregateClassName));
        AggregateASTTransformation.addEventToAggregate(aggregateClassName, theClassNode);
    }

}
 
开发者ID:rahulsom,项目名称:grooves,代码行数:17,代码来源:EventASTTransformation.java

示例4: parseLine

import org.codehaus.groovy.ast.expr.Expression; //导入依赖的package包/类
List<T> parseLine(BinaryExpression exp, Class<T> cls) {

        List<T> constantExpressions = new LinkedList<>();

        Expression leftExpression = exp.getLeftExpression();

        if (leftExpression.getClass().equals(cls)) {
            T leftConstantExpression = (T) leftExpression;
            constantExpressions.add(leftConstantExpression);
        } else {
            BinaryExpression leftBinaryExpression = (BinaryExpression) leftExpression;
            List<T> leftConstantExpressions = parseLine(leftBinaryExpression, cls);
            constantExpressions.addAll(leftConstantExpressions);
        }

        T rightExpression = (T) exp.getRightExpression();
        constantExpressions.add(rightExpression);

        return constantExpressions;

    }
 
开发者ID:kiview,项目名称:do-with-macro-method,代码行数:22,代码来源:WithBlockLineParser.java

示例5: inspectMethodCallExpression

import org.codehaus.groovy.ast.expr.Expression; //导入依赖的package包/类
private void inspectMethodCallExpression(MethodCallExpression mc, int childIndent, String in) {
		String name = mc.getMethodAsString();
		System.out.println(in+"-method as string:"+name);
		System.out.println("- generic types:"+ mc.getGenericsTypes());
		System.out.println("- type:"+mc.getType().getName());
		Expression method = mc.getMethod();
		inspect(method, childIndent);
//		System.out.println(in+"-type:"+mc.getType());
		Expression args = mc.getArguments();
		System.out.println(in + "-arguments:");
		inspect(args, childIndent);
		// System.out.println(in + "-method:");
		// System.out.println(in + "-target:");
		// inspect(mc.getMethodTarget(), childIndent);
		ASTNode receiver = mc.getReceiver();
		if (receiver!=null){
			System.out.println(in+"// Receiver found ...");
			inspect(receiver, childIndent);
		}
	}
 
开发者ID:de-jcup,项目名称:egradle,代码行数:21,代码来源:GradleBuildScriptResultInspector.java

示例6: createDependencyMaps

import org.codehaus.groovy.ast.expr.Expression; //导入依赖的package包/类
private List<Map<String, String>> createDependencyMaps(Expression valueExpression) {
	Map<String, String> dependency = null;
	List<ConstantExpression> constantExpressions = getConstantExpressions(
			valueExpression);
	List<Map<String, String>> dependencies = new ArrayList<Map<String, String>>(
			constantExpressions.size());
	for (ConstantExpression expression : constantExpressions) {
		Object value = expression.getValue();
		if (value instanceof String) {
			String[] components = ((String) expression.getValue()).split(":");
			if (components.length == 3) {
				dependency = new HashMap<String, String>();
				dependency.put("group", components[0]);
				dependency.put("module", components[1]);
				dependency.put("version", components[2]);
				dependency.put("type", "pom");
				dependencies.add(dependency);
			}
			else {
				handleMalformedDependency(expression);
			}
		}
	}
	return dependencies;
}
 
开发者ID:vikrammane23,项目名称:https-github.com-g0t4-jenkins2-course-spring-boot,代码行数:26,代码来源:DependencyManagementBomTransformation.java

示例7: getConstantExpressions

import org.codehaus.groovy.ast.expr.Expression; //导入依赖的package包/类
private List<ConstantExpression> getConstantExpressions(
		ListExpression valueExpression) {
	List<ConstantExpression> expressions = new ArrayList<ConstantExpression>();
	for (Expression expression : valueExpression.getExpressions()) {
		if (expression instanceof ConstantExpression
				&& ((ConstantExpression) expression).getValue() instanceof String) {
			expressions.add((ConstantExpression) expression);
		}
		else {
			reportError(
					"Each entry in the array must be an " + "inline string constant",
					expression);
		}
	}
	return expressions;
}
 
开发者ID:vikrammane23,项目名称:https-github.com-g0t4-jenkins2-course-spring-boot,代码行数:17,代码来源:DependencyManagementBomTransformation.java

示例8: applyGroupAndVersion

import org.codehaus.groovy.ast.expr.Expression; //导入依赖的package包/类
private void applyGroupAndVersion(AnnotationNode annotation, String module) {
	if (module != null) {
		setMember(annotation, "module", module);
	}
	else {
		Expression expression = annotation.getMembers().get("module");
		module = (String) ((ConstantExpression) expression).getValue();
	}
	if (annotation.getMember("group") == null) {
		setMember(annotation, "group", this.resolutionContext
				.getArtifactCoordinatesResolver().getGroupId(module));
	}
	if (annotation.getMember("version") == null) {
		setMember(annotation, "version", this.resolutionContext
				.getArtifactCoordinatesResolver().getVersion(module));
	}
}
 
开发者ID:vikrammane23,项目名称:https-github.com-g0t4-jenkins2-course-spring-boot,代码行数:18,代码来源:ResolveDependencyCoordinatesTransformation.java

示例9: getClosure

import org.codehaus.groovy.ast.expr.Expression; //导入依赖的package包/类
/**
 * Extract a top-level {@code name} closure from inside this block if there is one,
 * optionally removing it from the block at the same time.
 * @param block a block statement (class definition)
 * @param name the name to look for
 * @param remove whether or not the extracted closure should be removed
 * @return a beans Closure if one can be found, null otherwise
 */
public static ClosureExpression getClosure(BlockStatement block, String name,
		boolean remove) {
	for (ExpressionStatement statement : getExpressionStatements(block)) {
		Expression expression = statement.getExpression();
		if (expression instanceof MethodCallExpression) {
			ClosureExpression closure = getClosure(name,
					(MethodCallExpression) expression);
			if (closure != null) {
				if (remove) {
					block.getStatements().remove(statement);
				}
				return closure;
			}
		}
	}
	return null;
}
 
开发者ID:vikrammane23,项目名称:https-github.com-g0t4-jenkins2-course-spring-boot,代码行数:26,代码来源:AstUtils.java

示例10: getValue

import org.codehaus.groovy.ast.expr.Expression; //导入依赖的package包/类
private List<String> getValue() {
	Expression expression = findAnnotation().getMember("value");
	if (expression instanceof ListExpression) {
		List<String> list = new ArrayList<String>();
		for (Expression ex : ((ListExpression) expression).getExpressions()) {
			list.add((String) ((ConstantExpression) ex).getValue());
		}
		return list;
	}
	else if (expression == null) {
		return null;
	}
	else {
		throw new IllegalStateException("Member 'value' is not a ListExpression");
	}
}
 
开发者ID:vikrammane23,项目名称:https-github.com-g0t4-jenkins2-course-spring-boot,代码行数:17,代码来源:GenericBomAstTransformationTests.java

示例11: createBuilderMethodForField

import org.codehaus.groovy.ast.expr.Expression; //导入依赖的package包/类
private MethodNode createBuilderMethodForField(ClassNode builder, List<FieldNode> fields, String prefix, int fieldPos) {
    String fieldName = fields.get(fieldPos).getName();
    String setterName = getSetterName(prefix, fieldName);
    GenericsType[] gtypes = new GenericsType[fields.size()];
    List<Expression> argList = new ArrayList<Expression>();
    for (int i = 0; i < fields.size(); i++) {
        gtypes[i] = i == fieldPos ? new GenericsType(ClassHelper.make(SET.class)) : makePlaceholder(i);
        argList.add(i == fieldPos ? propX(varX("this"), constX(fieldName)) : varX(fields.get(i).getName()));
    }
    ClassNode returnType = makeClassSafeWithGenerics(builder, gtypes);
    FieldNode fNode = fields.get(fieldPos);
    Map<String,ClassNode> genericsSpec = createGenericsSpec(fNode.getDeclaringClass());
    extractSuperClassGenerics(fNode.getType(), builder, genericsSpec);
    ClassNode correctedType = correctToGenericsSpecRecurse(genericsSpec, fNode.getType());
    return new MethodNode(setterName, ACC_PUBLIC, returnType, params(param(correctedType, fieldName)), NO_EXCEPTIONS, block(
            stmt(assignX(propX(varX("this"), constX(fieldName)), varX(fieldName, correctedType))),
            returnS(ctorX(returnType, args(argList)))
    ));
}
 
开发者ID:apache,项目名称:groovy,代码行数:20,代码来源:InitializerStrategy.java

示例12: checkTypeGenerics

import org.codehaus.groovy.ast.expr.Expression; //导入依赖的package包/类
private void checkTypeGenerics(ClassNode leftExpressionType, ClassNode wrappedRHS, Expression rightExpression) {
    // last, check generic type information to ensure that inferred types are compatible
    if (!leftExpressionType.isUsingGenerics()) return;
    // List<Foo> l = new List() is an example for incomplete generics type info
    // we assume arity related errors are already handled here.
    if (hasRHSIncompleteGenericTypeInfo(wrappedRHS)) return;

    GenericsType gt = GenericsUtils.buildWildcardType(leftExpressionType);
    if (    UNKNOWN_PARAMETER_TYPE.equals(wrappedRHS) ||
            gt.isCompatibleWith(wrappedRHS) ||
            isNullConstant(rightExpression)) return;

    addStaticTypeError("Incompatible generic argument types. Cannot assign "
            + wrappedRHS.toString(false)
            + " to: " + leftExpressionType.toString(false), rightExpression);
}
 
开发者ID:apache,项目名称:groovy,代码行数:17,代码来源:StaticTypeCheckingVisitor.java

示例13: doPrimitiveCompare

import org.codehaus.groovy.ast.expr.Expression; //导入依赖的package包/类
protected boolean doPrimitiveCompare(ClassNode leftType, ClassNode rightType, BinaryExpression binExp) {
    Expression leftExp = binExp.getLeftExpression();
    Expression rightExp = binExp.getRightExpression();
    int operation = binExp.getOperation().getType();
    
    int operationType = getOperandConversionType(leftType,rightType);
    BinaryExpressionWriter bew = binExpWriter[operationType];

    if (!bew.write(operation, true)) return false;
        
    AsmClassGenerator acg = getController().getAcg();
    OperandStack os = getController().getOperandStack();
    leftExp.visit(acg);
    os.doGroovyCast(bew.getNormalOpResultType());
    rightExp.visit(acg);
    os.doGroovyCast(bew.getNormalOpResultType());
    bew.write(operation, false);
    
    return true;
}
 
开发者ID:apache,项目名称:groovy,代码行数:21,代码来源:BinaryExpressionMultiTypeDispatcher.java

示例14: writeNormalConstructorCall

import org.codehaus.groovy.ast.expr.Expression; //导入依赖的package包/类
protected void writeNormalConstructorCall(ConstructorCallExpression call) {
    Expression arguments = call.getArguments();
    if (arguments instanceof TupleExpression) {
        TupleExpression tupleExpression = (TupleExpression) arguments;
        int size = tupleExpression.getExpressions().size();
        if (size == 0) {
            arguments = MethodCallExpression.NO_ARGUMENTS;
        }
    }

    Expression receiverClass = new ClassExpression(call.getType());
    controller.getCallSiteWriter().makeCallSite(
            receiverClass, CallSiteWriter.CONSTRUCTOR,
            arguments, false, false, false,
            false);
}
 
开发者ID:apache,项目名称:groovy,代码行数:17,代码来源:InvocationWriter.java

示例15: visitMethodCallExpression

import org.codehaus.groovy.ast.expr.Expression; //导入依赖的package包/类
@Override
public void visitMethodCallExpression(final MethodCallExpression call) {
    boolean old = inBuilderMethod;
    inBuilderMethod = false;
    if (call.isImplicitThis() && call.getArguments() instanceof TupleExpression) {
        List<Expression> expressions = ((TupleExpression) call.getArguments()).getExpressions();
        if (!expressions.isEmpty()) {
            Expression lastArg = expressions.get(expressions.size() - 1);
            if (lastArg instanceof ClosureExpression) {
                call.getObjectExpression().visit(this);
                call.getMethod().visit(this);
                for (Expression expression : expressions) {
                    inBuilderMethod =  (expression == lastArg);
                    expression.visit(this);
                }
            }
        }
    } else {
        super.visitMethodCallExpression(call);
    }
    inBuilderMethod = old;
}
 
开发者ID:apache,项目名称:groovy,代码行数:23,代码来源:AutoNewLineTransformer.java


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