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


Java SourceUnit类代码示例

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


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

示例1: call

import org.codehaus.groovy.control.SourceUnit; //导入依赖的package包/类
@Override
public void call(SourceUnit source) throws CompilationFailedException {
    BlockStatement statementBlock = source.getAST().getStatementBlock();
    List<Statement> statements = statementBlock.getStatements();
    for (Statement statement : statements) {
        if (!AstUtils.mayHaveAnEffect(statement)) {
            continue;
        }
        ScriptBlock scriptBlock = AstUtils.detectScriptBlock(statement);
        if (scriptBlock != null && scriptBlock.getName().equals(ModelBlockTransformer.MODEL)) {
            continue;
        }
        imperativeStatementDetected = true;
        break;
    }
}
 
开发者ID:lxxlxx888,项目名称:Reer,代码行数:17,代码来源:ImperativeStatementDetectingTransformer.java

示例2: wrapCompilationFailure

import org.codehaus.groovy.control.SourceUnit; //导入依赖的package包/类
private void wrapCompilationFailure(ScriptSource source, MultipleCompilationErrorsException e) {
    // Fix the source file name displayed in the error messages
    for (Object message : e.getErrorCollector().getErrors()) {
        if (message instanceof SyntaxErrorMessage) {
            try {
                SyntaxErrorMessage syntaxErrorMessage = (SyntaxErrorMessage) message;
                Field sourceField = SyntaxErrorMessage.class.getDeclaredField("source");
                sourceField.setAccessible(true);
                SourceUnit sourceUnit = (SourceUnit) sourceField.get(syntaxErrorMessage);
                Field nameField = SourceUnit.class.getDeclaredField("name");
                nameField.setAccessible(true);
                nameField.set(sourceUnit, source.getDisplayName());
            } catch (Exception failure) {
                throw UncheckedException.throwAsUncheckedException(failure);
            }
        }
    }

    SyntaxException syntaxError = e.getErrorCollector().getSyntaxError(0);
    Integer lineNumber = syntaxError == null ? null : syntaxError.getLine();
    throw new ScriptCompilationException(String.format("Could not compile %s.", source.getDisplayName()), e, source, lineNumber);
}
 
开发者ID:lxxlxx888,项目名称:Reer,代码行数:23,代码来源:DefaultScriptCompilationHandler.java

示例3: call

import org.codehaus.groovy.control.SourceUnit; //导入依赖的package包/类
@Override
public void call(final SourceUnit source) throws CompilationFailedException {
    // currently we only look in script code; could extend this to build script classes
    AstUtils.visitScriptCode(source, new ClassCodeVisitorSupport() {
        @Override
        protected SourceUnit getSourceUnit() {
            return source;
        }

        @Override
        protected void visitStatement(Statement statement) {
            if (statement.getStatementLabel() != null) {
                String message = String.format("Statement labels may not be used in build scripts.%nIn case you tried to configure a property named '%s', replace ':' with '=' or ' ', otherwise it will not have the desired effect.",
                        statement.getStatementLabel());
                addError(message, statement);
            }
        }
    });
}
 
开发者ID:lxxlxx888,项目名称:Reer,代码行数:20,代码来源:StatementLabelsScriptTransformer.java

示例4: changeBaseScriptTypeFromPackageOrImport

import org.codehaus.groovy.control.SourceUnit; //导入依赖的package包/类
private void changeBaseScriptTypeFromPackageOrImport(final SourceUnit source, final AnnotatedNode parent, final AnnotationNode node) {
    Expression value = node.getMember("value");
    ClassNode scriptType;
    if (value == null) {
        scriptType = BASE_SCRIPT_TYPE;
    } else {
        if (!(value instanceof ClassExpression)) {
            addError("Annotation " + MY_TYPE_NAME + " member 'value' should be a class literal.", value);
            return;
        }
        scriptType = value.getType();
    }
    List<ClassNode> classes = source.getAST().getClasses();
    for (ClassNode classNode : classes) {
        if (classNode.isScriptBody()) {
            changeBaseScriptType(source, parent, classNode, scriptType, node);
        }
    }
}
 
开发者ID:remkop,项目名称:picocli,代码行数:20,代码来源:PicocliScriptASTTransformation.java

示例5: changeBaseScriptTypeFromDeclaration

