• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Java ConstructorNode类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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

示例1: createConstructor

import org.codehaus.groovy.ast.ConstructorNode; //导入依赖的package包/类
private void createConstructor(final ClassNode classNode) {
    Parameter[] params = new Parameter[]{
            new Parameter(MarkupTemplateEngine.MARKUPTEMPLATEENGINE_CLASSNODE, "engine"),
            new Parameter(ClassHelper.MAP_TYPE.getPlainNodeReference(), "model"),
            new Parameter(ClassHelper.MAP_TYPE.getPlainNodeReference(), "modelTypes"),
            new Parameter(TEMPLATECONFIG_CLASSNODE, "tplConfig")
    };
    List<Expression> vars = new LinkedList<Expression>();
    for (Parameter param : params) {
        vars.add(new VariableExpression(param));
    }
    ExpressionStatement body = new ExpressionStatement(
            new ConstructorCallExpression(ClassNode.SUPER, new ArgumentListExpression(vars)));
    ConstructorNode ctor = new ConstructorNode(Opcodes.ACC_PUBLIC, params, ClassNode.EMPTY_ARRAY, body);
    classNode.addConstructor(ctor);
}
 
开发者ID:apache,项目名称:groovy,代码行数:17,代码来源:TemplateASTTransformer.java


示例2: validateMethodDeclaration

import org.codehaus.groovy.ast.ConstructorNode; //导入依赖的package包/类
private void validateMethodDeclaration(MethodDeclarationContext ctx, MethodNode methodNode, ModifierManager modifierManager, ClassNode classNode) {
    boolean isAbstractMethod = methodNode.isAbstract();
    boolean hasMethodBody = asBoolean(methodNode.getCode());

    if (9 == ctx.ct) { // script
        if (isAbstractMethod || !hasMethodBody) { // method should not be declared abstract in the script
            throw createParsingFailedException("You can not define a " + (isAbstractMethod ? "abstract" : "") + " method[" + methodNode.getName() + "] " + (!hasMethodBody ? "without method body" : "") + " in the script. Try " + (isAbstractMethod ? "removing the 'abstract'" : "") + (isAbstractMethod && !hasMethodBody ? " and" : "") + (!hasMethodBody ? " adding a method body" : ""), methodNode);
        }
    } else {
        if (!isAbstractMethod && !hasMethodBody) { // non-abstract method without body in the non-script(e.g. class, enum, trait) is not allowed!
            throw createParsingFailedException("You defined a method[" + methodNode.getName() + "] without body. Try adding a method body, or declare it abstract", methodNode);
        }

        boolean isInterfaceOrAbstractClass = asBoolean(classNode) && classNode.isAbstract() && !classNode.isAnnotationDefinition();
        if (isInterfaceOrAbstractClass && !modifierManager.contains(DEFAULT) && isAbstractMethod && hasMethodBody) {
            throw createParsingFailedException("You defined an abstract method[" + methodNode.getName() + "] with body. Try removing the method body" + (classNode.isInterface() ? ", or declare it default" : ""), methodNode);
        }
    }

    modifierManager.validate(methodNode);

    if (methodNode instanceof ConstructorNode) {
        modifierManager.validate((ConstructorNode) methodNode);
    }
}
 
开发者ID:apache,项目名称:groovy,代码行数:26,代码来源:AstBuilder.java


示例3: processClass

import org.codehaus.groovy.ast.ConstructorNode; //导入依赖的package包/类
private void processClass(ClassNode cNode, AnnotationNode node) {
    if (cNode.isInterface()) {
        addError("Error processing interface '" + cNode.getName() +
                "'. " + MY_TYPE_NAME + " only allowed for classes.", cNode);
        return;
    }
    boolean copyConstructorAnnotations = memberHasValue(node, "constructorAnnotations", true);
    boolean copyParameterAnnotations = memberHasValue(node, "parameterAnnotations", true);
    ClassNode sNode = cNode.getSuperClass();
    List<AnnotationNode> superAnnotations = sNode.getAnnotations(MY_TYPE);
    if (superAnnotations.size() == 1) {
        // We need @InheritConstructors from parent classes processed first
        // so force that order here. The transformation is benign on an already
        // processed node so processing twice in any order won't matter bar
        // a very small time penalty.
        processClass(sNode, node);
    }
    for (ConstructorNode cn : sNode.getDeclaredConstructors()) {
        addConstructorUnlessAlreadyExisting(cNode, cn, copyConstructorAnnotations, copyParameterAnnotations);
    }
}
 
