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


Java DeclarationExpression.getRightExpression方法代码示例

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


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

示例1: changeBaseScriptTypeFromDeclaration

import org.codehaus.groovy.ast.expr.DeclarationExpression; //导入方法依赖的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

示例2: transformDeclarationExpression

import org.codehaus.groovy.ast.expr.DeclarationExpression; //导入方法依赖的package包/类
protected Expression transformDeclarationExpression(DeclarationExpression de) {
    visitAnnotations(de);
    Expression oldLeft = de.getLeftExpression();
    checkingVariableTypeInDeclaration = true;
    Expression left = transform(oldLeft);
    checkingVariableTypeInDeclaration = false;
    if (left instanceof ClassExpression) {
        ClassExpression ce = (ClassExpression) left;
        addError("you tried to assign a value to the class " + ce.getType().getName(), oldLeft);
        return de;
    }
    Expression right = transform(de.getRightExpression());
    if (right == de.getRightExpression()) {
        fixDeclaringClass(de);
        return de;
    }
    DeclarationExpression newDeclExpr = new DeclarationExpression(left, de.getOperation(), right);
    newDeclExpr.setDeclaringClass(de.getDeclaringClass());
    fixDeclaringClass(newDeclExpr);
    newDeclExpr.setSourcePosition(de);
    newDeclExpr.addAnnotations(de.getAnnotations());
    return newDeclExpr;
}
 
开发者ID:apache,项目名称:groovy,代码行数:24,代码来源:ResolveVisitor.java

示例3: setScriptURIOnDeclaration

import org.codehaus.groovy.ast.expr.DeclarationExpression; //导入方法依赖的package包/类
private void setScriptURIOnDeclaration(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;
    }

    URI uri = getSourceURI(node);

    if (uri == null) {
        addError("Unable to get the URI for the source of this script!", de);
    } else {
        // Set the RHS to '= URI.create("string for this URI")'.
        // That may throw an IllegalArgumentExpression wrapping the URISyntaxException.
        de.setRightExpression(getExpression(uri));
    }
}
 
开发者ID:apache,项目名称:groovy,代码行数:22,代码来源:SourceURIASTTransformation.java

示例4: changeBaseScriptTypeFromDeclaration

import org.codehaus.groovy.ast.expr.DeclarationExpression; //导入方法依赖的package包/类
private void changeBaseScriptTypeFromDeclaration(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(de, cNode, baseScriptType);
}
 
开发者ID:apache,项目名称:groovy,代码行数:23,代码来源:BaseScriptASTTransformation.java

示例5: visitDeclarationExpression

import org.codehaus.groovy.ast.expr.DeclarationExpression; //导入方法依赖的package包/类
@Override
public void visitDeclarationExpression(DeclarationExpression expression) {
    Expression right = expression.getRightExpression();
    right.visit(this);

    ClassNode leftType = typeChooser.resolveType(expression.getLeftExpression(), node);
    Expression rightExpression = expression.getRightExpression();
    ClassNode rightType = optimizeDivWithIntOrLongTarget(rightExpression, leftType);
    if (rightType==null) rightType = typeChooser.resolveType(expression.getRightExpression(), node);
    if (isPrimitiveType(leftType) && isPrimitiveType(rightType)) {
        // if right is a constant, then we optimize only if it makes
        // a block complete, so we set a maybe
        if (right instanceof ConstantExpression) {
            opt.chainCanOptimize(true);
        } else {
            opt.chainShouldOptimize(true);
        }
        StatementMeta meta = addMeta(expression);
        ClassNode declarationType = typeChooser.resolveType(expression, node);
        meta.type = declarationType!=null?declarationType:leftType;
        opt.chainInvolvedType(leftType);
        opt.chainInvolvedType(rightType);
    }
}
 
开发者ID:apache,项目名称:groovy,代码行数:25,代码来源:OptimizingStatementWriter.java

示例6: completeFutureByResults

import org.codehaus.groovy.ast.expr.DeclarationExpression; //导入方法依赖的package包/类
protected void completeFutureByResults(CompletableFuture<EGradleBuildscriptResult> future, List<ASTNode> result) {
	for (ASTNode node : result) {
		BlockStatement bs = (BlockStatement) node;
		for (org.codehaus.groovy.ast.stmt.Statement st : bs.getStatements()) {
			if (st instanceof ReturnStatement) {
				ReturnStatement rs = (ReturnStatement) st;
				Expression expression = rs.getExpression();
				if (expression instanceof DeclarationExpression) {
					DeclarationExpression de = (DeclarationExpression) expression;
					String name = de.getVariableExpression().getName();
					if (! "buildscript".equals(name)){
						continue;
					}
					Expression right = de.getRightExpression();
					if (right instanceof ClosureExpression) {
						ClosureExpression ce = (ClosureExpression) right;
						Statement buildCode = ce.getCode();
						
						future.complete(new EGradleBuildscriptResult(buildCode));
						return;
					}else{
						future.complete(new EGradleBuildscriptResult(new EGradleBuildScriptException("Did not found expected buildscript closure ,but:"+right)));
						return;
					}
				}
			}
		}
	}
}
 
