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


Java ASTNode类代码示例

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


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

示例1: visit

import org.codehaus.groovy.ast.ASTNode; //导入依赖的package包/类
public void visit(ASTNode[] nodes, SourceUnit sourceUnit) {
    LOGGER.trace("Apply AST transformation");
    ModuleNode ast = sourceUnit.getAST();
    BlockStatement blockStatement = ast.getStatementBlock();

    if (DEBUG) {
        printAST(blockStatement);
    }

    List<MethodNode> methods = ast.getMethods();
    for (MethodNode methodNode : methods) {
        methodNode.getCode().visit(new CustomClassCodeExpressionTransformer(sourceUnit));
    }

    blockStatement.visit(new CustomClassCodeExpressionTransformer(sourceUnit));

    if (DEBUG) {
        printAST(blockStatement);
    }
}
 
开发者ID:powsybl,项目名称:powsybl-core,代码行数:21,代码来源:ActionDslAstTransformation.java

示例2: inspectMethodCallExpression

import org.codehaus.groovy.ast.ASTNode; //导入依赖的package包/类
private void inspectMethodCallExpression(MethodCallExpression mc, int childIndent, String in) {
		String name = mc.getMethodAsString();
		System.out.println(in+"-method as string:"+name);
		System.out.println("- generic types:"+ mc.getGenericsTypes());
		System.out.println("- type:"+mc.getType().getName());
		Expression method = mc.getMethod();
		inspect(method, childIndent);
//		System.out.println(in+"-type:"+mc.getType());
		Expression args = mc.getArguments();
		System.out.println(in + "-arguments:");
		inspect(args, childIndent);
		// System.out.println(in + "-method:");
		// System.out.println(in + "-target:");
		// inspect(mc.getMethodTarget(), childIndent);
		ASTNode receiver = mc.getReceiver();
		if (receiver!=null){
			System.out.println(in+"// Receiver found ...");
			inspect(receiver, childIndent);
		}
	}
 
开发者ID:de-jcup,项目名称:egradle,代码行数:21,代码来源:GradleBuildScriptResultInspector.java

示例3: main

import org.codehaus.groovy.ast.ASTNode; //导入依赖的package包/类
public static void main(String[] args) throws Exception {
	String pathToGradle = System.getProperty("user.home")
			+ "/.gradle/wrapper/dists/gradle-3.1-bin/37qejo6a26ua35lyn7h1u9v2n/gradle-3.1";
	StringBuilder buildScript = new StringBuilder();

	buildScript.append("subProjects{\n");
	buildScript.append("	apply from: \"${rootProject.projectDir}/subX.gradle\"\n");
	buildScript.append("}");
	buildScript.append("allProjects{\n");
	buildScript.append("	apply from: \"${rootProject.projectDir}/allX.gradle\"\n");
	buildScript.append("}");

	Future<EGradleBuildscriptResult> futureStatement = new GradleBuildScriptResultBuilder()
			.build(buildScript.toString(), pathToGradle);
	EGradleBuildscriptResult buildscriptResult = futureStatement.get();
	ASTNode statement = buildscriptResult.getNode();
	if (buildscriptResult.getException()!=null){
		buildscriptResult.getException().printStackTrace(System.err);
		return;
	}
	String text = statement != null ? statement.getText() : "error:";
	System.out.println("script:" + text);
	GradleBuildScriptResultInspector inspector = new GradleBuildScriptResultInspector();
	inspector.inspect(statement);
}
 
开发者ID:de-jcup,项目名称:egradle,代码行数:26,代码来源:GradleBuildScriptResultBuilderTestcase1.java

示例4: visit

import org.codehaus.groovy.ast.ASTNode; //导入依赖的package包/类
@Override
public void visit(ASTNode[] nodes, SourceUnit source) {
	for (ASTNode astNode : nodes) {
		if (astNode instanceof ModuleNode) {
			visitModule((ModuleNode) astNode, getBomModule());
		}
	}
}
 
开发者ID:vikrammane23,项目名称:https-github.com-g0t4-jenkins2-course-spring-boot,代码行数:9,代码来源:GenericBomAstTransformation.java

示例5: onLineNumber

import org.codehaus.groovy.ast.ASTNode; //导入依赖的package包/类
public void onLineNumber(ASTNode statement, String message) {
    MethodVisitor mv = controller.getMethodVisitor();

    if (statement==null) return;
    int line = statement.getLineNumber();
    this.currentASTNode = statement;

    if (line < 0) return;
    if (!ASM_DEBUG && line==controller.getLineNumber()) return;

    controller.setLineNumber(line);
    if (mv != null) {
        Label l = new Label();
        mv.visitLabel(l);
        mv.visitLineNumber(line, l);
    }
}
 
开发者ID:apache,项目名称:groovy,代码行数:18,代码来源:AsmClassGenerator.java

示例6: visit

import org.codehaus.groovy.ast.ASTNode; //导入依赖的package包/类
/**
 * Handles the bulk of the processing, mostly delegating to other methods.
 *
 * @param nodes   the AST nodes
 * @param source  the source unit for the nodes
 */
public void visit(ASTNode[] nodes, SourceUnit source) {
    if (!(nodes[0] instanceof AnnotationNode) || !(nodes[1] instanceof AnnotatedNode)) {
        throw new RuntimeException("Internal error: wrong types: $node.class / $parent.class");
    }
    AnnotationNode node = (AnnotationNode) nodes[0];

    if (nodes[1] instanceof ClassNode) {
        addListenerToClass(source, (ClassNode) nodes[1]);
    } else {
        if ((((FieldNode)nodes[1]).getModifiers() & Opcodes.ACC_FINAL) != 0) {
            source.getErrorCollector().addErrorAndContinue(new SyntaxErrorMessage(
                    new SyntaxException("@groovy.beans.Vetoable cannot annotate a final property.",
                            node.getLineNumber(), node.getColumnNumber(), node.getLastLineNumber(), node.getLastColumnNumber()),
                    source));
        }

        addListenerToProperty(source, node, (AnnotatedNode) nodes[1]);
    }
}
 
开发者ID:apache,项目名称:groovy,代码行数:26,代码来源:VetoableASTTransformation.java

示例7: checkReturnType

import org.codehaus.groovy.ast.ASTNode; //导入依赖的package包/类
public void checkReturnType(ClassNode attrType, ASTNode node) {
    if (attrType.isArray()) {
        checkReturnType(attrType.getComponentType(), node);
    } else if (ClassHelper.isPrimitiveType(attrType)) {
        return;
    } else if (ClassHelper.STRING_TYPE.equals(attrType)) {
        return;
    } else if (ClassHelper.CLASS_Type.equals(attrType)) {
        return;
    } else if (attrType.isDerivedFrom(ClassHelper.Enum_Type)) {
        return;
    } else if (isValidAnnotationClass(attrType)) {
        return;
    } else {
        addError("Unexpected return type " + attrType.getName(), node);
    }
}
 
开发者ID:apache,项目名称:groovy,代码行数:18,代码来源:AnnotationVisitor.java

示例8: getRefDescriptor

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

import org.codehaus.groovy.ast.ASTNode; //导入依赖的package包/类
/**
 * {@inheritDoc}
 */
@Override
public void visit(final ASTNode[] nodes, final SourceUnit source) {
    if (shouldSkip(nodes)) {
        return; // skip
    }

    final AnnotationNode marker = (AnnotationNode) first(nodes);

    final ClassNode type = marker.getClassNode();
    final ClassNode reference = make(annotation);
    final Boolean isAnnotationOk = A.UTIL.CLASS.isOrExtends(type, reference);

    if (!isAnnotationOk) {
        return;
    }

    final S annotated = (S) last(nodes);

    this.sourceUnit = source;

    doVisit(marker, annotated);
}
 
开发者ID:grooviter,项目名称:asteroid,代码行数:26,代码来源:AbstractLocalTransformation.java

示例10: visit