开发者ID:apache,项目名称:groovy,代码行数:22,代码来源:InheritConstructorsASTTransformation.java


示例4: addTypeCheckingInfoAnnotation

import org.codehaus.groovy.ast.ConstructorNode; //导入依赖的package包/类
protected void addTypeCheckingInfoAnnotation(final MethodNode node) {
    // TypeChecked$TypeCheckingInfo can not be applied on constructors
    if (node instanceof ConstructorNode) return;

    // if a returned inferred type is available and no @TypeCheckingInfo is on node, then add an
    // annotation to the method node
    ClassNode rtype = getInferredReturnType(node);
    if (rtype != null && node.getAnnotations(TYPECHECKING_INFO_NODE).isEmpty()) {
        AnnotationNode anno = new AnnotationNode(TYPECHECKING_INFO_NODE);
        anno.setMember("version", CURRENT_SIGNATURE_PROTOCOL);
        SignatureCodec codec = SignatureCodecFactory.getCodec(CURRENT_SIGNATURE_PROTOCOL_VERSION, getTransformLoader());
        String genericsSignature = codec.encode(rtype);
        if (genericsSignature != null) {
            ConstantExpression signature = new ConstantExpression(genericsSignature);
            signature.setType(STRING_TYPE);
            anno.setMember("inferredType", signature);
            node.addAnnotation(anno);
        }
    }
}
 
开发者ID:apache,项目名称:groovy,代码行数:21,代码来源:StaticTypeCheckingVisitor.java


示例5: checkForConstructorWithCSButClassWithout

import org.codehaus.groovy.ast.ConstructorNode; //导入依赖的package包/类
/**
 * If we are in a constructor, that is static compiled, but in a class, that
 * is not, it may happen that init code from object initializers, fields
 * or properties is added into the constructor code. The backend assumes
 * a purely static constructor, so it may fail if it encounters dynamic
 * code here. Thus we make this kind of code fail
 */
private void checkForConstructorWithCSButClassWithout(MethodNode node) {
    if (!(node instanceof ConstructorNode)) return;
    Object meta = node.getNodeMetaData(STATIC_COMPILE_NODE);
    if (!Boolean.TRUE.equals(meta)) return;
    ClassNode clz = typeCheckingContext.getEnclosingClassNode();
    meta = clz.getNodeMetaData(STATIC_COMPILE_NODE);
    if (Boolean.TRUE.equals(meta)) return;
    if (    clz.getObjectInitializerStatements().isEmpty() &&
            clz.getFields().isEmpty() &&
            clz.getProperties().isEmpty())
    {
        return;
    }

    addStaticTypeError("Cannot statically compile constructor implicitly including non static elements from object initializers, properties or fields.",node);
}
 
开发者ID:apache,项目名称:groovy,代码行数:24,代码来源:StaticCompilationVisitor.java


示例6: adjustConstructorAndFields

import org.codehaus.groovy.ast.ConstructorNode; //导入依赖的package包/类
private void adjustConstructorAndFields(int skipIndex, ClassNode type) {
    List<ConstructorNode> constructors = type.getDeclaredConstructors();
    if (constructors.size() == 1) {
        ConstructorNode constructor = constructors.get(0);
        Parameter[] params = constructor.getParameters();
        Parameter[] newParams = new Parameter[params.length - 1];
        int to = 0;
        for (int from = 0; from < params.length; from++) {
            if (from != skipIndex) {
                newParams[to++] = params[from];
            }
        }
        type.removeConstructor(constructor);
        // code doesn't mention the removed param at this point, okay to leave as is
        type.addConstructor(constructor.getModifiers(), newParams, constructor.getExceptions(), constructor.getCode());
        type.removeField(variableName);
    }
}
 
