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


Java ClassHelper.make方法代码示例

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


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

示例1: findMacroMethods

import org.codehaus.groovy.ast.ClassHelper; //导入方法依赖的package包/类
/**
 * Finds all extension methods of {@link MacroContext} for given methodName
 * with @{@link org.codehaus.groovy.macro.runtime.Macro} annotation.
 */
private List<MethodNode> findMacroMethods(String methodName, List<Expression> callArguments) {
    List<MethodNode> methods = MacroMethodsCache.get(classLoader).get(methodName);

    if (methods == null) {
        // Not a macro call
        return Collections.emptyList();
    }

    ClassNode[] argumentsList = new ClassNode[callArguments.size()];

    for (int i = 0; i < callArguments.size(); i++) {
        argumentsList[i] = ClassHelper.make(callArguments.get(i).getClass());
    }

    return StaticTypeCheckingSupport.chooseBestMethod(MACRO_CONTEXT_CLASS_NODE, methods, argumentsList);
}
 
开发者ID:apache,项目名称:groovy,代码行数:21,代码来源:MacroCallTransformingVisitor.java

示例2: createCatchBlockForOuterNewTryCatchStatement

import org.codehaus.groovy.ast.ClassHelper; //导入方法依赖的package包/类
private CatchStatement createCatchBlockForOuterNewTryCatchStatement(String primaryExcName) {
    // { ... }
    BlockStatement blockStatement = new BlockStatement();
    String tExcName = this.genTExcName();

    // #primaryExc = #t;
    ExpressionStatement primaryExcAssignStatement =
            new ExpressionStatement(
                    new BinaryExpression(
                            new VariableExpression(primaryExcName),
                            org.codehaus.groovy.syntax.Token.newSymbol(Types.ASSIGN, -1, -1),
                            new VariableExpression(tExcName)));
    astBuilder.appendStatementsToBlockStatement(blockStatement, primaryExcAssignStatement);

    // throw #t;
    ThrowStatement throwTExcStatement = new ThrowStatement(new VariableExpression(tExcName));
    astBuilder.appendStatementsToBlockStatement(blockStatement, throwTExcStatement);

    // Throwable #t
    Parameter tExcParameter = new Parameter(ClassHelper.make(Throwable.class), tExcName);

    return new CatchStatement(tExcParameter, blockStatement);
}
 
开发者ID:apache,项目名称:groovy,代码行数:24,代码来源:TryWithResourcesASTTransformation.java

示例3: createBuilderMethodForField

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

示例4: makeType

import org.codehaus.groovy.ast.ClassHelper; //导入方法依赖的package包/类
protected ClassNode makeType(AST typeNode) {
    ClassNode answer = ClassHelper.DYNAMIC_TYPE;
    AST node = typeNode.getFirstChild();
    if (node != null) {
        if (isType(INDEX_OP, node) || isType(ARRAY_DECLARATOR, node)) {
            answer = makeType(node).makeArray();
        } else {
            checkTypeArgs(node, false);
            answer = ClassHelper.make(qualifiedName(node));
            if (answer.isUsingGenerics()) {
                ClassNode newAnswer = ClassHelper.makeWithoutCaching(answer.getName());
                newAnswer.setRedirect(answer);
                answer = newAnswer;
            }
        }
        configureAST(answer, node);
    }
    return answer;
}
 
开发者ID:apache,项目名称:groovy,代码行数:20,代码来源:AntlrParserPlugin.java

示例5: makeListOfAnnotations

import org.codehaus.groovy.ast.ClassHelper; //导入方法依赖的package包/类
private static List<AnnotationNode> makeListOfAnnotations(Object[][] data) {
    if (data.length == 0) {
        return Collections.emptyList();
    }
    List<AnnotationNode> ret = new ArrayList<AnnotationNode>(data.length);
    for (Object[] inner : data) {
        Class<?> anno = (Class) inner[0];
        AnnotationNode toAdd = new AnnotationNode(ClassHelper.make(anno));
        ret.add(toAdd);

        @SuppressWarnings("unchecked")
        Map<String,Object> member = (Map<String, Object>) inner[1];
        if (member.isEmpty()) {
            continue;
        }
        Map<String, Expression> generated = new HashMap<String, Expression>(member.size());
        for (Map.Entry<String, Object> entry : member.entrySet()) {
            generated.put(entry.getKey(), makeExpression(entry.getValue()));
        }
        copyMembers(generated, toAdd);
    }
    return ret;
}
 