import org.codehaus.groovy.ast.ASTNode; //导入依赖的package包/类
public void visit(ASTNode[] nodes, SourceUnit source) {
    init(nodes, source);
    AnnotatedNode parent = (AnnotatedNode) nodes[1];
    AnnotationNode anno = (AnnotationNode) nodes[0];
    if (!MY_TYPE.equals(anno.getClassNode())) return;

    if (parent instanceof ClassNode) {
        ClassNode cNode = (ClassNode) parent;
        if (!hasNoargConstructor(cNode)) {
            addError(MY_TYPE_NAME + ": An Externalizable class requires a no-arg constructor but none found", cNode);
        }
        if (!implementsExternalizable(cNode)) {
            addError(MY_TYPE_NAME + ": An Externalizable class must implement the Externalizable interface", cNode);
        }
        boolean includeFields = memberHasValue(anno, "includeFields", true);
        boolean checkPropertyTypes = memberHasValue(anno, "checkPropertyTypes", true);
        List<String> excludes = getMemberStringList(anno, "excludes");
        if (!checkPropertyList(cNode, excludes, "excludes", anno, MY_TYPE_NAME, includeFields)) return;
        List<FieldNode> list = getInstancePropertyFields(cNode);
        if (includeFields) {
            list.addAll(getInstanceNonPropertyFields(cNode));
        }
        checkProps(list, excludes, checkPropertyTypes);
    }
}
 
开发者ID:apache,项目名称:groovy,代码行数:26,代码来源:ExternalizeVerifierASTTransformation.java

示例11: makeDynamic

import org.codehaus.groovy.ast.ASTNode; //导入依赖的package包/类
/**
 * Used to instruct the type checker that the call is a dynamic method call.
 * Calling this method automatically sets the handled flag to true.
 * @param call the method call which is a dynamic method call
 * @param returnType the expected return type of the dynamic call
 * @return a virtual method node with the same name as the expected call
 */
public MethodNode makeDynamic(MethodCall call, ClassNode returnType) {
    TypeCheckingContext.EnclosingClosure enclosingClosure = context.getEnclosingClosure();
    MethodNode enclosingMethod = context.getEnclosingMethod();
    ((ASTNode)call).putNodeMetaData(StaticTypesMarker.DYNAMIC_RESOLUTION, returnType);
    if (enclosingClosure!=null) {
        enclosingClosure.getClosureExpression().putNodeMetaData(StaticTypesMarker.DYNAMIC_RESOLUTION, Boolean.TRUE);
    } else {
        enclosingMethod.putNodeMetaData(StaticTypesMarker.DYNAMIC_RESOLUTION, Boolean.TRUE);
    }
    setHandled(true);
    if (debug) {
        LOG.info("Turning "+call.getText()+" into a dynamic method call returning "+returnType.toString(false));
    }
    return new MethodNode(call.getMethodAsString(), 0, returnType, Parameter.EMPTY_ARRAY, ClassNode.EMPTY_ARRAY, EmptyStatement.INSTANCE);
}
 
开发者ID:apache,项目名称:groovy,代码行数:23,代码来源:AbstractTypeCheckingExtension.java

示例12: resolveClassNode

import org.codehaus.groovy.ast.ASTNode; //导入依赖的package包/类
private static ClassNode resolveClassNode(final SourceUnit sourceUnit, final CompilationUnit compilationUnit, final MethodNode mn, final ASTNode usage, final ClassNode parsedNode) {
    ClassNode dummyClass = new ClassNode("dummy",0, ClassHelper.OBJECT_TYPE);
    dummyClass.setModule(new ModuleNode(sourceUnit));
    dummyClass.setGenericsTypes(mn.getDeclaringClass().getGenericsTypes());
    MethodNode dummyMN = new MethodNode(
            "dummy",
            0,
            parsedNode,
            Parameter.EMPTY_ARRAY,
            ClassNode.EMPTY_ARRAY,
            EmptyStatement.INSTANCE
    );
    dummyMN.setGenericsTypes(mn.getGenericsTypes());
    dummyClass.addMethod(dummyMN);
    ResolveVisitor visitor = new ResolveVisitor(compilationUnit) {
        @Override
        public void addError(final String msg, final ASTNode expr) {
            sourceUnit.addError(new IncorrectTypeHintException(mn, msg, usage.getLineNumber(), usage.getColumnNumber()));
        }
    };
    visitor.startResolving(dummyClass, sourceUnit);
    return dummyMN.getReturnType();
}
 