开发者ID:apache,项目名称:groovy,代码行数:19,代码来源:FieldASTTransformation.java


示例7: lazyInitMembers

import org.codehaus.groovy.ast.ConstructorNode; //导入依赖的package包/类
private void lazyInitMembers() {
    synchronized (lazyInitLock) {
        if (!membersInitialized) {
            if (classData.methods != null) {
                for (MethodStub method : classData.methods) {
                    MethodNode node = addAnnotations(method, MemberSignatureParser.createMethodNode(resolver, method));
                    if (node instanceof ConstructorNode) {
                        addConstructor((ConstructorNode) node);
                    } else {
                        addMethod(node);
                    }
                }
            }

            if (classData.fields != null) {
                for (FieldStub field : classData.fields) {
                    addField(addAnnotations(field, MemberSignatureParser.createFieldNode(field, resolver, this)));
                }
            }

            membersInitialized = true;
        }
    }
}
 
开发者ID:apache,项目名称:groovy,代码行数:25,代码来源:DecompiledClassNode.java


示例8: getRefDescriptor

import org.codehaus.groovy.ast.ConstructorNode; //导入依赖的package包/类
private static String getRefDescriptor(ASTNode ref) {
    if (ref instanceof FieldNode) {
        FieldNode f = (FieldNode) ref;
        return "the field "+f.getName()+" ";
    } else if (ref instanceof PropertyNode) {
        PropertyNode p = (PropertyNode) ref;
        return "the property "+p.getName()+" ";
    } else if (ref instanceof ConstructorNode) {
        return "the constructor "+ref.getText()+" ";
    } else if (ref instanceof MethodNode) {
        return "the method "+ref.getText()+" ";
    } else if (ref instanceof ClassNode) {
        return "the super class "+ref+" ";
    }
    return "<unknown with class "+ref.getClass()+"> ";
}
 
开发者ID:apache,项目名称:groovy,代码行数:17,代码来源:ClassCompletionVerifier.java


示例9: addImplicitConstructors

import org.codehaus.groovy.ast.ConstructorNode; //导入依赖的package包/类
/**
 * Add map and no-arg constructor or mirror those of the superclass (i.e. base enum).
 */
private static void addImplicitConstructors(ClassNode enumClass, boolean aic) {
    if (aic) {
        ClassNode sn = enumClass.getSuperClass();
        List<ConstructorNode> sctors = new ArrayList<ConstructorNode>(sn.getDeclaredConstructors());
        if (sctors.isEmpty()) {
            addMapConstructors(enumClass, false);
        } else {
            for (ConstructorNode constructorNode : sctors) {
                ConstructorNode init = new ConstructorNode(Opcodes.ACC_PUBLIC, constructorNode.getParameters(), ClassNode.EMPTY_ARRAY, new BlockStatement());
                enumClass.addConstructor(init);
            }
        }
    } else {
        addMapConstructors(enumClass, false);
    }
}
 
开发者ID:apache,项目名称:groovy,代码行数:20,代码来源:EnumCompletionVisitor.java


示例10: addInitialization

import org.codehaus.groovy.ast.ConstructorNode; //导入依赖的package包/类
protected void addInitialization(final ClassNode node) {
    boolean addSwapInit = moveOptimizedConstantsInitialization(node);

    for (ConstructorNode cn : node.getDeclaredConstructors()) {
        addInitialization(node, cn);
    }

    if (addSwapInit) {
        BytecodeSequence seq = new BytecodeSequence(
                new BytecodeInstruction() {
                    @Override
                    public void visit(MethodVisitor mv) {
                        mv.visitMethodInsn(INVOKESTATIC, BytecodeHelper.getClassInternalName(node), SWAP_INIT, "()V", false);
                    }
                });

        List<Statement> swapCall = new ArrayList<Statement>(1);
        swapCall.add(seq);
        node.addStaticInitializerStatements(swapCall, true);
    }
}
 
开发者ID:apache,项目名称:groovy,代码行数:22,代码来源:Verifier.java


示例11: prepareConstructorCall