import org.codehaus.groovy.control.SourceUnit; //导入依赖的package包/类
private void changeBaseScriptTypeFromDeclaration(final SourceUnit source, final DeclarationExpression de, final AnnotationNode node) {
    if (de.isMultipleAssignmentDeclaration()) {
        addError("Annotation " + MY_TYPE_NAME + " not supported with multiple assignment notation.", de);
        return;
    }

    if (!(de.getRightExpression() instanceof EmptyExpression)) {
        addError("Annotation " + MY_TYPE_NAME + " not supported with variable assignment.", de);
        return;
    }
    Expression value = node.getMember("value");
    if (value != null) {
        addError("Annotation " + MY_TYPE_NAME + " cannot have member 'value' if used on a declaration.", value);
        return;
    }

    ClassNode cNode = de.getDeclaringClass();
    ClassNode baseScriptType = de.getVariableExpression().getType().getPlainNodeReference();
    de.setRightExpression(new VariableExpression("this"));

    changeBaseScriptType(source, de, cNode, baseScriptType, node);
}
 
开发者ID:remkop,项目名称:picocli,代码行数:23,代码来源:PicocliScriptASTTransformation.java

示例6: visit

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

示例7: visit

import org.codehaus.groovy.control.SourceUnit; //导入依赖的package包/类
@Override
public void visit(ASTNode[] nodes, SourceUnit source) {
    init(nodes, source);
    AnnotatedNode annotatedNode = (AnnotatedNode) nodes[1];
    AnnotationNode annotationNode = (AnnotationNode) nodes[0];

    if (MY_TYPE.equals(annotationNode.getClassNode()) && annotatedNode instanceof ClassNode) {
        final Expression theAggregate = annotationNode.getMember("value");
        final ClassNode theClassNode = (ClassNode) annotatedNode;
        final String aggregateClassName = theAggregate.getType().getName();
        log.fine(() -> MessageFormat.format("Adding event {0} to aggregate {1}",
                theClassNode.getNameWithoutPackage(), aggregateClassName));
        AggregateASTTransformation.addEventToAggregate(aggregateClassName, theClassNode);
    }

}
 
开发者ID:rahulsom,项目名称:grooves,代码行数:17,代码来源:EventASTTransformation.java

示例8: createCollector

import org.codehaus.groovy.control.SourceUnit; //导入依赖的package包/类
@Override
public ClassCollector createCollector(CompilationUnit unit, SourceUnit su) {
	InnerLoader loader = AccessController
			.doPrivileged(new PrivilegedAction<InnerLoader>() {
				@Override
				public InnerLoader run() {
					return new InnerLoader(ExtendedGroovyClassLoader.this) {
						// Don't return URLs from the inner loader so that Tomcat only
						// searches the parent. Fixes 'TLD skipped' issues
						@Override
						public URL[] getURLs() {
							return NO_URLS;
						}
					};
				}
			});
	return new ExtendedClassCollector(loader, unit, su);
}
 
开发者ID:vikrammane23,项目名称:https-github.com-g0t4-jenkins2-course-spring-boot,代码行数:19,代码来源:ExtendedGroovyClassLoader.java

示例9: visit

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

示例10: call

import org.codehaus.groovy.control.SourceUnit; //导入依赖的package包/类
@Override
public void call(SourceUnit source, GeneratorContext context, ClassNode classNode)
		throws CompilationFailedException {

	ImportCustomizer importCustomizer = new SmartImportCustomizer(source, context,
			classNode);
	ClassNode mainClassNode = MainClass.get(source.getAST().getClasses());

	// Additional auto configuration
	for (CompilerAutoConfiguration autoConfiguration : GroovyCompiler.this.compilerAutoConfigurations) {
		if (autoConfiguration.matches(classNode)) {
			if (GroovyCompiler.this.configuration.isGuessImports()) {
				autoConfiguration.applyImports(importCustomizer);
				importCustomizer.call(source, context, classNode);
			}
			if (classNode.equals(mainClassNode)) {
				autoConfiguration.applyToMainClass(GroovyCompiler.this.loader,
						GroovyCompiler.this.configuration, context, source,
						classNode);
			}
			autoConfiguration.apply(GroovyCompiler.this.loader,
					GroovyCompiler.this.configuration, context, source,
					classNode);
		}
	}
	importCustomizer.call(source, context, classNode);
}
 
开发者ID:philwebb,项目名称:spring-boot-concourse,代码行数:28,代码来源:GroovyCompiler.java