开发者ID:apache,项目名称:groovy,代码行数:24,代码来源:AnnotationCollectorTransform.java

示例6: testInheritedProperties

import org.codehaus.groovy.ast.ClassHelper; //导入方法依赖的package包/类
public void testInheritedProperties() throws Exception {
    ClassNode classNode = new ClassNode("Foo", ACC_PUBLIC + ACC_SUPER, ClassHelper.make(DummyBean.class));
    classNode.addProperty(new PropertyNode("bar", ACC_PUBLIC, ClassHelper.STRING_TYPE, classNode, null, null, null));

    Class fooClass = loadClass(classNode);
    assertTrue("Loaded a new class", fooClass != null);

    Object bean = fooClass.newInstance();
    assertTrue("Managed to create bean", bean != null);

    assertField(fooClass, "bar", 0, ClassHelper.STRING_TYPE);

    assertGetProperty(bean, "name", "James");
    assertSetProperty(bean, "name", "Bob");

    assertGetProperty(bean, "bar", null);
    assertSetProperty(bean, "bar", "newValue");
}
 
开发者ID:apache,项目名称:groovy,代码行数:19,代码来源:PropertyTest.java

示例7: addEnableAutoConfigurationAnnotation

import org.codehaus.groovy.ast.ClassHelper; //导入方法依赖的package包/类
private void addEnableAutoConfigurationAnnotation(SourceUnit source,
		ClassNode classNode) {
	if (!hasEnableAutoConfigureAnnotation(classNode)) {
		AnnotationNode annotationNode = new AnnotationNode(
				ClassHelper.make("EnableAutoConfiguration"));
		classNode.addAnnotation(annotationNode);
	}
}
 
开发者ID:vikrammane23,项目名称:https-github.com-g0t4-jenkins2-course-spring-boot,代码行数:9,代码来源:SpringBootCompilerAutoConfiguration.java

示例8: apply

import org.codehaus.groovy.ast.ClassHelper; //导入方法依赖的package包/类
@Override
public void apply(GroovyClassLoader loader, GroovyCompilerConfiguration configuration,
		GeneratorContext generatorContext, SourceUnit source, ClassNode classNode)
				throws CompilationFailedException {
	if (!AstUtils.hasAtLeastOneAnnotation(classNode, "RunWith")) {
		AnnotationNode runWith = new AnnotationNode(ClassHelper.make("RunWith"));
		runWith.addMember("value",
				new ClassExpression(ClassHelper.make("SpringRunner")));
		classNode.addAnnotation(runWith);
	}
}
 
开发者ID:vikrammane23,项目名称:https-github.com-g0t4-jenkins2-course-spring-boot,代码行数:12,代码来源:SpringTestCompilerAutoConfiguration.java

示例9: transformationOfClassWithExistingManagedDependencies

import org.codehaus.groovy.ast.ClassHelper; //导入方法依赖的package包/类
@Test
public void transformationOfClassWithExistingManagedDependencies() {
	this.moduleNode.setPackage(new PackageNode("foo"));
	ClassNode cls = ClassHelper.make("MyClass");
	this.moduleNode.addClass(cls);
	AnnotationNode annotation = new AnnotationNode(
			ClassHelper.make(DependencyManagementBom.class));
	annotation.addMember("value", new ConstantExpression("test:parent:1.0.0"));
	cls.addAnnotation(annotation);
	this.transformation.visit(new ASTNode[] { this.moduleNode }, this.sourceUnit);
	assertThat(getValue().toString())
			.isEqualTo("[test:parent:1.0.0, test:child:1.0.0]");
}
 
开发者ID:vikrammane23,项目名称:https-github.com-g0t4-jenkins2-course-spring-boot,代码行数:14,代码来源:GenericBomAstTransformationTests.java

示例10: findAnnotation

import org.codehaus.groovy.ast.ClassHelper; //导入方法依赖的package包/类
private AnnotationNode findAnnotation() {
	PackageNode packageNode = this.moduleNode.getPackage();
	ClassNode bom = ClassHelper.make(DependencyManagementBom.class);
	if (packageNode != null) {
		if (!packageNode.getAnnotations(bom).isEmpty()) {
			return packageNode.getAnnotations(bom).get(0);
		}
	}
	if (!this.moduleNode.getClasses().isEmpty()) {
		return this.moduleNode.getClasses().get(0).getAnnotations(bom).get(0);
	}
	throw new IllegalStateException("No package or class node found");
}
 
开发者ID:vikrammane23,项目名称:https-github.com-g0t4-jenkins2-course-spring-boot,代码行数:14,代码来源:GenericBomAstTransformationTests.java

示例11: transformationOfClassWithExistingManagedDependencies

import org.codehaus.groovy.ast.ClassHelper; //导入方法依赖的package包/类
@Test
public void transformationOfClassWithExistingManagedDependencies() {
	this.moduleNode.setPackage(new PackageNode("foo"));
	ClassNode cls = ClassHelper.make("MyClass");
	this.moduleNode.addClass(cls);
	AnnotationNode annotation = new AnnotationNode(
			ClassHelper.make(DependencyManagementBom.class));
	annotation.addMember("value", new ConstantExpression("test:parent:1.0.0"));
	cls.addAnnotation(annotation);
	this.transformation.visit(new ASTNode[] { this.moduleNode }, this.sourceUnit);
	assertEquals("[test:parent:1.0.0, test:child:1.0.0]", getValue().toString());
}
 
开发者ID:Nephilim84,项目名称:contestparser,代码行数:13,代码来源:GenericBomAstTransformationTests.java

示例12: resolveNonArrayType

import org.codehaus.groovy.ast.ClassHelper; //导入方法依赖的package包/类
private ClassNode resolveNonArrayType(Type type) {
    String className = type.getClassName();
    if (type.getSort() != Type.OBJECT) {
        return ClassHelper.make(className);
    }

    return resolveClass(className);
}
 
开发者ID:apache,项目名称:groovy,代码行数:9,代码来源:AsmReferenceResolver.java

示例13: attachGroovydocAnnotation

import org.codehaus.groovy.ast.ClassHelper; //导入方法依赖的package包/类
private void attachGroovydocAnnotation(ASTNode node, String docCommentNodeText) {
    if (!(node instanceof AnnotatedNode)) {
        return;
    }

    if (!(ATTACHING_RUNTIME_GROOVYDOC_ENABLED || docCommentNodeText.matches(RUNTIME_GROOVYDOC_PATTERN))) {
        return;
    }

    AnnotatedNode annotatedNode = (AnnotatedNode) node;
    AnnotationNode annotationNode = new AnnotationNode(ClassHelper.make(Groovydoc.class));
    annotationNode.addMember(VALUE, new ConstantExpression(docCommentNodeText));
    annotatedNode.addAnnotation(annotationNode);
}
 
开发者ID:apache,项目名称:groovy,代码行数:15,代码来源:GroovydocManager.java

示例14: setGenTypes

import org.codehaus.groovy.ast.ClassHelper; //导入方法依赖的package包/类
private static GenericsType[] setGenTypes(int numFields) {
    GenericsType[] gtypes = new GenericsType[numFields];
    for (int i = 0; i < gtypes.length; i++) {
        gtypes[i] = new GenericsType(ClassHelper.make(SET.class));
    }
    return gtypes;
}
 
开发者ID:apache,项目名称:groovy,代码行数:8,代码来源:InitializerStrategy.java

示例15: addPackageInfoClassNode

import org.codehaus.groovy.ast.ClassHelper; //导入方法依赖的package包/类
private void addPackageInfoClassNode() {
    List<ClassNode> classNodeList = moduleNode.getClasses();
    ClassNode packageInfoClassNode = ClassHelper.make(moduleNode.getPackageName() + PACKAGE_INFO);

    if (!classNodeList.contains(packageInfoClassNode)) {
        moduleNode.addClass(packageInfoClassNode);
    }
}
 
开发者ID:apache,项目名称:groovy,代码行数:9,代码来源:AstBuilder.java


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