import org.codehaus.groovy.ast.ConstructorNode; //导入依赖的package包/类
protected String prepareConstructorCall(ConstructorNode cn) {
    String owner = BytecodeHelper.getClassInternalName(cn.getDeclaringClass());
    MethodVisitor mv = controller.getMethodVisitor();
    
    mv.visitTypeInsn(NEW, owner);
    mv.visitInsn(DUP);
    return owner;
}
 
开发者ID:apache,项目名称:groovy,代码行数:9,代码来源:InvocationWriter.java


示例12: getMatchingConstructor

import org.codehaus.groovy.ast.ConstructorNode; //导入依赖的package包/类
private static ConstructorNode getMatchingConstructor(List<ConstructorNode> constructors, List<Expression> argumentList) {
    ConstructorNode lastMatch = null;
    for (int i=0; i<constructors.size(); i++) {
        ConstructorNode cn = constructors.get(i);
        Parameter[] params = cn.getParameters();
        // if number of parameters does not match we have no match
        if (argumentList.size()!=params.length) continue;
        if (lastMatch==null) {
            lastMatch = cn;
        } else {
            // we already had a match so we don't make a direct call at all
            return null;
        }
    }
    return lastMatch;
}
 
开发者ID:apache,项目名称:groovy,代码行数:17,代码来源:InvocationWriter.java


示例13: throwExceptionForNoStackElement

import org.codehaus.groovy.ast.ConstructorNode; //导入依赖的package包/类
private void throwExceptionForNoStackElement(int size, ClassNode targetType, boolean coerce) {
    if (size>0) return;
    StringBuilder sb = new StringBuilder();
    sb.append("Internal compiler error while compiling ").append(controller.getSourceUnit().getName()).append("\n");
    MethodNode methodNode = controller.getMethodNode();
    if (methodNode!=null) {
        sb.append("Method: ");
        sb.append(methodNode);
        sb.append("\n");
    }
    ConstructorNode constructorNode = controller.getConstructorNode();
    if (constructorNode!=null) {
        sb.append("Constructor: ");
        sb.append(methodNode);
        sb.append("\n");
    }
    sb.append("Line ").append(controller.getLineNumber()).append(",");
    sb.append(" expecting ").append(coerce ? "coercion" : "casting").append(" to ").append(targetType.toString(false));
    sb.append(" but operand stack is empty");
    throw new ArrayIndexOutOfBoundsException(sb.toString());
}
 
开发者ID:apache,项目名称:groovy,代码行数:22,代码来源:OperandStack.java


示例14: getConstructorCallExpression

import org.codehaus.groovy.ast.ConstructorNode; //导入依赖的package包/类
private static ConstructorCallExpression getConstructorCallExpression(ConstructorNode constructorNode) {
    Statement code = constructorNode.getCode();
    if (!(code instanceof BlockStatement))
        return null;

    BlockStatement block = (BlockStatement) code;
    List stats = block.getStatements();
    if (stats == null || stats.isEmpty())
        return null;

    Statement stat = (Statement) stats.get(0);
    if (!(stat instanceof ExpressionStatement))
        return null;

    Expression expr = ((ExpressionStatement) stat).getExpression();
    if (!(expr instanceof ConstructorCallExpression))
        return null;

    return (ConstructorCallExpression) expr;
}
 
开发者ID:apache,项目名称:groovy,代码行数:21,代码来源:JavaStubGenerator.java


示例15: printConstructor

import org.codehaus.groovy.ast.ConstructorNode; //导入依赖的package包/类
private void printConstructor(PrintWriter out, ClassNode clazz, ConstructorNode constructorNode) {
    printAnnotations(out, constructorNode);
    // printModifiers(out, constructorNode.getModifiers());

    out.print("public "); // temporary hack
    String className = clazz.getNameWithoutPackage();
    if (clazz instanceof InnerClassNode)
        className = className.substring(className.lastIndexOf("$") + 1);
    out.println(className);

    printParams(out, constructorNode);

    ConstructorCallExpression constrCall = getConstructorCallExpression(constructorNode);
    if (constrCall == null || !constrCall.isSpecialCall()) {
        out.println(" {}");
    } else {
        out.println(" {");
        printSpecialConstructorArgs(out, constructorNode, constrCall);
        out.println("}");
    }
}
 
