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


Java ClassNode.addMethod方法代码示例

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


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

示例1: transformationOfAnnotationOnLocalVariable

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

	DeclarationExpression declarationExpression = new DeclarationExpression(
			new VariableExpression("test"), null, new ConstantExpression("test"));
	declarationExpression.addAnnotation(this.grabAnnotation);

	BlockStatement code = new BlockStatement(
			Arrays.asList((Statement) new ExpressionStatement(declarationExpression)),
			new VariableScope());

	MethodNode methodNode = new MethodNode("test", 0, new ClassNode(Void.class),
			new Parameter[0], new ClassNode[0], code);

	classNode.addMethod(methodNode);

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

示例2: transformationOfAnnotationOnConstructor

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

	ConstructorNode constructorNode = new ConstructorNode(0, null);
	constructorNode.addAnnotation(this.grabAnnotation);
	classNode.addMethod(constructorNode);

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

示例3: transformationOfAnnotationOnMethod

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

	MethodNode methodNode = new MethodNode("test", 0, new ClassNode(Void.class),
			new Parameter[0], new ClassNode[0], null);
	methodNode.addAnnotation(this.grabAnnotation);
	classNode.addMethod(methodNode);

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

示例4: transformationOfAnnotationOnMethodParameter

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

	Parameter parameter = new Parameter(new ClassNode(Object.class), "test");
	parameter.addAnnotation(this.grabAnnotation);

	MethodNode methodNode = new MethodNode("test", 0, new ClassNode(Void.class),
			new Parameter[] { parameter }, new ClassNode[0], null);
	classNode.addMethod(methodNode);

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

示例5: changeBaseScriptType

import org.codehaus.groovy.ast.ClassNode; //导入方法依赖的package包/类
private void changeBaseScriptType(final SourceUnit source, final AnnotatedNode parent, final ClassNode cNode, final ClassNode baseScriptType, final AnnotationNode node) {
    if (!cNode.isScriptBody()) {
        addError("Annotation " + MY_TYPE_NAME + " can only be used within a Script.", parent);
        return;
    }

    if (!baseScriptType.isScript()) {
        addError("Declared type " + baseScriptType + " does not extend groovy.lang.Script class!", parent);
        return;
    }

    List<AnnotationNode> annotations = parent.getAnnotations(COMMAND_TYPE);
    cNode.addAnnotations(annotations);
    cNode.setSuperClass(baseScriptType);


    // Method in base script that will contain the script body code.
    MethodNode runScriptMethod = ClassHelper.findSAM(baseScriptType);

    // If they want to use a name other than than "run", then make the change.
    if (isCustomScriptBodyMethod(runScriptMethod)) {
        MethodNode defaultMethod = cNode.getDeclaredMethod("run", Parameter.EMPTY_ARRAY);
        // GROOVY-6706: Sometimes an NPE is thrown here.
        // The reason is that our transform is getting called more than once sometimes.
        if (defaultMethod != null) {
            cNode.removeMethod(defaultMethod);
            MethodNode methodNode = new MethodNode(runScriptMethod.getName(), runScriptMethod.getModifiers() & ~ACC_ABSTRACT
                    , runScriptMethod.getReturnType(), runScriptMethod.getParameters(), runScriptMethod.getExceptions()
                    , defaultMethod.getCode());
            // The AST node metadata has the flag that indicates that this method is a script body.
            // It may also be carrying data for other AST transforms.
            methodNode.copyNodeMetaData(defaultMethod);
            cNode.addMethod(methodNode);
        }
    }

    // If the new script base class does not have a contextual constructor (g.l.Binding), then we won't either.
    // We have to do things this way (and rely on just default constructors) because the logic that generates
    // the constructors for our script class have already run.
    if (cNode.getSuperClass().getDeclaredConstructor(CONTEXT_CTOR_PARAMETERS) == null) {
        ConstructorNode orphanedConstructor = cNode.getDeclaredConstructor(CONTEXT_CTOR_PARAMETERS);
        cNode.removeConstructor(orphanedConstructor);
    }
}
 
开发者ID:remkop,项目名称:picocli,代码行数:45,代码来源:PicocliScriptASTTransformation.java


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