开发者ID:apache,项目名称:groovy,代码行数:24,代码来源:GenericsUtils.java

示例13: parse

import org.codehaus.groovy.ast.ASTNode; //导入依赖的package包/类
static Options parse(MethodNode mn, ASTNode source, String[] options) throws IncorrectTypeHintException {
    int pIndex = 0;
    boolean generateIndex = false;
    for (String option : options) {
        String[] keyValue = option.split("=");
        if (keyValue.length==2) {
            String key = keyValue[0];
            String value = keyValue[1];
            if ("argNum".equals(key)) {
                pIndex = Integer.parseInt(value);
            } else if ("index".equals(key)) {
                generateIndex = Boolean.valueOf(value);
            } else {
                throw new IncorrectTypeHintException(mn, "Unrecognized option: "+key, source.getLineNumber(), source.getColumnNumber());
            }
        } else {
            throw new IncorrectTypeHintException(mn, "Incorrect option format. Should be argNum=<num> or index=<boolean> ", source.getLineNumber(), source.getColumnNumber());
        }
    }
    return new Options(pIndex, generateIndex);
}
 
开发者ID:apache,项目名称:groovy,代码行数:22,代码来源:MapEntryOrKeyValue.java

示例14: visit

import org.codehaus.groovy.ast.ASTNode; //导入依赖的package包/类
public void visit(ASTNode[] nodes, SourceUnit source) {
    init(nodes, source);
    AnnotatedNode parent = (AnnotatedNode) nodes[1];
    AnnotationNode anno = (AnnotationNode) nodes[0];
    if (!MY_TYPE.equals(anno.getClassNode())) return;

    if (parent instanceof ClassNode) {
        ClassNode cNode = (ClassNode) parent;
        if (!checkNotInterface(cNode, MY_TYPE_NAME)) return;
        cNode.addInterface(EXTERNALIZABLE_TYPE);
        boolean includeFields = memberHasValue(anno, "includeFields", true);
        List<String> excludes = getMemberStringList(anno, "excludes");
        if (!checkPropertyList(cNode, excludes, "excludes", anno, MY_TYPE_NAME, includeFields)) return;
        List<FieldNode> list = getInstancePropertyFields(cNode);
        if (includeFields) {
            list.addAll(getInstanceNonPropertyFields(cNode));
        }
        createWriteExternal(cNode, excludes, list);
        createReadExternal(cNode, excludes, list);
    }
}
 
开发者ID:apache,项目名称:groovy,代码行数:22,代码来源:ExternalizeMethodsASTTransformation.java

示例15: visit

import org.codehaus.groovy.ast.ASTNode; //导入依赖的package包/类
public void visit(ASTNode[] nodes, SourceUnit source) {
    init(nodes, source);
    AnnotatedNode parent = (AnnotatedNode) nodes[1];
    AnnotationNode anno = (AnnotationNode) nodes[0];
    if (!MY_TYPE.equals(anno.getClassNode())) return;

    if (parent instanceof ClassNode) {
        ClassNode cNode = (ClassNode) parent;
        if (!checkNotInterface(cNode, MY_TYPE_NAME)) return;
        ClassNode exception = getMemberClassValue(anno, "exception");
        if (exception != null && Undefined.isUndefinedException(exception)) {
            exception = null;
        }
        String message = getMemberStringValue(anno, "message");
        Expression code = anno.getMember("code");
        if (code != null && !(code instanceof ClosureExpression)) {
            addError("Expected closure value for annotation parameter 'code'. Found " + code, cNode);
            return;
        }
        createMethods(cNode, exception, message, (ClosureExpression) code);
        if (code != null) {
            anno.setMember("code", new ClosureExpression(new Parameter[0], EmptyStatement.INSTANCE));
        }
    }
}
 
开发者ID:apache,项目名称:groovy,代码行数:26,代码来源:AutoImplementASTTransformation.java


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