开发者ID:de-jcup,项目名称:egradle,代码行数:30,代码来源:GradleBuildScriptResultBuilder.java

示例7: createFieldDeclarationListStatement

import org.codehaus.groovy.ast.expr.DeclarationExpression; //导入方法依赖的package包/类
private DeclarationListStatement createFieldDeclarationListStatement(VariableDeclarationContext ctx, ModifierManager modifierManager, ClassNode variableType, List<DeclarationExpression> declarationExpressionList, ClassNode classNode) {
    for (int i = 0, n = declarationExpressionList.size(); i < n; i++) {
        DeclarationExpression declarationExpression = declarationExpressionList.get(i);
        VariableExpression variableExpression = (VariableExpression) declarationExpression.getLeftExpression();

        String fieldName = variableExpression.getName();

        int modifiers = modifierManager.getClassMemberModifiersOpValue();

        Expression initialValue = EmptyExpression.INSTANCE.equals(declarationExpression.getRightExpression()) ? null : declarationExpression.getRightExpression();
        Object defaultValue = findDefaultValueByType(variableType);

        if (classNode.isInterface()) {
            if (!asBoolean(initialValue)) {
                initialValue = !asBoolean(defaultValue) ? null : new ConstantExpression(defaultValue);
            }

            modifiers |= Opcodes.ACC_PUBLIC | Opcodes.ACC_STATIC | Opcodes.ACC_FINAL;
        }

        if (isFieldDeclaration(modifierManager, classNode)) {
            declareField(ctx, modifierManager, variableType, classNode, i, variableExpression, fieldName, modifiers, initialValue);
        } else {
            declareProperty(ctx, modifierManager, variableType, classNode, i, variableExpression, fieldName, modifiers, initialValue);
        }
    }

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

示例8: visit

import org.codehaus.groovy.ast.expr.DeclarationExpression; //导入方法依赖的package包/类
public void visit(ASTNode[] nodes, SourceUnit source) {
        sourceUnit = source;
        if (nodes.length != 2 || !(nodes[0] instanceof AnnotationNode) || !(nodes[1] instanceof AnnotatedNode)) {
            throw new GroovyBugError("Internal error: expecting [AnnotationNode, AnnotatedNode] but got: " + Arrays.asList(nodes));
        }

        AnnotatedNode parent = (AnnotatedNode) nodes[1];
        AnnotationNode node = (AnnotationNode) nodes[0];
        if (!MY_TYPE.equals(node.getClassNode())) return;
        final ClassNode declaringClass = parent.getDeclaringClass();
        
        
        if (parent instanceof DeclarationExpression) {
            DeclarationExpression de = (DeclarationExpression) parent;
            ClassNode cNode = de.getDeclaringClass();
            if (!cNode.isScript()) {
                addError("Annotation " + MY_TYPE_NAME + " can only be used within a Script.", parent);
                return;
            }
            candidate = de;
            // GROOVY-4548: temp fix to stop CCE until proper support is added
            if (de.isMultipleAssignmentDeclaration()) {
                addError("Annotation " + MY_TYPE_NAME + " not supported with multiple assignment notation.", parent);
                return;
            }
            VariableExpression ve = de.getVariableExpression();
            variableName = ve.getName();
            // set owner null here, it will be updated by addField
            final int modifiers = ve.getModifiers() | Modifier.VOLATILE | Modifier.PUBLIC;
            fieldNode = new FieldNode(variableName, modifiers, ve.getType(), null, de.getRightExpression());
            fieldNode.setSourcePosition(de);
            fieldNode.addAnnotation(node);
            fieldNode.setInitialValueExpression(new FieldExpression(fieldNode));
            cNode.addField(fieldNode);

            // GROOVY-4833 : annotations that are not Groovy transforms should be transferred to the generated field
            // GROOVY-6112 : also copy acceptable Groovy transforms
            final List<AnnotationNode> annotations = de.getAnnotations();
            for (AnnotationNode annotation : annotations) {
                // GROOVY-6337 HACK: in case newly created field is @Lazy
                if (annotation.getClassNode().equals(LAZY_TYPE)) {
                	PrivateAccessor.invokeStatic(LazyASTTransformation.class, "visitField", annotation, fieldNode);
//                    LazyASTTransformation.visitField(annotation, fieldNode);
                }
//                if(annotation.getClassNode().equals(MY_TYPE)) {
//                	final Map<String, Expression> members = annotation.getMembers();
//                	final Expression expr = members.remove("value");
//                	if(expr!=null) {
//                		final String exprValue = expr.getText();
//                		System.err.println("EXPR:" + exprValue);
//                	}
//                }
                
                final ClassNode annotationClassNode = annotation.getClassNode();
                if (notTransform(annotationClassNode) || acceptableTransform(annotation)) {
                    fieldNode.addAnnotation(annotation);
                }
            }

            super.visitClass(cNode);
            // GROOVY-5207 So that Closures can see newly added fields
            // (not super efficient for a very large class with many @Fields but we chose simplicity
            // and understandability of this solution over more complex but efficient alternatives)
            VariableScopeVisitor scopeVisitor = new VariableScopeVisitor(source);
            scopeVisitor.visitClass(cNode);
        }
    }
 
开发者ID:nickman,项目名称:HeliosStreams,代码行数:68,代码来源:VolatileFieldASTTransformation.java

示例9: processLocalVariable

import org.codehaus.groovy.ast.expr.DeclarationExpression; //导入方法依赖的package包/类
private void processLocalVariable(DeclarationExpression de, ClassCodeVisitorSupport visitor) {
    if (!isEnabled(de)) return;
    if (de.getRightExpression() instanceof ClosureExpression) {
        visitor.visitDeclarationExpression(de);
    }
}
 
开发者ID:apache,项目名称:groovy,代码行数:7,代码来源:AutoFinalASTTransformation.java

示例10: visit

import org.codehaus.groovy.ast.expr.DeclarationExpression; //导入方法依赖的package包/类
public void visit(ASTNode[] nodes, SourceUnit source) {
    sourceUnit = source;
    if (nodes.length != 2 || !(nodes[0] instanceof AnnotationNode) || !(nodes[1] instanceof AnnotatedNode)) {
        throw new GroovyBugError("Internal error: expecting [AnnotationNode, AnnotatedNode] but got: " + Arrays.asList(nodes));
    }

    AnnotatedNode parent = (AnnotatedNode) nodes[1];
    AnnotationNode node = (AnnotationNode) nodes[0];
    if (!MY_TYPE.equals(node.getClassNode())) return;

    if (parent instanceof DeclarationExpression) {
        DeclarationExpression de = (DeclarationExpression) parent;
        ClassNode cNode = de.getDeclaringClass();
        if (!cNode.isScript()) {
            addError("Annotation " + MY_TYPE_NAME + " can only be used within a Script.", parent);
            return;
        }
        candidate = de;
        // GROOVY-4548: temp fix to stop CCE until proper support is added
        if (de.isMultipleAssignmentDeclaration()) {
            addError("Annotation " + MY_TYPE_NAME + " not supported with multiple assignment notation.", parent);
            return;
        }
        VariableExpression ve = de.getVariableExpression();
        variableName = ve.getName();
        // set owner null here, it will be updated by addField
        fieldNode = new FieldNode(variableName, ve.getModifiers(), ve.getType(), null, de.getRightExpression());
        fieldNode.setSourcePosition(de);
        cNode.addField(fieldNode);
        // provide setter for CLI Builder purposes unless final
        if (fieldNode.isFinal()) {
            if (!de.getAnnotations(OPTION_TYPE).isEmpty()) {
                addError("Can't have a final field also annotated with @" + OPTION_TYPE.getNameWithoutPackage(), de);
            }
        } else {
            String setterName = "set" + MetaClassHelper.capitalize(variableName);
            cNode.addMethod(setterName, ACC_PUBLIC | ACC_SYNTHETIC, ClassHelper.VOID_TYPE, params(param(ve.getType(), variableName)), ClassNode.EMPTY_ARRAY, block(
                    stmt(assignX(propX(varX("this"), variableName), varX(variableName)))
            ));
        }

        // GROOVY-4833 : annotations that are not Groovy transforms should be transferred to the generated field
        // GROOVY-6112 : also copy acceptable Groovy transforms
        final List<AnnotationNode> annotations = de.getAnnotations();
        for (AnnotationNode annotation : annotations) {
            // GROOVY-6337 HACK: in case newly created field is @Lazy
            if (annotation.getClassNode().equals(LAZY_TYPE)) {
                LazyASTTransformation.visitField(this, annotation, fieldNode);
            }
            final ClassNode annotationClassNode = annotation.getClassNode();
            if (notTransform(annotationClassNode) || acceptableTransform(annotation)) {
                fieldNode.addAnnotation(annotation);
            }
        }

        super.visitClass(cNode);
        // GROOVY-5207 So that Closures can see newly added fields
        // (not super efficient for a very large class with many @Fields but we chose simplicity
        // and understandability of this solution over more complex but efficient alternatives)
        VariableScopeVisitor scopeVisitor = new VariableScopeVisitor(source);
        scopeVisitor.visitClass(cNode);
    }
}
 
开发者ID:apache,项目名称:groovy,代码行数:64,代码来源:FieldASTTransformation.java


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