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


Java ClassNode.addField方法代码示例

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


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

示例1: transformationOfAnnotationOnField

import org.codehaus.groovy.ast.ClassNode; //导入方法依赖的package包/类
@Test
public void transformationOfAnnotationOnField() {
	ClassNode classNode = new ClassNode("Test", 0, new ClassNode(Object.class));
	this.moduleNode.addClass(classNode);

	FieldNode fieldNode = new FieldNode("test", 0, new ClassNode(Object.class),
			classNode, null);
	classNode.addField(fieldNode);

	fieldNode.addAnnotation(this.grabAnnotation);

	assertGrabAnnotationHasBeenTransformed();
}
 
开发者ID:vikrammane23,项目名称:https-github.com-g0t4-jenkins2-course-spring-boot,代码行数:14,代码来源:ResolveDependencyCoordinatesTransformationTests.java

示例2: visit

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


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