示例11: visit

import org.codehaus.groovy.control.SourceUnit; //导入依赖的package包/类
public void visit(ASTNode[] nodes, SourceUnit source) {
    this.source = source;
    if (nodes.length != 2 || !(nodes[0] instanceof AnnotationNode) || !(nodes[1] instanceof AnnotatedNode)) {
        internalError("Expecting [AnnotationNode, AnnotatedClass] but got: " + Arrays.asList(nodes));
    }

    AnnotatedNode parent = (AnnotatedNode) nodes[1];
    AnnotationNode node = (AnnotationNode) nodes[0];
    if (!MY_TYPE.equals(node.getClassNode())) {
        internalError("Transformation called from wrong annotation: " + node.getClassNode().getName());
    }

    boolean autoFlag = determineAutoFlag(node.getMember("auto"));
    Expression value = node.getMember("value");

    if (parent instanceof ClassNode) {
        newifyClass((ClassNode) parent, autoFlag, determineClasses(value, false));
    } else if (parent instanceof MethodNode || parent instanceof FieldNode) {
        newifyMethodOrField(parent, autoFlag, determineClasses(value, false));
    } else if (parent instanceof DeclarationExpression) {
        newifyDeclaration((DeclarationExpression) parent, autoFlag, determineClasses(value, true));
    }
}
 
开发者ID:apache,项目名称:groovy,代码行数:24,代码来源:NewifyASTTransformation.java

示例12: getClosureArgument

import org.codehaus.groovy.control.SourceUnit; //导入依赖的package包/类
protected static ClosureExpression getClosureArgument(SourceUnit source, MethodCallExpression call) {
    TupleExpression tupleArguments = getMacroArguments(source, call);

    if (tupleArguments == null || tupleArguments.getExpressions().size() < 1) {
        source.addError(new SyntaxException("Call arguments should have at least one argument" + '\n', tupleArguments));
        return null;
    }

    Expression result = tupleArguments.getExpression(tupleArguments.getExpressions().size() - 1);
    if (!(result instanceof ClosureExpression)) {
        source.addError(new SyntaxException("Last call argument should be a closure" + '\n', result));
        return null;
    }

    return (ClosureExpression) result;
}
 
开发者ID:apache,项目名称:groovy,代码行数:17,代码来源:MacroGroovyMethods.java

示例13: AstBuilder

import org.codehaus.groovy.control.SourceUnit; //导入依赖的package包/类
public AstBuilder(SourceUnit sourceUnit) {
    this.sourceUnit = sourceUnit;
    this.moduleNode = new ModuleNode(sourceUnit);

    CharStream charStream = createCharStream(sourceUnit);

    this.lexer = new GroovyLangLexer(charStream);
    this.parser =
            new GroovyLangParser(
                new CommonTokenStream(this.lexer));

    this.parser.setErrorHandler(new DescriptiveErrorStrategy(charStream));

    this.tryWithResourcesASTTransformation = new TryWithResourcesASTTransformation(this);
    this.groovydocManager = GroovydocManager.getInstance();
}
 
开发者ID:apache,项目名称:groovy,代码行数:17,代码来源:AstBuilder.java

示例14: visit

import org.codehaus.groovy.control.SourceUnit; //导入依赖的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: makeMapTypedArgsTransformer

import org.codehaus.groovy.control.SourceUnit; //导入依赖的package包/类
private static ClassCodeExpressionTransformer makeMapTypedArgsTransformer() {
    return new ClassCodeExpressionTransformer() {
        @Override
        public Expression transform(Expression exp) {
            if (exp instanceof ClosureExpression) {
                ClosureExpression ce = (ClosureExpression) exp;
                ce.getCode().visit(this);
            } else if (exp instanceof VariableExpression) {
                VariableExpression ve = (VariableExpression) exp;
                if (ve.getName().equals("args") && ve.getAccessedVariable() instanceof DynamicVariable) {
                    VariableExpression newVe = new VariableExpression(new Parameter(MAP_TYPE, "args"));
                    newVe.setSourcePosition(ve);
                    return newVe;
                }
            }
            return exp.transformExpression(this);
        }

        @Override
        protected SourceUnit getSourceUnit() {
            return null;
        }
    };
}
 
开发者ID:apache,项目名称:groovy,代码行数:25,代码来源:MapConstructorASTTransformation.java


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