开发者ID:apache,项目名称:groovy,代码行数:22,代码来源:JavaStubGenerator.java


示例16: noExceptionToAvoid

import org.codehaus.groovy.ast.ConstructorNode; //导入依赖的package包/类
private static boolean noExceptionToAvoid(ConstructorNode fromStub, ConstructorNode fromSuper) {
    ClassNode[] superExceptions = fromSuper.getExceptions();
    if (superExceptions==null || superExceptions.length==0) return true;

    ClassNode[] stubExceptions = fromStub.getExceptions();
    if (stubExceptions==null || stubExceptions.length==0) return false;


    // if all remaining exceptions are used in the stub we are good
    outer: for (int i=0; i<superExceptions.length; i++) {
        ClassNode superExc = superExceptions[i];
        for (ClassNode stub:stubExceptions) {
            if (stub.isDerivedFrom(superExc)) continue outer;
        }
        // not found 
        return false;
    }

    return true;
}
 
开发者ID:apache,项目名称:groovy,代码行数:21,代码来源:JavaStubGenerator.java


示例17: transformationOfAnnotationOnConstructor

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


示例18: createConstructorNodeForClass

import org.codehaus.groovy.ast.ConstructorNode; //导入依赖的package包/类
private ConstructorNode createConstructorNodeForClass(String methodName, Parameter[] parameters, ClassNode[] exceptions, Statement code, ClassNode classNode, int modifiers) {
    ConstructorCallExpression thisOrSuperConstructorCallExpression = this.checkThisAndSuperConstructorCall(code);
    if (asBoolean(thisOrSuperConstructorCallExpression)) {
        throw createParsingFailedException(thisOrSuperConstructorCallExpression.getText() + " should be the first statement in the constructor[" + methodName + "]", thisOrSuperConstructorCallExpression);
    }

    return classNode.addConstructor(
            modifiers,
            parameters,
            exceptions,
            code);
}
 
开发者ID:apache,项目名称:groovy,代码行数:13,代码来源:AstBuilder.java


示例19: addConstructorUnlessAlreadyExisting

import org.codehaus.groovy.ast.ConstructorNode; //导入依赖的package包/类
private void addConstructorUnlessAlreadyExisting(ClassNode classNode, ConstructorNode consNode, boolean copyConstructorAnnotations, boolean copyParameterAnnotations) {
    Parameter[] origParams = consNode.getParameters();
    if (consNode.isPrivate()) return;
    Parameter[] params = new Parameter[origParams.length];
    Map<String, ClassNode> genericsSpec = createGenericsSpec(classNode);
    extractSuperClassGenerics(classNode, classNode.getSuperClass(), genericsSpec);
    List<Expression> theArgs = buildParams(origParams, params, genericsSpec, copyParameterAnnotations);
    if (isExisting(classNode, params)) return;
    ConstructorNode added = classNode.addConstructor(consNode.getModifiers(), params, consNode.getExceptions(), block(ctorSuperS(args(theArgs))));
    if (copyConstructorAnnotations) {
        added.addAnnotations(copyAnnotatedNodeAnnotations(consNode, MY_TYPE_NAME));
    }
}
 
开发者ID:apache,项目名称:groovy,代码行数:14,代码来源:InheritConstructorsASTTransformation.java


示例20: isExisting

import org.codehaus.groovy.ast.ConstructorNode; //导入依赖的package包/类
private static boolean isExisting(ClassNode classNode, Parameter[] params) {
    for (ConstructorNode consNode : classNode.getDeclaredConstructors()) {
        if (matchingTypes(params, consNode.getParameters())) {
            return true;
        }
    }
    return false;
}
 
开发者ID:apache,项目名称:groovy,代码行数:9,代码来源:InheritConstructorsASTTransformation.java



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java NaccacheSternPrivateKeyParameters类代码示例发布时间:2022-05-23
下一篇:
Java Repository类代码示例发布时间:2022-05-23
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap